ftrace: Separate out functionality from ftrace_location_range()

Create a new function called lookup_rec() from the functionality of
ftrace_location_range(). The difference between lookup_rec() is that it
returns the record that it finds, where as ftrace_location_range() returns
only if it found a match or not.

The lookup_rec() is static, and can be used for new functionality where
ftrace needs to find a record of a specific address.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
This commit is contained in:
Steven Rostedt (VMware) 2019-11-08 12:26:46 -05:00
Родитель 714641c367
Коммит 7e16f581a8
1 изменённых файлов: 23 добавлений и 15 удалений

Просмотреть файл

@ -1541,6 +1541,26 @@ static int ftrace_cmp_recs(const void *a, const void *b)
return 0; return 0;
} }
static struct dyn_ftrace *lookup_rec(unsigned long start, unsigned long end)
{
struct ftrace_page *pg;
struct dyn_ftrace *rec = NULL;
struct dyn_ftrace key;
key.ip = start;
key.flags = end; /* overload flags, as it is unsigned long */
for (pg = ftrace_pages_start; pg; pg = pg->next) {
if (end < pg->records[0].ip ||
start >= (pg->records[pg->index - 1].ip + MCOUNT_INSN_SIZE))
continue;
rec = bsearch(&key, pg->records, pg->index,
sizeof(struct dyn_ftrace),
ftrace_cmp_recs);
}
return rec;
}
/** /**
* ftrace_location_range - return the first address of a traced location * ftrace_location_range - return the first address of a traced location
* if it touches the given ip range * if it touches the given ip range
@ -1555,23 +1575,11 @@ static int ftrace_cmp_recs(const void *a, const void *b)
*/ */
unsigned long ftrace_location_range(unsigned long start, unsigned long end) unsigned long ftrace_location_range(unsigned long start, unsigned long end)
{ {
struct ftrace_page *pg;
struct dyn_ftrace *rec; struct dyn_ftrace *rec;
struct dyn_ftrace key;
key.ip = start; rec = lookup_rec(start, end);
key.flags = end; /* overload flags, as it is unsigned long */
for (pg = ftrace_pages_start; pg; pg = pg->next) {
if (end < pg->records[0].ip ||
start >= (pg->records[pg->index - 1].ip + MCOUNT_INSN_SIZE))
continue;
rec = bsearch(&key, pg->records, pg->index,
sizeof(struct dyn_ftrace),
ftrace_cmp_recs);
if (rec) if (rec)
return rec->ip; return rec->ip;
}
return 0; return 0;
} }