All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Daney <ddaney.cavm@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>,
	Al Cooper <alcooperx@gmail.com>,
	ralf@linux-mips.org
Cc: linux-mips@linux-mips.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mips: function tracer: Fix broken function tracing
Date: Tue, 15 Jan 2013 09:55:30 -0800	[thread overview]
Message-ID: <50F59812.6040806@gmail.com> (raw)
In-Reply-To: <20130115034006.GA3854@home.goodmis.org>

On 01/14/2013 07:40 PM, Steven Rostedt wrote:
> On Fri, Jan 11, 2013 at 09:01:01AM -0800, David Daney wrote:
>>
>> I thought all CPUs were in stop_machine() when the modifications
>> were done, so that there is no issue with multi-word instruction
>> patching.
>>
>> Am I wrong about this?
>>
>> So really I think you can do two NOP just as easily.
>
> The problem with double NOPs is that it can only work if there's no
> problem executing one nop and a non NOP. Which I think is an issue here.
>
>
> If you have something like:
>
> 	bl	_mcount
> 	addiu	sp,sp,-8
>
> And you convert that to:
>
> 	nop
> 	nop
>
> Now if you convert that back to:
>
> 	bl	ftrace_caller
> 	addiu	sp,sp,-8
>
> then you can have an issue if the task was preempted after that first
> nop. Because stop_machine() doesn't wait for tasks to exit kernel space.
> If you have a CONFIG_PREEMPT kernel, a task can be sleeping anywhere.
> Thus you have a task execute the first nop, get preempted. You update
> the code to be:

Thanks for the explanation Steven.  This is the part I was missing.


Given all of this, I think the most expedient course for the short term 
is to use the branch-likely-false trick.  Although the performance will 
probably not be great, I think it is probably race free.

In the longer term...

>
> 	bl	ftrace_caller
> 	addiu	sp,sp,-8
>
> When that task gets scheduled back in, it will act like it just
> executed:
>
> 	nop
> 	addiu	sp,sp,-8
>
> Which is the problem you're trying to solve in the first place.
>
> Now that said, There's no reason we need that addiu sp,sp,-8 there.
> That's just what the mips defined mcount requires. But as you can see
> above, with dynamic ftrace, the defined mcount is only called at boot
> up, and never again. That means at boot up you can convert to:
>
> 	nop
> 	nop
>
> and then when you enable tracing just convert it to:
>
> 	bl	ftrace_caller
> 	nop
>
> There's nothing that states what the ftrace caller must be. We can have
> it do a proper stack update. That is, only at boot up do we need to
> handle the defined mcount. After that, those instructions are just place
> holders for our own algorithms. If the addiu was needed for the defined
> mcount, there's no reason to keep it for our own ftrace_caller.
>
> Would that work?

... either do as you suggest and dynamically change the ABI of the 
target function.

Or add support to GCC for a better tracing ABI (as I already said we did 
for mips64).


Thanks,
David Daney

  parent reply	other threads:[~2013-01-15 17:55 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-11 14:33 [PATCH] mips: function tracer: Fix broken function tracing Al Cooper
2013-01-11 17:01 ` David Daney
2013-01-14 21:10   ` Alan Cooper
2013-01-14 22:12     ` David Daney
2013-01-15  0:13       ` Alan Cooper
2013-01-15  0:36         ` David Daney
2013-01-15  3:40   ` Steven Rostedt
2013-01-15 17:53     ` Alan Cooper
2013-01-15 21:08       ` Steven Rostedt
2013-01-15 17:55     ` David Daney [this message]
2013-01-15 21:07       ` Steven Rostedt
2013-01-15 21:34         ` David Daney
2013-01-15 22:42           ` Alan Cooper

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=50F59812.6040806@gmail.com \
    --to=ddaney.cavm@gmail.com \
    --cc=alcooperx@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=ralf@linux-mips.org \
    --cc=rostedt@goodmis.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.