2 * Multifd common functions
4 * Copyright (c) 2019-2020 Red Hat Inc
7 * Juan Quintela <quintela@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
13 #ifndef QEMU_MIGRATION_MULTIFD_H
14 #define QEMU_MIGRATION_MULTIFD_H
16 int multifd_save_setup(Error
**errp
);
17 void multifd_save_cleanup(void);
18 int multifd_load_setup(Error
**errp
);
19 int multifd_load_cleanup(Error
**errp
);
20 bool multifd_recv_all_channels_created(void);
21 bool multifd_recv_new_channel(QIOChannel
*ioc
, Error
**errp
);
22 void multifd_recv_sync_main(void);
23 int multifd_send_sync_main(QEMUFile
*f
);
24 int multifd_queue_page(QEMUFile
*f
, RAMBlock
*block
, ram_addr_t offset
);
26 /* Multifd Compression flags */
27 #define MULTIFD_FLAG_SYNC (1 << 0)
29 /* We reserve 3 bits for compression methods */
30 #define MULTIFD_FLAG_COMPRESSION_MASK (7 << 1)
31 /* we need to be compatible. Before compression value was 0 */
32 #define MULTIFD_FLAG_NOCOMP (0 << 1)
33 #define MULTIFD_FLAG_ZLIB (1 << 1)
34 #define MULTIFD_FLAG_ZSTD (2 << 1)
36 /* This value needs to be a multiple of qemu_target_page_size() */
37 #define MULTIFD_PACKET_SIZE (512 * 1024)
43 /* maximum number of allocated pages */
46 uint32_t normal_pages
;
47 /* size of the next packet that contains pages */
48 uint32_t next_packet_size
;
50 uint64_t unused
[4]; /* Reserved for future use */
53 } __attribute__((packed
)) MultiFDPacket_t
;
56 /* number of used pages */
58 /* number of allocated pages */
60 /* global number of generated multifd packets */
62 /* offset of each page */
68 /* Fields are only written at creating/deletion time */
69 /* No lock required for them, they are read only */
73 /* channel thread name */
75 /* channel thread id */
77 /* communication channel */
79 /* is the yank function registered */
81 /* packet allocated len */
83 /* multifd flags for sending ram */
86 /* sem where to wait for more work */
88 /* syncs main thread and channels */
89 QemuSemaphore sem_sync
;
91 /* this mutex protects the following parameters */
93 /* is this channel thread running */
95 /* should this thread finish */
97 /* multifd flags for each packet */
99 /* global number of generated multifd packets */
101 /* thread has work to do */
103 /* array of pages to sent.
104 * The owner of 'pages' depends of 'pending_job' value:
105 * pending_job == 0 -> migration_thread can use it.
106 * pending_job != 0 -> multifd_channel can use it.
108 MultiFDPages_t
*pages
;
110 /* thread local variables. No locking required */
112 /* pointer to the packet */
113 MultiFDPacket_t
*packet
;
114 /* size of the next packet that contains pages */
115 uint32_t next_packet_size
;
116 /* packets sent through this channel */
117 uint64_t num_packets
;
118 /* non zero pages sent through this channel */
119 uint64_t total_normal_pages
;
120 /* buffers to send */
122 /* number of iovs used */
124 /* Pages that are not zero */
126 /* num of non zero pages */
128 /* used for compression methods */
133 /* Fields are only written at creating/deletion time */
134 /* No lock required for them, they are read only */
138 /* channel thread name */
140 /* channel thread id */
142 /* communication channel */
144 /* packet allocated len */
147 /* syncs main thread and channels */
148 QemuSemaphore sem_sync
;
150 /* this mutex protects the following parameters */
152 /* is this channel thread running */
154 /* should this thread finish */
156 /* multifd flags for each packet */
158 /* global number of generated multifd packets */
161 /* thread local variables. No locking required */
163 /* pointer to the packet */
164 MultiFDPacket_t
*packet
;
165 /* size of the next packet that contains pages */
166 uint32_t next_packet_size
;
167 /* packets sent through this channel */
168 uint64_t num_packets
;
169 /* ramblock host address */
171 /* non zero pages recv through this channel */
172 uint64_t total_normal_pages
;
173 /* buffers to recv */
175 /* Pages that are not zero */
177 /* num of non zero pages */
179 /* used for de-compression methods */
184 /* Setup for sending side */
185 int (*send_setup
)(MultiFDSendParams
*p
, Error
**errp
);
186 /* Cleanup for sending side */
187 void (*send_cleanup
)(MultiFDSendParams
*p
, Error
**errp
);
188 /* Prepare the send packet */
189 int (*send_prepare
)(MultiFDSendParams
*p
, Error
**errp
);
190 /* Setup for receiving side */
191 int (*recv_setup
)(MultiFDRecvParams
*p
, Error
**errp
);
192 /* Cleanup for receiving side */
193 void (*recv_cleanup
)(MultiFDRecvParams
*p
);
195 int (*recv_pages
)(MultiFDRecvParams
*p
, Error
**errp
);
198 void multifd_register_ops(int method
, MultiFDMethods
*ops
);