Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B1F40CCF9E0 for ; Mon, 27 Oct 2025 16:58:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5EF8410E542; Mon, 27 Oct 2025 16:58:00 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="QUJnJrX0"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 59A2D10E537 for ; Mon, 27 Oct 2025 16:57:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1761584277; x=1793120277; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=YK+K2VHIObnGk58fSU6yoMY2C2Mq8GrISHdFBzWrDc4=; b=QUJnJrX0X9pR9uFCP8gl8erc7X0ZZ7p0B3eIMD1tp5I1NpetY0mLQ9wB 5rR72kd8krqCQf1cMV/4mElSzKS0Oez551Jg2OW3ksQaMIWTUu7O5aGRb c6E1SC/IKRijz4hP6O0/NKqC3Z225WhirlSIfqMJ8BwxpUpo8iooDUnVY gQVCGUcORdWaqAF/n1wjPOxoFSvN4wzYxz4+HDwNcx+pq6lqIOj5iwzCK aHDMBYmo1Ih0NuKSNiLFewIs7xWhFWfKmHEzDD4e+vCLxswhkkMxXSItr oBYN0J29fox1VIyKo3Kzz0RneAx5QeixlxqcV82k4RrVhawZbI+CWvMpb A==; X-CSE-ConnectionGUID: LDZyQV3WSIm7eauYbMy3sw== X-CSE-MsgGUID: vFx66E3qQ66TmMm1VGWl2w== X-IronPort-AV: E=McAfee;i="6800,10657,11586"; a="67537492" X-IronPort-AV: E=Sophos;i="6.19,259,1754982000"; d="scan'208";a="67537492" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Oct 2025 09:57:56 -0700 X-CSE-ConnectionGUID: 6/G0E+55TF6X3PzlITt8VA== X-CSE-MsgGUID: rVUcAIgETDSo5jo3Jupkhw== X-ExtLoop1: 1 Received: from intel-s2600wft.iind.intel.com ([10.223.26.143]) by fmviesa003.fm.intel.com with ESMTP; 27 Oct 2025 09:57:54 -0700 From: S Sebinraj To: igt-dev@lists.freedesktop.org Cc: jeevaka.badrappan@intel.com, zbigniew.kempczynski@intel.com, kamil.konieczny@intel.com, S Sebinraj Subject: [PATCH i-g-t] RFC: tools/gputop: Add GPU frequencies to the client headers Date: Mon, 27 Oct 2025 22:13:54 +0530 Message-Id: <20251027164354.3546543-1-s.sebinraj@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" 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 --- tools/gputop.c | 112 +++++++++++++++++++++++++++++++++++++++++++++- tools/meson.build | 2 +- 2 files changed, 112 insertions(+), 2 deletions(-) diff --git a/tools/gputop.c b/tools/gputop.c index f577a1750..23df3b367 100644 --- a/tools/gputop.c +++ b/tools/gputop.c @@ -30,7 +30,9 @@ #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, @@ -76,17 +78,125 @@ 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; + bool is_xe = false; + int gt; + 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 *path_ptr; + FILE *fp; + unsigned int cur_freq = 0, act_freq = 0; + char freq_buf[32]; + + /* 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/freq0/cur_freq", gt_path); + else + snprintf(freq_path, sizeof(freq_path), "%s/rps_cur_freq_mhz", gt_path); + + fp = fopen(freq_path, "r"); + if (fp) { + if (fgets(freq_buf, sizeof(freq_buf), fp)) + cur_freq = atoi(freq_buf); + fclose(fp); + } else { + fprintf(stderr, "Failed to open %s\n", freq_path); + } + + /* Read actual frequency */ + if (is_xe) + snprintf(freq_path, sizeof(freq_path), "%s/freq0/act_freq", gt_path); + else + snprintf(freq_path, sizeof(freq_path), "%s/rps_act_freq_mhz", gt_path); + + fp = fopen(freq_path, "r"); + if (fp) { + if (fgets(freq_buf, sizeof(freq_buf), fp)) + act_freq = atoi(freq_buf); + fclose(fp); + } else { + fprintf(stderr, "Failed to open %s\n", freq_path); + } + + /* 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