Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Discussion & Documentation Documentation, Tips & Tricks
  • Search

[SOLVED] Init scripts and changing cpu affinity with taskset

Unofficial documentation for various parts of Gentoo Linux. Note: This is not a support forum.
Post Reply
Advanced search
9 posts • Page 1 of 1
Author
Message
zirtik
n00b
n00b
Posts: 13
Joined: Fri Apr 15, 2011 2:47 pm

[SOLVED] Init scripts and changing cpu affinity with taskset

  • Quote

Post by zirtik » Tue May 15, 2012 8:03 pm

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: Select all

#!/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: Select all

rc-update add /etc/init.d/affty sysinit 
and restarted my computer. However, when I run:

Code: Select all

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

Code: Select all

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.
Top
SlashBeast
Retired Dev
Retired Dev
User avatar
Posts: 2922
Joined: Tue May 23, 2006 11:50 am
Contact:
Contact SlashBeast
Website

  • Quote

Post by SlashBeast » Tue May 15, 2012 8:20 pm

You better use cgroups's cpuset to do it. Or hack runscript.sh to exec your fancy app always, whenever runscript is done.
Top
zirtik
n00b
n00b
Posts: 13
Joined: Fri Apr 15, 2011 2:47 pm

  • Quote

Post by zirtik » Tue May 15, 2012 8:38 pm

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: Select all

/etc/init.d/affty status
I can see that the service has been stopped. What would cause this?
Top
zirtik
n00b
n00b
Posts: 13
Joined: Fri Apr 15, 2011 2:47 pm

  • Quote

Post by zirtik » Tue May 15, 2012 9:31 pm

I just did an

Code: Select all

rc-update -u
and rebuilt the dependency tree. It solved the problem.
Top
steveL
Watchman
Watchman
Posts: 5153
Joined: Wed Sep 13, 2006 1:18 pm
Location: The Peanut Gallery

Re: [SOLVED] Init scripts and changing cpu affinity with tas

  • Quote

Post by steveL » Wed May 16, 2012 2:54 am

Only thing that stuck out was:

Code: Select all

rc-update add /etc/init.d/affty sysinit
which is more usually done as:

Code: Select all

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.)
Top
zirtik
n00b
n00b
Posts: 13
Joined: Fri Apr 15, 2011 2:47 pm

  • Quote

Post by zirtik » Mon May 21, 2012 5:42 pm

I was actually rebooting it but for some reason it didn't work. Do you think specifying the full path as

Code: Select all

/etc/init.d/affty
was the problem that messed up the dependency calculation?
Top
steveL
Watchman
Watchman
Posts: 5153
Joined: Wed Sep 13, 2006 1:18 pm
Location: The Peanut Gallery

  • Quote

Post by steveL » Mon May 21, 2012 11:25 pm

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.
Top
zirtik
n00b
n00b
Posts: 13
Joined: Fri Apr 15, 2011 2:47 pm

  • Quote

Post by zirtik » Tue May 22, 2012 2:33 pm

Alright, thank you steveL. I'll keep that in mind.
Top
steveL
Watchman
Watchman
Posts: 5153
Joined: Wed Sep 13, 2006 1:18 pm
Location: The Peanut Gallery

  • Quote

Post by steveL » Wed May 23, 2012 12:38 pm

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.
Top
Post Reply

9 posts • Page 1 of 1

Return to “Documentation, Tips & Tricks”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Authors
Gentoo is a trademark of the Gentoo Foundation, Inc. and of Förderverein Gentoo e.V.
The contents of this document, unless otherwise expressly stated, are licensed under the CC-BY-SA-4.0 license.
The Gentoo Name and Logo Usage Guidelines apply.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy