mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Frédéric Weisbecker" <fweisbec@gmail.com>
To: "Ingo Molnar" <mingo@elte.hu>
Cc: "Steven Rostedt" <rostedt@goodmis.org>,
	"Tim Bird" <tim.bird@am.sony.com>,
	"Linux Kernel" <linux-kernel@vger.kernel.org>,
	"Alexander van Heukelum" <heukelum@mailshack.com>
Subject: Re: [PATCH] tracing/function-branch-tracer: support for x86-64
Date: Tue, 2 Dec 2008 12:10:28 +0100	[thread overview]
Message-ID: <c62985530812020310h42c3e58v28c080a7eaaab1ad@mail.gmail.com> (raw)
In-Reply-To: <20081202090205.GA11632@elte.hu>

2008/12/2 Ingo Molnar <mingo@elte.hu>:
> it's this bit:
>
>> +#ifdef CONFIG_X86_64
>> +             "1: movq (%[parent_old]), %[old]\n"
>> +             "2: movq %[return_hooker], (%[parent_replaced])\n"
>> +#else
>>               "1: movl (%[parent_old]), %[old]\n"
>>               "2: movl %[return_hooker], (%[parent_replaced])\n"
>> +#endif
>>               "   movl $0, %[faulted]\n"
>>
>>               ".section .fixup, \"ax\"\n"
>> @@ -476,8 +481,13 @@ void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr)
>>               ".previous\n"
>>
>>               ".section __ex_table, \"a\"\n"
>> +#ifdef CONFIG_X86_64
>> +             "   .quad 1b, 3b\n"
>> +             "   .quad 2b, 3b\n"
>> +#else
>>               "   .long 1b, 3b\n"
>>               "   .long 2b, 3b\n"
>> +#endif
>
> i think we might want to introduce a few assembly helpers/defines to
> standardize such constructs - they are quite frequent. Something like:
>
>                "   .ip_ptr 1b, 3b\n"
>                "   .ip_ptr 2b, 3b\n"


Yeah. Note that in this particular case I could use EX_TABLE() macro
too (if it is defined for x86, I can't verify yet).

> (Cc:-ed Alexander and Cyrill who have done work in this area recently)
>
> we might also introduce instruction helpers:
>
>                "1: mov_ptr (%[parent_old]), %[old]\n"
>                "2: mov_ptr %[return_hooker], (%[parent_replaced])\n"
>
> and avoid the #ifdefs altogether.


Good idea.

>
>> Note that arch/x86/process_64.c is not traced, as in X86-32. I first
>> thought __switch_to() was responsible of crashes during tracing because
>> I believed current task were changed inside but that's actually not the
>> case (actually yes, but not the "current" pointer).
>>
>> So I will have to investigate to find the functions that harm here, to
>> enable tracing of the other functions inside (but there is no issue at
>> this time, while process_64.c stays out of -pg flags).
>
> ok. You should take a look at arch/x86/include/asm/system.h's switch_to()
> macros - it has special stack switching smarts for context-switching.
>
> the other special stack layout case is the starting of kernel threads -
> ret_from_fork and its details in process*.c.


Ok, I will have a look inside.

>> A little possible race condition is fixed inside this patch too. When
>> the tracer allocate a return stack dynamically, the current depth is
>> not initialized before but after. An interrupt could occur at this time
>> and, after seeing that the return stack is allocated, the tracer could
>> try to trace it with a random uninitialized depth. It's a prevention,
>> even if I hadn't problems with it.
>
>> index 08b536a..1e9379d 100644
>> --- a/kernel/trace/ftrace.c
>> +++ b/kernel/trace/ftrace.c
>> @@ -1673,8 +1673,8 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list)
>>               }
>>
>>               if (t->ret_stack == NULL) {
>> -                     t->ret_stack = ret_stack_list[start++];
>>                       t->curr_ret_stack = -1;
>> +                     t->ret_stack = ret_stack_list[start++];
>>                       atomic_set(&t->trace_overrun, 0);
>>               }
>>       } while_each_thread(g, t);
>
> okay - the (optimization-)safe way to tell the compiler about such local
> CPU ordering information is:
>
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 08b536a..f724996 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -1673,8 +1673,10 @@ static int alloc_retstack_tasklist(struct ftrace_ret_stack **ret_stack_list)
>                }
>
>                if (t->ret_stack == NULL) {
> -                       t->ret_stack = ret_stack_list[start++];
>                        t->curr_ret_stack = -1;
> +                       /* Make sure IRQs see the -1 first: */
> +                       barrier();
> +                       t->ret_stack = ret_stack_list[start++];
>                        atomic_set(&t->trace_overrun, 0);
>                }
>        } while_each_thread(g, t);
>
> i changed the patch to do that.


Oops, I forgot it one more time.

That reminds me: I don't know why I always confuse the name of this
tracer: function-branch-tracer instead of function-graph-tracer.
Weird :-)


> All in one, great stuff!


Thanks :-)

  parent reply	other threads:[~2008-12-02 11:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-01 23:20 Frederic Weisbecker
2008-12-02  9:02 ` Ingo Molnar
2008-12-02  9:05   ` [PATCH] tracing/function-graph-tracer: " Ingo Molnar
2008-12-02 12:03     ` Frédéric Weisbecker
2008-12-02 11:10   ` Frédéric Weisbecker [this message]
2008-12-02 21:25   ` [PATCH] tracing/function-branch-tracer: " Steven Rostedt
2008-12-02 21:40     ` Frédéric Weisbecker
2008-12-03 21:29 ` Alexander van Heukelum
2008-12-03 23:33   ` Frédéric Weisbecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c62985530812020310h42c3e58v28c080a7eaaab1ad@mail.gmail.com \
    --to=fweisbec@gmail.com \
    --cc=heukelum@mailshack.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.org \
    --cc=tim.bird@am.sony.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®