tools/testing/selftests/kvm/include/riscv/arch_timer.h
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/include/riscv/arch_timer.h
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/include/riscv/arch_timer.h- Extension
.h- Size
- 1314 bytes
- Lines
- 72
- 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.
Dependency Surface
asm/csr.hasm/vdso/processor.h
Detected Declarations
function timer_get_cyclesfunction timer_set_cmpfunction timer_get_cmpfunction timer_irq_enablefunction timer_irq_disablefunction timer_set_next_cmp_msfunction __delayfunction udelay
Annotated Snippet
#ifndef SELFTEST_KVM_ARCH_TIMER_H
#define SELFTEST_KVM_ARCH_TIMER_H
#include <asm/csr.h>
#include <asm/vdso/processor.h>
static unsigned long timer_freq;
#define msec_to_cycles(msec) \
((timer_freq) * (u64)(msec) / 1000)
#define usec_to_cycles(usec) \
((timer_freq) * (u64)(usec) / 1000000)
#define cycles_to_usec(cycles) \
((u64)(cycles) * 1000000 / (timer_freq))
static inline u64 timer_get_cycles(void)
{
return csr_read(CSR_TIME);
}
static inline void timer_set_cmp(u64 cval)
{
csr_write(CSR_STIMECMP, cval);
}
static inline u64 timer_get_cmp(void)
{
return csr_read(CSR_STIMECMP);
}
static inline void timer_irq_enable(void)
{
csr_set(CSR_SIE, IE_TIE);
}
static inline void timer_irq_disable(void)
{
csr_clear(CSR_SIE, IE_TIE);
}
static inline void timer_set_next_cmp_ms(u32 msec)
{
u64 now_ct = timer_get_cycles();
u64 next_ct = now_ct + msec_to_cycles(msec);
timer_set_cmp(next_ct);
}
static inline void __delay(u64 cycles)
{
u64 start = timer_get_cycles();
while ((timer_get_cycles() - start) < cycles)
cpu_relax();
}
static inline void udelay(unsigned long usec)
{
__delay(usec_to_cycles(usec));
}
#endif /* SELFTEST_KVM_ARCH_TIMER_H */
Annotation
- Immediate include surface: `asm/csr.h`, `asm/vdso/processor.h`.
- Detected declarations: `function timer_get_cycles`, `function timer_set_cmp`, `function timer_get_cmp`, `function timer_irq_enable`, `function timer_irq_disable`, `function timer_set_next_cmp_ms`, `function __delay`, `function udelay`.
- 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.