Re: [PATCH 8/8] hrtimer: Remove hrtimer_clock_base::get_time

From: Thomas Weißschuh
Date: Tue Aug 12 2025 - 03:51:25 EST


On Tue, Aug 12, 2025 at 09:42:46AM +0200, Peter Zijlstra wrote:
> On Tue, Aug 12, 2025 at 08:08:16AM +0200, Thomas Weißschuh wrote:
>
> > @@ -76,42 +77,34 @@ DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) =
> > {
> > .index = HRTIMER_BASE_MONOTONIC,
> > .clockid = CLOCK_MONOTONIC,
> > - .get_time = &ktime_get,
> > },
> > {
> > .index = HRTIMER_BASE_REALTIME,
> > .clockid = CLOCK_REALTIME,
> > - .get_time = &ktime_get_real,
> > },
> > {
> > .index = HRTIMER_BASE_BOOTTIME,
> > .clockid = CLOCK_BOOTTIME,
> > - .get_time = &ktime_get_boottime,
> > },
> > {
> > .index = HRTIMER_BASE_TAI,
> > .clockid = CLOCK_TAI,
> > - .get_time = &ktime_get_clocktai,
> > },
> > {
> > .index = HRTIMER_BASE_MONOTONIC_SOFT,
> > .clockid = CLOCK_MONOTONIC,
> > - .get_time = &ktime_get,
> > },
> > {
> > .index = HRTIMER_BASE_REALTIME_SOFT,
> > .clockid = CLOCK_REALTIME,
> > - .get_time = &ktime_get_real,
> > },
> > {
> > .index = HRTIMER_BASE_BOOTTIME_SOFT,
> > .clockid = CLOCK_BOOTTIME,
> > - .get_time = &ktime_get_boottime,
> > },
> > {
> > .index = HRTIMER_BASE_TAI_SOFT,
> > .clockid = CLOCK_TAI,
> > - .get_time = &ktime_get_clocktai,
> > },
> > },
> > .csd = CSD_INIT(retrigger_next_event, NULL)
> > @@ -1253,7 +1246,7 @@ static int __hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
> > remove_hrtimer(timer, base, true, force_local);
> >
> > if (mode & HRTIMER_MODE_REL)
> > - tim = ktime_add_safe(tim, base->get_time());
> > + tim = ktime_add_safe(tim, __hrtimer_cb_get_time(base->clockid));
> >
> > tim = hrtimer_update_lowres(timer, tim, mode);
> >
> > @@ -1588,6 +1581,29 @@ static inline int hrtimer_clockid_to_base(clockid_t clock_id)
> > }
> > }
> >
> > +static ktime_t __hrtimer_cb_get_time(clockid_t clock_id)
> > +{
> > + switch (clock_id) {
> > + case CLOCK_REALTIME:
> > + return ktime_get_real();
> > + case CLOCK_MONOTONIC:
> > + return ktime_get();
> > + case CLOCK_BOOTTIME:
> > + return ktime_get_boottime();
> > + case CLOCK_TAI:
> > + return ktime_get_clocktai();
>
> It would've been nice if these had the same order as the other array.

Yeah. This is the same order as in hrtimer_clockid_to_base(), right above
this function. I'll add a patch to reorder that one, too.

>
> > + default:
> > + WARN(1, "Invalid clockid %d. Using MONOTONIC\n", clock_id);
> > + return ktime_get();
> > + }
> > +}