Skip to content

Commit f74ee32

Browse files
Qinxin Xiamszyprow
authored andcommitted
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
1 parent 23ee8a2 commit f74ee32

8 files changed

Lines changed: 74 additions & 20 deletions

File tree

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
/* SPDX-License-Identifier: GPL-2.0-only */
1+
/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
22
/*
3-
* Copyright (C) 2022 HiSilicon Limited.
3+
* Copyright (C) 2022-2025 HiSilicon Limited.
44
*/
55

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

911
#define DMA_MAP_BENCHMARK _IOWR('d', 1, struct map_benchmark)
1012
#define DMA_MAP_MAX_THREADS 1024
@@ -29,4 +31,5 @@ struct map_benchmark {
2931
__u32 granule; /* how many PAGE_SIZE will do map/unmap once a time */
3032
__u8 expansion[76]; /* For future use */
3133
};
32-
#endif /* _KERNEL_DMA_BENCHMARK_H */
34+
35+
#endif /* _UAPI_DMA_BENCHMARK_H */

kernel/dma/map_benchmark.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
#include <linux/dma-mapping.h>
1212
#include <linux/kernel.h>
1313
#include <linux/kthread.h>
14-
#include <linux/map_benchmark.h>
1514
#include <linux/math64.h>
1615
#include <linux/module.h>
1716
#include <linux/pci.h>
1817
#include <linux/platform_device.h>
1918
#include <linux/slab.h>
2019
#include <linux/timekeeping.h>
20+
#include <uapi/linux/map_benchmark.h>
2121

2222
struct map_benchmark_data {
2323
struct map_benchmark bparam;

tools/Makefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ help:
1414
@echo ' counter - counter tools'
1515
@echo ' cpupower - a tool for all things x86 CPU power'
1616
@echo ' debugging - tools for debugging'
17+
@echo ' dma - tools for DMA mapping'
1718
@echo ' firewire - the userspace part of nosy, an IEEE-1394 traffic sniffer'
1819
@echo ' firmware - Firmware tools'
1920
@echo ' freefall - laptop accelerometer program for disk protection'
@@ -69,7 +70,7 @@ acpi: FORCE
6970
cpupower: FORCE
7071
$(call descend,power/$@)
7172

72-
counter firewire hv guest bootconfig spi usb virtio mm bpf iio gpio objtool leds wmi firmware debugging tracing: FORCE
73+
counter dma firewire hv guest bootconfig spi usb virtio mm bpf iio gpio objtool leds wmi firmware debugging tracing: FORCE
7374
$(call descend,$@)
7475

7576
bpf/%: FORCE
@@ -122,7 +123,7 @@ kvm_stat: FORCE
122123
ynl: FORCE
123124
$(call descend,net/ynl)
124125

125-
all: acpi counter cpupower gpio hv firewire \
126+
all: acpi counter cpupower dma gpio hv firewire \
126127
perf selftests bootconfig spi turbostat usb \
127128
virtio mm bpf x86_energy_perf_policy \
128129
tmon freefall iio objtool kvm_stat wmi \
@@ -134,7 +135,7 @@ acpi_install:
134135
cpupower_install:
135136
$(call descend,power/$(@:_install=),install)
136137

137-
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:
138+
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:
138139
$(call descend,$(@:_install=),install)
139140

140141
selftests_install:
@@ -164,7 +165,7 @@ kvm_stat_install:
164165
ynl_install:
165166
$(call descend,net/$(@:_install=),install)
166167

167-
install: acpi_install counter_install cpupower_install gpio_install \
168+
install: acpi_install counter_install cpupower_install dma_install gpio_install \
168169
hv_install firewire_install iio_install \
169170
perf_install selftests_install turbostat_install usb_install \
170171
virtio_install mm_install bpf_install x86_energy_perf_policy_install \
@@ -178,7 +179,7 @@ acpi_clean:
178179
cpupower_clean:
179180
$(call descend,power/cpupower,clean)
180181

181-
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:
182+
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:
182183
$(call descend,$(@:_clean=),clean)
183184

184185
libapi_clean:
@@ -224,7 +225,7 @@ build_clean:
224225
ynl_clean:
225226
$(call descend,net/$(@:_clean=),clean)
226227

227-
clean: acpi_clean counter_clean cpupower_clean hv_clean firewire_clean \
228+
clean: acpi_clean counter_clean cpupower_clean dma_clean hv_clean firewire_clean \
228229
perf_clean selftests_clean turbostat_clean bootconfig_clean spi_clean usb_clean virtio_clean \
229230
mm_clean bpf_clean iio_clean x86_energy_perf_policy_clean tmon_clean \
230231
freefall_clean build_clean libbpf_clean libsubcmd_clean \

tools/dma/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
dma_map_benchmark
3+
include/linux/map_benchmark.h

tools/dma/Makefile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

tools/testing/selftests/dma/dma_map_benchmark.c renamed to tools/dma/dma_map_benchmark.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <unistd.h>
1111
#include <sys/ioctl.h>
1212
#include <sys/mman.h>
13-
#include <linux/types.h>
1413
#include <linux/map_benchmark.h>
1514

1615
#define NSEC_PER_MSEC 1000000L

tools/testing/selftests/dma/Makefile

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)