One can also sidestep writing to /tmp in the script in /lib/systemd/system-sleep/:

#!/bin/bash
### Ensure that the frequency is restored upon resuming from suspend
# The array to store frequencies:
declare -a frequencies
# Number of processors minus 1:
N=$((`nproc --all`-1))
case "${1}" in
  post)
    # Read the old values:
for i in `seq 0 $N`; do frequencies[$i]=`cat /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq`; done
    # Write a junk value first:
for i in `seq 0 $N`; do echo 1${frequencies[$i]} > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq; done
    # Let the file kernel digest the previous requests a bit:
    sleep 1
    # Write the old values:
for i in `seq 0 $N`; do echo ${frequencies[$i]} > /sys/devices/system/cpu/cpu$i/cpufreq/scaling_max_freq; done
    ;;
esac

Though this script now avoids writing into /tmp, it's a terribly wild hack again invoking bash and other utilities. I'm feeling that it is too much an overkill as opposed to doing the right thing in the kernel.

Reply via email to