On 2020/8/21 0:28, Dr. David Alan Gilbert wrote:
> * Chuan Zheng (zhengch...@huawei.com) wrote:
>> Add dirtyrate statistics to record/update dirtyrate info.
>>
>> Signed-off-by: Chuan Zheng <zhengch...@huawei.com>
>> Signed-off-by: YanYing Zhuang <ann.zhuangyany...@huawei.com>
>> ---
>> migration/dirtyrate.c | 30 ++++++++++++++++++++++++++++++
>> migration/dirtyrate.h | 10 ++++++++++
>> 2 files changed, 40 insertions(+)
>>
>> diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
>> index bb0ebe9..8708090 100644
>> --- a/migration/dirtyrate.c
>> +++ b/migration/dirtyrate.c
>> @@ -24,6 +24,7 @@
>> #include "dirtyrate.h"
>>
>> CalculatingDirtyRateState CalculatingState = CAL_DIRTY_RATE_INIT;
>> +static struct DirtyRateStat dirty_stat;
>>
>> static int dirty_rate_set_state(int new_state)
>> {
>> @@ -40,6 +41,35 @@ static int dirty_rate_set_state(int new_state)
>> return 0;
>> }
>>
>> +static void reset_dirtyrate_stat(void)
>> +{
>> + dirty_stat.total_dirty_samples = 0;
>> + dirty_stat.total_sample_count = 0;
>> + dirty_stat.total_block_mem_MB = 0;
>> + dirty_stat.dirty_rate = 0;
>> +}
>> +
>> +static void update_dirtyrate_stat(struct RamblockDirtyInfo *info)
>> +{
>> + dirty_stat.total_dirty_samples += info->sample_dirty_count;
>> + dirty_stat.total_sample_count += info->sample_pages_count;
>> + /* size of 4K pages in MB */
>> + dirty_stat.total_block_mem_MB += info->ramblock_pages / 256;
>> +}
>> +
>> +static void update_dirtyrate(uint64_t msec)
>> +{
>> + uint64_t dirty_rate;
>> + unsigned int total_dirty_samples = dirty_stat.total_dirty_samples;
>> + unsigned int total_sample_count = dirty_stat.total_sample_count;
>> + size_t total_block_mem_MB = dirty_stat.total_block_mem_MB;
>> +
>> + dirty_rate = total_dirty_samples * total_block_mem_MB *
>> + 1000 / (total_sample_count * msec);
>> +
>> + dirty_stat.dirty_rate = dirty_rate;
>> +}
>> +
>> static void calculate_dirtyrate(struct DirtyRateConfig config)
>> {
>> /* todo */
>> diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h
>> index 9650566..af57c80 100644
>> --- a/migration/dirtyrate.h
>> +++ b/migration/dirtyrate.h
>> @@ -57,6 +57,16 @@ struct RamblockDirtyInfo {
>> uint8_t *hash_result; /* array of hash result for sampled pages */
>> };
>>
>> +/*
>> + * Store calculate statistics for each measure.
>> + */
>> +struct DirtyRateStat {
>> + unsigned int total_dirty_samples; /* total dirty pages for this measure
>> */
>> + unsigned int total_sample_count; /* total sampled pages for this
>> measure */
>> + size_t total_block_mem_MB; /* size of sampled pages in MB */
>> + int64_t dirty_rate; /* dirty rate for this measure */
>
> As I said in the previous review, please comment 'dirty_rate' with it's
> units.
>
Sorry, i missed that, will be fix in V4:)
> Dave
>
>> +};
>> +
>> void *get_dirtyrate_thread(void *arg);
>> #endif
>>
>> --
>> 1.8.3.1
>>