Message ID | 20241107152049.822810-1-tglozar@redhat.com |
---|---|
State | Superseded |
Headers | show |
Series | [1/2] rt-tests: Detect libcpupower presence | expand |
On Thu, 7 Nov 2024, tglozar@redhat.com wrote: > From: Tomas Glozar <tglozar@redhat.com> > > Add test to detect the presence of libcpupower on the system, allowing > to conditionally build features that depend on it. > > The test uses a similar mechanism to the Linux kernel's tools' feature > detection: a small C program using the library is compiled, and based on > the success of the compilation, the presence of the library is > determined. > > Signed-off-by: Tomas Glozar <tglozar@redhat.com> This seems overly complicated, how about just doing ldconfig -p | grep -q libcpupower if it returns 0, the lib is there, if it returns 1, it's not there. This is the mechanism that perf uses, you can see in tools/perf/Makefile.config ifneq ($(shell ldconfig -p | grep libasan >/dev/null 2>&1; echo $$?), 0) $(error No libasan found, please install libasan) endif > --- > Makefile | 11 +++++++++++ > feature/Makefile | 12 ++++++++++++ > feature/test-feature.mak | 4 ++++ > feature/test-libcpupower.c | 8 ++++++++ > 4 files changed, 35 insertions(+) > create mode 100644 feature/Makefile > create mode 100644 feature/test-feature.mak > create mode 100644 feature/test-libcpupower.c > > diff --git a/Makefile b/Makefile > index e2f8579..1f698cf 100644 > --- a/Makefile > +++ b/Makefile > @@ -1,4 +1,6 @@ > # SPDX-License-Identifier: GPL-2.0-or-later > +include feature/test-feature.mak > + > VERSION = 2.7 > CC = $(CROSS_COMPILE)gcc > AR = $(CROSS_COMPILE)ar > @@ -37,6 +39,15 @@ LDFLAGS ?= > > PYLIB ?= $(shell python3 -m get_pylib) > > +# Check for optional libcpupower dependency > +ifeq ($(call test-feature,libcpupower), 0) > +CPPFLAGS += -DHAVE_LIBCPUPOWER_SUPPORT > +LDFLAGS += -lcpupower > +else > +$(warning libcpupower is missing, building without --deepest-idle-state support.) > +$(warning Please install libcpupower-dev/kernel-tools-libs-devel) > +endif > + > # Check for errors, such as python3 not available > ifeq (${PYLIB},) > undefine PYLIB > diff --git a/feature/Makefile b/feature/Makefile > new file mode 100644 > index 0000000..085e3a9 > --- /dev/null > +++ b/feature/Makefile > @@ -0,0 +1,12 @@ > +# SPDX-License-Identifier: GPL-2.0-or-later > +all: feature-libcpupower > + > +feature-libcpupower: $(OBJDIR)/test-libcpupower.o > + > +$(OBJDIR)/test-libcpupower.o: feature/test-libcpupower.c > + @$(CC) $(CFLAGS) $(CPPFLAGS) $< -lcpupower -o $@ > + > +.PHONY: clean > + > +clean: > + rm -f $(OBJDIR)/test-*.o > diff --git a/feature/test-feature.mak b/feature/test-feature.mak > new file mode 100644 > index 0000000..fffddef > --- /dev/null > +++ b/feature/test-feature.mak > @@ -0,0 +1,4 @@ > +# SPDX-License-Identifier: GPL-2.0-or-later > +define test-feature > +$(shell $(MAKE) OBJDIR=$(OBJDIR) -f feature/Makefile feature-$1 clean >/dev/null 2>/dev/null; echo $$?) > +endef > diff --git a/feature/test-libcpupower.c b/feature/test-libcpupower.c > new file mode 100644 > index 0000000..cd16269 > --- /dev/null > +++ b/feature/test-libcpupower.c > @@ -0,0 +1,8 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +#include <cpuidle.h> > + > +int main(void) > +{ > + int rv = cpuidle_state_count(0); > + return rv; > +} > -- > 2.47.0 > > >
út 12. 11. 2024 v 15:49 odesílatel John Kacur <jkacur@redhat.com> napsal: > > This seems overly complicated, how about just doing > > ldconfig -p | grep -q libcpupower > > if it returns 0, the lib is there, if it returns 1, it's not there. > > This is the mechanism that perf uses, you can see in > tools/perf/Makefile.config > > ifneq ($(shell ldconfig -p | grep libasan >/dev/null 2>&1; echo $$?), 0) > $(error No libasan found, please install libasan) > endif > Is that really enough? We also need to check for the presence of the header, taking CPPFLAGS into account, and also account for any addition LDFLAGS. I think this is the simplest solution to ensure that libcpupower is present for both header and library and working with the current configuration of the compiler. Tomas
On Tue, 12 Nov 2024, Tomas Glozar wrote: > út 12. 11. 2024 v 15:49 odesílatel John Kacur <jkacur@redhat.com> napsal: > > > > This seems overly complicated, how about just doing > > > > ldconfig -p | grep -q libcpupower > > > > if it returns 0, the lib is there, if it returns 1, it's not there. > > > > This is the mechanism that perf uses, you can see in > > tools/perf/Makefile.config > > > > ifneq ($(shell ldconfig -p | grep libasan >/dev/null 2>&1; echo $$?), 0) > > $(error No libasan found, please install libasan) > > endif > > > > Is that really enough? We also need to check for the presence of the > header, taking CPPFLAGS into account, and also account for any > addition LDFLAGS. I think this is the simplest solution to ensure that > libcpupower is present for both header and library and working with > the current configuration of the compiler. > > Tomas Ah right, thanks for pointing that out. John
diff --git a/Makefile b/Makefile index e2f8579..1f698cf 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-or-later +include feature/test-feature.mak + VERSION = 2.7 CC = $(CROSS_COMPILE)gcc AR = $(CROSS_COMPILE)ar @@ -37,6 +39,15 @@ LDFLAGS ?= PYLIB ?= $(shell python3 -m get_pylib) +# Check for optional libcpupower dependency +ifeq ($(call test-feature,libcpupower), 0) +CPPFLAGS += -DHAVE_LIBCPUPOWER_SUPPORT +LDFLAGS += -lcpupower +else +$(warning libcpupower is missing, building without --deepest-idle-state support.) +$(warning Please install libcpupower-dev/kernel-tools-libs-devel) +endif + # Check for errors, such as python3 not available ifeq (${PYLIB},) undefine PYLIB diff --git a/feature/Makefile b/feature/Makefile new file mode 100644 index 0000000..085e3a9 --- /dev/null +++ b/feature/Makefile @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +all: feature-libcpupower + +feature-libcpupower: $(OBJDIR)/test-libcpupower.o + +$(OBJDIR)/test-libcpupower.o: feature/test-libcpupower.c + @$(CC) $(CFLAGS) $(CPPFLAGS) $< -lcpupower -o $@ + +.PHONY: clean + +clean: + rm -f $(OBJDIR)/test-*.o diff --git a/feature/test-feature.mak b/feature/test-feature.mak new file mode 100644 index 0000000..fffddef --- /dev/null +++ b/feature/test-feature.mak @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +define test-feature +$(shell $(MAKE) OBJDIR=$(OBJDIR) -f feature/Makefile feature-$1 clean >/dev/null 2>/dev/null; echo $$?) +endef diff --git a/feature/test-libcpupower.c b/feature/test-libcpupower.c new file mode 100644 index 0000000..cd16269 --- /dev/null +++ b/feature/test-libcpupower.c @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include <cpuidle.h> + +int main(void) +{ + int rv = cpuidle_state_count(0); + return rv; +}