From: Ira Weiny <ira.weiny@intel.com>
To: Dave Jiang <dave.jiang@intel.com>, Fan Ni <fan.ni@samsung.com>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
Navneet Singh <navneet.singh@intel.com>
Cc: Dan Williams <dan.j.williams@intel.com>,
Davidlohr Bueso <dave@stgolabs.net>,
Alison Schofield <alison.schofield@intel.com>,
Vishal Verma <vishal.l.verma@intel.com>,
Ira Weiny <ira.weiny@intel.com>,
linux-btrfs@vger.kernel.org, linux-cxl@vger.kernel.org,
linux-kernel@vger.kernel.org, Petr Mladek <pmladek@suse.com>,
Steven Rostedt <rostedt@goodmis.org>,
Jonathan Corbet <corbet@lwn.net>,
"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>
Subject: [PATCH v2 02/25] printk: Add print format (%par) for struct range
Date: Fri, 16 Aug 2024 08:59:50 -0500 [thread overview]
Message-ID: <20240816-dcd-type2-upstream-v2-2-20189a10ad7d@intel.com> (raw)
In-Reply-To: <20240816-dcd-type2-upstream-v2-0-20189a10ad7d@intel.com>
The use of struct range in the CXL subsystem is growing. In particular,
the addition of Dynamic Capacity devices uses struct range in a number
of places which are reported in debug and error messages.
To wit requiring the printing of the start/end fields in each print
became cumbersome. Dan Williams mentions in [1] that it might be time
to have a print specifier for struct range similar to struct resource
A few alternatives were considered including '%pn' for 'print raNge' but
%par follows that struct range is most often used to store a range of
physical addresses. So use '%par' for 'print address range'.
To: Petr Mladek <pmladek@suse.com> (maintainer:VSPRINTF)
To: Steven Rostedt <rostedt@goodmis.org> (maintainer:VSPRINTF)
To: Jonathan Corbet <corbet@lwn.net> (maintainer:DOCUMENTATION)
Cc: linux-doc@vger.kernel.org (open list:DOCUMENTATION)
Cc: linux-kernel@vger.kernel.org (open list)
Link: https://lore.kernel.org/all/663922b475e50_d54d72945b@dwillia2-xfh.jf.intel.com.notmuch/ [1]
Suggested-by: "Dan Williams" <dan.j.williams@intel.com>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
Documentation/core-api/printk-formats.rst | 14 ++++++++++++
lib/vsprintf.c | 37 +++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+)
diff --git a/Documentation/core-api/printk-formats.rst b/Documentation/core-api/printk-formats.rst
index 4451ef501936..a02ef899b2a6 100644
--- a/Documentation/core-api/printk-formats.rst
+++ b/Documentation/core-api/printk-formats.rst
@@ -231,6 +231,20 @@ width of the CPU data path.
Passed by reference.
+Struct Range
+------------
+
+::
+
+ %par [range 0x60000000-0x6fffffff] or
+ [range 0x0000000060000000-0x000000006fffffff]
+
+For printing struct range. A variation of printing a physical address is to
+print the value of struct range which are often used to hold a physical address
+range.
+
+Passed by reference.
+
DMA address types dma_addr_t
----------------------------
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 2d71b1115916..c132178fac07 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1140,6 +1140,39 @@ char *resource_string(char *buf, char *end, struct resource *res,
return string_nocheck(buf, end, sym, spec);
}
+static noinline_for_stack
+char *range_string(char *buf, char *end, const struct range *range,
+ struct printf_spec spec, const char *fmt)
+{
+#define RANGE_PRINTK_SIZE 16
+#define RANGE_DECODED_BUF_SIZE ((2 * sizeof(struct range)) + 4)
+#define RANGE_PRINT_BUF_SIZE sizeof("[range - ]")
+ char sym[RANGE_DECODED_BUF_SIZE + RANGE_PRINT_BUF_SIZE];
+ char *p = sym, *pend = sym + sizeof(sym);
+
+ static const struct printf_spec str_spec = {
+ .field_width = -1,
+ .precision = 10,
+ .flags = LEFT,
+ };
+ static const struct printf_spec range_spec = {
+ .base = 16,
+ .field_width = RANGE_PRINTK_SIZE,
+ .precision = -1,
+ .flags = SPECIAL | SMALL | ZEROPAD,
+ };
+
+ *p++ = '[';
+ p = string_nocheck(p, pend, "range ", str_spec);
+ p = number(p, pend, range->start, range_spec);
+ *p++ = '-';
+ p = number(p, pend, range->end, range_spec);
+ *p++ = ']';
+ *p = '\0';
+
+ return string_nocheck(buf, end, sym, spec);
+}
+
static noinline_for_stack
char *hex_string(char *buf, char *end, u8 *addr, struct printf_spec spec,
const char *fmt)
@@ -1802,6 +1835,8 @@ char *address_val(char *buf, char *end, const void *addr,
return buf;
switch (fmt[1]) {
+ case 'r':
+ return range_string(buf, end, addr, spec, fmt);
case 'd':
num = *(const dma_addr_t *)addr;
size = sizeof(dma_addr_t);
@@ -2364,6 +2399,8 @@ char *rust_fmt_argument(char *buf, char *end, void *ptr);
* to use print_hex_dump() for the larger input.
* - 'a[pd]' For address types [p] phys_addr_t, [d] dma_addr_t and derivatives
* (default assumed to be phys_addr_t, passed by reference)
+ * - 'ar' For decoded struct ranges (a variation of physical address which are
+ * most often stored in struct ranges.
* - '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)
--
2.45.2
next prev parent reply other threads:[~2024-08-16 13:59 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-16 13:59 [PATCH v2 00/25] DCD: Add support for Dynamic Capacity Devices (DCD) Ira Weiny
2024-08-16 13:59 ` [PATCH v2 01/25] range: Add range_overlaps() Ira Weiny
2024-08-16 13:59 ` Ira Weiny [this message]
2024-08-16 13:59 ` [PATCH v2 03/25] dax: Document dax dev range tuple Ira Weiny
2024-08-16 13:59 ` [PATCH v2 04/25] cxl/pci: Delay event buffer allocation Ira Weiny
2024-08-16 13:59 ` [PATCH v2 05/25] cxl/mbox: Flag support for Dynamic Capacity Devices (DCD) ira.weiny
2024-08-16 13:59 ` [PATCH v2 06/25] cxl/mem: Read dynamic capacity configuration from the device ira.weiny
2024-08-16 13:59 ` [PATCH v2 07/25] cxl/core: Separate region mode from decoder mode ira.weiny
2024-08-16 13:59 ` [PATCH v2 08/25] cxl/region: Add dynamic capacity decoder and region modes ira.weiny
2024-08-16 13:59 ` [PATCH v2 09/25] cxl/hdm: Add dynamic capacity size support to endpoint decoders ira.weiny
2024-08-16 13:59 ` [PATCH v2 10/25] cxl/port: Add endpoint decoder DC mode support to sysfs ira.weiny
2024-08-16 13:59 ` [PATCH v2 11/25] cxl/mem: Expose DCD partition capabilities in sysfs ira.weiny
2024-08-16 14:00 ` [PATCH v2 12/25] cxl/region: Refactor common create region code Ira Weiny
2024-08-16 14:00 ` [PATCH v2 13/25] cxl/region: Add sparse DAX region support ira.weiny
2024-08-16 14:00 ` [PATCH v2 14/25] cxl/events: Split event msgnum configuration from irq setup Ira Weiny
2024-08-16 14:00 ` [PATCH v2 15/25] cxl/pci: Factor out interrupt policy check Ira Weiny
2024-08-16 14:00 ` [PATCH v2 16/25] cxl/mem: Configure dynamic capacity interrupts ira.weiny
2024-08-16 14:00 ` [PATCH v2 17/25] cxl/core: Return endpoint decoder information from region search Ira Weiny
2024-08-16 14:00 ` [PATCH v2 18/25] cxl/extent: Process DCD events and realize region extents ira.weiny
2024-08-16 14:00 ` [PATCH v2 19/25] cxl/region/extent: Expose region extent information in sysfs ira.weiny
2024-08-16 14:00 ` [PATCH v2 20/25] dax/bus: Factor out dev dax resize logic Ira Weiny
2024-08-16 14:00 ` [PATCH v2 21/25] dax/region: Create resources on sparse DAX regions Ira Weiny
2024-08-16 14:17 ` [PATCH v2 00/25] DCD: Add support for Dynamic Capacity Devices (DCD) Ira Weiny
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=20240816-dcd-type2-upstream-v2-2-20189a10ad7d@intel.com \
--to=ira.weiny@intel.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=alison.schofield@intel.com \
--cc=corbet@lwn.net \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=fan.ni@samsung.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=navneet.singh@intel.com \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=vishal.l.verma@intel.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