Dubious return code from sched_setaffinity() in boxes used in cgroups
Issue
I'm on a box that is using cgroups, and this shows that sched_setaffinity() returns 0 if an attempt to set affinity contains a valid CPU, but also contains invalid cores in the call.
[root@abc123 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.2 (Santiago)
[root@abc123 ~]# uname -r
2.6.32-220.4.1.el6.x86_64
[root@abc123 ~]# lscgroup
cpuset:/
cpuset:/gfprod
cpuset:/gfprod/socket1_5cores
cpuset:/gfprod/socket0_5cores
cpuset:/sysdefault
cpu:/
cpuacct:/
memory:/
devices:/
freezer:/
net_cls:/
blkio:/
[root@abc123 ~]# cat /cgroup/cpuset/sysdefault/cpuset.cpu_exclusive
0
[root@abc123 ~]# cat /cgroup/cpuset/sysdefault/cpuset.cpus
0
[root@abc123 ~]# taskset -pc $$
pid 30748's current affinity list: 0
Call with valid CPU 0 and two that are not available to be set.
[root@abc123 ~]# strace taskset -pc 0-3 $$ 2>&1 | grep setaffin
sched_setaffinity(30748, 256, { f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }) = 0
Here we see sched_setaffinity returns 0. This is misleading, because the caller will probably test the return code and assume they've set affinity to three CPUs when in fact they have not.
[root@abc123 ~]# taskset -pc $$
pid 30748's current affinity list: 0
Now we call it with ONLY an invalid CPU and it fails.
[root@abc123 ~]# taskset -pc 5 $$ 2>&1 | grep setaffin
sched_setaffinity: Invalid argument
Environment
Red Hat Enterprise Linux
6.2
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.