All of lore.kernel.org
 help / color / mirror / Atom feed
* Linux process and threads, CPU Affinity
@ 2013-09-13  7:43 manty kuma
  2013-09-13  8:21 ` Silviu Popescu
  0 siblings, 1 reply; 2+ messages in thread
From: manty kuma @ 2013-09-13  7:43 UTC (permalink / raw)
  To: kernelnewbies

I have few queries related to threads and Process scheduling in Linux.

   1. When my process goes into sleep and wakes back, is it always that it
   will be scheduled on the same CPU that it got scheduled before?
   2. When i create a thread from the process, Will it also be executed on
   the same CPU always? Even if other CPU's are free and sleeping.

I would like to know the mechanism in Linux in specific. Also i am creating
the threads through pthread library. I am facing a random hangup issue
which is always not reproducible. Need this information to proceed in the
right direction.


I have also posted a query for the same SO. But no constructive reply.
Hence re-posting it here.

http://stackoverflow.com/questions/18779947/linux-threads-and-process-cpu-affinity
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130913/7c609b0a/attachment.html 

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

* Linux process and threads, CPU Affinity
  2013-09-13  7:43 Linux process and threads, CPU Affinity manty kuma
@ 2013-09-13  8:21 ` Silviu Popescu
  0 siblings, 0 replies; 2+ messages in thread
From: Silviu Popescu @ 2013-09-13  8:21 UTC (permalink / raw)
  To: kernelnewbies

On Fri, Sep 13, 2013 at 10:43 AM, manty kuma <mantykuma@gmail.com> wrote:
> I have few queries related to threads and Process scheduling in Linux.
>
> When my process goes into sleep and wakes back, is it always that it will be
> scheduled on the same CPU that it got scheduled before?
> When i create a thread from the process, Will it also be executed on the
> same CPU always? Even if other CPU's are free and sleeping.
>
> I would like to know the mechanism in Linux in specific. Also i am creating
> the threads through pthread library. I am facing a random hangup issue which
> is always not reproducible. Need this information to proceed in the right
> direction.
>
>
> I have also posted a query for the same SO. But no constructive reply. Hence
> re-posting it here.
>
> http://stackoverflow.com/questions/18779947/linux-threads-and-process-cpu-affinity

Hello,

The answer you received on the SO thread seems accurate to me.
User-space processes and threads both map to something called tasks in
the kernel. They are both seem as execution units, but threads share
everything (code, data, open files) except registers and stack. So
they are treated the same by the kernel in terms of scheduling.

If a task sleeps as a result of I/O, signal or time slice exceeded it
is no longer run on the CPU and when it resumes running it is the
scheduler policy that decides how the task is rescheduled. I believe
the policy decides how to take into account the affinity, meaning that
you could set the affinity and the scheduler might ignore it.

The article at [1] demonstrates how to use CPU affinity and [2] and
[3] show how to change the affinity and scheduler policy.

[1] http://www.ibm.com/developerworks/linux/library/l-affinity/index.html
[2] http://man7.org/linux/man-pages/man2/sched_setaffinity.2.html
[3] http://man7.org/linux/man-pages/man2/sched_setscheduler.2.html

-- 
Silviu Popescu

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

end of thread, other threads:[~2013-09-13  8:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-13  7:43 Linux process and threads, CPU Affinity manty kuma
2013-09-13  8:21 ` Silviu Popescu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.