cregit-Linux how code gets into the kernel

Release 4.15 kernel/time/timer.c

Directory: kernel/time
/*
 *  linux/kernel/timer.c
 *
 *  Kernel internal timers
 *
 *  Copyright (C) 1991, 1992  Linus Torvalds
 *
 *  1997-01-28  Modified by Finn Arne Gangstad to make timers scale better.
 *
 *  1997-09-10  Updated NTP code according to technical memorandum Jan '96
 *              "A Kernel Model for Precision Timekeeping" by Dave Mills
 *  1998-12-24  Fixed a xtime SMP race (we need the xtime_lock rw spinlock to
 *              serialize accesses to xtime/lost_ticks).
 *                              Copyright (C) 1998  Andrea Arcangeli
 *  1999-03-10  Improved NTP compatibility by Ulrich Windl
 *  2002-05-31  Move sys_sysinfo here and make its locking sane, Robert Love
 *  2000-10-05  Implemented scalable SMP per-CPU timer handling.
 *                              Copyright (C) 2000, 2001, 2002  Ingo Molnar
 *              Designed by David S. Miller, Alexey Kuznetsov and Ingo Molnar
 */

#include <linux/kernel_stat.h>
#include <linux/export.h>
#include <linux/interrupt.h>
#include <linux/percpu.h>
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/swap.h>
#include <linux/pid_namespace.h>
#include <linux/notifier.h>
#include <linux/thread_info.h>
#include <linux/time.h>
#include <linux/jiffies.h>
#include <linux/posix-timers.h>
#include <linux/cpu.h>
#include <linux/syscalls.h>
#include <linux/delay.h>
#include <linux/tick.h>
#include <linux/kallsyms.h>
#include <linux/irq_work.h>
#include <linux/sched/signal.h>
#include <linux/sched/sysctl.h>
#include <linux/sched/nohz.h>
#include <linux/sched/debug.h>
#include <linux/slab.h>
#include <linux/compat.h>

#include <linux/uaccess.h>
#include <asm/unistd.h>
#include <asm/div64.h>
#include <asm/timex.h>
#include <asm/io.h>

#include "tick-internal.h"


#define CREATE_TRACE_POINTS
#include <trace/events/timer.h>


__visible u64 jiffies_64 __cacheline_aligned_in_smp = INITIAL_JIFFIES;


EXPORT_SYMBOL(jiffies_64);

/*
 * The timer wheel has LVL_DEPTH array levels. Each level provides an array of
 * LVL_SIZE buckets. Each level is driven by its own clock and therefor each
 * level has a different granularity.
 *
 * The level granularity is:            LVL_CLK_DIV ^ lvl
 * The level clock frequency is:        HZ / (LVL_CLK_DIV ^ level)
 *
 * The array level of a newly armed timer depends on the relative expiry
 * time. The farther the expiry time is away the higher the array level and
 * therefor the granularity becomes.
 *
 * Contrary to the original timer wheel implementation, which aims for 'exact'
 * expiry of the timers, this implementation removes the need for recascading
 * the timers into the lower array levels. The previous 'classic' timer wheel
 * implementation of the kernel already violated the 'exact' expiry by adding
 * slack to the expiry time to provide batched expiration. The granularity
 * levels provide implicit batching.
 *
 * This is an optimization of the original timer wheel implementation for the
 * majority of the timer wheel use cases: timeouts. The vast majority of
 * timeout timers (networking, disk I/O ...) are canceled before expiry. If
 * the timeout expires it indicates that normal operation is disturbed, so it
 * does not matter much whether the timeout comes with a slight delay.
 *
 * The only exception to this are networking timers with a small expiry
 * time. They rely on the granularity. Those fit into the first wheel level,
 * which has HZ granularity.
 *
 * We don't have cascading anymore. timers with a expiry time above the
 * capacity of the last wheel level are force expired at the maximum timeout
 * value of the last wheel level. From data sampling we know that the maximum
 * value observed is 5 days (network connection tracking), so this should not
 * be an issue.
 *
 * The currently chosen array constants values are a good compromise between
 * array size and granularity.
 *
 * This results in the following granularity and range levels:
 *
 * HZ 1000 steps
 * Level Offset  Granularity            Range
 *  0      0         1 ms                0 ms -         63 ms
 *  1     64         8 ms               64 ms -        511 ms
 *  2    128        64 ms              512 ms -       4095 ms (512ms - ~4s)
 *  3    192       512 ms             4096 ms -      32767 ms (~4s - ~32s)
 *  4    256      4096 ms (~4s)      32768 ms -     262143 ms (~32s - ~4m)
 *  5    320     32768 ms (~32s)    262144 ms -    2097151 ms (~4m - ~34m)
 *  6    384    262144 ms (~4m)    2097152 ms -   16777215 ms (~34m - ~4h)
 *  7    448   2097152 ms (~34m)  16777216 ms -  134217727 ms (~4h - ~1d)
 *  8    512  16777216 ms (~4h)  134217728 ms - 1073741822 ms (~1d - ~12d)
 *
 * HZ  300
 * Level Offset  Granularity            Range
 *  0      0         3 ms                0 ms -        210 ms
 *  1     64        26 ms              213 ms -       1703 ms (213ms - ~1s)
 *  2    128       213 ms             1706 ms -      13650 ms (~1s - ~13s)
 *  3    192      1706 ms (~1s)      13653 ms -     109223 ms (~13s - ~1m)
 *  4    256     13653 ms (~13s)    109226 ms -     873810 ms (~1m - ~14m)
 *  5    320    109226 ms (~1m)     873813 ms -    6990503 ms (~14m - ~1h)
 *  6    384    873813 ms (~14m)   6990506 ms -   55924050 ms (~1h - ~15h)
 *  7    448   6990506 ms (~1h)   55924053 ms -  447392423 ms (~15h - ~5d)
 *  8    512  55924053 ms (~15h) 447392426 ms - 3579139406 ms (~5d - ~41d)
 *
 * HZ  250
 * Level Offset  Granularity            Range
 *  0      0         4 ms                0 ms -        255 ms
 *  1     64        32 ms              256 ms -       2047 ms (256ms - ~2s)
 *  2    128       256 ms             2048 ms -      16383 ms (~2s - ~16s)
 *  3    192      2048 ms (~2s)      16384 ms -     131071 ms (~16s - ~2m)
 *  4    256     16384 ms (~16s)    131072 ms -    1048575 ms (~2m - ~17m)
 *  5    320    131072 ms (~2m)    1048576 ms -    8388607 ms (~17m - ~2h)
 *  6    384   1048576 ms (~17m)   8388608 ms -   67108863 ms (~2h - ~18h)
 *  7    448   8388608 ms (~2h)   67108864 ms -  536870911 ms (~18h - ~6d)
 *  8    512  67108864 ms (~18h) 536870912 ms - 4294967288 ms (~6d - ~49d)
 *
 * HZ  100
 * Level Offset  Granularity            Range
 *  0      0         10 ms               0 ms -        630 ms
 *  1     64         80 ms             640 ms -       5110 ms (640ms - ~5s)
 *  2    128        640 ms            5120 ms -      40950 ms (~5s - ~40s)
 *  3    192       5120 ms (~5s)     40960 ms -     327670 ms (~40s - ~5m)
 *  4    256      40960 ms (~40s)   327680 ms -    2621430 ms (~5m - ~43m)
 *  5    320     327680 ms (~5m)   2621440 ms -   20971510 ms (~43m - ~5h)
 *  6    384    2621440 ms (~43m) 20971520 ms -  167772150 ms (~5h - ~1d)
 *  7    448   20971520 ms (~5h) 167772160 ms - 1342177270 ms (~1d - ~15d)
 */

/* Clock divisor for the next level */

#define LVL_CLK_SHIFT	3

#define LVL_CLK_DIV	(1UL << LVL_CLK_SHIFT)

#define LVL_CLK_MASK	(LVL_CLK_DIV - 1)

#define LVL_SHIFT(n)	((n) * LVL_CLK_SHIFT)

#define LVL_GRAN(n)	(1UL << LVL_SHIFT(n))

/*
 * The time start value for each level to select the bucket at enqueue
 * time.
 */

#define LVL_START(n)	((LVL_SIZE - 1) << (((n) - 1) * LVL_CLK_SHIFT))

/* Size of each clock level */

#define LVL_BITS	6

#define LVL_SIZE	(1UL << LVL_BITS)

#define LVL_MASK	(LVL_SIZE - 1)

#define LVL_OFFS(n)	((n) * LVL_SIZE)

/* Level depth */
#if HZ > 100

# define LVL_DEPTH	9
# else

# define LVL_DEPTH	8
#endif

/* The cutoff (max. capacity of the wheel) */

#define WHEEL_TIMEOUT_CUTOFF	(LVL_START(LVL_DEPTH))

#define WHEEL_TIMEOUT_MAX	(WHEEL_TIMEOUT_CUTOFF - LVL_GRAN(LVL_DEPTH - 1))

/*
 * The resulting wheel size. If NOHZ is configured we allocate two
 * wheels so we have a separate storage for the deferrable timers.
 */

#define WHEEL_SIZE	(LVL_SIZE * LVL_DEPTH)

#ifdef CONFIG_NO_HZ_COMMON

# define NR_BASES	2

# define BASE_STD	0

# define BASE_DEF	1
#else

# define NR_BASES	1

# define BASE_STD	0

# define BASE_DEF	0
#endif


struct timer_base {
	
raw_spinlock_t		lock;
	
struct timer_list	*running_timer;
	
unsigned long		clk;
	
unsigned long		next_expiry;
	
unsigned int		cpu;
	
bool			migration_enabled;
	
bool			nohz_active;
	
bool			is_idle;
	
bool			must_forward_clk;
	DECLARE_BITMAP(pending_map, WHEEL_SIZE);
	
struct hlist_head	vectors[WHEEL_SIZE];

} ____cacheline_aligned;

static DEFINE_PER_CPU(struct timer_base, timer_bases[NR_BASES]);

#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)

unsigned int sysctl_timer_migration = 1;


void timers_update_migration(bool update_nohz) { bool on = sysctl_timer_migration && tick_nohz_active; unsigned int cpu; /* Avoid the loop, if nothing to update */ if (this_cpu_read(timer_bases[BASE_STD].migration_enabled) == on) return; for_each_possible_cpu(cpu) { per_cpu(timer_bases[BASE_STD].migration_enabled, cpu) = on; per_cpu(timer_bases[BASE_DEF].migration_enabled, cpu) = on; per_cpu(hrtimer_bases.migration_enabled, cpu) = on; if (!update_nohz) continue; per_cpu(timer_bases[BASE_STD].nohz_active, cpu) = true; per_cpu(timer_bases[BASE_DEF].nohz_active, cpu) = true; per_cpu(hrtimer_bases.nohz_active, cpu) = true; } }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner125100.00%4100.00%
Total125100.00%4100.00%


int timer_migration_handler(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos) { static DEFINE_MUTEX(mutex); int ret; mutex_lock(&mutex); ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); if (!ret && write) timers_update_migration(false); mutex_unlock(&mutex); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner7698.70%266.67%
Myungho Jung11.30%133.33%
Total77100.00%3100.00%

#endif
static unsigned long round_jiffies_common(unsigned long j, int cpu, bool force_up) { int rem; unsigned long original = j; /* * We don't want all cpus firing their timers at once hitting the * same lock or cachelines, so we skew each extra cpu with an extra * 3 jiffies. This 3 jiffies came originally from the mm/ code which * already did this. * The skew is done by adding 3*cpunr, then round, then subtract this * extra offset again. */ j += cpu * 3; rem = j % HZ; /* * If the target jiffie is just after a whole second (which can happen * due to delays of the timer irq, long irq off times etc etc) then * we should round down to the whole second, not up. Use 1/4th second * as cutoff for this rounding as an extreme upper bound for this. * But never round down if @force_up is set. */ if (rem < HZ/4 && !force_up) /* round down */ j = j - rem; else /* round up */ j = j - rem + HZ; /* now that we have rounded, subtract the extra skew again */ j -= cpu * 3; /* * Make sure j is still in the future. Otherwise return the * unmodified value. */ return time_is_after_jiffies(j) ? j : original; }

Contributors

PersonTokensPropCommitsCommitProp
Arjan van de Ven5867.44%120.00%
Thomas Gleixner1618.60%240.00%
Bart Van Assche89.30%120.00%
Alan Stern44.65%120.00%
Total86100.00%5100.00%

/** * __round_jiffies - function to round jiffies to a full second * @j: the time in (absolute) jiffies that should be rounded * @cpu: the processor number on which the timeout will happen * * __round_jiffies() rounds an absolute time in the future (in jiffies) * up or down to (approximately) full seconds. This is useful for timers * for which the exact time they fire does not matter too much, as long as * they fire approximately every X seconds. * * By rounding these timers to whole seconds, all such timers will fire * at the same time, rather than at various times spread out. The goal * of this is to have the CPU wake up less, which saves power. * * The exact rounding is skewed for each processor to avoid all * processors firing at the exact same time, which could lead * to lock contention or spurious cache line bouncing. * * The return value is the rounded version of the @j parameter. */
unsigned long __round_jiffies(unsigned long j, int cpu) { return round_jiffies_common(j, cpu, false); }

Contributors

PersonTokensPropCommitsCommitProp
Alan Stern23100.00%1100.00%
Total23100.00%1100.00%

EXPORT_SYMBOL_GPL(__round_jiffies); /** * __round_jiffies_relative - function to round jiffies to a full second * @j: the time in (relative) jiffies that should be rounded * @cpu: the processor number on which the timeout will happen * * __round_jiffies_relative() rounds a time delta in the future (in jiffies) * up or down to (approximately) full seconds. This is useful for timers * for which the exact time they fire does not matter too much, as long as * they fire approximately every X seconds. * * By rounding these timers to whole seconds, all such timers will fire * at the same time, rather than at various times spread out. The goal * of this is to have the CPU wake up less, which saves power. * * The exact rounding is skewed for each processor to avoid all * processors firing at the exact same time, which could lead * to lock contention or spurious cache line bouncing. * * The return value is the rounded version of the @j parameter. */
unsigned long __round_jiffies_relative(unsigned long j, int cpu) { unsigned long j0 = jiffies; /* Use j0 because jiffies might change while we run */ return round_jiffies_common(j + j0, cpu, false) - j0; }

Contributors

PersonTokensPropCommitsCommitProp
Arjan van de Ven2264.71%150.00%
Alan Stern1235.29%150.00%
Total34100.00%2100.00%

EXPORT_SYMBOL_GPL(__round_jiffies_relative); /** * round_jiffies - function to round jiffies to a full second * @j: the time in (absolute) jiffies that should be rounded * * round_jiffies() rounds an absolute time in the future (in jiffies) * up or down to (approximately) full seconds. This is useful for timers * for which the exact time they fire does not matter too much, as long as * they fire approximately every X seconds. * * By rounding these timers to whole seconds, all such timers will fire * at the same time, rather than at various times spread out. The goal * of this is to have the CPU wake up less, which saves power. * * The return value is the rounded version of the @j parameter. */
unsigned long round_jiffies(unsigned long j) { return round_jiffies_common(j, raw_smp_processor_id(), false); }

Contributors

PersonTokensPropCommitsCommitProp
Arjan van de Ven1885.71%150.00%
Alan Stern314.29%150.00%
Total21100.00%2100.00%

EXPORT_SYMBOL_GPL(round_jiffies); /** * round_jiffies_relative - function to round jiffies to a full second * @j: the time in (relative) jiffies that should be rounded * * round_jiffies_relative() rounds a time delta in the future (in jiffies) * up or down to (approximately) full seconds. This is useful for timers * for which the exact time they fire does not matter too much, as long as * they fire approximately every X seconds. * * By rounding these timers to whole seconds, all such timers will fire * at the same time, rather than at various times spread out. The goal * of this is to have the CPU wake up less, which saves power. * * The return value is the rounded version of the @j parameter. */
unsigned long round_jiffies_relative(unsigned long j) { return __round_jiffies_relative(j, raw_smp_processor_id()); }

Contributors

PersonTokensPropCommitsCommitProp
Arjan van de Ven19100.00%1100.00%
Total19100.00%1100.00%

EXPORT_SYMBOL_GPL(round_jiffies_relative); /** * __round_jiffies_up - function to round jiffies up to a full second * @j: the time in (absolute) jiffies that should be rounded * @cpu: the processor number on which the timeout will happen * * This is the same as __round_jiffies() except that it will never * round down. This is useful for timeouts for which the exact time * of firing does not matter too much, as long as they don't fire too * early. */
unsigned long __round_jiffies_up(unsigned long j, int cpu) { return round_jiffies_common(j, cpu, true); }

Contributors

PersonTokensPropCommitsCommitProp
Alan Stern23100.00%1100.00%
Total23100.00%1100.00%

EXPORT_SYMBOL_GPL(__round_jiffies_up); /** * __round_jiffies_up_relative - function to round jiffies up to a full second * @j: the time in (relative) jiffies that should be rounded * @cpu: the processor number on which the timeout will happen * * This is the same as __round_jiffies_relative() except that it will never * round down. This is useful for timeouts for which the exact time * of firing does not matter too much, as long as they don't fire too * early. */
unsigned long __round_jiffies_up_relative(unsigned long j, int cpu) { unsigned long j0 = jiffies; /* Use j0 because jiffies might change while we run */ return round_jiffies_common(j + j0, cpu, true) - j0; }

Contributors

PersonTokensPropCommitsCommitProp
Alan Stern34100.00%1100.00%
Total34100.00%1100.00%

EXPORT_SYMBOL_GPL(__round_jiffies_up_relative); /** * round_jiffies_up - function to round jiffies up to a full second * @j: the time in (absolute) jiffies that should be rounded * * This is the same as round_jiffies() except that it will never * round down. This is useful for timeouts for which the exact time * of firing does not matter too much, as long as they don't fire too * early. */
unsigned long round_jiffies_up(unsigned long j) { return round_jiffies_common(j, raw_smp_processor_id(), true); }

Contributors

PersonTokensPropCommitsCommitProp
Alan Stern21100.00%1100.00%
Total21100.00%1100.00%

EXPORT_SYMBOL_GPL(round_jiffies_up); /** * round_jiffies_up_relative - function to round jiffies up to a full second * @j: the time in (relative) jiffies that should be rounded * * This is the same as round_jiffies_relative() except that it will never * round down. This is useful for timeouts for which the exact time * of firing does not matter too much, as long as they don't fire too * early. */
unsigned long round_jiffies_up_relative(unsigned long j) { return __round_jiffies_up_relative(j, raw_smp_processor_id()); }

Contributors

PersonTokensPropCommitsCommitProp
Alan Stern19100.00%1100.00%
Total19100.00%1100.00%

EXPORT_SYMBOL_GPL(round_jiffies_up_relative);
static inline unsigned int timer_get_idx(struct timer_list *timer) { return (timer->flags & TIMER_ARRAYMASK) >> TIMER_ARRAYSHIFT; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner24100.00%1100.00%
Total24100.00%1100.00%


static inline void timer_set_idx(struct timer_list *timer, unsigned int idx) { timer->flags = (timer->flags & ~TIMER_ARRAYMASK) | idx << TIMER_ARRAYSHIFT; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner1854.55%150.00%
Arjan van de Ven1545.45%150.00%
Total33100.00%2100.00%

/* * Helper function to calculate the array index for a given expiry * time. */
static inline unsigned calc_index(unsigned expires, unsigned lvl) { expires = (expires + LVL_GRAN(lvl)) >> LVL_SHIFT(lvl); return LVL_OFFS(lvl) + (expires & LVL_MASK); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner3892.68%150.00%
Arjan van de Ven37.32%150.00%
Total41100.00%2100.00%


static int calc_wheel_index(unsigned long expires, unsigned long clk) { unsigned long delta = expires - clk; unsigned int idx; if (delta < LVL_START(1)) { idx = calc_index(expires, 0); } else if (delta < LVL_START(2)) { idx = calc_index(expires, 1); } else if (delta < LVL_START(3)) { idx = calc_index(expires, 2); } else if (delta < LVL_START(4)) { idx = calc_index(expires, 3); } else if (delta < LVL_START(5)) { idx = calc_index(expires, 4); } else if (delta < LVL_START(6)) { idx = calc_index(expires, 5); } else if (delta < LVL_START(7)) { idx = calc_index(expires, 6); } else if (LVL_DEPTH > 8 && delta < LVL_START(8)) { idx = calc_index(expires, 7); } else if ((long) delta < 0) { idx = clk & LVL_MASK; } else { /* * Force expire obscene large timeouts to expire at the * capacity limit of the wheel. */ if (expires >= WHEEL_TIMEOUT_CUTOFF) expires = WHEEL_TIMEOUT_MAX; idx = calc_index(expires, LVL_DEPTH - 1); } return idx; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner13455.14%233.33%
Ingo Molnar9539.09%233.33%
Anna-Maria Gleixner93.70%116.67%
Linus Torvalds (pre-git)52.06%116.67%
Total243100.00%6100.00%

/* * Enqueue the timer into the hash bucket, mark it pending in * the bitmap and store the index in the timer flags. */
static void enqueue_timer(struct timer_base *base, struct timer_list *timer, unsigned int idx) { hlist_add_head(&timer->entry, base->vectors + idx); __set_bit(idx, base->pending_map); timer_set_idx(timer, idx); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner3468.00%450.00%
Anna-Maria Gleixner816.00%112.50%
Ingo Molnar714.00%225.00%
Paul E. McKenney12.00%112.50%
Total50100.00%8100.00%


static void __internal_add_timer(struct timer_base *base, struct timer_list *timer) { unsigned int idx; idx = calc_wheel_index(timer->expires, base->clk); enqueue_timer(base, timer, idx); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner2866.67%360.00%
Anna-Maria Gleixner1330.95%120.00%
Oleg Nesterov12.38%120.00%
Total42100.00%5100.00%


static void trigger_dyntick_cpu(struct timer_base *base, struct timer_list *timer) { if (!IS_ENABLED(CONFIG_NO_HZ_COMMON) || !base->nohz_active) return; /* * TODO: This wants some optimizing similar to the code below, but we * will do that when we switch from push to pull for deferrable timers. */ if (timer->flags & TIMER_DEFERRABLE) { if (tick_nohz_full_cpu(base->cpu)) wake_up_nohz_cpu(base->cpu); return; } /* * We might have to IPI the remote CPU if the base is idle and the * timer is not deferrable. If the other CPU is on the way to idle * then it can't set base->is_idle as we hold the base lock: */ if (!base->is_idle) return; /* Check whether this is the new first expiring timer: */ if (time_after_eq(timer->expires, base->next_expiry)) return; /* * Set the next expiry time and kick the CPU so it can reevaluate the * wheel: */ base->next_expiry = timer->expires; wake_up_nohz_cpu(base->cpu); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner6566.33%666.67%
Viresh Kumar1616.33%111.11%
Anna-Maria Gleixner1515.31%111.11%
Joonwoo Park22.04%111.11%
Total98100.00%9100.00%


static void internal_add_timer(struct timer_base *base, struct timer_list *timer) { __internal_add_timer(base, timer); trigger_dyntick_cpu(base, timer); }

Contributors

PersonTokensPropCommitsCommitProp
Anna-Maria Gleixner2996.67%150.00%
Thomas Gleixner13.33%150.00%
Total30100.00%2100.00%

#ifdef CONFIG_DEBUG_OBJECTS_TIMERS static struct debug_obj_descr timer_debug_descr;
static void *timer_debug_hint(void *addr) { return ((struct timer_list *) addr)->function; }

Contributors

PersonTokensPropCommitsCommitProp
Stanislaw Gruszka23100.00%1100.00%
Total23100.00%1100.00%


static bool timer_is_static_object(void *addr) { struct timer_list *timer = addr; return (timer->entry.pprev == NULL && timer->entry.next == TIMER_ENTRY_STATIC); }

Contributors

PersonTokensPropCommitsCommitProp
Changbin Du36100.00%1100.00%
Total36100.00%1100.00%

/* * fixup_init is called when: * - an active object is initialized */
static bool timer_fixup_init(void *addr, enum debug_obj_state state) { struct timer_list *timer = addr; switch (state) { case ODEBUG_STATE_ACTIVE: del_timer_sync(timer); debug_object_init(timer, &timer_debug_descr); return true; default: return false; } }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner4692.00%133.33%
Changbin Du36.00%133.33%
Oleg Nesterov12.00%133.33%
Total50100.00%3100.00%

/* Stub timer callback for improperly used timers. */
static void stub_timer(struct timer_list *unused) { WARN_ON(1); }

Contributors

PersonTokensPropCommitsCommitProp
Stephen Boyd1275.00%150.00%
Thomas Gleixner425.00%150.00%
Total16100.00%2100.00%

/* * fixup_activate is called when: * - an active object is activated * - an unknown non-static object is activated */
static bool timer_fixup_activate(void *addr, enum debug_obj_state state) { struct timer_list *timer = addr; switch (state) { case ODEBUG_STATE_NOTAVAILABLE: timer_setup(timer, stub_timer, 0); return true; case ODEBUG_STATE_ACTIVE: WARN_ON(1); default: return false; } }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner4481.48%250.00%
Stephen Boyd712.96%125.00%
Changbin Du35.56%125.00%
Total54100.00%4100.00%

/* * fixup_free is called when: * - an active object is freed */
static bool timer_fixup_free(void *addr, enum debug_obj_state state) { struct timer_list *timer = addr; switch (state) { case ODEBUG_STATE_ACTIVE: del_timer_sync(timer); debug_object_free(timer, &timer_debug_descr); return true; default: return false; } }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner4794.00%150.00%
Changbin Du36.00%150.00%
Total50100.00%2100.00%

/* * fixup_assert_init is called when: * - an untracked/uninit-ed object is found */
static bool timer_fixup_assert_init(void *addr, enum debug_obj_state state) { struct timer_list *timer = addr; switch (state) { case ODEBUG_STATE_NOTAVAILABLE: timer_setup(timer, stub_timer, 0); return true; default: return false; } }

Contributors

PersonTokensPropCommitsCommitProp
Christine Chan4291.30%133.33%
Changbin Du36.52%133.33%
Thomas Gleixner12.17%133.33%
Total46100.00%3100.00%

static struct debug_obj_descr timer_debug_descr = { .name = "timer_list", .debug_hint = timer_debug_hint, .is_static_object = timer_is_static_object, .fixup_init = timer_fixup_init, .fixup_activate = timer_fixup_activate, .fixup_free = timer_fixup_free, .fixup_assert_init = timer_fixup_assert_init, };
static inline void debug_timer_init(struct timer_list *timer) { debug_object_init(timer, &timer_debug_descr); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner20100.00%1100.00%
Total20100.00%1100.00%


static inline void debug_timer_activate(struct timer_list *timer) { debug_object_activate(timer, &timer_debug_descr); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner20100.00%1100.00%
Total20100.00%1100.00%


static inline void debug_timer_deactivate(struct timer_list *timer) { debug_object_deactivate(timer, &timer_debug_descr); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner20100.00%1100.00%
Total20100.00%1100.00%


static inline void debug_timer_free(struct timer_list *timer) { debug_object_free(timer, &timer_debug_descr); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner20100.00%1100.00%
Total20100.00%1100.00%


static inline void debug_timer_assert_init(struct timer_list *timer) { debug_object_assert_init(timer, &timer_debug_descr); }

Contributors

PersonTokensPropCommitsCommitProp
Christine Chan20100.00%1100.00%
Total20100.00%1100.00%

static void do_init_timer(struct timer_list *timer, void (*func)(struct timer_list *), unsigned int flags, const char *name, struct lock_class_key *key);
void init_timer_on_stack_key(struct timer_list *timer, void (*func)(struct timer_list *), unsigned int flags, const char *name, struct lock_class_key *key) { debug_object_init_on_stack(timer, &timer_debug_descr); do_init_timer(timer, func, flags, name, key); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner2137.50%125.00%
Johannes Berg1526.79%125.00%
Kees Cook1323.21%125.00%
Tejun Heo712.50%125.00%
Total56100.00%4100.00%

EXPORT_SYMBOL_GPL(init_timer_on_stack_key);
void destroy_timer_on_stack(struct timer_list *timer) { debug_object_free(timer, &timer_debug_descr); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner18100.00%1100.00%
Total18100.00%1100.00%

EXPORT_SYMBOL_GPL(destroy_timer_on_stack); #else
static inline void debug_timer_init(struct timer_list *timer) { }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner11100.00%1100.00%
Total11100.00%1100.00%


static inline void debug_timer_activate(struct timer_list *timer) { }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner11100.00%1100.00%
Total11100.00%1100.00%


static inline void debug_timer_deactivate(struct timer_list *timer) { }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner11100.00%1100.00%
Total11100.00%1100.00%


static inline void debug_timer_assert_init(struct timer_list *timer) { }

Contributors

PersonTokensPropCommitsCommitProp
Christine Chan11100.00%1100.00%
Total11100.00%1100.00%

#endif
static inline void debug_init(struct timer_list *timer) { debug_timer_init(timer); trace_timer_init(timer); }

Contributors

PersonTokensPropCommitsCommitProp
Xiao Guangrong22100.00%1100.00%
Total22100.00%1100.00%


static inline void debug_activate(struct timer_list *timer, unsigned long expires) { debug_timer_activate(timer); trace_timer_start(timer, expires, timer->flags); }

Contributors

PersonTokensPropCommitsCommitProp
Xiao Guangrong2887.50%133.33%
Badhri Jagan Sridharan39.38%133.33%
Thomas Gleixner13.12%133.33%
Total32100.00%3100.00%


static inline void debug_deactivate(struct timer_list *timer) { debug_timer_deactivate(timer); trace_timer_cancel(timer); }

Contributors

PersonTokensPropCommitsCommitProp
Xiao Guangrong22100.00%1100.00%
Total22100.00%1100.00%


static inline void debug_assert_init(struct timer_list *timer) { debug_timer_assert_init(timer); }

Contributors

PersonTokensPropCommitsCommitProp
Christine Chan17100.00%1100.00%
Total17100.00%1100.00%


static void do_init_timer(struct timer_list *timer, void (*func)(struct timer_list *), unsigned int flags, const char *name, struct lock_class_key *key) { timer->entry.pprev = NULL; timer->function = func; timer->flags = flags | raw_smp_processor_id(); lockdep_init_map(&timer->lockdep_map, name, key, 0); }

Contributors

PersonTokensPropCommitsCommitProp
Johannes Berg2432.88%18.33%
Kees Cook1723.29%18.33%
Ingo Molnar810.96%216.67%
Thomas Gleixner79.59%325.00%
Tejun Heo68.22%18.33%
Oleg Nesterov56.85%18.33%
Andrew Morton34.11%18.33%
George Anzinger22.74%18.33%
Linus Torvalds (pre-git)11.37%18.33%
Total73100.00%12100.00%

/** * init_timer_key - initialize a timer * @timer: the timer to be initialized * @func: timer callback function * @flags: timer flags * @name: name of the timer * @key: lockdep class key of the fake lock used for tracking timer * sync lock dependencies * * init_timer_key() must be done to a timer prior calling *any* of the * other timer functions. */
void init_timer_key(struct timer_list *timer, void (*func)(struct timer_list *), unsigned int flags, const char *name, struct lock_class_key *key) { debug_init(timer); do_init_timer(timer, func, flags, name, key); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner1732.08%120.00%
Johannes Berg1528.30%120.00%
Kees Cook1324.53%120.00%
Tejun Heo713.21%120.00%
Xiao Guangrong11.89%120.00%
Total53100.00%5100.00%

EXPORT_SYMBOL(init_timer_key);
static inline void detach_timer(struct timer_list *timer, bool clear_pending) { struct hlist_node *entry = &timer->entry; debug_deactivate(timer); __hlist_del(entry); if (clear_pending) entry->pprev = NULL; entry->next = LIST_POISON2; }

Contributors

PersonTokensPropCommitsCommitProp
Oleg Nesterov2752.94%112.50%
Ingo Molnar1019.61%112.50%
Thomas Gleixner917.65%337.50%
Linus Torvalds (pre-git)47.84%225.00%
Xiao Guangrong11.96%112.50%
Total51100.00%8100.00%


static int detach_if_pending(struct timer_list *timer, struct timer_base *base, bool clear_pending) { unsigned idx = timer_get_idx(timer); if (!timer_pending(timer)) return 0; if (hlist_is_singular_node(&timer->entry, base->vectors + idx)) __clear_bit(idx, base->pending_map); detach_timer(timer, clear_pending); return 1; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner7298.63%375.00%
Paul E. McKenney11.37%125.00%
Total73100.00%4100.00%


static inline struct timer_base *get_timer_cpu_base(u32 tflags, u32 cpu) { struct timer_base *base = per_cpu_ptr(&timer_bases[BASE_STD], cpu); /* * If the timer is deferrable and NO_HZ_COMMON is set then we need * to use the deferrable base. */ if (IS_ENABLED(CONFIG_NO_HZ_COMMON) && (tflags & TIMER_DEFERRABLE)) base = per_cpu_ptr(&timer_bases[BASE_DEF], cpu); return base; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner6098.36%583.33%
Anna-Maria Gleixner11.64%116.67%
Total61100.00%6100.00%


static inline struct timer_base *get_timer_this_cpu_base(u32 tflags) { struct timer_base *base = this_cpu_ptr(&timer_bases[BASE_STD]); /* * If the timer is deferrable and NO_HZ_COMMON is set then we need * to use the deferrable base. */ if (IS_ENABLED(CONFIG_NO_HZ_COMMON) && (tflags & TIMER_DEFERRABLE)) base = this_cpu_ptr(&timer_bases[BASE_DEF]); return base; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner5398.15%375.00%
Anna-Maria Gleixner11.85%125.00%
Total54100.00%4100.00%


static inline struct timer_base *get_timer_base(u32 tflags) { return get_timer_cpu_base(tflags, tflags & TIMER_CPUMASK); }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner22100.00%2100.00%
Total22100.00%2100.00%

#ifdef CONFIG_NO_HZ_COMMON
static inline struct timer_base * get_target_base(struct timer_base *base, unsigned tflags) { #ifdef CONFIG_SMP if ((tflags & TIMER_PINNED) || !base->migration_enabled) return get_timer_this_cpu_base(tflags); return get_timer_cpu_base(tflags, get_nohz_timer_target()); #else return get_timer_this_cpu_base(tflags); #endif }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner5696.55%583.33%
Paul E. McKenney23.45%116.67%
Total58100.00%6100.00%


static inline void forward_timer_base(struct timer_base *base) { unsigned long jnow; /* * We only forward the base when we are idle or have just come out of * idle (must_forward_clk logic), and have a delta between base clock * and jiffies. In the common case, run_timers will take care of it. */ if (likely(!base->must_forward_clk)) return; jnow = READ_ONCE(jiffies); base->must_forward_clk = base->is_idle; if ((long)(jnow - base->clk) < 2) return; /* * If the next expiry value is > jiffies, then we fast forward to * jiffies otherwise we forward to the next expiry value. */ if (time_after(base->next_expiry, jnow)) base->clk = jnow; else base->clk = base->next_expiry; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Gleixner5665.12%233.33%
Nicholas Piggin2326.74%116.67%
Ingo Molnar44.65%116.67%
Oleg Nesterov22.33%116.67%
Linus Torvalds (pre-git)11.16%116.67%
Total86100.00%6100.00%

#