Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp637741imm; Thu, 31 May 2018 06:57:05 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJDbvo7G7AoCooz0o5xhLOGZRui6n3j0whe7NvfRGjjtlWyUhKYtfbhEI+PXQcn4cMXKkFZ X-Received: by 2002:a62:3a59:: with SMTP id h86-v6mr6918613pfa.209.1527775025478; Thu, 31 May 2018 06:57:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527775025; cv=none; d=google.com; s=arc-20160816; b=cN+Adpi+8QFTAzRdlEehy+yRBzudHK03Rw9ScCbFIOUjEstkNHXd2NRvTPAcH3OvEv B3q0kTviFK4ErBZ+OIkNbAg9PVCwGLfPvkLIM0NxzKKYVYyKIElitQKeDywifY+k1jEx oCLow5GRn/mnve3Qc90usDuMe0TB5KikQsFc1own/xps8PszvQqYo3wJpyQ9cYQF4560 TG0qs9iEHshFEFGRKPA2RlZCxlM2Bn3SE/Oyo7qZVeCbq+ZZuTQPZGrkmQ29+mz2j4Bd SJd88rB9q1s2N+bvOUlFCk/5ijWy7LElls8bNq2b3VHy75ehKcLnJKcIblk/qCWpVZPA XKvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=QHvCl8V049GWNlGxzXCgVz6n0oHk8UtuJqP7IR9+ELQ=; b=mhnEuYMf9S38DSz8LQsZk+uEj7gy2iiaNr1oRFMLpie2kpUb/uUByEl7/8H7KiDQWh j1VJ2PerqICFMsShRYmD7wjIyI/bfntgMAtC06kKn7SYyuToKF6hGDK9wXS8pNHNRG5f TfujpXNBxYYzvPN4tgQQ6jrw/tmUdXm3ERUgsXC00xezRhcQ5/5abBmVc7vYBRJicGf+ vcsubh1bBvujbbvQxFi1PKbh+kdnmOGogO3owo2hUePyHVwnxKowrKHkjabwurXCO6aX FxH+aVuAPWZbigfEuXK/HljrKhw8s4fLZWUoQgec0YI65Q4BK3mLETbF80IS87iNuZdm CMlA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e1-v6si29604939pgr.167.2018.05.31.06.56.51; Thu, 31 May 2018 06:57:05 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755383AbeEaNzr (ORCPT + 99 others); Thu, 31 May 2018 09:55:47 -0400 Received: from mx2.suse.de ([195.135.220.15]:54692 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755261AbeEaNzp (ORCPT ); Thu, 31 May 2018 09:55:45 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id F1778ABD0; Thu, 31 May 2018 13:55:43 +0000 (UTC) Date: Thu, 31 May 2018 15:55:42 +0200 From: Petr Mladek To: Feng Tang Cc: Ingo Molnar , Thomas Gleixner , "H . Peter Anvin" , Alan Cox , Peter Zijlstra , linux-kernel@vger.kernel.org, alek.du@intel.com Subject: Re: [RFC 2/2] x86, tsc: Enable clock for ealry printk timestamp Message-ID: <20180531135542.4j7w7bxsw43ydx3j@pathway.suse.cz> References: <1527672059-6225-1-git-send-email-feng.tang@intel.com> <1527672059-6225-2-git-send-email-feng.tang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1527672059-6225-2-git-send-email-feng.tang@intel.com> User-Agent: NeoMutt/20170421 (1.8.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 2018-05-30 17:20:59, Feng Tang wrote: > 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; I wonder if we could get some cleaner integration into the timer and printk code. I wonder if we could hide this under the existing timer interface. For example, local_clock() could provide values from this non-accurate timer and then transparently continue with the proper counting. The proper counting will not start from zero but from the offset reached by boot_tsc(). Best Regards, Petr > + 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 >