|
24 | 24 | #include "guest_modes.h"
|
25 | 25 | #include "processor.h"
|
26 | 26 |
|
| 27 | +#define DIRTY_MEM_BITS 30 /* 1G */ |
| 28 | +#define PAGE_SHIFT_4K 12 |
| 29 | + |
27 | 30 | /* The memory slot index to track dirty pages */
|
28 | 31 | #define TEST_MEM_SLOT_INDEX 1
|
29 | 32 |
|
@@ -273,6 +276,24 @@ static bool dirty_ring_supported(void)
|
273 | 276 |
|
274 | 277 | static void dirty_ring_create_vm_done(struct kvm_vm *vm)
|
275 | 278 | {
|
| 279 | + uint64_t pages; |
| 280 | + uint32_t limit; |
| 281 | + |
| 282 | + /* |
| 283 | + * We rely on vcpu exit due to full dirty ring state. Adjust |
| 284 | + * the ring buffer size to ensure we're able to reach the |
| 285 | + * full dirty ring state. |
| 286 | + */ |
| 287 | + pages = (1ul << (DIRTY_MEM_BITS - vm->page_shift)) + 3; |
| 288 | + pages = vm_adjust_num_guest_pages(vm->mode, pages); |
| 289 | + if (vm->page_size < getpagesize()) |
| 290 | + pages = vm_num_host_pages(vm->mode, pages); |
| 291 | + |
| 292 | + limit = 1 << (31 - __builtin_clz(pages)); |
| 293 | + test_dirty_ring_count = 1 << (31 - __builtin_clz(test_dirty_ring_count)); |
| 294 | + test_dirty_ring_count = min(limit, test_dirty_ring_count); |
| 295 | + pr_info("dirty ring count: 0x%x\n", test_dirty_ring_count); |
| 296 | + |
276 | 297 | /*
|
277 | 298 | * Switch to dirty ring mode after VM creation but before any
|
278 | 299 | * of the vcpu creation.
|
@@ -685,9 +706,6 @@ static struct kvm_vm *create_vm(enum vm_guest_mode mode, struct kvm_vcpu **vcpu,
|
685 | 706 | return vm;
|
686 | 707 | }
|
687 | 708 |
|
688 |
| -#define DIRTY_MEM_BITS 30 /* 1G */ |
689 |
| -#define PAGE_SHIFT_4K 12 |
690 |
| - |
691 | 709 | struct test_params {
|
692 | 710 | unsigned long iterations;
|
693 | 711 | unsigned long interval;
|
@@ -830,7 +848,7 @@ static void help(char *name)
|
830 | 848 | printf("usage: %s [-h] [-i iterations] [-I interval] "
|
831 | 849 | "[-p offset] [-m mode]\n", name);
|
832 | 850 | puts("");
|
833 |
| - printf(" -c: specify dirty ring size, in number of entries\n"); |
| 851 | + printf(" -c: hint to dirty ring size, in number of entries\n"); |
834 | 852 | printf(" (only useful for dirty-ring test; default: %"PRIu32")\n",
|
835 | 853 | TEST_DIRTY_RING_COUNT);
|
836 | 854 | printf(" -i: specify iteration counts (default: %"PRIu64")\n",
|
|
0 commit comments