* [PATCH 1/4] rtc-lib: Add rtc_show_time(const char *prefix_msg)
@ 2017-07-18 17:25 Mark Salyzyn
2017-07-18 17:41 ` Joe Perches
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Mark Salyzyn @ 2017-07-18 17:25 UTC (permalink / raw)
To: linux-kernel
Cc: rjw, len.brown, pavel, linux-pm, a.zummo, alexandre.belloni,
linux-rtc, Mark Salyzyn
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>
---
drivers/rtc/Kconfig | 11 +++++++++++
drivers/rtc/rtc-lib.c | 16 ++++++++++++++++
include/linux/rtc.h | 5 +++++
3 files changed, 32 insertions(+)
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 72419ac2c52a..7c308605bf42 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -5,6 +5,17 @@
config RTC_LIB
bool
+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.
+
config RTC_MC146818_LIB
bool
select RTC_LIB
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index 1ae7da5cfc60..676d6a83e843 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -94,6 +94,22 @@ void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
}
EXPORT_SYMBOL(rtc_time64_to_tm);
+#ifdef CONFIG_RTC_SHOW_TIME
+void rtc_show_time(const char *prefix_msg)
+{
+ struct timespec ts;
+ struct rtc_time tm;
+
+ getnstimeofday(&ts);
+ rtc_time_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);
+#endif
+
/*
* Does the rtc_time represent a valid date/time?
*/
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index 0a0f0d14a5fb..bf625e023799 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
+#define rtc_show_time(prefix_msg)
+#endif
ktime_t rtc_tm_to_ktime(struct rtc_time tm);
struct rtc_time rtc_ktime_to_tm(ktime_t kt);
--
2.13.2.932.g7449e964c-goog
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH 1/4] rtc-lib: Add rtc_show_time(const char *prefix_msg)
2017-07-18 17:25 [PATCH 1/4] rtc-lib: Add rtc_show_time(const char *prefix_msg) Mark Salyzyn
@ 2017-07-18 17:41 ` Joe Perches
2017-07-18 17:46 ` Andy Shevchenko
2017-07-18 17:52 ` Alexandre Belloni
2 siblings, 0 replies; 7+ messages in thread
From: Joe Perches @ 2017-07-18 17:41 UTC (permalink / raw)
To: Mark Salyzyn, linux-kernel
Cc: rjw, len.brown, pavel, linux-pm, a.zummo, alexandre.belloni,
linux-rtc
On Tue, 2017-07-18 at 10:25 -0700, Mark Salyzyn wrote:
> 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.
[]
> diff --git 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
> +#define rtc_show_time(prefix_msg)
It's generally better to use a static inline to avoid
misuses in newly added code in the !CONFIG_RTC_SHOW_TIME
compile path when CONFIG_RTC_SHOW_TIME may not be compiled.
static inline void rtc_show_time(const char *prefix_msg)
{
}
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 1/4] rtc-lib: Add rtc_show_time(const char *prefix_msg)
2017-07-18 17:25 [PATCH 1/4] rtc-lib: Add rtc_show_time(const char *prefix_msg) Mark Salyzyn
2017-07-18 17:41 ` Joe Perches
@ 2017-07-18 17:46 ` Andy Shevchenko
2017-07-18 17:49 ` Andy Shevchenko
2017-07-18 17:52 ` Alexandre Belloni
2 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2017-07-18 17:46 UTC (permalink / raw)
To: Mark Salyzyn
Cc: linux-kernel@vger.kernel.org, Rafael J. Wysocki, Brown, Len,
Pavel Machek, linux-pm@vger.kernel.org, Alessandro Zummo,
Alexandre Belloni, linux-rtc
On Tue, Jul 18, 2017 at 8:25 PM, Mark Salyzyn <salyzyn@android.com> wrote:
> 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.
What's wrong with procfs device nodes for that?
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/4] rtc-lib: Add rtc_show_time(const char *prefix_msg)
2017-07-18 17:46 ` Andy Shevchenko
@ 2017-07-18 17:49 ` Andy Shevchenko
0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2017-07-18 17:49 UTC (permalink / raw)
To: Mark Salyzyn
Cc: linux-kernel@vger.kernel.org, Rafael J. Wysocki, Brown, Len,
Pavel Machek, linux-pm@vger.kernel.org, Alessandro Zummo,
Alexandre Belloni, linux-rtc
On Tue, Jul 18, 2017 at 8:46 PM, Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Tue, Jul 18, 2017 at 8:25 PM, Mark Salyzyn <salyzyn@android.com> wrote:
>> 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.
>
> What's wrong with procfs device nodes for that?
Ah, it's internal API, ok.
Then would it be possible to use %pt [1] or alike?
[1]: https://www.spinics.net/lists/kernel/msg2528401.html
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/4] rtc-lib: Add rtc_show_time(const char *prefix_msg)
2017-07-18 17:25 [PATCH 1/4] rtc-lib: Add rtc_show_time(const char *prefix_msg) Mark Salyzyn
2017-07-18 17:41 ` Joe Perches
2017-07-18 17:46 ` Andy Shevchenko
@ 2017-07-18 17:52 ` Alexandre Belloni
2017-07-18 20:00 ` Mark Salyzyn
2 siblings, 1 reply; 7+ messages in thread
From: Alexandre Belloni @ 2017-07-18 17:52 UTC (permalink / raw)
To: Mark Salyzyn
Cc: linux-kernel, rjw, len.brown, pavel, linux-pm, a.zummo, linux-rtc
Hi,
On 18/07/2017 at 10:25:23 -0700, Mark Salyzyn wrote:
> 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>
> ---
> drivers/rtc/Kconfig | 11 +++++++++++
> drivers/rtc/rtc-lib.c | 16 ++++++++++++++++
> include/linux/rtc.h | 5 +++++
> 3 files changed, 32 insertions(+)
>
> diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
> index 72419ac2c52a..7c308605bf42 100644
> --- a/drivers/rtc/Kconfig
> +++ b/drivers/rtc/Kconfig
> @@ -5,6 +5,17 @@
> config RTC_LIB
> bool
>
> +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.
> +
> config RTC_MC146818_LIB
> bool
> select RTC_LIB
> diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
> index 1ae7da5cfc60..676d6a83e843 100644
> --- a/drivers/rtc/rtc-lib.c
> +++ b/drivers/rtc/rtc-lib.c
> @@ -94,6 +94,22 @@ void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
> }
> EXPORT_SYMBOL(rtc_time64_to_tm);
>
> +#ifdef CONFIG_RTC_SHOW_TIME
> +void rtc_show_time(const char *prefix_msg)
> +{
> + struct timespec ts;
> + struct rtc_time tm;
> +
> + getnstimeofday(&ts);
> + rtc_time_to_tm(ts.tv_sec, &tm);
Apart from using rtc_time_to_tm (and you should probably use
rtc_time64_to_tm), none of this is actually related to the RTC
subsystem. I feel like you should find another place to put that, maybe
timekeeping_debug.c?
> + 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);
> +#endif
> +
> /*
> * Does the rtc_time represent a valid date/time?
> */
> diff --git a/include/linux/rtc.h b/include/linux/rtc.h
> index 0a0f0d14a5fb..bf625e023799 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
> +#define rtc_show_time(prefix_msg)
> +#endif
> ktime_t rtc_tm_to_ktime(struct rtc_time tm);
> struct rtc_time rtc_ktime_to_tm(ktime_t kt);
>
> --
> 2.13.2.932.g7449e964c-goog
>
--
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 1/4] rtc-lib: Add rtc_show_time(const char *prefix_msg)
2017-07-18 17:52 ` Alexandre Belloni
@ 2017-07-18 20:00 ` Mark Salyzyn
2017-07-18 20:08 ` Mark Salyzyn
0 siblings, 1 reply; 7+ messages in thread
From: Mark Salyzyn @ 2017-07-18 20:00 UTC (permalink / raw)
To: Alexandre Belloni
Cc: linux-kernel, rjw, len.brown, pavel, linux-pm, a.zummo, linux-rtc
On 07/18/2017 10:52 AM, Alexandre Belloni wrote:
> Hi,
>
> On 18/07/2017 at 10:25:23 -0700, Mark Salyzyn wrote:
>> . . .
> Apart from using rtc_time_to_tm (and you should probably use
> rtc_time64_to_tm), none of this is actually related to the RTC
> subsystem. I feel like you should find another place to put that, maybe
> timekeeping_debug.c?
Makes a lot of sense!
-- Mark
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/4] rtc-lib: Add rtc_show_time(const char *prefix_msg)
2017-07-18 20:00 ` Mark Salyzyn
@ 2017-07-18 20:08 ` Mark Salyzyn
0 siblings, 0 replies; 7+ messages in thread
From: Mark Salyzyn @ 2017-07-18 20:08 UTC (permalink / raw)
To: Alexandre Belloni
Cc: linux-kernel, rjw, len.brown, pavel, linux-pm, a.zummo, linux-rtc
On 07/18/2017 01:00 PM, Mark Salyzyn wrote:
> On 07/18/2017 10:52 AM, Alexandre Belloni wrote:
>> Hi,
>>
>> On 18/07/2017 at 10:25:23 -0700, Mark Salyzyn wrote:
>>> . . .
>> Apart from using rtc_time_to_tm (and you should probably use
>> rtc_time64_to_tm), none of this is actually related to the RTC
>> subsystem. I feel like you should find another place to put that, maybe
>> timekeeping_debug.c?
> Makes a lot of sense!
>
> -- Mark
Ooops, timekeeping_debug.c is currently only to support a debugfs node.
Perhaps a _new_ file in that hierarchy like kernel/time/rtc_show_time.c.
-- Mark
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-07-18 20:08 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-18 17:25 [PATCH 1/4] rtc-lib: Add rtc_show_time(const char *prefix_msg) Mark Salyzyn
2017-07-18 17:41 ` Joe Perches
2017-07-18 17:46 ` Andy Shevchenko
2017-07-18 17:49 ` Andy Shevchenko
2017-07-18 17:52 ` Alexandre Belloni
2017-07-18 20:00 ` Mark Salyzyn
2017-07-18 20:08 ` Mark Salyzyn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox