Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2138873imm; Thu, 19 Jul 2018 13:59:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcxEM4ugMwNC4+RBh57hacDc7PTI2TKzWKGhgbZZWQ1mWRWtsdYMPEdmtMF56gpTAfwRJXc X-Received: by 2002:a17:902:6e09:: with SMTP id u9-v6mr11334071plk.13.1532033986363; Thu, 19 Jul 2018 13:59:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532033986; cv=none; d=google.com; s=arc-20160816; b=qtzY3nwcjotIJktTyee1ThWJdJ1iZWNlTwDv2A8GxBRS7cHtJPWS4dv4JccXkBxk3W gATaEnYgvXUXbcMYiUaB0Em0VYIoe5EIJ9fbFZ9U+d7c1TR/41r2S/gM3Pl7crnShNBB 8AEe4NEqnaqm6TWwp6xJcL+MBrTghMVSZ4+dmAhWu0AjZlifFAWOvlw1iGbB6LSGo/5O QgZDohygg6wK4ZfSgRs3whIVkx4msDxzuklxV0+RjbQL7+pWtAx7k/xl4bgkXEMAqbyS 5VCM1dsu8LQJDbkpktidpSVamnslcjZZLZhyr+MkkObkfhKs0f5g1YhBHvAh9pCSoqbG H9yQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:arc-authentication-results; bh=wIs5U4QfuxCg8kxQ0vkl/1AhFbu2WaGzBHCKQ/01X6E=; b=qY/lmTd9P5e39l5mwe8dVLvsWAo2zWVopp/nOfz43yamXRweQEikJ84bGEgW3Sv9oN kKDE6cGQh+dsF/8/hX+HBKBNPsY+zntL8XVYkv76bfIPub8ELYpb+IpVkf0mtH3dqy3/ zjFOP8N8Whdxu4Ag1hkaEpG8GMWeBRUR9n4/3d0VnnkKx5GW87Kwr7bPWoaZqvKx+OXg B1xiXEaCB71EdIwu2vXARPrrJWXu/LrYJkmOQtGMWehhyXFlmeUUx7wWX/eqGQJbS2ye JQgbyR9RWrkiRu8NntXQHMq1DNoIWXVm0pND/rgmYifsEsJrCfD9wWM5K32J6JSU5/Tw wXAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=duNDKALw; 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 p35-v6si163166pgl.202.2018.07.19.13.59.31; Thu, 19 Jul 2018 13:59:46 -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=duNDKALw; 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 S1731658AbeGSVmt (ORCPT + 99 others); Thu, 19 Jul 2018 17:42:49 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:45792 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730328AbeGSVmt (ORCPT ); Thu, 19 Jul 2018 17:42:49 -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 w6JKsYjV191975; Thu, 19 Jul 2018 20:56:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=wIs5U4QfuxCg8kxQ0vkl/1AhFbu2WaGzBHCKQ/01X6E=; b=duNDKALwR0ddX41KV9e4YO6MyGS0U1gT6Jr9YqeU/7ASwbJaSQqkoPIR4i53tY1KWwWG wLqsbqc69PL8hNOLUmgPalOESUrj1PcRCZ+JEorrNHKtqY0x7X1WmxxGGq8No86I8AKu pu3cz5qD2BQxIAr4toZIPf3pQYtgf5aMicrMykDGsIysbXHryrLbzzVUDoAWS+rii9W9 hx+IMCoqY7v24XdtA5WR31QayPy2ljJkrghsaZL12tWsCzLwn3G0QNtC6OkssxodaxJl mPr6O5l3QhGuDF/jNbU67KrvkxrB9Xx0JSlry26brLIFzBgVkJJ2IoG2RbZWU78xgjNv 5A== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2120.oracle.com with ESMTP id 2k9yjgruhd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Jul 2018 20:56:58 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w6JKuvmR002519 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 19 Jul 2018 20:56:57 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w6JKut7u027014; Thu, 19 Jul 2018 20:56:55 GMT Received: from localhost.localdomain (/73.69.118.222) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 19 Jul 2018 20:56:54 +0000 From: Pavel Tatashin To: steven.sistare@oracle.com, daniel.m.jordan@oracle.com, linux@armlinux.org.uk, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, john.stultz@linaro.org, sboyd@codeaurora.org, x86@kernel.org, linux-kernel@vger.kernel.org, mingo@redhat.com, tglx@linutronix.de, hpa@zytor.com, douly.fnst@cn.fujitsu.com, peterz@infradead.org, prarit@redhat.com, feng.tang@intel.com, pmladek@suse.com, gnomes@lxorguk.ukuu.org.uk, linux-s390@vger.kernel.org, pasha.tatashin@oracle.com, boris.ostrovsky@oracle.com, jgross@suse.com, pbonzini@redhat.com Subject: [PATCH v15 23/26] sched: early boot clock Date: Thu, 19 Jul 2018 16:55:42 -0400 Message-Id: <20180719205545.16512-24-pasha.tatashin@oracle.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180719205545.16512-1-pasha.tatashin@oracle.com> References: <20180719205545.16512-1-pasha.tatashin@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8959 signatures=668706 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-1806210000 definitions=main-1807190218 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow sched_clock() to be used before schec_clock_init() is called. This provides with a way to get early boot timestamps on machines with unstable clocks. Signed-off-by: Pavel Tatashin --- 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); -- 2.18.0