public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@kernel.org>
To: "Bird, Tim" <Tim.Bird@sony.com>,
	"pmladek@suse.com" <pmladek@suse.com>,
	"rostedt@goodmis.org" <rostedt@goodmis.org>,
	"senozhatsky@chromium.org" <senozhatsky@chromium.org>,
	Shashank Balaji <shashankbalaji02@gmail.com>,
	"john.ogness@linutronix.de" <john.ogness@linutronix.de>
Cc: "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, 01 Apr 2026 01:36:26 +0200	[thread overview]
Message-ID: <87ldf78tc5.ffs@tglx> (raw)
In-Reply-To: <87jyus9xft.ffs@tglx>

Tim!

On Tue, Mar 31 2026 at 11:10, Thomas Gleixner wrote:
> So the real good question is whether the extra information of how long
> that earliest init takes is really relevant to the goal of optimizing
> boot time. The expensive part of the boot process definitely comes after
> that.

That actually made me curious and so I hacked up the kernel with the
patch below to compensate for the difference between:

  x86_64_start_reservations()

	i.e. the C entry point of the kernel and the actual earliest
	point (ASM entry code aside) where the kernel can take a
	timestamp, which is modulo the sanity checks in the PoC the same
	thing, right?

and

  tsc_early_init()

        where the upstream kernel enables TSC sched clock today with all
        sanity checks and enumeration in place.

Here is the result on a bare metal 256 CPU machine:

[    0.000000] Linux version 7.0.0-rc3-dirty ...

....

[    0.000000] tsc: Detected 2100.000 MHz processor
[    0.012482] e820: update [mem 0x00000000-0x00000fff] System RAM ==> device reserved

That's ~12ms of time which is not accounted for in the overall boot time
until the machine reaches the init process:

[   12.289141] Run /init as init process

That means we are talking about ~0.1% of overall boot time in this case.

Starting a 4 CPU guest with the same kernel image on the same physical
machine and additionally 'no-kvmclock' on the command line to make the
hack work:

[    0.000000] Linux version 7.0.0-rc3-dirty ...

...

[    0.000000] tsc: Detected 2094.965 MHz processor
[    0.015122] last_pfn = 0x280000 max_arch_pfn = 0x400000000

Unsurpringly it takes a bit longer because during that phase the guest
takes a gazillion of vmexits.

[    0.995082] Run /init as init process

Now in this 4 CPU case we are talking about 1.5% of the overall boot
time.

With the same setup and 32 CPUs in the VM:

[    0.015150] e820: remove [mem 0x000a0000-0x000fffff] System RAM

The initial phase takes 30us more than with 4 CPUs, which is in the
noise and the machine ends up in init at:

[    3.329398] Run /init as init process

which means in total we are up to 0.45% of the overall boot time now.

I'm honestly confused. May I politely ask which problem you are trying
to solve?

Thanks,

        tglx
---
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -291,6 +291,8 @@ asmlinkage __visible void __init __noret
 	x86_64_start_reservations(real_mode_data);
 }
 
+extern u64 start_ts;
+
 void __init __noreturn x86_64_start_reservations(char *real_mode_data)
 {
 	/* version is always not zero if it is copied */
@@ -307,6 +309,8 @@ void __init __noreturn x86_64_start_rese
 		break;
 	}
 
+	start_ts = rdtsc();
+
 	start_kernel();
 }
 
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -53,6 +53,9 @@ static DEFINE_STATIC_KEY_FALSE_RO(__use_
 
 int tsc_clocksource_reliable;
 
+extern u64 start_ts;
+u64 start_ts;
+
 static int __read_mostly tsc_force_recalibrate;
 
 static struct clocksource_base art_base_clk = {
@@ -207,7 +210,7 @@ static void __init cyc2ns_init_boot_cpu(
 	struct cyc2ns *c2n = this_cpu_ptr(&cyc2ns);
 
 	seqcount_latch_init(&c2n->seq);
-	__set_cyc2ns_scale(tsc_khz, smp_processor_id(), rdtsc());
+	__set_cyc2ns_scale(tsc_khz, smp_processor_id(), start_ts);
 }
 
 /*


  reply	other threads:[~2026-03-31 23:36 UTC|newest]

Thread overview: 54+ 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
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-03-30 20:42         ` Bird, Tim
2026-03-31  8:17           ` Geert Uytterhoeven
2026-03-31  9:10           ` Thomas Gleixner
2026-03-31 23:36             ` Thomas Gleixner [this message]
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=87ldf78tc5.ffs@tglx \
    --to=tglx@kernel.org \
    --cc=Tim.Bird@sony.com \
    --cc=francesco@valla.it \
    --cc=geert@linux-m68k.org \
    --cc=john.ogness@linutronix.de \
    --cc=linux-embedded@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmladek@suse.com \
    --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