You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
** all 2 cores were enabled as shown by `sched_getaffinity = 1 1`
1943
+
** the process was randomly assigned to run on core 1 (the second one) as shown by `sched_getcpu = 1`. If we run this several times, it will also run on core 0 sometimes.
1944
+
* then we restrict the affinity to just core 0, and we see that the program was actually moved to core 0
1945
+
1946
+
The number of cores is modified as explained at: <<number-of-cores>>
1947
+
1948
+
`taskset` from the util-linux package sets the initial core affinity of a program:
1949
+
1950
+
....
1951
+
taskset -c 1,1 /sched_getaffinity.out
1952
+
....
1953
+
1954
+
output:
1955
+
1956
+
....
1957
+
sched_getaffinity = 0 1
1958
+
sched_getcpu = 1
1959
+
sched_getaffinity = 1 0
1960
+
sched_getcpu = 0
1961
+
....
1962
+
1963
+
so we see that the affinity was restricted to the second core from the start.
1925
1964
1926
-
TODO: how to do something cool to see that in action?
1965
+
Let's do a QEMU observation to justify this example being in the repository with <<gdb-step-debug-userland-non-init,userland breakpoints>>:
1927
1966
1928
-
I tried to play around with `taskset`, but when I have two CPUs the <<gdb-step-debug-userland-non-init,userland breakpoints>> don't work... Why?
1967
+
....
1968
+
./run -c2 -d -F 'i=0; while true; do taskset -c $i,$i /sched_getaffinity.out; i=$((! $i)); done'
1969
+
....
1970
+
1971
+
on another shell:
1972
+
1973
+
....
1974
+
./rungdb-user kernel_module-1.0/user/sched_getaffinity.out main
1975
+
....
1976
+
1977
+
Then, inside GDB:
1978
+
1979
+
....
1980
+
(gdb) info threads
1981
+
Id Target Id Frame
1982
+
* 1 Thread 1 (CPU#0 [running]) main () at sched_getaffinity.c:30
1983
+
2 Thread 2 (CPU#1 [halted ]) native_safe_halt () at ./arch/x86/include/asm/irqflags.h:55
1984
+
(gdb) c
1985
+
(gdb) info threads
1986
+
Id Target Id Frame
1987
+
1 Thread 1 (CPU#0 [halted ]) native_safe_halt () at ./arch/x86/include/asm/irqflags.h:55
1988
+
* 2 Thread 2 (CPU#1 [running]) main () at sched_getaffinity.c:30
1989
+
(gdb) c
1990
+
....
1991
+
1992
+
So we observe that `info threads` shows the actual correct core on which the process was restricted to run by `taskset`!
1929
1993
1930
1994
We should also try it out with kernel modules: https://stackoverflow.com/questions/28347876/set-cpu-affinity-on-a-loadable-linux-kernel-module
0 commit comments