]>
Commit | Line | Data |
---|---|---|
d32ca5ad JQ |
1 | /* |
2 | * Multifd common functions | |
3 | * | |
4 | * Copyright (c) 2019-2020 Red Hat Inc | |
5 | * | |
6 | * Authors: | |
7 | * Juan Quintela <quintela@redhat.com> | |
8 | * | |
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. | |
11 | */ | |
12 | ||
13 | #ifndef QEMU_MIGRATION_MULTIFD_H | |
14 | #define QEMU_MIGRATION_MULTIFD_H | |
15 | ||
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); | |
33d70973 | 23 | int multifd_send_sync_main(QEMUFile *f); |
d32ca5ad JQ |
24 | int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset); |
25 | ||
7ec2c2b3 | 26 | /* Multifd Compression flags */ |
d32ca5ad JQ |
27 | #define MULTIFD_FLAG_SYNC (1 << 0) |
28 | ||
ab7cbb0b JQ |
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) | |
7ec2c2b3 | 33 | #define MULTIFD_FLAG_ZLIB (1 << 1) |
87dc6f5f | 34 | #define MULTIFD_FLAG_ZSTD (2 << 1) |
ab7cbb0b | 35 | |
d32ca5ad JQ |
36 | /* This value needs to be a multiple of qemu_target_page_size() */ |
37 | #define MULTIFD_PACKET_SIZE (512 * 1024) | |
38 | ||
39 | typedef struct { | |
40 | uint32_t magic; | |
41 | uint32_t version; | |
42 | uint32_t flags; | |
43 | /* maximum number of allocated pages */ | |
44 | uint32_t pages_alloc; | |
8c0ec0b2 JQ |
45 | /* non zero pages */ |
46 | uint32_t normal_pages; | |
d32ca5ad JQ |
47 | /* size of the next packet that contains pages */ |
48 | uint32_t next_packet_size; | |
49 | uint64_t packet_num; | |
50 | uint64_t unused[4]; /* Reserved for future use */ | |
51 | char ramblock[256]; | |
52 | uint64_t offset[]; | |
53 | } __attribute__((packed)) MultiFDPacket_t; | |
54 | ||
55 | typedef struct { | |
56 | /* number of used pages */ | |
90a3d2f9 | 57 | uint32_t num; |
d32ca5ad JQ |
58 | /* number of allocated pages */ |
59 | uint32_t allocated; | |
60 | /* global number of generated multifd packets */ | |
61 | uint64_t packet_num; | |
62 | /* offset of each page */ | |
63 | ram_addr_t *offset; | |
d32ca5ad JQ |
64 | RAMBlock *block; |
65 | } MultiFDPages_t; | |
66 | ||
67 | typedef struct { | |
4a8f19c9 JQ |
68 | /* Fields are only written at creating/deletion time */ |
69 | /* No lock required for them, they are read only */ | |
70 | ||
d32ca5ad JQ |
71 | /* channel number */ |
72 | uint8_t id; | |
73 | /* channel thread name */ | |
74 | char *name; | |
75 | /* channel thread id */ | |
76 | QemuThread thread; | |
77 | /* communication channel */ | |
78 | QIOChannel *c; | |
4a8f19c9 JQ |
79 | /* is the yank function registered */ |
80 | bool registered_yank; | |
81 | /* packet allocated len */ | |
82 | uint32_t packet_len; | |
83 | /* multifd flags for sending ram */ | |
84 | int write_flags; | |
85 | ||
d32ca5ad JQ |
86 | /* sem where to wait for more work */ |
87 | QemuSemaphore sem; | |
4a8f19c9 JQ |
88 | /* syncs main thread and channels */ |
89 | QemuSemaphore sem_sync; | |
90 | ||
d32ca5ad JQ |
91 | /* this mutex protects the following parameters */ |
92 | QemuMutex mutex; | |
93 | /* is this channel thread running */ | |
94 | bool running; | |
95 | /* should this thread finish */ | |
96 | bool quit; | |
4a8f19c9 JQ |
97 | /* multifd flags for each packet */ |
98 | uint32_t flags; | |
99 | /* global number of generated multifd packets */ | |
100 | uint64_t packet_num; | |
d32ca5ad JQ |
101 | /* thread has work to do */ |
102 | int pending_job; | |
4a8f19c9 JQ |
103 | /* array of pages to sent. |
104 | * The owner of 'pages' depends of 'pending_job' value: | |
105 | * pending_job == 0 -> migration_thread can use it. | |
106 | * pending_job != 0 -> multifd_channel can use it. | |
107 | */ | |
d32ca5ad | 108 | MultiFDPages_t *pages; |
4a8f19c9 JQ |
109 | |
110 | /* thread local variables. No locking required */ | |
111 | ||
d32ca5ad JQ |
112 | /* pointer to the packet */ |
113 | MultiFDPacket_t *packet; | |
d32ca5ad JQ |
114 | /* size of the next packet that contains pages */ |
115 | uint32_t next_packet_size; | |
d32ca5ad JQ |
116 | /* packets sent through this channel */ |
117 | uint64_t num_packets; | |
815956f0 JQ |
118 | /* non zero pages sent through this channel */ |
119 | uint64_t total_normal_pages; | |
226468ba JQ |
120 | /* buffers to send */ |
121 | struct iovec *iov; | |
122 | /* number of iovs used */ | |
123 | uint32_t iovs_num; | |
815956f0 JQ |
124 | /* Pages that are not zero */ |
125 | ram_addr_t *normal; | |
126 | /* num of non zero pages */ | |
127 | uint32_t normal_num; | |
ab7cbb0b JQ |
128 | /* used for compression methods */ |
129 | void *data; | |
d32ca5ad JQ |
130 | } MultiFDSendParams; |
131 | ||
132 | typedef struct { | |
4a8f19c9 JQ |
133 | /* Fields are only written at creating/deletion time */ |
134 | /* No lock required for them, they are read only */ | |
135 | ||
d32ca5ad JQ |
136 | /* channel number */ |
137 | uint8_t id; | |
138 | /* channel thread name */ | |
139 | char *name; | |
140 | /* channel thread id */ | |
141 | QemuThread thread; | |
142 | /* communication channel */ | |
143 | QIOChannel *c; | |
4a8f19c9 JQ |
144 | /* packet allocated len */ |
145 | uint32_t packet_len; | |
146 | ||
147 | /* syncs main thread and channels */ | |
148 | QemuSemaphore sem_sync; | |
149 | ||
d32ca5ad JQ |
150 | /* this mutex protects the following parameters */ |
151 | QemuMutex mutex; | |
152 | /* is this channel thread running */ | |
153 | bool running; | |
154 | /* should this thread finish */ | |
155 | bool quit; | |
d32ca5ad JQ |
156 | /* multifd flags for each packet */ |
157 | uint32_t flags; | |
158 | /* global number of generated multifd packets */ | |
159 | uint64_t packet_num; | |
4a8f19c9 JQ |
160 | |
161 | /* thread local variables. No locking required */ | |
162 | ||
163 | /* pointer to the packet */ | |
164 | MultiFDPacket_t *packet; | |
d32ca5ad JQ |
165 | /* size of the next packet that contains pages */ |
166 | uint32_t next_packet_size; | |
167 | /* packets sent through this channel */ | |
168 | uint64_t num_packets; | |
4a8f19c9 JQ |
169 | /* ramblock host address */ |
170 | uint8_t *host; | |
cf2d4aa8 JQ |
171 | /* non zero pages recv through this channel */ |
172 | uint64_t total_normal_pages; | |
226468ba JQ |
173 | /* buffers to recv */ |
174 | struct iovec *iov; | |
cf2d4aa8 JQ |
175 | /* Pages that are not zero */ |
176 | ram_addr_t *normal; | |
177 | /* num of non zero pages */ | |
178 | uint32_t normal_num; | |
ab7cbb0b JQ |
179 | /* used for de-compression methods */ |
180 | void *data; | |
d32ca5ad JQ |
181 | } MultiFDRecvParams; |
182 | ||
ab7cbb0b JQ |
183 | typedef struct { |
184 | /* Setup for sending side */ | |
185 | int (*send_setup)(MultiFDSendParams *p, Error **errp); | |
186 | /* Cleanup for sending side */ | |
187 | void (*send_cleanup)(MultiFDSendParams *p, Error **errp); | |
188 | /* Prepare the send packet */ | |
02fb8104 | 189 | int (*send_prepare)(MultiFDSendParams *p, Error **errp); |
ab7cbb0b JQ |
190 | /* Setup for receiving side */ |
191 | int (*recv_setup)(MultiFDRecvParams *p, Error **errp); | |
192 | /* Cleanup for receiving side */ | |
193 | void (*recv_cleanup)(MultiFDRecvParams *p); | |
194 | /* Read all pages */ | |
40a4bfe9 | 195 | int (*recv_pages)(MultiFDRecvParams *p, Error **errp); |
ab7cbb0b JQ |
196 | } MultiFDMethods; |
197 | ||
7ec2c2b3 JQ |
198 | void multifd_register_ops(int method, MultiFDMethods *ops); |
199 | ||
d32ca5ad JQ |
200 | #endif |
201 |