From: Petr Mladek <pmladek@suse.com>
To: "Bird, Tim" <Tim.Bird@sony.com>
Cc: Shashank Balaji <shashankbalaji02@gmail.com>,
"rostedt@goodmis.org" <rostedt@goodmis.org>,
"john.ogness@linuxtronix.de" <john.ogness@linuxtronix.de>,
"senozhatsky@chromium.org" <senozhatsky@chromium.org>,
"francesco@valla.it" <francesco@valla.it>,
"geert@linux-m68k.org" <geert@linux-m68k.org>,
"linux-embedded@vger.kernel.org" <linux-embedded@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3] printk: fix zero-valued printk timestamps in early boot
Date: Wed, 11 Mar 2026 16:45:51 +0100 [thread overview]
Message-ID: <abGOL-sr7pMr3Ua_@pathway.suse.cz> (raw)
In-Reply-To: <SA1PR13MB5634C64991FD94776E9D3D82FD46A@SA1PR13MB5634.namprd13.prod.outlook.com>
On Tue 2026-03-10 18:54:22, Bird, Tim wrote:
> > From: Petr Mladek <pmladek@suse.com>
> > There are three stages:
> >
> > 1. Early messages where the cycles are stored.
> >
> > The serial console shows zero time stamp because
> > it reads the messages _before the calibration_, e.g.
> >
> > [ 0.000000] Linux version 6.19.0-rc7-default+ (pmladek@pathway) (gcc (SUSE Linux) 15.2.1 20251006, GNU ld (GNU Binutils;
> > openSUSE Tumbleweed) 2.45.0.20251103-2) #521 SMP PREEMPT_DYNAMIC Mon Feb 2 16:36:53 CET 2026
> > [ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-6.19.0-rc7-default+ root=UUID=587ae802-e330-4059-9b48-
> > d5b845e1075a resume=/dev/disk/by-uuid/369c7453-3d16-409d-88b2-5de027891a12 mitigations=auto nosplash
> > earlycon=uart8250,io,0x3f8,115200 console=ttyS0,115200 console=ttynull console=tty0 debug_non_panic_cpus=1 panic=10 ignore_loglevel
> > log_buf_len=1M
> > [ 0.000000] BIOS-provided physical RAM map:
> > [ 0.000000] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
> > [ 0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
> >
> > But "dmesg" shows some numbers because it reads the messages
> > _after the calibration_:
> >
> > [ 8.853613] Linux version 6.19.0-rc7-default+ (pmladek@pathway) (gcc (SUSE Linux) 15.2.1 20251006, GNU ld (GNU Binutils;
> > openSUSE Tumbleweed) 2.45.0.20251103-2) #521 SMP PREEMPT_DYNAMIC Mon Feb 2 16:36:53 CET 2026
> > [ 8.853617] Command line: BOOT_IMAGE=/boot/vmlinuz-6.19.0-rc7-default+ root=UUID=587ae802-e330-4059-9b48-
> > d5b845e1075a resume=/dev/disk/by-uuid/369c7453-3d16-409d-88b2-5de027891a12 mitigations=auto nosplash
> > earlycon=uart8250,io,0x3f8,115200 console=ttyS0,115200 console=ttynull console=tty0 debug_non_panic_cpus=1 panic=10 ignore_loglevel
> > log_buf_len=1M
> > [ 8.865086] BIOS-provided physical RAM map:
> > [ 8.865087] BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable
> > [ 8.865089] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved
> >
> >
> > 2. Early messages added _after the timekeeping_ is initialized
> > but _before the early cycles calibration_.
> >
> > They serial console prints them _without the offset_ because
> > it reads them _before the calibration_, e.g.
> >
> > [ 3.288049][ T1] Write protecting the kernel read-only data: 36864k
> > [ 3.298554][ T1] Freeing unused kernel image (text/rodata gap) memory: 1656K
> > [ 3.318942][ T1] Freeing unused kernel image (rodata/data gap) memory: 1540K
> >
> > But "dmesg" prints them _with the offset_ because it reads them
> > _after the calibration_, e.g.
> >
> > [ 12.179999] [ T1] Write protecting the kernel read-only data: 36864k
> > [ 12.190505] [ T1] Freeing unused kernel image (text/rodata gap) memory: 1656K
> > [ 12.210893] [ T1] Freeing unused kernel image (rodata/data gap) memory: 1540K
> >
> >
> > 3. Messages added after the calibration of the early cycles.
> >
> > They are printed with the offset by both serial console and
> > dmesg, e.g.
> >
> > [ 12.230014][ T1] Early printk times: mult=38775352, shift=27, offset=8891950261 ns
> > [ 12.246008][ T1] Run /init as init process
> > [ 12.254944][ T1] with arguments:
> > [ 12.264341][ T1] /init
>
> This is correct. I don't want to overwhelm users of this, but there are three time-gathering periods, and roughly
> 2 output times (before calibration and after calibration).
>
> early boot = before time init, before cycles calibration and offset calculation
> mid boot = after time init, before cycles calibration and offset calculation
> late boot = after time init, after cycles calibration and offset calculation
> All of these are before the start of user space processes.
>
> time of printk output time timestamp type stored timestamp output
> ------------------ ---------------- ----------------------------- ------------------------
> early boot early boot cycles 0
> mid boot mid-boot nanosecs seconds, with offset from time_init
> late boot late-boot nanosecs seconds with offset from cycle counter start
This is a bit confusing. I looks like the offset from time_init() is
not longer added.
> -----
> early boot post-boot (cycles already stored) seconds with offset from cycle counter start
> mid boot post-boot (ns already stored) seconds with offset from cycle counter start
> late boot post-boot (ns already stored) seconds with offset from cycle counter start
> all others post-boot nanosecs seconds with offset from cycle counter start
> The confusing thing is messages that are output to the console before calibration and offset calculation.
> Reports from all user space tools (ie from dmesg or journalctl) should be correct and consistent.
Yup.
I like that table. I just wonder how to better distinguish the offset from
timekeeping and calibrated cycles. My variant:
<proposal>
The printk timestamps are stored and interpretted differently in
the following periods:
- early boot: before timekeeping init, before cycles calibration
- mid boot: after timekeeping init, before cycles calibration
- late boot: after timekeeping init, after cycles calibration
Console output (immediately):
printk() time stored value immediate output(sec)
-----------------------------------------------------------------------------
early boot cycles 0
mid boot get_time() get_time()
late boot get_time() get_time + calibrated(cycles offset)
User space tools and late registered consoles:
printk() time stored value output after calibration (sec)
-----------------------------------------------------------------------------
early boot cycles calibrated(cycles)
mid boot get_time() get_time() + calibrated(cycles offset)
late boot get_time() get_time() + calibrated(cycles offset)
I am not sure where to put this. One place might be
Documentation/core-api/printk-basics.rst. But it might be better
add a separate file either under core-api/ or under admin-guide/.
> >
> > > An accessor can be implemented for (struct printk_info).ts_nsec, say
> > > get_timestamp(), which can be called from both the places.
> >
> > Yeah, a helper function for reading the timestamp might be a cleaner solution.
> >
> I consider adjust_early_ts() to be such an accessor function. It's supposed
> to hide the details of the type of the timestamp (cycles or ns) and
> the offset. Maybe this could be renamed to something better,
> like: get_adjusted_ts()? Let me know what you think.
This a bike shedding area ;-)
I personally find
u64 ts = get_printk_info_ts(info);
a bit cleaner than
u64 ts = adjust_early_ts(info->ts_nsec);
because you might add a comment into struct printk_info
definition that nobody should read the timestamp directly.
They should use the helper intead.
The helper would do something like:
/*
* The number of early cycles is stored before the timekeeping gets initialized.
* The local_clock() value is stored later.
*
* Note that early_ts_offset, early_mult, and early_shift are 0
* before the cycles get calibrated against the official time keeping.
*
* Any output after user space start (eg. from dmesg or journalctl)
* will show consistent values with calibrated cycles and offset.
*/
static inline u64 get_printk_info_ts(const struct printk_info *info)
{
if (likely(!(info->ts_cycles & EARLY_CYCLES_BIT)))
/* if timestamp is not in cycles, just add offset */
return info->ts_nsec + early_ts_offset;
/* mask high bit and convert to nanoseconds */
return mul_u64_u32_shr(info->ts_cycles & EARLY_CYCLES_MASK,
early_mult, early_shift);
}
Note that I have already used two names (ts_cycles and ts_nsec) which
would point to the same data via an union.
> I'll rebase this patch to resolve the #include conflicts, and address
> this feedback, and hopefully get a new version out this week.
Thanks a lot. v3 looked good enough to me. But v4 will be even better
after the feedback.
Take your time ;-)
Best Regards,
Petr
next prev parent reply other threads:[~2026-03-11 15:45 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-25 5:30 [PATCH] printk: add early_counter_ns routine for printk blind spot Tim Bird
2025-11-25 7:52 ` kernel test robot
2025-11-25 13:08 ` Francesco Valla
2025-11-26 7:38 ` Geert Uytterhoeven
2025-11-27 0:16 ` Bird, Tim
2025-11-27 16:16 ` Petr Mladek
2025-11-26 12:55 ` Petr Mladek
2025-11-27 0:03 ` Bird, Tim
2025-11-26 11:13 ` Petr Mladek
2025-11-27 9:13 ` kernel test robot
2026-01-24 19:40 ` [PATCH v2] printk: fix zero-valued printk timestamps in early boot Tim Bird
2026-01-25 14:41 ` Francesco Valla
2026-01-26 16:52 ` Bird, Tim
2026-02-02 16:23 ` Petr Mladek
2026-01-26 10:12 ` Geert Uytterhoeven
2026-01-26 17:11 ` Bird, Tim
2026-01-27 8:10 ` Geert Uytterhoeven
2026-02-10 23:47 ` [PATCH v3] " Tim Bird
2026-03-04 11:23 ` Petr Mladek
2026-03-09 17:27 ` Shashank Balaji
2026-03-10 10:43 ` Petr Mladek
2026-03-10 19:17 ` Bird, Tim
2026-03-09 19:25 ` Shashank Balaji
2026-03-10 11:39 ` Petr Mladek
2026-03-10 18:54 ` Bird, Tim
2026-03-11 15:45 ` Petr Mladek [this message]
2026-03-11 15:47 ` Michael Kelley
2026-03-13 4:52 ` Bird, Tim
2026-03-13 10:45 ` Petr Mladek
2026-03-14 14:16 ` Shashank Balaji
2026-03-24 20:07 ` Bird, Tim
2026-03-14 16:15 ` Michael Kelley
2026-03-24 19:47 ` Bird, Tim
2026-03-26 9:24 ` John Ogness
2026-03-27 18:04 ` Bird, Tim
2026-03-20 18:15 ` Bird, Tim
2026-03-28 15:56 ` Thomas Gleixner
2026-03-26 13:17 ` Thomas Gleixner
2026-03-27 18:48 ` Bird, Tim
2026-03-28 21:59 ` Thomas Gleixner
2026-03-29 22:42 ` Thomas Gleixner
2026-03-30 12:05 ` Peter Zijlstra
2026-03-30 13:38 ` David Laight
2026-04-07 20:34 ` Earlier tsc init patch (was RE: [PATCH v3] printk: fix zero-valued printk timestamps in early boot) Bird, Tim
2026-03-30 20:42 ` [PATCH v3] printk: fix zero-valued printk timestamps in early boot Bird, Tim
2026-03-31 8:17 ` Geert Uytterhoeven
2026-03-31 9:10 ` Thomas Gleixner
2026-03-31 23:36 ` Thomas Gleixner
2026-04-01 0:05 ` Steven Rostedt
2026-04-01 7:36 ` Geert Uytterhoeven
2026-04-01 8:33 ` Thomas Gleixner
2026-04-01 15:12 ` Steven Rostedt
2026-04-01 19:37 ` Thomas Gleixner
2026-04-01 1:16 ` Brian Masney
2026-04-01 9:19 ` Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=abGOL-sr7pMr3Ua_@pathway.suse.cz \
--to=pmladek@suse.com \
--cc=Tim.Bird@sony.com \
--cc=francesco@valla.it \
--cc=geert@linux-m68k.org \
--cc=john.ogness@linuxtronix.de \
--cc=linux-embedded@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=shashankbalaji02@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox