Skip to content

Commit bb286fd

Browse files
authored
Merge pull request #12 from utajum/fix/gpu-safety-guards-boot-service
Add GPU mode switching with safety guards for NVIDIA and AMD dGPUs (must run install script)
2 parents 8238a21 + 5cb21aa commit bb286fd

16 files changed

+2870
-359
lines changed

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,55 @@ Pull requests and feature requests are welcome!
7878

7979
---
8080

81+
## `░▒▓█ ╔══[ GPU MODE SWITCHING ]══╗ █▓▒░`
82+
83+
G-Helper manages the ASUS dGPU (discrete GPU) power state and MUX switch through four modes:
84+
85+
```
86+
╔══[ MODES ]═════════════════════════════════════════════════════╗
87+
║ ║
88+
║ Eco dGPU powered off (dgpu_disable=1) ║
89+
║ Maximum battery life, iGPU only ║
90+
║ ║
91+
║ Standard Hybrid mode (dgpu_disable=0, MUX=iGPU) ║
92+
║ dGPU available for offloading, iGPU drives display ║
93+
║ ║
94+
║ Optimized Auto-switch based on power source ║
95+
║ Eco on battery, Standard on AC power ║
96+
║ ║
97+
║ Ultimate dGPU direct (dgpu_disable=0, MUX=dGPU) ║
98+
║ Best performance — dGPU drives display directly ║
99+
║ ║
100+
╚═════════════════════════════════════════════════════════════════╝
101+
```
102+
103+
### `╠══[ REBOOT REQUIREMENTS ]══╣`
104+
105+
| Transition | Reboot? | Why |
106+
|------------|---------|-----|
107+
| Eco ↔ Standard | Usually no | May need reboot if GPU driver is active |
108+
| Any → Ultimate | **Yes** | MUX switch is latched, takes effect on reboot |
109+
| Ultimate → Any | **Yes** | MUX switch back to iGPU requires reboot |
110+
111+
When a reboot is required, G-Helper shows a notification and the pending mode appears in the UI. You can change your mind before rebooting — clicking a different mode cancels the pending change.
112+
113+
### `╠══[ DRIVER BLOCKING DIALOG ]══╣`
114+
115+
Switching to Eco while the dGPU driver is active shows a dialog with three options:
116+
117+
- **Switch Now** — attempts to unload the dGPU driver (requires admin password)
118+
- **After Reboot** — saves the mode for next boot (dGPU driver is blocked from loading via modprobe rules)
119+
- **Cancel** — keeps the current mode
120+
121+
### `╠══[ KNOWN LIMITATIONS ]══╣`
122+
123+
- **Ultimate → Eco** may require 2 reboots (MUX must change first, then Eco can apply)
124+
- **MUX switch support** varies by model — requires `gpu_mux_mode` sysfs attribute
125+
- **Eco mode** may require a reboot if the dGPU driver holds a DRM file descriptor
126+
- On boot, a systemd oneshot service applies pending GPU mode changes before the display manager starts
127+
128+
---
129+
81130
## `░▒▓█ ╔══[ SYSTEM REQUIREMENTS ]══╗ █▓▒░`
82131

83132
```

install/90-ghelper.conf

Lines changed: 0 additions & 69 deletions
This file was deleted.

install/ghelper-gpu-boot.service

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[Unit]
2+
Description=G-Helper GPU Mode Boot Application
3+
# Must run after sysfs is populated (asus-nb-wmi or asus-armoury module loaded)
4+
After=local-fs.target systemd-modules-load.service systemd-udevd.service
5+
# Must run BEFORE display manager starts — critical ordering
6+
# Without this, dGPU driver loads before dgpu_disable=1 is written
7+
Before=display-manager.service
8+
# Must run before GPU services try to initialize
9+
Before=nvidia-powerd.service nvidia-persistenced.service
10+
# Run on ASUS hardware with either legacy (asus-nb-wmi) or modern (asus-armoury) module.
11+
# ConditionPathExists uses pipe (|) prefix — ANY match triggers the unit.
12+
# Without pipe prefix, systemd requires ALL conditions to pass.
13+
ConditionPathExists=|/sys/bus/platform/devices/asus-nb-wmi
14+
ConditionPathExists=|/sys/class/firmware-attributes/asus-armoury
15+
# NOTE: No ConditionPathExists for trigger file — the boot script's MUX=0
16+
# safety check must run on EVERY boot, even without a pending mode change.
17+
18+
[Service]
19+
Type=oneshot
20+
ExecStart=/usr/local/lib/ghelper/ghelper-gpu-boot.sh
21+
RemainAfterExit=no
22+
# dgpu_disable write typically takes <5s when dGPU driver is blocked
23+
# but can theoretically block longer. 30s safety valve.
24+
TimeoutStartSec=30
25+
StandardOutput=journal
26+
StandardError=journal
27+
28+
[Install]
29+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)