Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1075703imm; Fri, 15 Jun 2018 10:46:37 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJnQNpxmkwLYMzqJIBxZX/mNee6EY5SZ1z1s45O+lDo/hj8icsqq6gWQ88KGx01frXWCrqm X-Received: by 2002:a62:40dc:: with SMTP id f89-v6mr2954009pfd.194.1529084797323; Fri, 15 Jun 2018 10:46:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529084797; cv=none; d=google.com; s=arc-20160816; b=N5kgLrFmBD4R3AdiJX5jTjDDBnuQDsjkRoYeJe3Ntgwm/Txqy02NopaCZrUaASZErT fDahVfqAbL8YaG/1x5ATH/9+c36M/1glUJMVfxfYtmt5MunlWA5z8+ta6tuZ70V5gzy1 oyY6reDPt/mUUzoNg9B0FFh288WxaqSAczR5ZQbED11pBtPgr9AXshaj6Fbg77keVLqo eNXlqRXwou1JQ6bUw1SucVcxkcvxGmhie4xRy/43vR9cJKotjcDxoEShXyh7VhD6OeDf HwwVBl7Os7wTamLSGDCYt8gA/lZBsfthG/eCwYpy3rF/y65mfVpwLVlwXrBHo8zhoMIR sMvQ== 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=T0h2r0sSc7tWjXGwr4r6W2STLW/66D3vCHN8FMxxB04=; b=kMGQvrbvj53UsMi5LgnUBncUAEC+9yfYLqWGbmIuaEZvmWV+wm56B0z182htBW8Tq2 fye4AhoBM2uHFmkVlQjIWmImtdEIIBs1Xl6eeG+KwTe2WWndLXJ7r4pVA2w/xWnf8AGI YOKljoh/Dxp4M2FHkCckeOhW0tG3OSCkxJnkfESWuG7wjj0+3ZXToYbVkHIAINd10pY3 QJEQaHVIsACnTLCeZIfyuHl0WbhSo+l1IPzKeDGwO67ecfFaShLxdylBjRzKftnsTuAo eAt+ZEctGibP2JY0pFlBsHA/3vGB/WbjYTaDIdjbpo3rdCK6QNWseB5rPpxY46cD5VKE ECZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=tBp22Ku4; 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 t186-v6si7131523pgd.41.2018.06.15.10.46.22; Fri, 15 Jun 2018 10:46: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-2017-10-26 header.b=tBp22Ku4; 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 S966252AbeFORpJ (ORCPT + 99 others); Fri, 15 Jun 2018 13:45:09 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:59006 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965850AbeFORnP (ORCPT ); Fri, 15 Jun 2018 13:43:15 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w5FHck4b139416; Fri, 15 Jun 2018 17:42:17 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-2017-10-26; bh=T0h2r0sSc7tWjXGwr4r6W2STLW/66D3vCHN8FMxxB04=; b=tBp22Ku4eGJqQDkcYdr50jReMmmxjuy++YlqEfR/P4qtWpMRrh7c9d3sDS4B4yLHVrl5 fdEj/YgBJ9J8VwgQhiEXRo34P2hz/d9YPzRQQISvRNyzi6G6X+GYRniYcuiMf2+f8/uE O+5FTDXzzYLwo/8V6PJA6EU1+LNAGZ+MCNHtCYADJ4iHLsLrpvvVub6YLxx0/wW/z4Ri NyVAabh43kZh39AgyYLexdBM7dfzGmhiVd6NZ4HyGFQ/ro0ksj4gtI8MnqbwKmZFOQ5R 2PdW0jnl/YOpFqU3lLafa9GUY3mvc2o4S3vkbr/ij/8e0M9it6UAlekPMV5TiPg/RxxM Og== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2jk0xr1vy8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Jun 2018 17:42:16 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w5FHgGCL031232 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Jun 2018 17:42:16 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w5FHgG34017029; Fri, 15 Jun 2018 17:42:16 GMT Received: from localhost.localdomain (/73.69.118.222) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 15 Jun 2018 10:42:16 -0700 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 Subject: [PATCH v10 3/7] x86/time: read_boot_clock64() implementation Date: Fri, 15 Jun 2018 13:42:00 -0400 Message-Id: <20180615174204.30581-4-pasha.tatashin@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180615174204.30581-1-pasha.tatashin@oracle.com> References: <20180615174204.30581-1-pasha.tatashin@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8925 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-1806150189 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org read_boot_clock64() returns time of when system was started. Now, that early boot clock is going to be available on x86 it is possible to implement x86 specific version of read_boot_clock64() that takes advantage of this new feature. Signed-off-by: Pavel Tatashin --- arch/x86/kernel/time.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c index 774ebafa97c4..32dff35719d9 100644 --- a/arch/x86/kernel/time.c +++ b/arch/x86/kernel/time.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -104,3 +105,32 @@ void __init time_init(void) { late_time_init = x86_late_time_init; } + +/* + * Called once during to boot to initialize boot time. + * This function returns timestamp in timespec format which is sec/nsec from + * epoch of when boot started. + * We use sched_clock_cpu() that gives us nanoseconds from when this clock has + * been started and it happens quiet early during boot process. To calculate + * offset from epoch we use information provided in 'now' by the caller + * + * If sched_clock_cpu() is not available or if there is any kind of error + * i.e. time from epoch is smaller than boot time, we must return zeros in ts, + * and the caller will take care of the error: by assuming that the time when + * this function was called is the beginning of boot time. + */ +void __init read_boot_clock64(struct timespec64 *now, struct timespec64 *ts) +{ + u64 ns_boot = sched_clock_cpu(smp_processor_id()); + bool valid_clock; + u64 ns_now; + + ns_now = timespec64_to_ns(now); + valid_clock = ns_boot && timespec64_valid_strict(now) && + (ns_now > ns_boot); + + if (!valid_clock) + *ts = (struct timespec64){0, 0}; + else + *ts = ns_to_timespec64(ns_now - ns_boot); +} -- 2.17.1