Skip to content

Commit af2d85d

Browse files
committed
KVM: selftests: Precisely track number of dirty/clear pages for each iteration
Track and print the number of dirty and clear pages for each iteration. This provides parity between all log modes, and will allow collecting the dirty ring multiple times per iteration without spamming the console. Opportunistically drop the "Dirtied N pages" print, which is redundant and wrong. For the dirty ring testcase, the vCPU isn't guaranteed to complete a loop. And when the vCPU does complete a loot, there are no guarantees that it has *dirtied* that many pages; because the writes are to random address, the vCPU may have written the same page over and over, i.e. only dirtied one page. While the number of writes performed by the vCPU is also interesting, e.g. the pr_info() could be tweaked to use different verbiage, pages_count doesn't correctly track the number of writes either (because loops aren't guaranteed to a complete). Delete the print for now, as a future patch will precisely track the number of writes, at which point the verification phase can report the number of writes performed by each iteration. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 1230907 commit af2d85d

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

tools/testing/selftests/kvm/dirty_log_test.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,6 @@ static void dirty_ring_collect_dirty_pages(struct kvm_vcpu *vcpu, int slot,
388388

389389
if (READ_ONCE(dirty_ring_vcpu_ring_full))
390390
dirty_ring_continue_vcpu();
391-
392-
pr_info("Iteration %ld collected %u pages\n", iteration, count);
393391
}
394392

395393
static void dirty_ring_after_vcpu_run(struct kvm_vcpu *vcpu)
@@ -508,24 +506,20 @@ static void log_mode_after_vcpu_run(struct kvm_vcpu *vcpu)
508506
static void *vcpu_worker(void *data)
509507
{
510508
struct kvm_vcpu *vcpu = data;
511-
uint64_t pages_count = 0;
512509

513510
while (!READ_ONCE(host_quit)) {
514-
pages_count += TEST_PAGES_PER_LOOP;
515511
/* Let the guest dirty the random pages */
516512
vcpu_run(vcpu);
517513
log_mode_after_vcpu_run(vcpu);
518514
}
519515

520-
pr_info("Dirtied %"PRIu64" pages\n", pages_count);
521-
522516
return NULL;
523517
}
524518

525519
static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap)
526520
{
521+
uint64_t page, nr_dirty_pages = 0, nr_clean_pages = 0;
527522
uint64_t step = vm_num_host_pages(mode, 1);
528-
uint64_t page;
529523
uint64_t *value_ptr;
530524
uint64_t min_iter = 0;
531525

@@ -544,7 +538,7 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap)
544538
if (__test_and_clear_bit_le(page, bmap)) {
545539
bool matched;
546540

547-
host_dirty_count++;
541+
nr_dirty_pages++;
548542

549543
/*
550544
* If the bit is set, the value written onto
@@ -605,7 +599,7 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap)
605599
" incorrect (iteration=%"PRIu64")",
606600
page, *value_ptr, iteration);
607601
} else {
608-
host_clear_count++;
602+
nr_clean_pages++;
609603
/*
610604
* If cleared, the value written can be any
611605
* value smaller or equals to the iteration
@@ -639,6 +633,12 @@ static void vm_dirty_log_verify(enum vm_guest_mode mode, unsigned long *bmap)
639633
}
640634
}
641635
}
636+
637+
pr_info("Iteration %2ld: dirty: %-6lu clean: %-6lu\n",
638+
iteration, nr_dirty_pages, nr_clean_pages);
639+
640+
host_dirty_count += nr_dirty_pages;
641+
host_clear_count += nr_clean_pages;
642642
}
643643

644644
static struct kvm_vm *create_vm(enum vm_guest_mode mode, struct kvm_vcpu **vcpu,

0 commit comments

Comments
 (0)