Re: [PATCH] update fix X86_64 procfs provide stack information forthreads

From: Stefani Seibold
Date: Wed Nov 04 2009 - 06:50:21 EST


Am Mittwoch, den 04.11.2009, 12:17 +0100 schrieb Andi Kleen:
> Stefani Seibold <stefani@xxxxxxxxxxx> writes:
> >
> > +#ifdef CONFIG_IA32_EMULATION
> > +unsigned long KSTK_ESP(struct task_struct *task)
> > +{
> > + return (test_tsk_thread_flag(task, TIF_IA32)) ? \
> > + (task_pt_regs(task)->sp) : \
> > + ((task)->thread.usersp);
>
> Usersp is only set for system calls, but not when the process is blocked
> in a interrupt.
>
> In general if you really want a reliable implementation of this
> you would really need to stop the task and grab the stack pointer;
> otherwise it can be arbitarily outdated anyways.
>

This is true, but i think it is better to get an outdated value than a
complete wrong value like -1.

The truth is that KSTK_ESP always return an outdated value on a multi
core system if the process never do a system call.

But we can work on the next step and try to implement it better ;-)

Question: is task_pt_regs(task)->sp set in 64 bit mode when the process
is blocked in an interrupt? If true, we can add two additional assembly
instruction to the system call handler and store the stack pointer into
this. Than KSTK_ESP wil be again a simple macro like

#define KST_ESP(task) task_pt_regs(task)->sp

The drawback is that this will cost a litte bit performance for a litte
bit more accuracy.

Stefani


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