Skip to content

Commit 2cfa08a

Browse files
committed
[RFC] ANDROID: GPU frequency tracing support
A periodic GPU frequency monitoring and tracing program for the Xe driver. The implementation provides bothperiodic sampling and event-driven frequency change notifications through the Linux ftrace infrastructure. Key features: - Periodic GPU frequency sampling with configurable intervals - Immediate frequency change reporting via tracepoints - Integration with Linux ftrace subsystem under 'power' events - Per-GT (Graphics Technology) monitoring support - Dedicated workqueue for non-blocking frequency sampling - Configurable via CONFIG_DRM_XE_GPUFREQTRACER kernel option - The monitoring interval can be configured at runtime via the sysfs (default 5sec). The sysfs entry is at: /sys/module/xe/parameters/gpufreq_monitoring_interval_ms The tracepoint is exposed at: /sys/kernel/debug/tracing/events/power/gpu_frequency Format: {unsigned int state, unsigned int gpu_id} - state: GPU frequency in KHz - gpu_id: GPU clock domain identifier This enables userspace tools and system monitoring applications to track GPU frequency changes for power management analysis, performance tuning, and debugging purposes. Bug: 388282937 Change-Id: I7e8025004abd4b3ffdfb4d7214a4b4896be95a64 Signed-off-by: S Sebinraj <s.sebinraj@intel.com>
1 parent 17c4bdc commit 2cfa08a

9 files changed

Lines changed: 508 additions & 0 deletions

File tree

drivers/gpu/drm/xe/Kconfig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,28 @@ config DRM_XE_FORCE_PROBE
8686

8787
Use "!*" to block the probe of the driver for all known devices.
8888

89+
config DRM_XE_GPUFREQTRACER
90+
bool "Enable XE GPU frequency tracing"
91+
depends on DRM_XE
92+
default n
93+
help
94+
Enable GPU frequency tracing support for Intel XE driver.
95+
This adds an ftrace tracepoint that reports GPU frequency changes
96+
at periodic boundaries (default 5 secs, configurable via the
97+
gpufreq_monitoring_interval_ms module parameter) and
98+
on direct frequency change events.
99+
100+
The monitoring interval can be configured at runtime via the sysfs module parameter:
101+
/sys/module/xe/parameters/gpufreq_monitoring_interval_ms
102+
103+
The tracepoint will be available at:
104+
/sys/kernel/debug/tracing/events/power/gpu_frequency
105+
106+
Format: {unsigned int state, unsigned int gpu_id}
107+
Where state is the frequency in KHz and gpu_id is the GPU clock domain.
108+
109+
If unsure, say N.
110+
89111
menu "drm/Xe Debugging"
90112
depends on DRM_XE
91113
depends on EXPERT

drivers/gpu/drm/xe/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ xe-$(CONFIG_PCI_IOV) += \
138138
xe_pci_sriov.o \
139139
xe_sriov_pf.o
140140

141+
# GPU frequency tracer
142+
xe-$(CONFIG_DRM_XE_GPUFREQTRACER) += xe_gpufreqtracer/xe_gpufreqtracer.o
143+
141144
# include helpers for tests even when XE is built-in
142145
ifdef CONFIG_DRM_XE_KUNIT_TEST
143146
xe-y += tests/xe_kunit_helpers.o

drivers/gpu/drm/xe/xe_device.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "xe_exec_queue.h"
3232
#include "xe_force_wake.h"
3333
#include "xe_ggtt.h"
34+
#include "xe_gpufreqtracer/xe_gpufreqtracer.h"
3435
#include "xe_gsc_proxy.h"
3536
#include "xe_gt.h"
3637
#include "xe_gt_mcr.h"
@@ -727,6 +728,21 @@ int xe_device_probe(struct xe_device *xe)
727728

728729
xe_heci_gsc_init(xe);
729730

731+
#ifdef CONFIG_DRM_XE_GPUFREQTRACER
732+
err = xe_gpufreqtracer_init(xe);
733+
if (err)
734+
goto err_fini_gt;
735+
736+
/* Start periodic monitoring on all GTs using global module parameter */
737+
for_each_gt(gt, xe, id) {
738+
err = xe_gpufreqtracer_start_monitoring(gt);
739+
if (err) {
740+
drm_err(&xe->drm, "xe_gpufreqtracer: failed to start monitoring for GT%u, err=%d\n",
741+
gt->info.id, err);
742+
}
743+
}
744+
#endif
745+
730746
err = xe_oa_init(xe);
731747
if (err)
732748
goto err_fini_gt;
@@ -788,6 +804,10 @@ void xe_device_remove(struct xe_device *xe)
788804

789805
xe_device_remove_display(xe);
790806

807+
#ifdef CONFIG_DRM_GPUFREQTRACER
808+
xe_gpufreqtracer_fini(xe);
809+
#endif
810+
791811
xe_display_fini(xe);
792812

793813
xe_oa_fini(xe);

drivers/gpu/drm/xe/xe_device_types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#endif
3434

3535
struct xe_ggtt;
36+
struct xe_gpufreqtracer_data;
3637
struct xe_pat_ops;
3738

3839
#define XE_BO_INVALID_OFFSET LONG_MAX
@@ -496,6 +497,11 @@ struct xe_device {
496497
/** @oa: oa observation subsystem */
497498
struct xe_oa oa;
498499

500+
#ifdef CONFIG_DRM_XE_GPUFREQTRACER
501+
/** @gpufreqtracer_data: GPU frequency tracer data */
502+
struct xe_gpufreqtracer_data *gpufreqtracer_data;
503+
#endif
504+
499505
/** @needs_flr_on_fini: requests function-reset on fini */
500506
bool needs_flr_on_fini;
501507

0 commit comments

Comments
 (0)