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(void);
25 int multifd_queue_page(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 /* offset of each page */
67 /* Fields are only written at creating/deletion time */
68 /* No lock required for them, they are read only */
72 /* channel thread name */
74 /* channel thread id */
76 /* communication channel */
78 /* is the yank function registered */
80 /* packet allocated len */
84 /* number of pages in a full packet */
86 /* multifd flags for sending ram */
89 /* sem where to wait for more work */
91 /* syncs main thread and channels */
92 QemuSemaphore sem_sync
;
94 /* this mutex protects the following parameters */
96 /* is this channel thread running */
98 /* should this thread finish */
100 /* multifd flags for each packet */
102 /* global number of generated multifd packets */
104 /* thread has work to do */
106 /* array of pages to sent.
107 * The owner of 'pages' depends of 'pending_job' value:
108 * pending_job == 0 -> migration_thread can use it.
109 * pending_job != 0 -> multifd_channel can use it.
111 MultiFDPages_t
*pages
;
113 /* thread local variables. No locking required */
115 /* pointer to the packet */
116 MultiFDPacket_t
*packet
;
117 /* size of the next packet that contains pages */
118 uint32_t next_packet_size
;
119 /* packets sent through this channel */
120 uint64_t num_packets
;
121 /* non zero pages sent through this channel */
122 uint64_t total_normal_pages
;
123 /* buffers to send */
125 /* number of iovs used */
127 /* Pages that are not zero */
129 /* num of non zero pages */
131 /* used for compression methods */
136 /* Fields are only written at creating/deletion time */
137 /* No lock required for them, they are read only */
141 /* channel thread name */
143 /* channel thread id */
145 /* communication channel */
147 /* packet allocated len */
149 /* guest page size */
151 /* number of pages in a full packet */
154 /* syncs main thread and channels */
155 QemuSemaphore sem_sync
;
157 /* this mutex protects the following parameters */
159 /* is this channel thread running */
161 /* should this thread finish */
163 /* multifd flags for each packet */
165 /* global number of generated multifd packets */
168 /* thread local variables. No locking required */
170 /* pointer to the packet */
171 MultiFDPacket_t
*packet
;
172 /* size of the next packet that contains pages */
173 uint32_t next_packet_size
;
174 /* packets sent through this channel */
175 uint64_t num_packets
;
178 /* ramblock host address */
180 /* non zero pages recv through this channel */
181 uint64_t total_normal_pages
;
182 /* buffers to recv */
184 /* Pages that are not zero */
186 /* num of non zero pages */
188 /* used for de-compression methods */
193 /* Setup for sending side */
194 int (*send_setup
)(MultiFDSendParams
*p
, Error
**errp
);
195 /* Cleanup for sending side */
196 void (*send_cleanup
)(MultiFDSendParams
*p
, Error
**errp
);
197 /* Prepare the send packet */
198 int (*send_prepare
)(MultiFDSendParams
*p
, Error
**errp
);
199 /* Setup for receiving side */
200 int (*recv_setup
)(MultiFDRecvParams
*p
, Error
**errp
);
201 /* Cleanup for receiving side */
202 void (*recv_cleanup
)(MultiFDRecvParams
*p
);
204 int (*recv_pages
)(MultiFDRecvParams
*p
, Error
**errp
);
207 void multifd_register_ops(int method
, MultiFDMethods
*ops
);