mbox series

[v2,0/4] printf: Add struct range print specifier

Message ID 20241025-cxl-pra-v2-0-123a825daba2@intel.com
Headers show
Series printf: Add struct range print specifier | expand

Message

Ira Weiny Oct. 26, 2024, 12:46 a.m. UTC
Support for the Compute Express Link (CXL) Dynamic Capacity Devices
(DCD) have grown a number of uses to print struct range.[1]  Support for
a printf specifier '%pra' was being worked within a large series and has
garnered a number of comments and discussion.

To better accelerate both features introduce a separate series to settle
the struct range print enhancement divorced from the CXL DCD feature.

Struct range is used to store a number range similar to struct resource.
Printing struct range becomes cumbersome having to specify 2 specifiers
and the members of the struct.  Furthermore, print output benefits from
using a standardized format.

Add to the pointer specifier support for struct range.  Share code with
struct resource for more standardization.  Add tests for struct resource
to help prevent regressions.

%pra was settled on as the most reasonable format in previous
discussions.[2]

Link: https://lore.kernel.org/all/20241007-dcd-type2-upstream-v4-2-c261ee6eeded@intel.com/ [1]
Link: https://lore.kernel.org/all/66cea3bf3332f_f937b29424@iweiny-mobl.notmuch/ [2]

Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
Changes in v2:
- Andy: s/resource_and_range/resource_or_range/
- djbw/Petr: Address comments on documentation
- Link to v1: https://patch.msgid.link/20241018-cxl-pra-v1-0-7f49ba58208b@intel.com

---
Ira Weiny (4):
      test printf: Add very basic struct resource tests
      Documentation/printf: struct resource add start == end special case
      printf: Add print format (%pra) for struct range
      cxl/cdat: Use %pra for dpa range outputs

 Documentation/core-api/printk-formats.rst | 20 +++++++++-
 drivers/cxl/core/cdat.c                   |  8 ++--
 include/linux/range.h                     |  6 +++
 lib/test_printf.c                         | 61 +++++++++++++++++++++++++++++++
 lib/vsprintf.c                            | 57 ++++++++++++++++++++++++++---
 5 files changed, 141 insertions(+), 11 deletions(-)
---
base-commit: 9852d85ec9d492ebef56dc5f229416c925758edc
change-id: 20240930-cxl-pra-53956ac5fc1e

Best regards,

Comments

metux Oct. 30, 2024, 10:51 a.m. UTC | #1
On 26.10.24 02:46, Ira Weiny wrote:
> Support for the Compute Express Link (CXL) Dynamic Capacity Devices
> (DCD) have grown a number of uses to print struct range.[1]  Support for
> a printf specifier '%pra' was being worked within a large series and has
> garnered a number of comments and discussion.

This is just printing out hex dump of a memory range, correct ?

What I'm looking for quite some time is a sane way for dumping structs
in a human readable form (field: value pairs, using their actual types
eg. int vs string, ...).

Any idea to do that in a generic way ?
(potentially using debug info ?)


--mtx
Ira Weiny Oct. 31, 2024, 9:34 p.m. UTC | #2
metux wrote:
> On 26.10.24 02:46, Ira Weiny wrote:
> > Support for the Compute Express Link (CXL) Dynamic Capacity Devices
> > (DCD) have grown a number of uses to print struct range.[1]  Support for
> > a printf specifier '%pra' was being worked within a large series and has
> > garnered a number of comments and discussion.
> 
> This is just printing out hex dump of a memory range, correct ?

No.  This prints the struct range values not the data.

> 
> What I'm looking for quite some time is a sane way for dumping structs
> in a human readable form (field: value pairs, using their actual types
> eg. int vs string, ...).
>
> Any idea to do that in a generic way ?
> (potentially using debug info ?)
> 

For printing buffers less than 64 bytes look at:[1]

 %*ph

or bigger buffers

print_hex_dump()

Ira

[1] https://www.kernel.org/doc/html/latest/core-api/printk-formats.html
Petr Mladek Nov. 7, 2024, 2:43 p.m. UTC | #3
On Wed 2024-10-30 11:51:54, metux wrote:
> On 26.10.24 02:46, Ira Weiny wrote:
> > Support for the Compute Express Link (CXL) Dynamic Capacity Devices
> > (DCD) have grown a number of uses to print struct range.[1]  Support for
> > a printf specifier '%pra' was being worked within a large series and has
> > garnered a number of comments and discussion.
> 
> This is just printing out hex dump of a memory range, correct ?
> 
> What I'm looking for quite some time is a sane way for dumping structs
> in a human readable form (field: value pairs, using their actual types
> eg. int vs string, ...).

You like to print it similar way like "gdb" or other debugging tools do.
Do I get it correctly, please?

> Any idea to do that in a generic way ?
> (potentially using debug info ?)

I am afraid that a generic solution would really need to work with
a debuginfo.

That said, there exists some generic approaches for printing various
values in the trace code, for example, see

    Documentation/trace/kprobetrace.rst
    Documentation/trace/events.rst

Best Regards,
Petr