kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: dhylands@gmail.com (Dave Hylands)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Linux kernel thread model
Date: Thu, 16 Jun 2011 14:54:21 -0700	[thread overview]
Message-ID: <BANLkTi=jXhCQdpPi5ECxVcgWV3ay8Tv6Cg@mail.gmail.com> (raw)
In-Reply-To: <BANLkTikoZ5mc2YtvXK1mRYmuPKB1c4TDpA@mail.gmail.com>

Hi Mulyadi,

On Thu, Jun 16, 2011 at 10:37 AM, Mulyadi Santosa
<mulyadi.santosa@gmail.com> wrote:
> On Thu, Jun 16, 2011 at 14:06, manish honap
> <manish_honap_vit@yahoo.co.in> wrote:
>> How they understand whether kernel part is scheduled or user part is scheduled ?
>
> not sure if I got your question correctly, but the one that is
> scheduled is the process..... 1:1 model means for single
> fork()/clone()/pthread_create() in user space, clone() syscall with
> various parameters are called in kernel space. Then, we end up
> creating single process. This represent that whole single thread.

A few clarifications. I like to think of a process as a memory space,
and a thread as a unit of execution.

Many processes have a single thread, but processes can have mutliple
threads as well.

Each thread has a kernel side and a user-mode side. The kernel mode
portion has its own stack which is separate from the user-mode stack,
but you can think of them all together as being a single thread.

You can view all of the processes in the system by using

ls -d /proc/[0-9]*

You can view all of the threads in the system by using

ls -d /proc/[0-9]*/task/*

Due to historical reasons, we have some confusing terminology which is
different between kernel space and user-space.
The numbers under the task directory are called tids in user-space,
but are called pids in kernel space (i.e. current->pid)
The numbers under the proc directory are called pids in user-space,
but are called tgid in kernel space (i.e. current->tgid)

When running in kernel space, the kernel component of the thread runs
(so the kernel thread-stack is used). When running in user-space, the
user component of the thread tuns (so the user-space stack is used).
When scheduling, you're scheduling the thread as a whole, and not the
kernel-side or user-side component.

If you write a driver or loadable module, you can create kernel
threads which have no user-mode portion, but you can't create a
user-mode thread which doesn't have a kernel side component.
kernel mode threads appear to be their own process, which is where my
process=memory space model break down, but for user space it holds.

-- 
Dave Hylands
Shuswap, BC, Canada
http://www.davehylands.com

  reply	other threads:[~2011-06-16 21:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-16  4:39 Linux kernel thread model manish honap
2011-06-16  5:15 ` Mulyadi Santosa
2011-06-16  7:06   ` manish honap
2011-06-16 17:37     ` Mulyadi Santosa
2011-06-16 21:54       ` Dave Hylands [this message]
2011-06-17  5:26 ` Prashant Shah

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='BANLkTi=jXhCQdpPi5ECxVcgWV3ay8Tv6Cg@mail.gmail.com' \
    --to=dhylands@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).