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

dma-mapping: benchmark: extract a common header file for map_benchmark definition

kernel/dma/map_benchmark.c and selftests/dma/dma_map_benchmark.c
have duplicate map_benchmark definitions, which tends to lead to
inconsistent changes to map_benchmark on both sides, extract a
common header file to avoid this problem.

Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
Acked-by: Barry Song <song.bao.hua@hisilicon.com>
Reviewed-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>

authored by

Tian Tao and committed by
Christoph Hellwig
8ddde07a 80e43909

+33 -48
+31
include/linux/map_benchmark.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Copyright (C) 2022 HiSilicon Limited. 4 + */ 5 + 6 + #ifndef _KERNEL_DMA_BENCHMARK_H 7 + #define _KERNEL_DMA_BENCHMARK_H 8 + 9 + #define DMA_MAP_BENCHMARK _IOWR('d', 1, struct map_benchmark) 10 + #define DMA_MAP_MAX_THREADS 1024 11 + #define DMA_MAP_MAX_SECONDS 300 12 + #define DMA_MAP_MAX_TRANS_DELAY (10 * NSEC_PER_MSEC) 13 + 14 + #define DMA_MAP_BIDIRECTIONAL 0 15 + #define DMA_MAP_TO_DEVICE 1 16 + #define DMA_MAP_FROM_DEVICE 2 17 + 18 + struct map_benchmark { 19 + __u64 avg_map_100ns; /* average map latency in 100ns */ 20 + __u64 map_stddev; /* standard deviation of map latency */ 21 + __u64 avg_unmap_100ns; /* as above */ 22 + __u64 unmap_stddev; 23 + __u32 threads; /* how many threads will do map/unmap in parallel */ 24 + __u32 seconds; /* how long the test will last */ 25 + __s32 node; /* which numa node this benchmark will run on */ 26 + __u32 dma_bits; /* DMA addressing capability */ 27 + __u32 dma_dir; /* DMA data direction */ 28 + __u32 dma_trans_ns; /* time for DMA transmission in ns */ 29 + __u32 granule; /* how many PAGE_SIZE will do map/unmap once a time */ 30 + }; 31 + #endif /* _KERNEL_DMA_BENCHMARK_H */
+1 -24
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> 14 15 #include <linux/math64.h> 15 16 #include <linux/module.h> 16 17 #include <linux/pci.h> 17 18 #include <linux/platform_device.h> 18 19 #include <linux/slab.h> 19 20 #include <linux/timekeeping.h> 20 - 21 - #define DMA_MAP_BENCHMARK _IOWR('d', 1, struct map_benchmark) 22 - #define DMA_MAP_MAX_THREADS 1024 23 - #define DMA_MAP_MAX_SECONDS 300 24 - #define DMA_MAP_MAX_TRANS_DELAY (10 * NSEC_PER_MSEC) 25 - 26 - #define DMA_MAP_BIDIRECTIONAL 0 27 - #define DMA_MAP_TO_DEVICE 1 28 - #define DMA_MAP_FROM_DEVICE 2 29 - 30 - struct map_benchmark { 31 - __u64 avg_map_100ns; /* average map latency in 100ns */ 32 - __u64 map_stddev; /* standard deviation of map latency */ 33 - __u64 avg_unmap_100ns; /* as above */ 34 - __u64 unmap_stddev; 35 - __u32 threads; /* how many threads will do map/unmap in parallel */ 36 - __u32 seconds; /* how long the test will last */ 37 - __s32 node; /* which numa node this benchmark will run on */ 38 - __u32 dma_bits; /* DMA addressing capability */ 39 - __u32 dma_dir; /* DMA data direction */ 40 - __u32 dma_trans_ns; /* time for DMA transmission in ns */ 41 - __u32 granule; /* how many PAGE_SIZE will do map/unmap once a time */ 42 - __u8 expansion[76]; /* For future use */ 43 - }; 44 21 45 22 struct map_benchmark_data { 46 23 struct map_benchmark bparam;
+1 -24
tools/testing/selftests/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/map_benchmark.h> 13 14 #include <linux/types.h> 14 15 15 16 #define NSEC_PER_MSEC 1000000L 16 - 17 - #define DMA_MAP_BENCHMARK _IOWR('d', 1, struct map_benchmark) 18 - #define DMA_MAP_MAX_THREADS 1024 19 - #define DMA_MAP_MAX_SECONDS 300 20 - #define DMA_MAP_MAX_TRANS_DELAY (10 * NSEC_PER_MSEC) 21 - 22 - #define DMA_MAP_BIDIRECTIONAL 0 23 - #define DMA_MAP_TO_DEVICE 1 24 - #define DMA_MAP_FROM_DEVICE 2 25 17 26 18 static char *directions[] = { 27 19 "BIDIRECTIONAL", 28 20 "TO_DEVICE", 29 21 "FROM_DEVICE", 30 - }; 31 - 32 - struct map_benchmark { 33 - __u64 avg_map_100ns; /* average map latency in 100ns */ 34 - __u64 map_stddev; /* standard deviation of map latency */ 35 - __u64 avg_unmap_100ns; /* as above */ 36 - __u64 unmap_stddev; 37 - __u32 threads; /* how many threads will do map/unmap in parallel */ 38 - __u32 seconds; /* how long the test will last */ 39 - __s32 node; /* which numa node this benchmark will run on */ 40 - __u32 dma_bits; /* DMA addressing capability */ 41 - __u32 dma_dir; /* DMA data direction */ 42 - __u32 dma_trans_ns; /* time for DMA transmission in ns */ 43 - __u32 granule; /* how many PAGE_SIZE will do map/unmap once a time */ 44 - __u8 expansion[76]; /* For future use */ 45 22 }; 46 23 47 24 int main(int argc, char **argv)