Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH i-g-t v2] RFC: tools/gputop: Add GPU frequencies to the client headers
@ 2025-10-29  5:31 S Sebinraj
  2025-10-29  6:34 ` ✓ Xe.CI.BAT: success for RFC: tools/gputop: Add GPU frequencies to the client headers (rev2) Patchwork
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: S Sebinraj @ 2025-10-29  5:31 UTC (permalink / raw)
  To: igt-dev
  Cc: jeevaka.badrappan, zbigniew.kempczynski, kamil.konieczny,
	krzysztof.karas, S Sebinraj

Enhance gputop to display GPU frequency information (current/actual)
for each GT in the client header line alongside the DRM minor number.

Key changes:
- Add get_gt_frequencies() function to read GT frequency values
- Support both i915 and Xe drivers using appropriate sysfs paths
- Display format: "DRM minor X  Freq(cur/act) GT0-freq/freq GT1-freq/freq"
- Use IGT API functions (xe_sysfs_gt_path, igt_sysfs_gt_path) for
  driver-agnostic sysfs access

The frequency information helps users monitor GPU performance states
in real-time while observing client workload utilization.

Example output:
  DRM minor 0          Freq(cur/act) GT0-1800/1800 GT1-400/400
  DRM minor 128        Freq(cur/act) GT0-400/400 GT1-400/400

Signed-off-by: S Sebinraj <s.sebinraj@intel.com>
---
 tools/gputop.c    | 113 +++++++++++++++++++++++++++++++++++++++++++++-
 tools/meson.build |   2 +-
 2 files changed, 113 insertions(+), 2 deletions(-)

diff --git a/tools/gputop.c b/tools/gputop.c
index f577a1750..9c4365c5d 100644
--- a/tools/gputop.c
+++ b/tools/gputop.c
@@ -30,13 +30,20 @@
 #include "igt_drm_clients.h"
 #include "igt_drm_fdinfo.h"
 #include "igt_profiling.h"
+#include "igt_sysfs.h"
 #include "drmtest.h"
+#include "xe/xe_gt.h"
 
 enum utilization_type {
 	UTILIZATION_TYPE_ENGINE_TIME,
 	UTILIZATION_TYPE_TOTAL_CYCLES,
 };
 
+#define XE_FREQ_CUR_SUFFIX "/freq0/cur_freq"
+#define XE_FREQ_ACT_SUFFIX "/freq0/act_freq"
+#define I915_FREQ_CUR_SUFFIX "/rps_cur_freq_mhz"
+#define I915_FREQ_ACT_SUFFIX "/rps_act_freq_mhz"
+
 static const char *bars[] = { " ", "▏", "▎", "▍", "▌", "▋", "▊", "▉", "█" };
 
 #define ANSI_HEADER "\033[7m"
@@ -76,17 +83,121 @@ static void print_percentage_bar(double percent, int max_len)
 	putchar('|');
 }
 
+static char *get_gt_frequencies(void)
+{
+	char freq_str[512] = "";
+	char gt_info[64];
+	int fd = -1;
+	int num_gts = 0;
+	int gt;
+	bool is_xe = false;
+	bool first = true;
+
+	fd = __drm_open_driver(DRIVER_INTEL | DRIVER_XE);
+	if (fd < 0) {
+		fprintf(stderr, "Failed to open DRM device\n");
+		return NULL;
+	}
+
+	/* Detect driver type and get GT count */
+	is_xe = is_xe_device(fd);
+	if (is_xe)
+		num_gts = xe_number_gt(fd);
+	else
+		num_gts = igt_sysfs_get_num_gt(fd);
+
+	if (num_gts <= 0) {
+		fprintf(stderr, "Failed to get GT count\n");
+		close(fd);
+		return NULL;
+	}
+
+	/* Read frequencies for each GT */
+	for (gt = 0; gt < num_gts; gt++) {
+		char gt_path[96];
+		char freq_path[128];
+		char freq_buf[32];
+		char *path_ptr;
+		unsigned int cur_freq = 0, act_freq = 0;
+		FILE *fp;
+
+		/* Get GT-specific sysfs path */
+		if (is_xe)
+			path_ptr = xe_sysfs_gt_path(fd, gt, gt_path, sizeof(gt_path));
+		else
+			path_ptr = igt_sysfs_gt_path(fd, gt, gt_path, sizeof(gt_path));
+
+		if (!path_ptr) {
+			fprintf(stderr, "Failed to get sysfs path for GT%d\n", gt);
+			continue;
+		}
+
+		/* Read current/requested frequency */
+		if (is_xe)
+			snprintf(freq_path, sizeof(freq_path), "%s%s", gt_path, XE_FREQ_CUR_SUFFIX);
+		else
+			snprintf(freq_path, sizeof(freq_path), "%s%s", gt_path, I915_FREQ_CUR_SUFFIX);
+
+		fp = fopen(freq_path, "r");
+		if (fp) {
+			if (fgets(freq_buf, sizeof(freq_buf), fp))
+				cur_freq = atoi(freq_buf);
+			fclose(fp);
+		}
+
+		/* Read actual frequency */
+		if (is_xe)
+			snprintf(freq_path, sizeof(freq_path), "%s%s", gt_path, XE_FREQ_ACT_SUFFIX);
+		else
+			snprintf(freq_path, sizeof(freq_path), "%s%s", gt_path, I915_FREQ_ACT_SUFFIX);
+
+		fp = fopen(freq_path, "r");
+		if (fp) {
+			if (fgets(freq_buf, sizeof(freq_buf), fp))
+				act_freq = atoi(freq_buf);
+			fclose(fp);
+		}
+
+		/* Append to frequency string */
+		if (!first)
+			strcat(freq_str, " ");
+		else
+			first = false;
+
+		snprintf(gt_info, sizeof(gt_info), "GT%d-%u/%u", gt, cur_freq, act_freq);
+		strcat(freq_str, gt_info);
+	}
+
+	close(fd);
+
+	if (strlen(freq_str) > 0)
+		return strdup(freq_str);
+
+	return NULL;
+}
+
 static int
 print_client_header(struct igt_drm_client *c, int lines, int con_w, int con_h,
 		    int *engine_w)
 {
 	int ret, len;
+	char *freq_info = NULL;
 
 	if (lines++ >= con_h)
 		return lines;
 
 	printf(ANSI_HEADER);
-	ret = printf("DRM minor %u", c->drm_minor);
+
+	/* Get frequency information */
+	freq_info = get_gt_frequencies();
+
+	if (freq_info) {
+		ret = printf("DRM minor %u          Freq(cur/act) %s", c->drm_minor, freq_info);
+		free(freq_info);
+	} else {
+		ret = printf("DRM minor %u", c->drm_minor);
+	}
+
 	n_spaces(con_w - ret);
 
 	if (lines++ >= con_h)
diff --git a/tools/meson.build b/tools/meson.build
index 8185ba160..d3261d429 100644
--- a/tools/meson.build
+++ b/tools/meson.build
@@ -73,7 +73,7 @@ endif
 executable('gputop', 'gputop.c',
            install : true,
            install_rpath : bindir_rpathdir,
-           dependencies : [lib_igt_drm_clients,lib_igt_drm_fdinfo,lib_igt_profiling,math])
+           dependencies : [lib_igt_drm_clients,lib_igt_drm_fdinfo,lib_igt_profiling,tool_deps,math])
 
 intel_l3_parity_src = [ 'intel_l3_parity.c', 'intel_l3_udev_listener.c' ]
 executable('intel_l3_parity', sources : intel_l3_parity_src,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-11-18  5:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-29  5:31 [PATCH i-g-t v2] RFC: tools/gputop: Add GPU frequencies to the client headers S Sebinraj
2025-10-29  6:34 ` ✓ Xe.CI.BAT: success for RFC: tools/gputop: Add GPU frequencies to the client headers (rev2) Patchwork
2025-10-29  7:46 ` [PATCH i-g-t v2] RFC: tools/gputop: Add GPU frequencies to the client headers Krzysztof Karas
2025-11-18  5:57   ` Sebinraj, S
2025-10-29  8:47 ` ✓ i915.CI.BAT: success for RFC: tools/gputop: Add GPU frequencies to the client headers (rev2) Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox