def collect_cpu_freq(metadata, cpus): # Parse /proc/cpuinfo: search for 'cpu MHz' (Intel) or 'clock' (Power8) cpu_set = set(cpus) cpu_freq = {} cpu = None for line in read_proc('cpuinfo'): if line.startswith('processor'): value = line.split(':', 1)[-1].strip() cpu = int(value) if cpu not in cpu_set: # skip this CPU cpu = None elif line.startswith('cpu MHz') and cpu is not None: # Intel: 'cpu MHz : 1261.613' mhz = line.split(':', 1)[-1].strip() mhz = float(mhz) mhz = int(round(mhz)) cpu_freq[cpu] = '%s MHz' % mhz elif line.startswith('clock') and line.endswith('MHz') and cpu is not None: # Power8: 'clock : 3425.000000MHz' mhz = line[:-3].split(':', 1)[-1].strip() mhz = float(mhz) mhz = int(round(mhz)) cpu_freq[cpu] = '%s MHz' % mhz if not cpu_freq: return metadata['cpu_freq'] = '; '.join(format_cpu_infos(cpu_freq))
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)
def show(self): cpus = {} for cpu in range(self.system.logical_cpu_count): freq = self.read_cpu(cpu) if freq is not None: cpus[cpu] = freq infos = format_cpu_infos(cpus) if not infos: return self.log_state('; '.join(infos))
def collect_cpu_freq(metadata, cpus): # Parse /proc/cpuinfo: search for 'cpu MHz' (Intel) or 'clock' (Power8) cpu_set = set(cpus) cpu_freq = {} cpu = None for line in read_proc('cpuinfo'): line = line.rstrip() if line.startswith('processor'): # Intel format, example where \t is a tab (U+0009 character): # processor\t: 7 # model name\t: Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz # cpu MHz\t\t: 800.009 match = re.match(r'^processor\s*: ([0-9]+)', line) if match is None: # IBM Z # Example: "processor 0: version = 00, identification = [...]" match = re.match(r'^processor ([0-9]+): ', line) if match is None: raise Exception # unknown /proc/cpuinfo format: silently ignore and exit return cpu = int(match.group(1)) if cpu not in cpu_set: # skip this CPU cpu = None elif line.startswith('cpu MHz') and cpu is not None: # Intel: 'cpu MHz : 1261.613' mhz = line.split(':', 1)[-1].strip() mhz = float(mhz) mhz = int(round(mhz)) cpu_freq[cpu] = '%s MHz' % mhz elif line.startswith('clock') and line.endswith( 'MHz') and cpu is not None: # Power8: 'clock : 3425.000000MHz' mhz = line[:-3].split(':', 1)[-1].strip() mhz = float(mhz) mhz = int(round(mhz)) cpu_freq[cpu] = '%s MHz' % mhz if not cpu_freq: return metadata['cpu_freq'] = '; '.join(format_cpu_infos(cpu_freq))
def collect_cpu_freq(metadata, cpus): # Parse /proc/cpuinfo: search for 'cpu MHz' (Intel) or 'clock' (Power8) cpu_set = set(cpus) cpu_freq = {} cpu = None for line in read_proc('cpuinfo'): line = line.rstrip() if line.startswith('processor'): # Intel format, example where \t is a tab (U+0009 character): # processor\t: 7 # model name\t: Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz # cpu MHz\t\t: 800.009 match = re.match(r'^processor\s*: ([0-9]+)', line) if match is None: # IBM Z # Example: "processor 0: version = 00, identification = [...]" match = re.match(r'^processor ([0-9]+): ', line) if match is None: raise Exception # unknown /proc/cpuinfo format: silently ignore and exit return cpu = int(match.group(1)) if cpu not in cpu_set: # skip this CPU cpu = None elif line.startswith('cpu MHz') and cpu is not None: # Intel: 'cpu MHz : 1261.613' mhz = line.split(':', 1)[-1].strip() mhz = float(mhz) mhz = int(round(mhz)) cpu_freq[cpu] = '%s MHz' % mhz elif line.startswith('clock') and line.endswith('MHz') and cpu is not None: # Power8: 'clock : 3425.000000MHz' mhz = line[:-3].split(':', 1)[-1].strip() mhz = float(mhz) mhz = int(round(mhz)) cpu_freq[cpu] = '%s MHz' % mhz if not cpu_freq: return metadata['cpu_freq'] = '; '.join(format_cpu_infos(cpu_freq))
def show(self): irqbalance_active = self.read_irqbalance_state() if irqbalance_active is not None: state = 'active' if irqbalance_active else 'inactive' self.log_state("irqbalance service: %s" % state) default_smp_affinity = self.read_default_affinity() if default_smp_affinity: self.log_state("Default IRQ affinity: CPU %s" % format_cpu_list(default_smp_affinity)) irq_affinity = self.read_irqs_affinity() if irq_affinity: infos = {irq: 'CPU %s' % format_cpu_list(cpus) for irq, cpus in irq_affinity.items()} infos = format_cpu_infos(infos) infos = ['IRQ %s' % info for info in infos] self.log_state('IRQ affinity: %s' % '; '.join(infos))