Skip to content

Commit b2a76fa

Browse files
chenhengqiyonghong-song
authored andcommitted
libbpf-tools: optimize fentry_exists helper
The previous implementation checks fentry support either in vmlinux or module BTF. So we need two calls to fentry_exists to verify that whether a symbol exists. This commit updates this behavior to use the module name provided as a hint, and fallback to vmlinux if module BTF is not available. Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
1 parent 9e38ee1 commit b2a76fa

4 files changed

Lines changed: 9 additions & 10 deletions

File tree

libbpf-tools/fsdist.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ static bool check_fentry()
230230
for (i = 0; i < MAX_OP; i++) {
231231
fn_name = fs_configs[fs_type].op_funcs[i];
232232
module = fs_configs[fs_type].fs;
233-
if (fn_name && !fentry_exists(fn_name, NULL)
234-
&& !fentry_exists(fn_name, module)) {
233+
if (fn_name && !fentry_exists(fn_name, module)) {
235234
support_fentry = false;
236235
break;
237236
}

libbpf-tools/fsslower.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ static bool check_fentry()
202202
for (i = 0; i < MAX_OP; i++) {
203203
fn_name = fs_configs[fs_type].op_funcs[i];
204204
module = fs_configs[fs_type].fs;
205-
if (fn_name && !fentry_exists(fn_name, NULL)
206-
&& !fentry_exists(fn_name, module)) {
205+
if (fn_name && !fentry_exists(fn_name, module)) {
207206
support_fentry = false;
208207
break;
209208
}

libbpf-tools/trace_helpers.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,16 +1013,18 @@ bool fentry_exists(const char *name, const char *mod)
10131013
sysfs_vmlinux, strerror(-libbpf_get_error(base)));
10141014
goto err_out;
10151015
}
1016-
if (mod) {
1016+
if (mod && module_btf_exists(mod)) {
10171017
snprintf(sysfs_mod, sizeof(sysfs_mod), "/sys/kernel/btf/%s", mod);
10181018
btf = btf__parse_split(sysfs_mod, base);
10191019
if (libbpf_get_error(btf)) {
10201020
fprintf(stderr, "failed to load BTF from %s: %s\n",
10211021
sysfs_mod, strerror(-libbpf_get_error(btf)));
1022-
goto err_out;
1022+
btf = base;
1023+
base = NULL;
10231024
}
10241025
} else {
10251026
btf = base;
1027+
base = NULL;
10261028
}
10271029

10281030
id = btf__find_by_name_kind(btf, "bpf_attach_type", BTF_KIND_ENUM);
@@ -1044,8 +1046,7 @@ bool fentry_exists(const char *name, const char *mod)
10441046
}
10451047

10461048
err_out:
1047-
if (mod)
1048-
btf__free(btf);
1049+
btf__free(btf);
10491050
btf__free(base);
10501051
return id > 0;
10511052
}

libbpf-tools/trace_helpers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ bool is_kernel_module(const char *name);
7575
*
7676
* *name* is the name of a kernel function to be attached to, which can be
7777
* from vmlinux or a kernel module.
78-
* *mod* is the name of a kernel module, if NULL, it means *name*
79-
* belongs to vmlinux.
78+
* *mod* is a hint that indicates the *name* may reside in module BTF,
79+
* if NULL, it means *name* belongs to vmlinux.
8080
*/
8181
bool fentry_exists(const char *name, const char *mod);
8282

0 commit comments

Comments
 (0)