#!/bin/bash
#
# CPUFreq scaling governor
# Copyright Daniel Mehrmann (Akusari) 2019
#
# $1 choosen governor (e.g ondemand,performance,schedutil,powersave)
#

if [ -z "$1" ]; then
	echo "$(basename $0) missing governor parameter"
	exit 254
fi

# governor 
 
core=$(grep -c processor /proc/cpuinfo)
((core--))

until [ $core -lt 0 ]; do
	echo "$1" >  /sys/devices/system/cpu/cpu${core}/cpufreq/scaling_governor || exit 255	
	((core--))
done

# ondemand settings

if [ "$1" == "ondemand" ]; then
	#echo -n  "1" > /sys/devices/system/cpu/cpufreq/ondemand/ignore_nice_load || exit 255
	echo -n "50" > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold || exit 255
fi

exit 0
