Skip to content

Instantly share code, notes, and snippets.

@mrdev023
Created July 1, 2022 19:20
Show Gist options
  • Save mrdev023/59f9ef9b40101745a645ce875697b79d to your computer and use it in GitHub Desktop.
Save mrdev023/59f9ef9b40101745a645ce875697b79d to your computer and use it in GitHub Desktop.
#!/bin/bash
function enable_core() {
bash -c "echo 1 > \"/sys/devices/system/cpu/cpu$1/online\""
echo "Set Core $1 : enabled"
}
function disable_core() {
bash -c "echo 0 > \"/sys/devices/system/cpu/cpu$1/online\""
echo "Set Core $1 : disabled"
}
function enable_game_mode() {
if [ "$UID" != "0" ]; then
echo "Run this script as root"
else
numberOfCores=$(nproc --all)
for ((x=0; x < $numberOfCores; x++)); do
if [ $(( $x % 2 )) -eq 0 ]; then
enable_core $x
else
disable_core $x
fi
done
fi
}
function disable_game_mode() {
if [ "$UID" != "0" ]; then
echo "Run this script as root"
else
numberOfCores=$(nproc --all)
for ((x=0; x < $numberOfCores; x++)); do
enable_core $x
done
fi
}
if [ "$1" == "enable" ]; then
enable_game_mode
else
disable_game_mode
fi
@mrdev023
Copy link
Author

mrdev023 commented Jul 1, 2022

If you want add it with gamemode

#!/bin/bash

function enable_core() {
    bash -c "echo 1 > \"/sys/devices/system/cpu/cpu$1/online\""
    echo "Set Core $1 : enabled"
}

function disable_core() {
    bash -c "echo 0 > \"/sys/devices/system/cpu/cpu$1/online\""
    echo "Set Core $1 : disabled"
}

function enable_game_mode() {
    numberOfCores=$(nproc --all)
    for ((x=0; x < $numberOfCores; x++)); do
        if [ $(( $x % 2 )) -eq 0 ]; then
            enable_core $x
        else
            disable_core $x
        fi
    done
}

function disable_game_mode() {
    numberOfCores=$(nproc --all)
    for ((x=0; x < $numberOfCores; x++)); do
        enable_core $x
    done
}

if [ "$UID" != "0" ]; then
    echo "Run this script as root"
    pkexec $0 $1

    if [ "$1" == "enable" ]; then
        notify-send "GameMode started"
    else
        notify-send "GameMode stopped"
    fi
else
    if [ "$1" == "enable" ]; then
        enable_game_mode
    else
        disable_game_mode
    fi
fi

gamemode.ini

[custom]
; Custom scripts (executed using the shell) when gamemode starts and ends
start=/home/me/bin/configure_sc.sh enable
;    /home/me/bin/stop_ethmining.sh

end=/home/me/bin/configure_sc.sh disable
;    /home/me/bin/start_ethmining.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment