Messages in this thread | | | Date | Wed, 30 Apr 2014 16:58:43 +0200 | From | Jiri Slaby <> | Subject | Re: [RFC 01/16] ftrace: Add function to find fentry of function |
| |
On 04/30/2014 04:48 PM, Steven Rostedt wrote: > On Wed, 30 Apr 2014 16:30:34 +0200 > Jiri Slaby <jslaby@suse.cz> wrote: >> --- a/kernel/trace/ftrace.c >> +++ b/kernel/trace/ftrace.c >> @@ -1495,6 +1495,35 @@ ftrace_ops_test(struct ftrace_ops *ops, unsigned long ip, void *regs) >> } \ >> } >> >> +/** >> + * ftrace_function_to_fentry -- lookup fentry location for a function >> + * @addr: function address to find a fentry in >> + * >> + * Perform a lookup in a list of fentry callsites to find one that fits a >> + * specified function @addr. It returns the corresponding fentry callsite or >> + * zero on failure. >> + */ >> +unsigned long ftrace_function_to_fentry(unsigned long addr) >> +{ >> + const struct dyn_ftrace *rec; >> + const struct ftrace_page *pg; >> + unsigned long ret = 0; >> + >> + mutex_lock(&ftrace_lock); >> + do_for_each_ftrace_rec(pg, rec) { > > The records are sorted within a pg. You can optimize this a lot if you > just test the first and last record and see if it is in the range. If > not, then skip to the next page. If it is, you can use a bsearch as > well, to save on the lookups.
Yes, this is a KISS (and suboptimal) version as there is a slight issue in your suggestion: if we pass addres of a function of which the fentry is the first in pg, it would be out of range for the particular pg. What should work is: check the first entry and then search binary...
thanks, -- js suse labs
| |