linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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>,
	"Ulf Hansson" <ulf.hansson@linaro.org>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Aleksandr Loktionov" <aleksandr.loktionov@intel.com>,
	"Vitaly Lifshits" <vitaly.lifshits@intel.com>,
	"Manivannan Sadhasivam" <mani@kernel.org>,
	"Niklas Cassel" <cassel@kernel.org>,
	"Calvin Owens" <calvin@wbinvd.org>,
	"Vadim Fedorenko" <vadim.fedorenko@linux.dev>,
	"Sagi Maimon" <maimon.sagi@gmail.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	"Karan Tilak Kumar" <kartilak@cisco.com>,
	"Hans Verkuil" <hverkuil+cisco@kernel.org>,
	"Casey Schaufler" <casey@schaufler-ca.com>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Petr Mladek" <pmladek@suse.com>,
	"Viacheslav Dubeyko" <Slava.Dubeyko@ibm.com>,
	"Max Kellermann" <max.kellermann@ionos.com>,
	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
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>,
	"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>,
	"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>,
	"Mauro Carvalho Chehab" <mchehab@kernel.org>,
	"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>
Subject: [PATCH v3 01/21] lib/vsprintf: Add specifier for printing struct timespec64
Date: Thu, 13 Nov 2025 15:32:15 +0100	[thread overview]
Message-ID: <20251113150217.3030010-2-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20251113150217.3030010-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                            | 28 ++++++++++++++++++++++-
 3 files changed, 40 insertions(+), 3 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>
+	%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/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 11dbf1023391..51a88b3f5b52 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1983,6 +1983,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)
@@ -1993,6 +2015,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:
@@ -2456,9 +2480,11 @@ early_param("no_hash_pointers", no_hash_pointers_enable);
  * - 'd[234]' For a dentry name (optionally 2-4 last components)
  * - 'D[234]' Same as 'd' but for a struct file
  * - 'g' For block_device name (gendisk + partition number)
- * - 't[RT][dt][r][s]' For time and date as represented by:
+ * - 't[RST][dt][r][s]' For time and date as represented by:
  *      R    struct rtc_time
+ *      S    struct timespec64
  *      T    time64_t
+ * - 'tSp' For time represented by struct timespec64 printed as <seconds>.<nanoseconds>
  * - 'C' For a clock, it prints the name (Common Clock Framework) or address
  *       (legacy clock framework) of the clock
  * - 'G' For flags to be printed as a collection of symbolic strings that would
-- 
2.50.1


  reply	other threads:[~2025-11-13 15:02 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-13 14:32 [PATCH v3 00/21] treewide: Introduce %ptS for struct timespec64 and convert users Andy Shevchenko
2025-11-13 14:32 ` Andy Shevchenko [this message]
2025-11-14 12:59   ` [PATCH v3 01/21] lib/vsprintf: Add specifier for printing struct timespec64 Petr Mladek
2025-11-13 14:32 ` [PATCH v3 02/21] ceph: Switch to use %ptSp Andy Shevchenko
2025-11-13 14:32 ` [PATCH v3 03/21] libceph: " Andy Shevchenko
2025-11-13 14:32 ` [PATCH v3 04/21] dma-buf: " Andy Shevchenko
2025-11-13 14:32 ` [PATCH v3 05/21] drm/amdgpu: " Andy Shevchenko
2025-11-13 14:32 ` [PATCH v3 06/21] drm/msm: " Andy Shevchenko
2025-11-14  4:12   ` Dmitry Baryshkov
2025-11-13 14:32 ` [PATCH v3 07/21] drm/vblank: " Andy Shevchenko
2025-11-13 14:32 ` [PATCH v3 08/21] drm/xe: " Andy Shevchenko
2025-11-13 14:32 ` [PATCH v3 09/21] e1000e: " Andy Shevchenko
2025-11-13 14:32 ` [PATCH v3 10/21] igb: " Andy Shevchenko
2025-11-13 14:32 ` [PATCH v3 11/21] ipmi: " Andy Shevchenko
2025-11-13 14:32 ` [PATCH v3 12/21] media: av7110: " Andy Shevchenko
2025-11-13 14:32 ` [PATCH v3 13/21] mmc: mmc_test: " Andy Shevchenko
2025-11-17 11:00   ` Ulf Hansson
2025-11-13 14:32 ` [PATCH v3 14/21] net: dsa: sja1105: " Andy Shevchenko
2025-11-13 14:32 ` [PATCH v3 15/21] PCI: epf-test: " Andy Shevchenko
2025-11-13 14:32 ` [PATCH v3 16/21] pps: " Andy Shevchenko
2025-11-13 14:32 ` [PATCH v3 17/21] ptp: ocp: " Andy Shevchenko
2025-11-13 14:32 ` [PATCH v3 18/21] s390/dasd: " Andy Shevchenko
2025-11-13 14:32 ` [PATCH v3 19/21] scsi: fnic: " Andy Shevchenko
2025-11-13 22:34   ` Karan Tilak Kumar (kartilak)
2025-11-13 14:32 ` [PATCH v3 20/21] scsi: snic: " Andy Shevchenko
2025-11-15 20:27   ` Karan Tilak Kumar (kartilak)
2025-11-13 14:32 ` [PATCH v3 21/21] tracing: " Andy Shevchenko

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=20251113150217.3030010-2-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=Slava.Dubeyko@ibm.com \
    --cc=abhinav.kumar@linux.dev \
    --cc=agordeev@linux.ibm.com \
    --cc=airlied@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=aleksandr.loktionov@intel.com \
    --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+cisco@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=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-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=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=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).