From: Feng Tang <feng.tang@intel.com>
To: Petr Mladek <pmladek@suse.com>, Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
"H . Peter Anvin" <hpa@zytor.com>,
Alan Cox <gnomes@lxorguk.ukuu.org.uk>,
Peter Zijlstra <peterz@infradead.org>,
linux-kernel@vger.kernel.org
Cc: alek.du@intel.com, Feng Tang <feng.tang@intel.com>
Subject: [RFC 2/2] x86, tsc: Enable clock for ealry printk timestamp
Date: Wed, 30 May 2018 17:20:59 +0800 [thread overview]
Message-ID: <1527672059-6225-2-git-send-email-feng.tang@intel.com> (raw)
In-Reply-To: <1527672059-6225-1-git-send-email-feng.tang@intel.com>
To show time info in kernel log earlier and help optimizing kernel
boot time, printk adds a debug hook "boot_printk_clock_fn()" for
capable platform which has accurate clock in early boot phase.
This patch will add early param setup option, so that user can
chose to provide a tsc based early printk clock simply by adding
in command line: "boot_tsc=xxxxM" (xxxxM is the stable TSC freq).
Signed-off-by: Feng Tang <feng.tang@intel.com>
---
arch/x86/kernel/tsc.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 74392d9..d99eb70 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -281,6 +281,57 @@ static int __init tsc_setup(char *str)
__setup("tsc=", tsc_setup);
+
+/*
+ * This is to provide a not-so-accurate clock for printk timestamp in
+ * early boot phase (before sched_clock is setup).It could be used for
+ * analyzing/optimising kernel boot time and tools like bootchart.
+ *
+ * User can use it by simply append something like
+ * "boot_tsc=1881M"
+ * to cmdline for a platform with a stable 1881MHz TSC.
+ */
+static u64 boot_tsc_mhz;
+static u64 boot_tsc_offset;
+
+static u64 boot_tsc_clock(void)
+{
+ u64 cur_tsc, cur_ns;
+
+ cur_tsc = rdtsc();
+ cur_tsc -= boot_tsc_offset;
+
+ /* return value in ns */
+ cur_ns = div64_u64(cur_tsc * 1000, boot_tsc_mhz);
+ return cur_ns;
+}
+
+static int __init boot_tsc_setup(char *p)
+{
+ u64 tsc_hz;
+
+ if (!p)
+ return -EINVAL;
+
+ boot_tsc_offset = rdtsc();
+
+ tsc_hz = memparse(p, &p);
+ boot_tsc_mhz = div64_u64(tsc_hz, 1024 * 1024);
+ if (boot_tsc_mhz == 0)
+ return -EINVAL;
+
+ pr_info("TSC has run for %lld us\n",
+ div64_u64(boot_tsc_offset, boot_tsc_mhz));
+
+ /* Setup the early printk clock */
+ boot_printk_clock_fn = boot_tsc_clock;
+ pr_info("TSC: Setup early printk timestamp with %lldM TSC.",
+ boot_tsc_mhz);
+
+ return 0;
+}
+early_param("boot_tsc", boot_tsc_setup);
+
#define MAX_RETRIES 5
#define SMI_TRESHOLD 50000
--
2.7.4
next prev parent reply other threads:[~2018-05-30 9:20 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-30 9:20 [RFC 1/2] printk: Enable platform to provide a early boot clock Feng Tang
2018-05-30 9:20 ` Feng Tang [this message]
2018-05-30 13:25 ` [RFC 2/2] x86, tsc: Enable clock for ealry printk timestamp Andy Shevchenko
2018-05-30 14:17 ` Feng Tang
2018-05-31 13:55 ` Petr Mladek
2018-05-31 15:52 ` Peter Zijlstra
2018-06-01 16:12 ` Feng Tang
2018-06-06 9:38 ` Feng Tang
2018-06-06 15:25 ` Pavel Tatashin
2018-06-07 1:34 ` Feng Tang
2018-06-13 7:29 ` Feng Tang
2018-06-01 18:05 ` Pavel Tatashin
2018-05-31 7:18 ` [RFC 1/2] printk: Enable platform to provide a early boot clock Andy Shevchenko
2018-05-31 17:22 ` Randy Dunlap
2018-05-31 18:15 ` Andy Shevchenko
2018-06-14 8:38 ` Feng Tang
2018-06-14 9:08 ` Thomas Gleixner
2018-06-14 9:55 ` Feng Tang
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=1527672059-6225-2-git-send-email-feng.tang@intel.com \
--to=feng.tang@intel.com \
--cc=alek.du@intel.com \
--cc=gnomes@lxorguk.ukuu.org.uk \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®