STRUCT TIMER_BASE(9)
β¨ struct timer_base(9) β¨
okay bestie, so this one is from the Kernel API Manual (the struct timer_base(9) page, if we're being official about it) and it's literally the per-CPU timer base π
β and the number of bases depends on your config, iykyk.
πΈ NAME πΈ
struct timer_base β per CPU timer base (and fr fr, the number of base depends on config π)
π SYNOPSIS π
struct timer_base {
raw_spinlock_t lock;
struct timer_list *running_timer;
#ifdef CONFIG_PREEMPT_RT;
spinlock_t expiry_lock;
atomic_t timer_waiters;
#endif;
unsigned long clk;
unsigned long next_expiry;
unsigned int cpu;
bool next_expiry_recalc;
bool is_idle;
bool timers_pending;
unsigned long pending_map[BITS_TO_LONGS( WHEEL_SIZE)];
struct hlist_head vectors[WHEEL_SIZE];
};
π¦ Members π¦
lockβ the lock protecting thetimer_base. literally its whole job π«Άrunning_timerβ so when timers are expiring, the lock gets dropped. to make sure we don't race against deleting/modifying a currently running timer, this pointer is set to the timer that's expiring at the moment. if no timer is running, the pointer isNULL. no cap πexpiry_lockβ PREEMPT_RT only: this lock is taken in softirq around timer expiry callback execution, and also when trying to delete a running timer and it wasn't successful in the first glance. it prevents priority inversion when the callback was preempted on a remote CPU and a caller tries to delete the running timer. it also prevents a life lock, when the task which tries to delete a timer preempted the softirq thread which is running the timer callback function. iconic protective behavior honestly β¨timer_waitersβ PREEMPT_RT only: tells, if there is a waiter waiting for the end of the timer callback function execution πclkβ clock of the timer base. it's updated before enqueue of a timer; during expiry, it is 1 offset ahead ofjiffiesto avoid endless requeuing to currentjiffies. self-care, honestly πnext_expiryβ expiry value of the first timer. it's updated when finding the next timer and during enqueue; the value is not valid whennext_expiry_recalcis set. so like, don't trust it then πcpuβ number of CPU the timer base belongs to. its little home πnext_expiry_recalcβ states whether a recalculation ofnext_expiryis required. value is settruewhen a timer was deleted.is_idleβ set whentimer_baseis idle. it's triggered by NOHZ code. this state is only used in standard base. deferrable timers, which are enqueued remotely never wake up an idle CPU. so no matter of supporting it for this base π¦timers_pendingβ set when a timer is pending in the base. β οΈ it is only reliable whennext_expiry_recalcis not set.pending_mapβ bitmap of the timer wheel; each bit reflects a bucket of the wheel. when a bit is set, at least a single timer is enqueued in the related bucket βvectorsβ array of lists; each array member reflects a bucket of the timer wheel. the list contains all timers which are enqueued into a specific bucket. love that for them π
π SEE ALSO π
kernel file ./kernel/time/timer.c β plus literally the whole friend group:
__round_jiffies_relative(9)round_jiffies(9)round_jiffies_relative(9)__round_jiffies_up_relative(9)round_jiffies_up(9)round_jiffies_up_relative(9)timer_init_key(9)mod_timer_pending(9)mod_timer(9)timer_reduce(9)add_timer(9)add_timer_local(9)add_timer_global(9)add_timer_on(9)__timer_delete(9)timer_delete(9)timer_shutdown(9)__try_to_del_timer_sync(9)timer_delete_sync_try(9)__timer_delete_sync(9)timer_delete_sync(9)timer_shutdown_sync(9)fetch_next_timer_interrupt_remote(9)timer_unlock_remote_bases(9)timer_lock_remote_bases(9)timer_base_is_idle(9)timer_expire_remote(9)get_next_timer_interrupt(9)timer_base_try_to_set_idle(9)timer_clear_idle(9)__run_timers(9)
π that's the whole page bestie, go forth and expire those timers responsibly π«Ά
and for the sign-off: this cutie came out of ./kernel/time, dated October 2026. mwah π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms