Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hrtimer: Remove hrtimer_clock_base:: Get_time

The get_time() callbacks always need to match the bases clockid.
Instead of maintaining that association twice in hrtimer_bases,
use a helper.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/all/20250821-hrtimer-cleanup-get_time-v2-8-3ae822e5bfbd@linutronix.de


authored by

Thomas Weißschuh and committed by
Thomas Gleixner
009eb5da cdea7cda

+26 -19
+1 -4
include/linux/hrtimer.h
··· 154 154 return ktime_to_ns(timer->node.expires); 155 155 } 156 156 157 - static inline ktime_t hrtimer_cb_get_time(const struct hrtimer *timer) 158 - { 159 - return timer->base->get_time(); 160 - } 157 + ktime_t hrtimer_cb_get_time(const struct hrtimer *timer); 161 158 162 159 static inline ktime_t hrtimer_expires_remaining(const struct hrtimer *timer) 163 160 {
-2
include/linux/hrtimer_defs.h
··· 41 41 * @seq: seqcount around __run_hrtimer 42 42 * @running: pointer to the currently running hrtimer 43 43 * @active: red black tree root node for the active timers 44 - * @get_time: function to retrieve the current time of the clock 45 44 * @offset: offset of this clock to the monotonic base 46 45 */ 47 46 struct hrtimer_clock_base { ··· 50 51 seqcount_raw_spinlock_t seq; 51 52 struct hrtimer *running; 52 53 struct timerqueue_head active; 53 - ktime_t (*get_time)(void); 54 54 ktime_t offset; 55 55 } __hrtimer_clock_base_align; 56 56
+25 -9
kernel/time/hrtimer.c
··· 59 59 #define HRTIMER_ACTIVE_ALL (HRTIMER_ACTIVE_SOFT | HRTIMER_ACTIVE_HARD) 60 60 61 61 static void retrigger_next_event(void *arg); 62 + static ktime_t __hrtimer_cb_get_time(clockid_t clock_id); 62 63 63 64 /* 64 65 * The timer bases: ··· 77 76 { 78 77 .index = HRTIMER_BASE_MONOTONIC, 79 78 .clockid = CLOCK_MONOTONIC, 80 - .get_time = &ktime_get, 81 79 }, 82 80 { 83 81 .index = HRTIMER_BASE_REALTIME, 84 82 .clockid = CLOCK_REALTIME, 85 - .get_time = &ktime_get_real, 86 83 }, 87 84 { 88 85 .index = HRTIMER_BASE_BOOTTIME, 89 86 .clockid = CLOCK_BOOTTIME, 90 - .get_time = &ktime_get_boottime, 91 87 }, 92 88 { 93 89 .index = HRTIMER_BASE_TAI, 94 90 .clockid = CLOCK_TAI, 95 - .get_time = &ktime_get_clocktai, 96 91 }, 97 92 { 98 93 .index = HRTIMER_BASE_MONOTONIC_SOFT, 99 94 .clockid = CLOCK_MONOTONIC, 100 - .get_time = &ktime_get, 101 95 }, 102 96 { 103 97 .index = HRTIMER_BASE_REALTIME_SOFT, 104 98 .clockid = CLOCK_REALTIME, 105 - .get_time = &ktime_get_real, 106 99 }, 107 100 { 108 101 .index = HRTIMER_BASE_BOOTTIME_SOFT, 109 102 .clockid = CLOCK_BOOTTIME, 110 - .get_time = &ktime_get_boottime, 111 103 }, 112 104 { 113 105 .index = HRTIMER_BASE_TAI_SOFT, 114 106 .clockid = CLOCK_TAI, 115 - .get_time = &ktime_get_clocktai, 116 107 }, 117 108 }, 118 109 .csd = CSD_INIT(retrigger_next_event, NULL) ··· 1246 1253 remove_hrtimer(timer, base, true, force_local); 1247 1254 1248 1255 if (mode & HRTIMER_MODE_REL) 1249 - tim = ktime_add_safe(tim, base->get_time()); 1256 + tim = ktime_add_safe(tim, __hrtimer_cb_get_time(base->clockid)); 1250 1257 1251 1258 tim = hrtimer_update_lowres(timer, tim, mode); 1252 1259 ··· 1580 1587 return HRTIMER_BASE_MONOTONIC; 1581 1588 } 1582 1589 } 1590 + 1591 + static ktime_t __hrtimer_cb_get_time(clockid_t clock_id) 1592 + { 1593 + switch (clock_id) { 1594 + case CLOCK_MONOTONIC: 1595 + return ktime_get(); 1596 + case CLOCK_REALTIME: 1597 + return ktime_get_real(); 1598 + case CLOCK_BOOTTIME: 1599 + return ktime_get_boottime(); 1600 + case CLOCK_TAI: 1601 + return ktime_get_clocktai(); 1602 + default: 1603 + WARN(1, "Invalid clockid %d. Using MONOTONIC\n", clock_id); 1604 + return ktime_get(); 1605 + } 1606 + } 1607 + 1608 + ktime_t hrtimer_cb_get_time(const struct hrtimer *timer) 1609 + { 1610 + return __hrtimer_cb_get_time(timer->base->clockid); 1611 + } 1612 + EXPORT_SYMBOL_GPL(hrtimer_cb_get_time); 1583 1613 1584 1614 static void __hrtimer_setup(struct hrtimer *timer, 1585 1615 enum hrtimer_restart (*function)(struct hrtimer *),
-2
kernel/time/timer_list.c
··· 102 102 SEQ_printf(m, " .index: %d\n", base->index); 103 103 104 104 SEQ_printf(m, " .resolution: %u nsecs\n", hrtimer_resolution); 105 - 106 - SEQ_printf(m, " .get_time: %ps\n", base->get_time); 107 105 #ifdef CONFIG_HIGH_RES_TIMERS 108 106 SEQ_printf(m, " .offset: %Lu nsecs\n", 109 107 (unsigned long long) ktime_to_ns(base->offset));
-2
scripts/gdb/linux/timerlist.py
··· 56 56 text += " .index: {}\n".format(base['index']) 57 57 58 58 text += " .resolution: {} nsecs\n".format(constants.LX_hrtimer_resolution) 59 - 60 - text += " .get_time: {}\n".format(base['get_time']) 61 59 if constants.LX_CONFIG_HIGH_RES_TIMERS: 62 60 text += " .offset: {} nsecs\n".format(base['offset']) 63 61 text += "active timers:\n"