From patchwork Tue Jul 18 22:15:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Salyzyn X-Patchwork-Id: 9849893 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A99FD600CC for ; Tue, 18 Jul 2017 22:16:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 916E8269DA for ; Tue, 18 Jul 2017 22:16:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8586327FA6; Tue, 18 Jul 2017 22:16:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED14C269DA for ; Tue, 18 Jul 2017 22:16:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752095AbdGRWQ3 (ORCPT ); Tue, 18 Jul 2017 18:16:29 -0400 Received: from mail-pg0-f44.google.com ([74.125.83.44]:33494 "EHLO mail-pg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751987AbdGRWQ2 (ORCPT ); Tue, 18 Jul 2017 18:16:28 -0400 Received: by mail-pg0-f44.google.com with SMTP id k14so19895713pgr.0 for ; Tue, 18 Jul 2017 15:16:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ZV+ISRe+AIqn7ct5cQidYCFYx5yuRQrs8wWcoPFD+G8=; b=HbJqmTzNYGgeFaFPrPXpBiUJQ2OKjSQayD47jUxeIXflrm8Cx0dr+xmHGBE7UPRaLP wZR/VTxK+p5sUIxJB263Lr9SbAuYosSwlIOsGNDNd897FLNijTvPjosE85IltwH00dF4 sSRcucAm4S8fE7kUTNznoUs7H9a4sPnL2Laqn55T+9tb9gTgOXOUJWnvrIP+QPjXZofp GgeSI9QMZhEuCxisNXDqrl9HIO89rO8D0DeI/20mdj2UFYlQon2K4CHxfyvazYs7LM29 LHs4nrc8Drr0AQ6zSrG5YlCLSvvE0OTCZYDRPcjT5q7Y3olU+9loZRMaTOSp9qkuigUp iYRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ZV+ISRe+AIqn7ct5cQidYCFYx5yuRQrs8wWcoPFD+G8=; b=heXFatf/SUWgUFd0OkGtZVlRxJDuQzo0/CIebeTIYHJ2vPzaIZJXqpnxZpuVLczluv ipDFHedUS8aNgJ1EhcXBEuX+GTuzRLpBWwDyP9KOqleBsxHb1XH8o5z9WUXk7y6o+OLh xroDMVhwpcs4Qg3169jLKA2m9qQcYCfBpUJ0NR8O9LgR24JQwUl1luT91h9zSV7/33uV 4KKCb3UD7/JST828XZGpMCNGXwaQrTdKRdM28atR8zFmQrc99SAwuL25lph7Vm+WiTLX OPxU2HpyoOt3bPZDKRifoCmjzzw0S/BG1UB+UKgKVTRTtncXzCeI7QinJ9IteEWt9pmg x91g== X-Gm-Message-State: AIVw110bm9bX+mLUKDUHZGpT7NUSSiMzyn8TEIRiFmYrhEcEbkqNsz2+ msOAd1NpESYnNTQ7 X-Received: by 10.99.171.67 with SMTP id k3mr3897483pgp.128.1500416187899; Tue, 18 Jul 2017 15:16:27 -0700 (PDT) Received: from nebulus.mtv.corp.google.com ([100.98.120.17]) by smtp.gmail.com with ESMTPSA id d19sm7603024pfe.24.2017.07.18.15.16.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Jul 2017 15:16:27 -0700 (PDT) From: Mark Salyzyn To: linux-kernel@vger.kernel.org Cc: rjw@rjwysocki.net, len.brown@intel.com, pavel@ucw.cz, linux-pm@vger.kernel.org, a.zummo@towertech.it, alexandre.belloni@free-electrons.com, linux-rtc@vger.kernel.org, andy.shevchenko@gmail.com, Mark Salyzyn , "Paul E. McKenney" , Mark Salyzyn , Thierry Strudel , Thomas Gleixner , John Stultz , Josh Triplett , Nicolas Pitre , Kees Cook Subject: [PATCH v3 1/4] time: rtc-lib: Add rtc_show_time(const char *prefix_msg) Date: Tue, 18 Jul 2017 15:15:57 -0700 Message-Id: <20170718221607.132539-1-salyzyn@android.com> X-Mailer: git-send-email 2.13.2.932.g7449e964c-goog Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Go directly to the rtc for persistent wall clock time and print. Useful if REALTIME is required to be logged in a low level power management function or when clock activities are suspended. An aid to permit user space alignment of kernel activities. Feature activated by CONFIG_RTC_SHOW_TIME. Signed-off-by: Mark Salyzyn v2 - move implementation to kernel timekeeping from rtc_lib files - use rtc_time64_to_tm() instead of rtc_time_to_tm() - use inline in include/linux/rtc.h for !CONFIG_RTC_SHOW_TIME v3 - _correctly_ use rtc_time64_to_tm --- include/linux/rtc.h | 5 +++++ kernel/time/Kconfig | 11 +++++++++++ kernel/time/Makefile | 1 + kernel/time/rtc_show_time.c | 23 +++++++++++++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 kernel/time/rtc_show_time.c diff --git a/include/linux/rtc.h b/include/linux/rtc.h index 0a0f0d14a5fb..779401c937d5 100644 --- a/include/linux/rtc.h +++ b/include/linux/rtc.h @@ -22,6 +22,11 @@ extern int rtc_year_days(unsigned int day, unsigned int month, unsigned int year extern int rtc_valid_tm(struct rtc_time *tm); extern time64_t rtc_tm_to_time64(struct rtc_time *tm); extern void rtc_time64_to_tm(time64_t time, struct rtc_time *tm); +#ifdef CONFIG_RTC_SHOW_TIME +extern void rtc_show_time(const char *prefix_msg); +#else +static inline void rtc_show_time(const char *prefix_msg) { } +#endif ktime_t rtc_tm_to_ktime(struct rtc_time tm); struct rtc_time rtc_ktime_to_tm(ktime_t kt); diff --git a/kernel/time/Kconfig b/kernel/time/Kconfig index ac09bc29eb08..4da093ae3e37 100644 --- a/kernel/time/Kconfig +++ b/kernel/time/Kconfig @@ -145,3 +145,14 @@ config HIGH_RES_TIMERS endmenu endif + +config RTC_SHOW_TIME + bool "rtc_show_time instrumentation" + select RTC_LIB + help + Activate rtc_show_time(const char *msg) wall clock time + instrumentation. + + The instrumentation is used to help triage and synchronize + kernel logs using CLOCK_MONOTONIC and user space activity + logs utilizing CLOCK_REALTIME references. diff --git a/kernel/time/Makefile b/kernel/time/Makefile index 938dbf33ef49..66f17e641052 100644 --- a/kernel/time/Makefile +++ b/kernel/time/Makefile @@ -17,3 +17,4 @@ obj-$(CONFIG_GENERIC_SCHED_CLOCK) += sched_clock.o obj-$(CONFIG_TICK_ONESHOT) += tick-oneshot.o tick-sched.o obj-$(CONFIG_DEBUG_FS) += timekeeping_debug.o obj-$(CONFIG_TEST_UDELAY) += test_udelay.o +obj-$(CONFIG_RTC_SHOW_TIME) += rtc_show_time.o diff --git a/kernel/time/rtc_show_time.c b/kernel/time/rtc_show_time.c new file mode 100644 index 000000000000..bbf4f92abf4f --- /dev/null +++ b/kernel/time/rtc_show_time.c @@ -0,0 +1,23 @@ +/* + * rtc time printing utility functions + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include + +void rtc_show_time(const char *prefix_msg) +{ + struct timespec64 ts; + struct rtc_time tm; + + getnstimeofday64(&ts); + rtc_time64_to_tm(ts.tv_sec, &tm); + pr_info("%s %d-%02d-%02d %02d:%02d:%02d.%09lu UTC\n", + prefix_msg ? prefix_msg : "Time:", + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec, ts.tv_nsec); +} +EXPORT_SYMBOL(rtc_show_time);