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 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 /* 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 */
65 /* pointer to each page */
71 /* this fields are not changed once the thread is created */
74 /* channel thread name */
78 /* channel thread id */
80 /* communication channel */
82 /* sem where to wait for more work */
84 /* this mutex protects the following parameters */
86 /* is this channel thread running */
88 /* should this thread finish */
90 /* is the yank function registered */
92 /* thread has work to do */
94 /* array of pages to sent */
95 MultiFDPages_t
*pages
;
96 /* packet allocated len */
98 /* pointer to the packet */
99 MultiFDPacket_t
*packet
;
100 /* multifd flags for each packet */
102 /* size of the next packet that contains pages */
103 uint32_t next_packet_size
;
104 /* global number of generated multifd packets */
106 /* thread local variables */
107 /* packets sent through this channel */
108 uint64_t num_packets
;
109 /* pages sent through this channel */
111 /* syncs main thread and channels */
112 QemuSemaphore sem_sync
;
113 /* used for compression methods */
118 /* this fields are not changed once the thread is created */
121 /* channel thread name */
123 /* channel thread id */
125 /* communication channel */
127 /* this mutex protects the following parameters */
129 /* is this channel thread running */
131 /* should this thread finish */
133 /* array of pages to receive */
134 MultiFDPages_t
*pages
;
135 /* packet allocated len */
137 /* pointer to the packet */
138 MultiFDPacket_t
*packet
;
139 /* multifd flags for each packet */
141 /* global number of generated multifd packets */
143 /* thread local variables */
144 /* size of the next packet that contains pages */
145 uint32_t next_packet_size
;
146 /* packets sent through this channel */
147 uint64_t num_packets
;
148 /* pages sent through this channel */
150 /* syncs main thread and channels */
151 QemuSemaphore sem_sync
;
152 /* used for de-compression methods */
157 /* Setup for sending side */
158 int (*send_setup
)(MultiFDSendParams
*p
, Error
**errp
);
159 /* Cleanup for sending side */
160 void (*send_cleanup
)(MultiFDSendParams
*p
, Error
**errp
);
161 /* Prepare the send packet */
162 int (*send_prepare
)(MultiFDSendParams
*p
, Error
**errp
);
163 /* Write the send packet */
164 int (*send_write
)(MultiFDSendParams
*p
, uint32_t used
, Error
**errp
);
165 /* Setup for receiving side */
166 int (*recv_setup
)(MultiFDRecvParams
*p
, Error
**errp
);
167 /* Cleanup for receiving side */
168 void (*recv_cleanup
)(MultiFDRecvParams
*p
);
170 int (*recv_pages
)(MultiFDRecvParams
*p
, Error
**errp
);
173 void multifd_register_ops(int method
, MultiFDMethods
*ops
);