diff options
author | Johannes Stoelp <johannes.stoelp@gmail.com> | 2024-08-27 23:50:44 +0200 |
---|---|---|
committer | Johannes Stoelp <johannes.stoelp@gmail.com> | 2024-08-28 23:16:36 +0200 |
commit | 014963008a43808119d9d6c56bbbd1692a4bcb27 (patch) | |
tree | f76f26a123a36c74c9370161a02bb4f18fe79166 /src | |
parent | e830fa716bedecbff8c3a572d1d20061342ec4c7 (diff) | |
download | notes-014963008a43808119d9d6c56bbbd1692a4bcb27.tar.gz notes-014963008a43808119d9d6c56bbbd1692a4bcb27.zip |
process: add taskset, nice
Diffstat (limited to 'src')
-rw-r--r-- | src/SUMMARY.md | 2 | ||||
-rw-r--r-- | src/process/README.md | 2 | ||||
-rw-r--r-- | src/process/nice.md | 15 | ||||
-rw-r--r-- | src/process/taskset.md | 46 |
4 files changed, 65 insertions, 0 deletions
diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 53de8e5..6d401d3 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -36,6 +36,8 @@ - [ps](./process/ps.md) - [pmap](./process/pmap.md) - [pstack](./process/pstack.md) + - [taskset](./process/taskset.md) + - [nice](./process/nice.md) - [Trace and Profile](./trace_profile/README.md) - [time](./trace_profile/time.md) diff --git a/src/process/README.md b/src/process/README.md index 5b07038..8abbdfb 100644 --- a/src/process/README.md +++ b/src/process/README.md @@ -6,3 +6,5 @@ - [ps](./ps.md) - [pmap](./pmap.md) - [pstack](./pstack.md) +- [taskset](./taskset.md) +- [nice](./nice.md) diff --git a/src/process/nice.md b/src/process/nice.md new file mode 100644 index 0000000..bda743d --- /dev/null +++ b/src/process/nice.md @@ -0,0 +1,15 @@ +# nice(1) + +Adjust `niceness` of a new command or running process. + +Niceness influences the scheduling priority and ranges between: +- `-20` most favorable +- `19` least favorable + +```sh +# Adjust niceness +5 for the launched process. +nice -n 5 yes + +# Adjust niceness of running process. +renice -n 5 -p PID +``` diff --git a/src/process/taskset.md b/src/process/taskset.md new file mode 100644 index 0000000..aca93b8 --- /dev/null +++ b/src/process/taskset.md @@ -0,0 +1,46 @@ +# taskset(1) + +Set cpu affinity for new processes or already running ones. + +```sh +# 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. +```python +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) +``` |