Skip to content

Commit 3830d04

Browse files
olsajiriAlexei Starovoitov
authored andcommitted
selftests/bpf: Move get_time_ns to testing_helpers.h
We'd like to have single copy of get_time_ns used b bench and test_progs, but we can't just include bench.h, because of conflicting 'struct env' objects. Moving get_time_ns to testing_helpers.h which is being included by both bench and test_progs objects. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Link: https://lore.kernel.org/r/20230809083440.3209381-19-jolsa@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 5902da6 commit 3830d04

3 files changed

Lines changed: 10 additions & 17 deletions

File tree

tools/testing/selftests/bpf/bench.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,6 @@ void grace_period_latency_basic_stats(struct bench_res res[], int res_cnt,
8181
void grace_period_ticks_basic_stats(struct bench_res res[], int res_cnt,
8282
struct basic_stats *gp_stat);
8383

84-
static inline __u64 get_time_ns(void)
85-
{
86-
struct timespec t;
87-
88-
clock_gettime(CLOCK_MONOTONIC, &t);
89-
90-
return (u64)t.tv_sec * 1000000000 + t.tv_nsec;
91-
}
92-
9384
static inline void atomic_inc(long *value)
9485
{
9586
(void)__atomic_add_fetch(value, 1, __ATOMIC_RELAXED);

tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,6 @@ static void test_attach_api_fails(void)
304304
kprobe_multi__destroy(skel);
305305
}
306306

307-
static inline __u64 get_time_ns(void)
308-
{
309-
struct timespec t;
310-
311-
clock_gettime(CLOCK_MONOTONIC, &t);
312-
return (__u64) t.tv_sec * 1000000000 + t.tv_nsec;
313-
}
314-
315307
static size_t symbol_hash(long key, void *ctx __maybe_unused)
316308
{
317309
return str_hash((const char *) key);

tools/testing/selftests/bpf/testing_helpers.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <stdbool.h>
88
#include <bpf/bpf.h>
99
#include <bpf/libbpf.h>
10+
#include <time.h>
1011

1112
int parse_num_list(const char *s, bool **set, int *set_len);
1213
__u32 link_info_prog_id(const struct bpf_link *link, struct bpf_link_info *info);
@@ -33,4 +34,13 @@ int load_bpf_testmod(bool verbose);
3334
int unload_bpf_testmod(bool verbose);
3435
int kern_sync_rcu(void);
3536

37+
static inline __u64 get_time_ns(void)
38+
{
39+
struct timespec t;
40+
41+
clock_gettime(CLOCK_MONOTONIC, &t);
42+
43+
return (u64)t.tv_sec * 1000000000 + t.tv_nsec;
44+
}
45+
3646
#endif /* __TESTING_HELPERS_H */

0 commit comments

Comments
 (0)