diff --git a/devlib/bin/scripts/shutils.in b/devlib/bin/scripts/shutils.in index 33bb0e1..1ae9a4f 100755 --- a/devlib/bin/scripts/shutils.in +++ b/devlib/bin/scripts/shutils.in @@ -7,12 +7,46 @@ BUSYBOX=${BUSYBOX:-__DEVLIB_BUSYBOX__} GREP=${GREP:-$BUSYBOX grep} SED=${SED:-$BUSYBOX sed} +################################################################################ +# CPUFrequency Utility Functions +################################################################################ + +cpufreq_set_all_frequencies() { + FREQ=$1 + for CPU in /sys/devices/system/cpu/cpu[0-9]*; do + echo $FREQ > $CPU/cpufreq/scaling_cur_freq + done +} + +cpufreq_set_all_governors() { + GOV=$1 + for CPU in /sys/devices/system/cpu/cpu[0-9]*; do + echo $GOV > $CPU/cpufreq/scaling_governor + done +} + +cpufreq_trace_all_frequencies() { + FREQS=$(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq) + CPU=0; for F in $FREQS; do + echo "cpu_frequency: state=$F cpu_id=$CPU" > /sys/kernel/debug/tracing/trace_marker + CPU=$((CPU + 1)) + done +} ################################################################################ # Main Function Dispatcher ################################################################################ case $CMD in +cpufreq_set_all_frequencies) + cpufreq_set_all_frequencies $* + ;; +cpufreq_set_all_governors) + cpufreq_set_all_governors $* + ;; +cpufreq_trace_all_frequencies) + cpufreq_trace_all_frequencies $* + ;; *) echo "Command [$CMD] not supported" exit -1 diff --git a/devlib/module/cpufreq.py b/devlib/module/cpufreq.py index 5a55213..ed2f2e5 100644 --- a/devlib/module/cpufreq.py +++ b/devlib/module/cpufreq.py @@ -349,30 +349,27 @@ class CpufreqModule(Module): for cpu in online_cpus: self.set_frequency(cpu, freq, exact) - def set_all_frequencies(self, freq, exact=False): - self.target.execute( - "for CPU in /sys/devices/system/cpu/cpu[0-9]*; do "\ - "echo {} > $CPU/cpufreq/scaling_cur_freq; "\ - "done"\ - .format(freq), as_root=True) + def set_all_frequencies(self, freq): + """ + Set the specified (minimum) frequency for all the (online) CPUs + """ + return self.target._execute_util( + 'cpufreq_set_all_frequencies {}'.format(freq), + as_root=True) + def set_all_governors(self, governor): - self.target.execute( - "for CPU in /sys/devices/system/cpu/cpu[0-9]*; do "\ - "echo {} > $CPU/cpufreq/scaling_governor; "\ - "done"\ - .format(governor), as_root=True) + """ + Set the specified governor for all the (online) CPUs + """ + return self.target._execute_util( + 'cpufreq_set_all_governors {}'.format(governor), + as_root=True) + def trace_frequencies(self): """ Report current frequencies on trace file """ - self.target.execute( - 'FREQS=$(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq); ' - 'CPU=0; for F in $FREQS; do ' - ' echo "cpu_frequency: state=$F cpu_id=$CPU" > /sys/kernel/debug/tracing/trace_marker; ' - ' let CPU++; ' - 'done', - as_root=True - ) + return self.target._execute_util('cpufreq_trace_all_frequencies', as_root=True)