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 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 void 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 /* size of the next packet that contains pages */
47 uint32_t next_packet_size;
49 uint64_t unused[4]; /* Reserved for future use */
52 } __attribute__((packed)) MultiFDPacket_t;
55 /* number of used pages */
57 /* number of allocated pages */
59 /* global number of generated multifd packets */
61 /* offset of each page */
63 /* pointer to each page */
69 /* this fields are not changed once the thread is created */
72 /* channel thread name */
76 /* channel thread id */
78 /* communication channel */
80 /* sem where to wait for more work */
82 /* this mutex protects the following parameters */
84 /* is this channel thread running */
86 /* should this thread finish */
88 /* thread has work to do */
90 /* array of pages to sent */
91 MultiFDPages_t *pages;
92 /* packet allocated len */
94 /* pointer to the packet */
95 MultiFDPacket_t *packet;
96 /* multifd flags for each packet */
98 /* size of the next packet that contains pages */
99 uint32_t next_packet_size;
100 /* global number of generated multifd packets */
102 /* thread local variables */
103 /* packets sent through this channel */
104 uint64_t num_packets;
105 /* pages sent through this channel */
107 /* syncs main thread and channels */
108 QemuSemaphore sem_sync;
109 /* used for compression methods */
114 /* this fields are not changed once the thread is created */
117 /* channel thread name */
119 /* channel thread id */
121 /* communication channel */
123 /* this mutex protects the following parameters */
125 /* is this channel thread running */
127 /* should this thread finish */
129 /* array of pages to receive */
130 MultiFDPages_t *pages;
131 /* packet allocated len */
133 /* pointer to the packet */
134 MultiFDPacket_t *packet;
135 /* multifd flags for each packet */
137 /* global number of generated multifd packets */
139 /* thread local variables */
140 /* size of the next packet that contains pages */
141 uint32_t next_packet_size;
142 /* packets sent through this channel */
143 uint64_t num_packets;
144 /* pages sent through this channel */
146 /* syncs main thread and channels */
147 QemuSemaphore sem_sync;
148 /* used for de-compression methods */
153 /* Setup for sending side */
154 int (*send_setup)(MultiFDSendParams *p, Error **errp);
155 /* Cleanup for sending side */
156 void (*send_cleanup)(MultiFDSendParams *p, Error **errp);
157 /* Prepare the send packet */
158 int (*send_prepare)(MultiFDSendParams *p, uint32_t used, Error **errp);
159 /* Write the send packet */
160 int (*send_write)(MultiFDSendParams *p, uint32_t used, Error **errp);
161 /* Setup for receiving side */
162 int (*recv_setup)(MultiFDRecvParams *p, Error **errp);
163 /* Cleanup for receiving side */
164 void (*recv_cleanup)(MultiFDRecvParams *p);
166 int (*recv_pages)(MultiFDRecvParams *p, uint32_t used, Error **errp);
169 void multifd_register_ops(int method, MultiFDMethods *ops);