From: Riana Tauro <riana.tauro@intel.com>
To: Soham Purkait <soham.purkait@intel.com>,
<igt-dev@lists.freedesktop.org>, <vinay.belgaumkar@intel.com>,
<kamil.konieczny@intel.com>, <krzysztof.karas@intel.com>,
<zbigniew.kempczynski@intel.com>
Cc: <anshuman.gupta@intel.com>, <lucas.demarchi@intel.com>,
<rodrigo.vivi@intel.com>, <ashutosh.dixit@intel.com>,
<umesh.nerlige.ramappa@intel.com>
Subject: Re: [PATCH v15 3/5] tools/gputop/utils: Add gputop utility functions common to all drivers
Date: Thu, 26 Jun 2025 15:02:23 +0530 [thread overview]
Message-ID: <b989f9c8-9d3b-4baa-ab8d-5f915e33ed4c@intel.com> (raw)
In-Reply-To: <20250626091626.3760324-4-soham.purkait@intel.com>
On 6/26/2025 2:46 PM, Soham Purkait wrote:
> Implement utility functions in gputop for common operations and data
> handling across different drivers.
>
> v1:
> - Refactor GPUTOP into a vendor-agnostic tool. (Lucas)
> v2:
> - Remove magic number. (Krzysztof)
>
> Signed-off-by: Soham Purkait <soham.purkait@intel.com>
Looks good to me
Reviewed-by: Riana Tauro <riana.tauro@intel.com>
> ---
> tools/gputop/utils.c | 51 +++++++++++++++++++++++++++++++++++
> tools/gputop/utils.h | 63 ++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 114 insertions(+)
> create mode 100644 tools/gputop/utils.c
> create mode 100644 tools/gputop/utils.h
>
> diff --git a/tools/gputop/utils.c b/tools/gputop/utils.c
> new file mode 100644
> index 000000000..7f260dc05
> --- /dev/null
> +++ b/tools/gputop/utils.c
> @@ -0,0 +1,51 @@
> +// SPDX-License-Identifier: MIT
> +/*
> + * Copyright © 2025 Intel Corporation
> + */
> +#include <assert.h>
> +
> +#include "utils.h"
> +
> +static const char * const bars[] = { " ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█" };
> +
> +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 = PERCLIENT_ENGINE_WIDTH;
> +
> + 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/utils.h b/tools/gputop/utils.h
> new file mode 100644
> index 000000000..00befed56
> --- /dev/null
> +++ b/tools/gputop/utils.h
> @@ -0,0 +1,63 @@
> +/* SPDX-License-Identifier: MIT */
> +/*
> + * Copyright © 2025 Intel Corporation
> + */
> +
> +#ifndef COMMON_GPUTOP_H
> +#define COMMON_GPUTOP_H
> +
> +#include <glib.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"
> +
> +#define PERCLIENT_ENGINE_WIDTH 8
> +
> +/**
> + * struct gputop_driver
> + *
> + * @device_present: It is set if at least a single device of the
> + * respective driver is found.
> + * @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_driver {
> + bool device_present;
> + int len;
> + void *instances;
> +};
> +
> +/**
> + * struct device_operations - Structure to hold function
> + * pointers for device specific operations for each individual driver.
> + * @gputop_init: Function to initialize GPUTOP object
> + * @init_engines: Function to initialize engines for the respective driver.
> + * @pmu_init: Function to initialize the PMU (Performance Monitoring Unit).
> + * @pmu_sample: Function to sample PMU data.
> + * @print_engines: Function to print engine business.
> + * @clean_up: Function to release resources.
> + */
> +struct device_operations {
> + void (*gputop_init)(void *ptr, int index,
> + struct igt_device_card *card);
> + void *(*init_engines)(const void *obj, int index);
> + int (*pmu_init)(const void *obj, int index);
> + void (*pmu_sample)(const void *obj, int index);
> + int (*print_engines)(const void *obj, int index, int lines,
> + int w, int h);
> + void (*clean_up)(void *obj, int len);
> +};
> +
> +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);
> +
> +#endif /* COMMON_GPUTOP_H */
next prev parent reply other threads:[~2025-06-26 9:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-26 9:16 [PATCH v15 0/5] Add per-device engine activity stats in GPUTOP Soham Purkait
2025-06-26 9:16 ` [PATCH v15 1/5] lib/igt_device_scan: Add support for the device filter Soham Purkait
2025-06-26 9:16 ` [PATCH v15 2/5] lib/igt_device_scan: Enable finding all matched IGT devices Soham Purkait
2025-06-26 9:16 ` [PATCH v15 3/5] tools/gputop/utils: Add gputop utility functions common to all drivers Soham Purkait
2025-06-26 9:32 ` Riana Tauro [this message]
2025-06-26 9:16 ` [PATCH v15 4/5] tools/gputop/xe_gputop: Add gputop support for xe specific devices Soham Purkait
2025-06-26 9:30 ` Riana Tauro
2025-06-26 9:16 ` [PATCH v15 5/5] tools/gputop/gputop: Enable support for multiple GPUs and instances Soham Purkait
2025-06-27 8:17 ` Riana Tauro
2025-06-26 15:14 ` ✓ i915.CI.BAT: success for Add per-device engine activity stats in GPUTOP (rev12) Patchwork
2025-06-26 15:42 ` ✓ Xe.CI.BAT: " Patchwork
2025-06-27 4:02 ` ✗ i915.CI.Full: failure " Patchwork
2025-06-30 15:55 ` ✓ Xe.CI.Full: success " Patchwork
-- strict thread matches above, loose matches on Subject: below --
2025-06-25 7:28 [PATCH v15 0/5] Add per-device engine activity stats in GPUTOP Soham Purkait
2025-06-25 7:28 ` [PATCH v15 3/5] tools/gputop/utils: Add gputop utility functions common to all drivers Soham Purkait
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=b989f9c8-9d3b-4baa-ab8d-5f915e33ed4c@intel.com \
--to=riana.tauro@intel.com \
--cc=anshuman.gupta@intel.com \
--cc=ashutosh.dixit@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=kamil.konieczny@intel.com \
--cc=krzysztof.karas@intel.com \
--cc=lucas.demarchi@intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=soham.purkait@intel.com \
--cc=umesh.nerlige.ramappa@intel.com \
--cc=vinay.belgaumkar@intel.com \
--cc=zbigniew.kempczynski@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.