migration/dirtyrate: introduce struct and adjust DirtyRateStat

introduce "DirtyRateMeasureMode" to specify what method should be
used to calculate dirty rate, introduce "DirtyRateVcpu" to store
dirty rate for each vcpu.

use union to store stat data of specific mode

Signed-off-by: Hyman Huang(黄勇) <huangy81@chinatelecom.cn>
Message-Id: <661c98c40f40e163aa58334337af8f3ddf41316a.1624040308.git.huangy81@chinatelecom.cn>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
This commit is contained in:
Hyman Huang(黄勇) 2021-06-29 16:01:20 +00:00 committed by Juan Quintela
parent 63b41db4bc
commit 71864eadd9
3 changed files with 74 additions and 23 deletions

View File

@ -88,33 +88,44 @@ static struct DirtyRateInfo *query_dirty_rate_info(void)
return info;
}
static void init_dirtyrate_stat(int64_t start_time, int64_t calc_time,
uint64_t sample_pages)
static void init_dirtyrate_stat(int64_t start_time,
struct DirtyRateConfig config)
{
DirtyStat.total_dirty_samples = 0;
DirtyStat.total_sample_count = 0;
DirtyStat.total_block_mem_MB = 0;
DirtyStat.dirty_rate = -1;
DirtyStat.start_time = start_time;
DirtyStat.calc_time = calc_time;
DirtyStat.sample_pages = sample_pages;
DirtyStat.calc_time = config.sample_period_seconds;
DirtyStat.sample_pages = config.sample_pages_per_gigabytes;
switch (config.mode) {
case DIRTY_RATE_MEASURE_MODE_PAGE_SAMPLING:
DirtyStat.page_sampling.total_dirty_samples = 0;
DirtyStat.page_sampling.total_sample_count = 0;
DirtyStat.page_sampling.total_block_mem_MB = 0;
break;
case DIRTY_RATE_MEASURE_MODE_DIRTY_RING:
DirtyStat.dirty_ring.nvcpu = -1;
DirtyStat.dirty_ring.rates = NULL;
break;
default:
break;
}
}
static void update_dirtyrate_stat(struct RamblockDirtyInfo *info)
{
DirtyStat.total_dirty_samples += info->sample_dirty_count;
DirtyStat.total_sample_count += info->sample_pages_count;
DirtyStat.page_sampling.total_dirty_samples += info->sample_dirty_count;
DirtyStat.page_sampling.total_sample_count += info->sample_pages_count;
/* size of total pages in MB */
DirtyStat.total_block_mem_MB += (info->ramblock_pages *
TARGET_PAGE_SIZE) >> 20;
DirtyStat.page_sampling.total_block_mem_MB += (info->ramblock_pages *
TARGET_PAGE_SIZE) >> 20;
}
static void update_dirtyrate(uint64_t msec)
{
uint64_t dirtyrate;
uint64_t total_dirty_samples = DirtyStat.total_dirty_samples;
uint64_t total_sample_count = DirtyStat.total_sample_count;
uint64_t total_block_mem_MB = DirtyStat.total_block_mem_MB;
uint64_t total_dirty_samples = DirtyStat.page_sampling.total_dirty_samples;
uint64_t total_sample_count = DirtyStat.page_sampling.total_sample_count;
uint64_t total_block_mem_MB = DirtyStat.page_sampling.total_block_mem_MB;
dirtyrate = total_dirty_samples * total_block_mem_MB *
1000 / (total_sample_count * msec);
@ -327,7 +338,7 @@ static bool compare_page_hash_info(struct RamblockDirtyInfo *info,
update_dirtyrate_stat(block_dinfo);
}
if (DirtyStat.total_sample_count == 0) {
if (DirtyStat.page_sampling.total_sample_count == 0) {
return false;
}
@ -372,8 +383,6 @@ void *get_dirtyrate_thread(void *arg)
struct DirtyRateConfig config = *(struct DirtyRateConfig *)arg;
int ret;
int64_t start_time;
int64_t calc_time;
uint64_t sample_pages;
ret = dirtyrate_set_state(&CalculatingState, DIRTY_RATE_STATUS_UNSTARTED,
DIRTY_RATE_STATUS_MEASURING);
@ -383,9 +392,7 @@ void *get_dirtyrate_thread(void *arg)
}
start_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME) / 1000;
calc_time = config.sample_period_seconds;
sample_pages = config.sample_pages_per_gigabytes;
init_dirtyrate_stat(start_time, calc_time, sample_pages);
init_dirtyrate_stat(start_time, config);
calculate_dirtyrate(config);
@ -442,6 +449,7 @@ void qmp_calc_dirty_rate(int64_t calc_time, bool has_sample_pages,
config.sample_period_seconds = calc_time;
config.sample_pages_per_gigabytes = sample_pages;
config.mode = DIRTY_RATE_MEASURE_MODE_PAGE_SAMPLING;
qemu_thread_create(&thread, "get_dirtyrate", get_dirtyrate_thread,
(void *)&config, QEMU_THREAD_DETACHED);
}

View File

@ -43,6 +43,7 @@
struct DirtyRateConfig {
uint64_t sample_pages_per_gigabytes; /* sample pages per GB */
int64_t sample_period_seconds; /* time duration between two sampling */
DirtyRateMeasureMode mode; /* mode of dirtyrate measurement */
};
/*
@ -58,17 +59,29 @@ struct RamblockDirtyInfo {
uint32_t *hash_result; /* array of hash result for sampled pages */
};
typedef struct SampleVMStat {
uint64_t total_dirty_samples; /* total dirty sampled page */
uint64_t total_sample_count; /* total sampled pages */
uint64_t total_block_mem_MB; /* size of total sampled pages in MB */
} SampleVMStat;
typedef struct VcpuStat {
int nvcpu; /* number of vcpu */
DirtyRateVcpu *rates; /* array of dirty rate for each vcpu */
} VcpuStat;
/*
* Store calculation statistics for each measure.
*/
struct DirtyRateStat {
uint64_t total_dirty_samples; /* total dirty sampled page */
uint64_t total_sample_count; /* total sampled pages */
uint64_t total_block_mem_MB; /* size of total sampled pages in MB */
int64_t dirty_rate; /* dirty rate in MB/s */
int64_t start_time; /* calculation start time in units of second */
int64_t calc_time; /* time duration of two sampling in units of second */
uint64_t sample_pages; /* sample pages per GB */
union {
SampleVMStat page_sampling;
VcpuStat dirty_ring;
};
};
void *get_dirtyrate_thread(void *arg);

View File

@ -1731,6 +1731,21 @@
{ 'event': 'UNPLUG_PRIMARY',
'data': { 'device-id': 'str' } }
##
# @DirtyRateVcpu:
#
# Dirty rate of vcpu.
#
# @id: vcpu index.
#
# @dirty-rate: dirty rate.
#
# Since: 6.1
#
##
{ 'struct': 'DirtyRateVcpu',
'data': { 'id': 'int', 'dirty-rate': 'int64' } }
##
# @DirtyRateStatus:
#
@ -1748,6 +1763,21 @@
{ 'enum': 'DirtyRateStatus',
'data': [ 'unstarted', 'measuring', 'measured'] }
##
# @DirtyRateMeasureMode:
#
# An enumeration of mode of measuring dirtyrate.
#
# @page-sampling: calculate dirtyrate by sampling pages.
#
# @dirty-ring: calculate dirtyrate by via dirty ring.
#
# Since: 6.1
#
##
{ 'enum': 'DirtyRateMeasureMode',
'data': ['page-sampling', 'dirty-ring'] }
##
# @DirtyRateInfo:
#