2020-01-22 16:16:07 +01:00
|
|
|
/*
|
|
|
|
* Multifd common functions
|
|
|
|
*
|
|
|
|
* Copyright (c) 2019-2020 Red Hat Inc
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Juan Quintela <quintela@redhat.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QEMU_MIGRATION_MULTIFD_H
|
|
|
|
#define QEMU_MIGRATION_MULTIFD_H
|
|
|
|
|
|
|
|
int multifd_save_setup(Error **errp);
|
|
|
|
void multifd_save_cleanup(void);
|
|
|
|
int multifd_load_setup(Error **errp);
|
2023-02-10 07:36:28 +01:00
|
|
|
void multifd_load_cleanup(void);
|
2023-02-10 07:36:31 +01:00
|
|
|
void multifd_load_shutdown(void);
|
2020-01-22 16:16:07 +01:00
|
|
|
bool multifd_recv_all_channels_created(void);
|
2022-12-20 19:44:18 +01:00
|
|
|
void multifd_recv_new_channel(QIOChannel *ioc, Error **errp);
|
2020-01-22 16:16:07 +01:00
|
|
|
void multifd_recv_sync_main(void);
|
2024-01-04 15:21:39 +01:00
|
|
|
int multifd_send_sync_main(void);
|
|
|
|
int multifd_queue_page(RAMBlock *block, ram_addr_t offset);
|
2020-01-22 16:16:07 +01:00
|
|
|
|
2019-01-04 15:30:06 +01:00
|
|
|
/* Multifd Compression flags */
|
2020-01-22 16:16:07 +01:00
|
|
|
#define MULTIFD_FLAG_SYNC (1 << 0)
|
|
|
|
|
2019-05-15 13:37:46 +02:00
|
|
|
/* We reserve 3 bits for compression methods */
|
|
|
|
#define MULTIFD_FLAG_COMPRESSION_MASK (7 << 1)
|
|
|
|
/* we need to be compatible. Before compression value was 0 */
|
|
|
|
#define MULTIFD_FLAG_NOCOMP (0 << 1)
|
2019-01-04 15:30:06 +01:00
|
|
|
#define MULTIFD_FLAG_ZLIB (1 << 1)
|
2019-12-13 13:47:14 +01:00
|
|
|
#define MULTIFD_FLAG_ZSTD (2 << 1)
|
2019-05-15 13:37:46 +02:00
|
|
|
|
2020-01-22 16:16:07 +01:00
|
|
|
/* This value needs to be a multiple of qemu_target_page_size() */
|
|
|
|
#define MULTIFD_PACKET_SIZE (512 * 1024)
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint32_t magic;
|
|
|
|
uint32_t version;
|
|
|
|
uint32_t flags;
|
|
|
|
/* maximum number of allocated pages */
|
|
|
|
uint32_t pages_alloc;
|
2021-11-22 14:13:51 +01:00
|
|
|
/* non zero pages */
|
|
|
|
uint32_t normal_pages;
|
2020-01-22 16:16:07 +01:00
|
|
|
/* size of the next packet that contains pages */
|
|
|
|
uint32_t next_packet_size;
|
|
|
|
uint64_t packet_num;
|
|
|
|
uint64_t unused[4]; /* Reserved for future use */
|
|
|
|
char ramblock[256];
|
|
|
|
uint64_t offset[];
|
|
|
|
} __attribute__((packed)) MultiFDPacket_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/* number of used pages */
|
2021-11-22 11:51:40 +01:00
|
|
|
uint32_t num;
|
2020-01-22 16:16:07 +01:00
|
|
|
/* number of allocated pages */
|
|
|
|
uint32_t allocated;
|
|
|
|
/* offset of each page */
|
|
|
|
ram_addr_t *offset;
|
|
|
|
RAMBlock *block;
|
|
|
|
} MultiFDPages_t;
|
|
|
|
|
|
|
|
typedef struct {
|
2022-05-31 12:43:06 +02:00
|
|
|
/* Fields are only written at creating/deletion time */
|
|
|
|
/* No lock required for them, they are read only */
|
|
|
|
|
2020-01-22 16:16:07 +01:00
|
|
|
/* channel number */
|
|
|
|
uint8_t id;
|
|
|
|
/* channel thread name */
|
|
|
|
char *name;
|
|
|
|
/* channel thread id */
|
|
|
|
QemuThread thread;
|
|
|
|
/* communication channel */
|
|
|
|
QIOChannel *c;
|
2022-05-31 12:43:06 +02:00
|
|
|
/* is the yank function registered */
|
|
|
|
bool registered_yank;
|
|
|
|
/* packet allocated len */
|
|
|
|
uint32_t packet_len;
|
2022-05-02 16:45:35 +02:00
|
|
|
/* guest page size */
|
|
|
|
uint32_t page_size;
|
2022-05-02 16:53:12 +02:00
|
|
|
/* number of pages in a full packet */
|
|
|
|
uint32_t page_count;
|
2022-05-31 12:43:06 +02:00
|
|
|
/* multifd flags for sending ram */
|
|
|
|
int write_flags;
|
|
|
|
|
2020-01-22 16:16:07 +01:00
|
|
|
/* sem where to wait for more work */
|
|
|
|
QemuSemaphore sem;
|
2022-05-31 12:43:06 +02:00
|
|
|
/* syncs main thread and channels */
|
|
|
|
QemuSemaphore sem_sync;
|
|
|
|
|
2020-01-22 16:16:07 +01:00
|
|
|
/* this mutex protects the following parameters */
|
|
|
|
QemuMutex mutex;
|
|
|
|
/* is this channel thread running */
|
|
|
|
bool running;
|
|
|
|
/* should this thread finish */
|
|
|
|
bool quit;
|
2022-05-31 12:43:06 +02:00
|
|
|
/* multifd flags for each packet */
|
|
|
|
uint32_t flags;
|
|
|
|
/* global number of generated multifd packets */
|
|
|
|
uint64_t packet_num;
|
2020-01-22 16:16:07 +01:00
|
|
|
/* thread has work to do */
|
|
|
|
int pending_job;
|
2022-05-31 12:43:06 +02:00
|
|
|
/* array of pages to sent.
|
|
|
|
* The owner of 'pages' depends of 'pending_job' value:
|
|
|
|
* pending_job == 0 -> migration_thread can use it.
|
|
|
|
* pending_job != 0 -> multifd_channel can use it.
|
|
|
|
*/
|
2020-01-22 16:16:07 +01:00
|
|
|
MultiFDPages_t *pages;
|
2022-05-31 12:43:06 +02:00
|
|
|
|
|
|
|
/* thread local variables. No locking required */
|
|
|
|
|
2020-01-22 16:16:07 +01:00
|
|
|
/* pointer to the packet */
|
|
|
|
MultiFDPacket_t *packet;
|
|
|
|
/* size of the next packet that contains pages */
|
|
|
|
uint32_t next_packet_size;
|
|
|
|
/* packets sent through this channel */
|
|
|
|
uint64_t num_packets;
|
2021-11-22 13:26:18 +01:00
|
|
|
/* non zero pages sent through this channel */
|
|
|
|
uint64_t total_normal_pages;
|
2021-11-19 12:06:05 +01:00
|
|
|
/* buffers to send */
|
|
|
|
struct iovec *iov;
|
|
|
|
/* number of iovs used */
|
|
|
|
uint32_t iovs_num;
|
2021-11-22 13:26:18 +01:00
|
|
|
/* Pages that are not zero */
|
|
|
|
ram_addr_t *normal;
|
|
|
|
/* num of non zero pages */
|
|
|
|
uint32_t normal_num;
|
2019-05-15 13:37:46 +02:00
|
|
|
/* used for compression methods */
|
|
|
|
void *data;
|
2020-01-22 16:16:07 +01:00
|
|
|
} MultiFDSendParams;
|
|
|
|
|
|
|
|
typedef struct {
|
2022-05-31 12:43:06 +02:00
|
|
|
/* Fields are only written at creating/deletion time */
|
|
|
|
/* No lock required for them, they are read only */
|
|
|
|
|
2020-01-22 16:16:07 +01:00
|
|
|
/* channel number */
|
|
|
|
uint8_t id;
|
|
|
|
/* channel thread name */
|
|
|
|
char *name;
|
|
|
|
/* channel thread id */
|
|
|
|
QemuThread thread;
|
|
|
|
/* communication channel */
|
|
|
|
QIOChannel *c;
|
2022-05-31 12:43:06 +02:00
|
|
|
/* packet allocated len */
|
|
|
|
uint32_t packet_len;
|
2022-05-02 16:45:35 +02:00
|
|
|
/* guest page size */
|
|
|
|
uint32_t page_size;
|
2022-05-02 16:53:12 +02:00
|
|
|
/* number of pages in a full packet */
|
|
|
|
uint32_t page_count;
|
2022-05-31 12:43:06 +02:00
|
|
|
|
|
|
|
/* syncs main thread and channels */
|
|
|
|
QemuSemaphore sem_sync;
|
|
|
|
|
2020-01-22 16:16:07 +01:00
|
|
|
/* this mutex protects the following parameters */
|
|
|
|
QemuMutex mutex;
|
|
|
|
/* is this channel thread running */
|
|
|
|
bool running;
|
|
|
|
/* should this thread finish */
|
|
|
|
bool quit;
|
|
|
|
/* multifd flags for each packet */
|
|
|
|
uint32_t flags;
|
|
|
|
/* global number of generated multifd packets */
|
|
|
|
uint64_t packet_num;
|
2022-05-31 12:43:06 +02:00
|
|
|
|
|
|
|
/* thread local variables. No locking required */
|
|
|
|
|
|
|
|
/* pointer to the packet */
|
|
|
|
MultiFDPacket_t *packet;
|
2020-01-22 16:16:07 +01:00
|
|
|
/* size of the next packet that contains pages */
|
|
|
|
uint32_t next_packet_size;
|
|
|
|
/* packets sent through this channel */
|
|
|
|
uint64_t num_packets;
|
2023-05-08 21:11:07 +02:00
|
|
|
/* ramblock */
|
|
|
|
RAMBlock *block;
|
2022-05-31 12:43:06 +02:00
|
|
|
/* ramblock host address */
|
|
|
|
uint8_t *host;
|
2021-11-22 13:41:06 +01:00
|
|
|
/* non zero pages recv through this channel */
|
|
|
|
uint64_t total_normal_pages;
|
2021-11-19 12:06:05 +01:00
|
|
|
/* buffers to recv */
|
|
|
|
struct iovec *iov;
|
2021-11-22 13:41:06 +01:00
|
|
|
/* Pages that are not zero */
|
|
|
|
ram_addr_t *normal;
|
|
|
|
/* num of non zero pages */
|
|
|
|
uint32_t normal_num;
|
2019-05-15 13:37:46 +02:00
|
|
|
/* used for de-compression methods */
|
|
|
|
void *data;
|
2020-01-22 16:16:07 +01:00
|
|
|
} MultiFDRecvParams;
|
|
|
|
|
2019-05-15 13:37:46 +02:00
|
|
|
typedef struct {
|
|
|
|
/* Setup for sending side */
|
|
|
|
int (*send_setup)(MultiFDSendParams *p, Error **errp);
|
|
|
|
/* Cleanup for sending side */
|
|
|
|
void (*send_cleanup)(MultiFDSendParams *p, Error **errp);
|
|
|
|
/* Prepare the send packet */
|
2021-11-22 12:08:08 +01:00
|
|
|
int (*send_prepare)(MultiFDSendParams *p, Error **errp);
|
2019-05-15 13:37:46 +02:00
|
|
|
/* Setup for receiving side */
|
|
|
|
int (*recv_setup)(MultiFDRecvParams *p, Error **errp);
|
|
|
|
/* Cleanup for receiving side */
|
|
|
|
void (*recv_cleanup)(MultiFDRecvParams *p);
|
|
|
|
/* Read all pages */
|
2021-11-22 12:49:43 +01:00
|
|
|
int (*recv_pages)(MultiFDRecvParams *p, Error **errp);
|
2019-05-15 13:37:46 +02:00
|
|
|
} MultiFDMethods;
|
|
|
|
|
2019-01-04 15:30:06 +01:00
|
|
|
void multifd_register_ops(int method, MultiFDMethods *ops);
|
|
|
|
|
2020-01-22 16:16:07 +01:00
|
|
|
#endif
|
|
|
|
|