[PATCH v1 1/3] perf build: Add libnvme feature detection

From: Ian Rogers

Date: Tue Jun 09 2026 - 03:04:18 EST


Introduce a feature check for libnvme so that we can conditionally
compile the NVMe PMU driver. This checks for the availability of the
libnvme headers and library using pkg-config.

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
CONV=ca4c5d09-4ef8-405a-80bb-aa988020b436
TAG=agy
---
tools/build/Makefile.feature | 2 ++
tools/build/feature/Makefile | 3 +++
tools/build/feature/test-libnvme.c | 11 +++++++++++
tools/perf/Makefile.config | 12 ++++++++++++
4 files changed, 28 insertions(+)
create mode 100644 tools/build/feature/test-libnvme.c

diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature
index ed1374af31c1..bf8503241539 100644
--- a/tools/build/Makefile.feature
+++ b/tools/build/Makefile.feature
@@ -73,6 +73,7 @@ FEATURE_TESTS_BASIC := \
libbfd \
libbfd-threadsafe \
libelf \
+ libnvme \
libelf-getphdrnum \
libelf-gelf_getnote \
libelf-getshdrstrndx \
@@ -146,6 +147,7 @@ FEATURE_DISPLAY ?= \
libdw \
glibc \
libelf \
+ libnvme \
libnuma \
numa_num_possible_cpus \
libpython \
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index 62909a9c799d..fd00e0be6069 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -147,6 +147,9 @@ $(OUTPUT)test-libcap.bin:
$(OUTPUT)test-libelf.bin:
$(BUILD) -lelf

+$(OUTPUT)test-libnvme.bin:
+ $(BUILD) -lnvme
+
$(OUTPUT)test-eventfd.bin:
$(BUILD)

diff --git a/tools/build/feature/test-libnvme.c b/tools/build/feature/test-libnvme.c
new file mode 100644
index 000000000000..3fefad70a680
--- /dev/null
+++ b/tools/build/feature/test-libnvme.c
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
+#include <libnvme.h>
+
+int main(void)
+{
+ nvme_root_t r = nvme_scan(NULL);
+
+ if (r)
+ nvme_free_tree(r);
+ return 0;
+}
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 6e7b15fab2ec..79c4ad10bc18 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -1060,6 +1060,18 @@ ifndef NO_CAPSTONE
endif
endif

+ifndef NO_LIBNVME
+ $(call feature_check,libnvme)
+ ifeq ($(feature-libnvme), 1)
+ CFLAGS += -DHAVE_LIBNVME_SUPPORT $(shell $(PKG_CONFIG) --cflags libnvme)
+ LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L libnvme)
+ EXTLIBS += $(shell $(PKG_CONFIG) --libs-only-l libnvme)
+ $(call detected,CONFIG_LIBNVME)
+ else
+ msg := $(warning No libnvme found, disables NVMe PMU support, please install libnvme-dev/libnvme-devel);
+ endif
+endif
+
ifdef EXTRA_TESTS
$(call detected,CONFIG_EXTRA_TESTS)
CFLAGS += -DHAVE_EXTRA_TESTS
--
2.54.0.1064.gd145956f57-goog