On Tue 2025-11-11 13:20:01, Andy Shevchenko wrote:
A handful drivers want to print a content of the struct timespec64 in a format of %lld:%09ld. In order to make their lives easier, add the respecting specifier directly to the printf() implementation.
Signed-off-by: Andy Shevchenko andriy.shevchenko@linux.intel.com
Documentation/core-api/printk-formats.rst | 11 ++++++++-- lib/tests/printf_kunit.c | 4 ++++ lib/vsprintf.c | 25 +++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst index 7f2f11b48286..c0b1b6089307 100644 --- a/Documentation/core-api/printk-formats.rst +++ b/Documentation/core-api/printk-formats.rst @@ -547,11 +547,13 @@ Time and date %pt[RT]s YYYY-mm-dd HH:MM:SS %pt[RT]d YYYY-mm-dd %pt[RT]t HH:MM:SS
- %pt[RT][dt][r][s]
- %ptSp <seconds>.<nanoseconds>
I know that that there was no good choice. But I am curious. Does the 'p' stands for some particular word, for example, "plain" ?
I do not want to start bike shedding but I think about using 'n' as "number".
- %pt[RST][dt][r][s]
For printing date and time as represented by::
- R struct rtc_time structure
- R content of struct rtc_time
- S content of struct timespec64 T time64_t type
in human readable format. @@ -563,6 +565,11 @@ The %pt[RT]s (space) will override ISO 8601 separator by using ' ' (space) instead of 'T' (Capital T) between date and time. It won't have any effect when date or time is omitted. +The %ptSp is equivalent to %lld.%09ld for the content of the struct timespec64. +When the other specifiers are given, it becomes the respective equivalent of +%ptT[dt][r][s].%09ld. In other words, the seconds are being printed in +the human readable format followed by a dot and nanoseconds.
Passed by reference. struct clk diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 3f99834fd788..fdd06e8957a3 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -2464,6 +2488,7 @@ early_param("no_hash_pointers", no_hash_pointers_enable);
- 'g' For block_device name (gendisk + partition number)
- 't[RT][dt][r][s]' For time and date as represented by:
We should add 'S' here as well:
* - 't[RST][dt][r][s]' For time and date as represented by:
That said, I am not sure about the optional '[p]'. We could either do:
* - 't[RST][p][dt][r][s]' For time and date as represented by:
or
* - 'tSp' For time represented by struct timespec64 printed as seconds.nanoseconds * - 't[RST][dt][r][s]' For time and date as represented by:
R struct rtc_time
S struct timespec64T time64_t
- 'C' For a clock, it prints the name (Common Clock Framework) or address
(legacy clock framework) of the clock
Otherwise, it looks good.
Best Regards, Petr