Skip to content

Commit 4fa118e

Browse files
committed
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
2 parents 744fab2 + 7320326 commit 4fa118e

25 files changed

+1315
-625
lines changed

tools/build/Makefile.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ FEATURE_TESTS_EXTRA := \
135135
libbpf-bpf_create_map \
136136
libpfm4 \
137137
libdebuginfod \
138-
clang-bpf-co-re
138+
clang-bpf-co-re \
139+
bpftool-skeletons
139140

140141

141142
FEATURE_TESTS ?= $(FEATURE_TESTS_BASIC)

tools/build/feature/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,9 @@ $(OUTPUT)test-file-handle.bin:
418418
$(OUTPUT)test-libpfm4.bin:
419419
$(BUILD) -lpfm
420420

421+
$(OUTPUT)test-bpftool-skeletons.bin:
422+
$(SYSTEM_BPFTOOL) version | grep '^features:.*skeletons' \
423+
> $(@:.bin=.make.output) 2>&1
421424
###############################
422425

423426
clean:

tools/scripts/Makefile.include

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ LLVM_CONFIG ?= llvm-config
9191
LLVM_OBJCOPY ?= llvm-objcopy
9292
LLVM_STRIP ?= llvm-strip
9393

94+
# Some tools require bpftool
95+
SYSTEM_BPFTOOL ?= bpftool
96+
9497
ifeq ($(CC_NO_CLANG), 1)
9598
EXTRA_WARNINGS += -Wstrict-aliasing=3
9699

tools/tracing/rtla/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ rtla-static
44
fixdep
55
feature
66
FEATURE-DUMP
7+
*.skel.h

tools/tracing/rtla/Makefile

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,15 @@ DOCSRC := ../../../Documentation/tools/rtla/
3333
FEATURE_TESTS := libtraceevent
3434
FEATURE_TESTS += libtracefs
3535
FEATURE_TESTS += libcpupower
36+
FEATURE_TESTS += libbpf
37+
FEATURE_TESTS += clang-bpf-co-re
38+
FEATURE_TESTS += bpftool-skeletons
3639
FEATURE_DISPLAY := libtraceevent
3740
FEATURE_DISPLAY += libtracefs
3841
FEATURE_DISPLAY += libcpupower
42+
FEATURE_DISPLAY += libbpf
43+
FEATURE_DISPLAY += clang-bpf-co-re
44+
FEATURE_DISPLAY += bpftool-skeletons
3945

4046
all: $(RTLA)
4147

@@ -61,6 +67,17 @@ CFLAGS += $(INCLUDES) $(LIB_INCLUDES)
6167

6268
export CFLAGS OUTPUT srctree
6369

70+
ifeq ($(BUILD_BPF_SKEL),1)
71+
src/timerlat.bpf.o: src/timerlat.bpf.c
72+
$(QUIET_CLANG)$(CLANG) -g -O2 -target bpf -c $(filter %.c,$^) -o $@
73+
74+
src/timerlat.skel.h: src/timerlat.bpf.o
75+
$(QUIET_GENSKEL)$(SYSTEM_BPFTOOL) gen skeleton $< > $@
76+
else
77+
src/timerlat.skel.h:
78+
$(Q)echo '/* BPF skeleton is disabled */' > src/timerlat.skel.h
79+
endif
80+
6481
$(RTLA): $(RTLA_IN)
6582
$(QUIET_LINK)$(CC) $(LDFLAGS) -o $(RTLA) $(RTLA_IN) $(EXTLIBS)
6683

@@ -71,14 +88,15 @@ static: $(RTLA_IN)
7188
rtla.%: fixdep FORCE
7289
make -f $(srctree)/tools/build/Makefile.build dir=. $@
7390

74-
$(RTLA_IN): fixdep FORCE
91+
$(RTLA_IN): fixdep FORCE src/timerlat.skel.h
7592
make $(build)=rtla
7693

7794
clean: doc_clean fixdep-clean
7895
$(call QUIET_CLEAN, rtla)
7996
$(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
8097
$(Q)rm -f rtla rtla-static fixdep FEATURE-DUMP rtla-*
8198
$(Q)rm -rf feature
99+
$(Q)rm -f src/timerlat.bpf.o src/timerlat.skel.h
82100
check: $(RTLA)
83101
RTLA=$(RTLA) prove -o -f tests/
84102
.PHONY: FORCE clean check

tools/tracing/rtla/Makefile.config

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,48 @@ else
5353
$(info Please install libcpupower-dev/kernel-tools-libs-devel)
5454
endif
5555

56+
ifndef BUILD_BPF_SKEL
57+
# BPF skeletons are used to implement improved sample collection, enable
58+
# them by default.
59+
BUILD_BPF_SKEL := 1
60+
endif
61+
62+
ifeq ($(BUILD_BPF_SKEL),0)
63+
$(info BPF skeleton support disabled, building without BPF skeleton support.)
64+
endif
65+
66+
$(call feature_check,libbpf)
67+
ifeq ($(feature-libbpf), 1)
68+
$(call detected,CONFIG_LIBBPF)
69+
else
70+
$(info libbpf is missing, building without BPF skeleton support.)
71+
$(info Please install libbpf-dev/libbpf-devel)
72+
BUILD_BPF_SKEL := 0
73+
endif
74+
75+
$(call feature_check,clang-bpf-co-re)
76+
ifeq ($(feature-clang-bpf-co-re), 1)
77+
$(call detected,CONFIG_CLANG_BPF_CO_RE)
78+
else
79+
$(info clang is missing or does not support BPF CO-RE, building without BPF skeleton support.)
80+
$(info Please install clang)
81+
BUILD_BPF_SKEL := 0
82+
endif
83+
84+
$(call feature_check,bpftool-skeletons)
85+
ifeq ($(feature-bpftool-skeletons), 1)
86+
$(call detected,CONFIG_BPFTOOL_SKELETONS)
87+
else
88+
$(info bpftool is missing or not supporting skeletons, building without BPF skeleton support.)
89+
$(info Please install bpftool)
90+
BUILD_BPF_SKEL := 0
91+
endif
92+
93+
ifeq ($(BUILD_BPF_SKEL),1)
94+
CFLAGS += -DHAVE_BPF_SKEL
95+
EXTLIBS += -lbpf
96+
endif
97+
5698
ifeq ($(STOP_ERROR),1)
5799
$(error Please, check the errors above.)
58100
endif

tools/tracing/rtla/Makefile.rtla

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ INSTALL := install
3434
MKDIR := mkdir
3535
STRIP := strip
3636
BINDIR := /usr/bin
37+
CTAGS := ctags
38+
ETAGS := ctags -e
3739

3840
.PHONY: install
3941
install: doc_install
@@ -47,6 +49,18 @@ install: doc_install
4749
@test ! -f $(DESTDIR)$(BINDIR)/timerlat || $(RM) $(DESTDIR)$(BINDIR)/timerlat
4850
@$(LN) -s rtla $(DESTDIR)$(BINDIR)/timerlat
4951

52+
.PHONY: tags
53+
tags:
54+
$(CTAGS) -R --extras=+f --c-kinds=+p src
55+
56+
.PHONY: TAGS
57+
TAGS:
58+
$(ETAGS) -R --extras=+f --c-kinds=+p src
59+
60+
.PHONY: tags_clean
61+
tags_clean:
62+
$(RM) tags TAGS
63+
5064
.PHONY: doc doc_clean doc_install
5165
doc:
5266
$(MAKE) -C $(DOCSRC)
@@ -57,8 +71,7 @@ doc_clean:
5771
doc_install:
5872
$(MAKE) -C $(DOCSRC) install
5973

60-
# This section is neesary for the tarball, when the tarball
61-
# support is removed, we can delete these entries.
74+
# This section is necessary to make the rtla tarball
6275
NAME := rtla
6376
DIRS := src
6477
FILES := Makefile README.txt

tools/tracing/rtla/src/Build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ rtla-y += timerlat_top.o
88
rtla-y += timerlat_hist.o
99
rtla-y += timerlat_u.o
1010
rtla-y += timerlat_aa.o
11+
rtla-y += timerlat_bpf.o
1112
rtla-y += rtla.o

tools/tracing/rtla/src/osnoise.c

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (C) 2021 Red Hat Inc, Daniel Bristot de Oliveira <bristot@kernel.org>
44
*/
55

6+
#define _GNU_SOURCE
67
#include <sys/types.h>
78
#include <sys/stat.h>
89
#include <pthread.h>
@@ -12,9 +13,12 @@
1213
#include <errno.h>
1314
#include <fcntl.h>
1415
#include <stdio.h>
16+
#include <sched.h>
1517

1618
#include "osnoise.h"
17-
#include "utils.h"
19+
20+
#define DEFAULT_SAMPLE_PERIOD 1000000 /* 1s */
21+
#define DEFAULT_SAMPLE_RUNTIME 1000000 /* 1s */
1822

1923
/*
2024
* osnoise_get_cpus - return the original "osnoise/cpus" content
@@ -1115,6 +1119,86 @@ osnoise_report_missed_events(struct osnoise_tool *tool)
11151119
}
11161120
}
11171121

1122+
/*
1123+
* osnoise_apply_config - apply common configs to the initialized tool
1124+
*/
1125+
int
1126+
osnoise_apply_config(struct osnoise_tool *tool, struct osnoise_params *params)
1127+
{
1128+
int retval;
1129+
1130+
if (!params->sleep_time)
1131+
params->sleep_time = 1;
1132+
1133+
retval = osnoise_set_cpus(tool->context, params->cpus ? params->cpus : "all");
1134+
if (retval) {
1135+
err_msg("Failed to apply CPUs config\n");
1136+
goto out_err;
1137+
}
1138+
1139+
if (params->runtime || params->period) {
1140+
retval = osnoise_set_runtime_period(tool->context,
1141+
params->runtime,
1142+
params->period);
1143+
} else {
1144+
retval = osnoise_set_runtime_period(tool->context,
1145+
DEFAULT_SAMPLE_PERIOD,
1146+
DEFAULT_SAMPLE_RUNTIME);
1147+
}
1148+
1149+
if (retval) {
1150+
err_msg("Failed to set runtime and/or period\n");
1151+
goto out_err;
1152+
}
1153+
1154+
retval = osnoise_set_stop_us(tool->context, params->stop_us);
1155+
if (retval) {
1156+
err_msg("Failed to set stop us\n");
1157+
goto out_err;
1158+
}
1159+
1160+
retval = osnoise_set_stop_total_us(tool->context, params->stop_total_us);
1161+
if (retval) {
1162+
err_msg("Failed to set stop total us\n");
1163+
goto out_err;
1164+
}
1165+
1166+
retval = osnoise_set_tracing_thresh(tool->context, params->threshold);
1167+
if (retval) {
1168+
err_msg("Failed to set tracing_thresh\n");
1169+
goto out_err;
1170+
}
1171+
1172+
if (params->hk_cpus) {
1173+
retval = sched_setaffinity(getpid(), sizeof(params->hk_cpu_set),
1174+
&params->hk_cpu_set);
1175+
if (retval == -1) {
1176+
err_msg("Failed to set rtla to the house keeping CPUs\n");
1177+
goto out_err;
1178+
}
1179+
} else if (params->cpus) {
1180+
/*
1181+
* Even if the user do not set a house-keeping CPU, try to
1182+
* move rtla to a CPU set different to the one where the user
1183+
* set the workload to run.
1184+
*
1185+
* No need to check results as this is an automatic attempt.
1186+
*/
1187+
auto_house_keeping(&params->monitored_cpus);
1188+
}
1189+
1190+
retval = osnoise_set_workload(tool->context, true);
1191+
if (retval < -1) {
1192+
err_msg("Failed to set OSNOISE_WORKLOAD option\n");
1193+
goto out_err;
1194+
}
1195+
1196+
return 0;
1197+
1198+
out_err:
1199+
return -1;
1200+
}
1201+
11181202
static void osnoise_usage(int err)
11191203
{
11201204
int i;

tools/tracing/rtla/src/osnoise.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,55 @@
11
// SPDX-License-Identifier: GPL-2.0
2+
#pragma once
3+
4+
#include "utils.h"
25
#include "trace.h"
36

7+
enum osnoise_mode {
8+
MODE_OSNOISE = 0,
9+
MODE_HWNOISE
10+
};
11+
12+
struct osnoise_params {
13+
/* Common params */
14+
char *cpus;
15+
cpu_set_t monitored_cpus;
16+
char *trace_output;
17+
char *cgroup_name;
18+
unsigned long long runtime;
19+
unsigned long long period;
20+
long long threshold;
21+
long long stop_us;
22+
long long stop_total_us;
23+
int sleep_time;
24+
int duration;
25+
int set_sched;
26+
int cgroup;
27+
int hk_cpus;
28+
cpu_set_t hk_cpu_set;
29+
struct sched_attr sched_param;
30+
struct trace_events *events;
31+
int warmup;
32+
int buffer_size;
33+
union {
34+
struct {
35+
/* top only */
36+
int quiet;
37+
int pretty_output;
38+
enum osnoise_mode mode;
39+
};
40+
struct {
41+
/* hist only */
42+
int output_divisor;
43+
char no_header;
44+
char no_summary;
45+
char no_index;
46+
char with_zeros;
47+
int bucket_size;
48+
int entries;
49+
};
50+
};
51+
};
52+
453
/*
554
* osnoise_context - read, store, write, restore osnoise configs.
655
*/
@@ -106,6 +155,7 @@ struct osnoise_tool *osnoise_init_tool(char *tool_name);
106155
struct osnoise_tool *osnoise_init_trace_tool(char *tracer);
107156
void osnoise_report_missed_events(struct osnoise_tool *tool);
108157
bool osnoise_trace_is_off(struct osnoise_tool *tool, struct osnoise_tool *record);
158+
int osnoise_apply_config(struct osnoise_tool *tool, struct osnoise_params *params);
109159

110160
int osnoise_hist_main(int argc, char *argv[]);
111161
int osnoise_top_main(int argc, char **argv);

0 commit comments

Comments
 (0)