Skip to content

Commit f200c31

Browse files
committed
Merge tag 'timers-core-2025-01-21' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull timer and timekeeping updates from Thomas Gleixner: - Just boring cleanups, typo and comment fixes and trivial optimizations * tag 'timers-core-2025-01-21' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: timers/migration: Simplify top level detection on group setup timers: Optimize get_timer_[this_]cpu_base() timekeeping: Remove unused ktime_get_fast_timestamps() timer/migration: Fix kernel-doc warnings for union tmigr_state tick/broadcast: Add kernel-doc for function parameters hrtimers: Update the return type of enqueue_hrtimer() clocksource/wdtest: Print time values for short udelay(1) posix-timers: Fix typo in __lock_timer() vdso: Correct typo in PAGE_SHIFT comment
2 parents 3360882 + dcf6230 commit f200c31

File tree

10 files changed

+33
-116
lines changed

10 files changed

+33
-116
lines changed

include/linux/timekeeping.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -263,18 +263,6 @@ extern bool timekeeping_rtc_skipresume(void);
263263

264264
extern void timekeeping_inject_sleeptime64(const struct timespec64 *delta);
265265

266-
/**
267-
* struct ktime_timestamps - Simultaneous mono/boot/real timestamps
268-
* @mono: Monotonic timestamp
269-
* @boot: Boottime timestamp
270-
* @real: Realtime timestamp
271-
*/
272-
struct ktime_timestamps {
273-
u64 mono;
274-
u64 boot;
275-
u64 real;
276-
};
277-
278266
/**
279267
* struct system_time_snapshot - simultaneous raw/real time capture with
280268
* counter value
@@ -345,9 +333,6 @@ extern int get_device_system_crosststamp(
345333
*/
346334
extern void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot);
347335

348-
/* NMI safe mono/boot/realtime timestamps */
349-
extern void ktime_get_fast_timestamps(struct ktime_timestamps *snap);
350-
351336
/*
352337
* Persistent clock related interfaces
353338
*/

include/vdso/page.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* PAGE_SHIFT determines the page size.
99
*
1010
* Note: This definition is required because PAGE_SHIFT is used
11-
* in several places throuout the codebase.
11+
* in several places throughout the codebase.
1212
*/
1313
#define PAGE_SHIFT CONFIG_PAGE_SHIFT
1414

kernel/time/clocksource-wdtest.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ static int wdtest_func(void *arg)
137137
udelay(1);
138138
j2 = clocksource_wdtest_ktime.read(&clocksource_wdtest_ktime);
139139
pr_info("--- tsc-like times: %lu - %lu = %lu.\n", j2, j1, j2 - j1);
140-
WARN_ON_ONCE(time_before(j2, j1 + NSEC_PER_USEC));
140+
WARN_ONCE(time_before(j2, j1 + NSEC_PER_USEC),
141+
"Expected at least 1000ns, got %lu.\n", j2 - j1);
141142

142143
/* Verify tsc-like stability with various numbers of errors injected. */
143144
max_retries = clocksource_get_max_watchdog_retry();

kernel/time/hrtimer.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,11 +1067,10 @@ EXPORT_SYMBOL_GPL(hrtimer_forward);
10671067
* The timer is inserted in expiry order. Insertion into the
10681068
* red black tree is O(log(n)). Must hold the base lock.
10691069
*
1070-
* Returns 1 when the new timer is the leftmost timer in the tree.
1070+
* Returns true when the new timer is the leftmost timer in the tree.
10711071
*/
1072-
static int enqueue_hrtimer(struct hrtimer *timer,
1073-
struct hrtimer_clock_base *base,
1074-
enum hrtimer_mode mode)
1072+
static bool enqueue_hrtimer(struct hrtimer *timer, struct hrtimer_clock_base *base,
1073+
enum hrtimer_mode mode)
10751074
{
10761075
debug_activate(timer, mode);
10771076
WARN_ON_ONCE(!base->cpu_base->online);

kernel/time/posix-timers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ static struct k_itimer *__lock_timer(timer_t timer_id, unsigned long *flags)
538538
* When the reference count reaches zero, the timer is scheduled
539539
* for RCU removal after the grace period.
540540
*
541-
* Holding rcu_read_lock() accross the lookup ensures that
541+
* Holding rcu_read_lock() across the lookup ensures that
542542
* the timer cannot be freed.
543543
*
544544
* The lookup validates locklessly that timr::it_signal ==

kernel/time/tick-broadcast.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,8 @@ static inline ktime_t tick_get_next_period(void)
10201020

10211021
/**
10221022
* tick_broadcast_setup_oneshot - setup the broadcast device
1023+
* @bc: the broadcast device
1024+
* @from_periodic: true if called from periodic mode
10231025
*/
10241026
static void tick_broadcast_setup_oneshot(struct clock_event_device *bc,
10251027
bool from_periodic)

kernel/time/timekeeping.c

Lines changed: 8 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -485,90 +485,29 @@ u64 notrace ktime_get_tai_fast_ns(void)
485485
}
486486
EXPORT_SYMBOL_GPL(ktime_get_tai_fast_ns);
487487

488-
static __always_inline u64 __ktime_get_real_fast(struct tk_fast *tkf, u64 *mono)
488+
/**
489+
* ktime_get_real_fast_ns: - NMI safe and fast access to clock realtime.
490+
*
491+
* See ktime_get_mono_fast_ns() for documentation of the time stamp ordering.
492+
*/
493+
u64 ktime_get_real_fast_ns(void)
489494
{
495+
struct tk_fast *tkf = &tk_fast_mono;
490496
struct tk_read_base *tkr;
491-
u64 basem, baser, delta;
497+
u64 baser, delta;
492498
unsigned int seq;
493499

494500
do {
495501
seq = raw_read_seqcount_latch(&tkf->seq);
496502
tkr = tkf->base + (seq & 0x01);
497-
basem = ktime_to_ns(tkr->base);
498503
baser = ktime_to_ns(tkr->base_real);
499504
delta = timekeeping_get_ns(tkr);
500505
} while (raw_read_seqcount_latch_retry(&tkf->seq, seq));
501506

502-
if (mono)
503-
*mono = basem + delta;
504507
return baser + delta;
505508
}
506-
507-
/**
508-
* ktime_get_real_fast_ns: - NMI safe and fast access to clock realtime.
509-
*
510-
* See ktime_get_mono_fast_ns() for documentation of the time stamp ordering.
511-
*/
512-
u64 ktime_get_real_fast_ns(void)
513-
{
514-
return __ktime_get_real_fast(&tk_fast_mono, NULL);
515-
}
516509
EXPORT_SYMBOL_GPL(ktime_get_real_fast_ns);
517510

518-
/**
519-
* ktime_get_fast_timestamps: - NMI safe timestamps
520-
* @snapshot: Pointer to timestamp storage
521-
*
522-
* Stores clock monotonic, boottime and realtime timestamps.
523-
*
524-
* Boot time is a racy access on 32bit systems if the sleep time injection
525-
* happens late during resume and not in timekeeping_resume(). That could
526-
* be avoided by expanding struct tk_read_base with boot offset for 32bit
527-
* and adding more overhead to the update. As this is a hard to observe
528-
* once per resume event which can be filtered with reasonable effort using
529-
* the accurate mono/real timestamps, it's probably not worth the trouble.
530-
*
531-
* Aside of that it might be possible on 32 and 64 bit to observe the
532-
* following when the sleep time injection happens late:
533-
*
534-
* CPU 0 CPU 1
535-
* timekeeping_resume()
536-
* ktime_get_fast_timestamps()
537-
* mono, real = __ktime_get_real_fast()
538-
* inject_sleep_time()
539-
* update boot offset
540-
* boot = mono + bootoffset;
541-
*
542-
* That means that boot time already has the sleep time adjustment, but
543-
* real time does not. On the next readout both are in sync again.
544-
*
545-
* Preventing this for 64bit is not really feasible without destroying the
546-
* careful cache layout of the timekeeper because the sequence count and
547-
* struct tk_read_base would then need two cache lines instead of one.
548-
*
549-
* Access to the time keeper clock source is disabled across the innermost
550-
* steps of suspend/resume. The accessors still work, but the timestamps
551-
* are frozen until time keeping is resumed which happens very early.
552-
*
553-
* For regular suspend/resume there is no observable difference vs. sched
554-
* clock, but it might affect some of the nasty low level debug printks.
555-
*
556-
* OTOH, access to sched clock is not guaranteed across suspend/resume on
557-
* all systems either so it depends on the hardware in use.
558-
*
559-
* If that turns out to be a real problem then this could be mitigated by
560-
* using sched clock in a similar way as during early boot. But it's not as
561-
* trivial as on early boot because it needs some careful protection
562-
* against the clock monotonic timestamp jumping backwards on resume.
563-
*/
564-
void ktime_get_fast_timestamps(struct ktime_timestamps *snapshot)
565-
{
566-
struct timekeeper *tk = &tk_core.timekeeper;
567-
568-
snapshot->real = __ktime_get_real_fast(&tk_fast_mono, &snapshot->mono);
569-
snapshot->boot = snapshot->mono + ktime_to_ns(data_race(tk->offs_boot));
570-
}
571-
572511
/**
573512
* halt_fast_timekeeper - Prevent fast timekeeper from accessing clocksource.
574513
* @tk: Timekeeper to snapshot.

kernel/time/timer.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -956,33 +956,29 @@ static int detach_if_pending(struct timer_list *timer, struct timer_base *base,
956956
static inline struct timer_base *get_timer_cpu_base(u32 tflags, u32 cpu)
957957
{
958958
int index = tflags & TIMER_PINNED ? BASE_LOCAL : BASE_GLOBAL;
959-
struct timer_base *base;
960-
961-
base = per_cpu_ptr(&timer_bases[index], cpu);
962959

963960
/*
964961
* If the timer is deferrable and NO_HZ_COMMON is set then we need
965962
* to use the deferrable base.
966963
*/
967964
if (IS_ENABLED(CONFIG_NO_HZ_COMMON) && (tflags & TIMER_DEFERRABLE))
968-
base = per_cpu_ptr(&timer_bases[BASE_DEF], cpu);
969-
return base;
965+
index = BASE_DEF;
966+
967+
return per_cpu_ptr(&timer_bases[index], cpu);
970968
}
971969

972970
static inline struct timer_base *get_timer_this_cpu_base(u32 tflags)
973971
{
974972
int index = tflags & TIMER_PINNED ? BASE_LOCAL : BASE_GLOBAL;
975-
struct timer_base *base;
976-
977-
base = this_cpu_ptr(&timer_bases[index]);
978973

979974
/*
980975
* If the timer is deferrable and NO_HZ_COMMON is set then we need
981976
* to use the deferrable base.
982977
*/
983978
if (IS_ENABLED(CONFIG_NO_HZ_COMMON) && (tflags & TIMER_DEFERRABLE))
984-
base = this_cpu_ptr(&timer_bases[BASE_DEF]);
985-
return base;
979+
index = BASE_DEF;
980+
981+
return this_cpu_ptr(&timer_bases[index]);
986982
}
987983

988984
static inline struct timer_base *get_timer_base(u32 tflags)

kernel/time/timer_migration.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,9 +1670,7 @@ static int tmigr_setup_groups(unsigned int cpu, unsigned int node)
16701670
* be different from tmigr_hierarchy_levels, contains only a
16711671
* single group.
16721672
*/
1673-
if (group->parent || i == tmigr_hierarchy_levels ||
1674-
(list_empty(&tmigr_level_list[i]) &&
1675-
list_is_singular(&tmigr_level_list[i - 1])))
1673+
if (group->parent || list_is_singular(&tmigr_level_list[i - 1]))
16761674
break;
16771675

16781676
} while (i < tmigr_hierarchy_levels);

kernel/time/timer_migration.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,19 @@ struct tmigr_cpu {
110110
* union tmigr_state - state of tmigr_group
111111
* @state: Combined version of the state - only used for atomic
112112
* read/cmpxchg function
113-
* @struct: Split version of the state - only use the struct members to
113+
* &anon struct: Split version of the state - only use the struct members to
114114
* update information to stay independent of endianness
115+
* @active: Contains each mask bit of the active children
116+
* @migrator: Contains mask of the child which is migrator
117+
* @seq: Sequence counter needs to be increased when an update
118+
* to the tmigr_state is done. It prevents a race when
119+
* updates in the child groups are propagated in changed
120+
* order. Detailed information about the scenario is
121+
* given in the documentation at the begin of
122+
* timer_migration.c.
115123
*/
116124
union tmigr_state {
117125
u32 state;
118-
/**
119-
* struct - split state of tmigr_group
120-
* @active: Contains each mask bit of the active children
121-
* @migrator: Contains mask of the child which is migrator
122-
* @seq: Sequence counter needs to be increased when an update
123-
* to the tmigr_state is done. It prevents a race when
124-
* updates in the child groups are propagated in changed
125-
* order. Detailed information about the scenario is
126-
* given in the documentation at the begin of
127-
* timer_migration.c.
128-
*/
129126
struct {
130127
u8 active;
131128
u8 migrator;

0 commit comments

Comments
 (0)