tools/gputop: Add GPU frequencies to the client headers
PATCH v4 1/1 tools/gputop: Add GPU frequencies to the client headers
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
v2:
- To use macro to suffix strings
- To skip failure loops
v3:
- To keep error logs
v4:
- Removed RFC from Subject
--- tools/gputop.c | 119 +++++++++++++++++++++++++++++++++++++++++++++- tools/meson.build | 2 +- 2 files changed, 119 insertions(+), 2 deletions(-)
tools/gputop.c +118 -1
@@ -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,127 @@ 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); + }else { +fprintf (stderr,"Failed to open %s\n" , freq_path); +continue ; + } + +/* 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); + }else { +fprintf (stderr,"Failed to open %s\n" , freq_path); +continue ; + } + +/* 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)
tools/meson.build +1 -1
@@ -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,
Signature · 1 line
2.43.0
Hi S,
Quoted 40 lines · 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:
- Addget_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 accessThe 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/400v2:
- To use macro to suffix strings
- To skip failure loopsv3:
- To keep error logsv4:
- Removed RFC from SubjectSigned-off-by S Sebinraj <[email protected]>Tested-by Karas Krzysztof <[email protected]>Reviewed-by Karas Krzysztof <[email protected]>--- tools/gputop.c | 119 +++++++++++++++++++++++++++++++++++++++++++++- tools/meson.build | 2 +- 2 files changed, 119 insertions(+), 2 deletions(-)tools/gputop.c +0
-0
tools/gputop.c line 35
Quoted 6 lines
tools/gputop.c +2
-0@@ -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"
This add a lot of dependencies to a tool, before your change:
ldd build/tools/gputop |wc -l
5
after it:
ldd build/tools/gputop |wc -l
78
Please make it without need for linking all test libs.
Regards,
Kamil
Quoted 159 lines
tools/gputop.c +116
-1enum 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,127 @@ 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); + }else { +fprintf (stderr,"Failed to open %s\n" , freq_path); +continue ; + } + +/* 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); + }else { +fprintf (stderr,"Failed to open %s\n" , freq_path); +continue ; + } + +/* 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)tools/meson.build +1
-1@@ -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,Signature · 1 line
2.43.0
________________________________
From: Kamil Konieczny <[email protected]>
Sent: Tuesday, January 20, 2026 6:51 PM
To: Sebinraj, S <[email protected]>
Cc: [email protected] <[email protected]>; Badrappan, Jeevaka <[email protected]>; Karas, Krzysztof <[email protected]>; Konieczny, Kamil <[email protected]>
Subject: Re: [PATCH i-g-t v4] tools/gputop: Add GPU frequencies to the client headers
Hi S,
Quoted 47 lines · 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:
- Addget_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 accessThe 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/400v2:
- To use macro to suffix strings
- To skip failure loopsv3:
- To keep error logsv4:
- Removed RFC from SubjectSigned-off-by S Sebinraj <[email protected]>Tested-by Karas Krzysztof <[email protected]>Reviewed-by Karas Krzysztof <[email protected]>--- tools/gputop.c | 119 +++++++++++++++++++++++++++++++++++++++++++++- tools/meson.build | 2 +- 2 files changed, 119 insertions(+), 2 deletions(-)tools/gputop.c +2
-0@@ -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"
Quoted 1 line
This add a lot of dependencies to a tool, before your change:
ldd build/tools/gputop |wc -l
5
Quoted 1 line
after it:
ldd build/tools/gputop |wc -l
78
Quoted 3 lines
Please make it without need for linking all test libs.
Regards,
Kamil
Sure, I'll check these out, Thanks for pointing out.
Quoted 159 lines
enum
utilization_type{
UTILIZATION_TYPE_ENGINE_TIME,
UTILIZATION_TYPE_TOTAL_CYCLES,
};tools/gputop.c +116
-1+#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,127 @@ 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); + }else { +fprintf (stderr,"Failed to open %s\n" , freq_path); +continue ; + } + +/* 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); + }else { +fprintf (stderr,"Failed to open %s\n" , freq_path); +continue ; + } + +/* 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)tools/meson.build +1
-2@@ -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