new file mode 100644
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <test_progs.h>
+#include <network_helpers.h>
+
+static void *time_thread(void *arg)
+{
+ __u32 duration, retval;
+ int err, prog_fd = *(u32 *) arg;
+
+ err = bpf_prog_test_run(prog_fd, 10000, &pkt_v4, sizeof(pkt_v4),
+ NULL, NULL, &retval, &duration);
+ CHECK(err || retval, "",
+ "err %d errno %d retval %d duration %d\n",
+ err, errno, retval, duration);
+ pthread_exit(arg);
+}
+
+void test_ktime_real(void)
+{
+ const char *file = "./test_ktime_get_real_ns.o";
+ struct bpf_object *obj = NULL;
+ pthread_t thread_id;
+ int prog_fd;
+ int err = 0;
+ void *ret;
+
+ err = bpf_prog_load(file, BPF_PROG_TYPE_CGROUP_SKB, &obj, &prog_fd);
+ if (CHECK_FAIL(err)) {
+ printf("test_ktime_get_real_ns:bpf_prog_load errno %d\n", errno);
+ goto close_prog;
+ }
+
+ if (CHECK_FAIL(pthread_create(&thread_id, NULL,
+ &time_thread, &prog_fd)))
+ goto close_prog;
+
+ if (CHECK_FAIL(pthread_join(thread_id, &ret) ||
+ ret != (void *)&prog_fd))
+ goto close_prog;
+close_prog:
+ bpf_object__close(obj);
+}
new file mode 100644
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/bpf.h>
+#include <linux/version.h>
+#include <bpf/bpf_helpers.h>
+
+struct {
+ __uint(type, BPF_MAP_TYPE_ARRAY);
+ __uint(max_entries, 1);
+ __type(key, int);
+ __type(value, unsigned long long);
+} time_map SEC(".maps");
+
+SEC("realtime_helper")
+int realtime_helper_test(struct __sk_buff *skb)
+{
+ unsigned long long *lasttime;
+ unsigned long long curtime;
+ int key = 0;
+ int err = 0;
+
+ lasttime = bpf_map_lookup_elem(&time_map, &key);
+ if (!lasttime)
+ goto err;
+
+ curtime = bpf_ktime_get_real_ns();
+ if (curtime <= *lasttime) {
+ err = 1;
+ goto err;
+ }
+ *lasttime = curtime;
+
+err:
+ return err;
+}
+
+char _license[] SEC("license") = "GPL";