Skip to content

Commit

Permalink
accel/kvm/kvm-all: Refactor per-vcpu dirty ring reaping
Browse files Browse the repository at this point in the history
Add a non-required argument 'CPUState' to kvm_dirty_ring_reap so
that it can cover single vcpu dirty-ring-reaping scenario.

Signed-off-by: Hyman Huang(黄勇) <[email protected]>
Reviewed-by: Peter Xu <[email protected]>
Message-Id: <c32001242875e83b0d9f78f396fe2dcd380ba9e8.1656177590.git.huangy81@chinatelecom.cn>
Signed-off-by: Dr. David Alan Gilbert <[email protected]>
  • Loading branch information
Hyman Huang(黄勇) authored and dagrh committed Jul 20, 2022
1 parent 68e26e1 commit 1667e2b
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions accel/kvm/kvm-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,17 +757,20 @@ static uint32_t kvm_dirty_ring_reap_one(KVMState *s, CPUState *cpu)
}

/* Must be with slots_lock held */
static uint64_t kvm_dirty_ring_reap_locked(KVMState *s)
static uint64_t kvm_dirty_ring_reap_locked(KVMState *s, CPUState* cpu)
{
int ret;
CPUState *cpu;
uint64_t total = 0;
int64_t stamp;

stamp = get_clock();

CPU_FOREACH(cpu) {
total += kvm_dirty_ring_reap_one(s, cpu);
if (cpu) {
total = kvm_dirty_ring_reap_one(s, cpu);
} else {
CPU_FOREACH(cpu) {
total += kvm_dirty_ring_reap_one(s, cpu);
}
}

if (total) {
Expand All @@ -788,7 +791,7 @@ static uint64_t kvm_dirty_ring_reap_locked(KVMState *s)
* Currently for simplicity, we must hold BQL before calling this. We can
* consider to drop the BQL if we're clear with all the race conditions.
*/
static uint64_t kvm_dirty_ring_reap(KVMState *s)
static uint64_t kvm_dirty_ring_reap(KVMState *s, CPUState *cpu)
{
uint64_t total;

Expand All @@ -808,7 +811,7 @@ static uint64_t kvm_dirty_ring_reap(KVMState *s)
* reset below.
*/
kvm_slots_lock();
total = kvm_dirty_ring_reap_locked(s);
total = kvm_dirty_ring_reap_locked(s, cpu);
kvm_slots_unlock();

return total;
Expand Down Expand Up @@ -855,7 +858,7 @@ static void kvm_dirty_ring_flush(void)
* vcpus out in a synchronous way.
*/
kvm_cpu_synchronize_kick_all();
kvm_dirty_ring_reap(kvm_state);
kvm_dirty_ring_reap(kvm_state, NULL);
trace_kvm_dirty_ring_flush(1);
}

Expand Down Expand Up @@ -1399,7 +1402,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml,
* Not easy. Let's cross the fingers until it's fixed.
*/
if (kvm_state->kvm_dirty_ring_size) {
kvm_dirty_ring_reap_locked(kvm_state);
kvm_dirty_ring_reap_locked(kvm_state, NULL);
} else {
kvm_slot_get_dirty_log(kvm_state, mem);
}
Expand Down Expand Up @@ -1471,7 +1474,7 @@ static void *kvm_dirty_ring_reaper_thread(void *data)
r->reaper_state = KVM_DIRTY_RING_REAPER_REAPING;

qemu_mutex_lock_iothread();
kvm_dirty_ring_reap(s);
kvm_dirty_ring_reap(s, NULL);
qemu_mutex_unlock_iothread();

r->reaper_iteration++;
Expand Down Expand Up @@ -2967,7 +2970,7 @@ int kvm_cpu_exec(CPUState *cpu)
*/
trace_kvm_dirty_ring_full(cpu->cpu_index);
qemu_mutex_lock_iothread();
kvm_dirty_ring_reap(kvm_state);
kvm_dirty_ring_reap(kvm_state, NULL);
qemu_mutex_unlock_iothread();
ret = 0;
break;
Expand Down

0 comments on commit 1667e2b

Please sign in to comment.