Created
June 13, 2016 17:32
-
-
Save anthonygtellez/946c212a974091f87316357484a1a709 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# found on the internet, not my creation | |
# - jsie | |
import re | |
total_logical_cpus = 0 | |
total_physical_cpus = 0 | |
total_cores = 0 | |
logical_cpus = {} | |
physical_cpus = {} | |
cores = {} | |
hyperthreading = False | |
for line in open('/proc/cpuinfo').readlines(): | |
if re.match('processor', line): | |
cpu = int(line.split()[2]) | |
if not logical_cpus.has_key(cpu): | |
logical_cpus[cpu] = [] | |
total_logical_cpus += 1 | |
if re.match('physical id', line): | |
phys_id = int(line.split()[3]) | |
if not physical_cpus.has_key(phys_id): | |
physical_cpus[phys_id] = [] | |
total_physical_cpus += 1 | |
if re.match('core id', line): | |
core = int(line.split()[3]) | |
if not cores.has_key(core): | |
cores[core] = [] | |
total_cores += 1 | |
cores[core].append(cpu) | |
if (total_cores * total_physical_cpus) * 2 == total_logical_cpus: | |
hyperthreading = True | |
print(" This system has %d physical CPUs" % total_physical_cpus) | |
print(" This system has %d cores per physical CPU" % total_cores) | |
print(" This system has %d total cores" % (total_cores * total_physical_cpus)) | |
print(" This system has %d logical CPUs" % total_logical_cpus) | |
if hyperthreading: | |
print(" HT detected, if you want to disable it:") | |
print(" Edit your grub config and add 'noht'") | |
print(" -OR- disable hyperthreading in the BIOS") | |
print(" -OR- try the following to offline those CPUs:") | |
for c in cores: | |
for p, val in enumerate(cores[c]): | |
if p > 0: | |
print(" echo 0 > /sys/devices/system/cpu/cpu%d/online" % (val)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment