kernel/time/jiffies.c
Source file repositories/reference/linux-study-clean/kernel/time/jiffies.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/time/jiffies.c- Extension
.c- Size
- 9132 bytes
- Lines
- 317
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clocksource.hlinux/jiffies.hlinux/module.hlinux/init.htimekeeping.htick-internal.h
Detected Declarations
function Copyrightfunction get_jiffies_64function clocksource_default_clockfunction register_refined_jiffiesfunction mult_hzfunction div_hzfunction sysctl_u2k_int_conv_hzfunction sysctl_k2u_int_conv_hzfunction sysctl_u2k_int_conv_userhzfunction sysctl_jiffies_to_clock_tfunction sysctl_k2u_int_conv_userhzfunction sysctl_msecs_to_jiffiesfunction sysctl_u2k_int_conv_msfunction sysctl_jiffies_to_msecsfunction sysctl_k2u_int_conv_msfunction do_proc_int_conv_jiffiesfunction do_proc_int_conv_userhz_jiffiesfunction do_proc_int_conv_ms_jiffiesfunction do_proc_int_conv_ms_jiffies_minmaxfunction do_proc_int_conv_jiffiesfunction do_proc_int_conv_userhz_jiffiesfunction do_proc_int_conv_ms_jiffiesfunction do_proc_int_conv_ms_jiffies_minmaxfunction proc_dointvec_jiffiesfunction proc_dointvec_userhz_jiffiesfunction proc_dointvec_ms_jiffiesfunction proc_dointvec_ms_jiffies_minmaxfunction proc_doulongvec_ms_jiffies_minmaxexport get_jiffies_64export jiffiesexport proc_dointvec_jiffiesexport proc_dointvec_userhz_jiffiesexport proc_dointvec_ms_jiffiesexport proc_doulongvec_ms_jiffies_minmax
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0+
/*
* This file contains the jiffies based clocksource.
*
* Copyright (C) 2004, 2005 IBM, John Stultz (johnstul@us.ibm.com)
*/
#include <linux/clocksource.h>
#include <linux/jiffies.h>
#include <linux/module.h>
#include <linux/init.h>
#include "timekeeping.h"
#include "tick-internal.h"
static u64 jiffies_read(struct clocksource *cs)
{
return (u64) jiffies;
}
/*
* The Jiffies based clocksource is the lowest common
* denominator clock source which should function on
* all systems. It has the same coarse resolution as
* the timer interrupt frequency HZ and it suffers
* inaccuracies caused by missed or lost timer
* interrupts and the inability for the timer
* interrupt hardware to accurately tick at the
* requested HZ value. It is also not recommended
* for "tick-less" systems.
*/
static struct clocksource clocksource_jiffies = {
.name = "jiffies",
.rating = 1, /* lowest valid rating*/
.read = jiffies_read,
.mask = CLOCKSOURCE_MASK(32),
.mult = TICK_NSEC << JIFFIES_SHIFT, /* details above */
.shift = JIFFIES_SHIFT,
.max_cycles = 10,
};
__cacheline_aligned_in_smp DEFINE_RAW_SPINLOCK(jiffies_lock);
__cacheline_aligned_in_smp seqcount_raw_spinlock_t jiffies_seq =
SEQCNT_RAW_SPINLOCK_ZERO(jiffies_seq, &jiffies_lock);
#if (BITS_PER_LONG < 64)
u64 get_jiffies_64(void)
{
unsigned int seq;
u64 ret;
do {
seq = read_seqcount_begin(&jiffies_seq);
ret = jiffies_64;
} while (read_seqcount_retry(&jiffies_seq, seq));
return ret;
}
EXPORT_SYMBOL(get_jiffies_64);
#endif
EXPORT_SYMBOL(jiffies);
static bool cs_jiffies_registered __initdata;
struct clocksource * __init __weak clocksource_default_clock(void)
{
if (!cs_jiffies_registered) {
__clocksource_register(&clocksource_jiffies);
cs_jiffies_registered = true;
}
return &clocksource_jiffies;
}
static struct clocksource refined_jiffies;
void __init register_refined_jiffies(long cycles_per_second)
{
u64 nsec_per_tick, shift_hz;
long cycles_per_tick;
refined_jiffies = clocksource_jiffies;
refined_jiffies.name = "refined-jiffies";
refined_jiffies.rating++;
/* Calc cycles per tick */
cycles_per_tick = (cycles_per_second + HZ/2)/HZ;
/* shift_hz stores hz<<8 for extra accuracy */
shift_hz = (u64)cycles_per_second << 8;
shift_hz += cycles_per_tick/2;
do_div(shift_hz, cycles_per_tick);
Annotation
- Immediate include surface: `linux/clocksource.h`, `linux/jiffies.h`, `linux/module.h`, `linux/init.h`, `timekeeping.h`, `tick-internal.h`.
- Detected declarations: `function Copyright`, `function get_jiffies_64`, `function clocksource_default_clock`, `function register_refined_jiffies`, `function mult_hz`, `function div_hz`, `function sysctl_u2k_int_conv_hz`, `function sysctl_k2u_int_conv_hz`, `function sysctl_u2k_int_conv_userhz`, `function sysctl_jiffies_to_clock_t`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration 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.