include/linux/timecounter.h
Source file repositories/reference/linux-study-clean/include/linux/timecounter.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/timecounter.h- Extension
.h- Size
- 5299 bytes
- Lines
- 165
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/types.h
Detected Declarations
struct cyclecounterstruct timecounterfunction cyclecounter_cyc2nsfunction timecounter_adjtimefunction cyclecounter_cyc2nsfunction timecounter_read
Annotated Snippet
struct cyclecounter {
u64 (*read)(struct cyclecounter *cc);
u64 mask;
u32 mult;
u32 shift;
};
/**
* struct timecounter - layer above a &struct cyclecounter which counts nanoseconds
* Contains the state needed by timecounter_read() to detect
* cycle counter wrap around. Initialize with
* timecounter_init(). Also used to convert cycle counts into the
* corresponding nanosecond counts with timecounter_cyc2time(). Users
* of this code are responsible for initializing the underlying
* cycle counter hardware, locking issues and reading the time
* more often than the cycle counter wraps around. The nanosecond
* counter will only wrap around after ~585 years.
*
* @cc: the cycle counter used by this instance
* @cycle_last: most recent cycle counter value seen by
* timecounter_read()
* @nsec: continuously increasing count
* @mask: bit mask for maintaining the 'frac' field
* @frac: accumulated fractional nanoseconds
*/
struct timecounter {
struct cyclecounter *cc;
u64 cycle_last;
u64 nsec;
u64 mask;
u64 frac;
};
/**
* cyclecounter_cyc2ns - converts cycle counter cycles to nanoseconds
* @cc: Pointer to cycle counter.
* @cycles: Cycles
* @mask: bit mask for maintaining the 'frac' field
* @frac: pointer to storage for the fractional nanoseconds.
*
* Returns: cycle counter cycles converted to nanoseconds
*/
static inline u64 cyclecounter_cyc2ns(const struct cyclecounter *cc,
u64 cycles, u64 mask, u64 *frac)
{
u64 ns = (u64) cycles;
ns = (ns * cc->mult) + *frac;
*frac = ns & mask;
return ns >> cc->shift;
}
/**
* timecounter_adjtime - Shifts the time of the clock.
* @tc: The &struct timecounter to adjust
* @delta: Desired change in nanoseconds.
*/
static inline void timecounter_adjtime(struct timecounter *tc, s64 delta)
{
tc->nsec += delta;
}
/**
* timecounter_init - initialize a time counter
* @tc: Pointer to time counter which is to be initialized/reset
* @cc: A cycle counter, ready to be used.
* @start_tstamp: Arbitrary initial time stamp.
*
* After this call the current cycle register (roughly) corresponds to
* the initial time stamp. Every call to timecounter_read() increments
* the time stamp counter by the number of elapsed nanoseconds.
*/
extern void timecounter_init(struct timecounter *tc,
struct cyclecounter *cc,
u64 start_tstamp);
/**
* timecounter_read - return nanoseconds elapsed since timecounter_init()
* plus the initial time stamp
* @tc: Pointer to time counter.
*
* In other words, keeps track of time since the same epoch as
* the function which generated the initial time stamp.
*
* Returns: nanoseconds since the initial time stamp
*/
extern u64 timecounter_read(struct timecounter *tc);
/*
* This is like cyclecounter_cyc2ns(), but it is used for computing a
Annotation
- Immediate include surface: `linux/types.h`.
- Detected declarations: `struct cyclecounter`, `struct timecounter`, `function cyclecounter_cyc2ns`, `function timecounter_adjtime`, `function cyclecounter_cyc2ns`, `function timecounter_read`.
- Atlas domain: Core OS / Core Kernel Interface.
- 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.