drm/nouveau: GSP telemetry via RUSD, and fdinfo telemetry exposure
Subsystems (3)
cover drm/nouveau: GSP telemetry via RUSD, and fdinfo telemetry exposure
On the GSP firmware, nouveau reports nothing about the GPU. The GSP owns the sensors, so the legacy nvkm therm/clk/volt hwmon paths never run, and monitoring tools have no data to read.
GSP on later firmware does publish all of it through a stable interface. It maintains a shared-memory region called "RM User Shared Data" (RUSD), which the firmware fills with all the relevant sensor readings like power, temperatures, clocks, and many others. Consuming it needs only two internal subdevice controls: INIT_USER_SHARED_DATA to register the buffer, and SET_DATA_POLL to tell the GSP which data groups to poll and how often.
This series makes nouveau a RUSD client and exposes the data through two main surfaces:
- hwmon, for the values that map onto standard channels: GPU and memory temperature, GPU/board/VRAM power, power cap.
- sysfs, under /sys/class/drm/cardN/device/rusd/, for everything hwmon has no channel type for: clocks, utilisation, pstate, throttle reason, ECC counters, PCIe error counters, and everything exposed to hwmon as well. One value per file according to sysfs convention.
Polling is demand-driven. GSP polls a group only while a client is reading it, and a group idles off after 10s after the last read. Polling costs power, so nothing is polled unless someone is looking. A section that has not been polled yet, or that the board does not support, reads -ENODATA.
The sysfs interface is documented inDocumentation/ABI/testing/sysfs-driver-nouveau.
While the original scope was RUSD support only, monitoring tools needed two extra additions to complete the picture:
- VRAM size and usage on sysfs (patch 5): since this series adds a sysfs interface for nouveau, it's better to expose VRAM metrics there rather than force monitoring apps to pull in libdrm for the GETPARAM memory ioctls.
- fdinfo (patch 6): nouveau implemented none at all, and monitoring apps could not show per-process GPU and memory usage. It now reports per-client memory and per-engine busy time, accounted from the DRM scheduler that the EXEC/VM_BIND path already uses.
Limitations, caveats, and additional considerations or questions:
- RUSD needs r570 or newer GSP firmware; r535 does not have the needed controls. Pre-GSP and r535 behavior is identical to what it was: the rusd/ group is not created, and hwmon keeps its current behavior.
- This is all read-only telemetry. Clock, voltage, or power control is through other interfaces out of scope of this series.
- The sysfs interface exposed here should be stable and valid for nova as well. RUSD is stable and only grows more fields with newer GSP firmware (e.g., fan telemetry gets added in r580), so it is possible to keep the same interface as we use newer firmware or as we move to nova and any potential considerations should be ironed out before this gets merged and the interface gets frozen.
- amdgpu offers a single binary blob with all the telemetry embedded in addition to the sysfs sensor files. This series currently only exposes sensor files, but it is possible to add a similar binary for a v2. This mainly offers a more efficient way to read the telemetry as clients would read only a few files instead of reading all of them.
- The last two patches don't depend on RUSD and work on every GPU. But they are here because they complete the sensor telemetry story. I am happy to split them into their own series if that is preferred.
Userspace WIP work built on this sysfs surface exists in form of nouveau backends for nvtop, LACT, and a NVK HUD:
- nvtop: https://github.com/mohamexiety/nvtop/tree/nvtop-nouvtop
- LACT: https://github.com/mohamexiety/LACT/tree/lnouvct
- NVK HUD:
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39898
None of these are merged yet and exist for testing only. Upstreaming will begin when this series gets merged and the interface is stable.
Mohamed Ahmed (6):
drm/nouveau/gsp: vendor the RUSD header drm/nouveau/gsp: add RUSD telemetry support drm/nouveau: add GSP hwmon support
drm/nouveau: expose RUSD telemetry via sysfs drm/nouveau: expose global VRAM size and usage via sysfs drm/nouveau: expose per-client GPU usage via fdinfo
.../ABI/testing/sysfs-driver-nouveau | 167 ++++++ MAINTAINERS | 1 + drivers/gpu/drm/nouveau/Kbuild | 1 + .../gpu/drm/nouveau/include/nvkm/subdev/gsp.h | 33 ++ .../drm/nouveau/include/nvkm/subdev/rusd.h | 114 ++++ .../gpu/drm/nouveau/include/nvrm/nvtypes.h | 3 + drivers/gpu/drm/nouveau/nouveau_abi16.c | 16 + drivers/gpu/drm/nouveau/nouveau_chan.h | 2 + drivers/gpu/drm/nouveau/nouveau_drm.c | 22 + drivers/gpu/drm/nouveau/nouveau_drv.h | 29 + drivers/gpu/drm/nouveau/nouveau_exec.c | 3 + drivers/gpu/drm/nouveau/nouveau_gem.c | 16 + drivers/gpu/drm/nouveau/nouveau_hwmon.c | 375 ++++++++++--- drivers/gpu/drm/nouveau/nouveau_sched.c | 87 +++ drivers/gpu/drm/nouveau/nouveau_sched.h | 11 + drivers/gpu/drm/nouveau/nouveau_sysfs.c | 311 ++++++++++ drivers/gpu/drm/nouveau/nouveau_sysfs.h | 10 + .../drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c | 26 + .../drm/nouveau/nvkm/subdev/gsp/rm/r535/rm.c | 1 + .../nouveau/nvkm/subdev/gsp/rm/r570/Kbuild | 1 + .../nvkm/subdev/gsp/rm/r570/nvrm/rusd.h | 303 ++++++++++ .../drm/nouveau/nvkm/subdev/gsp/rm/r570/rm.c | 1 + .../nouveau/nvkm/subdev/gsp/rm/r570/rusd.c | 531 ++++++++++++++++++ .../gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h | 7 + 24 files changed, 1990 insertions(+), 81 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-driver-nouveau create mode 100644 drivers/gpu/drm/nouveau/include/nvkm/subdev/rusd.h create mode 100644 drivers/gpu/drm/nouveau/nouveau_sysfs.c create mode 100644 drivers/gpu/drm/nouveau/nouveau_sysfs.h create mode 100644 drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/nvrm/rusd.h create mode 100644 drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c
Signature · 1 line
2.55.0
PATCH 1/6 drm/nouveau/gsp: vendor the RUSD header
RM User Shared Data (RUSD) is GSP-RM's telemetry channel: the kernel hands the firmware a buffer and the firmware fills it with telemetry data (temperatures, power draw, power limits, clocks, utilizations, etc) on its own timer, with a per-section timestamp/seqlock protocol for lock-free reads.
Vendor the ABI needed to use it from the 570.144 tag of NVIDIA's open-gpu-kernel-modules, matching the r570 firmware nouveau ships:
- NV00DE_SHARED_DATA and its section structs, the RUSD_TIMESTAMP_* read-protocol values and the NV00DE_RUSD_POLL_* group mask bits (src/common/sdk/nvidia/inc/class/cl00de.h),
- the two internal subdevice controls that drive it, NV2080_CTRL_CMD_INTERNAL_INIT_USER_SHARED_DATA (0x20800afe) and NV2080_CTRL_CMD_INTERNAL_USER_SHARED_DATA_SET_DATA_POLL (0x20800aff) (src/common/sdk/nvidia/inc/ctrl/ctrl2080/ctrl2080internal.h),
- the NvTemp signed 24.8 fixed-point temperature typedef chain (src/common/sdk/nvidia/inc/nvfixedtypes.h), with NvS32 added to nvtypes.h to support it.
There is no version, magic or size field anywhere in the buffer or the INIT params and the layout is pinned solely by the cl00de.h the firmware binary was built with, which does change (more items get added) between firmware branches. So this header must be re-derived from the exact tag of any future firmware bump.
--- .../gpu/drm/nouveau/include/nvrm/nvtypes.h | 3 + .../nvkm/subdev/gsp/rm/r570/nvrm/rusd.h | 303 ++++++++++++++++++ 2 files changed, 306 insertions(+) create mode 100644 drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/nvrm/rusd.h
drivers/gpu/drm/nouveau/include/nvrm/nvtypes.h +3 -0
@@ -4,6 +4,7 @@#define NV_ALIGN_BYTES (a) __attribute__ ((__aligned__(a)))#define NV_DECLARE_ALIGNED (f,a) f __attribute__ ((__aligned__(a))) +#define NVBIT (b) (1U << (b))typedef u32 NvV32 ;
@@ -12,6 +13,8 @@ typedef u16 NvU16;typedef u32 NvU32 ;typedef u64 NvU64 ; +typedef s32 NvS32 ; +typedef void *NvP64 ;typedef NvU8 NvBool ;
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/nvrm/rusd.h new file +303 -0
303 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 1/6] drm/nouveau/gsp: vendor the RUSD header
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] 32-bit platform ABI mismatch in shared telemetry buffer layout due to missing struct padding…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] 32-bit platform ABI mismatch in shared telemetry buffer layout due to missing struct padding, leading to memory corruption.
- [Medium] RUSD telemetry structures use native integer types, masking endianness mismatches on big-endian architectures. --
--- Patch [1]: [PATCH 1/6] drm/nouveau/gsp: vendor the RUSD header --- commit c1a3b8ad153588da7ba08ef117defa77f7ba5f2d
Author: Mohamed Ahmed <[email protected]>
drm/nouveau/gsp: vendor the RUSD header
RM User Shared Data (RUSD) is GSP-RM's telemetry channel: the kernel hands the firmware a buffer and the firmware fills it with telemetry data (temperatures, power draw, power limits, clocks, utilizations, etc) on its own timer. This commit vendors the ABI needed to use it from the 570.144 tag of NVIDIA's open-gpu-kernel-modules.
Quoted 5 lines
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/nvrm/rusd.h new file +0
-0
[ ... ]
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/nvrm/rusd.h line 146
Quoted 10 lines
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/nvrm/rusd.h new file +10
-0+typedef enum RUSD_TEMPERATURE_TYPE { +RUSD_TEMPERATURE_TYPE_GPU , +RUSD_TEMPERATURE_TYPE_HBM , +RUSD_TEMPERATURE_TYPE_MAX +}RUSD_TEMPERATURE_TYPE ; + +typedef struct RUSD_TEMPERATURE { +volatile NvU64 lastModifiedTimestamp; +NvTemp temperature; +}RUSD_TEMPERATURE ;
[Severity: High]
Does this struct lack explicit padding, causing an ABI mismatch on 32-bit platforms?
On 32-bit platforms (like x86-32), NvU64 has a 4-byte natural alignment, making sizeof(RUSD_TEMPERATURE) exactly 12 bytes. On 64-bit systems and the 64-bit RISC-V GSP firmware, it requires padding and is 16 bytes.
[ ... ]
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/nvrm/rusd.h line 227
Quoted 2 lines
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/nvrm/rusd.h new file +2
-0+typedef struct NV00DE_SHARED_DATA { + NV_DECLARE_ALIGNED(RUSD_BAR1_MEMORY_INFO bar1MemoryInfo, 8);
[Severity: Medium]
Will these fields be read incorrectly on big-endian architectures?
The shared data structures define fields with native integer types (NvU32, NvU64) instead of explicit little-endian types (__le32, __le64). On a big-endian host, the natively-read values will be byte-swapped versions of the little-endian data written by the RISC-V GSP firmware.
[ ... ]
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/nvrm/rusd.h line 266
Quoted 6 lines
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/nvrm/rusd.h new file +6
-0+// POLL_POWER +// Module Limit is not supported on Ampere/Hopper + NV_DECLARE_ALIGNED(RUSD_POWER_LIMITS powerLimitGpu, 8); + +// POLL_THERMAL + NV_DECLARE_ALIGNED(RUSD_TEMPERATURE temperatures[RUSD_TEMPERATURE_TYPE_MAX], 8);
[Severity: High]
Will the missing padding in RUSD_TEMPERATURE cause memory corruption here?
Because temperatures is declared as an array of 3 elements, the array occupies 36 bytes on 32-bit versus 48 bytes on 64-bit. This difference in array stride shifts all subsequent fields by 8 bytes.
The kernel will allocate a smaller buffer than the firmware expects, causing the 64-bit firmware to write past the end of the allocation when writing telemetry data.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH 2/6 drm/nouveau/gsp: add RUSD telemetry support
In reply to Mohamed AhmedAllocate the RUSD shared-data buffer and ask GSP-RM to poll telemetry into it, following OpenRM's call sequence (gpuCreateRusdMemory_IMPL, 570.144): allocate a zero-filled, physically contiguous, coherent sysmem buffer, hand its bus address to the firmware with INIT_USER_SHARED_DATA, then program the poll group mask and interval with USER_SHARED_DATA_SET_DATA_POLL. Both controls go over the existing internal subdevice object.
Readers copy sections out under the RUSD timestamp protocol: a section's leading u64 is 0 while invalid/unsupported, ~0 while the firmware is mid-write, and a timestamp otherwise. Reads fail with -ENODATA for sections the firmware never fills (e.g. HBM temperature on GDDR boards).
Polling is completely demand driven, each read enables its data group's poll bit on demand, and an idle worker drops a group's bit once it has gone unread for R570_RUSD_IDLE_MS. This idle backoff is what stops polling when nothing reads the sensors. The window is kept above a typical monitoring cadence so "sensors" in a loop doesn't switch the poll on and off.
Tracking is per group and each group has independent deadlines, so reading only temperatures doesn't keep the power section polled for example. A single delayed_work recomputes the wanted mask from the per-group last-access timestamps and issues one SET_DATA_POLL.
The vendored layout only matches the firmware's on 64-bit (32-bit u64 alignment shrinks segments and shifts every section), so init fails closed with -ENODEV on 32-bit kernels rather than misinterpreting telemetry or leading to GSP OOB writes.
--- .../gpu/drm/nouveau/include/nvkm/subdev/gsp.h | 33 ++ .../drm/nouveau/include/nvkm/subdev/rusd.h | 114 ++++ .../drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c | 26 + .../drm/nouveau/nvkm/subdev/gsp/rm/r535/rm.c | 1 + .../nouveau/nvkm/subdev/gsp/rm/r570/Kbuild | 1 + .../drm/nouveau/nvkm/subdev/gsp/rm/r570/rm.c | 1 + .../nouveau/nvkm/subdev/gsp/rm/r570/rusd.c | 531 ++++++++++++++++++ .../gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h | 7 + 8 files changed, 714 insertions(+) create mode 100644 drivers/gpu/drm/nouveau/include/nvkm/subdev/rusd.h create mode 100644 drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c
drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h +33 -0
@@ -4,6 +4,7 @@#include <core/subdev.h> #include <core/falcon.h> #include <core/firmware.h> +#include <subdev/rusd.h> #include <linux/debugfs.h>
@@ -233,6 +234,23 @@ struct nvkm_gsp {u8 tpcs; } gr; +/* RM User Shared Data telemetry buffer, polled by GSP-RM (r570+). +* +* GSP only polls the groups nouveau currently wants: a sensor read +* enables that group's poll bit on demand, and @work disables a group +* again once it has gone unread for a while. @mutex serialises @mask +* changes (and the SET_DATA_POLL RPC that carries them) against @work. +*/ +struct { +struct nvkm_gsp_mem mem; +u32 poll_ms; +bool valid; +struct mutex mutex; +u64 mask; +unsigned long group_access[NVKM_GSP_RUSD_GROUP_COUNT ]; +struct delayed_work work; + } rusd; +struct nvkm_rm *rm;struct {
@@ -275,6 +293,21 @@ nvkm_gsp_rm(struct nvkm_gsp *gsp)#include <rm/rm.h> +static inline bool +nvkm_gsp_rusd (struct nvkm_gsp *gsp) +{ +return nvkm_gsp_rm (gsp) && gsp->rusd.valid; +} + +static inline int +nvkm_gsp_rusd_read (struct nvkm_gsp *gsp,enum nvkm_gsp_rusd_item item,s64 *val) +{ +if (!nvkm_gsp_rusd (gsp) || !gsp->rm->api->rusd) +return -ENODEV ; + +return gsp->rm->api->rusd->read (gsp, item, val); +} +static inline void *nvkm_gsp_rpc_get (struct nvkm_gsp *gsp,u32 fn,u32 argc) {
drivers/gpu/drm/nouveau/include/nvkm/subdev/rusd.h new file +114 -0
114 lines not on this page · raw message
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c +26 -0
@@ -322,6 +322,9 @@ r535_gsp_postinit(struct nvkm_gsp *gsp)nvkm_gsp_mem_dtor (&gsp->boot.fw);nvkm_gsp_mem_dtor (&gsp->libos); +if (rmapi->rusd) + rmapi->rusd->init (gsp); +return ret; }
@@ -1727,6 +1730,19 @@ r535_gsp_fini(struct nvkm_gsp *gsp, enum nvkm_suspend_state suspend)struct nvkm_rm *rm = gsp->rm;int ret; +/* Stop demand-poll management before tearing the firmware down. Mark +* RUSD inactive under the lock first: gsp->running is still true +* throughout fini, so the flag is what stops an in-flight request +* from enabling a group (and issuing a SET_DATA_POLL) once teardown +* has begun. Then cancel the worker. +*/ +if (gsp->rusd.mem.data) { +mutex_lock (&gsp->rusd.mutex); + gsp->rusd.valid = false; +mutex_unlock (&gsp->rusd.mutex); +cancel_delayed_work_sync (&gsp->rusd.work); + } +if (suspend) {u32 len = rm->api->gsp->sr_data_size (gsp);GspFwSRMeta *sr;
@@ -1801,6 +1817,9 @@ r535_gsp_init(struct nvkm_gsp *gsp)nvkm_gsp_mem_dtor (&gsp->sr.meta);nvkm_gsp_radix3_dtor (gsp, &gsp->sr.radix3);nvkm_gsp_sg_free (gsp->subdev.device, &gsp->sr.sgt); + +if (ret ==0 && gsp->rm->api->rusd) + gsp->rm->api->rusd->resume (gsp);return ret; }
@@ -2120,6 +2139,13 @@ r535_gsp_dtor(struct nvkm_gsp *gsp)nvkm_gsp_mem_dtor (&gsp->loginit);nvkm_gsp_mem_dtor (&gsp->logintr);nvkm_gsp_mem_dtor (&gsp->logrm); + + gsp->rusd.valid = false; +if (gsp->rusd.mem.data) { +cancel_delayed_work_sync (&gsp->rusd.work); +mutex_destroy (&gsp->rusd.mutex); + } +nvkm_gsp_mem_dtor (&gsp->rusd.mem); } static void
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/rm.c +1 -0
@@ -37,6 +37,7 @@ r535_api = { .nvenc = &r535_nvenc, .nvjpg = &r535_nvjpg, .ofa = &r535_ofa, + .rusd = NULL, }; const struct nvkm_rm_impl
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/Kbuild +1 -0
@@ -7,3 +7,4 @@ nvkm-y += nvkm/subdev/gsp/rm/r570/disp.o nvkm-y += nvkm/subdev/gsp/rm/r570/fifo.o nvkm-y += nvkm/subdev/gsp/rm/r570/gr.o nvkm-y += nvkm/subdev/gsp/rm/r570/ofa.o +nvkm-y += nvkm/subdev/gsp/rm/r570/rusd.o
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rm.c +1 -0
@@ -66,6 +66,7 @@ r570_api = { .nvenc = &r535_nvenc, .nvjpg = &r535_nvjpg, .ofa = &r570_ofa, + .rusd = &r570_rusd, }; const struct nvkm_rm_impl
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c new file +531 -0
531 lines not on this page · raw message
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h +7 -0
@@ -130,6 +130,12 @@ struct nvkm_rm_api {void (*fini)(struct r535_gr *); } scrubber; } *gr; + +const struct nvkm_rm_api_rusd { +int (*init)(struct nvkm_gsp *); +void (*resume)(struct nvkm_gsp *); +int (*read)(struct nvkm_gsp *,enum nvkm_gsp_rusd_item ,s64 *); + } *rusd; };extern const struct nvkm_rm_impl r535_rm_tu102;
@@ -188,4 +194,5 @@ extern const struct nvkm_rm_api_gr r570_gr;int r570_gr_gpc_mask (struct nvkm_gsp *,u32 *mask);int r570_gr_tpc_mask (struct nvkm_gsp *,int gpc,u32 *mask);extern const struct nvkm_rm_api_engine r570_ofa; +extern const struct nvkm_rm_api_rusd r570_rusd;#endif
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 2/6] drm/nouveau/gsp: add RUSD telemetry support
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] Missing delay or CPU relax in bounded retry loop causes spurious -EAGAIN on GSP-RM telemetry…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Missing delay or CPU relax in bounded retry loop causes spurious -EAGAIN on GSP-RM telemetry reads.
- [Medium] Jiffies wrap-around edge case causes telemetry group to be prematurely dropped. --
--- Patch [2]: [PATCH 2/6] drm/nouveau/gsp: add RUSD telemetry support --- commit e2f85d24749e78bb60d3f7f4d694be38a59b92af
Author: Mohamed Ahmed <[email protected]>
drm/nouveau/gsp: add RUSD telemetry support
This commit adds RUSD telemetry support for GSP-RM by allocating a shared-data buffer and enabling demand-driven polling of sensor data. It tracks group access and disables polling for groups that have been idle for a timeout period.
Quoted 6 lines
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c new file +0
-0@@ -0,0 +1,531 @@
[ ... ]
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c line 108
Quoted 12 lines
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c new file +12
-0+static void +r570_rusd_poke (struct nvkm_gsp *gsp,enum nvkm_gsp_rusd_group group) +{ +mutex_lock (&gsp->rusd.mutex); +/* @valid (not gsp->running) is the teardown fence: it is cleared under +* this mutex at the very start of fini, while gsp->running is still +* true, so checking it here stops a read from enabling a group and +* issuing a SET_DATA_POLL to a firmware that is being unloaded. +*/ +if (gsp->rusd.valid) { + gsp->rusd.group_access[group] = jiffies; +r570_rusd_set_mask (gsp, gsp->rusd.mask | r570_rusd_group_mask[group]);
[Severity: Medium]
If jiffies happens to be exactly 0 during this assignment, could it cause issues in the idle worker below?
Quoted 11 lines
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c new file +11
-0+if (gsp->rusd.mask) +schedule_delayed_work (&gsp->rusd.work, +msecs_to_jiffies (R570_RUSD_IDLE_MS )); + } +mutex_unlock (&gsp->rusd.mutex); +} + +/* Drop the groups that haven't been read within the idle window. */ +static void +r570_rusd_work_drop_idle (struct work_struct *work) +{
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c line 129
Quoted 10 lines
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c new file +10
-0+struct nvkm_gsp *gsp =container_of (to_delayed_work (work), + struct nvkm_gsp, rusd.work); +unsigned long idle =msecs_to_jiffies (R570_RUSD_IDLE_MS ); +u64 mask =0 ; +int g; + +mutex_lock (&gsp->rusd.mutex); +if (gsp->rusd.valid) { +for (g =0 ; g <NVKM_GSP_RUSD_GROUP_COUNT ; g++) { + if (gsp->rusd.group_access[g] &&
[Severity: Medium]
When jiffies wraps to 0, this check evaluates to false.
Will this cause the telemetry group to be prematurely dropped from the poll mask until the next read cycle?
Quoted 3 lines
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c new file +3
-0+ time_before(jiffies, gsp->rusd.group_access[g] + idle)) + mask |= r570_rusd_group_mask[g]; + }
[ ... ]
Quoted 7 lines
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c new file +7
-0+/* +* Copy one section out of the shared buffer, untorn. Every section starts +* with a u64 timestamp GSP-RM sets to WRITE_IN_PROGRESS while updating it. +*/ +static int +r570_rusd_read_section (struct nvkm_gsp *gsp,size_t offset,size_t size,void *data) +{
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c line 259
Quoted 10 lines
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c new file +10
-0+const void *sect = gsp->rusd.mem.data + offset; +u64 seq0, seq1; +int retries; + +for (retries =10 ; retries; retries--) { + seq0 =READ_ONCE (*(const u64 *)sect); +if (seq0 ==RUSD_TIMESTAMP_INVALID ) +return -ENODATA ; +if (seq0 ==RUSD_TIMESTAMP_WRITE_IN_PROGRESS ) +continue ;
[Severity: Medium]
Without a delay or cpu_relax() here, the 10 iterations will exhaust extremely fast (in tens of nanoseconds).
Could this cause spurious -EAGAIN errors if the CPU spins through all retries before the GSP firmware has time to finish its memory write?
Quoted 6 lines
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c new file +6
-0+/* Sequence counters appear only in sections written by the kernel and +* never in GSP-polled ones. +*/ +if (seq0 >=RUSD_SEQ_START ) +return -ENODATA ; +
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
maintainerRe: [PATCH 2/6] drm/nouveau/gsp: add RUSD telemetry support
In reply to Mohamed AhmedSome lil nitpicks
Quoted 27 lines · Mohamed Ahmed
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c new file +27
-0+ case NVKM_GSP_RUSD_ROWREMAP_HIST_MAX ... NVKM_GSP_RUSD_ROWREMAP_FAILURE: { +RUSD_MEM_ROW_REMAP remap; + + ret =r570_rusd_read_section (gsp, + offsetof(NV00DE_SHARED_DATA, memRowRemap), + sizeof(remap), &remap); +if (ret) +return ret; + +switch (item) { +case NVKM_GSP_RUSD_ROWREMAP_HIST_MAX : + *val = remap.info.histogramMax; +break ; +case NVKM_GSP_RUSD_ROWREMAP_HIST_HIGH : + *val = remap.info.histogramHigh; +break ; +case NVKM_GSP_RUSD_ROWREMAP_HIST_PARTIAL : + *val = remap.info.histogramPartial; +break ; +case NVKM_GSP_RUSD_ROWREMAP_HIST_LOW : + *val = remap.info.histogramLow; +break ; +case NVKM_GSP_RUSD_ROWREMAP_HIST_NONE : + *val = remap.info.histogramNone; +break ; +case NVKM_GSP_RUSD_ROWREMAP_CORRECTABLE : + *val = remap.info.correctableRows;
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c line 494
Quoted 10 lines
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c new file +10
-0+break ; +case NVKM_GSP_RUSD_ROWREMAP_UNCORRECTABLE : + *val = remap.info.uncorrectableRows; +break ; +case NVKM_GSP_RUSD_ROWREMAP_PENDING : + *val = remap.info.isPending; +break ; +default :/* NVKM_GSP_RUSD_ROWREMAP_FAILURE */ + *val = remap.info.hasFailureOccurred; +break ;
Maybe this should be an explicit case instead of default, so we can drm_WARN_ON_ONCE unknown values?
Quoted 60 lines
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c new file +37
-0+ } +return 0 ; + } + case NVKM_GSP_RUSD_PCIE_GEN ... NVKM_GSP_RUSD_PCIE_UNSUPPORTED_REQUESTS: { +RUSD_PCIE_DATA pcie; + +int idx = item -NVKM_GSP_RUSD_PCIE_GEN ; + + ret =r570_rusd_read_section (gsp, + offsetof(NV00DE_SHARED_DATA, pciBusData), + sizeof(pcie), &pcie); +if (ret) +return ret; + + *val = pcie.info.data[idx]; +return 0 ; + } +default : +return -EINVAL ; + } + +/* A reading of 0 mW is indistinguishable from "not supported on this +* board" (e.g. module power on Ampere/Hopper). +*/ +if (!mw) +return -ENODATA ; + + *val = (s64 )mw *1000 ; +return 0 ; +} + +const struct nvkm_rm_api_rusd +r570_rusd = { + .init = r570_rusd_init, + .resume = r570_rusd_resume, + .read = r570_rusd_read, +};drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h +6
-0@@ -130,6 +130,12 @@ struct nvkm_rm_api { void (*fini)(struct r535_gr *); } scrubber; } *gr; + +const struct nvkm_rm_api_rusd { +int (*init)(struct nvkm_gsp *); +void (*resume)(struct nvkm_gsp *); +int (*read)(struct nvkm_gsp *,enum nvkm_gsp_rusd_item ,s64 *); + } *rusd; };
extern const structnvkm_rm_implr535_rm_tu102;drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h +1
-0@@ -188,4 +194,5 @@ extern const struct nvkm_rm_api_gr r570_gr; int r570_gr_gpc_mask(struct nvkm_gsp *, u32 *mask); int r570_gr_tpc_mask(struct nvkm_gsp *, int gpc, u32 *mask); extern const struct nvkm_rm_api_engine r570_ofa; +extern const struct nvkm_rm_api_rusd r570_rusd; #endif
PATCH 3/6 drm/nouveau: add GSP hwmon support
In reply to Mohamed AhmedGSP boards currently register no hwmon device at all, so every Turing through Blackwell user has been running without any temperature or power readout. Wire the RUSD telemetry up as the first one:
temp1_input/_label "gpu" temperatures[GPU] temp2_input/_label "vram" temperatures[HBM], HBM boards only power1_input/average "gpu" inst/avg GPU power power1_cap enforced power limit (read-only) power2_input/average "board" module power, where supported power3_average "vram" memory rail average, where supported update_interval the programmed RUSD poll interval
All channels are standard hwmon ABI, per-channel visibility is decided at registration time from live section validity, since support varies per SKU at runtime. If nothing becomes valid, no hwmon device is registered, matching today's behaviour on GSP boards.
The legacy therm/volt/iccsense paths are untouched and the new channels and attributes are gated on RUSD, so pre-GSP boards see no change.
--- drivers/gpu/drm/nouveau/nouveau_hwmon.c | 375 +++++++++++++++++++----- 1 file changed, 294 insertions(+), 81 deletions(-)
drivers/gpu/drm/nouveau/nouveau_hwmon.c +294 -81
@@ -25,6 +25,8 @@#ifdef CONFIG_ACPI #include <linux/acpi.h> #endif +#include <linux/delay.h> +#include <linux/jiffies.h> #include <linux/power_supply.h> #include <linux/hwmon.h> #include <linux/hwmon-sysfs.h>
@@ -32,6 +34,7 @@#include "nouveau_drv.h" #include "nouveau_hwmon.h" +#include <nvkm/subdev/gsp.h> #include <nvkm/subdev/iccsense.h> #include <nvkm/subdev/volt.h>
@@ -215,10 +218,11 @@ static const struct hwmon_channel_info * const nouveau_info[] = {HWMON_CHANNEL_INFO (chip,HWMON_C_UPDATE_INTERVAL ),HWMON_CHANNEL_INFO (temp, -HWMON_T_INPUT | +HWMON_T_INPUT |HWMON_T_LABEL |HWMON_T_MAX |HWMON_T_MAX_HYST |HWMON_T_CRIT |HWMON_T_CRIT_HYST | -HWMON_T_EMERGENCY |HWMON_T_EMERGENCY_HYST ), +HWMON_T_EMERGENCY |HWMON_T_EMERGENCY_HYST , +HWMON_T_INPUT |HWMON_T_LABEL ),HWMON_CHANNEL_INFO (fan,HWMON_F_INPUT ), HWMON_CHANNEL_INFO(in,
@@ -228,7 +232,10 @@ static const struct hwmon_channel_info * const nouveau_info[] = {HWMON_CHANNEL_INFO (pwm,HWMON_PWM_INPUT |HWMON_PWM_ENABLE ),HWMON_CHANNEL_INFO (power, -HWMON_P_INPUT |HWMON_P_CAP_MAX |HWMON_P_CRIT ), +HWMON_P_INPUT |HWMON_P_MAX |HWMON_P_CRIT | +HWMON_P_AVERAGE |HWMON_P_CAP |HWMON_P_LABEL , +HWMON_P_INPUT |HWMON_P_AVERAGE |HWMON_P_LABEL , +HWMON_P_AVERAGE |HWMON_P_LABEL ), NULL };
@@ -243,52 +250,144 @@ nouveau_chip_is_visible(const void *data, u32 attr, int channel) } } -static umode_t -nouveau_power_is_visible (const void *data,u32 attr,int channel) +static bool +nouveau_rusd_ok (struct nvkm_gsp *gsp,enum nvkm_gsp_rusd_item item) { -struct nouveau_drm *drm =nouveau_drm ((struct drm_device *)data); -struct nvkm_iccsense *iccsense =nvxx_iccsense (drm); +int retries =3 ; +s64 val; +int ret; -if (!iccsense || !iccsense->data_valid ||list_empty (&iccsense->rails)) -return 0 ; +/* Visibility decisions are made only once at registration. So retry +* to avoid letting racing a GSP write window (-EAGAIN) hide a channel +* for good. +*/ +do { + ret =nvkm_gsp_rusd_read (gsp, item, &val); +if (ret != -EAGAIN ) +break ; +usleep_range (100 ,200 ); + }while (--retries); + +return ret ==0 ; +} +static umode_t +nouveau_rusd_power_is_visible (struct nvkm_gsp *gsp,u32 attr,int channel) +{switch (attr) {case hwmon_power_input: -return 0444 ; -case hwmon_power_max: -if (iccsense->power_w_max) +if (channel ==0 &&nouveau_rusd_ok (gsp,NVKM_GSP_RUSD_POWER_GPU )) +return 0444 ; +if (channel ==1 &&nouveau_rusd_ok (gsp,NVKM_GSP_RUSD_POWER_BOARD )) +return 0444 ; +return 0 ; +case hwmon_power_average: +if (channel ==0 &&nouveau_rusd_ok (gsp,NVKM_GSP_RUSD_POWER_GPU_AVG )) +return 0444 ; +if (channel ==1 &&nouveau_rusd_ok (gsp,NVKM_GSP_RUSD_POWER_BOARD_AVG )) +return 0444 ; +if (channel ==2 &&nouveau_rusd_ok (gsp,NVKM_GSP_RUSD_POWER_VRAM_AVG ))return 0444 ;return 0 ; -case hwmon_power_crit: -if (iccsense->power_w_crit) +case hwmon_power_cap: +/* The enforced limit is only telemetry here. Setting it needs ctrls nouveau +* doesn't implement. +*/ +if (channel ==0 &&nouveau_rusd_ok (gsp,NVKM_GSP_RUSD_POWER_CAP ))return 0444 ;return 0 ; +case hwmon_power_label: +switch (channel) { +case 0 : +if (nouveau_rusd_ok (gsp,NVKM_GSP_RUSD_POWER_GPU ) || +nouveau_rusd_ok (gsp,NVKM_GSP_RUSD_POWER_GPU_AVG ) || +nouveau_rusd_ok (gsp,NVKM_GSP_RUSD_POWER_CAP )) +return 0444 ; +break ; +case 1 : +if (nouveau_rusd_ok (gsp,NVKM_GSP_RUSD_POWER_BOARD ) || +nouveau_rusd_ok (gsp,NVKM_GSP_RUSD_POWER_BOARD_AVG )) +return 0444 ; +break ; +case 2 : +if (nouveau_rusd_ok (gsp,NVKM_GSP_RUSD_POWER_VRAM_AVG )) +return 0444 ; +break ; + } +return 0 ;default :return 0 ; } }static umode_t -nouveau_temp_is_visible (const void *data,u32 attr,int channel) +nouveau_power_is_visible (const void *data,u32 attr,int channel) {struct nouveau_drm *drm =nouveau_drm ((struct drm_device *)data); -struct nvkm_therm *therm =nvxx_therm (drm); +struct nvkm_iccsense *iccsense =nvxx_iccsense (drm); +struct nvkm_device *device = drm->nvkm; +struct nvkm_gsp *gsp = device->gsp; -if (!therm || !therm->attr_get ||nvkm_therm_temp_get (therm) <0 ) -return 0 ; +if (nvkm_gsp_rusd (gsp)) +return nouveau_rusd_power_is_visible (gsp, attr, channel); +else { +if (!iccsense || !iccsense->data_valid ||list_empty (&iccsense->rails)) +return 0 ; -switch (attr) { -case hwmon_temp_input: -return 0444 ; -case hwmon_temp_max: -case hwmon_temp_max_hyst: -case hwmon_temp_crit: -case hwmon_temp_crit_hyst: -case hwmon_temp_emergency: -case hwmon_temp_emergency_hyst: -return 0644 ; -default : -return 0 ; +switch (attr) { +case hwmon_power_input: +return 0444 ; +case hwmon_power_max: +if (iccsense->power_w_max) +return 0444 ; +return 0 ; +case hwmon_power_crit: +if (iccsense->power_w_crit) +return 0444 ; +return 0 ; +default : +return 0 ; + } + } +} + +static umode_t +nouveau_temp_is_visible (const void *data,u32 attr,int channel) +{ +struct nouveau_drm *drm =nouveau_drm ((struct drm_device *)data); +struct nvkm_therm *therm =nvxx_therm (drm); +struct nvkm_device *device = drm->nvkm; +struct nvkm_gsp *gsp = device->gsp; + +if (nvkm_gsp_rusd (gsp)) { +switch (attr) { +case hwmon_temp_input: +case hwmon_temp_label: +if (nouveau_rusd_ok (gsp, channel ?NVKM_GSP_RUSD_TEMP_HBM : +NVKM_GSP_RUSD_TEMP_GPU )) +return 0444 ; +return 0 ; +default : +/* No threshold data in the RUSD buffer. */ +return 0 ; + } + }else { +if (!therm || !therm->attr_get ||nvkm_therm_temp_get (therm) <0 ) +return 0 ; + +switch (attr) { +case hwmon_temp_input: +return 0444 ; +case hwmon_temp_max: +case hwmon_temp_max_hyst: +case hwmon_temp_crit: +case hwmon_temp_crit_hyst: +case hwmon_temp_emergency: +case hwmon_temp_emergency_hyst: +return 0644 ; +default : +return 0 ; + } } }
@@ -351,9 +450,13 @@ nouveau_fan_is_visible(const void *data, u32 attr, int channel)static int nouveau_chip_read (struct device *dev,u32 attr,int channel,long *val) { +struct nouveau_drm *drm =nouveau_drm (dev_get_drvdata (dev)); +struct nvkm_device *device = drm->nvkm; +struct nvkm_gsp *gsp = device->gsp; +switch (attr) {case hwmon_chip_update_interval: - *val =1000 ; + *val =nvkm_gsp_rusd (gsp) ? gsp->rusd.poll_ms :1000 ;break ;default :return -EOPNOTSUPP ;
@@ -368,47 +471,67 @@ nouveau_temp_read(struct device *dev, u32 attr, int channel, long *val)struct drm_device *drm_dev =dev_get_drvdata (dev);struct nouveau_drm *drm =nouveau_drm (drm_dev);struct nvkm_therm *therm =nvxx_therm (drm); +struct nvkm_device *device = drm->nvkm; +struct nvkm_gsp *gsp = device->gsp;int ret; -if (!therm || !therm->attr_get) -return -EOPNOTSUPP ; +if (nvkm_gsp_rusd (gsp)) { +s64 value; + +if (attr != hwmon_temp_input) +return -EOPNOTSUPP ; -switch (attr) { -case hwmon_temp_input:if (drm_dev->switch_power_state !=DRM_SWITCH_POWER_ON )return -EINVAL ; - ret =nvkm_therm_temp_get (therm); - *val = ret <0 ? ret : (ret *1000 ); -break ; -case hwmon_temp_max: - *val = therm->attr_get (therm,NVKM_THERM_ATTR_THRS_DOWN_CLK ) - *1000 ; -break ; -case hwmon_temp_max_hyst: - *val = therm->attr_get (therm,NVKM_THERM_ATTR_THRS_DOWN_CLK_HYST ) - *1000 ; -break ; -case hwmon_temp_crit: - *val = therm->attr_get (therm,NVKM_THERM_ATTR_THRS_CRITICAL ) - *1000 ; -break ; -case hwmon_temp_crit_hyst: - *val = therm->attr_get (therm,NVKM_THERM_ATTR_THRS_CRITICAL_HYST ) - *1000 ; -break ; -case hwmon_temp_emergency: - *val = therm->attr_get (therm,NVKM_THERM_ATTR_THRS_SHUTDOWN ) - *1000 ; -break ; -case hwmon_temp_emergency_hyst: - *val = therm->attr_get (therm,NVKM_THERM_ATTR_THRS_SHUTDOWN_HYST ) - *1000 ; -break ; -default : -return -EOPNOTSUPP ; - } -return 0 ; + ret =nvkm_gsp_rusd_read (gsp, channel ?NVKM_GSP_RUSD_TEMP_HBM : +NVKM_GSP_RUSD_TEMP_GPU , &value); +if (ret) +return ret; + + *val = value; +return 0 ; + }else { +if (!therm || !therm->attr_get) +return -EOPNOTSUPP ; + +switch (attr) { +case hwmon_temp_input: +if (drm_dev->switch_power_state !=DRM_SWITCH_POWER_ON ) +return -EINVAL ; + ret =nvkm_therm_temp_get (therm); + *val = ret <0 ? ret : (ret *1000 ); +break ; +case hwmon_temp_max: + *val = therm->attr_get (therm,NVKM_THERM_ATTR_THRS_DOWN_CLK ) + *1000 ; +break ; +case hwmon_temp_max_hyst: + *val = therm->attr_get (therm,NVKM_THERM_ATTR_THRS_DOWN_CLK_HYST ) + *1000 ; +break ; +case hwmon_temp_crit: + *val = therm->attr_get (therm,NVKM_THERM_ATTR_THRS_CRITICAL ) + *1000 ; +break ; +case hwmon_temp_crit_hyst: + *val = therm->attr_get (therm,NVKM_THERM_ATTR_THRS_CRITICAL_HYST ) + *1000 ; +break ; +case hwmon_temp_emergency: + *val = therm->attr_get (therm,NVKM_THERM_ATTR_THRS_SHUTDOWN ) + *1000 ; +break ; +case hwmon_temp_emergency_hyst: + *val = therm->attr_get (therm,NVKM_THERM_ATTR_THRS_SHUTDOWN_HYST ) + *1000 ; +break ; +default : +return -EOPNOTSUPP ; + } + +return 0 ; + } } static int
@@ -492,34 +615,84 @@ nouveau_pwm_read(struct device *dev, u32 attr, int channel, long *val) }static int -nouveau_power_read (struct device *dev,u32 attr,int channel,long *val) +nouveau_rusd_power_read (struct drm_device *drm_dev,struct nvkm_gsp *gsp, +u32 attr,int channel,long *val) { -struct drm_device *drm_dev =dev_get_drvdata (dev); -struct nouveau_drm *drm =nouveau_drm (drm_dev); -struct nvkm_iccsense *iccsense =nvxx_iccsense (drm); - -if (!iccsense) -return -EOPNOTSUPP ; +enum nvkm_gsp_rusd_item item; +s64 value; +int ret;switch (attr) {case hwmon_power_input: -if (drm_dev->switch_power_state !=DRM_SWITCH_POWER_ON ) -return -EINVAL ; - *val =nvkm_iccsense_read_all (iccsense); +if (channel ==2 ) +return -EOPNOTSUPP ; + item = channel ?NVKM_GSP_RUSD_POWER_BOARD : +NVKM_GSP_RUSD_POWER_GPU ;break ; -case hwmon_power_max: - *val = iccsense->power_w_max; +case hwmon_power_average: +if (channel ==0 ) + item =NVKM_GSP_RUSD_POWER_GPU_AVG ; +else if (channel ==1 ) + item =NVKM_GSP_RUSD_POWER_BOARD_AVG ; +else + item =NVKM_GSP_RUSD_POWER_VRAM_AVG ;break ; -case hwmon_power_crit: - *val = iccsense->power_w_crit; +case hwmon_power_cap: +if (channel) +return -EOPNOTSUPP ; + item =NVKM_GSP_RUSD_POWER_CAP ;break ;default :return -EOPNOTSUPP ; } +if (drm_dev->switch_power_state !=DRM_SWITCH_POWER_ON ) +return -EINVAL ; + + ret =nvkm_gsp_rusd_read (gsp, item, &value); +if (ret) +return ret; + + *val = value; +return 0 ; } +static int +nouveau_power_read (struct device *dev,u32 attr,int channel,long *val) +{ +struct drm_device *drm_dev =dev_get_drvdata (dev); +struct nouveau_drm *drm =nouveau_drm (drm_dev); +struct nvkm_iccsense *iccsense =nvxx_iccsense (drm); +struct nvkm_device *device = drm->nvkm; +struct nvkm_gsp *gsp = device->gsp; + +if (nvkm_gsp_rusd (gsp)) +return nouveau_rusd_power_read (drm_dev, gsp, attr, channel, val); +else { +if (!iccsense) +return -EOPNOTSUPP ; + +switch (attr) { +case hwmon_power_input: +if (drm_dev->switch_power_state !=DRM_SWITCH_POWER_ON ) +return -EINVAL ; + *val =nvkm_iccsense_read_all (iccsense); +break ; +case hwmon_power_max: + *val = iccsense->power_w_max; +break ; +case hwmon_power_crit: + *val = iccsense->power_w_crit; +break ; +default : +return -EOPNOTSUPP ; + } + +return 0 ; + } +} +static int nouveau_temp_write (struct device *dev,u32 attr,int channel,long val) {
@@ -597,6 +770,8 @@ nouveau_is_visible(const void *data, enum hwmon_sensor_types type, u32 attr, }static const char input_label[] ="GPU core" ; +static const char *const nouveau_temp_labels[] = {"gpu" ,"vram" }; +static const char *const nouveau_power_labels[] = {"gpu" ,"board" ,"vram" }; static int nouveau_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,
@@ -607,6 +782,18 @@ nouveau_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,return 0 ; } +if (type == hwmon_temp && attr == hwmon_temp_label && + channel <ARRAY_SIZE (nouveau_temp_labels)) { + *buf = nouveau_temp_labels[channel]; +return 0 ; + } + +if (type == hwmon_power && attr == hwmon_power_label && + channel <ARRAY_SIZE (nouveau_power_labels)) { + *buf = nouveau_power_labels[channel]; +return 0 ; + } +return -EOPNOTSUPP ; }
@@ -667,13 +854,39 @@ nouveau_hwmon_init(struct drm_device *dev)struct nvkm_iccsense *iccsense =nvxx_iccsense (drm);struct nvkm_therm *therm =nvxx_therm (drm);struct nvkm_volt *volt =nvxx_volt (drm); +struct nvkm_device *device = drm->nvkm; +struct nvkm_gsp *gsp = device->gsp;const struct attribute_group *special_groups[N_ATTR_GROUPS ];struct nouveau_hwmon *hwmon;struct device *hwmon_dev; +bool rusd_active = false;int ret =0 ;int i =0 ; -if (!iccsense && !therm && !volt) { +if (nvkm_gsp_rusd (gsp)) { +/* Per-channel visibility is latched below from live RUSD +* section validity, so wait for GSP-RM's first poll of both +* requested groups (thermal, power). It is normally completed +* long before we get here and this is a last resort. +*/ +unsigned long timeout = jiffies + +msecs_to_jiffies (2 * gsp->rusd.poll_ms); +bool thermal, power; + +for (;;) { + thermal =nouveau_rusd_ok (gsp,NVKM_GSP_RUSD_TEMP_GPU ); + power =nouveau_rusd_ok (gsp,NVKM_GSP_RUSD_POWER_GPU ) || +nouveau_rusd_ok (gsp,NVKM_GSP_RUSD_POWER_GPU_AVG ) || +nouveau_rusd_ok (gsp,NVKM_GSP_RUSD_POWER_CAP ); +if ((thermal && power) || !time_before (jiffies, timeout)) +break ; +msleep (20 ); + } + + rusd_active = thermal || power; + } + +if (!iccsense && !therm && !volt && !rusd_active) {NV_DEBUG (drm,"Skipping hwmon registration\n" );return 0 ; }
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH 3/6] drm/nouveau: add GSP hwmon support
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] Legacy (pre-GSP) hardware exposes duplicate dummy temperature and power sensor attributes.…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] Legacy (pre-GSP) hardware exposes duplicate dummy temperature and power sensor attributes.
- [High] Unconditional 2-second timeout delay during driver initialization if the GPU supports only thermal or only power telemetry.
- [Medium] The hwmon sysfs read callbacks fail intermittently with -EAGAIN when racing with GSP telemetry updates.
- [Medium] The GSP 'temp1' label incorrectly reports 'GPU core' instead of 'gpu', leaving the new label definition as dead code. --
--- Patch [3]: [PATCH 3/6] drm/nouveau: add GSP hwmon support --- commit ceccedcbd9d07d5becab288795d358c7f8e9d71b
Author: Mohamed Ahmed <[email protected]>
drm/nouveau: add GSP hwmon support
This commit wires up the RUSD telemetry to provide hwmon device support for Turing through Blackwell boards. It adds temperature and power readout channels, aiming to leave legacy therm/volt/iccsense paths unchanged.
Quoted 3 lines
drivers/gpu/drm/nouveau/nouveau_hwmon.c +0
-0
[ ... ]
Quoted 1 line
drivers/gpu/drm/nouveau/nouveau_hwmon.c +0
-0@@ -243,52 +250,144 @@ nouveau_chip_is_visible(const void *data, u32 attr, int channel)
[ ... ]
Quoted 3 lines
drivers/gpu/drm/nouveau/nouveau_hwmon.c +3
-0+static umode_t +nouveau_power_is_visible (const void *data,u32 attr,int channel) +{
[ ... ]
drivers/gpu/drm/nouveau/nouveau_hwmon.c nouveau_chip_is_visible(const void *data, u32 attr, int channel) · line 368
Quoted 9 lines
drivers/gpu/drm/nouveau/nouveau_hwmon.c +9
-0+if (nvkm_gsp_rusd (gsp)) +return nouveau_rusd_power_is_visible (gsp, attr, channel); +else { +if (!iccsense || !iccsense->data_valid ||list_empty (&iccsense->rails)) +return 0 ; + +switch (attr) { +case hwmon_power_input: +return 0444 ;
[Severity: High]
Does this inadvertently expose dummy power sensors on pre-GSP hardware?
The hwmon core iterates over the newly added channels in nouveau_info, but this legacy fallback branch in nouveau_power_is_visible() does not check the channel index. Because it unconditionally returns 0444 for hwmon_power_input, it advertises support for channels 1 and 2 on legacy boards, duplicating channel 0.
A similar issue appears in nouveau_temp_is_visible() which returns 0444 for hwmon_temp_input regardless of the channel parameter.
Quoted 1 line
drivers/gpu/drm/nouveau/nouveau_hwmon.c +0
-0@@ -368,47 +471,67 @@ nouveau_temp_read(struct device *dev, u32 attr, int channel, long *val)
[ ... ]
Quoted 1 line
drivers/gpu/drm/nouveau/nouveau_hwmon.c +1
-0+if (nvkm_gsp_rusd (gsp)) {
[ ... ]
drivers/gpu/drm/nouveau/nouveau_hwmon.c nouveau_temp_read(struct device *dev, u32 attr, int channel, long *val) · line 490
Quoted 4 lines
drivers/gpu/drm/nouveau/nouveau_hwmon.c +4
-0+ ret =nvkm_gsp_rusd_read (gsp, channel ?NVKM_GSP_RUSD_TEMP_HBM : +NVKM_GSP_RUSD_TEMP_GPU , &value); +if (ret) +return ret;
[Severity: Medium]
Could this cause sporadic sensor read failures in userspace?
When userspace reads a sysfs attribute like temp1_input during a GSP write window, nvkm_gsp_rusd_read() returns -EAGAIN. Since there is no retry loop here in nouveau_temp_read() (unlike the one implemented in nouveau_rusd_ok() for initialization), does this directly fail the userspace read and cause monitoring tools to report errors?
This pattern also appears in nouveau_rusd_power_read().
Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_hwmon.c +2
-0@@ -597,6 +770,8 @@ nouveau_is_visible(const void *data, enum hwmon_sensor_types type, u32 attr, }static const char input_label[] ="GPU core" ; +static const char *const nouveau_temp_labels[] = {"gpu" ,"vram" }; +static const char *const nouveau_power_labels[] = {"gpu" ,"board" ,"vram" }; static int nouveau_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,
drivers/gpu/drm/nouveau/nouveau_hwmon.c nouveau_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr, · line 789
Quoted 8 lines
drivers/gpu/drm/nouveau/nouveau_hwmon.c +5
-0@@ -607,6 +782,18 @@ nouveau_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr,return 0 ; } +if (type == hwmon_temp && attr == hwmon_temp_label && + channel <ARRAY_SIZE (nouveau_temp_labels)) { + *buf = nouveau_temp_labels[channel]; +return 0 ; + }
[Severity: Medium]
Is the new label for temp1 unreachable for GSP boards?
Earlier in nouveau_read_string(), there is a check for channel == 0:
if (type == hwmon_temp && attr == hwmon_temp_label && channel == 0) {
*buf = input_label;
return 0;
}Because that check intercepts channel 0 and returns "GPU core", does it prevent the execution of this new block and leave nouveau_temp_labels[0] ("gpu") as dead code?
Quoted 1 line
drivers/gpu/drm/nouveau/nouveau_hwmon.c +0
-0@@ -667,13 +854,39 @@ nouveau_hwmon_init(struct drm_device *dev)
[ ... ]
drivers/gpu/drm/nouveau/nouveau_hwmon.c nouveau_hwmon_init(struct drm_device *dev) · line 884
Quoted 9 lines
drivers/gpu/drm/nouveau/nouveau_hwmon.c +9
-0+for (;;) { + thermal =nouveau_rusd_ok (gsp,NVKM_GSP_RUSD_TEMP_GPU ); + power =nouveau_rusd_ok (gsp,NVKM_GSP_RUSD_POWER_GPU ) || +nouveau_rusd_ok (gsp,NVKM_GSP_RUSD_POWER_GPU_AVG ) || +nouveau_rusd_ok (gsp,NVKM_GSP_RUSD_POWER_CAP ); +if ((thermal && power) || !time_before (jiffies, timeout)) +break ; +msleep (20 ); + }
[Severity: High]
Will this loop introduce a noticeable boot delay on configurations that only support one of these telemetry features?
The loop condition requires both thermal and power telemetry to become valid to break early. If a GPU SKU natively supports only thermal or only power sensors, the missing feature will constantly fail the check. Will this unnecessarily block driver probe for the full timeout duration (typically 2 seconds) before proceeding?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
maintainerRe: [PATCH 3/6] drm/nouveau: add GSP hwmon support
In reply to Mohamed AhmedQuoted 12 lines · Mohamed Ahmed
(quoted diff) +2
-0+static int +nouveau_power_read(struct device *dev, u32 attr, int channel, long*val)
drivers/gpu/drm/nouveau/nouveau_hwmon.c +9
-0+{ +struct drm_device *drm_dev =dev_get_drvdata (dev); +struct nouveau_drm *drm =nouveau_drm (drm_dev); +struct nvkm_iccsense *iccsense =nvxx_iccsense (drm); +struct nvkm_device *device = drm->nvkm; +struct nvkm_gsp *gsp = device->gsp; + +if (nvkm_gsp_rusd (gsp)) + return nouveau_rusd_power_read(drm_dev, gsp, attr,
Quoted 1 line
channel, val);
IMO - let's add braces to this conditional
Quoted 25 lines
drivers/gpu/drm/nouveau/nouveau_hwmon.c +7
-0+else { +if (!iccsense) +return -EOPNOTSUPP ; + +switch (attr) { +case hwmon_power_input: + if (drm_dev->switch_power_state !=
DRM_SWITCH_POWER_ON)drivers/gpu/drm/nouveau/nouveau_hwmon.c +17
-0+return -EINVAL ; + *val =nvkm_iccsense_read_all (iccsense); +break ; +case hwmon_power_max: + *val = iccsense->power_w_max; +break ; +case hwmon_power_crit: + *val = iccsense->power_w_crit; +break ; +default : +return -EOPNOTSUPP ; + } + +return 0 ; + } +} +
...
Quoted 43 lines
static int
nouveau_temp_write(struct device *dev, u32 attr, int channel, long val)
{drivers/gpu/drm/nouveau/nouveau_hwmon.c +3
-0@@ -667,13 +854,39 @@ nouveau_hwmon_init(struct drm_device *dev) struct nvkm_iccsense *iccsense = nvxx_iccsense(drm); struct nvkm_therm *therm = nvxx_therm(drm); struct nvkm_volt *volt = nvxx_volt(drm); +struct nvkm_device *device = drm->nvkm; +struct nvkm_gsp *gsp = device->gsp; const struct attribute_group *special_groups[N_ATTR_GROUPS]; struct nouveau_hwmon *hwmon; struct device *hwmon_dev; +bool rusd_active = false; int ret = 0; int i = 0;drivers/gpu/drm/nouveau/nouveau_hwmon.c +2
-1-if (!iccsense && !therm && !volt) { +if (nvkm_gsp_rusd (gsp)) { +/* Per-channel visibility is latched below from live RUSD
(quoted diff) +1
-0+ * section validity, so wait for GSP-RM's first pollof both
(quoted diff) +1
-0+ * requested groups (thermal, power). It is normallycompleted
(quoted diff) +1
-0+ * long before we get here and this is a lastresort.
drivers/gpu/drm/nouveau/nouveau_hwmon.c +7
-0+*/ +unsigned long timeout = jiffies + +msecs_to_jiffies (2 * gsp->rusd.poll_ms); +bool thermal, power; + +for (;;) { + thermal = nouveau_rusd_ok(gsp,
NVKM_GSP_RUSD_TEMP_GPU);(quoted diff) +1
-0+ power = nouveau_rusd_ok(gsp,
NVKM_GSP_RUSD_POWER_GPU) ||(quoted diff) +1
-0+ nouveau_rusd_ok(gsp,
NVKM_GSP_RUSD_POWER_GPU_AVG) ||(quoted diff) +1
-0+ nouveau_rusd_ok(gsp,
NVKM_GSP_RUSD_POWER_CAP);(quoted diff) +1
-0+ if ((thermal && power) ||!time_before(jiffies, timeout))
drivers/gpu/drm/nouveau/nouveau_hwmon.c nouveau_hwmon_init(struct drm_device *dev) · line 884
Quoted 3 lines
drivers/gpu/drm/nouveau/nouveau_hwmon.c +3
-0+break ; +msleep (20 ); + }
Is it possible to use nvif_msec() here?
Quoted 8 lines
drivers/gpu/drm/nouveau/nouveau_hwmon.c +5
-0+ + rusd_active = thermal || power; + } + +if (!iccsense && !therm && !volt && !rusd_active) {
NV_DEBUG(drm, "Skipping hwmon registration\n"); return 0;
}
Re: [PATCH 3/6] drm/nouveau: add GSP hwmon support
Quoted 86 lines · On Tue, Jul 21, 2026 at 10:36 PM <[email protected]> wrote:
Quoted 12 lines · Mohamed Ahmed
(quoted diff) +2
-0+static int +nouveau_power_read(struct device *dev, u32 attr, int channel, long*val)
drivers/gpu/drm/nouveau/nouveau_hwmon.c +9
-0+{ +struct drm_device *drm_dev =dev_get_drvdata (dev); +struct nouveau_drm *drm =nouveau_drm (drm_dev); +struct nvkm_iccsense *iccsense =nvxx_iccsense (drm); +struct nvkm_device *device = drm->nvkm; +struct nvkm_gsp *gsp = device->gsp; + +if (nvkm_gsp_rusd (gsp)) + return nouveau_rusd_power_read(drm_dev, gsp, attr,Quoted 1 line
channel, val);
IMO - let's add braces to this conditional
Quoted 25 lines
drivers/gpu/drm/nouveau/nouveau_hwmon.c +7
-0+else { +if (!iccsense) +return -EOPNOTSUPP ; + +switch (attr) { +case hwmon_power_input: + if (drm_dev->switch_power_state !=
DRM_SWITCH_POWER_ON)drivers/gpu/drm/nouveau/nouveau_hwmon.c +17
-0+return -EINVAL ; + *val =nvkm_iccsense_read_all (iccsense); +break ; +case hwmon_power_max: + *val = iccsense->power_w_max; +break ; +case hwmon_power_crit: + *val = iccsense->power_w_crit; +break ; +default : +return -EOPNOTSUPP ; + } + +return 0 ; + } +} +...
Quoted 40 lines
static int
nouveau_temp_write(struct device *dev, u32 attr, int channel, long
val)
{drivers/gpu/drm/nouveau/nouveau_hwmon.c +5
-1@@ -667,13 +854,39 @@ nouveau_hwmon_init(struct drm_device *dev)struct nvkm_iccsense *iccsense =nvxx_iccsense (drm);struct nvkm_therm *therm =nvxx_therm (drm);struct nvkm_volt *volt =nvxx_volt (drm); +struct nvkm_device *device = drm->nvkm; +struct nvkm_gsp *gsp = device->gsp;const struct attribute_group *special_groups[N_ATTR_GROUPS ];struct nouveau_hwmon *hwmon;struct device *hwmon_dev; +bool rusd_active = false;int ret =0 ;int i =0 ; -if (!iccsense && !therm && !volt) { +if (nvkm_gsp_rusd (gsp)) { +/* Per-channel visibility is latched below from live RUSD
+ * section validity, so wait for GSP-RM's first poll
of both
+ * requested groups (thermal, power). It is normally
completed
+ * long before we get here and this is a last
resort.drivers/gpu/drm/nouveau/nouveau_hwmon.c +7
-0+*/ +unsigned long timeout = jiffies + +msecs_to_jiffies (2 * gsp->rusd.poll_ms); +bool thermal, power; + +for (;;) { + thermal = nouveau_rusd_ok(gsp,
NVKM_GSP_RUSD_TEMP_GPU);
+ power = nouveau_rusd_ok(gsp,NVKM_GSP_RUSD_POWER_GPU) ||+ nouveau_rusd_ok(gsp, NVKM_GSP_RUSD_POWER_GPU_AVG) || + nouveau_rusd_ok(gsp,
Quoted 9 lines
drivers/gpu/drm/nouveau/nouveau_hwmon.c nouveau_hwmon_init(struct drm_device *dev) · line 884
Quoted 6 lines
NVKM_GSP_RUSD_POWER_CAP);
+ if ((thermal && power) ||
!time_before(jiffies, timeout))drivers/gpu/drm/nouveau/nouveau_hwmon.c +3
-0+break ; +msleep (20 ); + }Is it possible to use
nvif_msec()here?
It can work but it's strictly worse than this. nvif_msec() does busy looping, which would be overkill for this as it would be doing a lot more reading for something that changes at most once per 500ms poll cycle, and it keeps the CPU fully occupied with every read. It also couples us to GPU timing while the main thing we are waiting here on is whether the GSP's buffer writes are now visible in RAM so GPU side time doesn't offer us anything. I actually wasn't sure at first how to properly wait and did go over all the possible timing alternatives and jiffies looked to be the best here.
That said, to address what Milos mentioned (the weirdness of files being -ENODATA), I am going to have to move this into nvkm/rusd, inside r570_rusd_supported()/r570_rusd_read() which doesn't have any other alternative available to do a similar style waiting loop.
Quoted 9 lines
Quoted 8 lines
drivers/gpu/drm/nouveau/nouveau_hwmon.c +5
-0+ + rusd_active = thermal || power; + } + +if (!iccsense && !therm && !volt && !rusd_active) {NV_DEBUG (drm,"Skipping hwmon registration\n" );return 0 ; }
[email protected]
maintainerRe: [PATCH 3/6] drm/nouveau: add GSP hwmon support
Quoted 12 lines · Mohamed Ahmed
It can work but it's strictly worse than this.
nvif_msec()does busy looping, which would be overkill for this as it would be doing a lot more reading for something that changes at most once per 500ms poll cycle, and it keeps the CPU fully occupied with every read. It also couples us to GPU timing while the main thing we are waiting here on is whether the GSP's buffer writes are now visible in RAM so GPU side time doesn't offer us anything. I actually wasn't sure at first how to
properly wait and did go over all the possible timing alternatives and
jiffies looked to be the best here.
Quoted 4 lines
That said, to address what Milos mentioned (the weirdness of files being
-ENODATA), I am going to have to move this into nvkm/rusd, inside r570_rusd_supported()/r570_rusd_read() which doesn't have any other alternative available to do a similar style waiting loop.
Gotcha, sgtm
PATCH 4/6 drm/nouveau: expose RUSD telemetry via sysfs
In reply to Mohamed AhmedAdd a "rusd" attribute group under the DRM device (/sys/class/drm/cardN/device/rusd/) exposing every GSP-polled RUSD telemetry value as its own world-readable file: temperatures, the full set of power readings, clocks, GPU/memory/engine utilization, current pstate, clock throttle reasons, ECC error counts, memory row-remap state and PCIe link counters.
The data that fits hwmon (temperature, power) is already published there, this interface is for the rest, which has no hwmon channel type, and for tools that want a complete, self-contained view. Each file reads one decoded value through nvkm_gsp_rusd_read(). nvkm owns the units and conversions, so the show() is a thin wrapper.
The group is created only on GSP-RM boards whose firmware provides RUSD (r570+); all files appear when RUSD is active, and a section that is unsupported on the board (e.g. ECC on a consumer part) or has not been polled yet reads -ENODATA rather than being raced out of existence at probe time. Because reads are demand-driven, GSP only polls a value's group while its files are being read.
Files are documented in Documentation/ABI/testing/sysfs-driver-nouveau.
--- .../ABI/testing/sysfs-driver-nouveau | 152 +++++++++++ MAINTAINERS | 1 + drivers/gpu/drm/nouveau/Kbuild | 1 + drivers/gpu/drm/nouveau/nouveau_drm.c | 3 + drivers/gpu/drm/nouveau/nouveau_drv.h | 1 + drivers/gpu/drm/nouveau/nouveau_sysfs.c | 250 ++++++++++++++++++ drivers/gpu/drm/nouveau/nouveau_sysfs.h | 10 + 7 files changed, 418 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-nouveau create mode 100644 drivers/gpu/drm/nouveau/nouveau_sysfs.c create mode 100644 drivers/gpu/drm/nouveau/nouveau_sysfs.h
Documentation/ABI/testing/sysfs-driver-nouveau new file +152 -0
@@ -0,0 +1,152 @@ +What: /sys/class/drm/card<n>/device/rusd/ +Date: June 2026 +Contact: nouveau <[email protected]> +Description: + GPU telemetry read from NVIDIA GSP-RM's "RM User Shared Data" + (RUSD) buffer. Present only on GSP-RM boards whose firmware + supports RUSD (r570 and later); absent otherwise. Each file is + a single value, world-readable. GSP polls a value's data group + only while files in that group are being read, so the first read + after an idle period, and reads of a section not supported on the + board, return -ENODATA; a subsequent read returns data once the + group has been polled. All files are read-only. + +What: /sys/class/drm/card<n>/device/rusd/temp_gpu +What: /sys/class/drm/card<n>/device/rusd/temp_hbm +Date: June 2026 +Contact: nouveau <[email protected]> +Description: + GPU core and HBM/VRAM temperatures, in millidegrees Celsius. + temp_hbm is meaningful only on boards with on-package memory + temperature sensing. + +What: /sys/class/drm/card<n>/device/rusd/power_gpu +What: /sys/class/drm/card<n>/device/rusd/power_gpu_average +What: /sys/class/drm/card<n>/device/rusd/power_board +What: /sys/class/drm/card<n>/device/rusd/power_board_average +What: /sys/class/drm/card<n>/device/rusd/power_vram_average +What: /sys/class/drm/card<n>/device/rusd/power_cpu +What: /sys/class/drm/card<n>/device/rusd/power_cap +What: /sys/class/drm/card<n>/device/rusd/power_limit_requested +Date: June 2026 +Contact: nouveau <[email protected]> +Description: + Power readings, in microwatts. power_gpu / power_board / + power_cpu are instantaneous GPU, board (module) and CPU power; + the *_average variants are time-averaged. power_cap is the + enforced power limit and power_limit_requested the requested one + (read-only; RUSD does not set limits). Board/module and CPU + values are absent on form factors that do not report them (e.g. + module power on Ampere/Hopper add-in boards). + +What: /sys/class/drm/card<n>/device/rusd/clock_graphics +What: /sys/class/drm/card<n>/device/rusd/clock_memory +What: /sys/class/drm/card<n>/device/rusd/clock_video +What: /sys/class/drm/card<n>/device/rusd/clock_sm +Date: June 2026 +Contact: nouveau <[email protected]> +Description: + Target clock frequencies of the graphics, memory, video and SM + domains, in MHz. A domain a board does not implement reads 0. + +What: /sys/class/drm/card<n>/device/rusd/util_gpu +What: /sys/class/drm/card<n>/device/rusd/util_memory +What: /sys/class/drm/card<n>/device/rusd/util_nvenc +What: /sys/class/drm/card<n>/device/rusd/util_nvdec +What: /sys/class/drm/card<n>/device/rusd/util_nvjpg +What: /sys/class/drm/card<n>/device/rusd/util_nvofa +Date: June 2026 +Contact: nouveau <[email protected]> +Description: + Utilization of the GPU, the memory controller and the NVENC, + NVDEC, NVJPG and NVOFA engines, as a percentage (0-100). These + are device-global, not per-process. + +What: /sys/class/drm/card<n>/device/rusd/util_nvenc_period +What: /sys/class/drm/card<n>/device/rusd/util_nvdec_period +What: /sys/class/drm/card<n>/device/rusd/util_nvjpg_period +What: /sys/class/drm/card<n>/device/rusd/util_nvofa_period +Date: June 2026 +Contact: nouveau <[email protected]> +Description: + Sampling period, in microseconds, over which the matching + engine utilization above was measured. + +What: /sys/class/drm/card<n>/device/rusd/pstate +Date: June 2026 +Contact: nouveau <[email protected]> +Description: + Current performance state (P-state) index; lower is higher + performance (P0 is maximum). + +What: /sys/class/drm/card<n>/device/rusd/throttle_status +What: /sys/class/drm/card<n>/device/rusd/throttle_gpu_idle +What: /sys/class/drm/card<n>/device/rusd/throttle_app_clock +What: /sys/class/drm/card<n>/device/rusd/throttle_sw_power_cap +What: /sys/class/drm/card<n>/device/rusd/throttle_hw_slowdown +What: /sys/class/drm/card<n>/device/rusd/throttle_sync_boost +What: /sys/class/drm/card<n>/device/rusd/throttle_sw_thermal +What: /sys/class/drm/card<n>/device/rusd/throttle_hw_thermal +What: /sys/class/drm/card<n>/device/rusd/throttle_hw_power_brake +What: /sys/class/drm/card<n>/device/rusd/throttle_display_clock +Date: June 2026 +Contact: nouveau <[email protected]> +Description: + Clock throttling reasons. throttle_status is the raw bitmask of + all active reasons; the remaining files each read 0 or 1 for one + reason (GPU idle, application clock setting, software power cap, + hardware slowdown, sync boost, software/hardware thermal + slowdown, hardware power brake, and display clock setting). + +What: /sys/class/drm/card<n>/device/rusd/ecc_total_ce_volatile +What: /sys/class/drm/card<n>/device/rusd/ecc_total_ce_aggregate +What: /sys/class/drm/card<n>/device/rusd/ecc_total_ue_volatile +What: /sys/class/drm/card<n>/device/rusd/ecc_total_ue_aggregate +What: /sys/class/drm/card<n>/device/rusd/ecc_dram_ce_volatile +What: /sys/class/drm/card<n>/device/rusd/ecc_dram_ce_aggregate +What: /sys/class/drm/card<n>/device/rusd/ecc_dram_ue_volatile +What: /sys/class/drm/card<n>/device/rusd/ecc_dram_ue_aggregate +What: /sys/class/drm/card<n>/device/rusd/ecc_sram_ce_volatile +What: /sys/class/drm/card<n>/device/rusd/ecc_sram_ce_aggregate +What: /sys/class/drm/card<n>/device/rusd/ecc_sram_ue_volatile +What: /sys/class/drm/card<n>/device/rusd/ecc_sram_ue_aggregate +Date: June 2026 +Contact: nouveau <[email protected]> +Description: + ECC error counts for total, DRAM and SRAM, split into + correctable (ce) and uncorrectable (ue) errors, each as a + volatile (since boot) and an aggregate (lifetime) count. + Present only on boards with ECC. + +What: /sys/class/drm/card<n>/device/rusd/rowremap_histogram_max +What: /sys/class/drm/card<n>/device/rusd/rowremap_histogram_high +What: /sys/class/drm/card<n>/device/rusd/rowremap_histogram_partial +What: /sys/class/drm/card<n>/device/rusd/rowremap_histogram_low +What: /sys/class/drm/card<n>/device/rusd/rowremap_histogram_none +What: /sys/class/drm/card<n>/device/rusd/rowremap_correctable +What: /sys/class/drm/card<n>/device/rusd/rowremap_uncorrectable +What: /sys/class/drm/card<n>/device/rusd/rowremap_pending +What: /sys/class/drm/card<n>/device/rusd/rowremap_failure +Date: June 2026 +Contact: nouveau <[email protected]> +Description: + Memory row-remapping state. The histogram_* files count memory + banks by remap-resource availability (max/high/partial/low/none); + rowremap_correctable and rowremap_uncorrectable count remapped + rows; rowremap_pending and rowremap_failure read 0 or 1. Present + only on boards with row remapping (datacenter parts). + +What: /sys/class/drm/card<n>/device/rusd/pcie_gen +What: /sys/class/drm/card<n>/device/rusd/pcie_linecode_errors +What: /sys/class/drm/card<n>/device/rusd/pcie_crc_errors +What: /sys/class/drm/card<n>/device/rusd/pcie_naks_received +What: /sys/class/drm/card<n>/device/rusd/pcie_failed_l0s_exits +What: /sys/class/drm/card<n>/device/rusd/pcie_correctable_errors +What: /sys/class/drm/card<n>/device/rusd/pcie_nonfatal_errors +What: /sys/class/drm/card<n>/device/rusd/pcie_fatal_errors +What: /sys/class/drm/card<n>/device/rusd/pcie_unsupported_requests +Date: June 2026 +Contact: nouveau <[email protected]> +Description: + PCIe link telemetry. pcie_gen is a packed gen/width bitfield; + the remaining files are link error and event counters.
MAINTAINERS +1 -0
@@ -8289,6 +8289,7 @@ Q: https://gitlab.freedesktop.org/drm/nouveau/-/merge_requests B: https://gitlab.freedesktop.org/drm/nouveau/-/issues C: irc://irc.oftc.net/nouveau T: git https://gitlab.freedesktop.org/drm/misc/kernel.git +F: Documentation/ABI/testing/sysfs-driver-nouveau F: drivers/gpu/drm/nouveau/ F: include/uapi/drm/nouveau_drm.h
drivers/gpu/drm/nouveau/Kbuild +1 -0
@@ -26,6 +26,7 @@ nouveau-$(CONFIG_COMPAT) += nouveau_ioc32.o nouveau-$(CONFIG_LEDS_CLASS) += nouveau_led.o nouveau-y += nouveau_nvif.o nouveau-$(CONFIG_NOUVEAU_PLATFORM_DRIVER) += nouveau_platform.o +nouveau-y += nouveau_sysfs.o nouveau-y += nouveau_vga.o # DRM - memory management
drivers/gpu/drm/nouveau/nouveau_drm.c +3 -0
@@ -60,6 +60,7 @@#include "nouveau_vga.h" #include "nouveau_led.h" #include "nouveau_hwmon.h" +#include "nouveau_sysfs.h" #include "nouveau_acpi.h" #include "nouveau_bios.h" #include "nouveau_ioctl.h"
@@ -591,6 +592,7 @@ nouveau_drm_device_fini(struct nouveau_drm *drm)nouveau_dmem_fini (drm);nouveau_svm_fini (drm);nouveau_hwmon_fini (dev); +nouveau_sysfs_fini (drm);nouveau_debugfs_fini (drm);if (dev->mode_config.num_crtc)
@@ -675,6 +677,7 @@ nouveau_drm_device_init(struct nouveau_drm *drm) }nouveau_debugfs_init (drm); +nouveau_sysfs_init (drm);nouveau_hwmon_init (dev);nouveau_svm_init (drm);nouveau_dmem_init (drm);
drivers/gpu/drm/nouveau/nouveau_drv.h +1 -0
@@ -296,6 +296,7 @@ struct nouveau_drm {/* power management */ struct nouveau_hwmon *hwmon;struct nouveau_debugfs *debugfs; +bool rusd_sysfs;/* led management */ struct nouveau_led *led;
drivers/gpu/drm/nouveau/nouveau_sysfs.c new file +250 -0
250 lines not on this page · raw message
drivers/gpu/drm/nouveau/nouveau_sysfs.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: MIT */ +#ifndef __NOUVEAU_SYSFS_H__ +#define __NOUVEAU_SYSFS_H__ + +struct nouveau_drm ; + +int nouveau_sysfs_init (struct nouveau_drm *drm); +void nouveau_sysfs_fini (struct nouveau_drm *drm); + +#endif
Signature · 1 line
2.55.0
PATCH 5/6 drm/nouveau: expose global VRAM size and usage via sysfs
In reply to Mohamed AhmedMonitoring tools want a device-wide VRAM total and current usage, but nouveau exposed neither outside of NOUVEAU_GETPARAM ioctls, which are awkward to use for some tools as they rely on pulling libdrm.
Add two read-only files in a device attribute group:
mem_info_vram_total user-accessible VRAM, i.e. NOUVEAU_GETPARAM_FB_SIZE
mem_info_vram_used bytes currently allocated from the VRAM TTM manager
Both read nouveau's own framebuffer and TTM accounting, the exact source behind the FB_SIZE/VRAM_USED getparams, so they need no GSP and are present on every board, unlike the GSP-only RUSD group. total is the size of the pool used draws from, so used never exceeds total. used counts only memory nouveau itself allocated and can read below firmware-reserved usage.
--- .../ABI/testing/sysfs-driver-nouveau | 17 +++++- drivers/gpu/drm/nouveau/nouveau_drv.h | 1 + drivers/gpu/drm/nouveau/nouveau_sysfs.c | 61 +++++++++++++++++++ 3 files changed, 78 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-driver-nouveau +16 -1
@@ -149,4 +149,19 @@ Date: June 2026 Contact: nouveau <[email protected]> Description: PCIe link telemetry. pcie_gen is a packed gen/width bitfield; - the remaining files are link error and event counters. + the remaining files are link error and event counters. + +What: /sys/class/drm/card<n>/device/mem_info_vram_total +What: /sys/class/drm/card<n>/device/mem_info_vram_used +Date: June 2026 +Contact: nouveau <[email protected]> +Description: + The amount of VRAM usable for allocations and the amount currently + in use, in bytes, world-readable and read-only. mem_info_vram_total + is the installed VRAM minus the region firmware reserves. This is the + same value as NOUVEAU_GETPARAM_FB_SIZE, so it can read slightly below + the card's marketed size, and it is the size of the pool that + mem_info_vram_used draws from (so used never exceeds total). Both + come from nouveau's own framebuffer and TTM accounting (the same + source as the FB_SIZE/VRAM_USED ioctls) and are present on every + nouveau board, independent of GSP-RM.
drivers/gpu/drm/nouveau/nouveau_drv.h +1 -0
@@ -297,6 +297,7 @@ struct nouveau_drm {struct nouveau_hwmon *hwmon;struct nouveau_debugfs *debugfs;bool rusd_sysfs; +bool mem_sysfs;/* led management */ struct nouveau_led *led;
drivers/gpu/drm/nouveau/nouveau_sysfs.c +61 -0
87 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH 6/6 drm/nouveau: expose per-client GPU usage via fdinfo
In reply to Mohamed Ahmednouveau implemented no DRM fdinfo. Wire it up and report per-client memory and per-engine busy time, which monitoring tools consume generically.
Memory: add a GEM .status callback reporting residency and emit the standard stats via drm_show_memory_stats(). This works for every client regardless of submission path.
Engine busy time: account it from the DRM scheduler the EXEC/VM_BIND path already uses, similar to amdgpu. Each job's drm_sched fence carries scheduled/finished timestamps; (finished - scheduled) is folded into a per-client per-engine counter when the job retires (nouveau_sched_free_ job, the per-job hook the scheduler always calls). In-flight jobs are tracked on a per-client list and walked at fdinfo read time, adding (now - scheduled) so a currently-running client is accounted without waiting for its jobs to retire; the resulting non-monotonic correction on retire is permitted by drm-usage-stats. The drm_sched core back-fills the scheduled timestamp of in-order retiring jobs, so summing these intervals approximates the channel's busy wall-clock.
The engine a job is accounted against is recorded on its channel at allocation time. Only clients using the newer EXEC uAPI produce drm-engine-* values, legacy GEM_PUSHBUF submissions bypass the scheduler and are not accounted (memory still is). Of the engine classes the current uAPI can select, gfx/ce/dec are reachable. enc/jpg/ofa are defined for when per-engine channels become selectable.
--- drivers/gpu/drm/nouveau/nouveau_abi16.c | 16 +++++ drivers/gpu/drm/nouveau/nouveau_chan.h | 2 + drivers/gpu/drm/nouveau/nouveau_drm.c | 19 ++++++ drivers/gpu/drm/nouveau/nouveau_drv.h | 27 ++++++++ drivers/gpu/drm/nouveau/nouveau_exec.c | 3 + drivers/gpu/drm/nouveau/nouveau_gem.c | 16 +++++ drivers/gpu/drm/nouveau/nouveau_sched.c | 87 +++++++++++++++++++++++++ drivers/gpu/drm/nouveau/nouveau_sched.h | 11 ++++ 8 files changed, 181 insertions(+)
drivers/gpu/drm/nouveau/nouveau_abi16.c +16 -0
@@ -439,6 +439,22 @@ nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS)if (ret) goto done; +/* Record the channel's engine class for DRM fdinfo accounting. */ +switch (engine) { +case NV_DEVICE_HOST_RUNLIST_ENGINES_CE : + chan->chan->fdinfo_engine =NOUVEAU_FDINFO_ENGINE_CE ; +break ; +case NV_DEVICE_HOST_RUNLIST_ENGINES_MSPDEC : +case NV_DEVICE_HOST_RUNLIST_ENGINES_MSVLD : +case NV_DEVICE_HOST_RUNLIST_ENGINES_MSPPP : + chan->chan->fdinfo_engine =NOUVEAU_FDINFO_ENGINE_DEC ; +break ; +case NV_DEVICE_HOST_RUNLIST_ENGINES_GR : +default : + chan->chan->fdinfo_engine =NOUVEAU_FDINFO_ENGINE_GFX ; +break ; + } +/* If we're not using the VM_BIND uAPI, we don't need a scheduler. * * The client lock is already acquired by nouveau_abi16_get().
drivers/gpu/drm/nouveau/nouveau_chan.h +2 -0
@@ -20,6 +20,8 @@ struct nouveau_channel {u64 inst;u32 token; +u8 fdinfo_engine; +struct nvif_object vram;struct nvif_object gart;struct nvif_object nvsw;
drivers/gpu/drm/nouveau/nouveau_drm.c +19 -0
@@ -35,8 +35,10 @@#include <drm/clients/drm_client_setup.h> #include <drm/drm_drv.h> #include <drm/drm_fbdev_ttm.h> +#include <drm/drm_file.h> #include <drm/drm_gem_ttm_helper.h> #include <drm/drm_ioctl.h> +#include <drm/drm_print.h> #include <drm/drm_vblank.h> #include <core/gpuobj.h>
@@ -262,6 +264,9 @@ nouveau_cli_init(struct nouveau_drm *drm, const char *sname,INIT_LIST_HEAD (&cli->worker);mutex_init (&cli->lock); +spin_lock_init (&cli->fdinfo.lock); +INIT_LIST_HEAD (&cli->fdinfo.jobs); +mutex_lock (&drm->client_mutex); ret =nvif_client_ctor (&drm->_client, cli->name, &cli->base);mutex_unlock (&drm->client_mutex);
@@ -1347,6 +1352,18 @@ nouveau_drm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)return ret; } +static void +nouveau_show_fdinfo (struct drm_printer *p,struct drm_file *file) +{ +struct nouveau_cli *cli =nouveau_cli (file); + +/* Per-engine busy time of this client's EXEC jobs, then the standard +* per-region memory stats +*/ +nouveau_sched_show_fdinfo (cli, p); +drm_show_memory_stats (p, file); +} +static const struct file_operations nouveau_driver_fops = { .owner =THIS_MODULE ,
@@ -1360,6 +1377,7 @@ nouveau_driver_fops = { .compat_ioctl = nouveau_compat_ioctl, #endif .llseek = noop_llseek, + .show_fdinfo = drm_show_fdinfo, .fop_flags = FOP_UNSIGNED_OFFSET, };
@@ -1372,6 +1390,7 @@ driver_stub = { DRIVER_RENDER, .open = nouveau_drm_open, .postclose = nouveau_drm_postclose, + .show_fdinfo = PTR_IF(IS_ENABLED(CONFIG_PROC_FS), nouveau_show_fdinfo),#if defined(CONFIG_DEBUG_FS ) .debugfs_init = nouveau_drm_debugfs_init,
drivers/gpu/drm/nouveau/nouveau_drv.h +27 -0
@@ -65,6 +65,19 @@struct nouveau_channel ;struct platform_device ; +/* Engine classes tracked for DRM fdinfo per-client utilisation. The value +* NOUVEAU_FDINFO_ENGINE_COUNT doubles as "not accounted" +*/ +enum nouveau_fdinfo_engine { +NOUVEAU_FDINFO_ENGINE_GFX ,/* graphics/compute (GR) */ +NOUVEAU_FDINFO_ENGINE_CE ,/* copy */ +NOUVEAU_FDINFO_ENGINE_DEC ,/* video decode */ +NOUVEAU_FDINFO_ENGINE_ENC ,/* video encode */ +NOUVEAU_FDINFO_ENGINE_JPG ,/* jpeg */ +NOUVEAU_FDINFO_ENGINE_OFA ,/* optical flow */ +NOUVEAU_FDINFO_ENGINE_COUNT , +}; +#include "nouveau_fence.h" #include "nouveau_bios.h" #include "nouveau_sched.h"
@@ -114,6 +127,20 @@ struct nouveau_cli {struct work_struct work;struct list_head worker;struct mutex lock; + +/* Per-client engine busy-time accounting for DRM fdinfo. +* +* @engine_ns holds the accumulated busy time of retired jobs per +* engine; @jobs is the list of in-flight jobs, walked at fdinfo read +* time to additionally account currently-running work. Both are +* protected by @lock (a leaf spinlock taken from the job free path and +* from the fdinfo show callback) +*/ +struct { +spinlock_t lock; +struct list_head jobs; +u64 engine_ns[NOUVEAU_FDINFO_ENGINE_COUNT ]; + } fdinfo; };struct nouveau_cli_work {
drivers/gpu/drm/nouveau/nouveau_exec.c +3 -0
@@ -255,6 +255,9 @@ nouveau_exec_job_init(struct nouveau_exec_job **pjob,if (ret) goto err_free_pushs; +/* Account this job's busy time against the channel's engine in fdinfo */ + job->base.engine = job->chan->fdinfo_engine; +return 0 ; err_free_pushs:
drivers/gpu/drm/nouveau/nouveau_gem.c +16 -0
@@ -214,10 +214,26 @@ nouveau_gem_object_close(struct drm_gem_object *gem, struct drm_file *file_priv)ttm_bo_unreserve (&nvbo->bo); } +static enum drm_gem_object_status +nouveau_gem_object_status (struct drm_gem_object *gem) +{ +struct nouveau_bo *nvbo =nouveau_gem_object (gem); +enum drm_gem_object_status status =0 ; + +/* nouveau has no userspace madvise/purgeable concept, so only +* residency is reported +*/ +if (nvbo->bo.resource) + status |=DRM_GEM_OBJECT_RESIDENT ; + +return status; +} +const struct drm_gem_object_funcs nouveau_gem_object_funcs = { .free = nouveau_gem_object_del, .open = nouveau_gem_object_open, .close = nouveau_gem_object_close, + .status = nouveau_gem_object_status, .export = nouveau_gem_prime_export, .pin = nouveau_gem_prime_pin, .unpin = nouveau_gem_prime_unpin,
drivers/gpu/drm/nouveau/nouveau_sched.c +87 -0
117 lines not on this page · raw message
drivers/gpu/drm/nouveau/nouveau_sched.h +11 -0
@@ -56,6 +56,14 @@ struct nouveau_job {struct drm_file *file_priv;struct nouveau_cli *cli; +/* fdinfo per-engine busy-time accounting: @engine is the engine class +* this job runs on (NOUVEAU_FDINFO_ENGINE_COUNT == not accounted) +* @fdinfo_entry links the job into cli->fdinfo.jobs while it is in +* flight. +*/ +enum nouveau_fdinfo_engine engine; +struct list_head fdinfo_entry; +enum dma_resv_usage resv_usage;struct dma_fence *done_fence;
@@ -96,6 +104,9 @@ int nouveau_job_submit(struct nouveau_job *job);void nouveau_job_done (struct nouveau_job *job);void nouveau_job_free (struct nouveau_job *job); +struct drm_printer ; +void nouveau_sched_show_fdinfo (struct nouveau_cli *cli,struct drm_printer *p); +struct nouveau_sched {struct drm_gpu_scheduler base;struct drm_sched_entity entity;
Signature · 1 line
2.55.0
[email protected]
maintainer(just for other nouveau maintainers, e.g. danilo, I'm currently planning on looking at this during this week. Already started reviewing some of this, slightly underestimated how much I had to review :)
Quoted 162 lines · Mohamed Ahmed
On the GSP firmware, nouveau reports nothing about the GPU. The GSP owns
the sensors, so the legacy nvkm therm/clk/volt hwmon paths never run, and
monitoring tools have no data to read.GSP on later firmware does publish all of it through a stable interface.
It maintains a shared-memory region called "RM User Shared Data" (RUSD),
which the firmware fills with all the relevant sensor readings like power,
temperatures, clocks, and many others. Consuming it needs only two internal subdevice controls:INIT_USER_SHARED_DATAto register the buffer,
andSET_DATA_POLLto tell the GSP which data groups to poll and how often.This series makes nouveau a RUSD client and exposes the data through two
main surfaces:- hwmon, for the values that map onto standard channels: GPU and memory
temperature, GPU/board/VRAM power, power cap.- sysfs, under
/sys/class/drm/cardN/device/rusd/, for everything hwmon
has no channel type for: clocks, utilisation, pstate, throttle reason,
ECC counters, PCIe error counters, and everything exposed to hwmon as
well. One value per file according to sysfs convention.Polling is demand-driven. GSP polls a group only while a client is reading
it, and a group idles off after 10s after the last read. Polling costs
power, so nothing is polled unless someone is looking. A section that has
not been polled yet, or that the board does not support, reads - ENODATA.The sysfs interface is documented in
Documentation/ABI/testing/sysfs-driver-nouveau.While the original scope was RUSD support only, monitoring tools needed
two extra additions to complete the picture:- VRAM size and usage on sysfs (patch 5): since this series adds a sysfs
interface for nouveau, it's better to expose VRAM metrics there rather
than force monitoring apps to pull in libdrm for the GETPARAM memory
ioctls.- fdinfo (patch 6): nouveau implemented none at all, and monitoring apps
could not show per-process GPU and memory usage. It now reports per-client memory and per-engine busy time, accounted from the DRM
scheduler that the EXEC/VM_BIND path already uses.Limitations, caveats, and additional considerations or questions:
- RUSD needs r570 or newer GSP firmware; r535 does not have the needed
controls. Pre-GSP and r535 behavior is identical to what it was:
the
rusd/ group is not created, and hwmon keeps its current behavior.- This is all read-only telemetry. Clock, voltage, or power control is
through other interfaces out of scope of this series.- The sysfs interface exposed here should be stable and valid for nova
as well. RUSD is stable and only grows more fields with newer GSP firmware (e.g., fan telemetry gets added in r580), so it is possible
to keep the same interface as we use newer firmware or as we move to
nova and any potential considerations should be ironed out before this
gets merged and the interface gets frozen.- amdgpu offers a single binary blob with all the telemetry embedded in
addition to the sysfs sensor files. This series currently only exposes
sensor files, but it is possible to add a similar binary for a v2.
This mainly offers a more efficient way to read the telemetry as clients would read only a few files instead of reading all of them.- The last two patches don't depend on RUSD and work on every GPU. But
they are here because they complete the sensor telemetry story. I am
happy to split them into their own series if that is preferred.Userspace WIP work built on this sysfs surface exists in form of nouveau
backends for nvtop, LACT, and a NVK HUD:- nvtop: https://github.com/mohamexiety/nvtop/tree/nvtop-nouvtop
- LACT: https://github.com/mohamexiety/LACT/tree/lnouvct
- NVK HUD:
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39898None of these are merged yet and exist for testing only. Upstreaming will
begin when this series gets merged and the interface is stable.Mohamed Ahmed (6):
drm/nouveau/gsp: vendor the RUSD header drm/nouveau/gsp: add RUSD telemetry support drm/nouveau: add GSP hwmon support
drm/nouveau: expose RUSD telemetry via sysfs drm/nouveau: expose global VRAM size and usage via sysfs drm/nouveau: expose per-client GPU usage via fdinfo.../ABI/testing/sysfs-driver-nouveau | 167 ++++++ MAINTAINERS | 1 + drivers/gpu/drm/nouveau/Kbuild | 1 +
.../gpu/drm/nouveau/include/nvkm/subdev/gsp.h| 33 ++ .../drm/nouveau/include/nvkm/subdev/rusd.h | 114 ++++ .../gpu/drm/nouveau/include/nvrm/nvtypes.h | 3 + drivers/gpu/drm/nouveau/nouveau_abi16.c | 16 + drivers/gpu/drm/nouveau/nouveau_chan.h | 2 + drivers/gpu/drm/nouveau/nouveau_drm.c | 22 + drivers/gpu/drm/nouveau/nouveau_drv.h | 29 + drivers/gpu/drm/nouveau/nouveau_exec.c | 3 + drivers/gpu/drm/nouveau/nouveau_gem.c | 16 +drivers/gpu/drm/nouveau/nouveau_hwmon.c | 375 ++++++++++--- drivers/gpu/drm/nouveau/nouveau_sched.c | 87 +++ drivers/gpu/drm/nouveau/nouveau_sched.h | 11 + drivers/gpu/drm/nouveau/nouveau_sysfs.c | 311 ++++++++++ drivers/gpu/drm/nouveau/nouveau_sysfs.h | 10 +.../drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c | 26 + .../drm/nouveau/nvkm/subdev/gsp/rm/r535/rm.c | 1 + .../nouveau/nvkm/subdev/gsp/rm/r570/Kbuild | 1 + .../nvkm/subdev/gsp/rm/r570/nvrm/rusd.h | 303 ++++++++++ .../drm/nouveau/nvkm/subdev/gsp/rm/r570/rm.c | 1 + .../nouveau/nvkm/subdev/gsp/rm/r570/rusd.c | 531
++++++++++++++++++
.../gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h | 7 +24 files changed, 1990 insertions(+), 81 deletions(-)create mode 100644
Documentation/ABI/testing/sysfs-driver-nouveaucreate mode 100644drivers/gpu/drm/nouveau/include/nvkm/subdev/rusd.hcreate mode 100644drivers/gpu/drm/nouveau/nouveau_sysfs.ccreate mode 100644drivers/gpu/drm/nouveau/nouveau_sysfs.hcreate mode 100644drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/nvrm/rusd.hcreate mode 100644drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c
Quoted 3 lines · Mohamed Ahmed
A section that has
not been polled yet, or that the board does not support, reads-ENODATA.
Per hwmon/sysfs-interface.rst: "All entries (except name) are optional, and should only be created in a given driver if the chip has the feature."
It feels really weird to have a bunch of things there that just give an error code when reading. Does anything else use this pattern?
Quoted 2 lines
- The sysfs interface exposed here should be stable and valid for
nova as well.
Agreed. Please allow a bit of time for us to review the uAPI for Nova and future GSP versions.
Quoted 3 lines
RUSD is stable and only grows more fields with newer GSP firmware
(e.g., fan telemetry gets added in r580), so it is possible to keep
the same interface as we use newer firmware
Don't assume this. Work is underway to significantly rework the RUSD layout to make it extensibe in ABI-compatible ways, but there will be a single large ABI break compared to 570. This will happen when we add RUSD support to Nova, so it's some months out still.
Quoted 9 lines
- amdgpu offers a single binary blob with all the telemetry
embedded in
addition to the sysfs sensor files. This series currently only
exposes
sensor files, but it is possible to add a similar binary for a
v2.
This mainly offers a more efficient way to read the telemetry as clients would read only a few files instead of reading all of
them.
IIUC the reason amdgpu does that is so you can take a self-consistent atomic snapshot of all the telemetry readings. That's just not how RUSD works, so we don't need/want it.
We don't want to expose binary RUSD to userspace while it is unstable. Once it does become stable, the way this was meant to be exposed is to allow userspace to RO mmap the buffer and read the telemetry directly, with no syscall overhead. But I'm kind of loathe to do that even with the new format as it will require some parsing and that's easy to get wrong on the userspace side and still work in a given version, then break with an update.
We can revisit this when ABI-stable RUSD comes, and then maybe have a reference librusd that does the parsing.
Quoted 6 lines · Milos Tijanic
Quoted 3 lines · Mohamed Ahmed
A section that has
not been polled yet, or that the board does not support, reads-ENODATA.
Quoted 7 lines
Per
hwmon/sysfs-interface.rst: "All entries (except name) are optional, and should only be created in a given driver if the chip has the feature."It feels really weird to have a bunch of things there that just give an error code when reading. Does anything else use this pattern?
The power_supply sysfs group does something similar to this but this was something I was not sure how to handle and wanted more feedback on in general. I went with this with the logic that it would be similar to nvidia-smi's "N/A". The other alternative was going for something like hwmon where we detect if it's supported early on by probing everything and latching onto them and then unsupported stuff is simply dropped, but that approach felt not suitable because of the polling nature (if for some reason we couldn't latch onto something, it wouldn't show even if it were supported).
Another alternative now that I think about it more is that we could block for up to 1 poll interval if we get an invalid read, which would eliminate the transient errors completely. This would leave the unsupported items and in that case we could return -EOPNOTSUPP instead which makes more sense than -ENODATA for everything. It does still have the tradeoff with missing items having error files though, so I am not sure.
Quoted 6 lines
Quoted 2 lines
- The sysfs interface exposed here should be stable and valid for
nova as well.Agreed. Please allow a bit of time for us to review the uAPI for Nova and future GSP versions.
Quoted 9 lines
Quoted 3 lines
RUSD is stable and only grows more fields with newer GSP firmware
(e.g., fan telemetry gets added in r580), so it is possible to keep
the same interface as we use newer firmwareDon't assume this. Work is underway to significantly rework the RUSD layout to make it extensibe in ABI-compatible ways, but there will be a single large ABI break compared to 570. This will happen when we add RUSD support to Nova, so it's some months out still.
Understood, thanks! The FW ABI is fairly insulated from everything else in my design so the upcoming compatibility break shouldn't be an issue if nouveau upgrades to that firmware and the main concern is in the exposed uAPI.
Quoted 22 lines
Quoted 9 lines
- amdgpu offers a single binary blob with all the telemetry
embedded in
addition to the sysfs sensor files. This series currently only
exposes
sensor files, but it is possible to add a similar binary for a
v2.
This mainly offers a more efficient way to read the telemetry as clients would read only a few files instead of reading all of
them.IIUC the reason amdgpu does that is so you can take a self-consistent atomic snapshot of all the telemetry readings. That's just not how RUSD works, so we don't need/want it.
We don't want to expose binary RUSD to userspace while it is unstable. Once it does become stable, the way this was meant to be exposed is to allow userspace to RO mmap the buffer and read the telemetry directly, with no syscall overhead. But I'm kind of loathe to do that even with the new format as it will require some parsing and that's easy to get wrong on the userspace side and still work in a given version, then break with an update.
Quoted 4 lines
We can revisit this when ABI-stable RUSD comes, and then maybe have a reference librusd that does the parsing.
Noted, thanks! My original idea was 4 binaries (1 for each poll domain) but your idea is strictly better, so waiting till then and revisiting this is a better idea.
With the various nits addressed or responded to, for the whole series:
(I assume with you moving stuff into nvkm I might need to re-review later, but that's fine with me)
Quoted 162 lines · Mohamed Ahmed
On the GSP firmware, nouveau reports nothing about the GPU. The GSP owns
the sensors, so the legacy nvkm therm/clk/volt hwmon paths never run, and
monitoring tools have no data to read.GSP on later firmware does publish all of it through a stable interface.
It maintains a shared-memory region called "RM User Shared Data" (RUSD),
which the firmware fills with all the relevant sensor readings like power,
temperatures, clocks, and many others. Consuming it needs only two internal subdevice controls:INIT_USER_SHARED_DATAto register the buffer,
andSET_DATA_POLLto tell the GSP which data groups to poll and how often.This series makes nouveau a RUSD client and exposes the data through two
main surfaces:- hwmon, for the values that map onto standard channels: GPU and memory
temperature, GPU/board/VRAM power, power cap.- sysfs, under
/sys/class/drm/cardN/device/rusd/, for everything hwmon
has no channel type for: clocks, utilisation, pstate, throttle reason,
ECC counters, PCIe error counters, and everything exposed to hwmon as
well. One value per file according to sysfs convention.Polling is demand-driven. GSP polls a group only while a client is reading
it, and a group idles off after 10s after the last read. Polling costs
power, so nothing is polled unless someone is looking. A section that has
not been polled yet, or that the board does not support, reads - ENODATA.The sysfs interface is documented in
Documentation/ABI/testing/sysfs-driver-nouveau.While the original scope was RUSD support only, monitoring tools needed
two extra additions to complete the picture:- VRAM size and usage on sysfs (patch 5): since this series adds a sysfs
interface for nouveau, it's better to expose VRAM metrics there rather
than force monitoring apps to pull in libdrm for the GETPARAM memory
ioctls.- fdinfo (patch 6): nouveau implemented none at all, and monitoring apps
could not show per-process GPU and memory usage. It now reports per-client memory and per-engine busy time, accounted from the DRM
scheduler that the EXEC/VM_BIND path already uses.Limitations, caveats, and additional considerations or questions:
- RUSD needs r570 or newer GSP firmware; r535 does not have the needed
controls. Pre-GSP and r535 behavior is identical to what it was:
the
rusd/ group is not created, and hwmon keeps its current behavior.- This is all read-only telemetry. Clock, voltage, or power control is
through other interfaces out of scope of this series.- The sysfs interface exposed here should be stable and valid for nova
as well. RUSD is stable and only grows more fields with newer GSP firmware (e.g., fan telemetry gets added in r580), so it is possible
to keep the same interface as we use newer firmware or as we move to
nova and any potential considerations should be ironed out before this
gets merged and the interface gets frozen.- amdgpu offers a single binary blob with all the telemetry embedded in
addition to the sysfs sensor files. This series currently only exposes
sensor files, but it is possible to add a similar binary for a v2.
This mainly offers a more efficient way to read the telemetry as clients would read only a few files instead of reading all of them.- The last two patches don't depend on RUSD and work on every GPU. But
they are here because they complete the sensor telemetry story. I am
happy to split them into their own series if that is preferred.Userspace WIP work built on this sysfs surface exists in form of nouveau
backends for nvtop, LACT, and a NVK HUD:- nvtop: https://github.com/mohamexiety/nvtop/tree/nvtop-nouvtop
- LACT: https://github.com/mohamexiety/LACT/tree/lnouvct
- NVK HUD:
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39898None of these are merged yet and exist for testing only. Upstreaming will
begin when this series gets merged and the interface is stable.Mohamed Ahmed (6):
drm/nouveau/gsp: vendor the RUSD header drm/nouveau/gsp: add RUSD telemetry support drm/nouveau: add GSP hwmon support
drm/nouveau: expose RUSD telemetry via sysfs drm/nouveau: expose global VRAM size and usage via sysfs drm/nouveau: expose per-client GPU usage via fdinfo.../ABI/testing/sysfs-driver-nouveau | 167 ++++++ MAINTAINERS | 1 + drivers/gpu/drm/nouveau/Kbuild | 1 +
.../gpu/drm/nouveau/include/nvkm/subdev/gsp.h| 33 ++ .../drm/nouveau/include/nvkm/subdev/rusd.h | 114 ++++ .../gpu/drm/nouveau/include/nvrm/nvtypes.h | 3 + drivers/gpu/drm/nouveau/nouveau_abi16.c | 16 + drivers/gpu/drm/nouveau/nouveau_chan.h | 2 + drivers/gpu/drm/nouveau/nouveau_drm.c | 22 + drivers/gpu/drm/nouveau/nouveau_drv.h | 29 + drivers/gpu/drm/nouveau/nouveau_exec.c | 3 + drivers/gpu/drm/nouveau/nouveau_gem.c | 16 +drivers/gpu/drm/nouveau/nouveau_hwmon.c | 375 ++++++++++--- drivers/gpu/drm/nouveau/nouveau_sched.c | 87 +++ drivers/gpu/drm/nouveau/nouveau_sched.h | 11 + drivers/gpu/drm/nouveau/nouveau_sysfs.c | 311 ++++++++++ drivers/gpu/drm/nouveau/nouveau_sysfs.h | 10 +.../drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c | 26 + .../drm/nouveau/nvkm/subdev/gsp/rm/r535/rm.c | 1 + .../nouveau/nvkm/subdev/gsp/rm/r570/Kbuild | 1 + .../nvkm/subdev/gsp/rm/r570/nvrm/rusd.h | 303 ++++++++++ .../drm/nouveau/nvkm/subdev/gsp/rm/r570/rm.c | 1 + .../nouveau/nvkm/subdev/gsp/rm/r570/rusd.c | 531
++++++++++++++++++
.../gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h | 7 +24 files changed, 1990 insertions(+), 81 deletions(-)create mode 100644
Documentation/ABI/testing/sysfs-driver-nouveaucreate mode 100644drivers/gpu/drm/nouveau/include/nvkm/subdev/rusd.hcreate mode 100644drivers/gpu/drm/nouveau/nouveau_sysfs.ccreate mode 100644drivers/gpu/drm/nouveau/nouveau_sysfs.hcreate mode 100644drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/nvrm/rusd.hcreate mode 100644drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c
Quoted 8 lines · On Wed, Jul 22, 2026 at 12:40 AM <[email protected]> wrote:
With the various nits addressed or responded to, for the whole series:
Reviewed-by Lyude Paul <[email protected]>(I assume with you moving stuff into nvkm I might need to re-review later, but that's fine with me)
Thanks a lot! All your suggestions are fine by me so I'll incorporate them, do the shifting around to prevent the errors on unsupported metrics/cold reads from reaching userspace, and push a V2.
Quoted 164 lines · Mohamed Ahmed
Quoted 162 lines
On the GSP firmware, nouveau reports nothing about the GPU. The GSP owns
the sensors, so the legacy nvkm therm/clk/volt hwmon paths never run, and
monitoring tools have no data to read.GSP on later firmware does publish all of it through a stable interface.
It maintains a shared-memory region called "RM User Shared Data" (RUSD),
which the firmware fills with all the relevant sensor readings like power,
temperatures, clocks, and many others. Consuming it needs only two internal subdevice controls:INIT_USER_SHARED_DATAto register the buffer,
andSET_DATA_POLLto tell the GSP which data groups to poll and how often.This series makes nouveau a RUSD client and exposes the data through two
main surfaces:- hwmon, for the values that map onto standard channels: GPU and
memory
temperature, GPU/board/VRAM power, power cap.- sysfs, under
/sys/class/drm/cardN/device/rusd/, for everything
hwmon
has no channel type for: clocks, utilisation, pstate, throttle
reason,
ECC counters, PCIe error counters, and everything exposed to
hwmon as
well. One value per file according to sysfs convention.Polling is demand-driven. GSP polls a group only while a client is reading
it, and a group idles off after 10s after the last read. Polling costs
power, so nothing is polled unless someone is looking. A section that has
not been polled yet, or that the board does not support, reads - ENODATA.The sysfs interface is documented in
Documentation/ABI/testing/sysfs-driver-nouveau.While the original scope was RUSD support only, monitoring tools needed
two extra additions to complete the picture:- VRAM size and usage on sysfs (patch 5): since this series adds a
sysfs
interface for nouveau, it's better to expose VRAM metrics there
rather
than force monitoring apps to pull in libdrm for the GETPARAM
memory
ioctls.- fdinfo (patch 6): nouveau implemented none at all, and monitoring
apps
could not show per-process GPU and memory usage. It now reports per-client memory and per-engine busy time, accounted from the
DRM
scheduler that the EXEC/VM_BIND path already uses.Limitations, caveats, and additional considerations or questions:
- RUSD needs r570 or newer GSP firmware; r535 does not have the
needed
controls. Pre-GSP and r535 behavior is identical to what it was:
the
rusd/ group is not created, and hwmon keeps its current behavior.- This is all read-only telemetry. Clock, voltage, or power control
is
through other interfaces out of scope of this series.- The sysfs interface exposed here should be stable and valid for
nova
as well. RUSD is stable and only grows more fields with newer GSP firmware (e.g., fan telemetry gets added in r580), so it is
possible
to keep the same interface as we use newer firmware or as we move
to
nova and any potential considerations should be ironed out before
this
gets merged and the interface gets frozen.- amdgpu offers a single binary blob with all the telemetry
embedded in
addition to the sysfs sensor files. This series currently only
exposes
sensor files, but it is possible to add a similar binary for a
v2.
This mainly offers a more efficient way to read the telemetry as clients would read only a few files instead of reading all of
them.- The last two patches don't depend on RUSD and work on every GPU.
But
they are here because they complete the sensor telemetry story. I
am
happy to split them into their own series if that is preferred.Userspace WIP work built on this sysfs surface exists in form of nouveau
backends for nvtop, LACT, and a NVK HUD:- nvtop: https://github.com/mohamexiety/nvtop/tree/nvtop-nouvtop
- LACT: https://github.com/mohamexiety/LACT/tree/lnouvct
- NVK HUD:
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39898None of these are merged yet and exist for testing only. Upstreaming will
begin when this series gets merged and the interface is stable.Mohamed Ahmed (6):
drm/nouveau/gsp: vendor the RUSD header drm/nouveau/gsp: add RUSD telemetry support drm/nouveau: add GSP hwmon support
drm/nouveau: expose RUSD telemetry via sysfs drm/nouveau: expose global VRAM size and usage via sysfs drm/nouveau: expose per-client GPU usage via fdinfo.../ABI/testing/sysfs-driver-nouveau | 167 ++++++ MAINTAINERS | 1 + drivers/gpu/drm/nouveau/Kbuild | 1 + .../gpu/drm/nouveau/include/nvkm/subdev/gsp.h | 33 ++ .../drm/nouveau/include/nvkm/subdev/rusd.h | 114 ++++ .../gpu/drm/nouveau/include/nvrm/nvtypes.h | 3 + drivers/gpu/drm/nouveau/nouveau_abi16.c | 16 + drivers/gpu/drm/nouveau/nouveau_chan.h | 2 + drivers/gpu/drm/nouveau/nouveau_drm.c | 22 + drivers/gpu/drm/nouveau/nouveau_drv.h | 29 + drivers/gpu/drm/nouveau/nouveau_exec.c | 3 + drivers/gpu/drm/nouveau/nouveau_gem.c | 16 + drivers/gpu/drm/nouveau/nouveau_hwmon.c | 375 ++++++++++--- drivers/gpu/drm/nouveau/nouveau_sched.c | 87 +++ drivers/gpu/drm/nouveau/nouveau_sched.h | 11 + drivers/gpu/drm/nouveau/nouveau_sysfs.c | 311 ++++++++++ drivers/gpu/drm/nouveau/nouveau_sysfs.h | 10 + .../drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c | 26 + .../drm/nouveau/nvkm/subdev/gsp/rm/r535/rm.c | 1 + .../nouveau/nvkm/subdev/gsp/rm/r570/Kbuild | 1 + .../nvkm/subdev/gsp/rm/r570/nvrm/rusd.h | 303 ++++++++++ .../drm/nouveau/nvkm/subdev/gsp/rm/r570/rm.c | 1 + .../nouveau/nvkm/subdev/gsp/rm/r570/rusd.c | 531 ++++++++++++++++++ .../gpu/drm/nouveau/nvkm/subdev/gsp/rm/rm.h | 7 + 24 files changed, 1990 insertions(+), 81 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-driver-nouveau create mode 100644 drivers/gpu/drm/nouveau/include/nvkm/subdev/rusd.h create mode 100644 drivers/gpu/drm/nouveau/nouveau_sysfs.c create mode 100644 drivers/gpu/drm/nouveau/nouveau_sysfs.h create mode 100644 drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/nvrm/rusd.h create mode 100644
drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r570/rusd.c