summaryrefslogtreecommitdiffstats
path: root/remote/modules
diff options
context:
space:
mode:
authorJonathan Bauer2014-11-17 17:47:16 +0100
committerJonathan Bauer2014-11-17 17:47:16 +0100
commit9ef02255661d25d3f147abcbd48cd00eb5be2c51 (patch)
tree807de52fd90af90fd0873fa19452bff8c7bd297c /remote/modules
parent[mltk] added centos help msg support (diff)
downloadtm-scripts-9ef02255661d25d3f147abcbd48cd00eb5be2c51.tar.gz
tm-scripts-9ef02255661d25d3f147abcbd48cd00eb5be2c51.tar.xz
tm-scripts-9ef02255661d25d3f147abcbd48cd00eb5be2c51.zip
[cpu-governor] new module to set the cpu governor of clients
default: ondemand if you want something else, use the SLX config variable SLX_GOVERNOR
Diffstat (limited to 'remote/modules')
l---------remote/modules/cpugovernor/data/etc/systemd/system/basic.target.wants/cpu-governor.service1
-rw-r--r--remote/modules/cpugovernor/data/etc/systemd/system/cpu-governor.service6
-rwxr-xr-xremote/modules/cpugovernor/data/opt/openslx/scripts/systemd-cpu_governor62
-rw-r--r--remote/modules/cpugovernor/module.build11
-rw-r--r--remote/modules/cpugovernor/module.conf3
5 files changed, 83 insertions, 0 deletions
diff --git a/remote/modules/cpugovernor/data/etc/systemd/system/basic.target.wants/cpu-governor.service b/remote/modules/cpugovernor/data/etc/systemd/system/basic.target.wants/cpu-governor.service
new file mode 120000
index 00000000..878a1676
--- /dev/null
+++ b/remote/modules/cpugovernor/data/etc/systemd/system/basic.target.wants/cpu-governor.service
@@ -0,0 +1 @@
+../cpu-governor.service \ No newline at end of file
diff --git a/remote/modules/cpugovernor/data/etc/systemd/system/cpu-governor.service b/remote/modules/cpugovernor/data/etc/systemd/system/cpu-governor.service
new file mode 100644
index 00000000..e2ba1491
--- /dev/null
+++ b/remote/modules/cpugovernor/data/etc/systemd/system/cpu-governor.service
@@ -0,0 +1,6 @@
+[Unit]
+Description=Sets the CPU governor
+
+[Service]
+Type=oneshot
+ExecStart=/opt/openslx/scripts/systemd-cpu_governor
diff --git a/remote/modules/cpugovernor/data/opt/openslx/scripts/systemd-cpu_governor b/remote/modules/cpugovernor/data/opt/openslx/scripts/systemd-cpu_governor
new file mode 100755
index 00000000..115163c7
--- /dev/null
+++ b/remote/modules/cpugovernor/data/opt/openslx/scripts/systemd-cpu_governor
@@ -0,0 +1,62 @@
+#!/bin/ash
+#
+# Script to set the CPU governor to ondemand on all cores
+#
+
+# source global config
+. /opt/openslx/config || \
+ { echo "ERROR: Could not source /opt/openslx/config."; exit 1; }
+
+# set the governor to the one given in SLX_GOVERNOR
+TARGET_GOVERNOR=""
+if [ -n "$SLX_GOVERNOR" ]; then
+ TARGET_GOVERNOR="$SLX_GOVERNOR"
+else
+ # use 'ondemand' per default
+ TARGET_GOVERNOR="ondemand"
+fi
+echo "Setting governor to $TARGET_GOVERNOR"
+# global information needed
+# CORES is the range of cores present, on bwpc4 it has the value '0-3'
+# thus the split: MINCORE=0 MAXCORE=3
+CORES="$(cat /sys/devices/system/cpu/present)"
+MINCORE="$(echo $CORES | awk -F "-" '{print $1}')"
+MAXCORE="$(echo $CORES | awk -F "-" '{print $2}')"
+
+# Helper function 'test_for_gov'
+# Usage:
+# test_for_gov <governor>
+# Example:
+# test_for_gov "ondemand"
+# Return 0 if it is supported by all cpus, 1 otherwise
+test_for_gov() {
+ # if no argument is given, print error and exit (yes exit the whole script!)
+ [ $# -ne 1 ] && echo "Usage: test_for_gov <governor>. No arguments given!" && exit 1
+ local GOVERNOR="$1"
+
+ # check for each cpu just to be safe
+ # ash-style loop ....
+ local i=$MINCORE
+ while [ $i -le $MAXCORE ]; do
+ # check if the given governor is supported
+ grep -q "${GOVERNOR}" /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_available_governors || return 1;
+ # increment
+ true $(( i++ ))
+ done
+ return 0;
+}
+# now actually test the cpus for the 'ondemand' cpu governor
+if test_for_gov "${TARGET_GOVERNOR}"; then
+ # ok, so now set the governor to 'ondemand' for all cores
+ i=$MINCORE
+ while [ $i -le $MAXCORE ]; do
+ if ! echo "${TARGET_GOVERNOR}" > /sys/devices/system/cpu/cpu${i}/cpufreq/scaling_governor; then
+ echo "ERROR: Could not set the cpu governor to '${TARGET_GOVERNOR}'!"
+ exit 1
+ fi
+ true $(( i++ ))
+ done
+else
+ echo "ERROR: '${TARGET_GOVERNOR}' is not supported by this machine!"
+ exit 1
+fi
diff --git a/remote/modules/cpugovernor/module.build b/remote/modules/cpugovernor/module.build
new file mode 100644
index 00000000..97e93235
--- /dev/null
+++ b/remote/modules/cpugovernor/module.build
@@ -0,0 +1,11 @@
+fetch_source() {
+ :
+}
+
+build() {
+ :
+}
+
+post_copy() {
+ :
+}
diff --git a/remote/modules/cpugovernor/module.conf b/remote/modules/cpugovernor/module.conf
new file mode 100644
index 00000000..0cd03752
--- /dev/null
+++ b/remote/modules/cpugovernor/module.conf
@@ -0,0 +1,3 @@
+REQUIRED_BINARIES=""
+REQUIRED_LIBRARIES=""
+REQUIRED_DIRECTORIES=""