libbpf-tools: initialize global variables in cachestat and funclatency
authorchenhengqi <chenhengqi@outlook.com>
Tue, 16 Mar 2021 05:58:25 +0000 (13:58 +0800)
committeryonghong-song <ys114321@gmail.com>
Wed, 17 Mar 2021 06:13:45 +0000 (23:13 -0700)
Signed-off-by: Hengqi Chen <chenhengqi@outlook.com>
libbpf-tools/cachestat.bpf.c
libbpf-tools/funclatency.bpf.c

index 36b7fca58554c3d1884dad7900c3dfeaeeac808e..e7719e25aec757473863adbfcef4c48fd594ca51 100644 (file)
@@ -4,9 +4,9 @@
 #include <bpf/bpf_helpers.h>
 #include <bpf/bpf_tracing.h>
 
-__s64 total;   /* total cache accesses without counting dirties */
-__s64 misses;  /* total of add to lru because of read misses */
-__u64 mbd;     /* total of mark_buffer_dirty events */
+__s64 total = 0;       /* total cache accesses without counting dirties */
+__s64 misses = 0;      /* total of add to lru because of read misses */
+__u64 mbd = 0;         /* total of mark_buffer_dirty events */
 
 SEC("fentry/add_to_page_cache_lru")
 int BPF_PROG(add_to_page_cache_lru)
index c2f9fdd2b17e50194646f88ed30d41efd5e7fca0..c004b838066d1c26950f5830635d35be05304149 100644 (file)
@@ -7,8 +7,8 @@
 #include "funclatency.h"
 #include "bits.bpf.h"
 
-const volatile pid_t targ_tgid;
-const volatile int units;
+const volatile pid_t targ_tgid = 0;
+const volatile int units = 0;
 
 /* key: pid.  value: start time */
 struct {
@@ -18,7 +18,7 @@ struct {
        __type(value, u64);
 } starts SEC(".maps");
 
-__u32 hist[MAX_SLOTS];
+__u32 hist[MAX_SLOTS] = {};
 
 SEC("kprobe/dummy_kprobe")
 int BPF_KPROBE(dummy_kprobe)