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

feat: add AttachStructOps() #476

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions link.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
CgroupLegacy
Netns
Iter
StructOps
)

//
Expand All @@ -47,6 +48,7 @@ type bpfLinkLegacy struct {
type BPFLink struct {
link *C.struct_bpf_link
prog *BPFProg
m *BPFMap
linkType LinkType
eventName string
legacy *bpfLinkLegacy // if set, this is a fake BPFLink
Expand Down
13 changes: 13 additions & 0 deletions map.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ func (m *BPFMap) ReuseFD(fd int) error {
return nil
}

func (m *BPFMap) AttachStructOps() (*BPFLink, error) {
linkC, errno := C.bpf_map__attach_struct_ops(m.bpfMap)
if linkC == nil {
return nil, fmt.Errorf("failed to attach struct_ops: %w", errno)
}
return &BPFLink{
link: linkC,
m: m,
linkType: StructOps,
eventName: fmt.Sprintf("structOps-%s", m.Name()),
}, nil
}

func (m *BPFMap) Name() string {
return C.GoString(C.bpf_map__name(m.bpfMap))
}
Expand Down
5 changes: 4 additions & 1 deletion selftest/common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ LDFLAGS =
CGO_CFLAGS_STATIC = "-I$(abspath $(OUTPUT)) -I$(abspath ../common)"
CGO_LDFLAGS_STATIC = "$(shell PKG_CONFIG_PATH=$(LIBBPF_OBJDIR) $(PKGCONFIG) --static --libs libbpf)"
CGO_EXTLDFLAGS_STATIC = '-w -extldflags "-static"'
SCX_FLAGS=-mcpu=v3 -mlittle-endian \
-I ../../libbpf/src/usr/include -I ../../libbpf/include/uapi \
-I /lib/modules/$(shell uname -r)/build/tools/sched_ext/include/scx -I /lib/modules/$(shell uname -r)/build/tools/sched_ext/include/bpf-compat

CGO_CFLAGS_DYN = "-I. -I/usr/include/"
CGO_LDFLAGS_DYN = "$(shell $(PKGCONFIG) --shared --libs libbpf)"
Expand Down Expand Up @@ -52,7 +55,7 @@ outputdir:
## test bpf dependency

$(MAIN).bpf.o: $(MAIN).bpf.c
$(CLANG) $(CFLAGS) -target bpf -D__TARGET_ARCH_$(ARCH) -I$(OUTPUT) -I$(abspath ../common) -c $< -o $@
$(CLANG) $(CFLAGS) -target bpf -D__TARGET_ARCH_$(ARCH) $(SCX_FLAGS) -I$(OUTPUT) -I$(abspath ../common) -c $< -o $@

## test

Expand Down
Loading
Loading