Skip to content

Conversation

@ssebinraj
Copy link

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

goto err_free_tracer;
}

/* Allocate GT data array - assume max 2 GTs for now */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we read GTs count rather than doing hardcoding? May be we can implement some function to read it.

return -EOPNOTSUPP;
}

if (gt->info.id >= 2) { /* Assume max 2 GTs */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once you have the way to read GTs count, we can remove this hardcoding

struct xe_gpufreqtracer_data *tracer_data = gt_to_xe(gt)->gpufreqtracer_data;
struct xe_gpufreqtracer_gt_data *gt_data;

if (!tracer_data || gt->info.id >= 2) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment. we can remove the hardcoding once we implement function to read GTs count


gt_data->monitoring_active = false;

timer_delete(&gt_data->timer);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets use del_timer_sync()

* This function is executed in a workqueue context to periodically sample
* the GPU frequency and perform any necessary tracing or logging operations.
* It is part of the GPU frequency tracer subsystem.
*/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to create dedicated work queue? we can use system_highpri_wq a global workqueue provided by the kernel.
upstream people might ask this questions. Lets have a proper reason for the same.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the comment code has been modified.

*
* location: /d/events/power/gpu_frequency
* format: {unsigned int state, unsigned int gpu_id}
* where state holds the frequency(in Khz) and the gpu_id holds the GPU clock domain.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracepoint uses state for frequency. Consider using more descriptive field names in the tracepoint like freq_khz

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's right, but this is as per the spec shared by google, they require it in such format.

static int xe_validate_module_params(void)
{
/* Validate GPU frequency monitoring interval */
if (xe_modparam.gpufreq_monitoring_interval_ms < 100 ||
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we define max and min interval?


xe_device_remove_display(xe);

#ifdef CONFIG_DRM_GPUFREQTRACER
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#ifdef CONFIG_DRM_GPUFREQTRACER (missing XE). Have a look

current_freq = xe_guc_pc_get_act_freq(pc) * 1000; /* Convert MHz to KHz */

/* Only report if frequency has changed or this is the first sample */
if (current_freq != gt_data->last_frequency) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just check if there is concurrency problem. If yes use atomic or protect by some lock. Similarly for last_frequency.

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
Test: CtsGpuProfilingDataTestCases
Change-Id: I7e8025004abd4b3ffdfb4d7214a4b4896be95a64
Signed-off-by: S Sebinraj <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants