diff --git a/Makefile b/Makefile index 6c4fa4bd7ead56667c7fb6e6f3daeb0e9666b140..f5ba4bb9176a25c1685abd7d0cba560b0e8aa268 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ debug: all .PHONY: clean clean: $(call msg,CLEAN) - $(Q)rm -rf $(OUTPUT) $(APPS) + $(Q)rm -rf $(OUTPUT) $(APPS) $(patsubst %,%.bpf.o,$(APPS)) $(OUTPUT): $(call msg,MKDIR,$@) @@ -62,6 +62,7 @@ $(OUTPUT)/%.bpf.o: %.bpf.c $(wildcard %.h) | $(OUTPUT) $(VMLINUX_HEADER) $(DEBUG_FLAGS) \ $(INCLUDES) $(CLANG_BPF_SYS_INCLUDES) \ -g -O2 -target bpf -c $(filter %.c,$^) -o $@ + cp $@ $(abspath $(OUTPUT))/.. # Build common-helper code $(OUTPUT)/common_helper.o: common_helper.c | $(OUTPUT) diff --git a/atune_bpf_collection.spec b/atune_bpf_collection.spec index f1ac740fc12530df33767a6671ce3d609b72c536..0ce6dcee59195d6fb4001f911e69f2e0b6053cdb 100644 --- a/atune_bpf_collection.spec +++ b/atune_bpf_collection.spec @@ -25,12 +25,14 @@ make %{?_smp_mflags} %install install -D -p -m 0755 readahead_tune %{buildroot}/%{_sbindir}/readahead_tune +install -D -p -m 0644 readahead_tune.bpf.o %{buildroot}/%{_sbindir}/readahead_tune.bpf.o install -D -p -m 0755 start_readahead_tune %{buildroot}/%{_sbindir}/start_readahead_tune install -D -p -m 0755 stop_readahead_tune %{buildroot}/%{_sbindir}/stop_readahead_tune install -D -p -m 0644 readahead_tune.conf %{buildroot}%{_sysconfdir}/sysconfig/readahead_tune.conf %files %{_sbindir}/readahead_tune +%{_sbindir}/readahead_tune.bpf.o %{_sbindir}/start_readahead_tune %{_sbindir}/stop_readahead_tune %config(noreplace) %{_sysconfdir}/sysconfig/readahead_tune.conf diff --git a/readahead_tune.bpf.c b/readahead_tune.bpf.c index a0e30dd93737a559fc4e713f713e5da8a29aaed4..24a6ff9d64d65cc1142d1f458b76fdf10a14d60a 100644 --- a/readahead_tune.bpf.c +++ b/readahead_tune.bpf.c @@ -14,11 +14,11 @@ #define FMODE_WILLNEED 0x400000 #define PREFIX_PATTERN "blk_" -#define MAX_HASH_TABLE_ENTRY 10000 +#define MAX_HASH_TABLE_ENTRY 100000 #define MAP_ARRAY_SIZE 10 -char _license[] SEC("license") = "GPL"; -__u32 _version SEC("version") = 1; +char g_license[] SEC("license") = "GPL"; +__u32 g_version SEC("version") = 1; struct fs_file_read_args { struct fs_file_read_ctx *ctx; @@ -62,7 +62,6 @@ static __always_inline void get_conf(unsigned long long *file_read_conf, unsigne if (value) { *file_read_conf = *(unsigned long long *)value; } - bpf_trace_printk(conf_fmt, sizeof(conf_fmt), *file_read_conf); } static __always_inline bool is_expected_file(void *name) @@ -97,10 +96,6 @@ int fs_file_read(struct fs_file_read_args *args) * BPF program for-loop */ get_conf(file_read_conf + CONF_FILESZ, CONF_FILESZ); - get_conf(file_read_conf + CONF_READ_TIME, CONF_READ_TIME); - get_conf(file_read_conf + CONF_TOTAL_READ, CONF_TOTAL_READ); - get_conf(file_read_conf + CONF_LOWER_BOUND, CONF_LOWER_BOUND); - get_conf(file_read_conf + CONF_UPPER_BOUND, CONF_UPPER_BOUND); if (rd_ctx->i_size <= file_read_conf[CONF_FILESZ]) { rd_ctx->set_f_mode = FMODE_WILLNEED; @@ -126,14 +121,16 @@ int fs_file_read(struct fs_file_read_args *args) } hist->tot_nr += 1; - bpf_trace_printk(fmt, sizeof(fmt), now - hist->last_nsec, - hist->seq_nr, hist->tot_nr); - if (first) { bpf_map_update_elem(&htab, &key, hist, 0); return 0; } + get_conf(file_read_conf + CONF_READ_TIME, CONF_READ_TIME); + get_conf(file_read_conf + CONF_TOTAL_READ, CONF_TOTAL_READ); + get_conf(file_read_conf + CONF_LOWER_BOUND, CONF_LOWER_BOUND); + get_conf(file_read_conf + CONF_UPPER_BOUND, CONF_UPPER_BOUND); + if (now - hist->last_nsec >= file_read_conf[CONF_READ_TIME] || hist->tot_nr >= file_read_conf[CONF_TOTAL_READ]) { if (hist->tot_nr >= file_read_conf[CONF_TOTAL_READ]) { if (hist->seq_nr <= hist->tot_nr * file_read_conf[CONF_LOWER_BOUND] / HUNDRED_PERCENTAGE) { diff --git a/readahead_tune.c b/readahead_tune.c index 0070e5869220df93106ae2e4352dee2eef2412c8..f07f56e6cf999ae46c6d0afa498ed61b168ef12f 100644 --- a/readahead_tune.c +++ b/readahead_tune.c @@ -160,10 +160,10 @@ static void sig_handler(int sig) int main(int argc, char *argv[]) { - const char *file = ".output/readahead_tune.bpf.o"; + const char *file = "readahead_tune.bpf.o"; struct bpf_object *obj = NULL; unsigned int where = TERM; - int prog_fd; + int prog_fd = -1; int err = argp_parse(&argp, argc, argv, 0, NULL, NULL); if (err) {