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 void multifd_load_cleanup(void);
20 void multifd_load_shutdown(void);
21 bool multifd_recv_all_channels_created(void);
22 void multifd_recv_new_channel(QIOChannel
*ioc
, Error
**errp
);
23 void multifd_recv_sync_main(void);
24 int multifd_send_sync_main(QEMUFile
*f
);
25 int multifd_queue_page(QEMUFile
*f
, RAMBlock
*block
, ram_addr_t offset
);
27 /* Multifd Compression flags */
28 #define MULTIFD_FLAG_SYNC (1 << 0)
30 /* We reserve 3 bits for compression methods */
31 #define MULTIFD_FLAG_COMPRESSION_MASK (7 << 1)
32 /* we need to be compatible. Before compression value was 0 */
33 #define MULTIFD_FLAG_NOCOMP (0 << 1)
34 #define MULTIFD_FLAG_ZLIB (1 << 1)
35 #define MULTIFD_FLAG_ZSTD (2 << 1)
37 /* This value needs to be a multiple of qemu_target_page_size() */
38 #define MULTIFD_PACKET_SIZE (512 * 1024)
44 /* maximum number of allocated pages */
47 uint32_t normal_pages
;
48 /* size of the next packet that contains pages */
49 uint32_t next_packet_size
;
51 uint64_t unused
[4]; /* Reserved for future use */
54 } __attribute__((packed
)) MultiFDPacket_t
;
57 /* number of used pages */
59 /* number of allocated pages */
61 /* global number of generated multifd packets */
63 /* offset of each page */
69 /* Fields are only written at creating/deletion time */
70 /* No lock required for them, they are read only */
74 /* channel thread name */
76 /* channel thread id */
78 /* communication channel */
80 /* is the yank function registered */
82 /* packet allocated len */
86 /* number of pages in a full packet */
88 /* multifd flags for sending ram */
91 /* sem where to wait for more work */
93 /* syncs main thread and channels */
94 QemuSemaphore sem_sync
;
96 /* this mutex protects the following parameters */
98 /* is this channel thread running */
100 /* should this thread finish */
102 /* multifd flags for each packet */
104 /* global number of generated multifd packets */
106 /* thread has work to do */
108 /* array of pages to sent.
109 * The owner of 'pages' depends of 'pending_job' value:
110 * pending_job == 0 -> migration_thread can use it.
111 * pending_job != 0 -> multifd_channel can use it.
113 MultiFDPages_t
*pages
;
115 /* thread local variables. No locking required */
117 /* pointer to the packet */
118 MultiFDPacket_t
*packet
;
119 /* size of the next packet that contains pages */
120 uint32_t next_packet_size
;
121 /* packets sent through this channel */
122 uint64_t num_packets
;
123 /* non zero pages sent through this channel */
124 uint64_t total_normal_pages
;
125 /* buffers to send */
127 /* number of iovs used */
129 /* Pages that are not zero */
131 /* num of non zero pages */
133 /* used for compression methods */
138 /* Fields are only written at creating/deletion time */
139 /* No lock required for them, they are read only */
143 /* channel thread name */
145 /* channel thread id */
147 /* communication channel */
149 /* packet allocated len */
151 /* guest page size */
153 /* number of pages in a full packet */
156 /* syncs main thread and channels */
157 QemuSemaphore sem_sync
;
159 /* this mutex protects the following parameters */
161 /* is this channel thread running */
163 /* should this thread finish */
165 /* multifd flags for each packet */
167 /* global number of generated multifd packets */
170 /* thread local variables. No locking required */
172 /* pointer to the packet */
173 MultiFDPacket_t
*packet
;
174 /* size of the next packet that contains pages */
175 uint32_t next_packet_size
;
176 /* packets sent through this channel */
177 uint64_t num_packets
;
180 /* ramblock host address */
182 /* non zero pages recv through this channel */
183 uint64_t total_normal_pages
;
184 /* buffers to recv */
186 /* Pages that are not zero */
188 /* num of non zero pages */
190 /* used for de-compression methods */
195 /* Setup for sending side */
196 int (*send_setup
)(MultiFDSendParams
*p
, Error
**errp
);
197 /* Cleanup for sending side */
198 void (*send_cleanup
)(MultiFDSendParams
*p
, Error
**errp
);
199 /* Prepare the send packet */
200 int (*send_prepare
)(MultiFDSendParams
*p
, Error
**errp
);
201 /* Setup for receiving side */
202 int (*recv_setup
)(MultiFDRecvParams
*p
, Error
**errp
);
203 /* Cleanup for receiving side */
204 void (*recv_cleanup
)(MultiFDRecvParams
*p
);
206 int (*recv_pages
)(MultiFDRecvParams
*p
, Error
**errp
);
209 void multifd_register_ops(int method
, MultiFDMethods
*ops
);