tools/testing/selftests/kvm/riscv/sbi_pmu_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/riscv/sbi_pmu_test.c- Extension
.c- Size
- 22289 bytes
- Lines
- 750
- 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.hstring.hunistd.hsys/types.hkvm_util.htest_util.hprocessor.hsbi.harch_timer.hucall_common.h
Detected Declarations
struct test_argsfunction pmu_csr_read_numfunction dummy_func_loopfunction start_counterfunction stop_reset_counterfunction stop_counterfunction guest_illegal_exception_handlerfunction guest_irq_handlerfunction get_counter_indexfunction get_num_countersfunction update_counter_infofunction read_fw_counterfunction read_counterfunction verify_sbi_requirement_assertfunction snapshot_set_shmemfunction test_pmu_eventfunction test_pmu_event_snapshotfunction test_pmu_event_overflowfunction test_invalid_eventfunction test_pmu_eventsfunction test_pmu_basic_sanityfunction test_pmu_events_snaphostfunction test_pmu_events_overflowfunction run_vcpufunction test_vm_destroyfunction test_vm_basic_testfunction test_vm_events_testfunction test_vm_setup_snapshot_memfunction test_vm_events_snapshot_testfunction test_vm_events_overflowfunction test_print_helpfunction parse_argsfunction main
Annotated Snippet
struct test_args {
int disabled_tests;
int overflow_irqnum;
};
static struct test_args targs;
unsigned long pmu_csr_read_num(int csr_num)
{
#define switchcase_csr_read(__csr_num, __val) {\
case __csr_num: \
__val = csr_read(__csr_num); \
break; }
#define switchcase_csr_read_2(__csr_num, __val) {\
switchcase_csr_read(__csr_num + 0, __val) \
switchcase_csr_read(__csr_num + 1, __val)}
#define switchcase_csr_read_4(__csr_num, __val) {\
switchcase_csr_read_2(__csr_num + 0, __val) \
switchcase_csr_read_2(__csr_num + 2, __val)}
#define switchcase_csr_read_8(__csr_num, __val) {\
switchcase_csr_read_4(__csr_num + 0, __val) \
switchcase_csr_read_4(__csr_num + 4, __val)}
#define switchcase_csr_read_16(__csr_num, __val) {\
switchcase_csr_read_8(__csr_num + 0, __val) \
switchcase_csr_read_8(__csr_num + 8, __val)}
#define switchcase_csr_read_32(__csr_num, __val) {\
switchcase_csr_read_16(__csr_num + 0, __val) \
switchcase_csr_read_16(__csr_num + 16, __val)}
unsigned long ret = 0;
switch (csr_num) {
switchcase_csr_read_32(CSR_CYCLE, ret)
default :
break;
}
return ret;
#undef switchcase_csr_read_32
#undef switchcase_csr_read_16
#undef switchcase_csr_read_8
#undef switchcase_csr_read_4
#undef switchcase_csr_read_2
#undef switchcase_csr_read
}
static inline void dummy_func_loop(u64 iter)
{
int i = 0;
while (i < iter) {
asm volatile("nop");
i++;
}
}
static void start_counter(unsigned long counter, unsigned long start_flags,
unsigned long ival)
{
struct sbiret ret;
ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_START, counter, 1, start_flags,
ival, 0, 0);
__GUEST_ASSERT(ret.error == 0, "Unable to start counter %ld\n", counter);
}
/* This should be invoked only for reset counter use case */
static void stop_reset_counter(unsigned long counter, unsigned long stop_flags)
{
struct sbiret ret;
ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_STOP, counter, 1,
stop_flags | SBI_PMU_STOP_FLAG_RESET, 0, 0, 0);
__GUEST_ASSERT(ret.error == SBI_ERR_ALREADY_STOPPED,
"Unable to stop counter %ld\n", counter);
}
static void stop_counter(unsigned long counter, unsigned long stop_flags)
{
struct sbiret ret;
ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_STOP, counter, 1, stop_flags,
0, 0, 0);
__GUEST_ASSERT(ret.error == 0 || ret.error == SBI_ERR_ALREADY_STOPPED,
"Unable to stop counter %ld error %ld\n", counter, ret.error);
}
static void guest_illegal_exception_handler(struct pt_regs *regs)
{
unsigned long insn;
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `string.h`, `unistd.h`, `sys/types.h`, `kvm_util.h`, `test_util.h`, `processor.h`.
- Detected declarations: `struct test_args`, `function pmu_csr_read_num`, `function dummy_func_loop`, `function start_counter`, `function stop_reset_counter`, `function stop_counter`, `function guest_illegal_exception_handler`, `function guest_irq_handler`, `function get_counter_index`, `function get_num_counters`.
- 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.