[PATCH v3 07/14] sched: Introduce restrict_cpus_allowed_ptr() to limit task CPU affinity

Valentin Schneider valentin.schneider at arm.com
Thu Nov 19 11:57:22 EST 2020


On 19/11/20 16:09, Peter Zijlstra wrote:
> On Thu, Nov 19, 2020 at 01:13:20PM +0000, Will Deacon wrote:
>
>> Sure, but I was talking about what userspace sees, and I don't think it ever
>> sees CPUs that have been hotplugged off, right? That is, sched_getaffinity()
>> masks its result with the active_mask.
>
> # for i in /sys/devices/system/cpu/cpu*/online; do echo -n $i ":"; cat $i; done
> /sys/devices/system/cpu/cpu1/online :0
> /sys/devices/system/cpu/cpu2/online :1
> /sys/devices/system/cpu/cpu3/online :1
> /sys/devices/system/cpu/cpu4/online :1
> /sys/devices/system/cpu/cpu5/online :1
> /sys/devices/system/cpu/cpu6/online :1
> /sys/devices/system/cpu/cpu7/online :1
>
> # grep Cpus_allowed /proc/self/status
> Cpus_allowed:   ff
> Cpus_allowed_list:      0-7
>
>
> :-)

Harumph, so there is that...

$ while true; do continue; done &
$ PID=$!
$ taskset -pc 0-1 $PID
  pid 849's current affinity list: 0-5
  pid 849's new affinity list: 0,1
$ echo 0 > /sys/devices/system/cpu/cpu1/online
  [12578.545726] CPU1: shutdown
  [12578.548454] psci: CPU1 killed (polled 0 ms)
$ taskset -pc $PID
  pid 849's current affinity list: 0
$ cat /proc/$PID/status | grep Cpus
  Cpus_allowed:   03
  Cpus_allowed_list:      0-1



More information about the linux-arm-kernel mailing list