All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@redhat.com>
To: Ingo Molnar <mingo@elte.hu>, Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Andrew Morton <akpm@zip.com.au>
Subject: Re: [17/19] ftrace: dynamic enabling/disabling of function calls
Date: Mon, 11 Feb 2008 10:35:42 -0500	[thread overview]
Message-ID: <47B06B4E.1010704@redhat.com> (raw)
In-Reply-To: <20080210072109.GR4100@elte.hu>

Hi Ingo and Steven,

Ingo Molnar wrote:
> From: Steven Rostedt <srostedt@redhat.com>
> 
> This patch adds a feature to dynamically replace the ftrace code
> with the jmps to allow a kernel with ftrace configured to run
> as fast as it can without it configured.
> 
> The way this works, is on bootup, a ftrace function is registered
> to record the instruction pointer of all places that call the
> function.
> 
> Later, a kthread is awoken once a second that performs a stop_machine,
> and replaces all the code that was called with a jmp over the call
> to ftrace. It only replaces what was found the previous time.
> 
> e.g.
> 
>   call ftrace  /* 5 bytes */
> 
> is replaced with
> 
>   jmp 3f  /* jmp is 2 bytes and we jump 3 forward */
> 3:
> 
> When we want to enable ftrace for function tracing, the IP recording
> is removed, and stop_machine is called again to replace all the locations
> of that were recorded back to the call of ftrace.  When it is disabled,
> we replace the code back to the jmp.
> 
> Allocation is done by the kthread. If the ftrace recording function is
> called, and we don't have any record slots available, then we simply
> skip that call. Once a second a new page (if needed) is allocated for
> recording new ftrace function calls.  A large batch is allocated at
> boot up to get most of the calls there.
> 
> Because we do this via stop_machine, we don't have to worry about another
> CPU executing a ftrace call as we modify it. But we do need to worry
> about NMI's so all functions that might be called via nmi must be
> annotated with notrace_nmi. When this code is configured in, the NMI code
> will not call notrace.

I'd like to suggest that you can use djprobe-like solution here to eliminate
stop_machine.
The djprobe makes a bypass over that call instruction by using a kprobe,
and after replacing the call instruction, you can safely remove the bypass.
Here is an ols paper about djprobe.
http://www.kernel.org/doc/ols/2007/ols2007v1-pages-189-200.pdf

Thank you,

-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America) Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com


  reply	other threads:[~2008-02-11 15:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-10  7:21 [17/19] ftrace: dynamic enabling/disabling of function calls Ingo Molnar
2008-02-11 15:35 ` Masami Hiramatsu [this message]
2008-02-11 16:31   ` Ingo Molnar

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=47B06B4E.1010704@redhat.com \
    --to=mhiramat@redhat.com \
    --cc=akpm@zip.com.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.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.