Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp681617imm; Fri, 13 Jul 2018 04:40:37 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdP+Xn570y9A5HEBwk9mqaX637RiXzPfNJchU4abXI0DIFBJqgIwY1Ei+arbEBl+xLkFpik X-Received: by 2002:aa7:818b:: with SMTP id g11-v6mr6723952pfi.50.1531482037172; Fri, 13 Jul 2018 04:40:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531482037; cv=none; d=google.com; s=arc-20160816; b=kP6KexJG1hXKyvaVicokEvqOxJ7EG/o16jgzdBtFxcr9L0ay2svGwGyu9Wuk1bsZjN st/J1vzidzbvq3tFN0ezRKJ1YVHijLtFNlLvsP39Z08py7RfvNJrqQjgmkJNMdE2CaMx Q7AxfARjpVpqFILNQhgvZF4I9yEfBv9IZrYtj0giQatMJndP5oFztiDeWMDzy9IgSs1c x330M+mBvtEO4aoZs/hguU82IRRtaHBnFbh7OvSlq5iRx/Vg2ZYt/owWxx9WZCr1xl53 28RJ+SWLnY/2H8JUZrP6OqS9BCQH01fEz1LteHu0N6+xqXUuhfLKSodrGtWZnthB1GEJ GdzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=ZQnSgseBEdYtCg5YQ6J5kjvU8iAJ1P02+MDU4MoWe2c=; b=QpD++m3LJ7P2d4ySvbmTUTHio/ftbjxZFplfcQhiWhvN09aquv0teHLv+q8DtEhopL jZ0nvzxrwuOXufC4PHJlJo5BCNAoITiEBfKue4k2S52pLrSpRFS7zDUK8lY3KJPT2SBc ZkWqY2yzA6cUf5VFnu176ydfzW4T6CcgudS0NKQpb8u1evO2pRRTtS6vu/EP3rRILFwq NTutiWTHAEDsaDsTpWWC/J+9XUGJbEpVbxMt1sACIX/q7d6PSiumcAuNw7d92bysFBcz TQqNVa+Qe51p40u/dCHti9KTdR0nG+mdby+8lr5lbN4/uxslT4l3p3H2ne5TwE76cSEI ha2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=scwJLjFC; 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 o8-v6si7383020pgr.461.2018.07.13.04.40.20; Fri, 13 Jul 2018 04:40:37 -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-2018-07-02 header.b=scwJLjFC; 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 S1729625AbeGMLyC (ORCPT + 99 others); Fri, 13 Jul 2018 07:54:02 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:56382 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727434AbeGMLyB (ORCPT ); Fri, 13 Jul 2018 07:54:01 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w6DBclPQ014716; Fri, 13 Jul 2018 11:39:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : references : in-reply-to : from : date : message-id : subject : to : cc : content-type; s=corp-2018-07-02; bh=ZQnSgseBEdYtCg5YQ6J5kjvU8iAJ1P02+MDU4MoWe2c=; b=scwJLjFCTFRJkxzXN9oL2G4696xv/+FIHLj6ALzi4n70/9RY0psynfzy327A+E2t1y7c TLjoRzNqDVGWV1POr3WeOU4Y9sejNzMczh+qYBVuFP5OjAW+W9i5uZgS/iAZYv0tsXXn Vp0ZO1ExGIrj/N0tNsjIcF1GQl4AH5eGbsUAAwcUSu9q0O1YDvFdCSBOgeZfVDTGV6hP xw8yQBVIdZ62m3NdrGHexD6c6Pkm//qcOR+Pq3Mw8HF1jDfRYBqc+Spw7miCmEJfVrQ9 2uVnF+CkEpO5q0P3kicqPZuTI5T482q5yUJseOq3g6ktLhsgsjhNvYZ/aRocqGGmVdIe 5g== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2120.oracle.com with ESMTP id 2k2p7e7ga4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Jul 2018 11:39:42 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w6DBdeju029753 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 13 Jul 2018 11:39:40 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w6DBdduW028517; Fri, 13 Jul 2018 11:39:40 GMT Received: from mail-oi0-f42.google.com (/209.85.218.42) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 13 Jul 2018 04:39:39 -0700 Received: by mail-oi0-f42.google.com with SMTP id q11-v6so36070195oic.12; Fri, 13 Jul 2018 04:39:39 -0700 (PDT) X-Gm-Message-State: AOUpUlEF8PlHyTM/ZUlbdaSh3KFhc8POOwjZ2/36QJfVBdiz9llKxXLy All5T9tQT2Kv/wgMUOvPk+YFdGHSqIcCtSlAXG0= X-Received: by 2002:aca:3bc2:: with SMTP id i185-v6mr7001255oia.156.1531481978946; Fri, 13 Jul 2018 04:39:38 -0700 (PDT) MIME-Version: 1.0 References: <20180712000419.5165-1-pasha.tatashin@oracle.com> <20180712000419.5165-15-pasha.tatashin@oracle.com> In-Reply-To: From: Pavel Tatashin Date: Fri, 13 Jul 2018 07:39:02 -0400 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v13 14/18] x86/tsc: initialize cyc2ns when tsc freq. is determined To: douly.fnst@cn.fujitsu.com Cc: Steven Sistare , Daniel Jordan , linux@armlinux.org.uk, schwidefsky@de.ibm.com, Heiko Carstens , John Stultz , sboyd@codeaurora.org, x86@kernel.org, LKML , mingo@redhat.com, tglx@linutronix.de, hpa@zytor.com, peterz@infradead.org, prarit@redhat.com, feng.tang@intel.com, Petr Mladek , gnomes@lxorguk.ukuu.org.uk, linux-s390@vger.kernel.org, boris.ostrovsky@oracle.com, jgross@suse.com Content-Type: text/plain; charset="UTF-8" X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8952 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=3 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-1806210000 definitions=main-1807130091 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 13, 2018 at 5:13 AM Dou Liyang wrote: > > > > At 07/12/2018 08:04 AM, Pavel Tatashin wrote: > > cyc2ns converts tsc to nanoseconds, and it is handled in a per-cpu data > > structure. > > > > Currently, the setup code for c2ns data for every possible CPU goes through > > the same sequence of calculations as for the boot CPU, but is based on the > > same tsc frequency as the boot CPU, and thus this is not necessary. > > > > Initialize the boot cpu when tsc frequency is determined. Copy the > > calculated data from the boot CPU to the other CPUs in tsc_init(). > > > > In addition do the following: > > > > - Remove unnecessary zeroing of c2ns data by removing cyc2ns_data_init() > > - Split set_cyc2ns_scale() into two functions, so set_cyc2ns_scale() can be > > called when system is up, and wraps around __set_cyc2ns_scale() that can > > be called directly when system is booting but avoids saving restoring > > IRQs and going and waking up from idle. > > > > Suggested-by: Thomas Gleixner > > Signed-off-by: Pavel Tatashin > > --- > > arch/x86/kernel/tsc.c | 94 ++++++++++++++++++++++++------------------- > > 1 file changed, 53 insertions(+), 41 deletions(-) > > > > diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c > > index bc8eb82050a3..0b1abe7fdd8e 100644 > > --- a/arch/x86/kernel/tsc.c > > +++ b/arch/x86/kernel/tsc.c > > @@ -103,23 +103,6 @@ void cyc2ns_read_end(void) > > * -johnstul@us.ibm.com "math is hard, lets go shopping!" > > */ > > > > -static void cyc2ns_data_init(struct cyc2ns_data *data) > > -{ > > - data->cyc2ns_mul = 0; > > - data->cyc2ns_shift = 0; > > - data->cyc2ns_offset = 0; > > -} > > - > > -static void __init cyc2ns_init(int cpu) > > -{ > > - struct cyc2ns *c2n = &per_cpu(cyc2ns, cpu); > > - > > - cyc2ns_data_init(&c2n->data[0]); > > - cyc2ns_data_init(&c2n->data[1]); > > - > > - seqcount_init(&c2n->seq); > > -} > > - > > static inline unsigned long long cycles_2_ns(unsigned long long cyc) > > { > > struct cyc2ns_data data; > > @@ -135,18 +118,11 @@ static inline unsigned long long cycles_2_ns(unsigned long long cyc) > > return ns; > > } > > > > -static void set_cyc2ns_scale(unsigned long khz, int cpu, unsigned long long tsc_now) > > +static void __set_cyc2ns_scale(unsigned long khz, int cpu, unsigned long long tsc_now) > > { > > unsigned long long ns_now; > > struct cyc2ns_data data; > > struct cyc2ns *c2n; > > - unsigned long flags; > > - > > - local_irq_save(flags); > > - sched_clock_idle_sleep_event(); > > - > > - if (!khz) > > - goto done; > > > > ns_now = cycles_2_ns(tsc_now); > > > > @@ -178,12 +154,55 @@ static void set_cyc2ns_scale(unsigned long khz, int cpu, unsigned long long tsc_ > > c2n->data[0] = data; > > raw_write_seqcount_latch(&c2n->seq); > > c2n->data[1] = data; > > +} > > + > > +static void set_cyc2ns_scale(unsigned long khz, int cpu, unsigned long long tsc_now) > > +{ > > + unsigned long flags; > > + > > + local_irq_save(flags); > > + sched_clock_idle_sleep_event(); > > + > > + if (khz) > > + __set_cyc2ns_scale(khz, cpu, tsc_now); > > > > -done: > > sched_clock_idle_wakeup_event(); > > local_irq_restore(flags); > > } > > > +/* > > + * Initialize cyc2ns for boot cpu > > + */ > > +static void __init cyc2ns_init_boot_cpu(void) > > +{ > > + struct cyc2ns *c2n = this_cpu_ptr(&cyc2ns); > > + > > + seqcount_init(&c2n->seq); > > + __set_cyc2ns_scale(tsc_khz, smp_processor_id(), rdtsc()); > > +} > Hi Paval, > > Here we didn't protect it with local_irq_save()/local_irq_restore() Hi Dou, Thank you for reviewing this work. Correct, but no need to do that: we do local_irqsave()/restore() only in set_cyc2ns_scale(), because that is called when system is live, and frequency changes. cyc2ns_init_boot_cpu(), and cyc2ns_init_secondary_cpus(), are called during boot, before smp_init(), and frequency does not change during that time. So, nothing to protect us from. > In tsc_init(), the timer interrupt has worked, Is that OK? > > IMO, no need to change so much, just use the original code, > eg: The request and suggestions on how to cleanup cyc2ns came from Thomas. Overall, code is cleaner now. Thank you, Pavel