Skip to content

Commit 7e16f58

Browse files
committed
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>
1 parent 714641c commit 7e16f58

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

kernel/trace/ftrace.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,26 @@ static int ftrace_cmp_recs(const void *a, const void *b)
15411541
return 0;
15421542
}
15431543

1544+
static struct dyn_ftrace *lookup_rec(unsigned long start, unsigned long end)
1545+
{
1546+
struct ftrace_page *pg;
1547+
struct dyn_ftrace *rec = NULL;
1548+
struct dyn_ftrace key;
1549+
1550+
key.ip = start;
1551+
key.flags = end; /* overload flags, as it is unsigned long */
1552+
1553+
for (pg = ftrace_pages_start; pg; pg = pg->next) {
1554+
if (end < pg->records[0].ip ||
1555+
start >= (pg->records[pg->index - 1].ip + MCOUNT_INSN_SIZE))
1556+
continue;
1557+
rec = bsearch(&key, pg->records, pg->index,
1558+
sizeof(struct dyn_ftrace),
1559+
ftrace_cmp_recs);
1560+
}
1561+
return rec;
1562+
}
1563+
15441564
/**
15451565
* ftrace_location_range - return the first address of a traced location
15461566
* if it touches the given ip range
@@ -1555,23 +1575,11 @@ static int ftrace_cmp_recs(const void *a, const void *b)
15551575
*/
15561576
unsigned long ftrace_location_range(unsigned long start, unsigned long end)
15571577
{
1558-
struct ftrace_page *pg;
15591578
struct dyn_ftrace *rec;
1560-
struct dyn_ftrace key;
15611579

1562-
key.ip = start;
1563-
key.flags = end; /* overload flags, as it is unsigned long */
1564-
1565-
for (pg = ftrace_pages_start; pg; pg = pg->next) {
1566-
if (end < pg->records[0].ip ||
1567-
start >= (pg->records[pg->index - 1].ip + MCOUNT_INSN_SIZE))
1568-
continue;
1569-
rec = bsearch(&key, pg->records, pg->index,
1570-
sizeof(struct dyn_ftrace),
1571-
ftrace_cmp_recs);
1572-
if (rec)
1573-
return rec->ip;
1574-
}
1580+
rec = lookup_rec(start, end);
1581+
if (rec)
1582+
return rec->ip;
15751583

15761584
return 0;
15771585
}

0 commit comments

Comments
 (0)