diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2025-03-27 17:03:01 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2025-03-27 17:03:01 -0700 |
commit | 4fa118e5b79fcc537dcb1a860ed319a6106935eb (patch) | |
tree | 039083bd0075ccd8cca5a11dd8b7adad83c46369 /tools | |
parent | 744fab2d9ff9177a27647c3710e86d43f2efe68c (diff) | |
parent | 732032692f6ae311bc35159b18e5b7c5e64010fc (diff) | |
download | linux-4fa118e5b79fcc537dcb1a860ed319a6106935eb.tar.gz linux-4fa118e5b79fcc537dcb1a860ed319a6106935eb.tar.bz2 linux-4fa118e5b79fcc537dcb1a860ed319a6106935eb.zip |
Merge tag 'trace-tools-v6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull tracing tooling updates from Steven Rostedt:
- Allow RTLA to collect data via BPF
The current implementation of rtla uses libtracefs and libtraceevent
to pull sample events generated by the timerlat tracer from the trace
buffer. rtla then processes the sample by updating the histogram and
summary (current, maximum, minimum, and sum values) as well as checks
if tracing has been stopped due to threshold overflow.
In use cases where a large number of samples is being generated, that
is, with measurements running on many CPUs and with a low interval,
this sample processing design causes a significant CPU load on the
rtla side. Furthermore, with >100 CPUs and 100us interval, rtla was
reported as not being able to keep up with the samples and dropping
most of them, leading to it being unusable.
Change the way the timerlat trace processes samples by attaching a
BPF program to the trace event using the BPF skeleton feature of
bpftool. Unlike the current implementation, the BPF implementation
does not check whether tracing is stopped (in BPF mode, tracing is
always off to improve performance), but waits for a write to a BPF
ringbuffer instead. This allows rtla to exit immediately when a
threshold is violated, without waiting for the next iteration of the
while loop.
If the requirements for the BPF implementation are not met, either at
build time or at run time, the current implementation is used as
fallback. Which implementation is being used can be seen when running
rtla timerlat with "-D" option. rtla can be forced to run in non-BPF
mode by setting the RTLA_NO_BPF option to 1, for debugging purposes.
- Fix LD_FLAGS from being dropped in build
- Refactor code to remove duplication of save_trace_to_file
- Always set options and do not rely on default settings
Do not rely on the default kernel settings of the tracers when
starting. They could have been changed by the user which gives
inconsistent results. Always set the options that rtla expects.
- Add creation of ctags and TAGS for traversing code
* tag 'trace-tools-v6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace:
rtla: Add the ability to create ctags and etags
rtla/tests: Test setting default options
rtla/tests: Reset osnoise options before check
rtla: Always set all tracer options
rtla/osnoise: Set OSNOISE_WORKLOAD to true
rtla: Unify apply_config between top and hist
rtla/osnoise: Unify params struct
rtla: Fix segfault in save_trace_to_file call
tools/build: Use SYSTEM_BPFTOOL for system bpftool
rtla: Refactor save_trace_to_file
tools/rv: Keep user LDFLAGS in build
rtla/timerlat: Test BPF mode
rtla/timerlat_top: Use BPF to collect samples
rtla/timerlat_top: Move divisor to update
rtla/timerlat_hist: Use BPF to collect samples
rtla/timerlat: Add BPF skeleton to collect samples
rtla: Add optional dependency on BPF tooling
tools/build: Add bpftool-skeletons feature test
rtla/timerlat: Unify params struct
Diffstat (limited to 'tools')
25 files changed, 1315 insertions, 625 deletions
diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature index 1931b6321314..1f44ca677ad3 100644 --- a/tools/build/Makefile.feature +++ b/tools/build/Makefile.feature @@ -135,7 +135,8 @@ FEATURE_TESTS_EXTRA := \ libbpf-bpf_create_map \ libpfm4 \ libdebuginfod \ - clang-bpf-co-re + clang-bpf-co-re \ + bpftool-skeletons FEATURE_TESTS ?= $(FEATURE_TESTS_BASIC) diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index cb1e3e2feedf..b8b5fb183dd4 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile @@ -418,6 +418,9 @@ $(OUTPUT)test-file-handle.bin: $(OUTPUT)test-libpfm4.bin: $(BUILD) -lpfm +$(OUTPUT)test-bpftool-skeletons.bin: + $(SYSTEM_BPFTOOL) version | grep '^features:.*skeletons' \ + > $(@:.bin=.make.output) 2>&1 ############################### clean: diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.include index 45f4abef7064..5158250988ce 100644 --- a/tools/scripts/Makefile.include +++ b/tools/scripts/Makefile.include @@ -91,6 +91,9 @@ LLVM_CONFIG ?= llvm-config LLVM_OBJCOPY ?= llvm-objcopy LLVM_STRIP ?= llvm-strip +# Some tools require bpftool +SYSTEM_BPFTOOL ?= bpftool + ifeq ($(CC_NO_CLANG), 1) EXTRA_WARNINGS += -Wstrict-aliasing=3 diff --git a/tools/tracing/rtla/.gitignore b/tools/tracing/rtla/.gitignore index 293f0dbb0ca2..1a394ad26cc1 100644 --- a/tools/tracing/rtla/.gitignore +++ b/tools/tracing/rtla/.gitignore @@ -4,3 +4,4 @@ rtla-static fixdep feature FEATURE-DUMP +*.skel.h diff --git a/tools/tracing/rtla/Makefile b/tools/tracing/rtla/Makefile index 0b61208db604..746ccf2f5808 100644 --- a/tools/tracing/rtla/Makefile +++ b/tools/tracing/rtla/Makefile @@ -33,9 +33,15 @@ DOCSRC := ../../../Documentation/tools/rtla/ FEATURE_TESTS := libtraceevent FEATURE_TESTS += libtracefs FEATURE_TESTS += libcpupower +FEATURE_TESTS += libbpf +FEATURE_TESTS += clang-bpf-co-re +FEATURE_TESTS += bpftool-skeletons FEATURE_DISPLAY := libtraceevent FEATURE_DISPLAY += libtracefs FEATURE_DISPLAY += libcpupower +FEATURE_DISPLAY += libbpf +FEATURE_DISPLAY += clang-bpf-co-re +FEATURE_DISPLAY += bpftool-skeletons all: $(RTLA) @@ -61,6 +67,17 @@ CFLAGS += $(INCLUDES) $(LIB_INCLUDES) export CFLAGS OUTPUT srctree +ifeq ($(BUILD_BPF_SKEL),1) +src/timerlat.bpf.o: src/timerlat.bpf.c + $(QUIET_CLANG)$(CLANG) -g -O2 -target bpf -c $(filter %.c,$^) -o $@ + +src/timerlat.skel.h: src/timerlat.bpf.o + $(QUIET_GENSKEL)$(SYSTEM_BPFTOOL) gen skeleton $< > $@ +else +src/timerlat.skel.h: + $(Q)echo '/* BPF skeleton is disabled */' > src/timerlat.skel.h +endif + $(RTLA): $(RTLA_IN) $(QUIET_LINK)$(CC) $(LDFLAGS) -o $(RTLA) $(RTLA_IN) $(EXTLIBS) @@ -71,7 +88,7 @@ static: $(RTLA_IN) rtla.%: fixdep FORCE make -f $(srctree)/tools/build/Makefile.build dir=. $@ -$(RTLA_IN): fixdep FORCE +$(RTLA_IN): fixdep FORCE src/timerlat.skel.h make $(build)=rtla clean: doc_clean fixdep-clean @@ -79,6 +96,7 @@ clean: doc_clean fixdep-clean $(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete $(Q)rm -f rtla rtla-static fixdep FEATURE-DUMP rtla-* $(Q)rm -rf feature + $(Q)rm -f src/timerlat.bpf.o src/timerlat.skel.h check: $(RTLA) RTLA=$(RTLA) prove -o -f tests/ .PHONY: FORCE clean check diff --git a/tools/tracing/rtla/Makefile.config b/tools/tracing/rtla/Makefile.config index 92a6e12e42d3..5f2231d8d626 100644 --- a/tools/tracing/rtla/Makefile.config +++ b/tools/tracing/rtla/Makefile.config @@ -53,6 +53,48 @@ else $(info Please install libcpupower-dev/kernel-tools-libs-devel) endif +ifndef BUILD_BPF_SKEL + # BPF skeletons are used to implement improved sample collection, enable + # them by default. + BUILD_BPF_SKEL := 1 +endif + +ifeq ($(BUILD_BPF_SKEL),0) + $(info BPF skeleton support disabled, building without BPF skeleton support.) +endif + +$(call feature_check,libbpf) +ifeq ($(feature-libbpf), 1) + $(call detected,CONFIG_LIBBPF) +else + $(info libbpf is missing, building without BPF skeleton support.) + $(info Please install libbpf-dev/libbpf-devel) + BUILD_BPF_SKEL := 0 +endif + +$(call feature_check,clang-bpf-co-re) +ifeq ($(feature-clang-bpf-co-re), 1) + $(call detected,CONFIG_CLANG_BPF_CO_RE) +else + $(info clang is missing or does not support BPF CO-RE, building without BPF skeleton support.) + $(info Please install clang) + BUILD_BPF_SKEL := 0 +endif + +$(call feature_check,bpftool-skeletons) +ifeq ($(feature-bpftool-skeletons), 1) + $(call detected,CONFIG_BPFTOOL_SKELETONS) +else + $(info bpftool is missing or not supporting skeletons, building without BPF skeleton support.) + $(info Please install bpftool) + BUILD_BPF_SKEL := 0 +endif + +ifeq ($(BUILD_BPF_SKEL),1) + CFLAGS += -DHAVE_BPF_SKEL + EXTLIBS += -lbpf +endif + ifeq ($(STOP_ERROR),1) $(error Please, check the errors above.) endif diff --git a/tools/tracing/rtla/Makefile.rtla b/tools/tracing/rtla/Makefile.rtla index cc1d6b615475..08c1b40883d3 100644 --- a/tools/tracing/rtla/Makefile.rtla +++ b/tools/tracing/rtla/Makefile.rtla @@ -34,6 +34,8 @@ INSTALL := install MKDIR := mkdir STRIP := strip BINDIR := /usr/bin +CTAGS := ctags +ETAGS := ctags -e .PHONY: install install: doc_install @@ -47,6 +49,18 @@ install: doc_install @test ! -f $(DESTDIR)$(BINDIR)/timerlat || $(RM) $(DESTDIR)$(BINDIR)/timerlat @$(LN) -s rtla $(DESTDIR)$(BINDIR)/timerlat +.PHONY: tags +tags: + $(CTAGS) -R --extras=+f --c-kinds=+p src + +.PHONY: TAGS +TAGS: + $(ETAGS) -R --extras=+f --c-kinds=+p src + +.PHONY: tags_clean +tags_clean: + $(RM) tags TAGS + .PHONY: doc doc_clean doc_install doc: $(MAKE) -C $(DOCSRC) @@ -57,8 +71,7 @@ doc_clean: doc_install: $(MAKE) -C $(DOCSRC) install -# This section is neesary for the tarball, when the tarball -# support is removed, we can delete these entries. +# This section is necessary to make the rtla tarball NAME := rtla DIRS := src FILES := Makefile README.txt diff --git a/tools/tracing/rtla/src/Build b/tools/tracing/rtla/src/Build index dbed9e31829b..7bb7e39e391a 100644 --- a/tools/tracing/rtla/src/Build +++ b/tools/tracing/rtla/src/Build @@ -8,4 +8,5 @@ rtla-y += timerlat_top.o rtla-y += timerlat_hist.o rtla-y += timerlat_u.o rtla-y += timerlat_aa.o +rtla-y += timerlat_bpf.o rtla-y += rtla.o diff --git a/tools/tracing/rtla/src/osnoise.c b/tools/tracing/rtla/src/osnoise.c index 85f398b89597..2dc3e4539e99 100644 --- a/tools/tracing/rtla/src/osnoise.c +++ b/tools/tracing/rtla/src/osnoise.c @@ -3,6 +3,7 @@ * Copyright (C) 2021 Red Hat Inc, Daniel Bristot de Oliveira <bristot@kernel.org> */ +#define _GNU_SOURCE #include <sys/types.h> #include <sys/stat.h> #include <pthread.h> @@ -12,9 +13,12 @@ #include <errno.h> #include <fcntl.h> #include <stdio.h> +#include <sched.h> #include "osnoise.h" -#include "utils.h" + +#define DEFAULT_SAMPLE_PERIOD 1000000 /* 1s */ +#define DEFAULT_SAMPLE_RUNTIME 1000000 /* 1s */ /* * osnoise_get_cpus - return the original "osnoise/cpus" content @@ -1115,6 +1119,86 @@ osnoise_report_missed_events(struct osnoise_tool *tool) } } +/* + * osnoise_apply_config - apply common configs to the initialized tool + */ +int +osnoise_apply_config(struct osnoise_tool *tool, struct osnoise_params *params) +{ + int retval; + + if (!params->sleep_time) + params->sleep_time = 1; + + retval = osnoise_set_cpus(tool->context, params->cpus ? params->cpus : "all"); + if (retval) { + err_msg("Failed to apply CPUs config\n"); + goto out_err; + } + + if (params->runtime || params->period) { + retval = osnoise_set_runtime_period(tool->context, + params->runtime, + params->period); + } else { + retval = osnoise_set_runtime_period(tool->context, + DEFAULT_SAMPLE_PERIOD, + DEFAULT_SAMPLE_RUNTIME); + } + + if (retval) { + err_msg("Failed to set runtime and/or period\n"); + goto out_err; + } + + retval = osnoise_set_stop_us(tool->context, params->stop_us); + if (retval) { + err_msg("Failed to set stop us\n"); + goto out_err; + } + + retval = osnoise_set_stop_total_us(tool->context, params->stop_total_us); + if (retval) { + err_msg("Failed to set stop total us\n"); + goto out_err; + } + + retval = osnoise_set_tracing_thresh(tool->context, params->threshold); + if (retval) { + err_msg("Failed to set tracing_thresh\n"); + goto out_err; + } + + if (params->hk_cpus) { + retval = sched_setaffinity(getpid(), sizeof(params->hk_cpu_set), + ¶ms->hk_cpu_set); + if (retval == -1) { + err_msg("Failed to set rtla to the house keeping CPUs\n"); + goto out_err; + } + } else if (params->cpus) { + /* + * Even if the user do not set a house-keeping CPU, try to + * move rtla to a CPU set different to the one where the user + * set the workload to run. + * + * No need to check results as this is an automatic attempt. + */ + auto_house_keeping(¶ms->monitored_cpus); + } + + retval = osnoise_set_workload(tool->context, true); + if (retval < -1) { + err_msg("Failed to set OSNOISE_WORKLOAD option\n"); + goto out_err; + } + + return 0; + +out_err: + return -1; +} + static void osnoise_usage(int err) { int i; diff --git a/tools/tracing/rtla/src/osnoise.h b/tools/tracing/rtla/src/osnoise.h index 91835a7d8c2b..ac1c99910744 100644 --- a/tools/tracing/rtla/src/osnoise.h +++ b/tools/tracing/rtla/src/osnoise.h @@ -1,6 +1,55 @@ // SPDX-License-Identifier: GPL-2.0 +#pragma once + +#include "utils.h" #include "trace.h" +enum osnoise_mode { + MODE_OSNOISE = 0, + MODE_HWNOISE +}; + +struct osnoise_params { + /* Common params */ + char *cpus; + cpu_set_t monitored_cpus; + char *trace_output; + char *cgroup_name; + unsigned long long runtime; + unsigned long long period; + long long threshold; + long long stop_us; + long long stop_total_us; + int sleep_time; + int duration; + int set_sched; + int cgroup; + int hk_cpus; + cpu_set_t hk_cpu_set; + struct sched_attr sched_param; + struct trace_events *events; + int warmup; + int buffer_size; + union { + struct { + /* top only */ + int quiet; + int pretty_output; + enum osnoise_mode mode; + }; + struct { + /* hist only */ + int output_divisor; + char no_header; + char no_summary; + char no_index; + char with_zeros; + int bucket_size; + int entries; + }; + }; +}; + /* * osnoise_context - read, store, write, restore osnoise configs. */ @@ -106,6 +155,7 @@ struct osnoise_tool *osnoise_init_tool(char *tool_name); struct osnoise_tool *osnoise_init_trace_tool(char *tracer); void osnoise_report_missed_events(struct osnoise_tool *tool); bool osnoise_trace_is_off(struct osnoise_tool *tool, struct osnoise_tool *record); +int osnoise_apply_config(struct osnoise_tool *tool, struct osnoise_params *params); int osnoise_hist_main(int argc, char *argv[]); int osnoise_top_main(int argc, char **argv); diff --git a/tools/tracing/rtla/src/osnoise_hist.c b/tools/tracing/rtla/src/osnoise_hist.c index b4930b835b0a..d9d15c8f27c7 100644 --- a/tools/tracing/rtla/src/osnoise_hist.c +++ b/tools/tracing/rtla/src/osnoise_hist.c @@ -12,40 +12,9 @@ #include <errno.h> #include <stdio.h> #include <time.h> -#include <sched.h> -#include "utils.h" #include "osnoise.h" -struct osnoise_hist_params { - char *cpus; - cpu_set_t monitored_cpus; - char *trace_output; - char *cgroup_name; - unsigned long long runtime; - unsigned long long period; - long long threshold; - long long stop_us; - long long stop_total_us; - int sleep_time; - int duration; - int set_sched; - int output_divisor; - int cgroup; - int hk_cpus; - cpu_set_t hk_cpu_set; - struct sched_attr sched_param; - struct trace_events *events; - char no_header; - char no_summary; - char no_index; - char with_zeros; - int bucket_size; - int entries; - int warmup; - int buffer_size; -}; - struct osnoise_hist_cpu { int *samples; int count; @@ -126,7 +95,7 @@ cleanup: static void osnoise_hist_update_multiple(struct osnoise_tool *tool, int cpu, unsigned long long duration, int count) { - struct osnoise_hist_params *params = tool->params; + struct osnoise_params *params = tool->params; struct osnoise_hist_data *data = tool->data; unsigned long long total_duration; int entries = data->entries; @@ -168,7 +137,7 @@ static void osnoise_destroy_trace_hist(struct osnoise_tool *tool) */ static int osnoise_init_trace_hist(struct osnoise_tool *tool) { - struct osnoise_hist_params *params = tool->params; + struct osnoise_params *params = tool->params; struct osnoise_hist_data *data = tool->data; int bucket_size; char buff[128]; @@ -253,7 +222,7 @@ static void osnoise_read_trace_hist(struct osnoise_tool *tool) */ static void osnoise_hist_header(struct osnoise_tool *tool) { - struct osnoise_hist_params *params = tool->params; + struct osnoise_params *params = tool->params; struct osnoise_hist_data *data = tool->data; struct trace_seq *s = tool->trace.seq; char duration[26]; @@ -292,7 +261,7 @@ static void osnoise_hist_header(struct osnoise_tool *tool) * osnoise_print_summary - print the summary of the hist data to the output */ static void -osnoise_print_summary(struct osnoise_hist_params *params, +osnoise_print_summary(struct osnoise_params *params, struct trace_instance *trace, struct osnoise_hist_data *data) { @@ -370,7 +339,7 @@ osnoise_print_summary(struct osnoise_hist_params *params, * osnoise_print_stats - print data for all CPUs */ static void -osnoise_print_stats(struct osnoise_hist_params *params, struct osnoise_tool *tool) +osnoise_print_stats(struct osnoise_params *params, struct osnoise_tool *tool) { struct osnoise_hist_data *data = tool->data; struct trace_instance *trace = &tool->trace; @@ -508,10 +477,10 @@ static void osnoise_hist_usage(char *usage) /* * osnoise_hist_parse_args - allocs, parse and fill the cmd line parameters */ -static struct osnoise_hist_params +static struct osnoise_params *osnoise_hist_parse_args(int argc, char *argv[]) { - struct osnoise_hist_params *params; + struct osnoise_params *params; struct trace_events *tevent; int retval; int c; @@ -731,72 +700,13 @@ static struct osnoise_hist_params * osnoise_hist_apply_config - apply the hist configs to the initialized tool */ static int -osnoise_hist_apply_config(struct osnoise_tool *tool, struct osnoise_hist_params *params) +osnoise_hist_apply_config(struct osnoise_tool *tool, struct osnoise_params *params) { int retval; - if (!params->sleep_time) - params->sleep_time = 1; - - if (params->cpus) { - retval = osnoise_set_cpus(tool->context, params->cpus); - if (retval) { - err_msg("Failed to apply CPUs config\n"); - goto out_err; - } - } - - if (params->runtime || params->period) { - retval = osnoise_set_runtime_period(tool->context, - params->runtime, - params->period); - if (retval) { - err_msg("Failed to set runtime and/or period\n"); - goto out_err; - } - } - - if (params->stop_us) { - retval = osnoise_set_stop_us(tool->context, params->stop_us); - if (retval) { - err_msg("Failed to set stop us\n"); - goto out_err; - } - } - - if (params->stop_total_us) { - retval = osnoise_set_stop_total_us(tool->context, params->stop_total_us); - if (retval) { - err_msg("Failed to set stop total us\n"); - goto out_err; - } - } - - if (params->threshold) { - retval = osnoise_set_tracing_thresh(tool->context, params->threshold); - if (retval) { - err_msg("Failed to set tracing_thresh\n"); - goto out_err; - } - } - - if (params->hk_cpus) { - retval = sched_setaffinity(getpid(), sizeof(params->hk_cpu_set), - ¶ms->hk_cpu_set); - if (retval == -1) { - err_msg("Failed to set rtla to the house keeping CPUs\n"); - goto out_err; - } - } else if (params->cpus) { - /* - * Even if the user do not set a house-keeping CPU, try to - * move rtla to a CPU set different to the one where the user - * set the workload to run. - * - * No need to check results as this is an automatic attempt. - */ - auto_house_keeping(¶ms->monitored_cpus); - } + retval = osnoise_apply_config(tool, params); + if (retval) + goto out_err; return 0; @@ -808,7 +718,7 @@ out_err: * osnoise_init_hist - initialize a osnoise hist tool with parameters */ static struct osnoise_tool -*osnoise_init_hist(struct osnoise_hist_params *params) +*osnoise_init_hist(struct osnoise_params *params) { struct osnoise_tool *tool; int nr_cpus; @@ -842,7 +752,7 @@ static void stop_hist(int sig) * osnoise_hist_set_signals - handles the signal to stop the tool */ static void -osnoise_hist_set_signals(struct osnoise_hist_params *params) +osnoise_hist_set_signals(struct osnoise_params *params) { signal(SIGINT, stop_hist); if (params->duration) { @@ -853,7 +763,7 @@ osnoise_hist_set_signals(struct osnoise_hist_params *params) int osnoise_hist_main(int argc, char *argv[]) { - struct osnoise_hist_params *params; + struct osnoise_params *params; struct osnoise_tool *record = NULL; struct osnoise_tool *tool = NULL; struct trace_instance *trace; @@ -983,10 +893,8 @@ int osnoise_hist_main(int argc, char *argv[]) if (osnoise_trace_is_off(tool, record)) { printf("rtla osnoise hit stop tracing\n"); - if (params->trace_output) { - printf(" Saving trace to %s\n", params->trace_output); - save_trace_to_file(record->trace.inst, params->trace_output); - } + save_trace_to_file(record ? record->trace.inst : NULL, + params->trace_output); } out_hist: diff --git a/tools/tracing/rtla/src/osnoise_top.c b/tools/tracing/rtla/src/osnoise_top.c index 4772677ac762..3455ee73e2e6 100644 --- a/tools/tracing/rtla/src/osnoise_top.c +++ b/tools/tracing/rtla/src/osnoise_top.c @@ -11,43 +11,8 @@ #include <unistd.h> #include <stdio.h> #include <time.h> -#include <sched.h> #include "osnoise.h" -#include "utils.h" - -enum osnoise_mode { - MODE_OSNOISE = 0, - MODE_HWNOISE -}; - -/* - * osnoise top parameters - */ -struct osnoise_top_params { - char *cpus; - cpu_set_t monitored_cpus; - char *trace_output; - char *cgroup_name; - unsigned long long runtime; - unsigned long long period; - long long threshold; - long long stop_us; - long long stop_total_us; - int sleep_time; - int duration; - int quiet; - int set_sched; - int cgroup; - int hk_cpus; - int warmup; - int buffer_size; - int pretty_output; - cpu_set_t hk_cpu_set; - struct sched_attr sched_param; - struct trace_events *events; - enum osnoise_mode mode; -}; struct osnoise_top_cpu { unsigned long long sum_runtime; @@ -158,7 +123,7 @@ osnoise_top_handler(struct trace_seq *s, struct tep_record *record, */ static void osnoise_top_header(struct osnoise_tool *top) { - struct osnoise_top_params *params = top->params; + struct osnoise_params *params = top->params; struct trace_seq *s = top->trace.seq; char duration[26]; @@ -218,7 +183,7 @@ static void clear_terminal(struct trace_seq *seq) */ static void osnoise_top_print(struct osnoise_tool *tool, int cpu) { - struct osnoise_top_params *params = tool->params; + struct osnoise_params *params = tool->params; struct trace_seq *s = tool->trace.seq; struct osnoise_top_cpu *cpu_data; struct osnoise_top_data *data; @@ -258,7 +223,7 @@ static void osnoise_top_print(struct osnoise_tool *tool, int cpu) * osnoise_print_stats - print data for all cpus */ static void -osnoise_print_stats(struct osnoise_top_params *params, struct osnoise_tool *top) +osnoise_print_stats(struct osnoise_params *params, struct osnoise_tool *top) { struct trace_instance *trace = &top->trace; static int nr_cpus = -1; @@ -286,7 +251,7 @@ osnoise_print_stats(struct osnoise_top_params *params, struct osnoise_tool *top) /* * osnoise_top_usage - prints osnoise top usage message */ -static void osnoise_top_usage(struct osnoise_top_params *params, char *usage) +static void osnoise_top_usage(struct osnoise_params *params, char *usage) { int i; @@ -354,9 +319,9 @@ static void osnoise_top_usage(struct osnoise_top_params *params, char *usage) /* * osnoise_top_parse_args - allocs, parse and fill the cmd line parameters */ -struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv) +struct osnoise_params *osnoise_top_parse_args(int argc, char **argv) { - struct osnoise_top_params *params; + struct osnoise_params *params; struct trace_events *tevent; int retval; int c; @@ -553,54 +518,13 @@ struct osnoise_top_params *osnoise_top_parse_args(int argc, char **argv) * osnoise_top_apply_config - apply the top configs to the initialized tool */ static int -osnoise_top_apply_config(struct osnoise_tool *tool, struct osnoise_top_params *params) +osnoise_top_apply_config(struct osnoise_tool *tool, struct osnoise_params *params) { int retval; - if (!params->sleep_time) - params->sleep_time = 1; - - if (params->cpus) { - retval = osnoise_set_cpus(tool->context, params->cpus); - if (retval) { - err_msg("Failed to apply CPUs config\n"); - goto out_err; - } - } - - if (params->runtime || params->period) { - retval = osnoise_set_runtime_period(tool->context, - params->runtime, - params->period); - if (retval) { - err_msg("Failed to set runtime and/or period\n"); - goto out_err; - } - } - - if (params->stop_us) { - retval = osnoise_set_stop_us(tool->context, params->stop_us); - if (retval) { - err_msg("Failed to set stop us\n"); - goto out_err; - } - } - - if (params->stop_total_us) { - retval = osnoise_set_stop_total_us(tool->context, params->stop_total_us); - if (retval) { - err_msg("Failed to set stop total us\n"); - goto out_err; - } - } - - if (params->threshold) { - retval = osnoise_set_tracing_thresh(tool->context, params->threshold); - if (retval) { - err_msg("Failed to set tracing_thresh\n"); - goto out_err; - } - } + retval = osnoise_apply_config(tool, params); + if (retval) + goto out_err; if (params->mode == MODE_HWNOISE) { retval = osnoise_set_irq_disable(tool->context, 1); @@ -610,24 +534,6 @@ osnoise_top_apply_config(struct osnoise_tool *tool, struct osnoise_top_params *p } } - if (params->hk_cpus) { - retval = sched_setaffinity(getpid(), sizeof(params->hk_cpu_set), - ¶ms->hk_cpu_set); - if (retval == -1) { - err_msg("Failed to set rtla to the house keeping CPUs\n"); - goto out_err; - } - } else if (params->cpus) { - /* - * Even if the user do not set a house-keeping CPU, try to - * move rtla to a CPU set different to the one where the user - * set the workload to run. - * - * No need to check results as this is an automatic attempt. - */ - auto_house_keeping(¶ms->monitored_cpus); - } - if (isatty(STDOUT_FILENO) && !params->quiet) params->pretty_output = 1; @@ -640,7 +546,7 @@ out_err: /* * osnoise_init_top - initialize a osnoise top tool with parameters */ -struct osnoise_tool *osnoise_init_top(struct osnoise_top_params *params) +struct osnoise_tool *osnoise_init_top(struct osnoise_params *params) { struct osnoise_tool *tool; int nr_cpus; @@ -674,7 +580,7 @@ static void stop_top(int |