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 /* this fields are not changed once the thread is created */
71 /* channel thread name */
73 /* channel thread id */
75 /* communication channel */
77 /* sem where to wait for more work */
79 /* this mutex protects the following parameters */
81 /* is this channel thread running */
83 /* should this thread finish */
85 /* is the yank function registered */
87 /* thread has work to do */
89 /* array of pages to sent */
90 MultiFDPages_t
*pages
;
91 /* packet allocated len */
93 /* pointer to the packet */
94 MultiFDPacket_t
*packet
;
95 /* multifd flags for sending ram */
97 /* multifd flags for each packet */
99 /* size of the next packet that contains pages */
100 uint32_t next_packet_size
;
101 /* global number of generated multifd packets */
103 /* thread local variables */
104 /* packets sent through this channel */
105 uint64_t num_packets
;
106 /* non zero pages sent through this channel */
107 uint64_t total_normal_pages
;
108 /* syncs main thread and channels */
109 QemuSemaphore sem_sync
;
110 /* buffers to send */
112 /* number of iovs used */
114 /* Pages that are not zero */
116 /* num of non zero pages */
118 /* used for compression methods */
123 /* this fields are not changed once the thread is created */
126 /* channel thread name */
128 /* channel thread id */
130 /* communication channel */
132 /* this mutex protects the following parameters */
134 /* is this channel thread running */
136 /* should this thread finish */
138 /* ramblock host address */
140 /* packet allocated len */
142 /* pointer to the packet */
143 MultiFDPacket_t
*packet
;
144 /* multifd flags for each packet */
146 /* global number of generated multifd packets */
148 /* thread local variables */
149 /* size of the next packet that contains pages */
150 uint32_t next_packet_size
;
151 /* packets sent through this channel */
152 uint64_t num_packets
;
153 /* non zero pages recv through this channel */
154 uint64_t total_normal_pages
;
155 /* syncs main thread and channels */
156 QemuSemaphore sem_sync
;
157 /* buffers to recv */
159 /* Pages that are not zero */
161 /* num of non zero pages */
163 /* used for de-compression methods */
168 /* Setup for sending side */
169 int (*send_setup
)(MultiFDSendParams
*p
, Error
**errp
);
170 /* Cleanup for sending side */
171 void (*send_cleanup
)(MultiFDSendParams
*p
, Error
**errp
);
172 /* Prepare the send packet */
173 int (*send_prepare
)(MultiFDSendParams
*p
, Error
**errp
);
174 /* Setup for receiving side */
175 int (*recv_setup
)(MultiFDRecvParams
*p
, Error
**errp
);
176 /* Cleanup for receiving side */
177 void (*recv_cleanup
)(MultiFDRecvParams
*p
);
179 int (*recv_pages
)(MultiFDRecvParams
*p
, Error
**errp
);
182 void multifd_register_ops(int method
, MultiFDMethods
*ops
);