[PATCH v2 06/12] tools/arch/x86/pmtctl: Add 'list --summary'
From: David E. Box
Date: Sun Nov 22 2026 - 14:34:31 EST
Add the --summary mode to 'list', which shows the GUIDs of the PMT
telemetry devices on the system, each with its platform and description
when its definitions are available, and the devices that have it.
Unlike the metric listing it works without metric definitions, and like
it, it can be restricted with --guid and --device.
Signed-off-by: David E. Box <david.e.box@xxxxxxxxxxxxxxx>
---
V2 changes:
- Replaces 'list --devices' from v1 13; v1's 'list --guids' is
dropped.
- Works without metric definitions (v1's failed without built-in
ones), is sorted, and honors --guid and --device.
tools/arch/x86/pmtctl/src/cmd_list.c | 40 +++++++++++++++++++++++++++-
tools/arch/x86/pmtctl/src/main.c | 2 +-
2 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/tools/arch/x86/pmtctl/src/cmd_list.c b/tools/arch/x86/pmtctl/src/cmd_list.c
index cefcb465969a..35a610909558 100644
--- a/tools/arch/x86/pmtctl/src/cmd_list.c
+++ b/tools/arch/x86/pmtctl/src/cmd_list.c
@@ -28,6 +28,9 @@
#define LIST_GROUP_DESC_INDENT 4
#define LIST_METRIC_DESC_INDENT 8
+/* Indent of a device name under its GUID group header */
+#define LIST_DEVICE_INDENT 6
+
/* Width limits of the line under a group header */
#define LIST_SEP_MIN ((size_t)8)
#define LIST_SEP_MAX ((size_t)100)
@@ -36,11 +39,13 @@
enum {
OPT_LIST_GUID = CHAR_MAX + 1,
OPT_LIST_DEVICE,
+ OPT_LIST_SUMMARY,
};
struct list_opts {
bool show_help;
struct pmt_device_filter filter;
+ bool summary;
};
static void list_usage(FILE *out)
@@ -53,7 +58,8 @@ static void list_usage(FILE *out)
"Options:\n"
" -h, --help Show this help.\n"
" --guid <hex> Restrict to devices with this GUID.\n"
- " --device <name> Restrict to one device, e.g. telem3.\n");
+ " --device <name> Restrict to one device, e.g. telem3.\n"
+ " --summary List GUIDs and their devices.\n");
}
static int parse_list_opts(struct list_opts *opts, int argc, char **argv)
@@ -62,6 +68,7 @@ static int parse_list_opts(struct list_opts *opts, int argc, char **argv)
{ "help", no_argument, NULL, 'h' },
{ "guid", required_argument, NULL, OPT_LIST_GUID },
{ "device", required_argument, NULL, OPT_LIST_DEVICE },
+ { "summary", no_argument, NULL, OPT_LIST_SUMMARY },
{}
};
int opt;
@@ -80,6 +87,9 @@ static int parse_list_opts(struct list_opts *opts, int argc, char **argv)
case OPT_LIST_DEVICE:
opts->filter.name = optarg;
break;
+ case OPT_LIST_SUMMARY:
+ opts->summary = true;
+ break;
default:
return -EINVAL;
}
@@ -176,6 +186,29 @@ static void print_guid_group_line(uint32_t guid, const struct pmt_tss_info *info
print_description(info->description, LIST_GROUP_DESC_INDENT, cols);
}
+/* List @devs, which are sorted by GUID as ctx->devices is */
+static void do_list_summary(const struct pmtctl_ctx *ctx, const struct pmt_device **devs,
+ size_t num_devs)
+{
+ size_t cols = output_columns();
+
+ printf("PMT devices on this system:\n\n");
+
+ for (size_t i = 0; i < num_devs; i++) {
+ uint32_t guid = devs[i]->guid;
+
+ if (!i || guid != devs[i - 1]->guid)
+ print_guid_group_line(guid, pmt_tss_db_lookup(&ctx->tss, guid), cols);
+
+ print_chars(' ', LIST_DEVICE_INDENT);
+ printf("%s\n", devs[i]->name);
+
+ /* A blank line ends each GUID group */
+ if (i + 1 == num_devs || devs[i + 1]->guid != guid)
+ printf("\n");
+ }
+}
+
/*
* Underline a group header up to where its longest metric name would end at
* the description indent, within LIST_SEP_MIN and LIST_SEP_MAX columns
@@ -274,6 +307,11 @@ int cmd_list(int argc, char **argv, const struct pmt_global_opts *gopts)
return PMTCTL_EXIT_USER;
}
+ if (opts.summary) {
+ do_list_summary(&ctx, devs, num_devs);
+ return PMTCTL_EXIT_OK;
+ }
+
if (!ctx.tss.num_tss_info) {
if (gopts->json_path)
log_err("no metric definitions in %s", gopts->json_path);
diff --git a/tools/arch/x86/pmtctl/src/main.c b/tools/arch/x86/pmtctl/src/main.c
index d4a7ae464cb8..081c33aeb649 100644
--- a/tools/arch/x86/pmtctl/src/main.c
+++ b/tools/arch/x86/pmtctl/src/main.c
@@ -27,7 +27,7 @@ static void print_usage(FILE *out)
" If omitted, " PMTCTL_DEFS_DIR " is used if it exists.\n"
"\n"
"Commands:\n"
- " list List available PMT metrics\n"
+ " list List available PMT devices and metrics\n"
"\n"
"Run 'pmtctl <command> --help' for command-specific options.\n");
}
--
2.53.0