selftests/bpf: Move get_time_ns to testing_helpers.h
authorJiri Olsa <jolsa@kernel.org>
Wed, 9 Aug 2023 08:34:30 +0000 (10:34 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 21 Aug 2023 22:51:26 +0000 (15:51 -0700)
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>
tools/testing/selftests/bpf/bench.h
tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
tools/testing/selftests/bpf/testing_helpers.h

index 7ff32be3d7300d2e5ba9fa73e9447d4d9338de8f..68180d8f8558ec88544b4dcf0bdb3ef96b9a370f 100644 (file)
@@ -81,15 +81,6 @@ void grace_period_latency_basic_stats(struct bench_res res[], int res_cnt,
 void grace_period_ticks_basic_stats(struct bench_res res[], int res_cnt,
                                    struct basic_stats *gp_stat);
 
-static inline __u64 get_time_ns(void)
-{
-       struct timespec t;
-
-       clock_gettime(CLOCK_MONOTONIC, &t);
-
-       return (u64)t.tv_sec * 1000000000 + t.tv_nsec;
-}
-
 static inline void atomic_inc(long *value)
 {
        (void)__atomic_add_fetch(value, 1, __ATOMIC_RELAXED);
index 2173c4bb555ecd2a0188e7b8bf54707e81db8804..179fe300534f5c56501544e70468ec4a514a545f 100644 (file)
@@ -304,14 +304,6 @@ cleanup:
        kprobe_multi__destroy(skel);
 }
 
-static inline __u64 get_time_ns(void)
-{
-       struct timespec t;
-
-       clock_gettime(CLOCK_MONOTONIC, &t);
-       return (__u64) t.tv_sec * 1000000000 + t.tv_nsec;
-}
-
 static size_t symbol_hash(long key, void *ctx __maybe_unused)
 {
        return str_hash((const char *) key);
index 5312323881b65792772d9b10dd6ef007cf0af1ce..5b7a55136741ac45e2b477fd1e304f2698467d16 100644 (file)
@@ -7,6 +7,7 @@
 #include <stdbool.h>
 #include <bpf/bpf.h>
 #include <bpf/libbpf.h>
+#include <time.h>
 
 int parse_num_list(const char *s, bool **set, int *set_len);
 __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);
 int unload_bpf_testmod(bool verbose);
 int kern_sync_rcu(void);
 
+static inline __u64 get_time_ns(void)
+{
+       struct timespec t;
+
+       clock_gettime(CLOCK_MONOTONIC, &t);
+
+       return (u64)t.tv_sec * 1000000000 + t.tv_nsec;
+}
+
 #endif /* __TESTING_HELPERS_H */