Commit 0e2fb011 authored by Kumar Kartikeya Dwivedi's avatar Kumar Kartikeya Dwivedi Committed by Alexei Starovoitov
Browse files

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: default avatarJiri Olsa <jolsa@kernel.org>
Signed-off-by: default avatarKumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20241104171959.2938862-3-memxor@gmail.com


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent cb4158ce
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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;
+9 −0
Original line number Diff line number Diff line
@@ -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__ */
+2 −1
Original line number Diff line number Diff line
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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);
+3 −3
Original line number Diff line number Diff line
@@ -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);
Loading