llvm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [rfc, PATCH v1 1/1] hrtimers: Refactor hrtimer_clock_to_base_table initialisation
@ 2025-02-10  8:26 Andy Shevchenko
  2025-02-11 12:18 ` Andy Shevchenko
  2025-02-13 21:39 ` Thomas Gleixner
  0 siblings, 2 replies; 3+ messages in thread
From: Andy Shevchenko @ 2025-02-10  8:26 UTC (permalink / raw)
  To: Thomas Gleixner, linux-kernel, llvm
  Cc: Anna-Maria Behnsen, Frederic Weisbecker, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Andy Shevchenko

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@linux.intel.com>
---

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).
In any case this is an rfc, I would be glad if somebody fixes this in a better
way.

 kernel/time/hrtimer.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index deb1aa32814e..8ec6ff36b9ad 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -118,13 +118,21 @@ DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) =
 };
 
 static const int hrtimer_clock_to_base_table[MAX_CLOCKS] = {
-	/* Make sure we catch unsupported clockids */
-	[0 ... MAX_CLOCKS - 1]	= HRTIMER_MAX_CLOCK_BASES,
+	[CLOCK_REALTIME]			= HRTIMER_BASE_REALTIME,
+	[CLOCK_MONOTONIC]			= HRTIMER_BASE_MONOTONIC,
+	[CLOCK_PROCESS_CPUTIME_ID]		= HRTIMER_MAX_CLOCK_BASES,
+	[CLOCK_THREAD_CPUTIME_ID]		= HRTIMER_MAX_CLOCK_BASES,
+	[CLOCK_MONOTONIC_RAW]			= HRTIMER_MAX_CLOCK_BASES,
+	[CLOCK_REALTIME_COARSE]			= HRTIMER_MAX_CLOCK_BASES,
+	[CLOCK_MONOTONIC_COARSE]		= HRTIMER_MAX_CLOCK_BASES,
+	[CLOCK_BOOTTIME]			= HRTIMER_BASE_BOOTTIME,
+	[CLOCK_REALTIME_ALARM]			= HRTIMER_MAX_CLOCK_BASES,
+	[CLOCK_BOOTTIME_ALARM]			= HRTIMER_MAX_CLOCK_BASES,
+	[CLOCK_SGI_CYCLE]			= HRTIMER_MAX_CLOCK_BASES,
+	[CLOCK_TAI]				= HRTIMER_BASE_TAI,
 
-	[CLOCK_REALTIME]	= HRTIMER_BASE_REALTIME,
-	[CLOCK_MONOTONIC]	= HRTIMER_BASE_MONOTONIC,
-	[CLOCK_BOOTTIME]	= HRTIMER_BASE_BOOTTIME,
-	[CLOCK_TAI]		= HRTIMER_BASE_TAI,
+	/* Make sure we catch unsupported clockids */
+	[CLOCK_TAI + 1 ... MAX_CLOCKS - 1]	= HRTIMER_MAX_CLOCK_BASES,
 };
 
 static inline bool hrtimer_base_is_online(struct hrtimer_cpu_base *base)
-- 
2.45.1.3035.g276e886db78b


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [rfc, PATCH v1 1/1] hrtimers: Refactor hrtimer_clock_to_base_table initialisation
  2025-02-10  8:26 [rfc, PATCH v1 1/1] hrtimers: Refactor hrtimer_clock_to_base_table initialisation Andy Shevchenko
@ 2025-02-11 12:18 ` Andy Shevchenko
  2025-02-13 21:39 ` Thomas Gleixner
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2025-02-11 12:18 UTC (permalink / raw)
  To: Thomas Gleixner, linux-kernel, llvm
  Cc: Anna-Maria Behnsen, Frederic Weisbecker, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt

On Mon, Feb 10, 2025 at 10:26:02AM +0200, 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.

For the record, GCC also fails here.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [rfc, PATCH v1 1/1] hrtimers: Refactor hrtimer_clock_to_base_table initialisation
  2025-02-10  8:26 [rfc, PATCH v1 1/1] hrtimers: Refactor hrtimer_clock_to_base_table initialisation Andy Shevchenko
  2025-02-11 12:18 ` Andy Shevchenko
@ 2025-02-13 21:39 ` Thomas Gleixner
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Gleixner @ 2025-02-13 21:39 UTC (permalink / raw)
  To: Andy Shevchenko, linux-kernel, llvm
  Cc: Anna-Maria Behnsen, Frederic Weisbecker, Nathan Chancellor,
	Nick Desaulniers, Bill Wendling, Justin Stitt, Andy Shevchenko

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@linux.intel.com>
> ---
>
> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-02-13 21:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-10  8:26 [rfc, PATCH v1 1/1] hrtimers: Refactor hrtimer_clock_to_base_table initialisation Andy Shevchenko
2025-02-11 12:18 ` Andy Shevchenko
2025-02-13 21:39 ` Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).