]> git.proxmox.com Git - mirror_qemu.git/blame - migration/multifd.h
multifd: Add multifd-zlib-level parameter
[mirror_qemu.git] / migration / multifd.h
CommitLineData
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
16int multifd_save_setup(Error **errp);
17void multifd_save_cleanup(void);
18int multifd_load_setup(Error **errp);
19int multifd_load_cleanup(Error **errp);
20bool multifd_recv_all_channels_created(void);
21bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp);
22void multifd_recv_sync_main(void);
23void multifd_send_sync_main(QEMUFile *f);
24int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset);
25
26#define MULTIFD_FLAG_SYNC (1 << 0)
27
ab7cbb0b
JQ
28/* We reserve 3 bits for compression methods */
29#define MULTIFD_FLAG_COMPRESSION_MASK (7 << 1)
30/* we need to be compatible. Before compression value was 0 */
31#define MULTIFD_FLAG_NOCOMP (0 << 1)
32
d32ca5ad
JQ
33/* This value needs to be a multiple of qemu_target_page_size() */
34#define MULTIFD_PACKET_SIZE (512 * 1024)
35
36typedef struct {
37 uint32_t magic;
38 uint32_t version;
39 uint32_t flags;
40 /* maximum number of allocated pages */
41 uint32_t pages_alloc;
42 uint32_t pages_used;
43 /* size of the next packet that contains pages */
44 uint32_t next_packet_size;
45 uint64_t packet_num;
46 uint64_t unused[4]; /* Reserved for future use */
47 char ramblock[256];
48 uint64_t offset[];
49} __attribute__((packed)) MultiFDPacket_t;
50
51typedef struct {
52 /* number of used pages */
53 uint32_t used;
54 /* number of allocated pages */
55 uint32_t allocated;
56 /* global number of generated multifd packets */
57 uint64_t packet_num;
58 /* offset of each page */
59 ram_addr_t *offset;
60 /* pointer to each page */
61 struct iovec *iov;
62 RAMBlock *block;
63} MultiFDPages_t;
64
65typedef struct {
66 /* this fields are not changed once the thread is created */
67 /* channel number */
68 uint8_t id;
69 /* channel thread name */
70 char *name;
71 /* channel thread id */
72 QemuThread thread;
73 /* communication channel */
74 QIOChannel *c;
75 /* sem where to wait for more work */
76 QemuSemaphore sem;
77 /* this mutex protects the following parameters */
78 QemuMutex mutex;
79 /* is this channel thread running */
80 bool running;
81 /* should this thread finish */
82 bool quit;
83 /* thread has work to do */
84 int pending_job;
85 /* array of pages to sent */
86 MultiFDPages_t *pages;
87 /* packet allocated len */
88 uint32_t packet_len;
89 /* pointer to the packet */
90 MultiFDPacket_t *packet;
91 /* multifd flags for each packet */
92 uint32_t flags;
93 /* size of the next packet that contains pages */
94 uint32_t next_packet_size;
95 /* global number of generated multifd packets */
96 uint64_t packet_num;
97 /* thread local variables */
98 /* packets sent through this channel */
99 uint64_t num_packets;
100 /* pages sent through this channel */
101 uint64_t num_pages;
102 /* syncs main thread and channels */
103 QemuSemaphore sem_sync;
ab7cbb0b
JQ
104 /* used for compression methods */
105 void *data;
d32ca5ad
JQ
106} MultiFDSendParams;
107
108typedef struct {
109 /* this fields are not changed once the thread is created */
110 /* channel number */
111 uint8_t id;
112 /* channel thread name */
113 char *name;
114 /* channel thread id */
115 QemuThread thread;
116 /* communication channel */
117 QIOChannel *c;
118 /* this mutex protects the following parameters */
119 QemuMutex mutex;
120 /* is this channel thread running */
121 bool running;
122 /* should this thread finish */
123 bool quit;
124 /* array of pages to receive */
125 MultiFDPages_t *pages;
126 /* packet allocated len */
127 uint32_t packet_len;
128 /* pointer to the packet */
129 MultiFDPacket_t *packet;
130 /* multifd flags for each packet */
131 uint32_t flags;
132 /* global number of generated multifd packets */
133 uint64_t packet_num;
134 /* thread local variables */
135 /* size of the next packet that contains pages */
136 uint32_t next_packet_size;
137 /* packets sent through this channel */
138 uint64_t num_packets;
139 /* pages sent through this channel */
140 uint64_t num_pages;
141 /* syncs main thread and channels */
142 QemuSemaphore sem_sync;
ab7cbb0b
JQ
143 /* used for de-compression methods */
144 void *data;
d32ca5ad
JQ
145} MultiFDRecvParams;
146
ab7cbb0b
JQ
147typedef struct {
148 /* Setup for sending side */
149 int (*send_setup)(MultiFDSendParams *p, Error **errp);
150 /* Cleanup for sending side */
151 void (*send_cleanup)(MultiFDSendParams *p, Error **errp);
152 /* Prepare the send packet */
153 int (*send_prepare)(MultiFDSendParams *p, uint32_t used, Error **errp);
154 /* Write the send packet */
155 int (*send_write)(MultiFDSendParams *p, uint32_t used, Error **errp);
156 /* Setup for receiving side */
157 int (*recv_setup)(MultiFDRecvParams *p, Error **errp);
158 /* Cleanup for receiving side */
159 void (*recv_cleanup)(MultiFDRecvParams *p);
160 /* Read all pages */
161 int (*recv_pages)(MultiFDRecvParams *p, uint32_t used, Error **errp);
162} MultiFDMethods;
163
d32ca5ad
JQ
164#endif
165