Skip to content

Commit

Permalink
Fix hardirq/softirq value init logic (#253)
Browse files Browse the repository at this point in the history
I did not realize that valp was pointing to the *actual*
kernel ebpf value, and that the update we do here will
persist for the value sitting in the map.
  • Loading branch information
UmanShahzad authored Aug 30, 2021
1 parent bc6e88e commit abc1da7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
22 changes: 10 additions & 12 deletions kernel/hardirq_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,15 @@ int netdata_irq_handler_entry(struct netdata_irq_handler_entry *ptr)

key.irq = ptr->irq;
valp = bpf_map_lookup_elem(&tbl_hardirq, &key);
if (!valp) {
if (valp) {
valp->ts = bpf_ktime_get_ns();
} else {
val.latency = 0;
val.ts = bpf_ktime_get_ns();
TP_DATA_LOC_READ_CONST(val.name, ptr, ptr->data_loc_name, NETDATA_HARDIRQ_NAME_LEN);
} else {
val.latency = valp->latency;
bpf_map_update_elem(&tbl_hardirq, &key, &val, BPF_ANY);
}

val.ts = bpf_ktime_get_ns();
bpf_map_update_elem(&tbl_hardirq, &key, &val, BPF_ANY);

return 0;
}

Expand Down Expand Up @@ -85,15 +84,14 @@ int netdata_irq_ ##__type(struct netdata_irq_vectors_entry *ptr) \
\
idx = __enum_idx; \
valp = bpf_map_lookup_elem(&tbl_hardirq_static, &idx); \
if (!valp) { \
val.latency = 0; \
if (valp) { \
valp->ts = bpf_ktime_get_ns(); \
} else { \
val.latency = valp->latency; \
val.latency = 0; \
val.ts = bpf_ktime_get_ns(); \
bpf_map_update_elem(&tbl_hardirq_static, &idx, &val, BPF_ANY); \
} \
\
val.ts = bpf_ktime_get_ns(); \
bpf_map_update_elem(&tbl_hardirq_static, &idx, &val, BPF_ANY); \
\
return 0; \
}

Expand Down
11 changes: 5 additions & 6 deletions kernel/softirq_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ int netdata_softirq_entry(struct netdata_softirq_entry *ptr)
}

valp = bpf_map_lookup_elem(&tbl_softirq, &vec);
if (!valp) {
val.latency = 0;
if (valp) {
valp->ts = bpf_ktime_get_ns();
} else {
val.latency = valp->latency;
val.latency = 0;
val.ts = bpf_ktime_get_ns();
bpf_map_update_elem(&tbl_softirq, &vec, &val, BPF_ANY);
}

val.ts = bpf_ktime_get_ns();
bpf_map_update_elem(&tbl_softirq, &vec, &val, BPF_ANY);

return 0;
}

Expand Down

0 comments on commit abc1da7

Please sign in to comment.