systemd-units where the cpu is in performance mode only when the DAW is running

Optimize your system for ultimate performance.

Moderators: MattKingUSA, khz

Post Reply
User avatar
tkna
Established Member
Posts: 13
Joined: Mon Oct 16, 2023 7:29 pm
Location: Tokyo
Has thanked: 6 times
Been thanked: 3 times

systemd-units where the cpu is in performance mode only when the DAW is running

Post by tkna »

I want to put the cpu into performance mode only when REAPER, renoise, etc. are running. I thought such a systemd-unit would be useful to increase battery life on laptops and reduce electricity costs on desktops, but I'm not sure how to write it. Has anyone done something like that?

If only REAPER was the target, I would just run something like the following. However, I'm having a bit of trouble figuring out if different multiple processes are targeted.

I think there are others here besides me who would like something like this. I'd appreciate your wisdom.

Code: Select all

#!/bin/bash

sudo cpupower frequency-set -g performance
reaper
sudo cpupower frequency-set -g powersave
slangbein
Established Member
Posts: 13
Joined: Wed Dec 01, 2021 7:46 pm
Been thanked: 2 times

Re: systemd-units where the cpu is in performance mode only when the DAW is running

Post by slangbein »

it is exactly how i do it; just not with a systemd unit, but every other minute from crontab. and i disable smt for reaper as well

Code: Select all

if ps -C reaper > /dev/null; then
cpupower frequency-set -g performance
	if ! igrep off /sys/devices/system/cpu/smt/control; then
	echo off > /sys/devices/system/cpu/smt/control
	/usr/bin/printf "%s %s\n" "$NOW" "Set CPU SMT on 4 real cores for Reaper" >> "$LOGFILE"
	fi
else
echo "Reaper is not running"
fi
# on battery
STATUS=$( cat /sys/class/power_supply/BAT0/status )
if [[ "$STATUS" == "Discharging" ]]; then
cpupower frequency-set -g powersave
fi
User avatar
tkna
Established Member
Posts: 13
Joined: Mon Oct 16, 2023 7:29 pm
Location: Tokyo
Has thanked: 6 times
Been thanked: 3 times

Re: systemd-units where the cpu is in performance mode only when the DAW is running

Post by tkna »

You have made this possible for me.
In my sway environment, changing smt crashes the status bar (waybar), so I did not change the smt setting.
@slangbein Thanks kindly.

/root/.local/bin/cpupower-performance-app.sh

Code: Select all

#!/bin/bash

performance_app="$*"

if ps -C "$performance_app" > /dev/null ; then
    cpupower frequency-info | grep '"performance"' > /dev/null ||
    cpupower frequency-set -g performance
else
    cpupower frequency-info | grep '"powersave"' > /dev/null ||
    cpupower frequency-set -g powersave
fi

/etc/systemd/system/cpupower-performance-app.service

Code: Select all

[Unit]
Description=%n

[Service]
Type=oneshot
ExecStart=/bin/bash /root/.local/bin/cpupower-performance-app.sh reaper,renoise,pd

/etc/systemd/system/cpupower-performance-app.timer

Code: Select all

[Unit]
Description=%n

[Timer]
OnCalendar=minutely

[Install]
WantedBy=timers.target

Code: Select all

# grep cpupower /etc/sudoers.d/wheel
%wheel ALL=(ALL:ALL) NOPASSWD: /usr/bin/cpupower
#
# systemctl enable --now cpupower-performance-app.timer
Created symlink /etc/systemd/system/timers.target.wants/cpupower-performance-app.timer → /etc/systemd/system/cpupower-performance-app.timer.
#

When reaper is started, it is now in performance mode immediately, without waiting for timer to start.

~/.local/bin/reaper-performance.sh

Code: Select all

#!/bin/bash
sudo cpupower frequency-set -g performance
reaper
Post Reply