Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/dma: move dma_map_benchmark from selftests to tools/dma

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

Suggested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Suggested-by: Barry Song <baohua@kernel.org>
Signed-off-by: Qinxin Xia <xiaqinxin@huawei.com>
Acked-by: Barry Song <baohua@kernel.org>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Link: https://lore.kernel.org/r/20251028120900.2265511-3-xiaqinxin@huawei.com

authored by

Qinxin Xia and committed by
Marek Szyprowski
f74ee329 23ee8a25

+74 -20
+8 -5
include/linux/map_benchmark.h include/uapi/linux/map_benchmark.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0-only */ 1 + /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */ 2 2 /* 3 - * Copyright (C) 2022 HiSilicon Limited. 3 + * Copyright (C) 2022-2025 HiSilicon Limited. 4 4 */ 5 5 6 - #ifndef _KERNEL_DMA_BENCHMARK_H 7 - #define _KERNEL_DMA_BENCHMARK_H 6 + #ifndef _UAPI_DMA_BENCHMARK_H 7 + #define _UAPI_DMA_BENCHMARK_H 8 + 9 + #include <linux/types.h> 8 10 9 11 #define DMA_MAP_BENCHMARK _IOWR('d', 1, struct map_benchmark) 10 12 #define DMA_MAP_MAX_THREADS 1024 ··· 31 29 __u32 granule; /* how many PAGE_SIZE will do map/unmap once a time */ 32 30 __u8 expansion[76]; /* For future use */ 33 31 }; 34 - #endif /* _KERNEL_DMA_BENCHMARK_H */ 32 + 33 + #endif /* _UAPI_DMA_BENCHMARK_H */
+1 -1
kernel/dma/map_benchmark.c
··· 11 11 #include <linux/dma-mapping.h> 12 12 #include <linux/kernel.h> 13 13 #include <linux/kthread.h> 14 - #include <linux/map_benchmark.h> 15 14 #include <linux/math64.h> 16 15 #include <linux/module.h> 17 16 #include <linux/pci.h> 18 17 #include <linux/platform_device.h> 19 18 #include <linux/slab.h> 20 19 #include <linux/timekeeping.h> 20 + #include <uapi/linux/map_benchmark.h> 21 21 22 22 struct map_benchmark_data { 23 23 struct map_benchmark bparam;
+7 -6
tools/Makefile
··· 14 14 @echo ' counter - counter tools' 15 15 @echo ' cpupower - a tool for all things x86 CPU power' 16 16 @echo ' debugging - tools for debugging' 17 + @echo ' dma - tools for DMA mapping' 17 18 @echo ' firewire - the userspace part of nosy, an IEEE-1394 traffic sniffer' 18 19 @echo ' firmware - Firmware tools' 19 20 @echo ' freefall - laptop accelerometer program for disk protection' ··· 70 69 cpupower: FORCE 71 70 $(call descend,power/$@) 72 71 73 - counter firewire hv guest bootconfig spi usb virtio mm bpf iio gpio objtool leds wmi firmware debugging tracing: FORCE 72 + counter dma firewire hv guest bootconfig spi usb virtio mm bpf iio gpio objtool leds wmi firmware debugging tracing: FORCE 74 73 $(call descend,$@) 75 74 76 75 bpf/%: FORCE ··· 123 122 ynl: FORCE 124 123 $(call descend,net/ynl) 125 124 126 - all: acpi counter cpupower gpio hv firewire \ 125 + all: acpi counter cpupower dma gpio hv firewire \ 127 126 perf selftests bootconfig spi turbostat usb \ 128 127 virtio mm bpf x86_energy_perf_policy \ 129 128 tmon freefall iio objtool kvm_stat wmi \ ··· 135 134 cpupower_install: 136 135 $(call descend,power/$(@:_install=),install) 137 136 138 - 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: 137 + 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: 139 138 $(call descend,$(@:_install=),install) 140 139 141 140 selftests_install: ··· 165 164 ynl_install: 166 165 $(call descend,net/$(@:_install=),install) 167 166 168 - install: acpi_install counter_install cpupower_install gpio_install \ 167 + install: acpi_install counter_install cpupower_install dma_install gpio_install \ 169 168 hv_install firewire_install iio_install \ 170 169 perf_install selftests_install turbostat_install usb_install \ 171 170 virtio_install mm_install bpf_install x86_energy_perf_policy_install \ ··· 179 178 cpupower_clean: 180 179 $(call descend,power/cpupower,clean) 181 180 182 - 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: 181 + 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: 183 182 $(call descend,$(@:_clean=),clean) 184 183 185 184 libapi_clean: ··· 225 224 ynl_clean: 226 225 $(call descend,net/$(@:_clean=),clean) 227 226 228 - clean: acpi_clean counter_clean cpupower_clean hv_clean firewire_clean \ 227 + clean: acpi_clean counter_clean cpupower_clean dma_clean hv_clean firewire_clean \ 229 228 perf_clean selftests_clean turbostat_clean bootconfig_clean spi_clean usb_clean virtio_clean \ 230 229 mm_clean bpf_clean iio_clean x86_energy_perf_policy_clean tmon_clean \ 231 230 freefall_clean build_clean libbpf_clean libsubcmd_clean \
+3
tools/dma/.gitignore
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + dma_map_benchmark 3 + include/linux/map_benchmark.h
+55
tools/dma/Makefile
··· 1 + # SPDX-License-Identifier: GPL-2.0 2 + include ../scripts/Makefile.include 3 + 4 + bindir ?= /usr/bin 5 + 6 + # This will work when dma is built in tools env. where srctree 7 + # isn't set and when invoked from selftests build, where srctree 8 + # is set to ".". building_out_of_srctree is undefined for in srctree 9 + # builds 10 + ifndef building_out_of_srctree 11 + srctree := $(patsubst %/,%,$(dir $(CURDIR))) 12 + srctree := $(patsubst %/,%,$(dir $(srctree))) 13 + endif 14 + 15 + # Do not use make's built-in rules 16 + # (this improves performance and avoids hard-to-debug behaviour); 17 + MAKEFLAGS += -r 18 + 19 + override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include 20 + 21 + ALL_TARGETS := dma_map_benchmark 22 + ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS)) 23 + 24 + all: $(ALL_PROGRAMS) 25 + 26 + export srctree OUTPUT CC LD CFLAGS 27 + include $(srctree)/tools/build/Makefile.include 28 + 29 + # 30 + # We need the following to be outside of kernel tree 31 + # 32 + $(OUTPUT)include/linux/map_benchmark.h: ../../include/uapi/linux/map_benchmark.h 33 + mkdir -p $(OUTPUT)include/linux 2>&1 || true 34 + ln -sf $(CURDIR)/../../include/uapi/linux/map_benchmark.h $@ 35 + 36 + prepare: $(OUTPUT)include/linux/map_benchmark.h 37 + 38 + FORCE: 39 + 40 + DMA_MAP_BENCHMARK = dma_map_benchmark 41 + $(DMA_MAP_BENCHMARK): prepare FORCE 42 + $(CC) $(CFLAGS) $(DMA_MAP_BENCHMARK).c -o $(DMA_MAP_BENCHMARK) 43 + 44 + clean: 45 + rm -f $(ALL_PROGRAMS) 46 + rm -rf $(OUTPUT)include 47 + find $(or $(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete -o -name '\.*.cmd' -delete 48 + 49 + install: $(ALL_PROGRAMS) 50 + install -d -m 755 $(DESTDIR)$(bindir); \ 51 + for program in $(ALL_PROGRAMS); do \ 52 + install $$program $(DESTDIR)$(bindir); \ 53 + done 54 + 55 + .PHONY: all install clean prepare FORCE
-7
tools/testing/selftests/dma/Makefile
··· 1 - # SPDX-License-Identifier: GPL-2.0 2 - CFLAGS += -I../../../../usr/include/ 3 - CFLAGS += -I../../../../include/ 4 - 5 - TEST_GEN_PROGS := dma_map_benchmark 6 - 7 - include ../lib.mk
tools/testing/selftests/dma/config tools/dma/config
-1
tools/testing/selftests/dma/dma_map_benchmark.c tools/dma/dma_map_benchmark.c
··· 10 10 #include <unistd.h> 11 11 #include <sys/ioctl.h> 12 12 #include <sys/mman.h> 13 - #include <linux/types.h> 14 13 #include <linux/map_benchmark.h> 15 14 16 15 #define NSEC_PER_MSEC 1000000L