]> git.proxmox.com Git - mirror_qemu.git/blame - migration/dirtyrate.h
Merge tag 'hw-misc-20231020' of https://github.com/philmd/qemu into staging
[mirror_qemu.git] / migration / dirtyrate.h
CommitLineData
4240dcee
CZ
1/*
2 * Dirtyrate common functions
3 *
4 * Copyright (c) 2020 HUAWEI TECHNOLOGIES CO., LTD.
5 *
6 * Authors:
7 * Chuan Zheng <zhengchuan@huawei.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_DIRTYRATE_H
14#define QEMU_MIGRATION_DIRTYRATE_H
15
8244166d
HH
16#include "sysemu/dirtyrate.h"
17
4240dcee
CZ
18/*
19 * Sample 512 pages per GB as default.
4240dcee
CZ
20 */
21#define DIRTYRATE_DEFAULT_SAMPLE_PAGES 512
22
a2635f0a
CZ
23/*
24 * Record ramblock idstr
25 */
26#define RAMBLOCK_INFO_MAX_LEN 256
27
f82583cd
CZ
28/*
29 * Minimum RAMBlock size to sample, in megabytes.
30 */
31#define MIN_RAMBLOCK_SIZE 128
32
eca58224 33/*
34a68001
AG
34 * Allowed range for dirty page rate calculation (in milliseconds).
35 * Lower limit relates to the smallest realistic downtime it
36 * makes sense to impose on migration.
eca58224 37 */
34a68001
AG
38#define MIN_CALC_TIME_MS 50
39#define MAX_CALC_TIME_MS 60000
eca58224 40
7afa08cd
HH
41/*
42 * Take 1/16 pages in 1G as the maxmum sample page count
43 */
44#define MIN_SAMPLE_PAGE_COUNT 128
45#define MAX_SAMPLE_PAGE_COUNT 16384
46
4240dcee
CZ
47struct DirtyRateConfig {
48 uint64_t sample_pages_per_gigabytes; /* sample pages per GB */
34a68001 49 int64_t calc_time_ms; /* desired calculation time (in milliseconds) */
71864ead 50 DirtyRateMeasureMode mode; /* mode of dirtyrate measurement */
4240dcee
CZ
51};
52
a2635f0a
CZ
53/*
54 * Store dirtypage info for each ramblock.
55 */
56struct RamblockDirtyInfo {
57 char idstr[RAMBLOCK_INFO_MAX_LEN]; /* idstr for each ramblock */
58 uint8_t *ramblock_addr; /* base address of ramblock we measure */
59 uint64_t ramblock_pages; /* ramblock size in TARGET_PAGE_SIZE */
60 uint64_t *sample_page_vfn; /* relative offset address for sampled page */
61 uint64_t sample_pages_count; /* count of sampled pages */
62 uint64_t sample_dirty_count; /* count of dirty pages we measure */
63 uint32_t *hash_result; /* array of hash result for sampled pages */
64};
65
71864ead
HH
66typedef struct SampleVMStat {
67 uint64_t total_dirty_samples; /* total dirty sampled page */
68 uint64_t total_sample_count; /* total sampled pages */
69 uint64_t total_block_mem_MB; /* size of total sampled pages in MB */
70} SampleVMStat;
71
c9a58d71
CZ
72/*
73 * Store calculation statistics for each measure.
74 */
75struct DirtyRateStat {
c9a58d71
CZ
76 int64_t dirty_rate; /* dirty rate in MB/s */
77 int64_t start_time; /* calculation start time in units of second */
34a68001 78 int64_t calc_time_ms; /* actual calculation time (in milliseconds) */
7afa08cd 79 uint64_t sample_pages; /* sample pages per GB */
71864ead
HH
80 union {
81 SampleVMStat page_sampling;
82 VcpuStat dirty_ring;
83 };
c9a58d71
CZ
84};
85
4240dcee
CZ
86void *get_dirtyrate_thread(void *arg);
87#endif