tools/testing/selftests/kvm/x86/dirty_log_page_splitting_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/x86/dirty_log_page_splitting_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/x86/dirty_log_page_splitting_test.c- Extension
.c- Size
- 7426 bytes
- Lines
- 264
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hstdlib.hpthread.hlinux/bitmap.hkvm_util.htest_util.hmemstress.hguest_modes.hucall_common.h
Detected Declarations
struct kvm_page_statsfunction get_page_statsfunction run_vcpu_iterationfunction vcpu_workerfunction run_testfunction helpfunction main
Annotated Snippet
struct kvm_page_stats {
u64 pages_4k;
u64 pages_2m;
u64 pages_1g;
u64 hugepages;
};
static void get_page_stats(struct kvm_vm *vm, struct kvm_page_stats *stats, const char *stage)
{
stats->pages_4k = vm_get_stat(vm, pages_4k);
stats->pages_2m = vm_get_stat(vm, pages_2m);
stats->pages_1g = vm_get_stat(vm, pages_1g);
stats->hugepages = stats->pages_2m + stats->pages_1g;
pr_debug("\nPage stats after %s: 4K: %ld 2M: %ld 1G: %ld huge: %ld\n",
stage, stats->pages_4k, stats->pages_2m, stats->pages_1g,
stats->hugepages);
}
static void run_vcpu_iteration(struct kvm_vm *vm)
{
int i;
iteration++;
for (i = 0; i < VCPUS; i++) {
while (READ_ONCE(vcpu_last_completed_iteration[i]) !=
iteration)
;
}
}
static void vcpu_worker(struct memstress_vcpu_args *vcpu_args)
{
struct kvm_vcpu *vcpu = vcpu_args->vcpu;
int vcpu_idx = vcpu_args->vcpu_idx;
while (!READ_ONCE(host_quit)) {
int current_iteration = READ_ONCE(iteration);
vcpu_run(vcpu);
TEST_ASSERT_EQ(get_ucall(vcpu, NULL), UCALL_SYNC);
vcpu_last_completed_iteration[vcpu_idx] = current_iteration;
/* Wait for the start of the next iteration to be signaled. */
while (current_iteration == READ_ONCE(iteration) &&
READ_ONCE(iteration) >= 0 &&
!READ_ONCE(host_quit))
;
}
}
static void run_test(enum vm_guest_mode mode, void *unused)
{
struct kvm_vm *vm;
unsigned long **bitmaps;
u64 guest_num_pages;
u64 host_num_pages;
u64 pages_per_slot;
int i;
struct kvm_page_stats stats_populated;
struct kvm_page_stats stats_dirty_logging_enabled;
struct kvm_page_stats stats_dirty_pass[ITERATIONS];
struct kvm_page_stats stats_clear_pass[ITERATIONS];
struct kvm_page_stats stats_dirty_logging_disabled;
struct kvm_page_stats stats_repopulated;
vm = memstress_create_vm(mode, VCPUS, guest_percpu_mem_size,
SLOTS, backing_src, false);
guest_num_pages = (VCPUS * guest_percpu_mem_size) >> vm->page_shift;
guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages);
host_num_pages = vm_num_host_pages(mode, guest_num_pages);
pages_per_slot = host_num_pages / SLOTS;
TEST_ASSERT_EQ(host_num_pages, pages_per_slot * SLOTS);
TEST_ASSERT(!(host_num_pages % 512),
"Number of pages, '%lu' not a multiple of 2MiB", host_num_pages);
bitmaps = memstress_alloc_bitmaps(SLOTS, pages_per_slot);
if (dirty_log_manual_caps)
vm_enable_cap(vm, KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2,
dirty_log_manual_caps);
/* Start the iterations */
iteration = -1;
host_quit = false;
for (i = 0; i < VCPUS; i++)
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `pthread.h`, `linux/bitmap.h`, `kvm_util.h`, `test_util.h`, `memstress.h`, `guest_modes.h`.
- Detected declarations: `struct kvm_page_stats`, `function get_page_stats`, `function run_vcpu_iteration`, `function vcpu_worker`, `function run_test`, `function help`, `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.