Files
nvdriver/docs/GPU_NICE.md

5.2 KiB

GPU nice / renice & Interactive Desktop Priority

nvidia_rs automatically maps standard Linux process nice (-20..+19) and interactive desktop/compositor awareness onto NVIDIA GPU TSG (KEPLER_CHANNEL_GROUP_A, 0xa06c) scheduling and preemption controls—with zero application changes.

Quick Start

# 1. Standard Linux nice / renice works out of the box:
nice -n 19 blender -b scene.blend -a
renice -n 19 -p <pid>

# 2. Inspect active GPU processes, TSGs, interleave levels & timeslices:
tools/nv-nice

# 3. Launch or live-renice with nv-nice (Linux + GPU nice, or --gpu-only):
tools/nv-nice -n 19 blender -b scene.blend -a
tools/nv-nice --bg -p <pid>
tools/nv-nice --desktop --gpu-only -p <compositor_pid>
tools/nv-nice --auto -p <pid>

How It Works

1. Linux nice / renice Mapping (src/nvidia/src/gpu_nice.rs)

Every 0xa06c TSG (Graphics GR and Copy Engine CE) inherits the allocating process group leader's Linux nice value (sampled from group_leader on both allocation and live polling) and maps it monotonically onto hardware scheduling parameters:

Effective nice Class Interleave (0xa06c0107) Timeslice (0xa06c0103) Preemption Hint (0x20801210)
-20..-15 rt HIGH (2) 6000..8000 us WFI
-14..-5 desktop HIGH (2) 4000..5800 us (-5 = 4000 us) GFXP / CILP
-4..-1 (desktop boosted) desktop HIGH (2) 4000 us (non-desktop: 2400..3600 us) GFXP / CILP
0..+4 normal MEDIUM (1) 640..1024 us (0 = 1024 us) GFXP / CILP
+5..+14 bg LOW (0) 384..632 us (+10 = 512 us) GFXP / CILP + preempt on demote
+15..+19 idle LOW (0) 256..352 us (+19 = 256 us) GFXP / CILP + preempt on demote
  • Preemption hint (0x20801210): The preemption column is a policy hint, not a guaranteed hardware mode; the backend applies it only when the relevant channel or TSG has the required GFXP/CILP support and the backend issues the per-channel 0x20801210 control. A normal copy-engine (CE) TSG without a GR object (or a Pre-GSP local backend that does not issue 0x20801210) receives WFI.
  • Copy Engine (CE) protection: CE TSGs follow the same policy curve so bulk H2D/D2D/D2H transfers from nice +19 jobs run in short 256 us slices and cannot starve desktop compositor page flips.
  • Preemption on demotion: When a running process is demoted (lower interleave or shorter timeslice), NVA06C_CTRL_CMD_PREEMPT (0xa06c0105, non-blocking) is issued so the GPU yields immediately.
  • Live renice(1) / setpriority(2) tracking: nvidia_rs performs lazy sync on RM ioctls AND runs a lightweight 250 ms delayed_work scanner while any PID or TSG remains tracked (including override-only PIDs without a TSG; zero overhead when idle).

2. Desktop / Compositor Protection (gpu_desktop_boost=1)

Desktop boost (-5 floor, HIGH interleave, 4000 us for Linux nice -4..=+4) requires a trusted compositor eligibility signal—task->comm is never trusted on its own (since any unprivileged task can rename its own comm via prctl(PR_SET_NAME)), and is used only for /proc/driver/nvidia/gpu-prio display and as a non-authorizing filter for privileged processes:

  • A process holding CAP_SYS_NICE or CAP_SYS_ADMIN (in init_user_ns) whose comm matches the known compositor hint list (kwin_wayland, gnome-shell, mutter, Hyprland, sway, Xorg, Xwayland, gamescope, weston, niri, river, labwc, wayfire, picom, compiz, cage, cosmic-comp, or desktop_comm), OR that explicitly requests HIGH interleave (0xa06c0107/0xa06f0109), is automatically boosted to desktop.
  • An unprivileged compositor explicitly granted desktop trust by an administrator via /proc/driver/nvidia/gpu-prio (pid <PID> desktop) also receives desktop boost (and may request HIGH interleave) while gpu_desktop_boost=1 and nice <= +4. By contrast, numeric overrides such as pid <PID> -5 only set the GPU nice override to -5 without granting desktop eligibility.
  • Explicit user demotion (nice >= +5 or a gpu-prio override) always overrides desktop boost.

3. /proc/driver/nvidia/gpu-prio & Module Parameters

  • Module parameters (rmapi_node.c):
    • gpu_nice_auto=1 (default 1): automatic Linux nice tracking.
    • gpu_desktop_boost=1 (default 1): automatic desktop/compositor protection.
  • /proc/driver/nvidia/gpu-prio (0666 with Linux renice(1) permission checks):
    • Read: lists policy knobs, desktop comm hint list, and active GPU PIDs/TSGs.
    • Write commands:
      • pid <PID> <NICE|auto|desktop> — set GPU-only nice (-20..19), revert to auto, or grant desktop trust (CAP_SYS_NICE/CAP_SYS_ADMIN required for desktop, raising priority / lowering effective GPU nice, or other users' PIDs; owners may only lower priority / raise nice).
      • auto <0|1>, desktop_boost <0|1>, preempt <0|1> — toggle global policies (CAP_SYS_NICE/CAP_SYS_ADMIN).
      • desktop_comm add|del <NAME> — manage runtime desktop comm hint list (CAP_SYS_NICE/CAP_SYS_ADMIN).
      • sync — trigger immediate PID nice sync (CAP_SYS_NICE/CAP_SYS_ADMIN).