Using cpuset

So there are certain long-running daily processes to which I would like to assign a specific CPU.

I can do this by checking the pid after starting the process up (e.g. sh -c 'echo $$; exec command' or a little script to extract the pid), and then using the pid in a cpuset command.

Is there a more direct/obvious way to do this?

Alternatively I can start such processes inside a specific jail and assign a cpu to the jail. But then I would have to have a little startup script to get the jail id based on the jail name from an awk, and then use the jail id in a cpuset command.

Is there a more direct/obvious way to do this?
 
Good question. I noticed that Firefox is far better restricted with CPUSET when given only two cores than with NICE. However I cannot launch firefox with cpuset as normal user. Is there any way to do that? :)
 
So there are certain long-running daily processes to which I would like to assign a specific CPU.

I can do this by checking the pid after starting the process up (e.g. sh -c 'echo $$; exec command' or a little script to extract the pid), and then using the pid in a cpuset command.

Is there a more direct/obvious way to do this?
I don't know of one.
What does work is inheritance: if by some means the invoking process already has a cpuset assigned, a child process will inherit that. If this is useful, depends on how you invoke your processes.
Alternatively I can start such processes inside a specific jail and assign a cpu to the jail. But then I would have to have a little startup script to get the jail id based on the jail name from an awk, and then use the jail id in a cpuset command.

Is there a more direct/obvious way to do this?
Jails do already have a cpuset: jls cpuset.id. So alongside with the special cpuset 1 which is the default for the base system, each jail has another special cpuset as it's default.
(Behaviour of these special cpusets appears to have changed from Rel.11 to Rel.12, and in Rel.12 they behave a bit strange when modifying their mask and are somehow interdependent with cpuset 1 - that would need further research; and don't know about Rel.13).
Good question. I noticed that Firefox is far better restricted with CPUSET when given only two cores than with NICE. However I cannot launch firefox with cpuset as normal user. Is there any way to do that? :)
Why not? I can run commands with cpuset as normal user:
Code:
$ for i in 0 1 2 3; do
> cpuset -l $i procstat -aS | grep procstat
> done
 3768 101654 procstat            -                     0    6 0
 3770 101299 procstat            -                     1    6 1
 3772 101299 procstat            -                     2    6 2
 3774 101299 procstat            -                     3    6 3
 
Back
Top