Re: how does kernel get the "current" task struct?

From: Mitchell Blank Jr (mitch@sfgoth.com)
Date: Wed Feb 02 2000 - 19:32:50 EST


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

"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.

> 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.

-Mitch

-
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/



This archive was generated by hypermail 2b29 : Mon Feb 07 2000 - 21:00:08 EST