Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/panthor: Add tracepoint for hardware utilisation changes

Mali GPUs have three registers that indicate which parts of the hardware
are powered at any moment. These take the form of bitmaps. In the case
of SHADER_READY for example, a high bit indicates that the shader core
corresponding to that bit index is powered on. These bitmaps aren't
solely contiguous bits, as it's common to have holes in the sequence of
shader core indices, and the actual set of which cores are present is
defined by the "shader present" register.

When the GPU finishes a power state transition, it fires a
GPU_IRQ_POWER_CHANGED_ALL interrupt. After such an interrupt is
received, the _READY registers will contain new interesting data. During
power transitions, the GPU_IRQ_POWER_CHANGED interrupt will fire, and
the registers will likewise contain potentially changed data.

This is not to be confused with the PWR_IRQ_POWER_CHANGED_ALL interrupt,
which is something related to Mali v14+'s power control logic. The
_READY registers and corresponding interrupts are already available in
v9 and onwards.

Expose the data as a tracepoint to userspace. This allows users to debug
various scenarios and gather interesting information, such as: knowing
how much hardware is lit up at any given time, correlating graphics
corruption with a specific powered shader core, measuring when hardware
is allowed to go to a powered off state again, and so on.

The registration/unregistration functions for the tracepoint go through
a wrapper in panthor_hw.c, so that v14+ can implement the same
tracepoint by adding its hardware specific IRQ on/off callbacks to the
panthor_hw.ops member.

Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Link: https://patch.msgid.link/20260116-panthor-tracepoints-v10-3-d925986e3d1b@collabora.com
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>

authored by

Nicolas Frattaroli and committed by
Boris Brezillon
52ebfd8d c5bf1d4e

+158
+28
drivers/gpu/drm/panthor/panthor_gpu.c
··· 22 22 #include "panthor_hw.h" 23 23 #include "panthor_regs.h" 24 24 25 + #define CREATE_TRACE_POINTS 26 + #include "panthor_trace.h" 27 + 25 28 /** 26 29 * struct panthor_gpu - GPU block management data. 27 30 */ ··· 50 47 GPU_IRQ_PROTM_FAULT | \ 51 48 GPU_IRQ_RESET_COMPLETED | \ 52 49 GPU_IRQ_CLEAN_CACHES_COMPLETED) 50 + 51 + #define GPU_POWER_INTERRUPTS_MASK \ 52 + (GPU_IRQ_POWER_CHANGED | GPU_IRQ_POWER_CHANGED_ALL) 53 53 54 54 static void panthor_gpu_coherency_set(struct panthor_device *ptdev) 55 55 { ··· 85 79 static void panthor_gpu_irq_handler(struct panthor_device *ptdev, u32 status) 86 80 { 87 81 gpu_write(ptdev, GPU_INT_CLEAR, status); 82 + 83 + if (tracepoint_enabled(gpu_power_status) && (status & GPU_POWER_INTERRUPTS_MASK)) 84 + trace_gpu_power_status(ptdev->base.dev, 85 + gpu_read64(ptdev, SHADER_READY), 86 + gpu_read64(ptdev, TILER_READY), 87 + gpu_read64(ptdev, L2_READY)); 88 88 89 89 if (status & GPU_IRQ_FAULT) { 90 90 u32 fault_status = gpu_read(ptdev, GPU_FAULT_STATUS); ··· 167 155 return ret; 168 156 169 157 return 0; 158 + } 159 + 160 + int panthor_gpu_power_changed_on(struct panthor_device *ptdev) 161 + { 162 + guard(pm_runtime_active)(ptdev->base.dev); 163 + 164 + panthor_gpu_irq_enable_events(&ptdev->gpu->irq, GPU_POWER_INTERRUPTS_MASK); 165 + 166 + return 0; 167 + } 168 + 169 + void panthor_gpu_power_changed_off(struct panthor_device *ptdev) 170 + { 171 + guard(pm_runtime_active)(ptdev->base.dev); 172 + 173 + panthor_gpu_irq_disable_events(&ptdev->gpu->irq, GPU_POWER_INTERRUPTS_MASK); 170 174 } 171 175 172 176 /**
+2
drivers/gpu/drm/panthor/panthor_gpu.h
··· 51 51 int panthor_gpu_flush_caches(struct panthor_device *ptdev, 52 52 u32 l2, u32 lsc, u32 other); 53 53 int panthor_gpu_soft_reset(struct panthor_device *ptdev); 54 + void panthor_gpu_power_changed_off(struct panthor_device *ptdev); 55 + int panthor_gpu_power_changed_on(struct panthor_device *ptdev); 54 56 55 57 #endif
+62
drivers/gpu/drm/panthor/panthor_hw.c
··· 2 2 /* Copyright 2025 ARM Limited. All rights reserved. */ 3 3 4 4 #include <linux/nvmem-consumer.h> 5 + #include <linux/platform_device.h> 6 + 5 7 #include <drm/drm_print.h> 6 8 7 9 #include "panthor_device.h" ··· 32 30 .soft_reset = panthor_gpu_soft_reset, 33 31 .l2_power_off = panthor_gpu_l2_power_off, 34 32 .l2_power_on = panthor_gpu_l2_power_on, 33 + .power_changed_off = panthor_gpu_power_changed_off, 34 + .power_changed_on = panthor_gpu_power_changed_on, 35 35 }, 36 36 }; 37 37 ··· 57 53 .hwdev = &panthor_hw_arch_v14, 58 54 }, 59 55 }; 56 + 57 + static int panthor_hw_set_power_tracing(struct device *dev, void *data) 58 + { 59 + struct panthor_device *ptdev = dev_get_drvdata(dev); 60 + 61 + if (!ptdev) 62 + return -ENODEV; 63 + 64 + if (!ptdev->hw) 65 + return 0; 66 + 67 + if (data) { 68 + if (ptdev->hw->ops.power_changed_on) 69 + return ptdev->hw->ops.power_changed_on(ptdev); 70 + } else { 71 + if (ptdev->hw->ops.power_changed_off) 72 + ptdev->hw->ops.power_changed_off(ptdev); 73 + } 74 + 75 + return 0; 76 + } 77 + 78 + int panthor_hw_power_status_register(void) 79 + { 80 + struct device_driver *drv; 81 + int ret; 82 + 83 + drv = driver_find("panthor", &platform_bus_type); 84 + if (!drv) 85 + return -ENODEV; 86 + 87 + ret = driver_for_each_device(drv, NULL, (void *)true, 88 + panthor_hw_set_power_tracing); 89 + 90 + return ret; 91 + } 92 + 93 + void panthor_hw_power_status_unregister(void) 94 + { 95 + struct device_driver *drv; 96 + int ret; 97 + 98 + drv = driver_find("panthor", &platform_bus_type); 99 + if (!drv) 100 + return; 101 + 102 + ret = driver_for_each_device(drv, NULL, NULL, panthor_hw_set_power_tracing); 103 + 104 + /* 105 + * Ideally, it'd be possible to ask driver_for_each_device to hand us 106 + * another "start" to keep going after the failing device, but it 107 + * doesn't do that. Minor inconvenience in what is probably a bad day 108 + * on the computer already though. 109 + */ 110 + if (ret) 111 + pr_warn("Couldn't mask power IRQ for at least one device: %pe\n", 112 + ERR_PTR(ret)); 113 + } 60 114 61 115 static char *get_gpu_model_name(struct panthor_device *ptdev) 62 116 {
+8
drivers/gpu/drm/panthor/panthor_hw.h
··· 19 19 20 20 /** @l2_power_on: L2 power on function pointer */ 21 21 int (*l2_power_on)(struct panthor_device *ptdev); 22 + 23 + /** @power_changed_on: Start listening to power change IRQs */ 24 + int (*power_changed_on)(struct panthor_device *ptdev); 25 + 26 + /** @power_changed_off: Stop listening to power change IRQs */ 27 + void (*power_changed_off)(struct panthor_device *ptdev); 22 28 }; 23 29 24 30 /** ··· 38 32 }; 39 33 40 34 int panthor_hw_init(struct panthor_device *ptdev); 35 + int panthor_hw_power_status_register(void); 36 + void panthor_hw_power_status_unregister(void); 41 37 42 38 static inline int panthor_hw_soft_reset(struct panthor_device *ptdev) 43 39 {
+58
drivers/gpu/drm/panthor/panthor_trace.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 or MIT */ 2 + /* Copyright 2025 Collabora ltd. */ 3 + 4 + #undef TRACE_SYSTEM 5 + #define TRACE_SYSTEM panthor 6 + 7 + #if !defined(__PANTHOR_TRACE_H__) || defined(TRACE_HEADER_MULTI_READ) 8 + #define __PANTHOR_TRACE_H__ 9 + 10 + #include <linux/tracepoint.h> 11 + #include <linux/types.h> 12 + 13 + #include "panthor_hw.h" 14 + 15 + /** 16 + * gpu_power_status - called whenever parts of GPU hardware are turned on or off 17 + * @dev: pointer to the &struct device, for printing the device name 18 + * @shader_bitmap: bitmap where a high bit indicates the shader core at a given 19 + * bit index is on, and a low bit indicates a shader core is 20 + * either powered off or absent 21 + * @tiler_bitmap: bitmap where a high bit indicates the tiler unit at a given 22 + * bit index is on, and a low bit indicates a tiler unit is 23 + * either powered off or absent 24 + * @l2_bitmap: bitmap where a high bit indicates the L2 cache at a given bit 25 + * index is on, and a low bit indicates the L2 cache is either 26 + * powered off or absent 27 + */ 28 + TRACE_EVENT_FN(gpu_power_status, 29 + TP_PROTO(const struct device *dev, u64 shader_bitmap, u64 tiler_bitmap, 30 + u64 l2_bitmap), 31 + TP_ARGS(dev, shader_bitmap, tiler_bitmap, l2_bitmap), 32 + TP_STRUCT__entry( 33 + __string(dev_name, dev_name(dev)) 34 + __field(u64, shader_bitmap) 35 + __field(u64, tiler_bitmap) 36 + __field(u64, l2_bitmap) 37 + ), 38 + TP_fast_assign( 39 + __assign_str(dev_name); 40 + __entry->shader_bitmap = shader_bitmap; 41 + __entry->tiler_bitmap = tiler_bitmap; 42 + __entry->l2_bitmap = l2_bitmap; 43 + ), 44 + TP_printk("%s: shader_bitmap=0x%llx tiler_bitmap=0x%llx l2_bitmap=0x%llx", 45 + __get_str(dev_name), __entry->shader_bitmap, __entry->tiler_bitmap, 46 + __entry->l2_bitmap 47 + ), 48 + panthor_hw_power_status_register, panthor_hw_power_status_unregister 49 + ); 50 + 51 + #endif /* __PANTHOR_TRACE_H__ */ 52 + 53 + #undef TRACE_INCLUDE_PATH 54 + #define TRACE_INCLUDE_PATH . 55 + #undef TRACE_INCLUDE_FILE 56 + #define TRACE_INCLUDE_FILE panthor_trace 57 + 58 + #include <trace/define_trace.h>