lib/vdso/gettimeofday.c
Source file repositories/reference/linux-study-clean/lib/vdso/gettimeofday.c
File Facts
- System
- Linux kernel
- Corpus path
lib/vdso/gettimeofday.c- Extension
.c- Size
- 11520 bytes
- Lines
- 494
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: implementation source
- Status
- source implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
vdso/auxclock.hvdso/clocksource.hvdso/datapage.hvdso/helpers.hvdso/ktime.hvdso/limits.hvdso/math64.hvdso/time32.hvdso/time64.hasm/vdso/gettimeofday.hvdso/vsyscall.h
Detected Declarations
function gettimeofdayfunction vdso_delta_okfunction vdso_shift_nsfunction vdso_calc_nsfunction __arch_vdso_hres_capablefunction vdso_clocksource_okfunction vdso_cycles_okfunction vdso_clockid_validfunction __iter_div_u64_remfunction vdso_get_timestampfunction do_hres_timensfunction do_hresfunction do_coarse_timensfunction do_coarsefunction do_auxfunction __cvdso_clock_gettime_commonfunction __cvdso_clock_gettime_datafunction __cvdso_clock_gettimefunction __cvdso_clock_gettime32_datafunction __cvdso_clock_gettime32function __cvdso_gettimeofday_datafunction __cvdso_gettimeofdayfunction __cvdso_time_datafunction __cvdso_timefunction __cvdso_clock_getres_commonfunction __cvdso_clock_getres_datafunction __cvdso_clock_getresfunction __cvdso_clock_getres_time32_datafunction __cvdso_clock_getres_time32
Annotated Snippet
while (vdso_read_begin_timens(vc, &seq)) {
/* Re-read from the real time data page, reload seq by looping */
vd = vdso_timens_data(vd);
vc = &vd->aux_clock_data[idx];
}
/* Auxclock disabled? */
if (vc->clock_mode == VDSO_CLOCKMODE_NONE)
return false;
if (!vdso_get_timestamp(vd, vc, VDSO_BASE_AUX, &sec, &ns))
return false;
} while (vdso_read_retry(vc, seq));
vdso_set_timespec(ts, sec, ns);
return true;
}
static __always_inline bool
__cvdso_clock_gettime_common(const struct vdso_time_data *vd, clockid_t clock,
struct __kernel_timespec *ts)
{
const struct vdso_clock *vc = vd->clock_data;
u32 msk;
if (!vdso_clockid_valid(clock))
return false;
/*
* Convert the clockid to a bitmask and use it to check which
* clocks are handled in the VDSO directly.
*/
msk = 1U << clock;
if (likely(msk & VDSO_HRES))
vc = &vc[CS_HRES_COARSE];
else if (msk & VDSO_COARSE)
return do_coarse(vd, &vc[CS_HRES_COARSE], clock, ts);
else if (msk & VDSO_RAW)
vc = &vc[CS_RAW];
else if (msk & VDSO_AUX)
return do_aux(vd, clock, ts);
else
return false;
return do_hres(vd, vc, clock, ts);
}
static int
__cvdso_clock_gettime_data(const struct vdso_time_data *vd, clockid_t clock,
struct __kernel_timespec *ts)
{
bool ok;
ok = __cvdso_clock_gettime_common(vd, clock, ts);
if (unlikely(!ok))
return clock_gettime_fallback(clock, ts);
return 0;
}
static __maybe_unused int
__cvdso_clock_gettime(clockid_t clock, struct __kernel_timespec *ts)
{
return __cvdso_clock_gettime_data(__arch_get_vdso_u_time_data(), clock, ts);
}
#ifdef BUILD_VDSO32
static int
__cvdso_clock_gettime32_data(const struct vdso_time_data *vd, clockid_t clock,
struct old_timespec32 *res)
{
struct __kernel_timespec ts;
bool ok;
ok = __cvdso_clock_gettime_common(vd, clock, &ts);
if (unlikely(!ok))
return clock_gettime32_fallback(clock, res);
/* For ok == true */
res->tv_sec = ts.tv_sec;
res->tv_nsec = ts.tv_nsec;
return 0;
}
static __maybe_unused int
__cvdso_clock_gettime32(clockid_t clock, struct old_timespec32 *res)
{
Annotation
- Immediate include surface: `vdso/auxclock.h`, `vdso/clocksource.h`, `vdso/datapage.h`, `vdso/helpers.h`, `vdso/ktime.h`, `vdso/limits.h`, `vdso/math64.h`, `vdso/time32.h`.
- Detected declarations: `function gettimeofday`, `function vdso_delta_ok`, `function vdso_shift_ns`, `function vdso_calc_ns`, `function __arch_vdso_hres_capable`, `function vdso_clocksource_ok`, `function vdso_cycles_ok`, `function vdso_clockid_valid`, `function __iter_div_u64_rem`, `function vdso_get_timestamp`.
- Atlas domain: Kernel Services / lib.
- 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.