Skip to content

Commit

Permalink
fixed kernel versions
Browse files Browse the repository at this point in the history
Signed-off-by: Afek Berger <[email protected]>
  • Loading branch information
afek854 committed Feb 5, 2025
1 parent dbf553a commit 873ea7d
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 13 deletions.
19 changes: 17 additions & 2 deletions pkg/ebpf/gadgets/iouring/tracer/bpf/iouring.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,24 @@
#include "../../../../include/macros.h"
#include "../../../../include/buffer.h"

extern int LINUX_KERNEL_VERSION __kconfig;
#ifndef __KERNEL_FEATURE_H
#define __KERNEL_FEATURE_H

#define HAS_KERNEL_FEATURE(maj, min) (CURRENT_KERNEL_VERSION >= KERNEL_VERSION(maj, min, 0))
/* Define macro to check kernel version features */
#define HAS_KERNEL_FEATURE(major, minor) \
(KERNEL_VERSION_MAJOR > (major) || \
(KERNEL_VERSION_MAJOR == (major) && KERNEL_VERSION_MINOR >= (minor)))

/* Define current kernel version based on compile-time flags */
#ifdef VERSION_63
#define KERNEL_VERSION_MAJOR 6
#define KERNEL_VERSION_MINOR 3
#else
#define KERNEL_VERSION_MAJOR 0
#define KERNEL_VERSION_MINOR 0
#endif

#endif /* __KERNEL_FEATURE_H */

struct trace_event_raw_io_uring_submit_req {
struct trace_entry ent;
Expand Down
161 changes: 161 additions & 0 deletions pkg/ebpf/gadgets/iouring/tracer/iouring_63_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
28 changes: 17 additions & 11 deletions pkg/ebpf/gadgets/iouring/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/shirou/gopsutil/v4/host"
)

//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -strip /usr/bin/llvm-strip-18 -no-global-types -target bpfel -cc clang -cflags "-g -O2 -Wall -DVERSION_63=1" -type event iouring_63 bpf/iouring.c -- -I./bpf/
//go:generate go run github.com/cilium/ebpf/cmd/bpf2go -strip /usr/bin/llvm-strip-18 -no-global-types -target bpfel -cc clang -cflags "-g -O2 -Wall" -type event iouring bpf/iouring.c -- -I./bpf/

const (
Expand Down Expand Up @@ -66,32 +67,37 @@ func (t *Tracer) Close() {
}

func (t *Tracer) install() error {
spec, err := loadIouring()
if err != nil {
return fmt.Errorf("loading ebpf program: %w", err)
}

if err := gadgets.LoadeBPFSpec(t.config.MountnsMap, spec, nil, &t.objs); err != nil {
return fmt.Errorf("loading ebpf spec: %w", err)
}
var spec *ebpf.CollectionSpec
var tracepointName string

info, err := host.Info()
if err != nil {
return fmt.Errorf("failed to get host info: %w", err)
}

var tracepointName string
major, minor, _, err := kernel.ParseKernelVersion(info.KernelVersion)
if err != nil {
return fmt.Errorf("parsing kernel version: %w", err)
}

if major >= SupportedMajor && minor >= SupportedMinor {
tracepointName = "io_uring_submit_req"
spec, err = loadIouring_63()
if err != nil {
return fmt.Errorf("loading ebpf program: %w", err)
}
tracepointName = "io_uring_submit_sqe"

} else {
spec, err = loadIouring()
if err != nil {
return fmt.Errorf("loading ebpf program: %w", err)
}
tracepointName = "io_uring_submit_sqe"
}

if err := gadgets.LoadeBPFSpec(t.config.MountnsMap, spec, nil, &t.objs); err != nil {
return fmt.Errorf("loading ebpf spec: %w", err)
}

tracepoint, err := link.Tracepoint("io_uring", tracepointName, t.objs.HandleSubmitReq, nil)
if err != nil {
return fmt.Errorf("attaching tracepoint %s: %w", tracepointName, err)
Expand Down

0 comments on commit 873ea7d

Please sign in to comment.