Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _cpu_affinity(self):
cpus = self.args.affinity
if not cpus:
# --affinity option is not set: detect isolated CPUs
isolated = True
cpus = get_isolated_cpus()
if not cpus:
# no isolated CPUs or unable to get the isolated CPUs
return
else:
isolated = False
cpus = parse_cpu_list(cpus)
if set_cpu_affinity(cpus):
if self.args.verbose:
if isolated:
text = ("Pin process to isolated CPUs: %s"
% format_cpu_list(cpus))
else:
text = ("Pin process to CPUs: %s"
% format_cpu_list(cpus))
print(text)
if isolated:
self.args.affinity = format_cpu_list(cpus)
else:
if not isolated:
print("ERROR: CPU affinity not available.", file=sys.stderr)
def parse_affinity(value):
try:
cpus = parse_cpu_list(value)
except ValueError:
cpus = None
if not cpus:
raise argparse.ArgumentTypeError('invalid CPU list: %r' % value)
return cpus
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)
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