Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp965567imm; Wed, 6 Jun 2018 08:29:30 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKWzkYdrU2gvzMYG2v4/7u9X6MqsgULQWG4dy9hr0SCzeGMpLFjj/9omEqYceljuQKwGGnN X-Received: by 2002:a62:234a:: with SMTP id j71-v6mr2841749pfj.221.1528298970055; Wed, 06 Jun 2018 08:29:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528298970; cv=none; d=google.com; s=arc-20160816; b=q+eDs5tdryMOJo0jLTPEr8CJnNvWJ0q1B1ZsHo/ZjEwTs/4R+3ynkFuyCvWFlKM3wZ QROashFly4e9fOq+litySXlq2HDJAxkJa+5t7fkEfuvXOlJNYrzSNQGsu2/vDQHTMz3o Yt+1Cd4cokb/XsaUIeA/5E8QB9x9sRDMU2V2+miqEUs9axCBb/3wXlmaTvmr88Sq0Yur 2rBBLP82PooIQtdpvfD02AnaQwns1e8X+9a88T8gFJ+5+tbyr44aKIrEaN0IeoFOZwzH QRv1QUnpuevfqxrz9CMzlb1TlxVr217pPK51tNKmAmMTPtP+PPa9DLY///1zj3k5EowO y++w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=a839Iv2iIvjuJgsnudqxkDTdWrowCm0RfTN5u2i+UMM=; b=KhIkEl/HosZk2+WcDrcf98c5A+AMtr/rczfYjUbD8A6ERDpjyevYtkcoI4+eI07jBT eKYC1VKBv9u8NxEPMsYQmaQyDpRZd63ZQzJFgD+suQiIj+U/MpaUlSmswvCXl6J+OoaH 4y+zIp40UsIMTzDCDBjBcSM1Nm0Yb9P/Ar6+nprPgh/AfEQs/UH8ShYijtyoC/rylMqK 4xkSCel2QWKplTHe4gHqPLTylTwsopcZpwG2WkfTgimbAOXj2/0D/eUpiJwbRmfrc3oz 9LF72kLHTqQqJ1wjyhLIArvtZrtfBtzTulD5+sNeyqXsWIyPhXkHoSGJxXW0I9aqn3UW eCSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=u8/N5M74; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q15-v6si5227854pgr.507.2018.06.06.08.29.15; Wed, 06 Jun 2018 08:29:30 -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; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=u8/N5M74; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752673AbeFFP1M (ORCPT + 99 others); Wed, 6 Jun 2018 11:27:12 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:37354 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751885AbeFFP1J (ORCPT ); Wed, 6 Jun 2018 11:27:09 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w56FLhC8190214; Wed, 6 Jun 2018 15:25:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=a839Iv2iIvjuJgsnudqxkDTdWrowCm0RfTN5u2i+UMM=; b=u8/N5M74ViiHEZXcU0n+Xb5DhDEPCvFBVN2TlcbcwMUx3Zk4GPS872B9dWrr8ZLCl+oH mQfvEWq2DyhRFO87V1mxYx5rCmdn3Oa5d/I0DP6jKHjZEY7m46Scc2psRlIfWiqv1lVn WeN7YSI4HfkE3/DbBVYv4UbHmOAg6yRuHgCzEkImC0Etjrfhfhw1GCHFI+TsoAM6vLuY +3IydbYrjcJIpywCUrZLTbTEtvg+YZE9oQS5bk4gDtijcD173kPkrzo36Q/+lenJb0eU A+ziBW6q71DbDaT6ACLw7GEjHN/Z+k1bjsRAxZnqIVsQKKYiJ0veBodkmPxlHYubO1kb 8A== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2jbvypn68m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Jun 2018 15:25:32 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w56FPVqL017607 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Jun 2018 15:25:32 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w56FPUnd008501; Wed, 6 Jun 2018 15:25:30 GMT Received: from [10.39.243.144] (/10.39.243.144) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Jun 2018 08:25:30 -0700 Subject: Re: [RFC 2/2] x86, tsc: Enable clock for ealry printk timestamp To: Feng Tang , Peter Zijlstra , Petr Mladek Cc: Ingo Molnar , Thomas Gleixner , "H . Peter Anvin" , Alan Cox , linux-kernel@vger.kernel.org, alek.du@intel.com, arjan@linux.intel.com, len.brown@intel.com References: <1527672059-6225-1-git-send-email-feng.tang@intel.com> <1527672059-6225-2-git-send-email-feng.tang@intel.com> <20180531135542.4j7w7bxsw43ydx3j@pathway.suse.cz> <20180531155210.GL12180@hirez.programming.kicks-ass.net> <20180601161213.tm44nhrhwfxa2767@shbuild888> <20180606093833.vqg47yhdq7mnj2kp@shbuild888> From: Pavel Tatashin Message-ID: Date: Wed, 6 Jun 2018 11:25:22 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180606093833.vqg47yhdq7mnj2kp@shbuild888> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8916 signatures=668702 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806060175 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Feng, Using a global variable for this is not going to work, because you are adding a conditional branch and a load to a very hot path for the live of the system, not only for the duration of the boot. Pavel > > +int tsc_inited; > /* > * TSC can be unstable due to cpufreq or due to unsynced TSCs > */ > @@ -192,7 +193,7 @@ static void set_cyc2ns_scale(unsigned long khz, int cpu, unsigned long long tsc_ > */ > u64 native_sched_clock(void) > { > - if (static_branch_likely(&__use_tsc)) { > + if (static_branch_likely(&__use_tsc) || tsc_inited) { > u64 tsc_now = rdtsc(); > > /* return the value in ns */ > @@ -1387,30 +1391,16 @@ static int __init init_tsc_clocksource(void) > */ > device_initcall(init_tsc_clocksource); > > -void __init tsc_early_delay_calibrate(void) > -{ > - unsigned long lpj; > - > - if (!boot_cpu_has(X86_FEATURE_TSC)) > - return; > - > - cpu_khz = x86_platform.calibrate_cpu(); > - tsc_khz = x86_platform.calibrate_tsc(); > - > - tsc_khz = tsc_khz ? : cpu_khz; > - if (!tsc_khz) > - return; > - > - lpj = tsc_khz * 1000; > - do_div(lpj, HZ); > - loops_per_jiffy = lpj; > -} > - > void __init tsc_init(void) > { > u64 lpj, cyc; > int cpu; > > + if (tsc_inited) > + return; > + > + tsc_inited = 1; > + > if (!boot_cpu_has(X86_FEATURE_TSC)) { > setup_clear_cpu_cap(X86_FEATURE_TSC_DEADLINE_TIMER); > return; > @@ -1474,11 +1464,15 @@ void __init tsc_init(void) > lpj = ((u64)tsc_khz * 1000); > do_div(lpj, HZ); > lpj_fine = lpj; > + loops_per_jiffy = lpj; > > use_tsc_delay(); > > check_system_tsc_reliable(); > > + extern void early_set_sched_clock_stable(u64 sched_clock_offset); > + early_set_sched_clock_stable(div64_u64(rdtsc() * 1000, tsc_khz)); > + > if (unsynchronized_tsc()) { > mark_tsc_unstable("TSCs unsynchronized"); > return; > diff --git a/kernel/sched/clock.c b/kernel/sched/clock.c > index 10c83e7..6c5c22d 100644 > --- a/kernel/sched/clock.c > +++ b/kernel/sched/clock.c > @@ -119,6 +119,13 @@ static void __scd_stamp(struct sched_clock_data *scd) > scd->tick_raw = sched_clock(); > } > > + > +void early_set_sched_clock_stable(u64 sched_clock_offset) > +{ > + __sched_clock_offset = sched_clock_offset; > + static_branch_enable(&__sched_clock_stable); > +} > + > static void __set_sched_clock_stable(void) > { > struct sched_clock_data *scd; > @@ -342,12 +349,14 @@ static u64 sched_clock_remote(struct sched_clock_data *scd) > * > * See cpu_clock(). > */ > + > +extern int tsc_inited; > u64 sched_clock_cpu(int cpu) > { > struct sched_clock_data *scd; > u64 clock; > > - if (sched_clock_stable()) > + if (sched_clock_stable() || tsc_inited) > return sched_clock() + __sched_clock_offset; > > if (unlikely(!sched_clock_running)) > > > > >>> >>> If you have a dodgy part (sorry SKX), you'll just have to live with >>> sched_clock starting late(r). >>> >>> Do not cobble things on the side, try and get the normal things running >>> earlier.