Skip to content

Commit

Permalink
bpf: refactor fileids
Browse files Browse the repository at this point in the history
Signed-off-by: Kornilios Kourtis <[email protected]>
  • Loading branch information
kkourt committed Dec 12, 2024
1 parent fc77143 commit 7dbd046
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ clean: cli-clean tarball-clean

##@ Build and install

pkg/errmetrics/fileids.json: bpf/lib/fileids.h
go run ./cmd/bpf-fileids bpf/lib/fileids.h pkg/errmetrics/fileids.json
pkg/errmetrics/fileids.json: bpf/tetragon/fileids.h
go run ./cmd/bpf-fileids bpf/tetragon/fileids.h pkg/errmetrics/fileids.json

.PHONY: fileids
fileids: pkg/errmetrics/fileids.json
Expand Down
3 changes: 2 additions & 1 deletion bpf/Makefile.defs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ROOT_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
IDIR = $(ROOT_DIR)include/
LIBBPF = $(ROOT_DIR)libbpf/
LDIR = $(ROOT_DIR)lib
TETRAGONDIR = $(ROOT_DIR)tetragon/
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))

FLAGS := -I$(ROOT_DIR) \
Expand All @@ -31,4 +32,4 @@ ifeq ($(DEBUG),1)
__DEBUG_FLAGS = -DTETRAGON_BPF_DEBUG
endif

CLANG_FLAGS += $(FLAGS) -I $(LIBBPF) -I $(IDIR) -I $(LDIR) -target bpf -mcpu=v2 -g -D__TARGET_ARCH_$(BPF_TARGET_ARCH) -fdebug-default-version=4 $(__DEBUG_FLAGS)
CLANG_FLAGS += $(FLAGS) -I $(LIBBPF) -I $(IDIR) -I $(LDIR) -I $(TETRAGONDIR) -target bpf -mcpu=v2 -g -D__TARGET_ARCH_$(BPF_TARGET_ARCH) -fdebug-default-version=4 $(__DEBUG_FLAGS)
13 changes: 1 addition & 12 deletions bpf/lib/bpf_errmetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define BPF_ERRMETRICS_H__

#include "compiler.h"
#include "get_fileid.h"

// should match: pkg/errmetrics/map.go:MapKey
struct errmetrics_key {
Expand All @@ -14,18 +15,6 @@ struct errmetrics_key {
__u16 pad2;
} __attribute__((packed));

FUNC_INLINE __u16
get_fileid__(const char *const fname)
{
#define fileid__(f, id) \
if (!__builtin_strcmp(f, fname)) \
return id;
#include "fileids.h"
#undef fileid__

return 0;
}

struct {
__uint(type, BPF_MAP_TYPE_LRU_PERCPU_HASH);
__uint(max_entries, 1024);
Expand Down
File renamed without changes.
19 changes: 19 additions & 0 deletions bpf/tetragon/get_fileid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
/* Copyright Authors of Tetragon */

#ifndef GET_FILEID_H__
#define GET_FILEID_H__

FUNC_INLINE __u16
get_fileid__(const char *const fname)
{
#define fileid__(f, id) \
if (!__builtin_strcmp(f, fname)) \
return id;
#include "fileids.h"
#undef fileid__

return 0;
}

#endif /* GET_FILEID_H__ */

0 comments on commit 7dbd046

Please sign in to comment.