Skip to content
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
bpftune: expose strategy_id to tuner bpf programs
tuners that share bpf programs across strategies may want to
have different behaviours depending on which strategy is active;
assign strategy ids when strategies are added to tuner and expose
to bpf progs via strategy_id variable; it is set as part of
bpftune_bpf_open().

Signed-off-by: Alan Maguire <[email protected]>
  • Loading branch information
alan-maguire committed Aug 23, 2023
commit 9f1e82fb2537c02b1a1da726b42d0bab8e33f384
1 change: 1 addition & 0 deletions include/bpftune/bpftune.bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ BPF_RINGBUF(ring_buffer_map, 128 * 1024);
BPF_MAP_DEF(netns_map, BPF_MAP_TYPE_HASH, __u64, __u64, 65536);

unsigned int tuner_id;
unsigned int strategy_id;
unsigned int bpftune_pid;
/* init_net value used for older kernels since __ksym does not work */
unsigned long bpftune_init_net;
Expand Down
1 change: 1 addition & 0 deletions include/bpftune/bpftune.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ struct bpftuner_strategy {
/* return a number to compare with other strategies */
long double (*evaluate)(struct bpftuner *tuner, struct bpftuner_strategy *strategy);
unsigned long timeout; /* time in seconds until evaluation */
unsigned int id; /* strategy id */
const char **bpf_progs; /* programs to load in BPF skeleton for this
* strategy; if NULL, all */
};
Expand Down
2 changes: 2 additions & 0 deletions include/bpftune/libbpftune.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ void bpftuner_tunables_fini(struct bpftuner *tuner);
__skel->bss->bpftune_pid = getpid(); \
__skel->bss->bpftune_learning_rate = bpftune_learning_rate; \
__skel->bss->tuner_id = bpftune_tuner_num(); \
if (tuner->strategy) \
__skel->bss->strategy_id = tuner->strategy->id; \
tuner->obj = __skel->obj; \
tuner->ring_buffer_map = __skel->maps.ring_buffer_map; \
tuner->netns_map = __skel->maps.netns_map; \
Expand Down
4 changes: 2 additions & 2 deletions sample_tuner/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ $(TUNER_LIBS): $(BPF_SKELS) $(TUNER_OBJS)
%.skel.h: %.bpf.o
$(QUIET_GEN)$(BPFTOOL) gen skeleton $< > $@

$(BPF_OBJS): $(patsubst %.o,%.c,$(BPF_OBJS))
$(CLANG) -g -D__TARGET_ARCH_$(SRCARCH) -O2 -target bpf \
$(BPF_OBJS): $(patsubst %.o,%.c,$(BPF_OBJS)) ../include/bpftune/bpftune.bpf.h
$(CLANG) -g -D__TARGET_ARCH_$(SRCARCH) -O2 -target bpf \
$(INCLUDES) -c $(patsubst %.o,%.c,$(@)) -o $(@);
$(CLANG) -g -D__TARGET_ARCH_$(SRCARCH) -DBPFTUNE_LEGACY -O2 -target bpf \
$(INCLUDES) -c $(patsubst %.o,%.c,$(@)) \
Expand Down
6 changes: 3 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,16 @@ $(OPATH)bpftune.o: $(OPATH)libbpftune.so
%.skel.h: %.bpf.o
$(QUIET_GEN)$(BPFTOOL) gen skeleton $< > $@

$(BPF_OBJS): $(patsubst %.o,%.c,$(BPF_OBJS))
$(BPF_OBJS): $(patsubst %.o,%.c,$(BPF_OBJS)) ../include/bpftune/bpftune.bpf.h
$(CLANG) $(BPF_CFLAGS) -D__TARGET_ARCH_$(SRCARCH) -O2 -target bpf \
$(INCLUDES) -c $(patsubst %.o,%.c,$(@)) -o $(@)

$(LEGACY_BPF_OBJS): $(patsubst %.legacy.o,%.c,$(LEGACY_BPF_OBJS))
$(LEGACY_BPF_OBJS): $(patsubst %.legacy.o,%.c,$(LEGACY_BPF_OBJS)) ../include/bpftune/bpftune.bpf.h
$(CLANG) $(BPF_CFLAGS) -D__TARGET_ARCH_$(SRCARCH) -DBPFTUNE_LEGACY -O2 -target bpf \
$(INCLUDES) -c $(patsubst %.legacy.o,%.c,$(@)) \
-o $(@)

$(NOBTF_BPF_OBJS): $(patsubst %.nobtf.o,%.c,$(NOBTF_BPF_OBJS))
$(NOBTF_BPF_OBJS): $(patsubst %.nobtf.o,%.c,$(NOBTF_BPF_OBJS)) ../include/bpftune/bpftune.bpf.h
$(CLANG) $(BPF_CFLAGS) -D__TARGET_ARCH_$(SRCARCH) -DBPFTUNE_NOBTF -O2 -target bpf \
$(INCLUDES) -c $(patsubst %.nobtf.o,%.c,$(@)) \
-o $(@)
Expand Down
6 changes: 6 additions & 0 deletions src/libbpftune.c
Original file line number Diff line number Diff line change
Expand Up @@ -1620,9 +1620,15 @@ int bpftuner_strategy_set(struct bpftuner *tuner,
int bpftuner_strategies_add(struct bpftuner *tuner, struct bpftuner_strategy **strategies,
struct bpftuner_strategy *default_strategy)
{
struct bpftuner_strategy *strategy;
unsigned int strategy_id = 0;

if (!strategies || tuner->strategies)
return 0;
tuner->strategies = strategies;
/* assign ids to each strategy added; used in BPF context */
bpftuner_for_each_strategy(tuner, strategy)
strategy->id = strategy_id++;
if (default_strategy)
return bpftuner_strategy_set(tuner, default_strategy);
bpftuner_strategy_update(tuner);
Expand Down
6 changes: 3 additions & 3 deletions test/strategy/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ $(TUNER_LIBS): $(BPF_SKELS) $(TUNER_OBJS)

$(TUNER_OBJS): $(BPF_SKELS) $(LEGACY_BPF_SKELS) $(NOBTF_BPF_SKELS)

$(BPF_OBJS): $(patsubst %.o,%.c,$(BPF_OBJS))
$(BPF_OBJS): $(patsubst %.o,%.c,$(BPF_OBJS)) ../../include/bpftune/bpftune.bpf.h
$(CLANG) $(BPF_CFLAGS) -D__TARGET_ARCH_$(SRCARCH) -O2 -target bpf \
$(INCLUDES) -c $(patsubst %.o,%.c,$(@)) -o $(@)

$(LEGACY_BPF_OBJS): $(patsubst %.legacy.o,%.c,$(LEGACY_BPF_OBJS))
$(LEGACY_BPF_OBJS): $(patsubst %.legacy.o,%.c,$(LEGACY_BPF_OBJS)) ../../include/bpftune/bpftune.bpf.h
$(CLANG) $(BPF_CFLAGS) -D__TARGET_ARCH_$(SRCARCH) -DBPFTUNE_LEGACY -O2 -target bpf \
$(INCLUDES) -c $(patsubst %.legacy.o,%.c,$(@)) \
-o $(@)

$(NOBTF_BPF_OBJS): $(patsubst %.nobtf.o,%.c,$(NOBTF_BPF_OBJS))
$(NOBTF_BPF_OBJS): $(patsubst %.nobtf.o,%.c,$(NOBTF_BPF_OBJS)) ../../include/bpftune/bpftune.bpf.h
$(CLANG) $(BPF_CFLAGS) -D__TARGET_ARCH_$(SRCARCH) -DBPFTUNE_NOBTF -O2 -target bpf \
$(INCLUDES) -c $(patsubst %.nobtf.o,%.c,$(@)) \
-o $(@)
Expand Down