From 4dcb4974e5cc1700bd1e410d85b85beff1ebe3dd Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Wed, 16 Sep 2015 18:03:04 +0100 Subject: [PATCH 1/2] cpufreq: add methods to set the governor for a specified set of CPUs Sometimes it could be required to change the governor for a set of different CPUs. This patch provides an utility method to easily and achieve that with a single method call. Signed-off-by: Patrick Bellasi --- devlib/module/cpufreq.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/devlib/module/cpufreq.py b/devlib/module/cpufreq.py index a41cff2..37c49dc 100644 --- a/devlib/module/cpufreq.py +++ b/devlib/module/cpufreq.py @@ -326,3 +326,26 @@ class CpufreqModule(Module): self.target.write_value(sysfile, value) except ValueError: raise ValueError('Frequency must be an integer; got: "{}"'.format(frequency)) + + def set_governor_for_cpus(self, cpus, governor, **kwargs): + """ + Set the governor for the specified list of CPUs. + See https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt + + :param cpus: The list of CPU for which the governor is to be set. + """ + online_cpus = self.target.list_online_cpus() + for cpu in online_cpus: + self.set_governor(cpu, governor, kwargs) + + def set_frequency_for_cpus(self, cpus, freq, exact=False): + """ + Set the frequency for the specified list of CPUs. + See https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt + + :param cpus: The list of CPU for which the frequency has to be set. + """ + online_cpus = self.target.list_online_cpus() + for cpu in online_cpus: + self.set_frequency(cpu, freq, exact) + From b598b38f125cf84a501f9c1ec58938b29a36f7a9 Mon Sep 17 00:00:00 2001 From: Patrick Bellasi Date: Thu, 17 Sep 2015 17:39:32 +0100 Subject: [PATCH 2/2] cpufreq: add methods to configure all CPUs at once Sometimes it could be required to change governor or frequency for a all the online CPUs of a target. This patch provides an utility method to easily do that using a single method call. Signed-off-by: Patrick Bellasi --- devlib/module/cpufreq.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/devlib/module/cpufreq.py b/devlib/module/cpufreq.py index 37c49dc..f4386ad 100644 --- a/devlib/module/cpufreq.py +++ b/devlib/module/cpufreq.py @@ -349,3 +349,17 @@ 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_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) +