mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-13 05:54:23 +08:00
selftests/bpf: Clean up open-coded gettid syscall invocations
Availability of the gettid definition across glibc versions supported by BPF selftests is not certain. Currently, all users in the tree open-code syscall to gettid. Convert them to a common macro definition. Reviewed-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Link: https://lore.kernel.org/r/20241104171959.2938862-3-memxor@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
cb4158ce8e
commit
0e2fb011a0
@ -4,6 +4,7 @@
|
||||
#include <argp.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include "bpf_util.h"
|
||||
#include "bench.h"
|
||||
#include "trigger_bench.skel.h"
|
||||
#include "trace_helpers.h"
|
||||
@ -72,7 +73,7 @@ static __always_inline void inc_counter(struct counter *counters)
|
||||
unsigned slot;
|
||||
|
||||
if (unlikely(tid == 0))
|
||||
tid = syscall(SYS_gettid);
|
||||
tid = sys_gettid();
|
||||
|
||||
/* multiplicative hashing, it's fast */
|
||||
slot = 2654435769U * tid;
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <syscall.h>
|
||||
#include <bpf/libbpf.h> /* libbpf_num_possible_cpus */
|
||||
|
||||
static inline unsigned int bpf_num_possible_cpus(void)
|
||||
@ -59,4 +60,12 @@ static inline void bpf_strlcpy(char *dst, const char *src, size_t sz)
|
||||
(offsetof(TYPE, MEMBER) + sizeof_field(TYPE, MEMBER))
|
||||
#endif
|
||||
|
||||
/* Availability of gettid across glibc versions is hit-and-miss, therefore
|
||||
* fallback to syscall in this macro and use it everywhere.
|
||||
*/
|
||||
#ifndef sys_gettid
|
||||
#define sys_gettid() syscall(SYS_gettid)
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __BPF_UTIL__ */
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <bpf/bpf.h>
|
||||
#include <bpf/libbpf.h>
|
||||
|
||||
#include "bpf_util.h"
|
||||
#include "test_maps.h"
|
||||
#include "task_local_storage_helpers.h"
|
||||
#include "read_bpf_task_storage_busy.skel.h"
|
||||
@ -115,7 +116,7 @@ void test_task_storage_map_stress_lookup(void)
|
||||
CHECK(err, "attach", "error %d\n", err);
|
||||
|
||||
/* Trigger program */
|
||||
syscall(SYS_gettid);
|
||||
sys_gettid();
|
||||
skel->bss->pid = 0;
|
||||
|
||||
CHECK(skel->bss->busy != 0, "bad bpf_task_storage_busy", "got %d\n", skel->bss->busy);
|
||||
|
@ -690,7 +690,7 @@ void test_bpf_cookie(void)
|
||||
if (!ASSERT_OK_PTR(skel, "skel_open"))
|
||||
return;
|
||||
|
||||
skel->bss->my_tid = syscall(SYS_gettid);
|
||||
skel->bss->my_tid = sys_gettid();
|
||||
|
||||
if (test__start_subtest("kprobe"))
|
||||
kprobe_subtest(skel);
|
||||
|
@ -226,7 +226,7 @@ static void test_task_common_nocheck(struct bpf_iter_attach_opts *opts,
|
||||
ASSERT_OK(pthread_create(&thread_id, NULL, &do_nothing_wait, NULL),
|
||||
"pthread_create");
|
||||
|
||||
skel->bss->tid = syscall(SYS_gettid);
|
||||
skel->bss->tid = sys_gettid();
|
||||
|
||||
do_dummy_read_opts(skel->progs.dump_task, opts);
|
||||
|
||||
@ -255,10 +255,10 @@ static void *run_test_task_tid(void *arg)
|
||||
union bpf_iter_link_info linfo;
|
||||
int num_unknown_tid, num_known_tid;
|
||||
|
||||
ASSERT_NEQ(getpid(), syscall(SYS_gettid), "check_new_thread_id");
|
||||
ASSERT_NEQ(getpid(), sys_gettid(), "check_new_thread_id");
|
||||
|
||||
memset(&linfo, 0, sizeof(linfo));
|
||||
linfo.task.tid = syscall(SYS_gettid);
|
||||
linfo.task.tid = sys_gettid();
|
||||
opts.link_info = &linfo;
|
||||
opts.link_info_len = sizeof(linfo);
|
||||
test_task_common(&opts, 0, 1);
|
||||
|
@ -63,14 +63,14 @@ static void test_tp_btf(int cgroup_fd)
|
||||
if (!ASSERT_OK(err, "map_delete_elem"))
|
||||
goto out;
|
||||
|
||||
skel->bss->target_pid = syscall(SYS_gettid);
|
||||
skel->bss->target_pid = sys_gettid();
|
||||
|
||||
err = cgrp_ls_tp_btf__attach(skel);
|
||||
if (!ASSERT_OK(err, "skel_attach"))
|
||||
goto out;
|
||||
|
||||
syscall(SYS_gettid);
|
||||
syscall(SYS_gettid);
|
||||
sys_gettid();
|
||||
sys_gettid();
|
||||
|
||||
skel->bss->target_pid = 0;
|
||||
|
||||
@ -154,7 +154,7 @@ static void test_recursion(int cgroup_fd)
|
||||
goto out;
|
||||
|
||||
/* trigger sys_enter, make sure it does not cause deadlock */
|
||||
syscall(SYS_gettid);
|
||||
sys_gettid();
|
||||
|
||||
out:
|
||||
cgrp_ls_recursion__destroy(skel);
|
||||
@ -224,7 +224,7 @@ static void test_yes_rcu_lock(__u64 cgroup_id)
|
||||
return;
|
||||
|
||||
CGROUP_MODE_SET(skel);
|
||||
skel->bss->target_pid = syscall(SYS_gettid);
|
||||
skel->bss->target_pid = sys_gettid();
|
||||
|
||||
bpf_program__set_autoload(skel->progs.yes_rcu_lock, true);
|
||||
err = cgrp_ls_sleepable__load(skel);
|
||||
|
@ -1010,7 +1010,7 @@ static void run_core_reloc_tests(bool use_btfgen)
|
||||
struct data *data;
|
||||
void *mmap_data = NULL;
|
||||
|
||||
my_pid_tgid = getpid() | ((uint64_t)syscall(SYS_gettid) << 32);
|
||||
my_pid_tgid = getpid() | ((uint64_t)sys_gettid() << 32);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(test_cases); i++) {
|
||||
char btf_file[] = "/tmp/core_reloc.btf.XXXXXX";
|
||||
|
@ -20,7 +20,7 @@ void test_linked_funcs(void)
|
||||
bpf_program__set_autoload(skel->progs.handler1, true);
|
||||
bpf_program__set_autoload(skel->progs.handler2, true);
|
||||
|
||||
skel->rodata->my_tid = syscall(SYS_gettid);
|
||||
skel->rodata->my_tid = sys_gettid();
|
||||
skel->bss->syscall_id = SYS_getpgid;
|
||||
|
||||
err = linked_funcs__load(skel);
|
||||
|
@ -23,7 +23,7 @@ static int get_pid_tgid(pid_t *pid, pid_t *tgid,
|
||||
struct stat st;
|
||||
int err;
|
||||
|
||||
*pid = syscall(SYS_gettid);
|
||||
*pid = sys_gettid();
|
||||
*tgid = getpid();
|
||||
|
||||
err = stat("/proc/self/ns/pid", &st);
|
||||
|
@ -21,7 +21,7 @@ static void test_success(void)
|
||||
if (!ASSERT_OK_PTR(skel, "skel_open"))
|
||||
return;
|
||||
|
||||
skel->bss->target_pid = syscall(SYS_gettid);
|
||||
skel->bss->target_pid = sys_gettid();
|
||||
|
||||
bpf_program__set_autoload(skel->progs.get_cgroup_id, true);
|
||||
bpf_program__set_autoload(skel->progs.task_succ, true);
|
||||
@ -58,7 +58,7 @@ static void test_rcuptr_acquire(void)
|
||||
if (!ASSERT_OK_PTR(skel, "skel_open"))
|
||||
return;
|
||||
|
||||
skel->bss->target_pid = syscall(SYS_gettid);
|
||||
skel->bss->target_pid = sys_gettid();
|
||||
|
||||
bpf_program__set_autoload(skel->progs.task_acquire, true);
|
||||
err = rcu_read_lock__load(skel);
|
||||
|
@ -31,14 +31,14 @@ static void test_sys_enter_exit(void)
|
||||
if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
|
||||
return;
|
||||
|
||||
skel->bss->target_pid = syscall(SYS_gettid);
|
||||
skel->bss->target_pid = sys_gettid();
|
||||
|
||||
err = task_local_storage__attach(skel);
|
||||
if (!ASSERT_OK(err, "skel_attach"))
|
||||
goto out;
|
||||
|
||||
syscall(SYS_gettid);
|
||||
syscall(SYS_gettid);
|
||||
sys_gettid();
|
||||
sys_gettid();
|
||||
|
||||
/* 3x syscalls: 1x attach and 2x gettid */
|
||||
ASSERT_EQ(skel->bss->enter_cnt, 3, "enter_cnt");
|
||||
@ -107,7 +107,7 @@ static void test_recursion(void)
|
||||
|
||||
/* trigger sys_enter, make sure it does not cause deadlock */
|
||||
skel->bss->test_pid = getpid();
|
||||
syscall(SYS_gettid);
|
||||
sys_gettid();
|
||||
skel->bss->test_pid = 0;
|
||||
task_ls_recursion__detach(skel);
|
||||
|
||||
@ -262,7 +262,7 @@ static void test_uptr_basic(void)
|
||||
__u64 ev_dummy_data = 1;
|
||||
int err;
|
||||
|
||||
my_tid = syscall(SYS_gettid);
|
||||
my_tid = sys_gettid();
|
||||
parent_task_fd = sys_pidfd_open(my_tid, 0);
|
||||
if (!ASSERT_OK_FD(parent_task_fd, "parent_task_fd"))
|
||||
return;
|
||||
|
@ -125,7 +125,7 @@ static void *child_thread(void *ctx)
|
||||
struct child *child = ctx;
|
||||
int c = 0, err;
|
||||
|
||||
child->tid = syscall(SYS_gettid);
|
||||
child->tid = sys_gettid();
|
||||
|
||||
/* let parent know we are ready */
|
||||
err = write(child->c2p[1], &c, 1);
|
||||
|
Loading…
Reference in New Issue
Block a user