[PATCH v2] tools/dma: move dma_map_benchmark from selftests to tools/dma

Qinxin Xia posted 1 patch 3 months, 3 weeks ago
There is a newer version of this series
include/linux/map_benchmark.h                 | 22 +------------
include/uapi/linux/map_benchmark.h            | 33 +++++++++++++++++++
tools/Makefile                                | 13 ++++----
tools/dma/.gitignore                          |  2 ++
tools/dma/Makefile                            | 17 ++++++++++
tools/{testing/selftests => }/dma/config      |  0
.../selftests => }/dma/dma_map_benchmark.c    |  0
tools/testing/selftests/dma/Makefile          |  7 ----
8 files changed, 60 insertions(+), 34 deletions(-)
create mode 100644 include/uapi/linux/map_benchmark.h
create mode 100644 tools/dma/.gitignore
create mode 100644 tools/dma/Makefile
rename tools/{testing/selftests => }/dma/config (100%)
rename tools/{testing/selftests => }/dma/dma_map_benchmark.c (100%)
delete mode 100644 tools/testing/selftests/dma/Makefile
[PATCH v2] tools/dma: move dma_map_benchmark from selftests to tools/dma
Posted by Qinxin Xia 3 months, 3 weeks ago
dma_map_benchmark is a standalone developer tool rather than an
automated selftest. It has no pass/fail criteria, expects manual
invocation, and is built as a normal userspace binary. Move it to
tools/dma/ and add a minimal, the original selftest/dma/Makefile
entry is removed to avoid duplication.

Signed-off-by: Qinxin Xia <xiaqinxin@huawei.com>
---
Changes since v1:
1) Addressed comments from Barry:
   - Moved map_benchmark.h from include/linux to include/uapi/linux/.
   - Modified CFLAGS in Makefile to reflect the new header location.

2) Added a .gitignore file to exclude unnecessary files.

3) Restored the 'expansion' field in 'struct map_benchmark':
   - This field was accidentally removed in commit 8ddde07a3d.
   - The change ensures that the structure remains compatible with existing codebases.
Link: https://lore.kernel.org/all/20250814133527.2679261-1-xiaqinxin@huawei.com/
---
 include/linux/map_benchmark.h                 | 22 +------------
 include/uapi/linux/map_benchmark.h            | 33 +++++++++++++++++++
 tools/Makefile                                | 13 ++++----
 tools/dma/.gitignore                          |  2 ++
 tools/dma/Makefile                            | 17 ++++++++++
 tools/{testing/selftests => }/dma/config      |  0
 .../selftests => }/dma/dma_map_benchmark.c    |  0
 tools/testing/selftests/dma/Makefile          |  7 ----
 8 files changed, 60 insertions(+), 34 deletions(-)
 create mode 100644 include/uapi/linux/map_benchmark.h
 create mode 100644 tools/dma/.gitignore
 create mode 100644 tools/dma/Makefile
 rename tools/{testing/selftests => }/dma/config (100%)
 rename tools/{testing/selftests => }/dma/dma_map_benchmark.c (100%)
 delete mode 100644 tools/testing/selftests/dma/Makefile

diff --git a/include/linux/map_benchmark.h b/include/linux/map_benchmark.h
index 62674c83bde4..c1bcb4b23398 100644
--- a/include/linux/map_benchmark.h
+++ b/include/linux/map_benchmark.h
@@ -6,26 +6,6 @@
 #ifndef _KERNEL_DMA_BENCHMARK_H
 #define _KERNEL_DMA_BENCHMARK_H
 
-#define DMA_MAP_BENCHMARK       _IOWR('d', 1, struct map_benchmark)
-#define DMA_MAP_MAX_THREADS     1024
-#define DMA_MAP_MAX_SECONDS     300
-#define DMA_MAP_MAX_TRANS_DELAY (10 * NSEC_PER_MSEC)
+#include <uapi/linux/map_benchmark.h>
 
-#define DMA_MAP_BIDIRECTIONAL   0
-#define DMA_MAP_TO_DEVICE       1
-#define DMA_MAP_FROM_DEVICE     2
-
-struct map_benchmark {
-	__u64 avg_map_100ns; /* average map latency in 100ns */
-	__u64 map_stddev; /* standard deviation of map latency */
-	__u64 avg_unmap_100ns; /* as above */
-	__u64 unmap_stddev;
-	__u32 threads; /* how many threads will do map/unmap in parallel */
-	__u32 seconds; /* how long the test will last */
-	__s32 node; /* which numa node this benchmark will run on */
-	__u32 dma_bits; /* DMA addressing capability */
-	__u32 dma_dir; /* DMA data direction */
-	__u32 dma_trans_ns; /* time for DMA transmission in ns */
-	__u32 granule;  /* how many PAGE_SIZE will do map/unmap once a time */
-};
 #endif /* _KERNEL_DMA_BENCHMARK_H */
diff --git a/include/uapi/linux/map_benchmark.h b/include/uapi/linux/map_benchmark.h
new file mode 100644
index 000000000000..2a75041803d4
--- /dev/null
+++ b/include/uapi/linux/map_benchmark.h
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
+/*
+ * Copyright (C) 2025 HiSilicon Limited.
+ */
+
+#ifndef _UAPI_DMA_BENCHMARK_H
+#define _UAPI_DMA_BENCHMARK_H
+
+#define DMA_MAP_BENCHMARK       _IOWR('d', 1, struct map_benchmark)
+#define DMA_MAP_MAX_THREADS     1024
+#define DMA_MAP_MAX_SECONDS     300
+#define DMA_MAP_MAX_TRANS_DELAY (10 * NSEC_PER_MSEC)
+
+#define DMA_MAP_BIDIRECTIONAL   0
+#define DMA_MAP_TO_DEVICE       1
+#define DMA_MAP_FROM_DEVICE     2
+
+struct map_benchmark {
+	__u64 avg_map_100ns; /* average map latency in 100ns */
+	__u64 map_stddev; /* standard deviation of map latency */
+	__u64 avg_unmap_100ns; /* as above */
+	__u64 unmap_stddev;
+	__u32 threads; /* how many threads will do map/unmap in parallel */
+	__u32 seconds; /* how long the test will last */
+	__s32 node; /* which numa node this benchmark will run on */
+	__u32 dma_bits; /* DMA addressing capability */
+	__u32 dma_dir; /* DMA data direction */
+	__u32 dma_trans_ns; /* time for DMA transmission in ns */
+	__u32 granule;  /* how many PAGE_SIZE will do map/unmap once a time */
+	__u8 expansion[76]; /* For future use */
+};
+
+#endif /* _UAPI_DMA_BENCHMARK_H */
diff --git a/tools/Makefile b/tools/Makefile
index c31cbbd12c45..cb40961a740f 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -14,6 +14,7 @@ help:
 	@echo '  counter                - counter tools'
 	@echo '  cpupower               - a tool for all things x86 CPU power'
 	@echo '  debugging              - tools for debugging'
+	@echo '  dma                    - tools for DMA mapping'
 	@echo '  firewire               - the userspace part of nosy, an IEEE-1394 traffic sniffer'
 	@echo '  firmware               - Firmware tools'
 	@echo '  freefall               - laptop accelerometer program for disk protection'
@@ -69,7 +70,7 @@ acpi: FORCE
 cpupower: FORCE
 	$(call descend,power/$@)
 
-counter firewire hv guest bootconfig spi usb virtio mm bpf iio gpio objtool leds wmi firmware debugging tracing: FORCE
+counter dma firewire hv guest bootconfig spi usb virtio mm bpf iio gpio objtool leds wmi firmware debugging tracing: FORCE
 	$(call descend,$@)
 
 bpf/%: FORCE
@@ -122,7 +123,7 @@ kvm_stat: FORCE
 ynl: FORCE
 	$(call descend,net/ynl)
 
-all: acpi counter cpupower gpio hv firewire \
+all: acpi counter cpupower dma gpio hv firewire \
 		perf selftests bootconfig spi turbostat usb \
 		virtio mm bpf x86_energy_perf_policy \
 		tmon freefall iio objtool kvm_stat wmi \
@@ -134,7 +135,7 @@ acpi_install:
 cpupower_install:
 	$(call descend,power/$(@:_install=),install)
 
-counter_install firewire_install gpio_install hv_install iio_install perf_install bootconfig_install spi_install usb_install virtio_install mm_install bpf_install objtool_install wmi_install debugging_install tracing_install:
+counter_install dma_install firewire_install gpio_install hv_install iio_install perf_install bootconfig_install spi_install usb_install virtio_install mm_install bpf_install objtool_install wmi_install debugging_install tracing_install:
 	$(call descend,$(@:_install=),install)
 
 selftests_install:
@@ -164,7 +165,7 @@ kvm_stat_install:
 ynl_install:
 	$(call descend,net/$(@:_install=),install)
 
-install: acpi_install counter_install cpupower_install gpio_install \
+install: acpi_install counter_install cpupower_install dma_install gpio_install \
 		hv_install firewire_install iio_install \
 		perf_install selftests_install turbostat_install usb_install \
 		virtio_install mm_install bpf_install x86_energy_perf_policy_install \
@@ -178,7 +179,7 @@ acpi_clean:
 cpupower_clean:
 	$(call descend,power/cpupower,clean)
 
-counter_clean hv_clean firewire_clean bootconfig_clean spi_clean usb_clean virtio_clean mm_clean wmi_clean bpf_clean iio_clean gpio_clean objtool_clean leds_clean firmware_clean debugging_clean tracing_clean:
+counter_clean dma_clean hv_clean firewire_clean bootconfig_clean spi_clean usb_clean virtio_clean mm_clean wmi_clean bpf_clean iio_clean gpio_clean objtool_clean leds_clean firmware_clean debugging_clean tracing_clean:
 	$(call descend,$(@:_clean=),clean)
 
 libapi_clean:
@@ -224,7 +225,7 @@ build_clean:
 ynl_clean:
 	$(call descend,net/$(@:_clean=),clean)
 
-clean: acpi_clean counter_clean cpupower_clean hv_clean firewire_clean \
+clean: acpi_clean counter_clean cpupower_clean dma_clean hv_clean firewire_clean \
 		perf_clean selftests_clean turbostat_clean bootconfig_clean spi_clean usb_clean virtio_clean \
 		mm_clean bpf_clean iio_clean x86_energy_perf_policy_clean tmon_clean \
 		freefall_clean build_clean libbpf_clean libsubcmd_clean \
diff --git a/tools/dma/.gitignore b/tools/dma/.gitignore
new file mode 100644
index 000000000000..b4b99b6ffea3
--- /dev/null
+++ b/tools/dma/.gitignore
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+dma_map_benchmark
diff --git a/tools/dma/Makefile b/tools/dma/Makefile
new file mode 100644
index 000000000000..4acbd9e00cfa
--- /dev/null
+++ b/tools/dma/Makefile
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0
+bindir ?= /usr/bin
+
+CFLAGS += -idirafter../../include/uapi
+
+TARGET = dma_map_benchmark
+
+all: $(TARGET)
+
+$(TARGET): $(TARGET).c
+	$(CC) $(CFLAGS) $< -o $@
+
+install: all
+	install -D -m 755 $(TARGET) $(DESTDIR)$(bindir)/$(TARGET)
+
+clean:
+	rm -f $(TARGET)
diff --git a/tools/testing/selftests/dma/config b/tools/dma/config
similarity index 100%
rename from tools/testing/selftests/dma/config
rename to tools/dma/config
diff --git a/tools/testing/selftests/dma/dma_map_benchmark.c b/tools/dma/dma_map_benchmark.c
similarity index 100%
rename from tools/testing/selftests/dma/dma_map_benchmark.c
rename to tools/dma/dma_map_benchmark.c
diff --git a/tools/testing/selftests/dma/Makefile b/tools/testing/selftests/dma/Makefile
deleted file mode 100644
index cd8c5ece1cba..000000000000
--- a/tools/testing/selftests/dma/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0
-CFLAGS += -I../../../../usr/include/
-CFLAGS += -I../../../../include/
-
-TEST_GEN_PROGS := dma_map_benchmark
-
-include ../lib.mk
-- 
2.33.0
Re: [PATCH v2] tools/dma: move dma_map_benchmark from selftests to tools/dma
Posted by kernel test robot 3 months, 2 weeks ago
Hi Qinxin,

kernel test robot noticed the following build errors:

[auto build test ERROR on shuah-kselftest/next]
[also build test ERROR on shuah-kselftest/fixes linus/master v6.18-rc1 next-20251017]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Qinxin-Xia/tools-dma-move-dma_map_benchmark-from-selftests-to-tools-dma/20251018-181628
base:   https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git next
patch link:    https://lore.kernel.org/r/20251018101402.3079372-1-xiaqinxin%40huawei.com
patch subject: [PATCH v2] tools/dma: move dma_map_benchmark from selftests to tools/dma
config: x86_64-buildonly-randconfig-002-20251019 (https://download.01.org/0day-ci/archive/20251019/202510191133.ThgrGhqL-lkp@intel.com/config)
compiler: gcc-13 (Debian 13.3.0-16) 13.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251019/202510191133.ThgrGhqL-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202510191133.ThgrGhqL-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from <command-line>:
>> ./usr/include/linux/map_benchmark.h:19:9: error: unknown type name '__u64'
      19 |         __u64 avg_map_100ns; /* average map latency in 100ns */
         |         ^~~~~
   ./usr/include/linux/map_benchmark.h:20:9: error: unknown type name '__u64'
      20 |         __u64 map_stddev; /* standard deviation of map latency */
         |         ^~~~~
   ./usr/include/linux/map_benchmark.h:21:9: error: unknown type name '__u64'
      21 |         __u64 avg_unmap_100ns; /* as above */
         |         ^~~~~
   ./usr/include/linux/map_benchmark.h:22:9: error: unknown type name '__u64'
      22 |         __u64 unmap_stddev;
         |         ^~~~~
>> ./usr/include/linux/map_benchmark.h:23:9: error: unknown type name '__u32'
      23 |         __u32 threads; /* how many threads will do map/unmap in parallel */
         |         ^~~~~
   ./usr/include/linux/map_benchmark.h:24:9: error: unknown type name '__u32'
      24 |         __u32 seconds; /* how long the test will last */
         |         ^~~~~
>> ./usr/include/linux/map_benchmark.h:25:9: error: unknown type name '__s32'
      25 |         __s32 node; /* which numa node this benchmark will run on */
         |         ^~~~~
   ./usr/include/linux/map_benchmark.h:26:9: error: unknown type name '__u32'
      26 |         __u32 dma_bits; /* DMA addressing capability */
         |         ^~~~~
   ./usr/include/linux/map_benchmark.h:27:9: error: unknown type name '__u32'
      27 |         __u32 dma_dir; /* DMA data direction */
         |         ^~~~~
   ./usr/include/linux/map_benchmark.h:28:9: error: unknown type name '__u32'
      28 |         __u32 dma_trans_ns; /* time for DMA transmission in ns */
         |         ^~~~~
   ./usr/include/linux/map_benchmark.h:29:9: error: unknown type name '__u32'
      29 |         __u32 granule;  /* how many PAGE_SIZE will do map/unmap once a time */
         |         ^~~~~
>> ./usr/include/linux/map_benchmark.h:30:9: error: unknown type name '__u8'
      30 |         __u8 expansion[76]; /* For future use */
         |         ^~~~

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki