From 3b226d19bb19a87eb565f3e1d16e14f446b56e76 Mon Sep 17 00:00:00 2001 From: johannst Date: Tue, 27 Aug 2024 22:25:00 +0000 Subject: deploy: 9b47b98b7c5efce0bf50d57aa5d7e374bcbabf23 --- process/taskset.html | 271 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 271 insertions(+) create mode 100644 process/taskset.html (limited to 'process/taskset.html') diff --git a/process/taskset.html b/process/taskset.html new file mode 100644 index 0000000..4a49f60 --- /dev/null +++ b/process/taskset.html @@ -0,0 +1,271 @@ + + + + + + taskset - Notes + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+
+

taskset(1)

+

Set cpu affinity for new processes or already running ones.

+
# Pin all (-a) tasks of new command on cores 0,1,2,4.
+taskset -ac 0-2,4 CMD [ARGS]
+
+# Pin all tasks of running PID onto cores 0,2,4.
+taskset -ac 0-5:2 -p PID
+
+

Example

+

Utility script to extract cpu lists grouped by the last-level-cache.

+
import subprocess
+
+res = subprocess.run(["lscpu", "-p=cpu,cache"], capture_output=True, check=True)
+
+LLC2CPU = dict()
+
+for line in res.stdout.decode().splitlines():
+    if line.startswith("#"):
+        continue
+
+    cpu, cache = line.split(",")
+    llc        = cache.split(":")[-1]
+
+    LLC2CPU.setdefault(llc, list()).append(int(cpu))
+
+LLC2RANGE = dict()
+
+for llc, cpus in LLC2CPU.items():
+    first_cpu = cpus[0]
+    prev_cpu  = cpus[0]
+    for cpu in cpus[1:]:
+        if cpu != prev_cpu + 1:
+            LLC2RANGE.setdefault(llc, list()).append(f"{first_cpu}-{prev_cpu}")
+            # New range begins.
+            first_cpu = cpu
+        prev_cpu = cpu
+    # Trailing range.
+    LLC2RANGE.setdefault(llc, list()).append(f"{first_cpu}-{prev_cpu}")
+
+print(LLC2RANGE)
+
+ +
+ + +
+
+ + + +
+ + + + + + + + + + + + + + + + + + +
+ + -- cgit v1.2.3