Re: [rfc, PATCH v1 1/1] hrtimers: Refactor hrtimer_clock_to_base_table initialisation

From: Thomas Gleixner
Date: Thu Feb 13 2025 - 16:39:12 EST


On Mon, Feb 10 2025 at 10:26, Andy Shevchenko wrote:
> Clang complains about overlapped initialisers in the
> hrtimer_clock_to_base_table definition. With `make W=1` and
> CONFIG_WERROR=y (which is default nowadays) this breaks
> the build:
>
> CC kernel/time/hrtimer.o
> kernel/time/hrtimer.c:124:21: error: initializer overrides prior initialization of this subobject [-Werror,-Winitializer-overrides]
> 124 | [CLOCK_REALTIME] = HRTIMER_BASE_REALTIME,
>
> kernel/time/hrtimer.c:122:27: note: previous initialization is here
> 122 | [0 ... MAX_CLOCKS - 1] = HRTIMER_MAX_CLOCK_BASES,
>
> (and similar for CLOCK_MONOTONIC, CLOCK_BOOTTIME, and CLOCK_TAI).
>
> Refactor hrtimer_clock_to_base_table initialisation to make
> the compiler happy.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
> ---
>
> TBH, I don't like much this solution as it diminishes the point of that
> override to be there in the first place. I haven't found better alternatives
> as they may be too intrusive. Another one might be to remove this table,
> but in such case the replacement might add latency to some cases (although
> I haven't checked the generated code for, for example, switch-case approach).

The only place this table is used is in __hrtimer_init(), which is not a
hot-path. The four resulting comparisons are probably not even noticable.

Thanks,

tglx