Last active
July 1, 2019 10:03
-
-
Save jenrik/ec70c1da8066e53e7d0e3f4c844eb9c9 to your computer and use it in GitHub Desktop.
Enable/Disable a number of cores on a Linux system
This file contains 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
#!/usr/bin/env python3 | |
import sys | |
MAX_CORES = 12 | |
if len(sys.argv) >= 2: | |
n = int(sys.argv[1]) | |
if n > MAX_CORES or n < 1: | |
sys.exit(1) | |
for i in range(1, n): | |
path = "/sys/devices/system/cpu/cpu{}/online".format(i) | |
with open(path, "w") as f: | |
f.write("1") | |
for i in range(n, MAX_CORES): | |
path = "/sys/devices/system/cpu/cpu{}/online".format(i) | |
with open(path, "w") as f: | |
f.write("0") | |
else: | |
enabled = 1 | |
for i in range(1, MAX_CORES): | |
path = "/sys/devices/system/cpu/cpu{}/online".format(i) | |
with open(path, "r") as f: | |
c = f.read(1) | |
if c == "1": | |
enabled += 1 | |
print(enabled) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment