From 37d99e4a5d3735bfe42adf321a9ecf29122dee67 Mon Sep 17 00:00:00 2001 From: Marc Bonnici Date: Mon, 12 Jun 2017 17:27:21 +0100 Subject: [PATCH] LinuxDevice: Remove duplicate method and rename for consistency These function were duplicated of each other so one has been removed and the remaining methods renamed for consistency with WA terminology and the relevant calls updated. --- wlauto/common/linux/device.py | 20 +++---------------- .../instrumentation/energy_model/__init__.py | 2 +- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/wlauto/common/linux/device.py b/wlauto/common/linux/device.py index ca5fc7b5..58d05ecd 100644 --- a/wlauto/common/linux/device.py +++ b/wlauto/common/linux/device.py @@ -106,7 +106,7 @@ class BaseLinuxDevice(Device): # pylint: disable=abstract-method runtime_parameters = [ RuntimeParameter('sysfile_values', 'get_sysfile_values', 'set_sysfile_values', value_name='params'), - CoreParameter('${core}_cores', 'get_number_of_online_cpus', 'set_number_of_online_cpus', + CoreParameter('${core}_cores', 'get_number_of_online_cores', 'set_number_of_online_cores', value_name='number'), CoreParameter('${core}_min_frequency', 'get_core_min_frequency', 'set_core_min_frequency', value_name='freq'), @@ -477,20 +477,6 @@ class BaseLinuxDevice(Device): # pylint: disable=abstract-method else: raise ValueError(c) - def get_number_of_online_cpus(self, core): - return len(self.get_online_cpus(core)) - - def set_number_of_online_cpus(self, core, number): - core_ids = [i for i, c in enumerate(self.core_names) if c == core] - max_cores = len(core_ids) - if number > max_cores: - message = 'Attempting to set the number of active {} to {}; maximum is {}' - raise ValueError(message.format(core, number, max_cores)) - for i in xrange(0, number): - self.enable_cpu(core_ids[i]) - for i in xrange(number, max_cores): - self.disable_cpu(core_ids[i]) - # hotplug def enable_cpu(self, cpu): @@ -529,7 +515,7 @@ class BaseLinuxDevice(Device): # pylint: disable=abstract-method sysfile = '/sys/devices/system/cpu/{}/online'.format(cpu) self.set_sysfile_value(sysfile, status) - def get_number_of_active_cores(self, core): + def get_number_of_online_cores(self, core): if core not in self.core_names: raise ValueError('Unexpected core: {}; must be in {}'.format(core, list(set(self.core_names)))) active_cpus = self.active_cpus @@ -539,7 +525,7 @@ class BaseLinuxDevice(Device): # pylint: disable=abstract-method num_active_cores += 1 return num_active_cores - def set_number_of_active_cores(self, core, number): # NOQA + def set_number_of_online_cores(self, core, number): # NOQA if core not in self.core_names: raise ValueError('Unexpected core: {}; must be in {}'.format(core, list(set(self.core_names)))) core_ids = [i for i, c in enumerate(self.core_names) if c == core] diff --git a/wlauto/instrumentation/energy_model/__init__.py b/wlauto/instrumentation/energy_model/__init__.py index 95056ece..6796c949 100644 --- a/wlauto/instrumentation/energy_model/__init__.py +++ b/wlauto/instrumentation/energy_model/__init__.py @@ -650,7 +650,7 @@ class EnergyModelInstrument(Instrument): def enable_all_cores(self): counter = Counter(self.device.core_names) for core, number in counter.iteritems(): - self.device.set_number_of_online_cpus(core, number) + self.device.set_number_of_online_cores(core, number) self.big_cpus = self.device.get_online_cpus(self.big_core) self.little_cpus = self.device.get_online_cpus(self.little_core)