lkml.org 
[lkml]   [2000]   [Feb]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: how does kernel get the "current" task struct?
Mitchell Blank Jr wrote:
>
> Jun Sun wrote:
> > static inline struct task_struct * get_current(void)
> > {
> > struct task_struct *current;
> > __asm__("andl %%esp,%0; ":"=r" (current) : "0" (~8191UL));
> > return current;
> > }
> [...]
> > Basically, the pointer to the current task_struct is the current stack
> > pointer(%esp) substracted by 8K.
>
> No, it's AND'ed with 0xFFFFE000
>

Oops! My mistake. Mistook "andl" as "addl".

> "current"'s task-struct is stored at the beginning of the kernel-land
> stack space. get_current just clears out the low-order bits from the
> current stack pointer to get the first address. Neat little
> efficiency trick, since it keeps the address of the commonly-used
> "current" struct without dereferencing a pointer in memory, plus
> it automatically follows the currently running kernel thread.
>

I suppose if you have a global pointer "current", you don't even need
to do "andl" instruction. (But you will need to update "current"
whenever
a context switch happens, and you'll probably have a "current" array in
the CMP version.)


> > In addition, how can we have different "current" values for different
> > CPUs in
> > the SMP version?
>
> "current" is the task_struct of the thread that queries it - it
> has nothing to do with what is running on the other CPUs.
>

I see.

This question is not related, but if you want to know which process
is running on another CPU, which data structure tells you that?


Jun

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:56    [W:0.078 / U:0.108 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site