]> git.proxmox.com Git - mirror_qemu.git/blame - migration/dirtyrate.h
docs: Convert u2f.txt to rST
[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
CZ
33/*
34 * Take 1s as minimum time for calculation duration
35 */
36#define MIN_FETCH_DIRTYRATE_TIME_SEC 1
37#define MAX_FETCH_DIRTYRATE_TIME_SEC 60
38
7afa08cd
HH
39/*
40 * Take 1/16 pages in 1G as the maxmum sample page count
41 */
42#define MIN_SAMPLE_PAGE_COUNT 128
43#define MAX_SAMPLE_PAGE_COUNT 16384
44
4240dcee
CZ
45struct DirtyRateConfig {
46 uint64_t sample_pages_per_gigabytes; /* sample pages per GB */
47 int64_t sample_period_seconds; /* time duration between two sampling */
71864ead 48 DirtyRateMeasureMode mode; /* mode of dirtyrate measurement */
4240dcee
CZ
49};
50
a2635f0a
CZ
51/*
52 * Store dirtypage info for each ramblock.
53 */
54struct RamblockDirtyInfo {
55 char idstr[RAMBLOCK_INFO_MAX_LEN]; /* idstr for each ramblock */
56 uint8_t *ramblock_addr; /* base address of ramblock we measure */
57 uint64_t ramblock_pages; /* ramblock size in TARGET_PAGE_SIZE */
58 uint64_t *sample_page_vfn; /* relative offset address for sampled page */
59 uint64_t sample_pages_count; /* count of sampled pages */
60 uint64_t sample_dirty_count; /* count of dirty pages we measure */
61 uint32_t *hash_result; /* array of hash result for sampled pages */
62};
63
71864ead
HH
64typedef struct SampleVMStat {
65 uint64_t total_dirty_samples; /* total dirty sampled page */
66 uint64_t total_sample_count; /* total sampled pages */
67 uint64_t total_block_mem_MB; /* size of total sampled pages in MB */
68} SampleVMStat;
69
c9a58d71
CZ
70/*
71 * Store calculation statistics for each measure.
72 */
73struct DirtyRateStat {
c9a58d71
CZ
74 int64_t dirty_rate; /* dirty rate in MB/s */
75 int64_t start_time; /* calculation start time in units of second */
76 int64_t calc_time; /* time duration of two sampling in units of second */
7afa08cd 77 uint64_t sample_pages; /* sample pages per GB */
71864ead
HH
78 union {
79 SampleVMStat page_sampling;
80 VcpuStat dirty_ring;
81 };
c9a58d71
CZ
82};
83
4240dcee
CZ
84void *get_dirtyrate_thread(void *arg);
85#endif