Skip to content

Commit 8be9253

Browse files
olsajiriAlexei Starovoitov
authored andcommitted
fprobe: Resolve symbols with ftrace_lookup_symbols
Using ftrace_lookup_symbols to speed up symbols lookup in register_fprobe_syms API. Acked-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Jiri Olsa <jolsa@kernel.org> Link: https://lore.kernel.org/r/20220510122616.2652285-4-jolsa@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent bed0d9a commit 8be9253

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

kernel/trace/fprobe.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,39 +85,31 @@ static void fprobe_exit_handler(struct rethook_node *rh, void *data,
8585
}
8686
NOKPROBE_SYMBOL(fprobe_exit_handler);
8787

88+
static int symbols_cmp(const void *a, const void *b)
89+
{
90+
const char **str_a = (const char **) a;
91+
const char **str_b = (const char **) b;
92+
93+
return strcmp(*str_a, *str_b);
94+
}
95+
8896
/* Convert ftrace location address from symbols */
8997
static unsigned long *get_ftrace_locations(const char **syms, int num)
9098
{
91-
unsigned long addr, size;
9299
unsigned long *addrs;
93-
int i;
94100

95101
/* Convert symbols to symbol address */
96102
addrs = kcalloc(num, sizeof(*addrs), GFP_KERNEL);
97103
if (!addrs)
98104
return ERR_PTR(-ENOMEM);
99105

100-
for (i = 0; i < num; i++) {
101-
addr = kallsyms_lookup_name(syms[i]);
102-
if (!addr) /* Maybe wrong symbol */
103-
goto error;
104-
105-
/* Convert symbol address to ftrace location. */
106-
if (!kallsyms_lookup_size_offset(addr, &size, NULL) || !size)
107-
goto error;
106+
/* ftrace_lookup_symbols expects sorted symbols */
107+
sort(syms, num, sizeof(*syms), symbols_cmp, NULL);
108108

109-
addr = ftrace_location_range(addr, addr + size - 1);
110-
if (!addr) /* No dynamic ftrace there. */
111-
goto error;
109+
if (!ftrace_lookup_symbols(syms, num, addrs))
110+
return addrs;
112111

113-
addrs[i] = addr;
114-
}
115-
116-
return addrs;
117-
118-
error:
119112
kfree(addrs);
120-
121113
return ERR_PTR(-ENOENT);
122114
}
123115

0 commit comments

Comments
 (0)