Skip to contentSkip to conversation

tools/intel_gpu_frequency: Add multi-GT support and Xe driver compatibility

PATCH Superseded S Sebinraj 2 participants 6 messages Nov 19, 2025 – Nov 20, 2025 Library code

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

S Sebinraj

author
#0 lore raw

v3 cover tools/intel_gpu_frequency: Add multi-GT support and Xe driver compatibility

This patch enhances intel_gpu_frequency to support Intel GPUs with multiple Graphics Technology (GT) units and adds compatibility with both i915 and Xe drivers. This also includes the changes to use get, set in order and vice-versa which was resulting in assertion errors, prior to this changes.

Key improvements:
- Add runtime GT detection using igt_sysfs_get_num_gt() and xe_number_gt()
- Auto-detect driver type (i915 vs Xe) using is_xe_device()
- New --gt/-t option to specify target GT (defaults to GT0)
- New --list/-l option to display available GTs
- Driver-agnostic frequency management with unified interface
- Add support for get, set inorder and vice-versa.

Driver-specific implementations:
- Frequency name mapping for Xe (RP1→rpe, RP0→rp0, RPn→rpn for Xe)

Usage examples:
intel_gpu_frequency --get --gt 1 # Get GT1 frequencies
intel_gpu_frequency --set 400 --gt 0 # Set GT0 frequency
intel_gpu_frequency --list # List available GTs

The tool now auto-detects i915 / Xe drivers and uses appropriate interfaces.

S Sebinraj (3):
tools/intel_gpu_frequency: Add support for get, set in order &
vice-versa
tools/intel_gpu_frequency: Add multi-GT support tools/intel_gpu_frequency: Add Xe driver support

 lib/drmtest.c               |   2 +-
 man/intel_gpu_frequency.rst |  34 +++-
 tools/intel_gpu_frequency.c | 363 +++++++++++++++++++++++++++++-------
 3 files changed, 321 insertions(+), 78 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v3 1/3 tools/intel_gpu_frequency: Add support for get, set in order & vice-versa

Add proper conditions for handling get and set in order (also vice-versa), as the same was failing before with the below error. To note here, In this scenario w.r.t set operation, only writable sysfs path has to be used ie. [min, max].

Error: set_frequency:

	Assertion `fprintf(freq_info->filp, "%d", val) > 0' failed.
---
 tools/intel_gpu_frequency.c | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)
tools/intel_gpu_frequency.c +23 -11
index de0c6ddba..2cf3cabb6 100644
@@ -151,7 +151,7 @@ version(const char *prog)
 
 /* Returns read or write operation */
 static bool
-parse(int argc, char *argv[], bool *act_upon, size_t act_upon_n, int *new_freq)
+parse(int argc, char *argv[], bool *act_upon, size_t act_upon_n, int *new_freq, bool *reader)
 {
 	int c, tmp;
 	bool write = false;
@@ -182,13 +182,12 @@ parse(int argc, char *argv[], bool *act_upon, size_t act_upon_n, int *new_freq)
 
 		switch (c) {
 		case 'g':
-			if (write == true)
-				fprintf(stderr, "Read and write operations not support simultaneously.\n");
 			{
 				int i;
 				for (i = 0; i < act_upon_n; i++)
 					act_upon[i] = true;
 			}
+			*reader = true;
 			break;
 		case 's':
 			if (!optarg)
@@ -280,7 +279,7 @@ done:
 int main(int argc, char *argv[])
 {
 
-	bool write, fail, targets[MAX+1] = {false};
+	bool write, reader = false, fail, targets[MAX+1] = {false};
 	int i, fd, try = 1, set_freq[MAX+1] = {0};
 
 	fd = __drm_open_driver(DRIVER_INTEL);
@@ -288,7 +287,7 @@ int main(int argc, char *argv[])
 	device = igt_device_get_card_index(fd);
 	close(fd);
 
-	write = parse(argc, argv, targets, ARRAY_SIZE(targets), set_freq);
+	write = parse(argc, argv, targets, ARRAY_SIZE(targets), set_freq, &reader);
 	fail = write;
 
 	/* If we've previously locked the frequency, we need to make sure to set things
@@ -305,18 +304,24 @@ again:
 		fprintf(stderr, "Did not achieve desired freq.\n");
 		exit(EXIT_FAILURE);
 	}
-	for (i = 0; i < ARRAY_SIZE(targets); i++) {
-		if (targets[i] == false)
-			continue;
 
-		if (write) {
+	if (write) {
+		/* only reset and set max & min act_upons flags if a read operation is also requested */
+		if (reader != false) {
+			for (int j = 0; j < ARRAY_SIZE(targets); j++)
+				targets[j] = false;
+			targets[MIN] = true;
+			targets[MAX] = true;
+		}
+
+		for (i = 0; i < ARRAY_SIZE(targets); i++) {
+			if (targets[i] == false)
+				continue;
 			set_frequency(&info[i], set_freq[i]);
 			if (get_frequency(&info[i]) != set_freq[i])
 				fail = true;
 			else
 				fail = false;
-		} else {
-			printf("%s: %d MHz\n", info[i].name, get_frequency(&info[i]));
 		}
 	}
 
@@ -325,6 +330,13 @@ again:
 		goto again;
 	}
 
+	if (reader || argc == 1) {
+		for (i = 0; i < ARRAY_SIZE(targets); i++) {
+			/* loop for all frequencies for get operations */
+			printf("%s: %d MHz\n", info[i].name, get_frequency(&info[i]));
+		}
+	}
+
 	for (i = 0; i < ARRAY_SIZE(targets); i++) {
 		if (info[i].filp) {
 			fclose(info[i].filp);
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH v3 2/3 tools/intel_gpu_frequency: Add multi-GT support

In reply to S Sebinraj

This change enhances intel_gpu_frequency to support Intel GPUs with multiple Graphics Technology (GT) units.

Key improvements:
- Add runtime GT detection using igt_sysfs_get_num_gt()
- New --gt/-t option to specify target GT (defaults to GT0)
- New --list/-l option to display available GTs
- Update sysfs path generation to use igt_sysfs_gt_path()
- Update the man page for new options

Usage examples:
intel_gpu_frequency --get --gt 1 # Get GT1 frequencies
intel_gpu_frequency --set 400 --gt 0 # Set GT0 frequency
intel_gpu_frequency --list # List available GTs

The tool now dynamically detects available GTs at runtime and provides error messages when invalid GT numbers are specified. Also by default for set / get operations it acts upon all available GTs unless specified.

---
 lib/drmtest.c               |   2 +-
 man/intel_gpu_frequency.rst |  34 +++-
 tools/intel_gpu_frequency.c | 318 +++++++++++++++++++++++++++---------
 3 files changed, 269 insertions(+), 85 deletions(-)
lib/drmtest.c +1 -1
index 590c4671a..7311f83af 100644
@@ -310,7 +310,7 @@ static void log_opened_device_path(const char *device_path)
 	item->path = strdup(device_path);
 	igt_assert(item->path);
 	igt_list_add(&item->link, &opened_paths);
-	igt_info("Opened device: %s\n", item->path);
+	igt_debug("Opened device: %s\n", item->path);
 }
 
 /**
man/intel_gpu_frequency.rst +29 -5
index 92f039645..285870857 100644
@@ -38,7 +38,8 @@ OPTIONS
     Lock frequency to the most efficient frequency.
 
 -g, --get
-    Get all the current frequency settings.
+    Get all the current frequency settings. Displays results
+    showing all GTs with their corresponding frequencies.
 
 -s FREQUENCY, --set=FREQUENCY
     Lock frequency to an absolute value (MHz).
@@ -55,6 +56,14 @@ OPTIONS
 -d, --defaults
     Return the system to hardware defaults.
 
+-t GT_NUMBER, --gt=GT_NUMBER
+    Specify which GT (Graphics Technology) to operate on. GT numbers start from 0.
+    If not specified, operations apply to all available GTs. Use with --list
+    to see available GTs.
+
+-l, --list
+    List all available GTs in the system with their sysfs paths.
+
 -h, --help
     Show help.
 
@@ -64,14 +73,29 @@ OPTIONS
 EXAMPLES
 ========
 
-intel_gpu_frequency -gmin,cur
-    Get the current and minimum frequency.
+intel_gpu_frequency
+    Display frequency information for all GTs in table format.
+
+intel_gpu_frequency -g
+    Get frequency settings for all GTs (displays in table format).
+
+intel_gpu_frequency --list-gts
+    List all available GTs in the system.
+
+intel_gpu_frequency --get --gt 1
+    Get frequency settings for GT1 only.
 
 intel_gpu_frequency -s 400
-    Lock frequency to 400Mhz.
+    Lock frequency to 400Mhz for all GTs.
+
+intel_gpu_frequency -s 400 --gt 0
+    Lock frequency to 400Mhz for GT0 only.
 
 intel_gpu_frequency -c max=750
-    Set the max frequency to 750MHz
+    Set the max frequency to 750MHz for all GTs.
+
+intel_gpu_frequency -c max=750 --gt 1
+    Set the max frequency to 750MHz for GT1 only.
 
 REPORTING BUGS
 ==============
tools/intel_gpu_frequency.c +239 -79

453 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH i-g-t v3 2/3] tools/intel_gpu_frequency: Add multi-GT support

________________________________

Hi,
Seems there is Ci.Build error with this patch, due to patch not getting applied properly, I guess I missed the rebase before pushing these patches. I'll share a v4 version with the changes Rebased with latest sync.

Regards,
Sebin

This change enhances intel_gpu_frequency to support Intel GPUs with multiple Graphics Technology (GT) units.

Key improvements:
- Add runtime GT detection using igt_sysfs_get_num_gt()
- New --gt/-t option to specify target GT (defaults to GT0)
- New --list/-l option to display available GTs
- Update sysfs path generation to use igt_sysfs_gt_path()
- Update the man page for new options

Usage examples:
intel_gpu_frequency --get --gt 1 # Get GT1 frequencies
intel_gpu_frequency --set 400 --gt 0 # Set GT0 frequency
intel_gpu_frequency --list # List available GTs

The tool now dynamically detects available GTs at runtime and provides error messages when invalid GT numbers are specified. Also by default for set / get operations it acts upon all available GTs unless specified.

---
 lib/drmtest.c               |   2 +-
 man/intel_gpu_frequency.rst |  34 +++-
 tools/intel_gpu_frequency.c | 318 +++++++++++++++++++++++++++---------
 3 files changed, 269 insertions(+), 85 deletions(-)
lib/drmtest.c +1 -1
index 590c4671a..7311f83af 100644
@@ -310,7 +310,7 @@ static void log_opened_device_path(const char *device_path)
         item->path = strdup(device_path);
         igt_assert(item->path);
         igt_list_add(&item->link, &opened_paths);
-       igt_info("Opened device: %s\n", item->path);
+       igt_debug("Opened device: %s\n", item->path);
 }
 
 /**
man/intel_gpu_frequency.rst +29 -5
index 92f039645..285870857 100644
@@ -38,7 +38,8 @@ OPTIONS
     Lock frequency to the most efficient frequency.
 
 -g, --get
-    Get all the current frequency settings.
+    Get all the current frequency settings. Displays results
+    showing all GTs with their corresponding frequencies.
 
 -s FREQUENCY, --set=FREQUENCY
     Lock frequency to an absolute value (MHz).
@@ -55,6 +56,14 @@ OPTIONS
 -d, --defaults
     Return the system to hardware defaults.
 
+-t GT_NUMBER, --gt=GT_NUMBER
+    Specify which GT (Graphics Technology) to operate on. GT numbers start from 0.
+    If not specified, operations apply to all available GTs. Use with --list
+    to see available GTs.
+
+-l, --list
+    List all available GTs in the system with their sysfs paths.
+
 -h, --help
     Show help.
 
@@ -64,14 +73,29 @@ OPTIONS
 EXAMPLES
 ========
 
-intel_gpu_frequency -gmin,cur
-    Get the current and minimum frequency.
+intel_gpu_frequency
+    Display frequency information for all GTs in table format.
+
+intel_gpu_frequency -g
+    Get frequency settings for all GTs (displays in table format).
+
+intel_gpu_frequency --list-gts
+    List all available GTs in the system.
+
+intel_gpu_frequency --get --gt 1
+    Get frequency settings for GT1 only.
 
 intel_gpu_frequency -s 400
-    Lock frequency to 400Mhz.
+    Lock frequency to 400Mhz for all GTs.
+
+intel_gpu_frequency -s 400 --gt 0
+    Lock frequency to 400Mhz for GT0 only.
 
 intel_gpu_frequency -c max=750
-    Set the max frequency to 750MHz
+    Set the max frequency to 750MHz for all GTs.
+
+intel_gpu_frequency -c max=750 --gt 1
+    Set the max frequency to 750MHz for GT1 only.
 
 REPORTING BUGS
 ==============
tools/intel_gpu_frequency.c +239 -79

453 lines not on this page · raw message

--
2.43.0

author
#4 lore raw

PATCH v3 3/3 tools/intel_gpu_frequency: Add Xe driver support

In reply to S Sebinraj

This change enhances intel_gpu_frequency to add compatibility with Xe drivers.

Key improvements:
- Add runtime GT detection using xe_number_gt()
- Auto-detect driver type using is_xe_device()
- Driver-agnostic frequency management with unified interface

Driver-specific implementations:
- Automatic frequency name mapping (RP1→rpe, RP0→rp0, RPn→rpn for Xe)

The tool now auto-detects Xe drivers and uses appropriate interfaces.

---
 tools/intel_gpu_frequency.c | 87 ++++++++++++++++++++++++++++---------
 1 file changed, 67 insertions(+), 20 deletions(-)
tools/intel_gpu_frequency.c +67 -20
index aaadd0857..2c56f0e2e 100644
@@ -32,11 +32,13 @@
 #include "igt_device.h"
 #include "igt_sysfs.h"
 #include "intel_chipset.h"
+#include "xe/xe_gt.h"
 
 #define VERSION "1.0"
 #define SYSFS_PATH_MAX 96
 
 static int device, devid;
+static bool is_xe;
 
 enum {
 	CUR=0,
@@ -57,27 +59,55 @@ struct freq_info {
 static struct freq_info info[] = {
 	{ "cur", "r"  },
 	{ "min", "rb+" },
-	{ "RP1", "r" },
+	{ "RP1", "r" },    /* i915: RP1, xe: rpe */
 	{ "max", "rb+" },
-	{ "RP0", "r" },
-	{ "RPn", "r" }
+	{ "RP0", "r" },    /* i915: RP0, xe: rp0 */
+	{ "RPn", "r" }     /* i915: RPn, xe: rpn */
 };
 
+static int driver_get_num_gts(int fd)
+{
+	if (is_xe) {
+		return xe_number_gt(fd);
+	} else {
+		return igt_sysfs_get_num_gt(fd);
+	}
+}
+
 static char *
 get_sysfs_path(int fd, int gt_id, const char *which)
 {
 	static char path[SYSFS_PATH_MAX];
 	char *gt_path;
 	int path_len, ret;
+	const char *freq_name;
+
+	/* Get driver-specific GT path */
+	if (is_xe)
+		gt_path = xe_sysfs_gt_path(fd, gt_id, path, sizeof(path));
+	else
+		gt_path = igt_sysfs_gt_path(fd, gt_id, path, sizeof(path));
 
-	gt_path = igt_sysfs_gt_path(fd, gt_id, path, sizeof(path));
 	if (gt_path == NULL) {
-		fprintf(stderr, "igt_sysfs_gt_path returned NULL for GT%d\n", gt_id);
+		fprintf(stderr, "sysfs_gt_path returned NULL for GT%d\n", gt_id);
 		return NULL;
 	}
+
 	path_len = strlen(gt_path);
-	ret = snprintf(path + path_len, sizeof(path) - path_len,
-		       "/rps_%s_freq_mhz", which);
+
+	if (is_xe) {
+		/* Xe uses /freq0/ directory with different file names */
+		freq_name = !strcmp(which, "RP1") ? "rpe" :
+			    !strcmp(which, "RP0") ? "rp0" :
+			    !strcmp(which, "RPn") ? "rpn" : which;
+
+		ret = snprintf(path + path_len, sizeof(path) - path_len,
+			       "/freq0/%s_freq", freq_name);
+	} else {
+		/* i915 uses /rps_*_freq_mhz files */
+		ret = snprintf(path + path_len, sizeof(path) - path_len,
+			       "/rps_%s_freq_mhz", which);
+	}
 
 	if (ret >= sizeof(path) - path_len) {
 		fprintf(stderr, "Path truncated\n");
@@ -263,6 +293,8 @@ usage(const char *prog)
 	printf("   intel_gpu_frequency --custom max=750 --gt 0\tSet GT0 max frequency to 750MHz\n");
 	printf("   intel_gpu_frequency --list\t\t\tList all available GTs\n");
 	printf("\n");
+	printf("Auto-detects i915 vs Xe driver and uses appropriate interfaces.\n");
+	printf("\n");
 	printf("Report bugs to https://gitlab.freedesktop.org/drm/igt-gpu-tools/-/issues\n");
 	exit(EXIT_FAILURE);
 }
@@ -356,7 +388,7 @@ parse(int argc, char *argv[], int fd, bool *act_upon, size_t act_upon_n, int *ne
 			}
 			break;
 		case 'e': /* efficient */
-			if (IS_VALLEYVIEW(devid) || IS_CHERRYVIEW(devid)) {
+			if (!is_xe && (IS_VALLEYVIEW(devid) || IS_CHERRYVIEW(devid))) {
 				/* the LP parts have special efficient frequencies */
 				fprintf(stderr,
 					"FIXME: Warning efficient frequency information is incorrect.\n");
@@ -435,8 +467,13 @@ static void list_available_gts(int fd, int num_gts)
 	for (i = 0; i < num_gts; i++) {
 		char path[SYSFS_PATH_MAX];
 
-		if (igt_sysfs_gt_path(fd, i, path, sizeof(path)))
-			printf("  GT%d: %s\n", i, path);
+		if (is_xe) {
+			if (xe_sysfs_gt_path(fd, i, path, sizeof(path)))
+				printf("  GT%d: %s\n", i, path);
+		} else {
+			if (igt_sysfs_gt_path(fd, i, path, sizeof(path)))
+				printf("  GT%d: %s\n", i, path);
+		}
 	}
 }
 
@@ -464,26 +501,36 @@ static void execute_frequency_operations(int argc, int fd, int specified_gt, boo
 		/* Process single specified GT */
 		process_gt_frequencies(argc, fd, specified_gt, write, reader, targets, set_freq);
 	} else {
-		/* Process all GTs using for_each_gt pattern */
-		int gt_dir;
-
-		i915_for_each_gt(fd, gt_dir, target_gt) {
-			process_gt_frequencies(argc, fd, target_gt, write, reader, targets, set_freq);
+		/* Process all GTs using driver-specific for_each_gt pattern */
+		if (is_xe) {
+			xe_for_each_gt(fd, target_gt)
+				process_gt_frequencies(argc, fd, target_gt, write, reader, targets, set_freq);
+		} else {
+			int gt_dir;
+			i915_for_each_gt(fd, gt_dir, target_gt)
+				process_gt_frequencies(argc, fd, target_gt, write, reader, targets, set_freq);
 		}
 	}
 }
 
 int main(int argc, char *argv[])
 {
-
 	bool write, reader = false, targets[MAX+1] = {false}, list_gts = false;
 	int i, fd, set_freq[MAX+1] = {0}, num_gts;
 	int specified_gt = -1;
 
-	fd = drm_open_driver(DRIVER_INTEL);
-	devid = intel_get_drm_devid(fd);
-	device = igt_device_get_card_index(fd);
-	num_gts = igt_sysfs_get_num_gt(fd);
+	fd = drm_open_driver(DRIVER_INTEL | DRIVER_XE);
+	is_xe = is_xe_device(fd);
+
+	if (is_xe) {
+		igt_debug("Using Xe driver\n");
+	} else {
+		devid = intel_get_drm_devid(fd);
+		device = igt_device_get_card_index(fd);
+		igt_debug("Using i915 driver\n");
+	}
+
+	num_gts = driver_get_num_gts(fd);
 
 	write = parse(argc, argv, fd, targets, ARRAY_SIZE(targets), set_freq, &reader,
 		       &list_gts, &specified_gt);
Signature · 1 line
2.43.0
#5 lore raw

✗ Fi.CI.BUILD: failure for tools/intel_gpu_frequency: Add multi-GT support and Xe driver compatibility (rev2)

In reply to S Sebinraj
== Series Details ==

== Series Details ==

Series: tools/intel_gpu_frequency: Add multi-GT support and Xe driver compatibility (rev2)
URL : https://patchwork.freedesktop.org/series/156767/
State : failure

== Summary ==

Applying: tools/intel_gpu_frequency: Add support for get, set in order & vice-versa Using index info to reconstruct a base tree...
M tools/intel_gpu_frequency.c
Falling back to patching base and 3-way merge...
Auto-merging tools/intel_gpu_frequency.c
Applying: tools/intel_gpu_frequency: Add multi-GT support
Using index info to reconstruct a base tree...
M lib/drmtest.c
M tools/intel_gpu_frequency.c
Falling back to patching base and 3-way merge...
Auto-merging tools/intel_gpu_frequency.c
CONFLICT (content): Merge conflict in tools/intel_gpu_frequency.c Auto-merging lib/drmtest.c
Patch failed at 0002 tools/intel_gpu_frequency: Add multi-GT support When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".