kernel/time/ntp.c
Source file repositories/reference/linux-study-clean/kernel/time/ntp.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/time/ntp.c- Extension
.c- Size
- 32946 bytes
- Lines
- 1109
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- 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/capability.hlinux/clocksource.hlinux/workqueue.hlinux/hrtimer.hlinux/jiffies.hlinux/math64.hlinux/timex.hlinux/time.hlinux/mm.hlinux/module.hlinux/rtc.hlinux/audit.hlinux/timekeeper_internal.hntp_internal.htimekeeping_internal.h
Detected Declarations
struct ntp_datastruct pps_normtimefunction ntp_offset_chunkfunction pps_reset_freq_intervalfunction pps_clearfunction pps_dec_validfunction pps_set_freqfunction is_error_statusfunction pps_fill_timexfunction ntp_offset_chunkfunction pps_reset_freq_intervalfunction pps_fill_timexfunction ntp_update_frequencyfunction ntp_update_offset_fllfunction ntp_update_offsetfunction __ntp_clearfunction ntp_clearfunction ntp_tick_lengthfunction ntp_get_next_leapfunction Millsfunction sync_timer_callbackfunction sched_sync_hw_clockfunction writefunction update_persistent_clock64function update_persistent_clock64function update_rtcfunction update_rtcfunction ntp_syncedfunction sync_hw_clockfunction ntp_notify_cmos_timerfunction ntp_init_cmos_syncfunction ntp_init_cmos_syncfunction process_adjtimex_modesfunction adjtimexfunction pps_normalize_tsfunction pps_phase_filter_getfunction pps_phase_filter_addfunction pps_dec_freq_intervalfunction pps_inc_freq_intervalfunction hardpps_update_freqfunction hardpps_update_phasefunction __hardppsfunction ntp_tick_adj_setupfunction ntp_init
Annotated Snippet
struct ntp_data {
unsigned long tick_usec;
u64 tick_length;
u64 tick_length_base;
int time_state;
int time_status;
s64 time_offset;
long time_constant;
long time_maxerror;
long time_esterror;
s64 time_freq;
time64_t time_reftime;
long time_adjust;
s64 ntp_tick_adj;
time64_t ntp_next_leap_sec;
#ifdef CONFIG_NTP_PPS
int pps_valid;
long pps_tf[3];
long pps_jitter;
struct timespec64 pps_fbase;
int pps_shift;
int pps_intcnt;
s64 pps_freq;
long pps_stabil;
long pps_calcnt;
long pps_jitcnt;
long pps_stbcnt;
long pps_errcnt;
#endif
};
static struct ntp_data tk_ntp_data[TIMEKEEPERS_MAX] = {
[ 0 ... TIMEKEEPERS_MAX - 1 ] = {
.tick_usec = USER_TICK_USEC,
.time_state = TIME_OK,
.time_status = STA_UNSYNC,
.time_constant = 2,
.time_maxerror = NTP_PHASE_LIMIT,
.time_esterror = NTP_PHASE_LIMIT,
.ntp_next_leap_sec = TIME64_MAX,
},
};
#define SECS_PER_DAY 86400
#define MAX_TICKADJ 500LL /* usecs */
#define MAX_TICKADJ_SCALED \
(((MAX_TICKADJ * NSEC_PER_USEC) << NTP_SCALE_SHIFT) / NTP_INTERVAL_FREQ)
#define MAX_TAI_OFFSET 100000
#ifdef CONFIG_NTP_PPS
/*
* The following variables are used when a pulse-per-second (PPS) signal
* is available. They establish the engineering parameters of the clock
* discipline loop when controlled by the PPS signal.
*/
#define PPS_VALID 10 /* PPS signal watchdog max (s) */
#define PPS_POPCORN 4 /* popcorn spike threshold (shift) */
#define PPS_INTMIN 2 /* min freq interval (s) (shift) */
#define PPS_INTMAX 8 /* max freq interval (s) (shift) */
#define PPS_INTCOUNT 4 /* number of consecutive good intervals to
increase pps_shift or consecutive bad
intervals to decrease it */
#define PPS_MAXWANDER 100000 /* max PPS freq wander (ns/s) */
/*
* PPS kernel consumer compensates the whole phase error immediately.
* Otherwise, reduce the offset by a fixed factor times the time constant.
*/
static inline s64 ntp_offset_chunk(struct ntp_data *ntpdata, s64 offset)
{
if (ntpdata->time_status & STA_PPSTIME && ntpdata->time_status & STA_PPSSIGNAL)
return offset;
else
return shift_right(offset, SHIFT_PLL + ntpdata->time_constant);
}
static inline void pps_reset_freq_interval(struct ntp_data *ntpdata)
{
/* The PPS calibration interval may end surprisingly early */
ntpdata->pps_shift = PPS_INTMIN;
ntpdata->pps_intcnt = 0;
}
/**
* pps_clear - Clears the PPS state variables
* @ntpdata: Pointer to ntp data
*/
static inline void pps_clear(struct ntp_data *ntpdata)
{
Annotation
- Immediate include surface: `linux/capability.h`, `linux/clocksource.h`, `linux/workqueue.h`, `linux/hrtimer.h`, `linux/jiffies.h`, `linux/math64.h`, `linux/timex.h`, `linux/time.h`.
- Detected declarations: `struct ntp_data`, `struct pps_normtime`, `function ntp_offset_chunk`, `function pps_reset_freq_interval`, `function pps_clear`, `function pps_dec_valid`, `function pps_set_freq`, `function is_error_status`, `function pps_fill_timex`, `function ntp_offset_chunk`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- 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.