Re: [RFC 01/16] ftrace: Add function to find fentry of function

From: Jiri Slaby
Date: Wed Apr 30 2014 - 10:58:50 EST


On 04/30/2014 04:48 PM, Steven Rostedt wrote:
> On Wed, 30 Apr 2014 16:30:34 +0200
> Jiri Slaby <jslaby@xxxxxxx> 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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/