View previous topic :: View next topic |
Author |
Message |
zirtik n00b
Joined: 15 Apr 2011 Posts: 13
|
Posted: Tue May 15, 2012 8:03 pm Post subject: [SOLVED] Init scripts and changing cpu affinity with taskset |
|
|
Hi,
I have a 6-core system and I would like to change the affinity of all processes to restrict them to use only the first four cores. I know what I'm doing, and I'll use the last two cores for a special purpose. I created a new init script under /etc/init.d/affty and here is its contents:
Code: | #!/sbin/runscript
description="Set processor affinity"
depend() {
before *
}
start() {
/usr/bin/taskset -cp 0,1,2,3 1
/usr/bin/taskset -cp 0,1,2,3 $$
}
|
I added the script to sysinit runlevel by issuing:
Code: | rc-update add /etc/init.d/affty sysinit | and restarted my computer. However, when I run:
I see that it can still use all cores available in the system. Also, if I run:
I see that affty is not started. The weirdest thing is that this only happens in one computer. I have the same exact hardware with the same configuration and that one seems to work just fine.
Any ideas? I've been stuck with this for over two days already.
Last edited by zirtik on Tue May 15, 2012 9:32 pm; edited 1 time in total |
|
Back to top |
|
|
SlashBeast Retired Dev
Joined: 23 May 2006 Posts: 2922
|
Posted: Tue May 15, 2012 8:20 pm Post subject: |
|
|
You better use cgroups's cpuset to do it. Or hack runscript.sh to exec your fancy app always, whenever runscript is done. |
|
Back to top |
|
|
zirtik n00b
Joined: 15 Apr 2011 Posts: 13
|
Posted: Tue May 15, 2012 8:38 pm Post subject: |
|
|
Thank you. But I have a pretty good feeling that it has something to do with the launching of the init script. The same configuration works in my other machine. When I type
Code: | /etc/init.d/affty status |
I can see that the service has been stopped. What would cause this? |
|
Back to top |
|
|
zirtik n00b
Joined: 15 Apr 2011 Posts: 13
|
Posted: Tue May 15, 2012 9:31 pm Post subject: |
|
|
I just did an
and rebuilt the dependency tree. It solved the problem. |
|
Back to top |
|
|
steveL Watchman
Joined: 13 Sep 2006 Posts: 5153 Location: The Peanut Gallery
|
Posted: Wed May 16, 2012 2:54 am Post subject: Re: [SOLVED] Init scripts and changing cpu affinity with tas |
|
|
Only thing that stuck out was:
Code: | rc-update add /etc/init.d/affty sysinit |
which is more usually done as:
Code: | rc-update add affty sysinit |
(just for future ref, in case it makes a difference; the dependency calculation is normally done at reboot, so if you weren't rebooting that might explain it.) |
|
Back to top |
|
|
zirtik n00b
Joined: 15 Apr 2011 Posts: 13
|
Posted: Mon May 21, 2012 5:42 pm Post subject: |
|
|
I was actually rebooting it but for some reason it didn't work. Do you think specifying the full path as was the problem that messed up the dependency calculation? |
|
Back to top |
|
|
steveL Watchman
Joined: 13 Sep 2006 Posts: 5153 Location: The Peanut Gallery
|
Posted: Mon May 21, 2012 11:25 pm Post subject: |
|
|
I'm not sure, but it could be; someone else was trying to get a script in /opt to run and, while rc-update seemed to accept the path, it didn't actually boot. |
|
Back to top |
|
|
zirtik n00b
Joined: 15 Apr 2011 Posts: 13
|
Posted: Tue May 22, 2012 2:33 pm Post subject: |
|
|
Alright, thank you steveL. I'll keep that in mind. |
|
Back to top |
|
|
steveL Watchman
Joined: 13 Sep 2006 Posts: 5153 Location: The Peanut Gallery
|
Posted: Wed May 23, 2012 12:38 pm Post subject: |
|
|
You're welcome zirtik :)
FWIW I found a relevant bug when I looked to report the issue of rc-update accepting paths which it then didn't boot. This is the other topic where it happened (with a path in /opt.)
The linked one shows there was a problem, but I think that could be fixed with applet = basename_c(argv[1]); instead of applet = basename_c(service); which would allow the use of service = realpath(argv[1], NULL);.
Hopefully it'll get fixed soon. |
|
Back to top |
|
|
|