* distinguish kernel thread / user task
@ 2004-12-03 17:16 Sylvain
2004-12-03 19:24 ` Brian Gerst
0 siblings, 1 reply; 5+ messages in thread
From: Sylvain @ 2004-12-03 17:16 UTC (permalink / raw)
To: Linux Kernel
Hi all,
I have little question while doing some kernel implementation.
How can I distinguish whether a task_struct is actually kernel thread
or mere user task?
My idea was to look at task_struct "mm" field to discriminate them,
but that was wrong...
Thanks,
Sylvain
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: distinguish kernel thread / user task
2004-12-03 17:16 distinguish kernel thread / user task Sylvain
@ 2004-12-03 19:24 ` Brian Gerst
2004-12-03 20:15 ` Sylvain
0 siblings, 1 reply; 5+ messages in thread
From: Brian Gerst @ 2004-12-03 19:24 UTC (permalink / raw)
To: Sylvain; +Cc: Linux Kernel
Sylvain wrote:
> Hi all,
>
> I have little question while doing some kernel implementation.
> How can I distinguish whether a task_struct is actually kernel thread
> or mere user task?
>
> My idea was to look at task_struct "mm" field to discriminate them,
> but that was wrong...
>
> Thanks,
>
> Sylvain
To the scheduler, a thread is a thread. It doesn't care if it's a
kernel thread or not. The difference is execution context, which is
cpu-dependant. For example, on x86 the difference is in the code
segment the task runs in. Kernel threads run in KERNEL_CS (ring 0), and
user threads run USER_CS (or any other ring 3 code segment, or vm86 mode
set in eflags). Other cpus might have a flag in the status register.
What are you trying to do that you need to know whether a thread is
kernel or user? I suppose if there were a compelling enough reason, a
kernel/user flag could be added to the task struct, set in do_fork() for
kernel threads, and cleared by execve().
--
Brian Gerst
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: distinguish kernel thread / user task
2004-12-03 19:24 ` Brian Gerst
@ 2004-12-03 20:15 ` Sylvain
2004-12-03 20:50 ` Brian Gerst
0 siblings, 1 reply; 5+ messages in thread
From: Sylvain @ 2004-12-03 20:15 UTC (permalink / raw)
To: Brian Gerst; +Cc: Linux Kernel
I am trying to do a tool to record task switching...separating also
kernel/user tasks, but I got some trouble with that last case.
I confused since "ps" is actually able to distinguish kernel thread
from user task.
I wouldn't had a flag if It 's not necessary
Sylvain
On Fri, 03 Dec 2004 14:24:27 -0500, Brian Gerst <bgerst@didntduck.org> wrote:
> Sylvain wrote:
>
>
> > Hi all,
> >
> > I have little question while doing some kernel implementation.
> > How can I distinguish whether a task_struct is actually kernel thread
> > or mere user task?
> >
> > My idea was to look at task_struct "mm" field to discriminate them,
> > but that was wrong...
> >
> > Thanks,
> >
> > Sylvain
>
> To the scheduler, a thread is a thread. It doesn't care if it's a
> kernel thread or not. The difference is execution context, which is
> cpu-dependant. For example, on x86 the difference is in the code
> segment the task runs in. Kernel threads run in KERNEL_CS (ring 0), and
> user threads run USER_CS (or any other ring 3 code segment, or vm86 mode
> set in eflags). Other cpus might have a flag in the status register.
>
> What are you trying to do that you need to know whether a thread is
> kernel or user? I suppose if there were a compelling enough reason, a
> kernel/user flag could be added to the task struct, set in do_fork() for
> kernel threads, and cleared by execve().
>
> --
> Brian Gerst
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: distinguish kernel thread / user task
2004-12-03 20:15 ` Sylvain
@ 2004-12-03 20:50 ` Brian Gerst
2004-12-03 21:32 ` Sylvain
0 siblings, 1 reply; 5+ messages in thread
From: Brian Gerst @ 2004-12-03 20:50 UTC (permalink / raw)
To: Sylvain; +Cc: Linux Kernel
Sylvain wrote:
> I am trying to do a tool to record task switching...separating also
> kernel/user tasks, but I got some trouble with that last case.
>
> I confused since "ps" is actually able to distinguish kernel thread
> from user task.
> I wouldn't had a flag if It 's not necessary
>
> Sylvain
>
Pstools doesn't really know the difference between user and kernel
threads. It only shows kernel threads as swapped out (in brackets)
because they have an RSS of zero (since kernel threads have no mm struct).
--
Brian Gerst
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: distinguish kernel thread / user task
2004-12-03 20:50 ` Brian Gerst
@ 2004-12-03 21:32 ` Sylvain
0 siblings, 0 replies; 5+ messages in thread
From: Sylvain @ 2004-12-03 21:32 UTC (permalink / raw)
To: Brian Gerst; +Cc: Linux Kernel
kernel threads have no mm struct, right.
but it appears some programs (user tasks) haven't either ?! actually,
that what I notice..
Sylvain
On Fri, 03 Dec 2004 15:50:19 -0500, Brian Gerst <bgerst@didntduck.org> wrote:
> Sylvain wrote:
> > I am trying to do a tool to record task switching...separating also
> > kernel/user tasks, but I got some trouble with that last case.
> >
> > I confused since "ps" is actually able to distinguish kernel thread
> > from user task.
> > I wouldn't had a flag if It 's not necessary
> >
> > Sylvain
> >
>
> Pstools doesn't really know the difference between user and kernel
> threads. It only shows kernel threads as swapped out (in brackets)
> because they have an RSS of zero (since kernel threads have no mm struct).
>
> --
> Brian Gerst
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-12-03 21:32 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-03 17:16 distinguish kernel thread / user task Sylvain
2004-12-03 19:24 ` Brian Gerst
2004-12-03 20:15 ` Sylvain
2004-12-03 20:50 ` Brian Gerst
2004-12-03 21:32 ` Sylvain
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).