Skip to content

Commit 48209d7

Browse files
rtla: Add libsubcmd dependency
In preparation for migrating RTLA to libsubcmd, build libsubcmd from the appropriate directory next to the RTLA build proper, and link the resulting object to RTLA. libsubcmd uses str_error_r() and strlcpy() at several places. To support these, also link the respective libraries from tools/lib. For completeness, also add tools/include to include path. This will allow other userspace functions and macros shipped with the kernel to be used in RTLA; perf and bpftool, two other users of libsubcmd, already do that. To prevent a name conflict, rename RTLA's run_command() function to run_tool_command(), and replace RTLA's own container_of implementation with the one in tools/include/linux/container_of.h. Assisted-by: Composer:composer-1 Link: https://lore.kernel.org/r/20260528103254.2990068-2-tglozar@redhat.com Signed-off-by: Tomas Glozar <tglozar@redhat.com>
1 parent 6a1700b commit 48209d7

4 files changed

Lines changed: 67 additions & 15 deletions

File tree

tools/tracing/rtla/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ custom_filename.txt
1010
osnoise_irq_noise_hist.txt
1111
osnoise_trace.txt
1212
timerlat_trace.txt
13+
libsubcmd/
14+
lib/

tools/tracing/rtla/Makefile

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@ endif
2727
RTLA := $(OUTPUT)rtla
2828
RTLA_IN := $(RTLA)-in.o
2929

30+
LIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/
31+
ifneq ($(OUTPUT),)
32+
LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd
33+
else
34+
LIBSUBCMD_OUTPUT = $(CURDIR)/libsubcmd
35+
endif
36+
LIBSUBCMD = $(LIBSUBCMD_OUTPUT)/libsubcmd.a
37+
LIBSUBCMD_INCLUDES = $(LIBSUBCMD_OUTPUT)/include
38+
LIBSUBCMD_MAKEFLAGS = O=$(LIBSUBCMD_OUTPUT) DESTDIR=$(LIBSUBCMD_OUTPUT) prefix= subdir=
39+
40+
TOOLS_INCLUDES = -I$(srctree)/tools/include
41+
42+
ifneq ($(OUTPUT),)
43+
LIB_OUTPUT = $(abspath $(OUTPUT))/lib
44+
else
45+
LIB_OUTPUT = $(CURDIR)/lib
46+
endif
47+
48+
LIB_STRING = $(LIB_OUTPUT)/string.o
49+
LIB_STRING_SRC = $(srctree)/tools/lib/string.c
50+
51+
LIB_STR_ERROR_R = $(LIB_OUTPUT)/str_error_r.o
52+
LIB_STR_ERROR_R_SRC = $(srctree)/tools/lib/str_error_r.c
53+
3054
VERSION := $(shell sh -c "make -sC ../../.. kernelversion | grep -v make")
3155
DOCSRC := ../../../Documentation/tools/rtla/
3256

@@ -66,7 +90,7 @@ ifeq ($(config),1)
6690
include Makefile.config
6791
endif
6892

69-
CFLAGS += $(INCLUDES) $(LIB_INCLUDES)
93+
CFLAGS += $(INCLUDES) $(LIB_INCLUDES) $(TOOLS_INCLUDES) -I$(LIBSUBCMD_INCLUDES)
7094

7195
export CFLAGS OUTPUT srctree
7296

@@ -93,20 +117,48 @@ tests/bpf/bpf_action_map.o: tests/bpf/bpf_action_map.c
93117
$(Q)echo "BPF skeleton support is disabled, skipping tests/bpf/bpf_action_map.o"
94118
endif
95119

96-
$(RTLA): $(RTLA_IN)
97-
$(QUIET_LINK)$(CC) $(LDFLAGS) -o $(RTLA) $(RTLA_IN) $(EXTLIBS)
120+
$(RTLA): $(RTLA_IN) $(LIBSUBCMD) $(LIB_STRING) $(LIB_STR_ERROR_R)
121+
$(QUIET_LINK)$(CC) $(LDFLAGS) -o $(RTLA) $(RTLA_IN) $(LIBSUBCMD) $(LIB_STRING) $(LIB_STR_ERROR_R) $(EXTLIBS)
98122

99-
static: $(RTLA_IN)
123+
static: $(RTLA_IN) $(LIBSUBCMD) $(LIB_STRING) $(LIB_STR_ERROR_R)
100124
$(eval LDFLAGS += -static)
101-
$(QUIET_LINK)$(CC) -static $(LDFLAGS) -o $(RTLA)-static $(RTLA_IN) $(EXTLIBS)
125+
$(QUIET_LINK)$(CC) -static $(LDFLAGS) -o $(RTLA)-static $(RTLA_IN) $(LIBSUBCMD) $(LIB_STRING) $(LIB_STR_ERROR_R) $(EXTLIBS)
102126

103127
rtla.%: fixdep FORCE
104128
make -f $(srctree)/tools/build/Makefile.build dir=. $@
105129

106-
$(RTLA_IN): fixdep FORCE src/timerlat.skel.h
130+
$(RTLA_IN): fixdep FORCE src/timerlat.skel.h $(LIBSUBCMD_INCLUDES)
107131
make $(build)=rtla
108132

109-
clean: doc_clean fixdep-clean
133+
$(LIBSUBCMD_OUTPUT):
134+
$(Q)$(MKDIR) -p $@
135+
136+
$(LIBSUBCMD_INCLUDES): FORCE | $(LIBSUBCMD_OUTPUT)
137+
$(Q)$(MAKE) -C $(LIBSUBCMD_DIR) $(LIBSUBCMD_MAKEFLAGS) \
138+
install_headers
139+
140+
$(LIBSUBCMD): FORCE | $(LIBSUBCMD_OUTPUT)
141+
$(Q)$(MAKE) -C $(LIBSUBCMD_DIR) $(LIBSUBCMD_MAKEFLAGS) \
142+
$@
143+
144+
$(LIB_OUTPUT):
145+
$(Q)$(MKDIR) -p $@
146+
147+
$(LIB_STR_ERROR_R): $(LIB_STR_ERROR_R_SRC) | $(LIB_OUTPUT)
148+
$(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
149+
150+
$(LIB_STRING): $(LIB_STRING_SRC) | $(LIB_OUTPUT)
151+
$(QUIET_CC)$(CC) $(CFLAGS) -c -o $@ $<
152+
153+
libsubcmd-clean:
154+
$(call QUIET_CLEAN, libsubcmd)
155+
$(Q)$(RM) -r -- $(LIBSUBCMD_OUTPUT)
156+
157+
lib-clean:
158+
$(call QUIET_CLEAN, lib)
159+
$(Q)$(RM) -r -- $(LIB_OUTPUT)
160+
161+
clean: doc_clean fixdep-clean libsubcmd-clean lib-clean
110162
$(call QUIET_CLEAN, rtla)
111163
$(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
112164
$(Q)rm -f rtla rtla-static fixdep FEATURE-DUMP rtla-*

tools/tracing/rtla/src/rtla.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ static void rtla_usage(int err)
3838
}
3939

4040
/*
41-
* run_command - try to run a rtla tool command
41+
* run_tool_command - try to run a rtla tool command
4242
*
4343
* It returns 0 if it fails. The tool's main will generally not
4444
* return as they should call exit().
4545
*/
46-
int run_command(int argc, char **argv, int start_position)
46+
int run_tool_command(int argc, char **argv, int start_position)
4747
{
4848
if (strcmp(argv[start_position], "osnoise") == 0) {
4949
osnoise_main(argc-start_position, &argv[start_position]);
@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
6969
int retval;
7070

7171
/* is it an alias? */
72-
retval = run_command(argc, argv, 0);
72+
retval = run_tool_command(argc, argv, 0);
7373
if (retval)
7474
exit(0);
7575

@@ -82,7 +82,7 @@ int main(int argc, char *argv[])
8282
rtla_usage(0);
8383
}
8484

85-
retval = run_command(argc, argv, 1);
85+
retval = run_tool_command(argc, argv, 1);
8686
if (retval)
8787
exit(0);
8888

tools/tracing/rtla/src/utils.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <stdbool.h>
88
#include <stdlib.h>
99

10+
#include <linux/container_of.h>
11+
1012
/*
1113
* '18446744073709551615\0'
1214
*/
@@ -37,10 +39,6 @@ static inline bool str_has_prefix(const char *str, const char *prefix)
3739
return strncmp(str, prefix, strlen(prefix)) == 0;
3840
}
3941

40-
#define container_of(ptr, type, member)({ \
41-
const typeof(((type *)0)->member) *__mptr = (ptr); \
42-
(type *)((char *)__mptr - offsetof(type, member)) ; })
43-
4442
extern int config_debug;
4543
void debug_msg(const char *fmt, ...);
4644
void err_msg(const char *fmt, ...);

0 commit comments

Comments
 (0)