[PATCH] Allow atomic sets of non-overlapping CPU sets for a global cpuset

John Baldwin jhb at freebsd.org
Wed Jun 5 15:13:46 UTC 2013


On Friday, May 31, 2013 12:16:56 pm John Baldwin wrote:
> So there's an oddity with cpuset I've run into recently at work.  Suppose I 
> have created a new cpuset and want to change the set of CPUs for that set (say 
> from a mask of just CPU 1 to a mask of just CPU 2).  I can't do that 
> atomically.  I have to first set the mask to contain both the old set (CPU 1) 
> and the new set (CPU 2) and then change it a second time to only contain the 
> new set (CPU 2).  The reason is that cpuset_modify() runs cpuset_testupdate() 
> on the set it is about to modify, so when I try to change it in a single 
> operation the new mask doesn't overlap with the old mask and it fails with 
> EDEADLK.
> 
> % cpuset -c -l 1 /bin/sh
> $ cpuset -gi
> pid -1 cpuset id: 2
> $ cpuset -g
> pid -1 mask: 1
> $ cpuset -l 2 -s 2
> cpuset: setaffinity: Resource deadlock avoided

Also note that non-overlapping masks work fine if you change the "local" mask
of a process:

% cpuset -l 1 /bin/sh
$ cpuset -g
pid -1 mask: 1
$ cpuset -l 2 -p $$
$ cpuset -g
pid -1 mask: 2

-- 
John Baldwin


More information about the freebsd-arch mailing list