LKML Archive mirror
 help / color / mirror / Atom feed
* Thread Affinity structure
@ 2011-02-04 17:11 Sri Ram Vemulpali
  2011-02-04 19:29 ` Christoph Lameter
  0 siblings, 1 reply; 4+ messages in thread
From: Sri Ram Vemulpali @ 2011-02-04 17:11 UTC (permalink / raw
  To: Kernel-newbies, linux-kernel-mail

Hi all,

    I have doubt regarding how the thread affinity (to processor) is
defined in a process (task). If there is only single thread in a
process, then when process calls itself on binding to a core, will let
run on that core forever. But, what if there are multiple threads, in
a process (task). If the main thread calls set affinity to a core, is
it going to get inherited to all other threads, or just the calling
thread in a task. What happens when forked a process with threads that
has affinity to a core. Please can anyone point me to the literature
on this. Thanks in advance.

-- 
Regards,
Sri.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Thread Affinity structure
  2011-02-04 17:11 Thread Affinity structure Sri Ram Vemulpali
@ 2011-02-04 19:29 ` Christoph Lameter
  2011-02-04 20:05   ` Sri Ram Vemulpali
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Lameter @ 2011-02-04 19:29 UTC (permalink / raw
  To: Sri Ram Vemulpali; +Cc: Kernel-newbies, linux-kernel-mail

On Fri, 4 Feb 2011, Sri Ram Vemulpali wrote:

>     I have doubt regarding how the thread affinity (to processor) is
> defined in a process (task). If there is only single thread in a
> process, then when process calls itself on binding to a core, will let
> run on that core forever. But, what if there are multiple threads, in
> a process (task). If the main thread calls set affinity to a core, is
> it going to get inherited to all other threads, or just the calling
> thread in a task. What happens when forked a process with threads that
> has affinity to a core. Please can anyone point me to the literature
> on this. Thanks in advance.

See "man sched_setaffinity"

"
The affinity mask is actually a per-thread attribute that can be
adjusted independently for each of the threads in a thread group.  The
value returned  from a call to gettid(2) can be passed in the argument
pid.  Specifying pid as 0 will set the attribute for the calling thread,
and passing the value returned from a call to getpid(2) will set the
attribute for the main thread of the thread group.  (If you  are  using
the  POSIX threads API, then use pthread_setaffinity_np(3) instead of
sched_setaffinity().)
"



The setting of the affinity occurs for the running thread if pid == 0.
Affinity masks are inherited across forks.






^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Thread Affinity structure
  2011-02-04 19:29 ` Christoph Lameter
@ 2011-02-04 20:05   ` Sri Ram Vemulpali
  2011-02-04 20:13     ` Christoph Lameter
  0 siblings, 1 reply; 4+ messages in thread
From: Sri Ram Vemulpali @ 2011-02-04 20:05 UTC (permalink / raw
  To: Christoph Lameter; +Cc: Kernel-newbies, linux-kernel-mail

Hi Christoph,

  Thanks for response. Can you please explain in little bit elaborate
what do you mean

 "The value returned  from a call to gettid(2) can be passed in the argument
 pid.  Specifying pid as 0 will set the attribute for the calling thread,
 and passing the value returned from a call to getpid(2) will set the
 attribute for the main thread of the thread group."

To whom I should pass the id. I did not understood.

Thanks,
Sri.

On Fri, Feb 4, 2011 at 2:29 PM, Christoph Lameter <cl@linux.com> wrote:
> On Fri, 4 Feb 2011, Sri Ram Vemulpali wrote:
>
>>     I have doubt regarding how the thread affinity (to processor) is
>> defined in a process (task). If there is only single thread in a
>> process, then when process calls itself on binding to a core, will let
>> run on that core forever. But, what if there are multiple threads, in
>> a process (task). If the main thread calls set affinity to a core, is
>> it going to get inherited to all other threads, or just the calling
>> thread in a task. What happens when forked a process with threads that
>> has affinity to a core. Please can anyone point me to the literature
>> on this. Thanks in advance.
>
> See "man sched_setaffinity"
>
> "
> The affinity mask is actually a per-thread attribute that can be
> adjusted independently for each of the threads in a thread group.  The
> value returned  from a call to gettid(2) can be passed in the argument
> pid.  Specifying pid as 0 will set the attribute for the calling thread,
> and passing the value returned from a call to getpid(2) will set the
> attribute for the main thread of the thread group.  (If you  are  using
> the  POSIX threads API, then use pthread_setaffinity_np(3) instead of
> sched_setaffinity().)
> "
>
>
>
> The setting of the affinity occurs for the running thread if pid == 0.
> Affinity masks are inherited across forks.
>
>
>
>
>
>



-- 
Regards,
Sri.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Thread Affinity structure
  2011-02-04 20:05   ` Sri Ram Vemulpali
@ 2011-02-04 20:13     ` Christoph Lameter
  0 siblings, 0 replies; 4+ messages in thread
From: Christoph Lameter @ 2011-02-04 20:13 UTC (permalink / raw
  To: Sri Ram Vemulpali; +Cc: Kernel-newbies, linux-kernel-mail

[-- Attachment #1: Type: TEXT/PLAIN, Size: 651 bytes --]

On Fri, 4 Feb 2011, Sri Ram Vemulpali wrote:

> Hi Christoph,
>
>   Thanks for response. Can you please explain in little bit elaborate
> what do you mean
>
>  "The value returned  from a call to gettid(2) can be passed in the argument
>  pid.  Specifying pid as 0 will set the attribute for the calling thread,
>  and passing the value returned from a call to getpid(2) will set the
>  attribute for the main thread of the thread group."
>
> To whom I should pass the id. I did not understood.

The passage was from the man page that you get by typing

man sched_setaffinity


You pass the id as a parameter to sched_setaffinity.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-02-04 20:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-04 17:11 Thread Affinity structure Sri Ram Vemulpali
2011-02-04 19:29 ` Christoph Lameter
2011-02-04 20:05   ` Sri Ram Vemulpali
2011-02-04 20:13     ` Christoph Lameter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).