public inbox for linux-rt-users@vger.kernel.org
 help / color / mirror / Atom feed
From: tglozar@redhat.com
To: linux-rt-users@vger.kernel.org
Cc: jkacur@redhat.com, williams@redhat.com,
	Tomas Glozar <tglozar@redhat.com>
Subject: [PATCH v2 1/3] rt-tests: Detect libcpupower presence
Date: Wed, 13 Nov 2024 12:45:07 +0100	[thread overview]
Message-ID: <20241113114509.1058593-2-tglozar@redhat.com> (raw)
In-Reply-To: <20241113114509.1058593-1-tglozar@redhat.com>

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.

no_libcpupower=1 may be passed to make to disable libcpupower dependency
even on systems where the library is present.

Signed-off-by: Tomas Glozar <tglozar@redhat.com>
---
 Makefile                   | 15 +++++++++++++++
 feature/Makefile           | 12 ++++++++++++
 feature/test-feature.mak   |  5 +++++
 feature/test-libcpupower.c |  8 ++++++++
 4 files changed, 40 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..60d2f69 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,19 @@ LDFLAGS ?=
 
 PYLIB ?= $(shell python3 -m get_pylib)
 
+# Check for optional libcpupower dependency
+ifneq ($(no_libcpupower), 1)
+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
+else
+$(warning libcpupower disabled, building without --deepest-idle-state support.)
+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..de08121
--- /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) $(LDFLAGS) $< -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..0b3e51c
--- /dev/null
+++ b/feature/test-feature.mak
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+define test-feature
+$(shell $(MAKE) OBJDIR=$(OBJDIR) CFLAGS=$(CFLAGS) CPPFLAGS=$(CPPFLAGS) LDFLAGS=$(LDFLAGS) \
+-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


  reply	other threads:[~2024-11-13 11:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-13 11:45 [PATCH v2 0/3] rt-tests: cyclictest: Support idle state disabling via libcpupower tglozar
2024-11-13 11:45 ` tglozar [this message]
2024-11-13 11:45 ` [PATCH v2 2/3] " tglozar
2024-11-26 22:29   ` John Kacur
2024-11-27  0:08     ` Crystal Wood
2024-11-27  9:45       ` Tomas Glozar
2024-11-27 15:51         ` John Kacur
2024-12-06 11:52         ` Sebastian Andrzej Siewior
2024-12-06 12:14           ` Tomas Glozar
2024-12-06 14:41             ` Sebastian Andrzej Siewior
2024-12-06 15:29           ` John Kacur
2024-11-27 15:47       ` John Kacur
2024-12-02 19:30         ` Crystal Wood
2024-11-13 11:45 ` [PATCH v2 3/3] rt-tests: cyclictest: Add --deepest-idle-state to manpage tglozar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241113114509.1058593-2-tglozar@redhat.com \
    --to=tglozar@redhat.com \
    --cc=jkacur@redhat.com \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox