sched_getcpu example

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2020-04-17 03:00:02 +00:00
parent 14b87f6efe
commit 547ac466ef
3 changed files with 53 additions and 0 deletions

View File

@@ -17294,6 +17294,17 @@ The best article to understand spinlocks is: https://eli.thegreenplace.net/2018/
The example in `man futex` is also a must.
[[getcpu]]
==== `getcpu` system call and the `sched_getaffinity` glibc wrapper
Example: link:userland/linux/sched_getcpu.c[]
Returns the CPU that the process/thread is currently running on: https://stackoverflow.com/questions/491520/how-can-i-get-the-cpu-core-number-from-within-a-user-space-app-linux-c
So when running a multicore program, we may see that each thread can be running on a different core.
The cores in which the process runs can be fixed with `sched_setaffinity` as shown at: link:userland/linux/sched_getaffinity.c[].
=== Linux calling conventions
A summary of results is shown at: xref:table-linux-calling-conventions[xrefstyle=full].