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
-