Skip to content

Commit 8ddde07

Browse files
Tian TaoChristoph Hellwig
authored andcommitted
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>
1 parent 80e4390 commit 8ddde07

File tree

3 files changed

+33
-48
lines changed

3 files changed

+33
-48
lines changed

include/linux/map_benchmark.h

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

kernel/dma/map_benchmark.c

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,14 @@
1111
#include <linux/dma-mapping.h>
1212
#include <linux/kernel.h>
1313
#include <linux/kthread.h>
14+
#include <linux/map_benchmark.h>
1415
#include <linux/math64.h>
1516
#include <linux/module.h>
1617
#include <linux/pci.h>
1718
#include <linux/platform_device.h>
1819
#include <linux/slab.h>
1920
#include <linux/timekeeping.h>
2021

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-
4522
struct map_benchmark_data {
4623
struct map_benchmark bparam;
4724
struct device *dev;

tools/testing/selftests/dma/dma_map_benchmark.c

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,17 @@
1010
#include <unistd.h>
1111
#include <sys/ioctl.h>
1212
#include <sys/mman.h>
13+
#include <linux/map_benchmark.h>
1314
#include <linux/types.h>
1415

1516
#define NSEC_PER_MSEC 1000000L
1617

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-
2618
static char *directions[] = {
2719
"BIDIRECTIONAL",
2820
"TO_DEVICE",
2921
"FROM_DEVICE",
3022
};
3123

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-
};
46-
4724
int main(int argc, char **argv)
4825
{
4926
struct map_benchmark map;

0 commit comments

Comments
 (0)