From 786dc59d0e6937aa76f5cecc16dec49261c8a625 Mon Sep 17 00:00:00 2001 From: Spacedio Date: Fri, 17 Apr 2026 22:45:53 -0400 Subject: Optimization of the dGPU with a script to specifically turn it off. --- bashrc/.bashrc | 3 + dgpu-toggle/usr/bin/gpu-toggle | 87 ++++++++++++++++++++++++++ i3/.config/i3/config | 5 -- nvim/.config/nvim/lazy-lock.json | 8 +-- nvim/.config/nvim/lua/plugins/one-liners.lua | 2 +- polybar/.config/polybar/config.ini | 19 ++++++ polybar/.config/polybar/scripts/dgpu-status.sh | 15 +++++ 7 files changed, 129 insertions(+), 10 deletions(-) create mode 100755 dgpu-toggle/usr/bin/gpu-toggle create mode 100755 polybar/.config/polybar/scripts/dgpu-status.sh diff --git a/bashrc/.bashrc b/bashrc/.bashrc index 0959a04..12ab075 100644 --- a/bashrc/.bashrc +++ b/bashrc/.bashrc @@ -14,10 +14,13 @@ alias poweroff='sudo poweroff' alias reboot='sudo reboot' alias ssh-kleingelt='ssh spacedio@thernusen.net' alias ssh-git='ssh git.thernusen.net -p 23231' +alias ssh-eligor='ssh closetcat@eligor.home.arpa' #EXPORTS export PATH="$HOME/.local/bin:$PATH" export EDITOR='nvim' +export GTK_THEME=Adwaita:dark +export ADW_DISABLE_PORTAL=1 #OTHER PS1='[\u@\h \W]\$ ' diff --git a/dgpu-toggle/usr/bin/gpu-toggle b/dgpu-toggle/usr/bin/gpu-toggle new file mode 100755 index 0000000..4e1ddd2 --- /dev/null +++ b/dgpu-toggle/usr/bin/gpu-toggle @@ -0,0 +1,87 @@ +#!/bin/bash + +# ------------------------------------------------------------------------- +# GPU-SWITCH: Discrete Graphics Power & Bus Management +# Target: Razer Blade Stealth 13 (Late 2019) | Void Linux +# ------------------------------------------------------------------------- + +# Configuration: Static PCI Identifier for Turing dGPU +# We use a static ID because the device disappears from the bus when disabled. +DEVICE_ID="57:00.0" +PCI_PATH="/sys/bus/pci/devices/0000:$DEVICE_ID" +REQUIRED_MODULES=("nvidia_drm" "nvidia_modeset" "nvidia_uvm" "nvidia") + +if [[ $EUID -ne 0 ]]; then + echo "[ERROR] Elevated privileges required. Please execute with sudo." + exit 1 +fi + +check_status() { + echo "--- System Graphics Status ---" + if [ -d "$PCI_PATH" ]; then + echo "Hardware State: [ ONLINE ] at $DEVICE_ID" + if lsmod | grep -q "nvidia"; then + echo "Driver State: [ LOADED ]" + else + echo "Driver State: [ UNLOADED ]" + fi + else + echo "Hardware State: [ OFFLINE ] (Device removed from PCI bus)" + echo "Driver State: [ UNLOADED ]" + fi + echo "------------------------------" +} + +disable_gpu() { + echo "[INFO] Initializing dGPU shutdown sequence..." + + # 1. Unload Kernel Modules + echo "[STEP 1/2] Terminating NVIDIA kernel modules..." + for mod in "${REQUIRED_MODULES[@]}"; do + if lsmod | grep -q "$mod"; then + modprobe -r "$mod" 2>/dev/null + if [ $? -ne 0 ]; then + echo "[WARN] Module $mod is currently in use. Ensure Xorg/i3 is not using the dGPU." + fi + fi + done + + # 2. Physical Bus Removal + if [ -d "$PCI_PATH" ]; then + echo "[STEP 2/2] Detaching device from PCI bus..." + echo 1 > "$PCI_PATH/remove" + echo "[SUCCESS] dGPU has been isolated and powered down." + else + echo "[SKIP] Device is already detached from the bus." + fi +} + +enable_gpu() { + echo "[INFO] Initializing dGPU activation sequence..." + + # 1. Trigger PCI Rescan + echo "[STEP 1/2] Scanning PCI bridge for hardware changes..." + echo 1 > /sys/bus/pci/rescan + + # Allow firmware-level handshake + sleep 2 + + # 2. Validate and Load Drivers + if [ -d "$PCI_PATH" ]; then + echo "[STEP 2/2] Hardware detected at $DEVICE_ID. Loading modules..." + for mod in "nvidia" "nvidia_uvm" "nvidia_modeset" "nvidia_drm"; do + modprobe "$mod" + done + echo "[SUCCESS] dGPU is now online and available for Prime Offload." + else + echo "[FATAL] Hardware failed to initialize at $DEVICE_ID." + echo "[DEBUG] Check 'dmesg | tail' for PCI link training errors." + fi +} + +case "$1" in + on) enable_gpu ;; + off) disable_gpu ;; + status) check_status ;; + *) echo "Usage: gpu-switch {on|off|status}" ;; +esac diff --git a/i3/.config/i3/config b/i3/.config/i3/config index 6d1ded8..8472507 100644 --- a/i3/.config/i3/config +++ b/i3/.config/i3/config @@ -226,8 +226,6 @@ bindsym $mod+Shift+r restart #bindsym $mod+Shift+e exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -B 'Yes, exit i3' 'i3-msg exit'" - - # Define the menu labels set $sysmenu System: (l)ock, (e)xit i3, (s)uspend, (r)eboot, (Shift+s)hutdown @@ -251,9 +249,6 @@ mode "$sysmenu" { # Bind it to a key - replacing the default exit behavior bindsym $mod+Shift+e mode "$sysmenu" - - - # resize window (you can also use the mouse for that) mode "resize" { # These bindings trigger as soon as you enter the resize mode diff --git a/nvim/.config/nvim/lazy-lock.json b/nvim/.config/nvim/lazy-lock.json index 834e455..506301b 100644 --- a/nvim/.config/nvim/lazy-lock.json +++ b/nvim/.config/nvim/lazy-lock.json @@ -1,12 +1,12 @@ { "lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" }, - "lualine.nvim": { "branch": "master", "commit": "f5d2a8570f8b736ddb9bb4be504355bcd6e15ec8" }, - "nvim-colorizer.lua": { "branch": "master", "commit": "a065833f35a3a7cc3ef137ac88b5381da2ba302e" }, + "lualine.nvim": { "branch": "master", "commit": "a905eeebc4e63fdc48b5135d3bf8aea5618fb21c" }, + "nvim-colorizer.lua": { "branch": "master", "commit": "5cfe7fffbd01e17b3c1e14af85d5febdef88bd8c" }, "nvim-highlight-colors": { "branch": "main", "commit": "e2cb22089cc2358b2b995c09578224f142de6039" }, "nvim-osc52": { "branch": "main", "commit": "04cfaba1865ae5c53b6f887c3ca7304973824fb2" }, "nvim-treesitter": { "branch": "master", "commit": "cf12346a3414fa1b06af75c79faebe7f76df080a" }, - "nvim-web-devicons": { "branch": "master", "commit": "6e76c5e47e957fbf080b1fdac165c66dbd2e7cfb" }, - "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, + "nvim-web-devicons": { "branch": "master", "commit": "c72328a5494b4502947a022fe69c0c47e53b6aa6" }, + "plenary.nvim": { "branch": "master", "commit": "74b06c6c75e4eeb3108ec01852001636d85a932b" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "6fea601bd2b694c6f2ae08a6c6fab14930c60e2c" }, "telescope.nvim": { "branch": "master", "commit": "5255aa27c422de944791318024167ad5d40aad20" }, "tokyonight.nvim": { "branch": "main", "commit": "cdc07ac78467a233fd62c493de29a17e0cf2b2b6" }, diff --git a/nvim/.config/nvim/lua/plugins/one-liners.lua b/nvim/.config/nvim/lua/plugins/one-liners.lua index fe240f1..c6c5ab2 100644 --- a/nvim/.config/nvim/lua/plugins/one-liners.lua +++ b/nvim/.config/nvim/lua/plugins/one-liners.lua @@ -2,7 +2,7 @@ return { { "tpope/vim-fugitive" }, { "ojroques/nvim-osc52" }, { - "norcalli/nvim-colorizer.lua", + "catgoose/nvim-colorizer.lua", config = function() require("colorizer").setup() end, diff --git a/polybar/.config/polybar/config.ini b/polybar/.config/polybar/config.ini index 5c35631..09656ec 100644 --- a/polybar/.config/polybar/config.ini +++ b/polybar/.config/polybar/config.ini @@ -120,6 +120,25 @@ format-prefix-foreground = ${colors.magenta} label = %gb_used% %percentage_used%% label-foreground = ${colors.foreground} +[module/gpu-status] +type = custom/script + +; Path to the helper script we just created +exec = ~/.config/polybar/scripts/dgpu-status.sh + +; Update interval in seconds +interval = 5 + +; Professional styling +format-prefix = "dGPU Status: " +format-padding = 1 +format-background = ${colors.background-alt} +format-foreground = ${colors.primary} + +; Optional: Left-click to open a terminal and toggle +; click-left = st -e sudo gpu-switch on +; click-right = st -e sudo gpu-switch off + ;[module/wlan] ;inherit = network-base ;interface-type = wireless diff --git a/polybar/.config/polybar/scripts/dgpu-status.sh b/polybar/.config/polybar/scripts/dgpu-status.sh new file mode 100755 index 0000000..257c744 --- /dev/null +++ b/polybar/.config/polybar/scripts/dgpu-status.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Path to the dGPU on the PCI bus +PCI_PATH="/sys/bus/pci/devices/0000:57:00.0" + +if [ -d "$PCI_PATH" ]; then + # Optional: Check if the driver is actually loaded + if lsmod | grep -q "nvidia"; then + echo "ON" # Icon for NVIDIA/GPU Active + else + echo "STBY" # Hardware present but driver unloaded + fi +else + echo "OFF" # GPU powered down and removed +fi -- cgit v1.2.3