From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9F044CD13D3 for ; Tue, 11 Nov 2025 12:27:52 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 339AD60B9B; Tue, 11 Nov 2025 12:27:52 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id OaBn_WJGcQfh; Tue, 11 Nov 2025 12:27:50 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.166.142; helo=lists1.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org CADC860BA5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1762864070; bh=Y5r1nTziB8h17GUDW6RpOJ3bXeCV5EyDYesNxKaVYtQ=; h=From:To:Cc:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=G8qJQ0AwIJ93/8VezKccCKkw2CYenvxjhtaZgIj2Cwk73WTtivagphELlgo0quATt fv6JOIoQ3k7gdmMm2/1ly050JrTVIMHP82nbLeCKnQ/MIjAwJ8bGe2Nf/n2obI81zK zNlumC++KJ26YZNVQzAgd/zP3/1VSHI4VjaMbkLEUaD7CkLgWwSD7ayYIlrh3IfPki G2Bbq3JfBzyzKacyveOQq4iBEaxGxv+8Ie6yHZ/NmVErzirFE5YOgHCZRE2xNA8DU9 yGVSX8q+zh2eCu8MErFRPzeCS3Uch6zEMhIxr8J6NVg8aMkWQK7VTBM9YvnLeK6wTt wKZuWrQ8GIkyg== Received: from lists1.osuosl.org (lists1.osuosl.org [140.211.166.142]) by smtp3.osuosl.org (Postfix) with ESMTP id CADC860BA5; Tue, 11 Nov 2025 12:27:50 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists1.osuosl.org (Postfix) with ESMTP id 6DB4125D for ; Tue, 11 Nov 2025 12:27:49 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 5FF1E81EC1 for ; Tue, 11 Nov 2025 12:27:49 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 6kx9tYkeRkRP for ; Tue, 11 Nov 2025 12:27:48 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=192.198.163.9; helo=mgamail.intel.com; envelope-from=andriy.shevchenko@linux.intel.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp1.osuosl.org 1455981EC0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 1455981EC0 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) by smtp1.osuosl.org (Postfix) with ESMTPS id 1455981EC0 for ; Tue, 11 Nov 2025 12:27:47 +0000 (UTC) X-CSE-ConnectionGUID: VZrvj0a0Tf6cea80Noi3TA== X-CSE-MsgGUID: JcaZOjQ9T5WWj0YfZBWqIQ== X-IronPort-AV: E=McAfee;i="6800,10657,11609"; a="75606796" X-IronPort-AV: E=Sophos;i="6.19,296,1754982000"; d="scan'208";a="75606796" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2025 04:27:47 -0800 X-CSE-ConnectionGUID: 27aLKgpbQgyuRTW/cPkNLA== X-CSE-MsgGUID: uLAEySsEStOcyWXcWtA4FA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,296,1754982000"; d="scan'208";a="188592894" Received: from black.igk.intel.com ([10.91.253.5]) by fmviesa007.fm.intel.com with ESMTP; 11 Nov 2025 04:27:39 -0800 Received: by black.igk.intel.com (Postfix, from userid 1003) id D15F797; Tue, 11 Nov 2025 13:27:37 +0100 (CET) From: Andy Shevchenko To: Corey Minyard , =?UTF-8?q?Christian=20K=C3=B6nig?= , "Dr. David Alan Gilbert" , Alex Deucher , Thomas Zimmermann , Dmitry Baryshkov , Rob Clark , Matthew Brost , Ulf Hansson , Andy Shevchenko , Vitaly Lifshits , Manivannan Sadhasivam , Niklas Cassel , Calvin Owens , Vadim Fedorenko , Sagi Maimon , "Martin K. Petersen" , Karan Tilak Kumar , Hans Verkuil , Casey Schaufler , Steven Rostedt , Petr Mladek , Viacheslav Dubeyko , Max Kellermann , 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 , Sergey Senozhatsky , Jonathan Corbet , Sumit Semwal , Gustavo Padovan , David Airlie , Simona Vetter , Maarten Lankhorst , Maxime Ripard , Dmitry Baryshkov , Abhinav Kumar , Jessica Zhang , Sean Paul , Marijn Suijten , Konrad Dybcio , Lucas De Marchi , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Rodrigo Vivi , Vladimir Oltean , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Tony Nguyen , Przemek Kitszel , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Kishon Vijay Abraham I , Bjorn Helgaas , Rodolfo Giometti , Richard Cochran , Jonathan Lemon , Stefan Haberland , Jan Hoeppner , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Satish Kharat , Sesidhar Baddela , "James E.J. Bottomley" , Mauro Carvalho Chehab , Greg Kroah-Hartman , Xiubo Li , Ilya Dryomov , Masami Hiramatsu , Mathieu Desnoyers , Andrew Morton Date: Tue, 11 Nov 2025 13:20:01 +0100 Message-ID: <20251111122735.880607-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20251111122735.880607-1-andriy.shevchenko@linux.intel.com> References: <20251111122735.880607-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1762864068; x=1794400068; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=t3O/1gfEc/6EHpptFUQui/+YRYvWifZWWwljDBKqPQc=; b=lOUCn1XP5XTQUxwrU/xmyESe/nHTgaSInGdg0rhGuqXDxyscfr522fDR nk0p5jNJ6+8ftfzdJ88FpkUBUFCYVehjNZaWNvSrgtd8PSzoDCRQ7D+sv v1x9dPDxzPp0h3U68MW18AJHZJH6xsu9NtWrfmGFKOEcQuJrR7Olae76j ddUR3K1hc25pbv1w8tHum0CFrTDeDxCz4V/EQqiGjIUEStsiQJ2ws8Dai X3y+WpYfbU0+0blzrC9Hbv5YzBVyaJc9nxqTsFuFUcJkjPqlQOwBW7nPl N+giSKIqJPLM2se6bkafLzC6DhJdtMcQnm8qPvnusQ+KTY0kIf9LxglgY w==; X-Mailman-Original-Authentication-Results: smtp1.osuosl.org; dmarc=none (p=none dis=none) header.from=linux.intel.com X-Mailman-Original-Authentication-Results: smtp1.osuosl.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=lOUCn1XP Subject: [Intel-wired-lan] [PATCH v2 01/21] lib/vsprintf: Add specifier for printing struct timespec64 X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" 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 --- 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 . + %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 3f99834fd788..fdd06e8957a3 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