Re: [PATCH 1/2] rt-tests: Detect libcpupower presence

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Thu, 7 Nov 2024, tglozar@xxxxxxxxxx wrote:

> From: Tomas Glozar <tglozar@xxxxxxxxxx>
> 
> 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@xxxxxxxxxx>


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
> 
> 
> 





[Index of Archives]     [RT Stable]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux