2 * Multifd common functions
4 * Copyright (c) 2019-2020 Red Hat Inc
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 bool migrate_multifd_is_allowed(void);
17 void migrate_protocol_allow_multifd(bool allow);
18 int multifd_save_setup(Error **errp);
19 void multifd_save_cleanup(void);
20 int multifd_load_setup(Error **errp);
21 int multifd_load_cleanup(Error **errp);
22 bool multifd_recv_all_channels_created(void);
23 bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp);
24 void multifd_recv_sync_main(void);
25 void multifd_send_sync_main(QEMUFile *f);
26 int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset);
28 /* Multifd Compression flags */
29 #define MULTIFD_FLAG_SYNC (1 << 0)
31 /* We reserve 3 bits for compression methods */
32 #define MULTIFD_FLAG_COMPRESSION_MASK (7 << 1)
33 /* we need to be compatible. Before compression value was 0 */
34 #define MULTIFD_FLAG_NOCOMP (0 << 1)
35 #define MULTIFD_FLAG_ZLIB (1 << 1)
36 #define MULTIFD_FLAG_ZSTD (2 << 1)
38 /* This value needs to be a multiple of qemu_target_page_size() */
39 #define MULTIFD_PACKET_SIZE (512 * 1024)
45 /* maximum number of allocated pages */
48 uint32_t normal_pages;
49 /* size of the next packet that contains pages */
50 uint32_t next_packet_size;
52 uint64_t unused[4]; /* Reserved for future use */
55 } __attribute__((packed)) MultiFDPacket_t;
58 /* number of used pages */
60 /* number of allocated pages */
62 /* global number of generated multifd packets */
64 /* offset of each page */
70 /* this fields are not changed once the thread is created */
73 /* channel thread name */
77 /* channel thread id */
79 /* communication channel */
81 /* sem where to wait for more work */
83 /* this mutex protects the following parameters */
85 /* is this channel thread running */
87 /* should this thread finish */
89 /* is the yank function registered */
91 /* thread has work to do */
93 /* array of pages to sent */
94 MultiFDPages_t *pages;
95 /* packet allocated len */
97 /* pointer to the packet */
98 MultiFDPacket_t *packet;
99 /* multifd flags for each packet */
101 /* size of the next packet that contains pages */
102 uint32_t next_packet_size;
103 /* global number of generated multifd packets */
105 /* thread local variables */
106 /* packets sent through this channel */
107 uint64_t num_packets;
108 /* non zero pages sent through this channel */
109 uint64_t total_normal_pages;
110 /* syncs main thread and channels */
111 QemuSemaphore sem_sync;
112 /* buffers to send */
114 /* number of iovs used */
116 /* Pages that are not zero */
118 /* num of non zero pages */
120 /* used for compression methods */
125 /* this fields are not changed once the thread is created */
128 /* channel thread name */
130 /* channel thread id */
132 /* communication channel */
134 /* this mutex protects the following parameters */
136 /* is this channel thread running */
138 /* should this thread finish */
140 /* ramblock host address */
142 /* packet allocated len */
144 /* pointer to the packet */
145 MultiFDPacket_t *packet;
146 /* multifd flags for each packet */
148 /* global number of generated multifd packets */
150 /* thread local variables */
151 /* size of the next packet that contains pages */
152 uint32_t next_packet_size;
153 /* packets sent through this channel */
154 uint64_t num_packets;
155 /* non zero pages recv through this channel */
156 uint64_t total_normal_pages;
157 /* syncs main thread and channels */
158 QemuSemaphore sem_sync;
159 /* buffers to recv */
161 /* Pages that are not zero */
163 /* num of non zero pages */
165 /* used for de-compression methods */
170 /* Setup for sending side */
171 int (*send_setup)(MultiFDSendParams *p, Error **errp);
172 /* Cleanup for sending side */
173 void (*send_cleanup)(MultiFDSendParams *p, Error **errp);
174 /* Prepare the send packet */
175 int (*send_prepare)(MultiFDSendParams *p, Error **errp);
176 /* Setup for receiving side */
177 int (*recv_setup)(MultiFDRecvParams *p, Error **errp);
178 /* Cleanup for receiving side */
179 void (*recv_cleanup)(MultiFDRecvParams *p);
181 int (*recv_pages)(MultiFDRecvParams *p, Error **errp);
184 void multifd_register_ops(int method, MultiFDMethods *ops);