Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] Init scripts and changing cpu affinity with taskset
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
zirtik
n00b
n00b


Joined: 15 Apr 2011
Posts: 13

PostPosted: Tue May 15, 2012 8:03 pm    Post subject: [SOLVED] Init scripts and changing cpu affinity with taskset Reply with quote

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:

Code:

taskset -p 1


I see that it can still use all cores available in the system. Also, if I run:

Code:
rc-status sysinit


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
View user's profile Send private message
SlashBeast
Retired Dev
Retired Dev


Joined: 23 May 2006
Posts: 2922

PostPosted: Tue May 15, 2012 8:20 pm    Post subject: Reply with quote

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
View user's profile Send private message
zirtik
n00b
n00b


Joined: 15 Apr 2011
Posts: 13

PostPosted: Tue May 15, 2012 8:38 pm    Post subject: Reply with quote

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
View user's profile Send private message
zirtik
n00b
n00b


Joined: 15 Apr 2011
Posts: 13

PostPosted: Tue May 15, 2012 9:31 pm    Post subject: Reply with quote

I just did an

Code:
rc-update -u
and rebuilt the dependency tree. It solved the problem.
Back to top
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Wed May 16, 2012 2:54 am    Post subject: Re: [SOLVED] Init scripts and changing cpu affinity with tas Reply with quote

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
View user's profile Send private message
zirtik
n00b
n00b


Joined: 15 Apr 2011
Posts: 13

PostPosted: Mon May 21, 2012 5:42 pm    Post subject: Reply with quote

I was actually rebooting it but for some reason it didn't work. Do you think specifying the full path as
Code:
/etc/init.d/affty
was the problem that messed up the dependency calculation?
Back to top
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Mon May 21, 2012 11:25 pm    Post subject: Reply with quote

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
View user's profile Send private message
zirtik
n00b
n00b


Joined: 15 Apr 2011
Posts: 13

PostPosted: Tue May 22, 2012 2:33 pm    Post subject: Reply with quote

Alright, thank you steveL. I'll keep that in mind.
Back to top
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Wed May 23, 2012 12:38 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum