tools/testing/selftests/kvm/include/arm64/arch_timer.h
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/include/arm64/arch_timer.h
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/include/arm64/arch_timer.h- Extension
.h- Size
- 3562 bytes
- Lines
- 183
- 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
processor.h
Detected Declarations
enum arch_timerfunction timer_get_cntfrqfunction timer_get_cntctfunction timer_set_cvalfunction timer_get_cvalfunction timer_set_tvalfunction timer_get_tvalfunction timer_set_ctlfunction timer_get_ctlfunction timer_set_next_cval_msfunction timer_set_next_tval_msfunction vcpu_get_vtimer_irqfunction vcpu_get_ptimer_irq
Annotated Snippet
#ifndef SELFTEST_KVM_ARCH_TIMER_H
#define SELFTEST_KVM_ARCH_TIMER_H
#include "processor.h"
enum arch_timer {
VIRTUAL,
PHYSICAL,
};
#define CTL_ENABLE (1 << 0)
#define CTL_IMASK (1 << 1)
#define CTL_ISTATUS (1 << 2)
#define msec_to_cycles(msec) \
(timer_get_cntfrq() * (u64)(msec) / 1000)
#define usec_to_cycles(usec) \
(timer_get_cntfrq() * (u64)(usec) / 1000000)
#define cycles_to_usec(cycles) \
((u64)(cycles) * 1000000 / timer_get_cntfrq())
static inline u32 timer_get_cntfrq(void)
{
return read_sysreg(cntfrq_el0);
}
static inline u64 timer_get_cntct(enum arch_timer timer)
{
isb();
switch (timer) {
case VIRTUAL:
return read_sysreg(cntvct_el0);
case PHYSICAL:
return read_sysreg(cntpct_el0);
default:
GUEST_FAIL("Unexpected timer type = %u", timer);
}
/* We should not reach here */
return 0;
}
static inline void timer_set_cval(enum arch_timer timer, u64 cval)
{
switch (timer) {
case VIRTUAL:
write_sysreg(cval, cntv_cval_el0);
break;
case PHYSICAL:
write_sysreg(cval, cntp_cval_el0);
break;
default:
GUEST_FAIL("Unexpected timer type = %u", timer);
}
isb();
}
static inline u64 timer_get_cval(enum arch_timer timer)
{
switch (timer) {
case VIRTUAL:
return read_sysreg(cntv_cval_el0);
case PHYSICAL:
return read_sysreg(cntp_cval_el0);
default:
GUEST_FAIL("Unexpected timer type = %u", timer);
}
/* We should not reach here */
return 0;
}
static inline void timer_set_tval(enum arch_timer timer, s32 tval)
{
switch (timer) {
case VIRTUAL:
write_sysreg(tval, cntv_tval_el0);
break;
case PHYSICAL:
write_sysreg(tval, cntp_tval_el0);
break;
default:
GUEST_FAIL("Unexpected timer type = %u", timer);
}
isb();
Annotation
- Immediate include surface: `processor.h`.
- Detected declarations: `enum arch_timer`, `function timer_get_cntfrq`, `function timer_get_cntct`, `function timer_set_cval`, `function timer_get_cval`, `function timer_set_tval`, `function timer_get_tval`, `function timer_set_ctl`, `function timer_get_ctl`, `function timer_set_next_cval_ms`.
- 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.