Skip to content

Commit c0995ce

Browse files
chenhengqiyonghong-song
authored andcommitted
libbpf-tools: Fix syscount
Running syscount causes the following error: ... ; if (measure_latency) 103: (18) r1 = 0xffffc90000b6a002 105: (71) r1 = *(u8 *)(r1 +0) R0_w=inv(id=0,umax_value=16,var_off=(0x0; 0x1f)) R1_w=map_value(id=0,off=2,ks=4,vs=48,imm=0) R7=map_value(id=0,off=0,ks=4,vs=32,imm=0) R8=inv(id=0,smin_value=-2147483648,smax_value=2147483647) R10=fp0 fp-8=mmmmmmmm fp-16=mmmmmmmm ; if (measure_latency) 106: (15) if r1 == 0x0 goto pc+4 R0_w=inv(id=0,umax_value=16,var_off=(0x0; 0x1f)) R1_w=inv(id=0,umax_value=255,var_off=(0x0; 0xff)) R7=map_value(id=0,off=0,ks=4,vs=32,imm=0) R8=inv(id=0,smin_value=-2147483648,smax_value=2147483647) R10=fp0 fp-8=mmmmmmmm fp-16=mmmmmmmm ; __sync_fetch_and_add(&val->total_ns, bpf_ktime_get_ns() - *start_ts); 107: (85) call bpf_ktime_get_ns#5 ; __sync_fetch_and_add(&val->total_ns, bpf_ktime_get_ns() - *start_ts); 108: (79) r1 = *(u64 *)(r6 +0) R6 !read_ok processed 181 insns (limit 1000000) max_states_per_insn 1 total_states 19 peak_states 19 mark_read 8 -- END PROG LOAD LOG -- libbpf: failed to load program 'sys_exit' libbpf: failed to load object 'syscount_bpf' libbpf: failed to load BPF skeleton 'syscount_bpf': -13 failed to load BPF object: Permission denied Fix this by calculating the latency and store on a local variable. Signed-off-by: Hengqi Chen <[email protected]>
1 parent 77615d4 commit c0995ce

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

libbpf-tools/syscount.bpf.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int sys_exit(struct trace_event_raw_sys_exit *args)
7878
static const struct data_t zero;
7979
pid_t pid = id >> 32;
8080
struct data_t *val;
81-
u64 *start_ts;
81+
u64 *start_ts, lat = 0;
8282
u32 tid = id;
8383
u32 key;
8484

@@ -97,6 +97,7 @@ int sys_exit(struct trace_event_raw_sys_exit *args)
9797
start_ts = bpf_map_lookup_elem(&start, &tid);
9898
if (!start_ts)
9999
return 0;
100+
lat = bpf_ktime_get_ns() - *start_ts;
100101
}
101102

102103
key = (count_by_process) ? pid : args->id;
@@ -106,7 +107,7 @@ int sys_exit(struct trace_event_raw_sys_exit *args)
106107
if (count_by_process)
107108
save_proc_name(val);
108109
if (measure_latency)
109-
__sync_fetch_and_add(&val->total_ns, bpf_ktime_get_ns() - *start_ts);
110+
__sync_fetch_and_add(&val->total_ns, lat);
110111
}
111112
return 0;
112113
}

0 commit comments

Comments
 (0)