test/test_histogram.py: fix test failed on kernel-5.10
authorChunmei Xu <xuchunmei@linux.alibaba.com>
Fri, 15 Jan 2021 01:51:27 +0000 (09:51 +0800)
committeryonghong-song <ys114321@gmail.com>
Fri, 15 Jan 2021 19:31:44 +0000 (11:31 -0800)
kernel commit(cf25e24db61cc) rename tsk->real_start_time to
start_boottime, so test_hostogram will get failed on kernel>=5.5

Signed-off-by: Chunmei Xu <xuchunmei@linux.alibaba.com>
tests/python/test_histogram.py

index 2fb8c1685d734e752db53b9a07d89ddee5babb31..ec7950c9d5a7b894da4dd716f57845e10509805b 100755 (executable)
@@ -59,10 +59,15 @@ int kprobe__htab_map_delete_elem(struct pt_regs *ctx, struct bpf_map *map, u64 *
         b = BPF(text="""
 #include <uapi/linux/ptrace.h>
 #include <linux/sched.h>
+#include <linux/version.h>
 typedef struct { char name[TASK_COMM_LEN]; u64 slot; } Key;
 BPF_HISTOGRAM(hist1, Key, 1024);
 int kprobe__finish_task_switch(struct pt_regs *ctx, struct task_struct *prev) {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5,5,0)
     Key k = {.slot = bpf_log2l(prev->real_start_time)};
+#else
+    Key k = {.slot = bpf_log2l(prev->start_boottime)};
+#endif
     if (!bpf_get_current_comm(&k.name, sizeof(k.name)))
         hist1.increment(k);
     return 0;