qemu/migration/dirtyrate.h
<<
>>
Prefs
   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
  16/*
  17 * Sample 512 pages per GB as default.
  18 */
  19#define DIRTYRATE_DEFAULT_SAMPLE_PAGES            512
  20
  21/*
  22 * Record ramblock idstr
  23 */
  24#define RAMBLOCK_INFO_MAX_LEN                     256
  25
  26/*
  27 * Minimum RAMBlock size to sample, in megabytes.
  28 */
  29#define MIN_RAMBLOCK_SIZE                         128
  30
  31/*
  32 * Take 1s as minimum time for calculation duration
  33 */
  34#define MIN_FETCH_DIRTYRATE_TIME_SEC              1
  35#define MAX_FETCH_DIRTYRATE_TIME_SEC              60
  36
  37/*
  38 * Take 1/16 pages in 1G as the maxmum sample page count
  39 */
  40#define MIN_SAMPLE_PAGE_COUNT                     128
  41#define MAX_SAMPLE_PAGE_COUNT                     16384
  42
  43struct DirtyRateConfig {
  44    uint64_t sample_pages_per_gigabytes; /* sample pages per GB */
  45    int64_t sample_period_seconds; /* time duration between two sampling */
  46    DirtyRateMeasureMode mode; /* mode of dirtyrate measurement */
  47};
  48
  49/*
  50 * Store dirtypage info for each ramblock.
  51 */
  52struct RamblockDirtyInfo {
  53    char idstr[RAMBLOCK_INFO_MAX_LEN]; /* idstr for each ramblock */
  54    uint8_t *ramblock_addr; /* base address of ramblock we measure */
  55    uint64_t ramblock_pages; /* ramblock size in TARGET_PAGE_SIZE */
  56    uint64_t *sample_page_vfn; /* relative offset address for sampled page */
  57    uint64_t sample_pages_count; /* count of sampled pages */
  58    uint64_t sample_dirty_count; /* count of dirty pages we measure */
  59    uint32_t *hash_result; /* array of hash result for sampled pages */
  60};
  61
  62typedef struct SampleVMStat {
  63    uint64_t total_dirty_samples; /* total dirty sampled page */
  64    uint64_t total_sample_count; /* total sampled pages */
  65    uint64_t total_block_mem_MB; /* size of total sampled pages in MB */
  66} SampleVMStat;
  67
  68typedef struct VcpuStat {
  69    int nvcpu; /* number of vcpu */
  70    DirtyRateVcpu *rates; /* array of dirty rate for each vcpu */
  71} VcpuStat;
  72
  73/*
  74 * Store calculation statistics for each measure.
  75 */
  76struct DirtyRateStat {
  77    int64_t dirty_rate; /* dirty rate in MB/s */
  78    int64_t start_time; /* calculation start time in units of second */
  79    int64_t calc_time; /* time duration of two sampling in units of second */
  80    uint64_t sample_pages; /* sample pages per GB */
  81    union {
  82        SampleVMStat page_sampling;
  83        VcpuStat dirty_ring;
  84    };
  85};
  86
  87void *get_dirtyrate_thread(void *arg);
  88#endif
  89