-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Software IRQ latency tracking (#251)
- Loading branch information
1 parent
d099cdc
commit bc6e88e
Showing
6 changed files
with
114 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#ifndef _NETDATA_SOFTIRQ_H_ | ||
#define _NETDATA_SOFTIRQ_H_ 1 | ||
|
||
#define NETDATA_SOFTIRQ_MAX_IRQS 10 | ||
|
||
// /sys/kernel/debug/tracing/events/irq/softirq_entry | ||
struct netdata_softirq_entry { | ||
u64 pad; // This is not used with eBPF | ||
u32 vec; // offset:8; size:4; signed:0; | ||
}; | ||
|
||
// /sys/kernel/debug/tracing/events/irq/softirq_exit | ||
struct netdata_softirq_exit { | ||
u64 pad; // This is not used with eBPF | ||
u32 vec; // offset:8; size:4; signed:0; | ||
}; | ||
|
||
typedef struct softirq_val { | ||
// incremental counter storing the total latency so far. | ||
u64 latency; | ||
|
||
// temporary timestamp stored at the entry handler, to be diff'd with a | ||
// timestamp at the exit handler, to get the latency to add to the | ||
// `latency` field. | ||
u64 ts; | ||
} softirq_val_t; | ||
|
||
#endif /* _NETDATA_SOFTIRQ_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#define KBUILD_MODNAME "softirq_netdata" | ||
#include <linux/bpf.h> | ||
#include <linux/ptrace.h> | ||
#include <linux/genhd.h> | ||
|
||
#include "bpf_helpers.h" | ||
#include "netdata_ebpf.h" | ||
|
||
/************************************************************************************ | ||
* MAPS | ||
***********************************************************************************/ | ||
|
||
// maps from irq index to latency. | ||
struct bpf_map_def SEC("maps") tbl_softirq = { | ||
.type = BPF_MAP_TYPE_PERCPU_ARRAY, | ||
.key_size = sizeof(__u32), | ||
.value_size = sizeof(softirq_val_t), | ||
.max_entries = NETDATA_SOFTIRQ_MAX_IRQS | ||
}; | ||
|
||
/************************************************************************************ | ||
* SOFTIRQ SECTION | ||
***********************************************************************************/ | ||
|
||
SEC("tracepoint/irq/softirq_entry") | ||
int netdata_softirq_entry(struct netdata_softirq_entry *ptr) | ||
{ | ||
softirq_val_t *valp, val = {}; | ||
u32 vec = ptr->vec; | ||
|
||
// out-of-range index. | ||
if (vec > NETDATA_SOFTIRQ_MAX_IRQS-1) { | ||
return 0; | ||
} | ||
|
||
valp = bpf_map_lookup_elem(&tbl_softirq, &vec); | ||
if (!valp) { | ||
val.latency = 0; | ||
} else { | ||
val.latency = valp->latency; | ||
} | ||
|
||
val.ts = bpf_ktime_get_ns(); | ||
bpf_map_update_elem(&tbl_softirq, &vec, &val, BPF_ANY); | ||
|
||
return 0; | ||
} | ||
|
||
SEC("tracepoint/irq/softirq_exit") | ||
int netdata_softirq_exit(struct netdata_softirq_exit *ptr) | ||
{ | ||
softirq_val_t *valp; | ||
u32 vec = ptr->vec; | ||
|
||
// out-of-range index. | ||
if (vec > NETDATA_SOFTIRQ_MAX_IRQS-1) { | ||
return 0; | ||
} | ||
|
||
valp = bpf_map_lookup_elem(&tbl_softirq, &vec); | ||
if (!valp) { | ||
return 0; | ||
} | ||
|
||
// get time diff and convert to microseconds. | ||
u64 latency = (bpf_ktime_get_ns() - valp->ts) / 1000; | ||
libnetdata_update_u64(&valp->latency, latency); | ||
|
||
return 0; | ||
} | ||
|
||
char _license[] SEC("license") = "GPL"; |