This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: stack_used() not accurate?


Hi -

On Fri, May 30, 2008 at 03:39:54PM -0400, Mike Snitzer wrote:
> On Thu, May 29, 2008 at 5:23 PM, Mike Snitzer <snitzer@gmail.com> wrote:
> > I came up with the following for x86_64:
> >
> > %( arch == "x86_64" %?
> > function stack_used_new:long() %{
> >        unsigned long free = THREAD_SIZE;
> >        if (CONTEXT->regs) {
> >                u64 curbase = (u64)task_stack_page(current);
> > #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
> >                unsigned long sp = CONTEXT->regs->sp;
> > #else
> >                unsigned long sp = CONTEXT->regs->rsp;
> > #endif
> >                free = sp - (curbase + sizeof(struct thread_info));
> >        }
> >        THIS->__retvalue = THREAD_SIZE - free;
> > %}
> > %)

This looks OK, but REGS_SP(CONTEXT->regs) should do the right thing
without that #if stuff.  Actually, that may be enough to make this
function architecture-independent.


> Here is the x86 version (from irq_32.c's do_IRQ):
> 
> function stack_used_new:long() %{
>         unsigned long free = THREAD_SIZE;
>         if (CONTEXT->regs) {
>                 long sp;
>                 __asm__ __volatile__("andl %%esp,%0" :
>                                         "=r" (sp) : "0" (THREAD_SIZE - 1));
>                 free = sp - sizeof(struct thread_info);
>         }
>         THIS->__retvalue = THREAD_SIZE - free;
> %}

(This version doesn't use CONTEXT->regs, which it should.)


> Along the way I've uncovered what seems to be an issue with
> systemtap's print_stack() on x86.  [...]

Yeah, that's one of several smelly bits that we're working on.


- FChE


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]