Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp4270929imm; Wed, 30 May 2018 02:22:11 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKLVUcZj76WTu6t+rz1VUPRTNTDKdqq16THtbb5UsSsMThhuFDaV4TDUDb5nwlPpcGIq/PX X-Received: by 2002:a63:6e4f:: with SMTP id j76-v6mr1590107pgc.16.1527672131830; Wed, 30 May 2018 02:22:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527672131; cv=none; d=google.com; s=arc-20160816; b=0CYrMPkmBt6IxKemWYkpebZbqnvapzDPFIlg3wdDifdSwGeDe4/bdpLGoessrQCTkk lZ5MlMz0WwwvD31ok3Y1RgmN3xYguy3+CKDHnTJA4CNroxEwMYdghIbec6mz2+TB51rQ 7b7FkZIsiIk9WsTzyKabal4YNK/EumVLrGEgfoq0hYicSoy6eUWfy57BF2dJ5ZBauPrR pa8nloP7Sv46PeaYcwZbuIIts9aH3Kju1oTXYdTEeWnjJB1BvRIzI/5GeXv+hGygaWhH 0RpIjeP3Y4flf/iTakiiQzvrajAr5JyWZIgXN5E4vrKK0QldGOAmhKCB5JNgOvdiIrsZ D+kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=tSsY94FUlTQEKBYnmizf9SgnFhuwcKl0IsfpcTFzYaY=; b=mC4EZTWDEmT31wzRBOLrQNEnfIJegIiz+VFxoWh2fg2Au7P2893BUpN5r38UI1SUrc x4oQcV/dLevMjxyORJcRj7DvTPXLhl3GtFxnoTznedFNBDFZEvq+p12bJSBZ0VQlDSO7 2XOty/hdnotOAS0CtJJCC66LDc8Yk5eBLTaLK9hlXpAM7YdHqyRQrTAVaMCALSxNzIGx Ga2vsLkSJTcUegzsTNu/BEwgK+XDAiQHO4cxz5cVqt4A9cI5UJL0gs/ck6bWpUD7O/CS ZSXV7AfMqYiO+/SnawJ9breVOQpJJctuQqqmhnoVzp2OujZwSmQXkxrhTsWUICDVo/Yk gjTQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i33-v6si33721553pld.546.2018.05.30.02.21.57; Wed, 30 May 2018 02:22:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S968880AbeE3JUl (ORCPT + 99 others); Wed, 30 May 2018 05:20:41 -0400 Received: from mga17.intel.com ([192.55.52.151]:22682 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S968864AbeE3JUi (ORCPT ); Wed, 30 May 2018 05:20:38 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 May 2018 02:20:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,459,1520924400"; d="scan'208";a="232890685" Received: from shbuild999.sh.intel.com ([10.239.146.218]) by fmsmga005.fm.intel.com with ESMTP; 30 May 2018 02:20:36 -0700 From: Feng Tang To: Petr Mladek , Ingo Molnar , Thomas Gleixner , "H . Peter Anvin" , Alan Cox , Peter Zijlstra , linux-kernel@vger.kernel.org Cc: alek.du@intel.com, Feng Tang Subject: [RFC 2/2] x86, tsc: Enable clock for ealry printk timestamp Date: Wed, 30 May 2018 17:20:59 +0800 Message-Id: <1527672059-6225-2-git-send-email-feng.tang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527672059-6225-1-git-send-email-feng.tang@intel.com> References: <1527672059-6225-1-git-send-email-feng.tang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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