On Tue, Nov 22, 2005 at 12:02:12PM +0200, Rafi Gordon wrote:
> Is the cost , in terms of CPU , when there occurs a context switch
> between two kernel threads is the same as when
> there is a context switch between two user space threads ?

userspace threads are mapped to kernel threads in Linux (more
accurately, userspace threads are represented by tasks in a 1-1
mapping).

> Is this cost the same when there is a context switch between a kernel
> thread and a user space thread ?

No. A switch between userspace threads in Linux requires switching to
kernel space first. There's no support by default for userspace
threading.

> If you look at the implementation of kernel_thread() method (in i386 it's in
> arch/i386/kernel/process.c), you will see that it ultimately
> calls do_fork() ; in fact also when you create a user space process/thread by
> fork() or pthread_create() you also ultimately call do_fork().
> 
> There are of course some differences between kernel threads
> and user space threads.
> for example : a kernel thread does not have any need for access to memory
> of user space.
> 
> But do these differences cause a conetxt switch between 2 kernel
> threads to be quicker ?

Yes. Since there's no need to switch address spaces or priviledge
levels to ctx switch between two kernel threads, it's just th overhead
of the scheduler and ctx_switch itself.

Cheers,
Muli
-- 
Muli Ben-Yehuda
http://www.mulix.org | http://mulix.livejournal.com/


=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to