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

Add softirq type in prober #182

Merged
merged 1 commit into from
Feb 4, 2024
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
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ FROM docker.io/library/golang:1.20.5-alpine AS build
ARG GOPROXY
# --build-arg ALPINE_MIRROR=mirrors.aliyun.com
ARG ALPINE_MIRROR
ENV GOPROXY=$GOPROXY
ENV ALPINE_MIRROR=$ALPINE_MIRROR

RUN if [ ! -z "$ALPINE_MIRROR" ]; then sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories; fi && \
apk add gcc g++ linux-headers git make bash && \
Expand All @@ -18,8 +20,12 @@ ADD ./webui /webconsole
RUN yarn install && yarn build

FROM docker.io/library/alpine

RUN apk add --no-cache \
ARG GOPROXY
ARG ALPINE_MIRROR
ENV GOPROXY=$GOPROXY
ENV ALPINE_MIRROR=$ALPINE_MIRROR
RUN if [ ! -z "$ALPINE_MIRROR" ]; then sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories; fi && \
apk add --no-cache \
iproute2 \
ipset \
iptables \
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ build-btfhack:
build-webconsole:
cd webui && CGO_ENABLED=0 go build -o ../bin/webconsole -ldflags $(ldflags) .

.PHONY: generate-btf
generate-btf:
go generate ./pkg/exporter/probe/...

.PHONY: image
image: ## build kubeskoop image
docker build -t $(SKOOP_REPO):$(TAG) .
Expand Down
75 changes: 49 additions & 26 deletions bpf/net_softirq.c → bpf/softirq.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,35 @@
#define PHASE_EXCUTE 2
#define SOFTIRQ_THRESH 10000000

volatile const __u32 irq_filter_bits = 0x8; // {"net_rx"}

bool filter_irqs(u32 vec_nr)
{
return (irq_filter_bits & (1 << vec_nr)) != 0;
}

struct softirq_args {
unsigned long pad;
unsigned int vec;
};

struct insp_softirq_entry_key {
u32 vec_nr;
u32 phase;
};

struct insp_softirq_event_t {
u32 pid;
u32 cpu;
u32 phase;
u32 vec_nr;
u64 latency;
};

struct {
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__uint(max_entries, 2);
__type(key, u32);
__uint(type, BPF_MAP_TYPE_PERCPU_HASH);
__uint(max_entries, 64);
__type(key, struct insp_softirq_entry_key);
__type(value, u64);
} insp_softirq_entry SEC(".maps");

Expand All @@ -37,13 +50,13 @@ struct {

struct insp_softirq_event_t *unused_event __attribute__((unused));

static inline int report_softirq_events(void *ctx, u64 latency, u32 phase)
static inline int report_softirq_events(void *ctx, u64 latency, u32 phase, u32 vec_nr)
{
struct insp_softirq_event_t event = {0};
event.pid = bpf_get_current_pid_tgid()>> 32;
event.cpu = bpf_get_smp_processor_id();
event.latency = latency;
event.phase = phase;
event.vec_nr = vec_nr;
bpf_perf_event_output(ctx, &insp_softirq_events, BPF_F_CURRENT_CPU, &event, sizeof(event));
return 0;
}
Expand All @@ -52,56 +65,66 @@ SEC("tracepoint/irq/softirq_raise")
int trace_softirq_raise(struct softirq_args *ctx)
{
u32 vec_nr = ctx->vec;
if(vec_nr!=3){
if(filter_irqs(vec_nr) == false){
return 0;
}
u64 ts = bpf_ktime_get_ns();
u32 rasiekey = 0;
bpf_map_update_elem(&insp_softirq_entry, &rasiekey, &ts, 0);
struct insp_softirq_entry_key key = {0};
key.vec_nr = vec_nr;
key.phase = PHASE_SCHED;
// only keep the first raise entry
bpf_map_update_elem(&insp_softirq_entry, &key, &ts, BPF_NOEXIST);
return 0;
}

SEC("tracepoint/irq/softirq_entry")
int trace_softirq_entry(struct softirq_args *ctx)
{
u32 vec_nr = ctx->vec;
if(vec_nr!=3){
if(filter_irqs(vec_nr) == false){
return 0;
}
u32 rasiekey = 0;
u64 *tsp = bpf_map_lookup_elem(&insp_softirq_entry,&rasiekey);
if (!tsp) {
return 0;
}
u64 ts = bpf_ktime_get_ns();
u64 latency;
latency = ts - *tsp;
if( latency>SOFTIRQ_THRESH ){
report_softirq_events(ctx,latency,PHASE_SCHED);
struct insp_softirq_entry_key key = {0};
key.vec_nr = vec_nr;
key.phase = PHASE_SCHED;
u64 ts = bpf_ktime_get_ns();
u64 *tsp = bpf_map_lookup_elem(&insp_softirq_entry, &key);
if (tsp && *tsp != 0) {
u64 latency;
latency = ts - *tsp;
if( latency>SOFTIRQ_THRESH ){
report_softirq_events(ctx,latency, PHASE_SCHED, vec_nr);
}
}
u32 entrykey = 1;
bpf_map_update_elem(&insp_softirq_entry, &entrykey, &ts, 0);
bpf_map_delete_elem(&insp_softirq_entry, &key);

key.vec_nr = vec_nr;
key.phase = PHASE_EXCUTE;
bpf_map_update_elem(&insp_softirq_entry, &key, &ts, BPF_ANY);
return 0;
}

SEC("tracepoint/irq/softirq_exit")
int trace_softirq_exit(struct softirq_args *ctx)
{
u32 vec_nr = ctx->vec;
if(vec_nr!=3){
if(filter_irqs(vec_nr) == false){
return 0;
}
u32 entrykey = 1;
u64 *tsp = bpf_map_lookup_elem(&insp_softirq_entry,&entrykey);
if (!tsp) {
struct insp_softirq_entry_key key = {0};
key.vec_nr = vec_nr;
key.phase = PHASE_EXCUTE;
u64 *tsp = bpf_map_lookup_elem(&insp_softirq_entry, &key);
if (!tsp || *tsp == 0) {
return 0;
}
u64 ts = bpf_ktime_get_ns();
u64 latency;
latency = ts - *tsp;
if( latency>SOFTIRQ_THRESH ){
report_softirq_events(ctx,latency,PHASE_EXCUTE);
report_softirq_events(ctx,latency,PHASE_EXCUTE, vec_nr);
}
bpf_map_delete_elem(&insp_softirq_entry, &key);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/exporter/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
_ "github.com/alibaba/kubeskoop/pkg/exporter/probe/tracebiolatency"
_ "github.com/alibaba/kubeskoop/pkg/exporter/probe/tracekernel"
_ "github.com/alibaba/kubeskoop/pkg/exporter/probe/tracenetiftxlatency"
_ "github.com/alibaba/kubeskoop/pkg/exporter/probe/tracenetsoftirq"
_ "github.com/alibaba/kubeskoop/pkg/exporter/probe/tracepacketloss"
_ "github.com/alibaba/kubeskoop/pkg/exporter/probe/tracesocketlatency"
_ "github.com/alibaba/kubeskoop/pkg/exporter/probe/tracesoftirq"
_ "github.com/alibaba/kubeskoop/pkg/exporter/probe/tracetcpreset"
_ "github.com/alibaba/kubeskoop/pkg/exporter/probe/tracevirtcmdlat"
)
2 changes: 1 addition & 1 deletion deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Skoop-exporter支持的配置项如下:
| io | Infromation of io syscalls, support metrics | `true` |
| socketlatency | Latency statistics of socket recv/send syscalls, support metrics and events | `true` |
| packetloss | Infromation of io syscalls, support metrics | `true` |
| net_softirq | Network softirq sched and excute latency, support metrics and events | `true` |
| softirq | softirq sched and excute latency, support metrics and events | `true` |
| tcpext | Infromation of tcp netstat, support metrics | `true` |
| tcpsummary | Infromation of tcp detail connection statistic, support metrics | `true` |
| tcp | Infromation of snmp statistics, support metrics | `true` |
Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ config:
- name: io
- name: socketlatency
- name: packetloss
- name: net_softirq
- name: softirq
- name: tcpext
- name: tcpsummary
- name: tcp
Expand Down
2 changes: 1 addition & 1 deletion deploy/vagrant-exporter/deploy/skoop-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ data:
- tcp
- tcpext
- udp
- net_softirq
- softirq
- virtcmdlatency
event_config:
port: 19102
Expand Down
Binary file removed pkg/exporter/probe/tracenetsoftirq/bpf_bpfeb.o
Binary file not shown.
Binary file removed pkg/exporter/probe/tracenetsoftirq/bpf_bpfel.o
Binary file not shown.
Loading
Loading