LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 08-19-2009, 07:35 AM   #1
aloktiagi
LQ Newbie
 
Registered: Jul 2009
Posts: 20

Rep: Reputation: 0
thread affinity for a cpu core


Is there a way to assign cpu core affinity for a thread.

for a process it is sched_setaffinity(), but i can't find one for a thread.

thanks
 
Old 08-20-2009, 08:03 AM   #2
Pearlseattle
Member
 
Registered: Aug 2007
Location: Switzerland
Distribution: Gentoo
Posts: 716

Rep: Reputation: 81
Hello
So, this...
Quote:
Function: int sched_setaffinity (pid_t pid, size_t cpusetsize, const cpu_set_t *cpuset)
This function installs the cpusetsize bytes long affinity mask pointed to by cpuset for the process or thread with the ID pid.
...is not true?
Greetings
 
Old 08-20-2009, 09:41 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
Indeed, but I think he wants to be able to put separate threads on separate cpus.
That doc implies (as per kernel 2.4.x) that a thread has its own pid. As of kernel 2.6, this is no longer true... the threads for a given process are inside the process, and therefore there is only one pid as shown by the top cmd.
BTW, only one copy of the pid shows up, even if you have many threads.
 
Old 08-21-2009, 04:23 AM   #4
aloktiagi
LQ Newbie
 
Registered: Jul 2009
Posts: 20

Original Poster
Rep: Reputation: 0
thanks

so is there a functions to set thread affinity even though we can't see it in top command?
 
Old 08-21-2009, 06:53 AM   #5
Pearlseattle
Member
 
Registered: Aug 2007
Location: Switzerland
Distribution: Gentoo
Posts: 716

Rep: Reputation: 81
Hi chrism01
Interesting reply.
I just had a look at my webserver using "htop", and I see the usual list of apache and jvm entries. I thought that, apart from the main calling program, all of them were threads, and I see that all of them have different pids.
And I am programming since a while in C++ & QT a small app (on my notebook) which starts a separate QT-Thread ("QThread") and it gets a different PID than the main calling program.
Both the webserver & the notebook have 2.6.x-Kernels (Notebook 2.6.28).

But yes, I remember that in the past I saw threads having the same pid as the main program, but I cannot remember anymore where - perhaps it was on a AIX system.

So, perhaps there are threads and threads? Different types?
Greetings
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting thread affinity lennyk Programming 1 02-17-2009 02:56 AM
CPU binding - How to modify the CPU affinity mask? Thaidog Linux - General 1 03-15-2008 06:54 PM
cpu affinity process hlds multiple CosmicDebris Linux - Games 2 01-09-2008 02:55 PM
CPU affinity on kernel 2.4.14-SMP tsik Linux - Kernel 0 11-05-2007 10:27 PM
Processor affinity and cpu scheduling...? Thaidog Linux - Newbie 5 01-09-2003 08:08 PM


All times are GMT -5. The time now is 11:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration