Skip to content

Commit 7786ae4

Browse files
Hyman Huang(黄勇)Juan Quintela
authored andcommitted
KVM: introduce dirty_pages and kvm_dirty_ring_enabled
dirty_pages is used to calculate dirtyrate via dirty ring, when enabled, kvm-reaper will increase the dirty pages after gfns being dirtied. kvm_dirty_ring_enabled shows if kvm-reaper is working. dirtyrate thread could use it to check if measurement can base on dirty ring feature. Signed-off-by: Hyman Huang(黄勇) <[email protected]> Message-Id: <fee5fb2ab17ec2159405fc54a3cff8e02322f816.1624040308.git.huangy81@chinatelecom.cn> Reviewed-by: Peter Xu <[email protected]> Reviewed-by: Juan Quintela <[email protected]> Signed-off-by: Juan Quintela <[email protected]>
1 parent b390afd commit 7786ae4

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

accel/kvm/kvm-all.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ int kvm_init_vcpu(CPUState *cpu, Error **errp)
469469
cpu->kvm_fd = ret;
470470
cpu->kvm_state = s;
471471
cpu->vcpu_dirty = true;
472+
cpu->dirty_pages = 0;
472473

473474
mmap_size = kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0);
474475
if (mmap_size < 0) {
@@ -743,6 +744,7 @@ static uint32_t kvm_dirty_ring_reap_one(KVMState *s, CPUState *cpu)
743744
count++;
744745
}
745746
cpu->kvm_fetch_index = fetch;
747+
cpu->dirty_pages += count;
746748

747749
return count;
748750
}
@@ -2296,6 +2298,11 @@ bool kvm_vcpu_id_is_valid(int vcpu_id)
22962298
return vcpu_id >= 0 && vcpu_id < kvm_max_vcpu_id(s);
22972299
}
22982300

2301+
bool kvm_dirty_ring_enabled(void)
2302+
{
2303+
return kvm_state->kvm_dirty_ring_size ? true : false;
2304+
}
2305+
22992306
static int kvm_init(MachineState *ms)
23002307
{
23012308
MachineClass *mc = MACHINE_GET_CLASS(ms);

accel/stubs/kvm-stub.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,9 @@ bool kvm_arm_supports_user_irq(void)
147147
{
148148
return false;
149149
}
150+
151+
bool kvm_dirty_ring_enabled(void)
152+
{
153+
return false;
154+
}
150155
#endif

include/hw/core/cpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ struct CPUState {
381381
struct kvm_run *kvm_run;
382382
struct kvm_dirty_gfn *kvm_dirty_gfns;
383383
uint32_t kvm_fetch_index;
384+
uint64_t dirty_pages;
384385

385386
/* Used for events with 'vcpu' and *without* the 'disabled' properties */
386387
DECLARE_BITMAP(trace_dstate_delayed, CPU_TRACE_DSTATE_MAX_EVENTS);

include/sysemu/kvm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,4 +547,5 @@ bool kvm_cpu_check_are_resettable(void);
547547

548548
bool kvm_arch_cpu_check_are_resettable(void);
549549

550+
bool kvm_dirty_ring_enabled(void);
550551
#endif

0 commit comments

Comments
 (0)