From: Mark Salyzyn <salyzyn@android.com>
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 <salyzyn@android.com>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Mark Salyzyn <salyzyn@google.com>,
Thierry Strudel <tstrudel@google.com>,
Thomas Gleixner <tglx@linutronix.de>,
John Stultz <john.stultz@linaro.org>,
Josh Triplett <josh@joshtriplett.org>,
Nicolas Pitre <nicolas.pitre@linaro.org>,
Kees Cook <keescook@chromium.org>
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 [thread overview]
Message-ID: <20170718221607.132539-1-salyzyn@android.com> (raw)
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 <salyzyn@android.com>
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 <linux/rtc.h>
+
+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);
--
2.13.2.932.g7449e964c-goog
next reply other threads:[~2017-07-18 22:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-18 22:15 Mark Salyzyn [this message]
2017-07-18 22:36 ` [PATCH v3 1/4] time: rtc-lib: Add rtc_show_time(const char *prefix_msg) Thomas Gleixner
2017-07-19 0:00 ` John Stultz
2017-07-19 14:52 ` Mark Salyzyn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170718221607.132539-1-salyzyn@android.com \
--to=salyzyn@android.com \
--cc=a.zummo@towertech.it \
--cc=alexandre.belloni@free-electrons.com \
--cc=andy.shevchenko@gmail.com \
--cc=john.stultz@linaro.org \
--cc=josh@joshtriplett.org \
--cc=keescook@chromium.org \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=nicolas.pitre@linaro.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=pavel@ucw.cz \
--cc=rjw@rjwysocki.net \
--cc=salyzyn@google.com \
--cc=tglx@linutronix.de \
--cc=tstrudel@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox