Exemple #1
0
def collect_cpu_config(metadata, cpus):
    nohz_full = read_first_line(sysfs_path('devices/system/cpu/nohz_full'))
    if nohz_full:
        nohz_full = parse_cpu_list(nohz_full)

    isolated = get_isolated_cpus()
    if isolated:
        isolated = set(isolated)

    configs = {}
    for cpu in cpus:
        config = get_cpu_config(cpu)
        if nohz_full and cpu in nohz_full:
            config.append('nohz_full')
        if isolated and cpu in isolated:
            config.append('isolated')
        if config:
            configs[cpu] = ', '.join(config)
    config = format_cpu_infos(configs)

    cpuidle = read_first_line('/sys/devices/system/cpu/cpuidle/current_driver')
    if cpuidle:
        config.append('idle:%s' % cpuidle)

    if not config:
        return
    metadata['cpu_config'] = '; '.join(config)
Exemple #2
0
def collect_cpu_config(metadata, cpus):
    nohz_full = read_first_line(sysfs_path('devices/system/cpu/nohz_full'))
    if nohz_full:
        nohz_full = parse_cpu_list(nohz_full)

    isolated = get_isolated_cpus()
    if isolated:
        isolated = set(isolated)

    configs = {}
    for cpu in cpus:
        config = get_cpu_config(cpu)
        if nohz_full and cpu in nohz_full:
            config.append('nohz_full')
        if isolated and cpu in isolated:
            config.append('isolated')
        if config:
            configs[cpu] = ', '.join(config)
    config = format_cpu_infos(configs)

    cpuidle = read_first_line('/sys/devices/system/cpu/cpuidle/current_driver')
    if cpuidle:
        config.append('idle:%s' % cpuidle)

    if not config:
        return
    metadata['cpu_config'] = '; '.join(config)
Exemple #3
0
def collect_cpu_temperatures(metadata):
    path = sysfs_path("class/hwmon")
    try:
        names = os.listdir(path)
    except OSError:
        return None

    cpu_temp = []
    for name in names:
        hwmon = os.path.join(path, name)
        get_cpu_temperature(hwmon, cpu_temp)
    if not cpu_temp:
        return None

    metadata['cpu_temp'] = ', '.join(cpu_temp)
Exemple #4
0
def collect_cpu_temperatures(metadata):
    path = sysfs_path("class/hwmon")
    try:
        names = os.listdir(path)
    except OSError:
        return None

    cpu_temp = []
    for name in names:
        hwmon = os.path.join(path, name)
        get_cpu_temperature(hwmon, cpu_temp)
    if not cpu_temp:
        return None

    metadata['cpu_temp'] = ', '.join(cpu_temp)
Exemple #5
0
    def show(self):
        nohz_full = self.read_first_line(sysfs_path('devices/system/cpu/nohz_full'))
        if not nohz_full:
            return

        nohz_full = parse_cpu_list(nohz_full)
        if not nohz_full:
            return

        used = set(self.system.cpus) | set(nohz_full)
        if not used:
            return

        self.advice("WARNING: nohz_full is enabled on CPUs %s which use the "
                    "intel_pstate driver, whereas intel_pstate is incompatible "
                    "with nohz_full"
                    % format_cpu_list(used))
        self.advice("See https://bugzilla.redhat.com/show_bug.cgi?id=1378529")
        self.tuned_for_benchmarks = False
Exemple #6
0
    def show(self):
        nohz_full = self.read_first_line(sysfs_path('devices/system/cpu/nohz_full'))
        if not nohz_full:
            return

        nohz_full = parse_cpu_list(nohz_full)
        if not nohz_full:
            return

        used = set(self.system.cpus) | set(nohz_full)
        if not used:
            return

        self.advice("WARNING: nohz_full is enabled on CPUs %s which use the "
                    "intel_pstate driver, whereas intel_pstate is incompatible "
                    "with nohz_full"
                    % format_cpu_list(used))
        self.advice("See https://bugzilla.redhat.com/show_bug.cgi?id=1378529")
        self.tuned_for_benchmarks = False
Exemple #7
0
def get_isolated_cpus():
    """Get the list of isolated CPUs.

    Return a sorted list of CPU identifiers, or return None if no CPU is
    isolated.
    """
    # The cpu/isolated sysfs was added in Linux 4.2
    # (commit 59f30abe94bff50636c8cad45207a01fdcb2ee49)
    path = sysfs_path('devices/system/cpu/isolated')
    isolated = read_first_line(path)
    if isolated:
        return parse_cpu_list(isolated)

    cmdline = read_first_line(proc_path('cmdline'))
    if cmdline:
        match = re.search(r'\bisolcpus=([^ ]+)', cmdline)
        if match:
            isolated = match.group(1)
            return parse_cpu_list(isolated)

    return None
Exemple #8
0
def get_isolated_cpus():
    """Get the list of isolated CPUs.

    Return a sorted list of CPU identifiers, or return None if no CPU is
    isolated.
    """
    # The cpu/isolated sysfs was added in Linux 4.2
    # (commit 59f30abe94bff50636c8cad45207a01fdcb2ee49)
    path = sysfs_path('devices/system/cpu/isolated')
    isolated = read_first_line(path)
    if isolated:
        return parse_cpu_list(isolated)

    cmdline = read_first_line(proc_path('cmdline'))
    if cmdline:
        match = re.search(r'\bisolcpus=([^ ]+)', cmdline)
        if match:
            isolated = match.group(1)
            return parse_cpu_list(isolated)

    return None
Exemple #9
0
def get_cpu_config(cpu):
    sys_cpu_path = sysfs_path("devices/system/cpu")
    info = []

    path = os.path.join(sys_cpu_path, "cpu%s/cpufreq/scaling_driver" % cpu)
    scaling_driver = read_first_line(path)
    if scaling_driver:
        info.append('driver:%s' % scaling_driver)

    if scaling_driver == 'intel_pstate':
        path = os.path.join(sys_cpu_path, "intel_pstate/no_turbo")
        no_turbo = read_first_line(path)
        if no_turbo == '1':
            info.append('intel_pstate:no turbo')
        elif no_turbo == '0':
            info.append('intel_pstate:turbo')

    path = os.path.join(sys_cpu_path, "cpu%s/cpufreq/scaling_governor" % cpu)
    scaling_governor = read_first_line(path)
    if scaling_governor:
        info.append('governor:%s' % scaling_governor)

    return info
Exemple #10
0
def get_cpu_config(cpu):
    sys_cpu_path = sysfs_path("devices/system/cpu")
    info = []

    path = os.path.join(sys_cpu_path, "cpu%s/cpufreq/scaling_driver" % cpu)
    scaling_driver = read_first_line(path)
    if scaling_driver:
        info.append('driver:%s' % scaling_driver)

    if scaling_driver == 'intel_pstate':
        path = os.path.join(sys_cpu_path, "intel_pstate/no_turbo")
        no_turbo = read_first_line(path)
        if no_turbo == '1':
            info.append('intel_pstate:no turbo')
        elif no_turbo == '0':
            info.append('intel_pstate:turbo')

    path = os.path.join(sys_cpu_path, "cpu%s/cpufreq/scaling_governor" % cpu)
    scaling_governor = read_first_line(path)
    if scaling_governor:
        info.append('governor:%s' % scaling_governor)

    return info
Exemple #11
0
class PowerSupply(Operation):
    path = sysfs_path('class/power_supply')

    @classmethod
    def available(cls):
        return os.path.exists(cls.path)

    def __init__(self, system):
        Operation.__init__(self, 'Power supply', system)

    def read_power_supply(self):
        # Python implementation of the on_ac_power shell script
        for name in os.listdir(self.path):
            filename = os.path.join(self.path, name, 'online')
            if not os.path.exists(filename):
                continue

            line = self.read_first_line(filename)
            if line == '1':
                return True
            if line == '0':
                return False
            self.error("Failed to parse %s: %r" % (filename, line))
            break

        return None

    def show(self):
        plugged = self.read_power_supply()
        if plugged is None:
            return

        state = 'plugged' if plugged else 'unplugged'
        self.log_state('the power cable is %s' % state)
        if not plugged:
            self.advice('The power cable must be plugged')
Exemple #12
0
 def __init__(self, system):
     Operation.__init__(self, 'Turbo Boost (intel_pstate)', system)
     self.path = sysfs_path("devices/system/cpu/intel_pstate/no_turbo")
     self.enabled = None
Exemple #13
0
 def __init__(self, system):
     Operation.__init__(self, 'CPU scaling governor (intel_pstate)',
                        system)
     self.path = sysfs_path("devices/system/cpu/cpu0/cpufreq/scaling_governor")
     self.governor = None
Exemple #14
0
 def available():
     # On virtual machines, there is no cpufreq directory
     return os.path.exists(sysfs_path("devices/system/cpu/cpu0/cpufreq"))
Exemple #15
0
 def __init__(self, system):
     Operation.__init__(self, 'CPU Frequency', system)
     self.device_syspath = sysfs_path("devices/system/cpu")
Exemple #16
0
def use_intel_pstate():
    cpu = 0
    path = sysfs_path("devices/system/cpu/cpu%s/cpufreq/scaling_driver" % cpu)
    scaling_driver = read_first_line(path)
    return (scaling_driver == 'intel_pstate')
Exemple #17
0
 def __init__(self, system):
     Operation.__init__(self, 'CPU Frequency', system)
     self.device_syspath = sysfs_path("devices/system/cpu")
Exemple #18
0
 def available():
     # On virtual machines, there is no cpufreq directory
     return os.path.exists(sysfs_path("devices/system/cpu/cpu0/cpufreq"))
Exemple #19
0
 def __init__(self, system):
     Operation.__init__(self, 'CPU scaling governor (intel_pstate)',
                        system)
     self.path = sysfs_path("devices/system/cpu/cpu0/cpufreq/scaling_governor")
     self.governor = None
Exemple #20
0
 def __init__(self, system):
     Operation.__init__(self, 'Turbo Boost (intel_pstate)', system)
     self.path = sysfs_path("devices/system/cpu/intel_pstate/no_turbo")
     self.enabled = None
Exemple #21
0
def use_intel_pstate():
    cpu = 0
    path = sysfs_path("devices/system/cpu/cpu%s/cpufreq/scaling_driver" % cpu)
    scaling_driver = read_first_line(path)
    return (scaling_driver == 'intel_pstate')