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