From patchwork Tue Jul 18 21:19:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Salyzyn X-Patchwork-Id: 9849557 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 9F866602C8 for ; Tue, 18 Jul 2017 21:19:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94BCF1FEB1 for ; Tue, 18 Jul 2017 21:19:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87DCD285FC; Tue, 18 Jul 2017 21:19:51 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI 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 B3316285F3 for ; Tue, 18 Jul 2017 21:19:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751794AbdGRVTt (ORCPT ); Tue, 18 Jul 2017 17:19:49 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:35446 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751962AbdGRVTs (ORCPT ); Tue, 18 Jul 2017 17:19:48 -0400 Received: by mail-pf0-f181.google.com with SMTP id e199so17024029pfh.2 for ; Tue, 18 Jul 2017 14:19:48 -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=+mEaFcepG6p1XOLWrdgklGmvh35nqF9mrbtfH0r3uxc=; b=nx4s276gWYIjR5wwXhccyWvSFh1gpipqIoMnzylYK3SG9CzGnxQaUOoRJ+287CgZgg kQsHb28wrQfYgb8TPEyGBkLGSLqAEgpmrQvUydXcJzPY866NQiEtDlMoFRd/wec0OMFk jdlDcm0SSFB5TEQLH0tzn773d8+QBmFzNcgcO0ZSSyyFYlLOAapSikbvdAxURuwESZTt WI7QFsF7+RHVRo8PEwni9KN0J5xNNQ3ozX/9mBZW1GVRtUUAvMKDHZ0CX8PhTvTob2vX /DsaadHaQGSydJsTQOUoUPIb/MI4W56OSb4DdHnzhfAUjgAKThwpxNG1EWcI5Blxh4Ve HKtg== 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=+mEaFcepG6p1XOLWrdgklGmvh35nqF9mrbtfH0r3uxc=; b=M/PriQx60Dn9YgAh6bYdaFDuIROf6cy91UHnRLLuLiR3rglwzgNb/liptJqEi507IE AJ/JNG56vBW1sox46wY4rwPCMkw3B6hrgbBJ+KQwyvhRz5ShHg+MElHWdu5oLonSvWEU ipriH6rmbjLLGWCrqfBvlIw1jPoeLcA4SXmu7UIwBuURbFPT70QCIw7eVsk/uc27Y0T1 XuOrgg1rH1Iewv9s9A4tvQ5U+uRch0z454fEhslqlDqqUnAZUtUercShgTo2luzDXUr/ V5YSIX1/fbYSBenKiKvNZ2rbtY9ECE/bcYxz9zhOUmQfZV8JphFw20KQk/ZQukTFhjmt fveA== X-Gm-Message-State: AIVw110louOGlZN0qOgdqcc1jZgnbVAaHCIjSkZk6BOWT/iDKZ8vLpFI j2W4tuFyETqhC8Nw X-Received: by 10.84.214.143 with SMTP id j15mr3864250pli.40.1500412787833; Tue, 18 Jul 2017 14:19:47 -0700 (PDT) Received: from nebulus.mtv.corp.google.com ([100.98.120.17]) by smtp.gmail.com with ESMTPSA id e124sm6827005pfc.76.2017.07.18.14.19.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Jul 2017 14:19:47 -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 , Mark Salyzyn , "Paul E. McKenney" , Thierry Strudel , Thomas Gleixner , John Stultz , Richard Cochran , Nicolas Pitre , Kees Cook Subject: [PATCH v2 1/4] time: rtc-lib: Add rtc_show_time(const char *prefix_msg) Date: Tue, 18 Jul 2017 14:19:09 -0700 Message-Id: <20170718211930.123077-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 --- 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 timespec ts; + struct rtc_time tm; + + getnstimeofday(&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);