From: Riana Tauro <riana.tauro@intel.com>
To: Soham Purkait <soham.purkait@intel.com>,
<igt-dev@lists.freedesktop.org>, <vinay.belgaumkar@intel.com>
Cc: <anshuman.gupta@intel.com>, <lucas.demarchi@intel.com>,
<rodrigo.vivi@intel.com>, <jonathan.ming.jun.lui@intel.com>
Subject: Re: [PATCH i-g-t v3 2/4] Add gputop functionality common to all drivers
Date: Tue, 4 Mar 2025 15:37:09 +0530 [thread overview]
Message-ID: <31284f0d-4d38-440e-b087-6f5493521377@intel.com> (raw)
In-Reply-To: <20250228141810.1417657-3-soham.purkait@intel.com>
Hi Soham
Add description for each patch
On 2/28/2025 7:48 PM, Soham Purkait wrote:
> v2 : fix for refactoring GPUTOP into a
> vendor-agnostic tool (Lucas)
>
> v3 : Headers in alphabetical order (Kamil, Riana)
missing signed-off-by
use git commit -s
>
> ---
> tools/gputop/common_gputop.c | 79 ++++++++++++++++++++++++++++++++++++
> tools/gputop/common_gputop.h | 58 ++++++++++++++++++++++++++
> 2 files changed, 137 insertions(+)
> create mode 100644 tools/gputop/common_gputop.c
> create mode 100644 tools/gputop/common_gputop.h
>
> diff --git a/tools/gputop/common_gputop.c b/tools/gputop/common_gputop.c
> new file mode 100644
> index 000000000..578bd0a01
> --- /dev/null
> +++ b/tools/gputop/common_gputop.c
since this file has formatting and printing related functions.
different name?
> @@ -0,0 +1,79 @@
> +// SPDX-License-Identifier: MIT
> +/*
> + * Copyright © 2025 Intel Corporation
> + */
> +#include <assert.h>
> +
> +#include "common_gputop.h"
> +
> +static const char * const bars[] = { " ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█" };
> +
> +/* tr_pmu_name()
> + *
> + * Transliterate pci_slot_id to sysfs device name entry for GPU
> + * from type struct igt_device_card.
> + * GPU PCI ID ("xxxx:yy:zz.z") device = "xe_xxxx_yy_zz.z".
> + */
> +char *tr_pmu_name(const struct igt_device_card *card)
> +{
> + int ret;
> + const int bufsize = 16;
> + char *buf, *device = NULL;
> +
> + assert(card->pci_slot_name[0]);
> +
> + device = malloc(bufsize);
> + assert(device);
> +
> + ret = snprintf(device, bufsize, "xe_%s", card->pci_slot_name);
this file is named common but has "xe" in this function
you can use below from lib/igt_perf.h
const char *xe_perf_device(int xe, char *buf, int buflen)
const char *i915_perf_device(int i915, char *buf, int buflen)
or add a common function in igt_perf and re-use
> + assert(ret == (bufsize - 1));
> +
> + buf = device;
> + for (; *buf; buf++)
> + if (*buf == ':')
> + *buf = '_';
> +
> + return device;
> +}
> +
> +void n_spaces(const unsigned int n)
> +{
> + unsigned int i;
> +
> + for (i = 0; i < n; i++)
> + putchar(' ');
> +}
> +
> +void print_percentage_bar(double percent, int max_len)
> +{
> + int bar_len, i, len = max_len - 1;
> + const int w = 8;
> +
> + len -= printf("|%5.1f%% ", percent);
> +
> + /* no space left for bars, do what we can */
> + if (len < 0)
> + len = 0;
> +
> + bar_len = ceil(w * percent * len / 100.0);
> + if (bar_len > w * len)
> + bar_len = w * len;
> +
> + for (i = bar_len; i >= w; i -= w)
> + printf("%s", bars[w]);
> + if (i)
> + printf("%s", bars[i]);
> +
> + len -= (bar_len + (w - 1)) / w;
> + n_spaces(len);
> +
> + putchar('|');
> +}
> +
> +int print_engines_footer(int lines, int con_w, int con_h)
> +{
> + if (lines++ < con_h)
> + printf("\n");
> +
> + return lines;
> +}
> diff --git a/tools/gputop/common_gputop.h b/tools/gputop/common_gputop.h
> new file mode 100644
> index 000000000..4e6f632af
> --- /dev/null
> +++ b/tools/gputop/common_gputop.h
> @@ -0,0 +1,58 @@
> +// SPDX-License-Identifier: MIT
> +/*
> + * Copyright © 2025 Intel Corporation
> + */
> +
> +#ifndef COMMON_GPUTOP_H
> +#define COMMON_GPUTOP_H
> +
> +#include <math.h>
> +#include <stdbool.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +
> +#include "igt_device_scan.h"
> +
> +#define ANSI_HEADER "\033[7m"
> +#define ANSI_RESET "\033[0m"
> +
> +/**
> + * struct gputop_device
> + *
> + * @driver_present: It is set if at least a
> + * single device found of the respective driver
> + * @len: Number of total device discovered
> + * of the respective driver
> + * @instances: pointer to the array of
> + * discovered instances of the devices
> + * of the same driver
> + */
> +struct gputop_device {
> + bool driver_present;
> + int len;
> + void *instances;
> +};
> +
> +/**
> + * struct device_operations - Structure to hold function
> + * pointers for device specific operations for each individual driver.
> + * @populate_device_instances: Function to populate device instances.
> + * @discover_engines: Function to discover engines.
> + * @pmu_init: Function to initialize the PMU (Performance Monitoring Unit).
> + * @pmu_sample: Function to sample PMU data.
> + * @print_engines: Function to print engine business.
> + */
> +struct device_operations {
> + void (*populate_device_instances)(struct gputop_device *dv);
%s/dv/dev or device
> + void *(*discover_engines)(const void *obj);
> + int (*pmu_init)(const void *obj);
> + void (*pmu_sample)(const void *obj);
> + int (*print_engines)(const void *obj, int lines, int w, int h);
> +};
Why not combine both? Both are device specific.
Thanks
Riana Tauro
> +
> +void print_percentage_bar(double percent, int max_len);
> +int print_engines_footer(int lines, int con_w, int con_h);
> +void n_spaces(const unsigned int n);
> +char *tr_pmu_name(const struct igt_device_card *card);
> +
> +#endif // COMMON_GPUTOP_H
next prev parent reply other threads:[~2025-03-04 10:07 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-28 14:18 [PATCH i-g-t v3 0/4] Add single engine busyness stats in GPUTOP Soham Purkait
2025-02-28 14:18 ` [PATCH i-g-t v3 1/4] Enable finding all IGT devices for xe driver Soham Purkait
2025-02-28 16:58 ` Lucas De Marchi
2025-02-28 14:18 ` [PATCH i-g-t v3 2/4] Add gputop functionality common to all drivers Soham Purkait
2025-03-04 10:07 ` Riana Tauro [this message]
2025-02-28 14:18 ` [PATCH i-g-t v3 3/4] Add gputop support for xe specific devices Soham Purkait
2025-03-04 10:22 ` Riana Tauro
2025-02-28 14:18 ` [PATCH i-g-t v3 4/4] Enable support for multiple GPUs and instances Soham Purkait
2025-02-28 22:37 ` ✓ i915.CI.BAT: success for Add single engine busyness stats in GPUTOP (rev4) Patchwork
2025-02-28 23:06 ` ✓ Xe.CI.BAT: " Patchwork
2025-03-01 7:45 ` ✗ Xe.CI.Full: failure " Patchwork
2025-03-01 11:23 ` ✗ i915.CI.Full: " Patchwork
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=31284f0d-4d38-440e-b087-6f5493521377@intel.com \
--to=riana.tauro@intel.com \
--cc=anshuman.gupta@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=jonathan.ming.jun.lui@intel.com \
--cc=lucas.demarchi@intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=soham.purkait@intel.com \
--cc=vinay.belgaumkar@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