From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: "Corey Minyard" <corey@minyard.net>,
"Christian König" <christian.koenig@amd.com>,
"Dr. David Alan Gilbert" <linux@treblig.org>,
"Alex Deucher" <alexander.deucher@amd.com>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"Dmitry Baryshkov" <dmitry.baryshkov@oss.qualcomm.com>,
"Rob Clark" <robin.clark@oss.qualcomm.com>,
"Matthew Brost" <matthew.brost@intel.com>,
"Hans Verkuil" <hverkuil@kernel.org>,
"Laurent Pinchart" <laurent.pinchart+renesas@ideasonboard.com>,
"Ulf Hansson" <ulf.hansson@linaro.org>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Vitaly Lifshits" <vitaly.lifshits@intel.com>,
"Manivannan Sadhasivam" <mani@kernel.org>,
"Niklas Cassel" <cassel@kernel.org>,
"Calvin Owens" <calvin@wbinvd.org>,
"Sagi Maimon" <maimon.sagi@gmail.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
"Karan Tilak Kumar" <kartilak@cisco.com>,
"Casey Schaufler" <casey@schaufler-ca.com>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Petr Mladek" <pmladek@suse.com>,
"Max Kellermann" <max.kellermann@ionos.com>,
"Takashi Iwai" <tiwai@suse.de>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
openipmi-developer@lists.sourceforge.net,
linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
linaro-mm-sig@lists.linaro.org, amd-gfx@lists.freedesktop.org,
linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org,
intel-xe@lists.freedesktop.org, linux-mmc@vger.kernel.org,
netdev@vger.kernel.org, intel-wired-lan@lists.osuosl.org,
linux-pci@vger.kernel.org, linux-s390@vger.kernel.org,
linux-scsi@vger.kernel.org, linux-staging@lists.linux.dev,
ceph-devel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
linux-sound@vger.kernel.org
Cc: "Rasmus Villemoes" <linux@rasmusvillemoes.dk>,
"Sergey Senozhatsky" <senozhatsky@chromium.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"Sumit Semwal" <sumit.semwal@linaro.org>,
"Gustavo Padovan" <gustavo@padovan.org>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Dmitry Baryshkov" <lumag@kernel.org>,
"Abhinav Kumar" <abhinav.kumar@linux.dev>,
"Jessica Zhang" <jesszhan0024@gmail.com>,
"Sean Paul" <sean@poorly.run>,
"Marijn Suijten" <marijn.suijten@somainline.org>,
"Konrad Dybcio" <konradybcio@kernel.org>,
"Lucas De Marchi" <lucas.demarchi@intel.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Mauro Carvalho Chehab" <mchehab@kernel.org>,
"Vladimir Oltean" <olteanv@gmail.com>,
"Andrew Lunn" <andrew@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Tony Nguyen" <anthony.l.nguyen@intel.com>,
"Przemek Kitszel" <przemyslaw.kitszel@intel.com>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Kishon Vijay Abraham I" <kishon@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Rodolfo Giometti" <giometti@enneenne.com>,
"Jonathan Lemon" <jonathan.lemon@gmail.com>,
"Vadim Fedorenko" <vadim.fedorenko@linux.dev>,
"Richard Cochran" <richardcochran@gmail.com>,
"Stefan Haberland" <sth@linux.ibm.com>,
"Jan Hoeppner" <hoeppner@linux.ibm.com>,
"Heiko Carstens" <hca@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
"Christian Borntraeger" <borntraeger@linux.ibm.com>,
"Sven Schnelle" <svens@linux.ibm.com>,
"Satish Kharat" <satishkh@cisco.com>,
"Sesidhar Baddela" <sebaddel@cisco.com>,
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Xiubo Li" <xiubli@redhat.com>,
"Ilya Dryomov" <idryomov@gmail.com>,
"Masami Hiramatsu" <mhiramat@kernel.org>,
"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Jaroslav Kysela" <perex@perex.cz>,
"Takashi Iwai" <tiwai@suse.com>
Subject: [PATCH v1 01/23] lib/vsprintf: Add specifier for printing struct timespec64
Date: Mon, 10 Nov 2025 19:40:20 +0100 [thread overview]
Message-ID: <20251110184727.666591-2-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20251110184727.666591-1-andriy.shevchenko@linux.intel.com>
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..6fdb417f5140 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>
+ %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 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 dot and nanoseconds.
+
Passed by reference.
struct clk
diff --git a/lib/tests/printf_kunit.c b/lib/tests/printf_kunit.c
index bc54cca2d7a6..7617e5b8b02c 100644
--- a/lib/tests/printf_kunit.c
+++ b/lib/tests/printf_kunit.c
@@ -504,6 +504,7 @@ time_and_date(struct kunit *kunittest)
};
/* 2019-01-04T15:32:23 */
time64_t t = 1546615943;
+ struct timespec64 ts = { .tv_sec = t, .tv_nsec = 11235813 };
test("(%pt?)", "%pt", &tm);
test("2018-11-26T05:35:43", "%ptR", &tm);
@@ -522,6 +523,9 @@ time_and_date(struct kunit *kunittest)
test("0119-00-04 15:32:23", "%ptTsr", &t);
test("15:32:23|2019-01-04", "%ptTts|%ptTds", &t, &t);
test("15:32:23|0119-00-04", "%ptTtrs|%ptTdrs", &t, &t);
+
+ test("2019-01-04T15:32:23.011235813", "%ptS", &ts);
+ test("1546615943.011235813", "%ptSp", &ts);
}
static void
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 3f99834fd788..f29eb6368891 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1989,6 +1989,28 @@ char *time64_str(char *buf, char *end, const time64_t time,
return rtc_str(buf, end, &rtc_time, spec, fmt);
}
+static noinline_for_stack
+char *timespec64_str(char *buf, char *end, const struct timespec64 *ts,
+ struct printf_spec spec, const char *fmt)
+{
+ static const struct printf_spec default_dec09_spec = {
+ .base = 10,
+ .field_width = 9,
+ .precision = -1,
+ .flags = ZEROPAD,
+ };
+
+ if (fmt[2] == 'p')
+ buf = number(buf, end, ts->tv_sec, default_dec_spec);
+ else
+ buf = time64_str(buf, end, ts->tv_sec, spec, fmt);
+ if (buf < end)
+ *buf = '.';
+ buf++;
+
+ return number(buf, end, ts->tv_nsec, default_dec09_spec);
+}
+
static noinline_for_stack
char *time_and_date(char *buf, char *end, void *ptr, struct printf_spec spec,
const char *fmt)
@@ -1999,6 +2021,8 @@ char *time_and_date(char *buf, char *end, void *ptr, struct printf_spec spec,
switch (fmt[1]) {
case 'R':
return rtc_str(buf, end, (const struct rtc_time *)ptr, spec, fmt);
+ case 'S':
+ return timespec64_str(buf, end, (const struct timespec64 *)ptr, spec, fmt);
case 'T':
return time64_str(buf, end, *(const time64_t *)ptr, spec, fmt);
default:
@@ -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:
* R struct rtc_time
+ * S struct timespec64
* T time64_t
* - 'C' For a clock, it prints the name (Common Clock Framework) or address
* (legacy clock framework) of the clock
--
2.50.1
next prev parent reply other threads:[~2025-11-10 18:47 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-10 18:40 [PATCH v1 00/23] treewide: Introduce %ptS for struct timespec64 and convert users Andy Shevchenko
2025-11-10 18:40 ` Andy Shevchenko [this message]
2025-11-10 18:40 ` [PATCH v1 02/23] ALSA: seq: Switch to use %ptSp Andy Shevchenko
2025-11-11 6:42 ` Takashi Iwai
2025-11-10 18:40 ` [PATCH v1 03/23] ceph: " Andy Shevchenko
2025-11-10 19:12 ` Viacheslav Dubeyko
2025-11-10 18:40 ` [PATCH v1 04/23] libceph: " Andy Shevchenko
2025-11-10 19:13 ` Viacheslav Dubeyko
2025-11-10 18:40 ` [PATCH v1 05/23] dma-buf: " Andy Shevchenko
2025-11-10 18:50 ` Christian König
2025-11-10 18:40 ` [PATCH v1 06/23] drm/amdgpu: " Andy Shevchenko
2025-11-10 18:40 ` [PATCH v1 07/23] drm/msm: " Andy Shevchenko
2025-11-10 18:40 ` [PATCH v1 08/23] drm/vblank: " Andy Shevchenko
2025-11-10 18:40 ` [PATCH v1 09/23] drm/xe: " Andy Shevchenko
2025-11-10 19:24 ` Lucas De Marchi
2025-11-10 18:40 ` [PATCH v1 10/23] e1000e: " Andy Shevchenko
2025-11-10 18:40 ` [PATCH v1 11/23] igb: " Andy Shevchenko
2025-11-10 18:40 ` [PATCH v1 12/23] ipmi: " Andy Shevchenko
2025-11-11 1:17 ` Corey Minyard
2025-11-11 8:08 ` Sergey Senozhatsky
2025-11-11 14:37 ` Corey Minyard
2025-11-10 18:40 ` [PATCH v1 13/23] media: av7110: " Andy Shevchenko
2025-11-11 7:57 ` Hans Verkuil
2025-11-10 18:40 ` [PATCH v1 14/23] media: v4l2-ioctl: " Andy Shevchenko
2025-11-11 8:04 ` Hans Verkuil
2025-11-10 18:40 ` [PATCH v1 15/23] mmc: mmc_test: " Andy Shevchenko
2025-11-10 18:40 ` [PATCH v1 16/23] net: dsa: sja1105: " Andy Shevchenko
2025-11-10 18:40 ` [PATCH v1 17/23] PCI: epf-test: " Andy Shevchenko
2025-11-11 0:11 ` Bjorn Helgaas
2025-11-10 18:40 ` [PATCH v1 18/23] pps: " Andy Shevchenko
2025-11-11 8:09 ` Rodolfo Giometti
2025-11-10 18:40 ` [PATCH v1 19/23] ptp: ocp: " Andy Shevchenko
2025-11-10 23:37 ` Vadim Fedorenko
2025-11-10 18:40 ` [PATCH v1 20/23] s390/dasd: " Andy Shevchenko
2025-11-10 18:40 ` [PATCH v1 21/23] scsi: fnic: Switch to use %ptS Andy Shevchenko
2025-11-10 18:40 ` [PATCH v1 22/23] scsi: snic: Switch to use %ptSp Andy Shevchenko
2025-11-10 18:40 ` [PATCH v1 23/23] tracing: " Andy Shevchenko
2025-11-10 19:12 ` Steven Rostedt
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=20251110184727.666591-2-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=abhinav.kumar@linux.dev \
--cc=agordeev@linux.ibm.com \
--cc=airlied@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=andrew@lunn.ch \
--cc=anthony.l.nguyen@intel.com \
--cc=bhelgaas@google.com \
--cc=borntraeger@linux.ibm.com \
--cc=calvin@wbinvd.org \
--cc=casey@schaufler-ca.com \
--cc=cassel@kernel.org \
--cc=ceph-devel@vger.kernel.org \
--cc=christian.koenig@amd.com \
--cc=corbet@lwn.net \
--cc=corey@minyard.net \
--cc=davem@davemloft.net \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=edumazet@google.com \
--cc=freedreno@lists.freedesktop.org \
--cc=giometti@enneenne.com \
--cc=gor@linux.ibm.com \
--cc=gregkh@linuxfoundation.org \
--cc=gustavo@padovan.org \
--cc=hca@linux.ibm.com \
--cc=hoeppner@linux.ibm.com \
--cc=hverkuil@kernel.org \
--cc=idryomov@gmail.com \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=jesszhan0024@gmail.com \
--cc=jonathan.lemon@gmail.com \
--cc=kartilak@cisco.com \
--cc=kishon@kernel.org \
--cc=konradybcio@kernel.org \
--cc=kuba@kernel.org \
--cc=kwilczynski@kernel.org \
--cc=laurent.pinchart+renesas@ideasonboard.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=linux@treblig.org \
--cc=lucas.demarchi@intel.com \
--cc=lumag@kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=maimon.sagi@gmail.com \
--cc=mani@kernel.org \
--cc=marijn.suijten@somainline.org \
--cc=martin.petersen@oracle.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=matthew.brost@intel.com \
--cc=max.kellermann@ionos.com \
--cc=mchehab@kernel.org \
--cc=mhiramat@kernel.org \
--cc=mripard@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=openipmi-developer@lists.sourceforge.net \
--cc=pabeni@redhat.com \
--cc=perex@perex.cz \
--cc=pmladek@suse.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=richardcochran@gmail.com \
--cc=robin.clark@oss.qualcomm.com \
--cc=rodrigo.vivi@intel.com \
--cc=rostedt@goodmis.org \
--cc=satishkh@cisco.com \
--cc=sean@poorly.run \
--cc=sebaddel@cisco.com \
--cc=senozhatsky@chromium.org \
--cc=simona@ffwll.ch \
--cc=sth@linux.ibm.com \
--cc=sumit.semwal@linaro.org \
--cc=svens@linux.ibm.com \
--cc=thomas.hellstrom@linux.intel.com \
--cc=tiwai@suse.com \
--cc=tiwai@suse.de \
--cc=tzimmermann@suse.de \
--cc=ulf.hansson@linaro.org \
--cc=vadim.fedorenko@linux.dev \
--cc=vitaly.lifshits@intel.com \
--cc=xiubli@redhat.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;
as well as URLs for NNTP newsgroup(s).