1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-02-27 15:07:50 +00:00
devlib/devlib/module/hotplug.py
Patrick Bellasi 7ba791b2a7 hotplug: make hotplug probing more robust
In general it makes not sense to hotplug out all the CPUs of a system, thus
ususally CPU0 is configured as not hot/plugggable.
Definitively, on a single core system it does not make sense to hotpolug out
the only available CPU.

This patch switch to usage of CPU1 for hotplug support probing, which is the
really first one for which enabling hotplug could be useful.

Signed-off-by: Patrick Bellasi <patrick.bellasi@arm.com>
2015-10-12 18:35:29 +01:00

41 lines
1.2 KiB
Python

from devlib.module import Module
class HotplugModule(Module):
name = 'hotplug'
base_path = '/sys/devices/system/cpu'
@classmethod
def probe(cls, target): # pylint: disable=arguments-differ
# If a system has just 1 CPU, it makes not sense to hotplug it.
# If a system has more than 1 CPU, CPU0 could be configured to be not
# hotpluggable. Thus, check for hotplug support by looking at CPU1
path = cls._cpu_path(target, 1)
return target.file_exists(path) and target.is_rooted
@classmethod
def _cpu_path(cls, target, cpu):
if isinstance(cpu, int):
cpu = 'cpu{}'.format(cpu)
return target.path.join(cls.base_path, cpu, 'online')
def online_all(self):
self.online(*range(self.target.number_of_cpus))
def online(self, *args):
for cpu in args:
self.hotplug(cpu, online=True)
def offline(self, *args):
for cpu in args:
self.hotplug(cpu, online=False)
def hotplug(self, cpu, online):
path = self._cpu_path(self.target, cpu)
if not self.target.file_exists(path):
return
value = 1 if online else 0
self.target.write_value(path, value)