List the drm-ras nodes, and show the error counters of a given node: # drm_ras 0 0000:03:00.0 correctable-errors error-counter 1 0000:03:00.0 uncorrectable-errors error-counter # drm_ras -n 0 1 core-compute 0 2 soc-internal 0
Signed-off-by: Rodrigo Vivi <[email protected]> --- tools/drm_ras.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++ tools/meson.build | 7 +++ 2 files changed, 113 insertions(+) create mode 100644 tools/drm_ras.c diff --git a/tools/drm_ras.c b/tools/drm_ras.c new file mode 100644 index 000000000..0af1ca919 --- /dev/null +++ b/tools/drm_ras.c @@ -0,0 +1,106 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright © 2026 Intel Corporation + */ + +#include <errno.h> +#include <getopt.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "drmtest.h" +#include "igt_drm_ras_nl.h" + +static const char * const node_types[] = { + [DRM_RAS_NODE_TYPE_ERROR_COUNTER] = "error-counter", +}; + +#define name_of(names, i) \ + ((i) < ARRAY_SIZE(names) && (names)[i] ? (names)[i] : "unknown") + +static void print_node(const struct igt_drm_ras_node *node, void *data) +{ + printf("%u\t%s\t%s\t%s\n", node->id, node->device_name, node->node_name, + name_of(node_types, node->type)); +} + +static void find_node(const struct igt_drm_ras_node *node, void *data) +{ + struct igt_drm_ras_node *found = data; + + if (node->id == found->id) + *found = *node; +} + +static void print_error_counter(const struct igt_drm_ras_error_counter *counter, void *data) +{ + printf("%u\t%s\t%u\n", counter->id, counter->name, counter->value); +} + +static int show_node(struct igt_drm_ras_nl_context *ctx, uint32_t id) +{ + struct igt_drm_ras_node node = { .id = id }; + int ret; + + ret = igt_drm_ras_nl_list_nodes(ctx, find_node, &node); + if (ret) + return ret; + + switch (node.type) { + case 0: + return -ENOENT; + case DRM_RAS_NODE_TYPE_ERROR_COUNTER: + return igt_drm_ras_nl_list_error_counters(ctx, id, print_error_counter, NULL); + default: + return -EOPNOTSUPP; + } +} + +static void usage(const char *name) +{ + printf("Usage: %s [-n <node-id>]\n" + "List the DRM RAS nodes, or show the content of one node.\n" + " -n, --node <node-id> show the error counters of a node\n" + " -h, --help show this help\n", name); +} + +int main(int argc, char **argv) +{ + static const struct option opts[] = { + { "node", required_argument, NULL, 'n' }, + { "help", no_argument, NULL, 'h' }, + { } + }; + struct igt_drm_ras_nl_context ctx; + long node = -1; + int c, ret; + + while ((c = getopt_long(argc, argv, "n:h", opts, NULL)) != -1) { + switch (c) { + case 'n': + node = strtol(optarg, NULL, 0); + break; + case 'h': + usage(argv[0]); + return EXIT_SUCCESS; + default: + usage(argv[0]); + return EXIT_FAILURE; + } + } + + if (igt_drm_ras_nl_init(&ctx)) + return EXIT_FAILURE; + + ret = node < 0 ? igt_drm_ras_nl_list_nodes(&ctx, print_node, NULL) : + show_node(&ctx, node); + if (ret) + fprintf(stderr, "%s\n", strerror(-ret)); + else if (ctx.dump_interrupted) + fprintf(stderr, "List changed while reading, rerun for a consistent view\n"); + + igt_drm_ras_nl_cleanup(&ctx); + + return ret ? EXIT_FAILURE : EXIT_SUCCESS; +} diff --git a/tools/meson.build b/tools/meson.build index 68c31da92..78587ec74 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -38,6 +38,13 @@ foreach prog : tools_progs install : true) endforeach +if have_libnl + executable('drm_ras', 'drm_ras.c', + dependencies : [tool_deps, libnl, libnl_genl], + install_rpath : bindir_rpathdir, + install : true) +endif + executable('igt_stats', 'igt_stats.c', dependencies : [lib_igt_stats, lib_igt_tools_stub, math], install_rpath : bindir_rpathdir, -- 2.56.0
