tools/testing/selftests/kvm/access_tracking_perf_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/access_tracking_perf_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/access_tracking_perf_test.c- Extension
.c- Size
- 18055 bytes
- Lines
- 610
- 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
inttypes.hlimits.hpthread.hsys/types.hsys/stat.hkvm_syscalls.hkvm_util.htest_util.hmemstress.hguest_modes.hprocessor.hucall_common.hcgroup_util.hlru_gen_util.h
Detected Declarations
struct test_paramsenum access_typefunction pread_u64function lookup_pfnfunction is_page_idlefunction mark_page_idlefunction too_many_idle_pagesfunction pageidle_mark_vcpu_memory_idlefunction find_generationfunction lru_gen_mark_memory_idlefunction assert_ucallfunction spin_wait_for_next_iterationfunction vcpu_thread_mainfunction spin_wait_for_vcpufunction run_iterationfunction access_memoryfunction mark_memory_idlefunction run_testfunction access_tracking_unreliablefunction run_test_for_each_guest_modefunction helpfunction destroy_cgroupfunction main
Annotated Snippet
struct test_params {
/* The backing source for the region of memory. */
enum vm_mem_backing_src_type backing_src;
/* The amount of memory to allocate for each vCPU. */
u64 vcpu_memory_bytes;
/* The number of vCPUs to create in the VM. */
int nr_vcpus;
};
static u64 pread_u64(int fd, const char *filename, u64 index)
{
u64 value;
off_t offset = index * sizeof(value);
TEST_ASSERT(pread(fd, &value, sizeof(value), offset) == sizeof(value),
"pread from %s offset 0x%" PRIx64 " failed!",
filename, offset);
return value;
}
#define PAGEMAP_PRESENT (1ULL << 63)
#define PAGEMAP_PFN_MASK ((1ULL << 55) - 1)
static u64 lookup_pfn(int pagemap_fd, struct kvm_vm *vm, gva_t gva)
{
u64 hva = (u64)addr_gva2hva(vm, gva);
u64 entry;
u64 pfn;
entry = pread_u64(pagemap_fd, "pagemap", hva / getpagesize());
if (!(entry & PAGEMAP_PRESENT))
return 0;
pfn = entry & PAGEMAP_PFN_MASK;
__TEST_REQUIRE(pfn, "Looking up PFNs requires CAP_SYS_ADMIN");
return pfn;
}
static bool is_page_idle(int page_idle_fd, u64 pfn)
{
u64 bits = pread_u64(page_idle_fd, "page_idle", pfn / 64);
return !!((bits >> (pfn % 64)) & 1);
}
static void mark_page_idle(int page_idle_fd, u64 pfn)
{
u64 bits = 1ULL << (pfn % 64);
TEST_ASSERT(pwrite(page_idle_fd, &bits, 8, 8 * (pfn / 64)) == 8,
"Set page_idle bits for PFN 0x%" PRIx64, pfn);
}
static void too_many_idle_pages(long idle_pages, long total_pages, int vcpu_idx)
{
char prefix[18] = {};
if (vcpu_idx >= 0)
snprintf(prefix, 18, "vCPU%d: ", vcpu_idx);
TEST_ASSERT(idle_pages_warn_only,
"%sToo many pages still idle (%lu out of %lu)",
prefix, idle_pages, total_pages);
printf("WARNING: %sToo many pages still idle (%lu out of %lu), "
"this will affect performance results.\n",
prefix, idle_pages, total_pages);
}
static void pageidle_mark_vcpu_memory_idle(struct kvm_vm *vm,
struct memstress_vcpu_args *vcpu_args)
{
int vcpu_idx = vcpu_args->vcpu_idx;
gva_t base_gva = vcpu_args->gva;
u64 pages = vcpu_args->pages;
u64 page;
u64 still_idle = 0;
u64 no_pfn = 0;
int page_idle_fd;
int pagemap_fd;
/* If vCPUs are using an overlapping region, let vCPU 0 mark it idle. */
if (overlap_memory_access && vcpu_idx)
return;
Annotation
- Immediate include surface: `inttypes.h`, `limits.h`, `pthread.h`, `sys/types.h`, `sys/stat.h`, `kvm_syscalls.h`, `kvm_util.h`, `test_util.h`.
- Detected declarations: `struct test_params`, `enum access_type`, `function pread_u64`, `function lookup_pfn`, `function is_page_idle`, `function mark_page_idle`, `function too_many_idle_pages`, `function pageidle_mark_vcpu_memory_idle`, `function find_generation`, `function lru_gen_mark_memory_idle`.
- 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.