In my opinion, the expanded the macro will be:
extern __typeof__(struct task_struct *) per_cpu_current_task;
...
__typeof__(per_cpu_current_task) __ret;
switch (sizeof(per_cpu_current_task))
...
case 4: \
asm("mov" "l " __percpu_seg"%1,%0" \
: "-r" (__ret) \
: "m" (per_cpu_current_task) \
break; \
...
__ret has the output value, which is what we want: the pointer
points to the currrent task's task_struct. per_cpu_current_task
is the offset of some segment?
finally translated into this:
movl %1,%0
or
movl %%fs:%1,%0
(that macro__percpu_seg() means "" on a non-SMP machine, or
"%%fs:" on a SMP machine.)
Let's say I have a non-SMP machine, how dose that give me the
pointer? I googled my answer, found that, every CPU has a private
data zone, it contains the pointer to current task_struct. And I still
have a question: where is that segment (pointed by which segment
register)? And where in that segment containes the pointer we want?
On 8/2/07, Mulyadi Santosa
<mulyadi.santosa@xxxxxxxxx> wrote:
Hi Paul....
> can anyone tell me how does the code above give me current task_struct
> structure? and what about current_thread_info() function? is it useless now?
let me try to intepret it for you...
First, to ease our understanding, let's convert :
return x86_read_percpu(current_task)
to:
percpu_from_op("mov", per_cpu__current_task)
ret__ is probably the variable which substitute the name real variable
that is referred by the above "return x86_read_percpu". Assume we hit
the third case ("case 3:"), I think if the asm macro is expanded, we
will see:
mov __percpu_seg(var), ret__
Note: Above is my best guess on what the asm block mean:
So for the final puzzle, could you check what __percpu_seg() means?
regards,
Mulyadi
--
Paul Francisco = pAnk7.yArdbird
http://pank7yardbird.googlepages.com
http://hi.baidu.com/pank7
.' ' ` . pAnk7.yArdbird ^_^
: :' : pank7yardbird(AT)gmail.com
`. ` ' liyi(AT)net.pku.edu.cn
`- Debian GNU/Linux -- The power of reedom