Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2679673imm; Fri, 20 Jul 2018 03:02:13 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcAOZDfhDF5ye1XTpZ/V27mKceJrm/faoF8wchDb6iUABokXkeFzDrvWQDq+IHoQRxndfDW X-Received: by 2002:a17:902:e201:: with SMTP id ce1-v6mr1450398plb.136.1532080933026; Fri, 20 Jul 2018 03:02:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532080933; cv=none; d=google.com; s=arc-20160816; b=dnxMfnEViqHsM5xqyQ1S1wEgC8/wHcKhE0KIQRvoYUjjseeGNL9jJIm4KkKX0NFOnm JDW0xLRBGPIkXSBXfU9B5O1j8SdD4jX09tpiKIknaGwAvvP4b9b5skoSz6RfeH5ddaIX yBCTF0cx6XAX6ZYDlx2dHygfaVMcx0Te13YWlhEllGY61DPDvTcqc20ElHZm6HEscOME 55Esqxh++wGf+bgWgaVbh0SrKkNSJq00YVZTB8yMSbNIbSGlxEwDmA80KuW3rYiI0rg+ IzcYEYUluxp7FgUwdAZaYj88ghdJH4H+aeBEMbp5CYeTPeNkiVAsMeO81w06PQ8KUDAb VcXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=ZhdbR7v+7PLVNdNxC6Qtnkx0Lj4D5wxaJdgb5fhsu+c=; b=lp38qF/BePArENkSRtuv3BzilVZvp/TpTbe5LuTzaP31BQJbHUESqZOjcYWAaodSCe R2ZbLv55CnocQqPAvjMSrJPnzOSD1c//lCC3vFL3Ed81eTR04N80MzRQuBX8Cylvd/6f HkYHaQObRCwLesWTiPTKis2MCcobfclwLYkqxMrwlQg3FcRghXFIU2zckTAsg10jl9YC COlrux9mWV1hmPDsJ23Ijt0nw5LHXGvMjT0FVIqVg3D4e/amEMC2J40Iu0d/sS1jRSVg pD2QMgw16d0afQ+Vlb9FP914wXbDOZgrfILl59NPdbK+gGG/hJsNMmG2Hd9FgZBsBzaY cWeg== 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 j33-v6si1439114pgm.584.2018.07.20.03.01.58; Fri, 20 Jul 2018 03:02:12 -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 S1729816AbeGTKsy (ORCPT + 99 others); Fri, 20 Jul 2018 06:48:54 -0400 Received: from terminus.zytor.com ([198.137.202.136]:37217 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727243AbeGTKsy (ORCPT ); Fri, 20 Jul 2018 06:48:54 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w6KA0oTt2614589 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 20 Jul 2018 03:00:50 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w6KA0oDt2614586; Fri, 20 Jul 2018 03:00:50 -0700 Date: Fri, 20 Jul 2018 03:00:50 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Peter Zijlstra Message-ID: Cc: mingo@kernel.org, tglx@linutronix.de, peterz@infradead.org, linux-kernel@vger.kernel.org, pasha.tatashin@oracle.com, hpa@zytor.com Reply-To: tglx@linutronix.de, peterz@infradead.org, mingo@kernel.org, pasha.tatashin@oracle.com, hpa@zytor.com, linux-kernel@vger.kernel.org In-Reply-To: <20180720080911.GM2494@hirez.programming.kicks-ass.net> References: <20180720080911.GM2494@hirez.programming.kicks-ass.net> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/timers] sched/clock: Close a hole in sched_clock_init() Git-Commit-ID: 9407f5a7ee77c631d1e100436132437cf6237e45 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 9407f5a7ee77c631d1e100436132437cf6237e45 Gitweb: https://git.kernel.org/tip/9407f5a7ee77c631d1e100436132437cf6237e45 Author: Peter Zijlstra AuthorDate: Fri, 20 Jul 2018 10:09:11 +0200 Committer: Thomas Gleixner CommitDate: Fri, 20 Jul 2018 11:58:00 +0200 sched/clock: Close a hole in sched_clock_init() All data required for the 'unstable' sched_clock must be set-up _before_ enabling it -- setting sched_clock_running. This includes the __gtod_offset but also a recent scd stamp. Make the gtod-offset update also set the csd stamp -- it requires the same two clock reads _anyway_. This doesn't hurt in the sched_clock_tick_stable() case and ensures sched_clock_init() gets everything set-up before use. Also switch to unconditional IRQ-disable/enable because the static key stuff already requires this is not ran with IRQs disabled. Fixes: 857baa87b642 ("sched/clock: Enable sched clock early") Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Thomas Gleixner Cc: Pavel Tatashin Cc: steven.sistare@oracle.com Cc: daniel.m.jordan@oracle.com Cc: linux@armlinux.org.uk Cc: schwidefsky@de.ibm.com Cc: heiko.carstens@de.ibm.com Cc: john.stultz@linaro.org Cc: sboyd@codeaurora.org Cc: hpa@zytor.com Cc: douly.fnst@cn.fujitsu.com Cc: prarit@redhat.com Cc: feng.tang@intel.com Cc: pmladek@suse.com Cc: gnomes@lxorguk.ukuu.org.uk Cc: linux-s390@vger.kernel.org Cc: boris.ostrovsky@oracle.com Cc: jgross@suse.com Cc: pbonzini@redhat.com Link: https://lkml.kernel.org/r/20180720080911.GM2494@hirez.programming.kicks-ass.net --- kernel/sched/clock.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/kernel/sched/clock.c b/kernel/sched/clock.c index c5c47ad3f386..811a39aca1ce 100644 --- a/kernel/sched/clock.c +++ b/kernel/sched/clock.c @@ -197,13 +197,14 @@ void clear_sched_clock_stable(void) static void __sched_clock_gtod_offset(void) { - __gtod_offset = (sched_clock() + __sched_clock_offset) - ktime_get_ns(); + struct sched_clock_data *scd = this_scd(); + + __scd_stamp(scd); + __gtod_offset = (scd->tick_raw + __sched_clock_offset) - scd->tick_gtod; } void __init sched_clock_init(void) { - unsigned long flags; - /* * Set __gtod_offset such that once we mark sched_clock_running, * sched_clock_tick() continues where sched_clock() left off. @@ -211,16 +212,11 @@ void __init sched_clock_init(void) * Even if TSC is buggered, we're still UP at this point so it * can't really be out of sync. */ - local_irq_save(flags); + local_irq_disable(); __sched_clock_gtod_offset(); - local_irq_restore(flags); + local_irq_enable(); static_branch_inc(&sched_clock_running); - - /* Now that sched_clock_running is set adjust scd */ - local_irq_save(flags); - sched_clock_tick(); - local_irq_restore(flags); } /* * We run this as late_initcall() such that it runs after all built-in drivers,