[PATCH i-g-t v7 5/5] tools/gputop.src/gputop: Add command line option for device filter

Soham Purkait
2026-01-30T09:58:45Z

With a new command-line option for device filtering, the engine
busyness for the specific device could be selected.

Signed-off-by: Soham Purkait <soham.purkait@intel.com>
---
tools/gputop.src/gputop.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/tools/gputop.src/gputop.c b/tools/gputop.src/gputop.c
index 7d4515f8f..e803db99e 100644
--- a/tools/gputop.src/gputop.c
+++ b/tools/gputop.src/gputop.c
@@ -412,6 +412,7 @@ static void clrscr(void)
struct gputop_args {
long n_iter;
unsigned long delay_usec;
+ char *device;
};

static void countdown(const char *msg, const int start_sec)
@@ -450,7 +451,8 @@ static void help(char *full_path)
"Options:\n"
"\t-h, --help show this help\n"
"\t-d, --delay =SEC[.TENTHS] iterative delay as SECS [.TENTHS]\n"
- "\t-n, --iterations =NUMBER number of executions\n\n"
+ "\t-n, --iterations =NUMBER number of executions\n"
+ "\t-D, --device Device filter\n\n"
"Running without root:\n"
"\tAs a non-root user, CAP_PERFMON or perf_event_paranoid is required to\n"
"\taccess engine busyness\n"
@@ -481,11 +483,12 @@ static void help(char *full_path)

static int parse_args(int argc, char * const argv[], struct gputop_args *args)
{
- static const char cmdopts_s[] = "hn:d:";
+ static const char cmdopts_s[] = "hn:d:D:";
static const struct option cmdopts[] = {
{"help", no_argument, 0, 'h'},
{"delay", required_argument, 0, 'd'},
{"iterations", required_argument, 0, 'n'},
+ {"device", required_argument, 0, 'D'},
{ }
};

@@ -493,6 +496,7 @@ static int parse_args(int argc, char * const argv[], struct gputop_args *args)
memset(args, 0, sizeof(*args));
args->n_iter = -1;
args->delay_usec = 2 * USEC_PER_SEC;
+ args->device = NULL;

for (;;) {
int c, idx = 0;
@@ -516,6 +520,9 @@ static int parse_args(int argc, char * const argv[], struct gputop_args *args)
return -1;
}
break;
+ case 'D':
+ args->device = optarg;
+ break;
case 'h':
help(argv[0]);
return 0;
@@ -557,7 +564,8 @@ int main(int argc, char **argv)

n = args.n_iter;
period_us = args.delay_usec;
- populate_device_instances("device:subsystem=pci,card=all");
+ populate_device_instances(args.device ? args.device
+ : "device:subsystem=pci,card=all");

for (int i = 0; drivers[i]; i++) {
if (!per_driver_contexts[i].device_present)
--
2.34.1