Thanks! !

As I understand , a TLB flush is an expenive operation.

   Have anybody any idea if there is a TLB flush (on x86) when there is a
context switch between two kernel threads ?

   My guess is that there is no need for such a TLB flush (on x86) since
the kernel thread does not need to access virtual addresses of
the user space. (But  I am not sure about it, because a kernel thread DOES
have access to 1GB virtual address space of the kernel ).

(To be more precise,and If I remember well from Love's kernel book,
the  task struct has 2 mm_struct
members : mm and mm_acive;  and in case of kernel_thread mm is NULL
,but active_mm gets
the value of previous thread , but in fact it needs ONLY the kernel
address space part of it because anyhow a kernel thread is NOT allowed to use
the user space address space.)

And to verify one more thing, if I may : when there is a context
switch between 2 ***user space*** threads,is  there ALWAYS a TLB
flush?

Rafi G.




On 11/22/05, Muli Ben-Yehuda <[EMAIL PROTECTED]> wrote:
> 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