* Re: [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot
2026-04-10 20:37 ` [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot Tim Bird
@ 2026-04-12 10:10 ` kernel test robot
2026-04-13 17:58 ` Bird, Tim
2026-04-12 11:12 ` kernel test robot
` (3 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: kernel test robot @ 2026-04-12 10:10 UTC (permalink / raw)
To: Tim Bird, pmladek, rostedt, john.ogness, senozhatsky
Cc: oe-kbuild-all, francesco, geert, tglx, shashankbalaji02,
linux-embedded, linux-kernel, Tim Bird
Hi Tim,
kernel test robot noticed the following build warnings:
[auto build test WARNING on linus/master]
[also build test WARNING on v7.0-rc7 next-20260410]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Tim-Bird/printk-fix-zero-valued-printk-timestamps-in-early-boot/20260412-134726
base: linus/master
patch link: https://lore.kernel.org/r/20260410203741.997410-2-tim.bird%40sony.com
patch subject: [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot
config: arm64-allnoconfig (https://download.01.org/0day-ci/archive/20260412/202604121822.OvOLcTnO-lkp@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260412/202604121822.OvOLcTnO-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202604121822.OvOLcTnO-lkp@intel.com/
All warnings (new ones prefixed by >>):
In file included from kernel/printk/printk.c:49:
include/linux/early_times.h: In function 'early_times_ns':
>> include/linux/early_times.h:45:61: warning: division by zero [-Wdiv-by-zero]
45 | return (early_unsafe_cycles() * NS_PER_KHZ) / CONFIG_EARLY_CYCLES_KHZ;
| ^
vim +45 include/linux/early_times.h
34
35 /* returns a nanosecond value based on early cycles */
36 static inline u64 early_times_ns(void)
37 {
38 if (CONFIG_EARLY_CYCLES_KHZ)
39 /*
40 * Note: the multiply must precede the division to avoid
41 * truncation and loss of resolution
42 * Don't use fancier MULT/SHIFT math here. Since this is
43 * static, the compiler can optimize the math operations.
44 */
> 45 return (early_unsafe_cycles() * NS_PER_KHZ) / CONFIG_EARLY_CYCLES_KHZ;
46 return 0;
47 }
48 #else
49 static inline u64 early_times_ns(void)
50 {
51 return 0;
52 }
53 #endif
54
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 12+ messages in thread* RE: [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot
2026-04-12 10:10 ` kernel test robot
@ 2026-04-13 17:58 ` Bird, Tim
2026-04-13 20:17 ` David Laight
2026-04-14 22:48 ` Thomas Gleixner
0 siblings, 2 replies; 12+ messages in thread
From: Bird, Tim @ 2026-04-13 17:58 UTC (permalink / raw)
To: kernel test robot, pmladek@suse.com, rostedt@goodmis.org,
john.ogness@linutronix.de, senozhatsky@chromium.org
Cc: oe-kbuild-all@lists.linux.dev, francesco@valla.it,
geert@linux-m68k.org, tglx@kernel.org, shashankbalaji02@gmail.com,
linux-embedded@vger.kernel.org, linux-kernel@vger.kernel.org
Hmmm,
This is a false positive warning from the compiler (see below).
I apologize for not catching it. I did test with CONFIG_EARLY_CYCLES=0
and I'm not sure why I didn't see the warning.
I'll see if I can silence this warning.
> -----Original Message-----
> From: kernel test robot <lkp@intel.com>
> Sent: Sunday, April 12, 2026 4:11 AM
> Hi Tim,
>
> kernel test robot noticed the following build warnings:
>
> [auto build test WARNING on linus/master]
> [also build test WARNING on v7.0-rc7 next-20260410]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
>
> url: https://github.com/intel-lab-lkp/linux/commits/Tim-Bird/printk-fix-zero-valued-printk-timestamps-in-early-boot/20260412-134726
> base: linus/master
> patch link: https://lore.kernel.org/r/20260410203741.997410-2-tim.bird%40sony.com
> patch subject: [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot
> config: arm64-allnoconfig (https://download.01.org/0day-ci/archive/20260412/202604121822.OvOLcTnO-lkp@intel.com/config)
> compiler: aarch64-linux-gcc (GCC) 15.2.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260412/202604121822.OvOLcTnO-lkp@intel.com/reproduce)
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202604121822.OvOLcTnO-lkp@intel.com/
>
> All warnings (new ones prefixed by >>):
>
> In file included from kernel/printk/printk.c:49:
> include/linux/early_times.h: In function 'early_times_ns':
> >> include/linux/early_times.h:45:61: warning: division by zero [-Wdiv-by-zero]
> 45 | return (early_unsafe_cycles() * NS_PER_KHZ) / CONFIG_EARLY_CYCLES_KHZ;
> | ^
>
>
> vim +45 include/linux/early_times.h
>
> 34
> 35 /* returns a nanosecond value based on early cycles */
> 36 static inline u64 early_times_ns(void)
> 37 {
> 38 if (CONFIG_EARLY_CYCLES_KHZ)
> 39 /*
> 40 * Note: the multiply must precede the division to avoid
> 41 * truncation and loss of resolution
> 42 * Don't use fancier MULT/SHIFT math here. Since this is
> 43 * static, the compiler can optimize the math operations.
> 44 */
> > 45 return (early_unsafe_cycles() * NS_PER_KHZ) / CONFIG_EARLY_CYCLES_KHZ;
Based on this conditional, it's not possible for CONFIG_EARLY_CYCLES_KHZ to be zero
on this line of code. Does GCC not catch this?
if (0)
x = <some expression>/0;
So this is a false positive.
> 46 return 0;
> 47 }
> 48 #else
> 49 static inline u64 early_times_ns(void)
> 50 {
> 51 return 0;
> 52 }
> 53 #endif
> 54
>
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot
2026-04-13 17:58 ` Bird, Tim
@ 2026-04-13 20:17 ` David Laight
2026-04-14 22:48 ` Thomas Gleixner
1 sibling, 0 replies; 12+ messages in thread
From: David Laight @ 2026-04-13 20:17 UTC (permalink / raw)
To: Bird, Tim
Cc: kernel test robot, pmladek@suse.com, rostedt@goodmis.org,
john.ogness@linutronix.de, senozhatsky@chromium.org,
oe-kbuild-all@lists.linux.dev, francesco@valla.it,
geert@linux-m68k.org, tglx@kernel.org, shashankbalaji02@gmail.com,
linux-embedded@vger.kernel.org, linux-kernel@vger.kernel.org
On Mon, 13 Apr 2026 17:58:34 +0000
"Bird, Tim" <Tim.Bird@sony.com> wrote:
> Hmmm,
>
> This is a false positive warning from the compiler (see below).
>
> I apologize for not catching it. I did test with CONFIG_EARLY_CYCLES=0
> and I'm not sure why I didn't see the warning.
>
> I'll see if I can silence this warning.
>
> > -----Original Message-----
> > From: kernel test robot <lkp@intel.com>
> > Sent: Sunday, April 12, 2026 4:11 AM
> > Hi Tim,
> >
> > kernel test robot noticed the following build warnings:
> >
> > [auto build test WARNING on linus/master]
> > [also build test WARNING on v7.0-rc7 next-20260410]
> > [If your patch is applied to the wrong git tree, kindly drop us a note.
> > And when submitting patch, we suggest to use '--base' as documented in
> > https://git-scm.com/docs/git-format-patch#_base_tree_information]
> >
> > url: https://github.com/intel-lab-lkp/linux/commits/Tim-Bird/printk-fix-zero-valued-printk-timestamps-in-early-boot/20260412-134726
> > base: linus/master
> > patch link: https://lore.kernel.org/r/20260410203741.997410-2-tim.bird%40sony.com
> > patch subject: [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot
> > config: arm64-allnoconfig (https://download.01.org/0day-ci/archive/20260412/202604121822.OvOLcTnO-lkp@intel.com/config)
> > compiler: aarch64-linux-gcc (GCC) 15.2.0
> > reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260412/202604121822.OvOLcTnO-lkp@intel.com/reproduce)
> >
> > If you fix the issue in a separate patch/commit (i.e. not just a new version of
> > the same patch/commit), kindly add following tags
> > | Reported-by: kernel test robot <lkp@intel.com>
> > | Closes: https://lore.kernel.org/oe-kbuild-all/202604121822.OvOLcTnO-lkp@intel.com/
> >
> > All warnings (new ones prefixed by >>):
> >
> > In file included from kernel/printk/printk.c:49:
> > include/linux/early_times.h: In function 'early_times_ns':
> > >> include/linux/early_times.h:45:61: warning: division by zero [-Wdiv-by-zero]
> > 45 | return (early_unsafe_cycles() * NS_PER_KHZ) / CONFIG_EARLY_CYCLES_KHZ;
> > | ^
> >
> >
> > vim +45 include/linux/early_times.h
> >
> > 34
> > 35 /* returns a nanosecond value based on early cycles */
> > 36 static inline u64 early_times_ns(void)
> > 37 {
> > 38 if (CONFIG_EARLY_CYCLES_KHZ)
> > 39 /*
> > 40 * Note: the multiply must precede the division to avoid
> > 41 * truncation and loss of resolution
> > 42 * Don't use fancier MULT/SHIFT math here. Since this is
> > 43 * static, the compiler can optimize the math operations.
> > 44 */
> > > 45 return (early_unsafe_cycles() * NS_PER_KHZ) / CONFIG_EARLY_CYCLES_KHZ;
> Based on this conditional, it's not possible for CONFIG_EARLY_CYCLES_KHZ to be zero
> on this line of code. Does GCC not catch this?
> if (0)
> x = <some expression>/0;
>
> So this is a false positive.
I suspect the warning is being generated before the optimiser throws
the code away as unreachable.
You might have to do:
return (early_unsafe_cycles() * NS_PER_KHZ) / (CONFIG_EARLY_CYCLES_KHZ ?: 1);
David
>
> > 46 return 0;
> > 47 }
> > 48 #else
> > 49 static inline u64 early_times_ns(void)
> > 50 {
> > 51 return 0;
> > 52 }
> > 53 #endif
> > 54
> >
> > --
> > 0-DAY CI Kernel Test Service
> > https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 12+ messages in thread* RE: [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot
2026-04-13 17:58 ` Bird, Tim
2026-04-13 20:17 ` David Laight
@ 2026-04-14 22:48 ` Thomas Gleixner
1 sibling, 0 replies; 12+ messages in thread
From: Thomas Gleixner @ 2026-04-14 22:48 UTC (permalink / raw)
To: Bird, Tim, kernel test robot, pmladek@suse.com,
rostedt@goodmis.org, john.ogness@linutronix.de,
senozhatsky@chromium.org
Cc: oe-kbuild-all@lists.linux.dev, francesco@valla.it,
geert@linux-m68k.org, shashankbalaji02@gmail.com,
linux-embedded@vger.kernel.org, linux-kernel@vger.kernel.org
On Mon, Apr 13 2026 at 17:58, Tim Bird wrote:
> This is a false positive warning from the compiler (see below).
This is _NOT_ a false positive warning. The compiler is absolutely
correct.
>> 34
>> 35 /* returns a nanosecond value based on early cycles */
>> 36 static inline u64 early_times_ns(void)
>> 37 {
>> 38 if (CONFIG_EARLY_CYCLES_KHZ)
>> 39 /*
>> 40 * Note: the multiply must precede the division to avoid
>> 41 * truncation and loss of resolution
>> 42 * Don't use fancier MULT/SHIFT math here. Since this is
>> 43 * static, the compiler can optimize the math operations.
>> 44 */
>> > 45 return (early_unsafe_cycles() * NS_PER_KHZ) / CONFIG_EARLY_CYCLES_KHZ;
> Based on this conditional, it's not possible for CONFIG_EARLY_CYCLES_KHZ to be zero
> on this line of code. Does GCC not catch this?
> if (0)
> x = <some expression>/0;
>
> So this is a false positive.
You clearly fail to understand how compilers work. The dead code
elimination happens _after_ the evaluation of the code and the compiler
does not care whether your initial condition evaluated to false or
not. That's documented compiler behaviour,
Whether GCC complains about it or not is completely irrelevant.
> I'll see if I can silence this warning.
Don't put much effort into it. This whole hack is going nowhere.
Thanks,
tglx
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot
2026-04-10 20:37 ` [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot Tim Bird
2026-04-12 10:10 ` kernel test robot
@ 2026-04-12 11:12 ` kernel test robot
2026-04-12 12:55 ` kernel test robot
` (2 subsequent siblings)
4 siblings, 0 replies; 12+ messages in thread
From: kernel test robot @ 2026-04-12 11:12 UTC (permalink / raw)
To: Tim Bird, pmladek, rostedt, john.ogness, senozhatsky
Cc: llvm, oe-kbuild-all, francesco, geert, tglx, shashankbalaji02,
linux-embedded, linux-kernel, Tim Bird
Hi Tim,
kernel test robot noticed the following build warnings:
[auto build test WARNING on linus/master]
[also build test WARNING on v7.0-rc7 next-20260410]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Tim-Bird/printk-fix-zero-valued-printk-timestamps-in-early-boot/20260412-134726
base: linus/master
patch link: https://lore.kernel.org/r/20260410203741.997410-2-tim.bird%40sony.com
patch subject: [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot
config: um-defconfig (https://download.01.org/0day-ci/archive/20260412/202604121907.nsngvl5u-lkp@intel.com/config)
compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project ae825cb8cea7f3ac8e5e4096f22713845cf5e501)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260412/202604121907.nsngvl5u-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202604121907.nsngvl5u-lkp@intel.com/
All warnings (new ones prefixed by >>):
In file included from kernel/printk/printk.c:49:
include/linux/early_times.h:20:9: error: call to undeclared function 'rdtsc'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
20 | return rdtsc();
| ^
>> include/linux/early_times.h:45:47: warning: division by zero is undefined [-Wdivision-by-zero]
45 | return (early_unsafe_cycles() * NS_PER_KHZ) / CONFIG_EARLY_CYCLES_KHZ;
| ^ ~~~~~~~~~~~~~~~~~~~~~~~
1 warning and 1 error generated.
vim +45 include/linux/early_times.h
34
35 /* returns a nanosecond value based on early cycles */
36 static inline u64 early_times_ns(void)
37 {
38 if (CONFIG_EARLY_CYCLES_KHZ)
39 /*
40 * Note: the multiply must precede the division to avoid
41 * truncation and loss of resolution
42 * Don't use fancier MULT/SHIFT math here. Since this is
43 * static, the compiler can optimize the math operations.
44 */
> 45 return (early_unsafe_cycles() * NS_PER_KHZ) / CONFIG_EARLY_CYCLES_KHZ;
46 return 0;
47 }
48 #else
49 static inline u64 early_times_ns(void)
50 {
51 return 0;
52 }
53 #endif
54
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot
2026-04-10 20:37 ` [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot Tim Bird
2026-04-12 10:10 ` kernel test robot
2026-04-12 11:12 ` kernel test robot
@ 2026-04-12 12:55 ` kernel test robot
2026-04-14 7:03 ` Geert Uytterhoeven
2026-04-14 22:38 ` Thomas Gleixner
4 siblings, 0 replies; 12+ messages in thread
From: kernel test robot @ 2026-04-12 12:55 UTC (permalink / raw)
To: Tim Bird, pmladek, rostedt, john.ogness, senozhatsky
Cc: llvm, oe-kbuild-all, francesco, geert, tglx, shashankbalaji02,
linux-embedded, linux-kernel, Tim Bird
Hi Tim,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on v7.0-rc7 next-20260410]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Tim-Bird/printk-fix-zero-valued-printk-timestamps-in-early-boot/20260412-134726
base: linus/master
patch link: https://lore.kernel.org/r/20260410203741.997410-2-tim.bird%40sony.com
patch subject: [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot
config: um-defconfig (https://download.01.org/0day-ci/archive/20260412/202604122037.R14cnXpl-lkp@intel.com/config)
compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project ae825cb8cea7f3ac8e5e4096f22713845cf5e501)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260412/202604122037.R14cnXpl-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202604122037.R14cnXpl-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from kernel/printk/printk.c:49:
>> include/linux/early_times.h:20:9: error: call to undeclared function 'rdtsc'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
20 | return rdtsc();
| ^
include/linux/early_times.h:45:47: warning: division by zero is undefined [-Wdivision-by-zero]
45 | return (early_unsafe_cycles() * NS_PER_KHZ) / CONFIG_EARLY_CYCLES_KHZ;
| ^ ~~~~~~~~~~~~~~~~~~~~~~~
1 warning and 1 error generated.
vim +/rdtsc +20 include/linux/early_times.h
10
11 #ifdef CONFIG_EARLY_CYCLES_KHZ
12 static inline u64 early_unsafe_cycles(void)
13 {
14 #if defined(CONFIG_X86_64)
15 /*
16 * This rdtsc may happen before secure TSC is initialized, and
17 * it is unordered. So please don't use this value for cryptography
18 * or after SMP is initialized.
19 */
> 20 return rdtsc();
21 #elif defined(CONFIG_ARM64)
22 return read_sysreg(cntvct_el0);
23 #elif defined(CONFIG_RISCV_TIMER)
24 u64 val;
25
26 asm volatile("rdtime %0" : "=r"(val));
27 return val;
28 #else
29 return 0;
30 #endif
31 }
32
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot
2026-04-10 20:37 ` [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot Tim Bird
` (2 preceding siblings ...)
2026-04-12 12:55 ` kernel test robot
@ 2026-04-14 7:03 ` Geert Uytterhoeven
2026-04-14 9:51 ` Roberto A. Foglietta
2026-04-14 22:38 ` Thomas Gleixner
4 siblings, 1 reply; 12+ messages in thread
From: Geert Uytterhoeven @ 2026-04-14 7:03 UTC (permalink / raw)
To: Tim Bird
Cc: pmladek, rostedt, john.ogness, senozhatsky, francesco, tglx,
shashankbalaji02, linux-embedded, linux-kernel
Hi Tim,
Thanks for your patch!
On Fri, 10 Apr 2026 at 22:38, Tim Bird <tim.bird@sony.com> wrote:
> During early boot, printk timestamps are reported as zero before
> kernel timekeeping starts (i.e. before time_init()). This
> hinders boot-time optimization efforts. This period ranges from
> 17 to 1700 milliseconds on different embedded machines running Linux.
>
> Add support for early timestamps based on processor cycle-generators
> that need no kernel initialization. Use a statically-configured
> frequency value for converting cycles to nanoseconds. This means
> that this feature cannot be turned on in generic distro kernels.
> It is intended for temporary use during kernel development and
> boot-time research and optimization only.
>
> This yields non-zero timestamps for printks from the very start
> of kernel execution. The timestamps are relative to the start of
> an architecture-specific counter (e.g. tsc on x86_64 and cntvct_el0
> on arm64). Affected timestamps reflect time from cycle counter
> init (usually machine power-on or virtual machine start) instead of
> time from the kernel's timekeeping initialization. This results in a
> discontinuity in the printk timestamp values, one time, when
> kernel timekeeping starts.
Won't it be hard to see where the discontinuity happens in some cases?
Perhaps this can be made more obvious by not doing the time conversion
in kernelspace, like in your first version?
> Signed-off-by: Tim Bird <tim.bird@sony.com>
> --- /dev/null
> +++ b/include/linux/early_times.h
> +/* returns a nanosecond value based on early cycles */
> +static inline u64 early_times_ns(void)
> +{
> + if (CONFIG_EARLY_CYCLES_KHZ)
> + /*
> + * Note: the multiply must precede the division to avoid
> + * truncation and loss of resolution
> + * Don't use fancier MULT/SHIFT math here. Since this is
> + * static, the compiler can optimize the math operations.
> + */
> + return (early_unsafe_cycles() * NS_PER_KHZ) / CONFIG_EARLY_CYCLES_KHZ;
Still, this contains a 64-by-32 division, so let's see how this works
out on 32-bit (RISCV_TIMER is set on rv32!). If the compiler would
generate a function call to a libgcc helper, you will have to switch
to the mul_u64_u32_div() helper...
> + return 0;
> +}
> +#else
> +static inline u64 early_times_ns(void)
> +{
> + return 0;
> +}
> +#endif
> +
> +#endif /* _EARLY_TIMES_H */
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot
2026-04-14 7:03 ` Geert Uytterhoeven
@ 2026-04-14 9:51 ` Roberto A. Foglietta
0 siblings, 0 replies; 12+ messages in thread
From: Roberto A. Foglietta @ 2026-04-14 9:51 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Tim Bird, pmladek, rostedt, john.ogness, senozhatsky, francesco,
tglx, shashankbalaji02, linux-embedded, linux-kernel
On Tue, 14 Apr 2026 at 09:03, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>
> Hi Tim,
>
> Thanks for your patch!
>
> On Fri, 10 Apr 2026 at 22:38, Tim Bird <tim.bird@sony.com> wrote:
> > During early boot, printk timestamps are reported as zero before
> > kernel timekeeping starts (i.e. before time_init()). This
...
> Won't it be hard to see where the discontinuity happens in some cases?
> Perhaps this can be made more obvious by not doing the time conversion
> in kernelspace, like in your first version?
>
> > Signed-off-by: Tim Bird <tim.bird@sony.com>
>
> > --- /dev/null
> > +++ b/include/linux/early_times.h
>
> > +/* returns a nanosecond value based on early cycles */
> > +static inline u64 early_times_ns(void)
> > +{
> > + if (CONFIG_EARLY_CYCLES_KHZ)
> > + /*
> > + * Note: the multiply must precede the division to avoid
> > + * truncation and loss of resolution
> > + * Don't use fancier MULT/SHIFT math here. Since this is
> > + * static, the compiler can optimize the math operations.
> > + */
> > + return (early_unsafe_cycles() * NS_PER_KHZ) / CONFIG_EARLY_CYCLES_KHZ;
>
> Still, this contains a 64-by-32 division, so let's see how this works
> out on 32-bit (RISCV_TIMER is set on rv32!). If the compiler would
> generate a function call to a libgcc helper, you will have to switch
> to the mul_u64_u32_div() helper...
Interesting.
https://github.com/robang74/uchaosys/blob/53e72d169/cnfg/printk-fix-early-boot-timestamps-patch-v4.txt#L92
Elvis the King (A?:), R-
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot
2026-04-10 20:37 ` [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot Tim Bird
` (3 preceding siblings ...)
2026-04-14 7:03 ` Geert Uytterhoeven
@ 2026-04-14 22:38 ` Thomas Gleixner
2026-04-15 0:19 ` Roberto A. Foglietta
4 siblings, 1 reply; 12+ messages in thread
From: Thomas Gleixner @ 2026-04-14 22:38 UTC (permalink / raw)
To: Tim Bird, pmladek, rostedt, john.ogness, senozhatsky
Cc: francesco, geert, shashankbalaji02, linux-embedded, linux-kernel,
Tim Bird
On Fri, Apr 10 2026 at 14:37, Tim Bird wrote:
> +
> +#include <linux/timekeeping.h>
> +#ifdef CONFIG_ARM64
> +#include <asm/sysreg.h>
> +#endif
> +
> +#ifdef CONFIG_EARLY_CYCLES_KHZ
> +static inline u64 early_unsafe_cycles(void)
> +{
> +#if defined(CONFIG_X86_64)
> + /*
> + * This rdtsc may happen before secure TSC is initialized, and
> + * it is unordered. So please don't use this value for cryptography
> + * or after SMP is initialized.
> + */
> + return rdtsc();
> +#elif defined(CONFIG_ARM64)
> + return read_sysreg(cntvct_el0);
> +#elif defined(CONFIG_RISCV_TIMER)
> + u64 val;
> +
> + asm volatile("rdtime %0" : "=r"(val));
> + return val;
> +#else
> + return 0;
> +#endif
> +}
No. Generic code and generic headers have no business to implement any
architecture specific code and there is zero justification for
architecture specific #ifdefs in generic code.
Ask your favourite AI assistant for an opinion.
> +#define NS_PER_KHZ 1000000UL
The existing nomenclature for nanosecond related constants is NSEC_*
> +
> +/* returns a nanosecond value based on early cycles */
> +static inline u64 early_times_ns(void)
> +{
> + if (CONFIG_EARLY_CYCLES_KHZ)
> + /*
> + * Note: the multiply must precede the division to avoid
> + * truncation and loss of resolution
> + * Don't use fancier MULT/SHIFT math here. Since this is
> + * static, the compiler can optimize the math operations.
> + */
> + return (early_unsafe_cycles() * NS_PER_KHZ) / CONFIG_EARLY_CYCLES_KHZ;
This code will result in a division by zero warning from any reasonable
compiler because this is evaluated _before_ it is eliminated.
> @@ -2294,6 +2295,8 @@ int vprintk_store(int facility, int level,
> * timestamp with respect to the caller.
> */
> ts_nsec = local_clock();
> + if (unlikely(!ts_nsec))
> + ts_nsec = early_times_ns();
I explained to you how this wants to be implemented to be useful and you
declared that you are unwilling to put the effort in.
My NAK for this disgusting and tasteless hack still applies.
Either you are willing to work with the community and the relevant
maintainers or you can keep your hackery maintained out of tree for
those who care about it and are willing to ignore the fallout.
Thanks,
tglx
^ permalink raw reply [flat|nested] 12+ messages in thread* Re: [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot
2026-04-14 22:38 ` Thomas Gleixner
@ 2026-04-15 0:19 ` Roberto A. Foglietta
0 siblings, 0 replies; 12+ messages in thread
From: Roberto A. Foglietta @ 2026-04-15 0:19 UTC (permalink / raw)
To: Thomas Gleixner
Cc: Tim Bird, pmladek, rostedt, john.ogness, senozhatsky, francesco,
geert, shashankbalaji02, linux-embedded, linux-kernel
On Wed, 15 Apr 2026 at 00:38, Thomas Gleixner <tglx@kernel.org> wrote:
>
> On Fri, Apr 10 2026 at 14:37, Tim Bird wrote:
> > +
> > +#include <linux/timekeeping.h>
> > +#ifdef CONFIG_ARM64
> > +#include <asm/sysreg.h>
> > +#endif
> > +
> > +#ifdef CONFIG_EARLY_CYCLES_KHZ
> > +static inline u64 early_unsafe_cycles(void)
> > +{
> > +#if defined(CONFIG_X86_64)
> > + /*
> > + * This rdtsc may happen before secure TSC is initialized, and
> > + * it is unordered. So please don't use this value for cryptography
> > + * or after SMP is initialized.
> > + */
> > + return rdtsc();
> > +#elif defined(CONFIG_ARM64)
> > + return read_sysreg(cntvct_el0);
> > +#elif defined(CONFIG_RISCV_TIMER)
> > + u64 val;
> > +
> > + asm volatile("rdtime %0" : "=r"(val));
> > + return val;
> > +#else
> > + return 0;
> > +#endif
> > +}
>
> No. Generic code and generic headers have no business to implement any
> architecture specific code and there is zero justification for
> architecture specific #ifdefs in generic code.
This translates in practice in early_unsafe_cycles() various
instances, one for each architecture supported. Even better a macro
for each architecture like this example below (untested code, just for
exemplification):
ts_nsec = local_clock();
#ifdef CONFIG_EARLY_CYCLES_KHZ
#if defined(CONFIG_ARM64)
#include <asm/sysreg.h>
#define early_unsafe_cycles read_sysreg(cntvct_el0);
#elif defined(CONFIG_X86_64)
#define early_unsafe_cycles rdtsc()
#elif defined(CONFIG_RISCV_TIMER)
#define early_unsafe_cycles ({ u64 val; asm volatile("rdtime %0" :
"=r"(val)); val; })
#else
#define early_unsafe_cycles 0
#endif
+ if (unlikely(!ts_nsec))
+ ts_nsec = early_times_ns();
#endif // CONFIG_EARLY_CYCLES_KHZ
caller_id = printk_caller_id();
While keeping architectures separate is for abstraction layer best
practice, in very specific cases abstraction can be a meaningless
concept or much less important than having a single file for a single
feature (the complementary way of organising stuff). Because in Linux
the abstraction layer approach applies for architectures, the gap
between aesthetic and a specific case like an early boot macros set
hack for debugging is to clarify the exception from the general rule
in the header itself.
On Wed, 15 Apr 2026 at 00:38, Thomas Gleixner <tglx@kernel.org> wrote: (to TIM)
>
> Ask your favourite AI assistant for an opinion.
(Roberto maintaining the cold blood in front of "Tim's overlooking a
false positive gcc warning" and check Thomas suggestion just for the
sake of curiosity)
Gemini Thinking AI: Whether or not you can justify this exception
depends entirely on whether this is a permanent feature or a transient
debug hack.
Cheers, R-
^ permalink raw reply [flat|nested] 12+ messages in thread