Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hard IRQ latency tracking #248

Merged
merged 4 commits into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions includes/bpf_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,25 @@ static int (*bpf_skb_change_head)(void *, int len, int flags) =
(void *)(PT_REGS_FP(ctx) + sizeof(ip))); })
#endif

/*
the TP_DATA_LOC_READ_* macros are used for reading from a field that's pointed
to by a __data_loc variable.

FYI, a __data_loc variable is really an int that contains within it the data
needed to get the location of the actual value. these macros do the
transformation needed to get that final location and then read from it.

this code is from iovisor/bcc file src/cc/exports/helpers.h and modified by
Netdata's Agent team for inclusion in Netdata.
*/
#define TP_DATA_LOC_READ_CONST(_dst, _arg, _data_loc, _length) do { \
unsigned short __offset = _data_loc & 0xFFFF; \
bpf_probe_read((void *)_dst, _length, (char *)_arg + __offset); \
} while (0)
#define TP_DATA_LOC_READ(_dst, _arg, _data_loc) do { \
unsigned short __offset = _data_loc & 0xFFFF; \
unsigned short __length = _data_loc >> 16; \
bpf_probe_read((void *)_dst, __length, (char *)_arg + __offset); \
} while (0)

#endif
1 change: 1 addition & 0 deletions includes/netdata_ebpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This header has the common definitions for all `.c` files.
#include "netdata_disk.h"
#include "netdata_fd.h"
#include "netdata_fs.h"
#include "netdata_hardirq.h"
#include "netdata_mount.h"
#include "netdata_network.h"
#include "netdata_process.h"
Expand Down
85 changes: 85 additions & 0 deletions includes/netdata_hardirq.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef _NETDATA_HARDIRQ_H_
#define _NETDATA_HARDIRQ_H_ 1

#define NETDATA_HARDIRQ_MAX_IRQS 1024L
#define NETDATA_HARDIRQ_NAME_LEN 32

// /sys/kernel/debug/tracing/events/irq/irq_handler_entry/
struct netdata_irq_handler_entry {
u64 pad; // This is not used with eBPF
int irq; // offset:8; size:4; signed:1;
int data_loc_name; // offset:12; size:4; signed:1; (https://github.com/iovisor/bpftrace/issues/385)
// (https://lists.linuxfoundation.org/pipermail/iovisor-dev/2017-February/000627.html)
};

// /sys/kernel/debug/tracing/events/irq/irq_handler_exit/
struct netdata_irq_handler_exit {
u64 pad; // This is not used with eBPF
int irq; // offset:8; size:4; signed:1;
int ret; // offset:12; size:4; signed:1;
};

typedef struct hardirq_key {
int irq;
} hardirq_key_t;

typedef struct hardirq_val {
// incremental counter storing the total latency so far.
u64 latency;

// temporary timestamp stored at the IRQ entry handler, to be diff'd with a
// timestamp at the IRQ exit handler, to get the latency to add to the
// `latency` field.
u64 ts;

// identifies the IRQ with a human-readable string.
char name[NETDATA_HARDIRQ_NAME_LEN];
} hardirq_val_t;

/************************************************************************************
* HARDIRQ STATIC
***********************************************************************************/

// all of the `irq_vectors` events, except `vector_*`, have the same format.
// cat /sys/kernel/debug/tracing/available_events | grep 'irq_vectors' | grep -v ':vector_'
struct netdata_irq_vectors_entry {
u64 pad; // This is not used with eBPF
int vector; // offset:8; size:4; signed:1;
};
struct netdata_irq_vectors_exit {
u64 pad; // This is not used with eBPF
int vector; // offset:8; size:4; signed:1;
};

// these represent static IRQs that aren't given an IRQ ID like the ones above.
// they each require separate entry/exit tracepoints to track.
enum netdata_hardirq_static {
NETDATA_HARDIRQ_STATIC_APIC_THERMAL,
NETDATA_HARDIRQ_STATIC_APIC_THRESHOLD,
NETDATA_HARDIRQ_STATIC_APIC_ERROR,
NETDATA_HARDIRQ_STATIC_APIC_DEFERRED_ERROR,
NETDATA_HARDIRQ_STATIC_APIC_SPURIOUS,
NETDATA_HARDIRQ_STATIC_FUNC_CALL,
NETDATA_HARDIRQ_STATIC_FUNC_CALL_SINGLE,
NETDATA_HARDIRQ_STATIC_RESCHEDULE,
NETDATA_HARDIRQ_STATIC_LOCAL_TIMER,
NETDATA_HARDIRQ_STATIC_IRQ_WORK,
NETDATA_HARDIRQ_STATIC_X86_PLATFORM_IPI,

// must be last; used as counter.
NETDATA_HARDIRQ_STATIC_END
};

typedef struct hardirq_static_val {
// incremental counter storing the total latency so far.
u64 latency;

// temporary timestamp stored at the IRQ entry handler, to be diff'd with a
// timestamp at the IRQ exit handler, to get the latency to add to the
// `latency` field.
u64 ts;
} hardirq_static_val_t;

#endif /* _NETDATA_HARDIRQ_H_ */
1 change: 1 addition & 0 deletions kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ NETDATA_APPS= btrfs \
fd \
fdatasync \
fsync \
hardirq \
mount \
msync \
nfs \
Expand Down
37 changes: 19 additions & 18 deletions kernel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,22 @@ of your distribution.

Right now we have the following `eBPF` program collectors:

- `cachestat_kern.c` : provides Linux page cache monitoring.
- `dc_kern.c` : provides Linux directory cache monitoring.
- `disk_kern.c` : provides disk latency monitoring.
- `ext4_kern.c` : provides ext4 monitoring.
- `fdatasync_kern.c` : monitor calls for syscall `fdatasync`.
- `fsync_kern.c` : monitor calls for syscall `fsync`.
- `mount_kern.c` : monitor calls for syscalls `mount` and `umount`.
- `msync_kern.c` : monitor calls for syscall `msync`.
- `nfs_kern.c` : provides nfs monitoring.
- `process_kern.c` : provides process, file and VFS stats.
- `socket_kern.c` : provides network stats;
- `swap_kern.c` : provides swap stats;
- `sync_file_range_kern.c`: monitor calls for syscall `sync_file_range`.
- `sync_kern.c` : monitor calls for syscall `sync`.
- `syncfs_kern.c` : monitor calls for syscall `syncfs`.
- `vfs_kern.c` : monitor Virtual Filesystem functions.
- `xfs_kern.c` : provides XFS monitoring.
- `zfs_kern.c` : provides ZFS monitoring.
- `cachestat_kern.c` : provides Linux page cache monitoring.
- `dc_kern.c` : provides Linux directory cache monitoring.
- `disk_kern.c` : provides disk latency monitoring.
- `ext4_kern.c` : provides ext4 monitoring.
- `fdatasync_kern.c` : monitor calls for syscall `fdatasync`.
- `fsync_kern.c` : monitor calls for syscall `fsync`.
- `hardirq_kern.c` : provides hard interrupt (hard IRQ) latency monitoring.
- `mount_kern.c` : monitor calls for syscalls `mount` and `umount`.
- `msync_kern.c` : monitor calls for syscall `msync`.
- `nfs_kern.c` : provides nfs monitoring.
- `process_kern.c` : provides process, file and VFS stats.
- `socket_kern.c` : provides network stats;
- `swap_kern.c` : provides swap stats;
- `sync_file_range_kern.c`: monitor calls for syscall `sync_file_range`.
- `sync_kern.c` : monitor calls for syscall `sync`.
- `syncfs_kern.c` : monitor calls for syscall `syncfs`.
- `vfs_kern.c` : monitor Virtual Filesystem functions.
- `xfs_kern.c` : provides XFS monitoring.
- `zfs_kern.c` : provides ZFS monitoring.
Loading