Skip to content

Instantly share code, notes, and snippets.

@clementperon
Last active Apr 12, 2020
Embed
What would you like to do?
#!/bin/sh
# License: MIT or GPL-2.0-or-later
# Copyright (c) 2020 Clément Péron <peron.clem@gmail.com>
set -e
# Time in seconds
TIME_MIN=10
TIME_MAX=100
TIME_DELTA=$((TIME_MAX - TIME_MIN))
# CPU Freq folder
CPU0FREQ="/sys/devices/system/cpu/cpu0/cpufreq"
CPUTEMP="/sys/class/thermal/thermal_zone0/temp"
FREQUENCIES=$(cat "${CPU0FREQ}/scaling_available_frequencies")
set_frequency_and_wait()
{
FREQUENCY=${1}
TIME=${2}
echo "Frequency:${FREQUENCY}Hz Time:${TIME}s"
echo userspace > ${CPU0FREQ}/scaling_governor
echo "${FREQUENCY}" > "${CPU0FREQ}/scaling_setspeed"
sleep ${TIME}
}
get_frequency()
{
INDEX=${1}
set -- ${FREQUENCIES}
shift ${INDEX}
echo ${1}
}
echo "Frequencies: ${FREQUENCIES}"
# Count number of FREQUENCIES
FREQUENCIES_SIZE=0
set -- ${FREQUENCIES}
while [ -n "$1" ]; do
FREQUENCIES_SIZE=$((FREQUENCIES_SIZE+1))
shift
done
echo "Number of frequencies available: ${FREQUENCIES_SIZE}"
echo "Testing all frequencies in ascending order"
i=0
while [ $i -lt ${FREQUENCIES_SIZE} ]; do
FREQUENCY=$(get_frequency ${i})
TIME=1
set_frequency_and_wait ${FREQUENCY} ${TIME_MIN}
i=$((i+1))
done
echo "Testing all frequencies in descending order"
i=0
while [ $i -lt ${FREQUENCIES_SIZE} ]; do
INDEX=$((FREQUENCIES_SIZE - (i + 1)))
FREQUENCY=$(get_frequency ${INDEX})
TIME=1
set_frequency_and_wait ${FREQUENCY} ${TIME_MIN}
i=$((i+1))
done
echo "Testing 10 bumps from min to max frequencies"
FREQUENCY_MIN=$(get_frequency 0)
FREQUENCY_MAX=$(get_frequency $((FREQUENCIES_SIZE - 1)))
TIME=1
i=0
while [ $i -lt 10 ]; do
set_frequency_and_wait ${FREQUENCY_MIN} ${TIME_MIN}
set_frequency_and_wait ${FREQUENCY_MAX} ${TIME_MIN}
i=$((i+1))
done
while true; do
set -- ${FREQUENCIES}
# Choose a random number between 0 and Frequencies_size - 1.
RAND=$((RANDOM % FREQUENCIES_SIZE))
shift ${RAND}
FREQUENCY=${1}
# Choose a random time
TIME=$(($((RANDOM % TIME_DELTA)) + TIME_MIN))
set_frequency_and_wait ${FREQUENCY} ${TIME}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment