Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2214321imm; Thu, 19 Jul 2018 15:35:16 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdYvL++sCghSOWiTOylhQr1D81sSnkt9O8FSGlmFlibGVJMLgDt6zqrt/SJNY2EOzFXK1cN X-Received: by 2002:a17:902:b205:: with SMTP id t5-v6mr11633457plr.220.1532039716275; Thu, 19 Jul 2018 15:35:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532039716; cv=none; d=google.com; s=arc-20160816; b=mSGwV9zaF0xFxBRwVPRqMQ+2r+6OsICJCqKD48cJJmxKPqFeu+wVsWDBvTTY7cMwSb FZpCpEsZyt2qBP/D2VdTYnWkLp3aK/qhUlu7311eOtj2tziOIgDWhyRuRFdiywahDTAC 8pUYIWgva7t+tfa6HOGmYdV+0nU7a5LB4O3WQhSSX5vcBH5CINVRIpWtcwFhDuJpS50O 216LErwn88Gqf5SicLJjzHiXfC7a6N51s1V1bUb8z3jzSjb1xwHME9ecB4WY7XTgXPQp Ydk0ndttsu0aR+BRfI0FS/f7ppnpWPPMXtuaprDQIUriN5OFXaUwzg6qzVt5ZSVarESq dZ4Q== 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=pgKg41qUKbdtbKjKRE9vjXlI+fPzLAmmgUpUC0HaBIE=; b=a6/z29anPwrO9SV/T38oPL9meCSJDNclIHGfS2UKt2vGHnaVxouxPaKf6YZooXROdY rrEBeUAJGVEmAVD9d65B2G+YLAT5IFpNnIHxWTEoaeswpXbKDiBOniQHDYdNBdWwh8TB A8X9Jr2+EEoI5/tCxdPiQdu4Wj9ooOSdT4HcxETRLv9GCH0h3UKnGahLtEN/cauGraHG pJG4HvAp6YiBeDFzrAv6gDbb7bh6qOVHtWLvWmJHHo1bHfi3jViVJcmH+XQOtqPX2Alm i22gRTkMMrah6CVS2W79rtaf2lG+lZs81+HH6dHzs5pMtOgRjHqLrkOggmueYpfPiGun o5/Q== 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 e186-v6si300556pfc.176.2018.07.19.15.35.01; Thu, 19 Jul 2018 15:35:16 -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 S1731445AbeGSXSi (ORCPT + 99 others); Thu, 19 Jul 2018 19:18:38 -0400 Received: from terminus.zytor.com ([198.137.202.136]:33405 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731112AbeGSXSh (ORCPT ); Thu, 19 Jul 2018 19:18:37 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w6JMXLHG2439893 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 19 Jul 2018 15:33:21 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w6JMXLgj2439890; Thu, 19 Jul 2018 15:33:21 -0700 Date: Thu, 19 Jul 2018 15:33:21 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Pavel Tatashin Message-ID: Cc: pasha.tatashin@oracle.com, linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@kernel.org, tglx@linutronix.de Reply-To: linux-kernel@vger.kernel.org, pasha.tatashin@oracle.com, mingo@kernel.org, tglx@linutronix.de, hpa@zytor.com In-Reply-To: <20180719205545.16512-24-pasha.tatashin@oracle.com> References: <20180719205545.16512-24-pasha.tatashin@oracle.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/timers] sched/clock: Enable sched clock early Git-Commit-ID: 857baa87b6422bcfb84ed3631d6839920cb5b09d 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, 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: 857baa87b6422bcfb84ed3631d6839920cb5b09d Gitweb: https://git.kernel.org/tip/857baa87b6422bcfb84ed3631d6839920cb5b09d Author: Pavel Tatashin AuthorDate: Thu, 19 Jul 2018 16:55:42 -0400 Committer: Thomas Gleixner CommitDate: Fri, 20 Jul 2018 00:02:43 +0200 sched/clock: Enable sched clock early Allow sched_clock() to be used before schec_clock_init() is called. This provides a way to get early boot timestamps on machines with unstable clocks. Signed-off-by: Pavel Tatashin Signed-off-by: Thomas Gleixner 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: peterz@infradead.org 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/20180719205545.16512-24-pasha.tatashin@oracle.com --- init/main.c | 2 +- kernel/sched/clock.c | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/init/main.c b/init/main.c index 162d931c9511..ff0a24170b95 100644 --- a/init/main.c +++ b/init/main.c @@ -642,7 +642,6 @@ asmlinkage __visible void __init start_kernel(void) softirq_init(); timekeeping_init(); time_init(); - sched_clock_init(); printk_safe_init(); perf_event_init(); profile_init(); @@ -697,6 +696,7 @@ asmlinkage __visible void __init start_kernel(void) acpi_early_init(); if (late_time_init) late_time_init(); + sched_clock_init(); calibrate_delay(); pid_idr_init(); anon_vma_init(); diff --git a/kernel/sched/clock.c b/kernel/sched/clock.c index 0e9dbb2d9aea..422cd63f8f17 100644 --- a/kernel/sched/clock.c +++ b/kernel/sched/clock.c @@ -202,7 +202,25 @@ static void __sched_clock_gtod_offset(void) 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. + * + * 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); + __sched_clock_gtod_offset(); + local_irq_restore(flags); + sched_clock_running = 1; + + /* 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, @@ -356,7 +374,7 @@ u64 sched_clock_cpu(int cpu) return sched_clock() + __sched_clock_offset; if (unlikely(!sched_clock_running)) - return 0ull; + return sched_clock(); preempt_disable_notrace(); scd = cpu_sdc(cpu);