1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-04-20 09:40:50 +01:00

minor fixes to cpufreq APIs

- adding missing cpu id conversion to set_cpu_min_freq
- adding "exact" parameter to set_cpu_frequency; only produce an error
  when the specified frequency is not supported by the cpu if "axact"
  is set; (otherwise let cpufreq decide what the actual frequency will
  be).
This commit is contained in:
Sergei Trofimov 2015-05-11 11:53:36 +01:00
parent fbde403f6f
commit 40bd32280a

View File

@ -486,6 +486,8 @@ class BaseLinuxDevice(Device): # pylint: disable=abstract-method
:raises: DeviceError if for some reason the frequency could not be read. :raises: DeviceError if for some reason the frequency could not be read.
""" """
if isinstance(cpu, int):
cpu = 'cpu{}'.format(cpu)
sysfile = '/sys/devices/system/cpu/{}/cpufreq/scaling_min_freq'.format(cpu) sysfile = '/sys/devices/system/cpu/{}/cpufreq/scaling_min_freq'.format(cpu)
return self.get_sysfile_value(sysfile) return self.get_sysfile_value(sysfile)
@ -533,17 +535,19 @@ class BaseLinuxDevice(Device): # pylint: disable=abstract-method
sysfile = '/sys/devices/system/cpu/{}/cpufreq/scaling_cur_freq'.format(cpu) sysfile = '/sys/devices/system/cpu/{}/cpufreq/scaling_cur_freq'.format(cpu)
return self.get_sysfile_value(sysfile) return self.get_sysfile_value(sysfile)
def set_cpu_frequency(self, cpu, frequency): def set_cpu_frequency(self, cpu, frequency, exact=True):
""" """
Set's the minimum value for CPU frequency. Actual frequency will Set's the minimum value for CPU frequency. Actual frequency will
depend on the Governor used and may vary during execution. The value should be depend on the Governor used and may vary during execution. The value should be
either an int or a string representing an integer. The Value must also be either an int or a string representing an integer.
supported by the device. The available frequencies can be obtained by calling
If ``exact`` flag is set (the default), the Value must also be supported by
the device. The available frequencies can be obtained by calling
get_available_frequencies() or examining get_available_frequencies() or examining
/sys/devices/system/cpu/cpuX/cpufreq/scaling_available_frequencies /sys/devices/system/cpu/cpuX/cpufreq/scaling_available_frequencies
on the device. on the device (if it exists).
:raises: ConfigError if the frequency is not supported by the CPU. :raises: ConfigError if the frequency is not supported by the CPU.
:raises: DeviceError if, for some reason, frequency could not be set. :raises: DeviceError if, for some reason, frequency could not be set.
@ -551,19 +555,20 @@ class BaseLinuxDevice(Device): # pylint: disable=abstract-method
""" """
if isinstance(cpu, int): if isinstance(cpu, int):
cpu = 'cpu{}'.format(cpu) cpu = 'cpu{}'.format(cpu)
available_frequencies = self.list_available_cpu_frequencies(cpu)
try: try:
value = int(frequency) value = int(frequency)
if available_frequencies and value not in available_frequencies: if exact:
raise ConfigError('Can\'t set {} frequency to {}\nmust be in {}'.format(cpu, available_frequencies = self.list_available_cpu_frequencies(cpu)
value, if available_frequencies and value not in available_frequencies:
available_frequencies)) raise ConfigError('Can\'t set {} frequency to {}\nmust be in {}'.format(cpu,
value,
available_frequencies))
if self.get_cpu_governor(cpu) != 'userspace': if self.get_cpu_governor(cpu) != 'userspace':
raise ConfigError('Can\'t set {} frequency; governor must be "userspace"'.format(cpu)) raise ConfigError('Can\'t set {} frequency; governor must be "userspace"'.format(cpu))
sysfile = '/sys/devices/system/cpu/{}/cpufreq/scaling_setspeed'.format(cpu) sysfile = '/sys/devices/system/cpu/{}/cpufreq/scaling_setspeed'.format(cpu)
self.set_sysfile_value(sysfile, value, verify=False) self.set_sysfile_value(sysfile, value, verify=False)
except ValueError: except ValueError:
raise ValueError('value must be an integer; got: "{}"'.format(value)) raise ValueError('frequency must be an integer; got: "{}"'.format(value))
def get_cpu_max_frequency(self, cpu): def get_cpu_max_frequency(self, cpu):
""" """