Re: KPROBES: Instrumenting a function's call site

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Avishay Traeger
Date: Thursday, November 8, 2007 - 12:42 pm

Sorry for reviving a thread from two months ago... :)

On Wed, 2007-09-26 at 10:09 +0530, Ananth N Mavinakayanahalli wrote:

The approach that we took until now is (a):

kprobe1.pre_handler();
foo();
kprobe2.pre_handler();

However, my colleague Ivan has come up with another approach that I
think it pretty novel:
- kprob1.pre-handler is placed at the call site as before.
- A post-handler is also added to this same kprobe, which saves foo's
return value, and modifies it to point to a new function.  This new
function contains the code that used to be in kprobe2.pre_handler
(reading the TSC register a second time and computing the latency).
This new function then returns to the original return location.

The only caveat is that to handle recursion, you need to save a stack of
return addresses.

This has 2 main benefits:
1. It guarantees that the code contained in the second kprobe is
executed only when the first is (in case there is a jump in the code to
the location of the 2nd kprobe).
2. We only need one kprobe instead of two, which speeds things up.

We have tested this, and it works great.  Just wanted to let you know
about this technique in case this issue comes up again.  Have you ever
seen kprobes used in this way?

Thanks,
Avishay

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
KPROBES: Instrumenting a function's call site, Avishay Traeger, (Tue Sep 25, 3:12 pm)
Re: KPROBES: Instrumenting a function's call site, Ananth N Mavinakayan ..., (Tue Sep 25, 9:39 pm)
Re: KPROBES: Instrumenting a function's call site, Ananth N Mavinakayan ..., (Wed Sep 26, 2:03 am)
Re: KPROBES: Instrumenting a function's call site, Avishay Traeger, (Wed Sep 26, 9:09 am)
Re: KPROBES: Instrumenting a function's call site, Abhishek Sagar, (Wed Sep 26, 9:37 am)
Re: KPROBES: Instrumenting a function's call site, Abhishek Sagar, (Wed Sep 26, 9:52 am)
Re: KPROBES: Instrumenting a function's call site, Ananth N Mavinakayan ..., (Wed Sep 26, 10:27 am)
Re: KPROBES: Instrumenting a function's call site, Keshavamurthy, Anil S, (Wed Sep 26, 10:28 am)
Re: KPROBES: Instrumenting a function's call site, Avishay Traeger, (Wed Sep 26, 10:35 am)
Re: KPROBES: Instrumenting a function's call site, Avishay Traeger, (Wed Sep 26, 10:37 am)
Re: KPROBES: Instrumenting a function's call site, Avishay Traeger, (Thu Nov 8, 12:42 pm)
Re: KPROBES: Instrumenting a function's call site, Ananth N Mavinakayan ..., (Mon Nov 12, 3:27 am)