Skip to contentSkip to conversation

dma-mapping: benchmark: Add support for dma_map_sg

PATCH Applied Qinxin Xia 3 participants 8 messages Feb 25 – Mar 7

Subsystems (2)
lore
Share & tools
lore

Qinxin Xia

author maintainer
#0 lore raw

v7 cover dma-mapping: benchmark: Add support for dma_map_sg

Modify the framework to adapt to more map modes, add benchmark support for dma_map_sg, and add support sg map mode in ioctl.

The result:

[root@localhost]# ./dma_map_benchmark -m 1 -g 8 -t 8 -s 30 -d 2
dma mapping benchmark(SG_MODE): threads:8 seconds:30 node:-1 dir:FROM_DEVICE granule/sg_nents: 8
average map latency(us):1.4 standard deviation:0.3
average unmap latency(us):1.3 standard deviation:0.3
[root@localhost]# ./dma_map_benchmark -m 0 -g 8 -t 8 -s 30 -d 2
dma mapping benchmark(SINGLE_MODE): threads:8 seconds:30 node:-1 dir:FROM_DEVICE granule/sg_nents: 8
average map latency(us):1.0 standard deviation:0.3
average unmap latency(us):1.3 standard deviation:0.5 

---
Changes since V6:
- Address the comments from Barry, update the comment of the granule.
- Link: https://lore.kernel.org/lkml/[email protected]/

Changes since V5:
- Address the comments from Barry, the incorrect and unnecessary 'prepare_data' judgment is deleted and renamed 'prepare_data()' to 'initialize_data()'. The mode and
other parameters in the output print are placed in the same print. In addition, the incorrect map_mode judgment in ioctrl and the wrong path in sg:prepare() does not release 'params' is fixed.
- Link: https://lore.kernel.org/all/[email protected]/

Changes since V4:
- Address the comments from Barry and Jonathan, irrelevant patches are deleted and the original cache processing logic is restored with add prepare_data().
- Link: https://lore.kernel.org/all/[email protected]/

Changes since V3:
- Address the comments from Barry, change mode to a more specific namespace.
- Link: https://lore.kernel.org/all/[email protected]/

Changes since V2:
- Address the comments from Barry and ALOK, some commit information and function input parameter names are modified to make them more accurate.
- Link: https://lore.kernel.org/all/[email protected]/

Changes since V1:
- Address the comments from Barry, added some comments and changed the unmap type to void.
- Link: https://lore.kernel.org/lkml/[email protected]/

Qinxin Xia (3):
dma-mapping: benchmark: modify the framework to adapt to more map
modes
dma-mapping: benchmark: add support for dma_map_sg tools/dma: Add dma_map_sg support

 include/uapi/linux/map_benchmark.h |  13 +-
 kernel/dma/map_benchmark.c         | 246 ++++++++++++++++++++++++++---
 tools/dma/dma_map_benchmark.c      |  23 ++-
 3 files changed, 254 insertions(+), 28 deletions(-)
Signature · 1 line
2.33.0
author maintainer
#1 lore raw

PATCH v7 1/3 dma-mapping: benchmark: modify the framework to adapt to more map modes

This patch adjusts the DMA map benchmark framework to make the DMA map benchmark framework more flexible and adaptable to other mapping modes in the future. By abstracting the framework into five interfaces:
prepare, unprepare, initialize_data, do_map, and do_unmap. The new map schema can be introduced more easily
without major modifications to the existing code structure.

---
 include/uapi/linux/map_benchmark.h |   8 +-
 kernel/dma/map_benchmark.c         | 131 ++++++++++++++++++++++++-----
 2 files changed, 115 insertions(+), 24 deletions(-)
include/uapi/linux/map_benchmark.h +7 -1
index c2d91088a40d..e076748f2120 100644
@@ -17,6 +17,11 @@
 #define DMA_MAP_TO_DEVICE       1
 #define DMA_MAP_FROM_DEVICE     2
 
+enum {
+	DMA_MAP_BENCH_SINGLE_MODE,
+	DMA_MAP_BENCH_MODE_MAX
+};
+
 struct map_benchmark {
 	__u64 avg_map_100ns; /* average map latency in 100ns */
 	__u64 map_stddev; /* standard deviation of map latency */
@@ -29,7 +34,8 @@ struct map_benchmark {
 	__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 */
+	__u8 map_mode;  /* the mode of dma map */
+	__u8 expansion[75]; /* For future use */
 };
 
 #endif /* _UAPI_DMA_BENCHMARK_H */
kernel/dma/map_benchmark.c +108 -23

174 lines not on this page · raw message

Signature · 1 line
2.33.0
author maintainer
#2 lore raw

PATCH v7 2/3 dma-mapping: benchmark: add support for dma_map_sg

In reply to Qinxin Xia

Support for dma scatter-gather mapping and is intended for testing mapping performance. It achieves by introducing the dma_sg_map_param structure and related functions, which enable the implementation of scatter-gather mapping preparation, mapping, and unmapping operations. Additionally, the dma_map_benchmark_ops array is updated to include operations for scatter-gather mapping. This commit aims to provide a wider range of mapping performance test to cater to different scenarios.

---
 include/uapi/linux/map_benchmark.h |   5 +-
 kernel/dma/map_benchmark.c         | 115 +++++++++++++++++++++++++++++
 2 files changed, 119 insertions(+), 1 deletion(-)
include/uapi/linux/map_benchmark.h +4 -1
index e076748f2120..4b17829a9f17 100644
@@ -19,6 +19,7 @@
 
 enum {
 	DMA_MAP_BENCH_SINGLE_MODE,
+	DMA_MAP_BENCH_SG_MODE,
 	DMA_MAP_BENCH_MODE_MAX
 };
 
@@ -33,7 +34,9 @@ struct map_benchmark {
 	__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 */
+	__u32 granule;  /* - SINGLE_MODE: number of pages mapped/unmapped per operation
+			 * - SG_MODE: number of scatterlist entries (each maps one page)
+			 */
 	__u8 map_mode;  /* the mode of dma map */
 	__u8 expansion[75]; /* For future use */
 };
kernel/dma/map_benchmark.c +115 -0

129 lines not on this page · raw message

Signature · 1 line
2.33.0
author maintainer
#3 lore raw

PATCH v7 3/3 tools/dma: Add dma_map_sg support

In reply to Qinxin Xia

Support for dma_map_sg, add option '-m' to distinguish mode.

i) Users can set option '-m' to select mode:
DMA_MAP_BENCH_SINGLE_MODE=0, DMA_MAP_BENCH_SG_MODE:=1 (The mode is also show in the test result).
ii) Users can set option '-g' to set sg_nents
(total count of entries in scatterlist)
the maximum number is 1024. Each of sg buf size is PAGE_SIZE. e.g
[root@localhost]# ./dma_map_benchmark -m 1 -g 8 -t 8 -s 30 -d 2 dma mapping mode: DMA_MAP_BENCH_SG_MODE
dma mapping benchmark: threads:8 seconds:30 node:-1 dir:FROM_DEVICE granule/sg_nents: 8
average map latency(us):1.4 standard deviation:0.3 average unmap latency(us):1.3 standard deviation:0.3 [root@localhost]# ./dma_map_benchmark -m 0 -g 8 -t 8 -s 30 -d 2 dma mapping mode: DMA_MAP_BENCH_SINGLE_MODE
dma mapping benchmark: threads:8 seconds:30 node:-1 dir:FROM_DEVICE granule/sg_nents: 8
average map latency(us):1.0 standard deviation:0.3 average unmap latency(us):1.3 standard deviation:0.5

---
 tools/dma/dma_map_benchmark.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
tools/dma/dma_map_benchmark.c +20 -3
index dd0ed528e6df..eab0ac611a23 100644
@@ -20,12 +20,19 @@ static char *directions[] = {
 	"FROM_DEVICE",
 };
 
+static char *mode[] = {
+	"SINGLE_MODE",
+	"SG_MODE",
+};
+
 int main(int argc, char **argv)
 {
 	struct map_benchmark map;
 	int fd, opt;
 	/* default single thread, run 20 seconds on NUMA_NO_NODE */
 	int threads = 1, seconds = 20, node = -1;
+	/* default single map mode */
+	int map_mode = DMA_MAP_BENCH_SINGLE_MODE;
 	/* default dma mask 32bit, bidirectional DMA */
 	int bits = 32, xdelay = 0, dir = DMA_MAP_BIDIRECTIONAL;
 	/* default granule 1 PAGESIZE */
@@ -33,7 +40,7 @@ int main(int argc, char **argv)
 
 	int cmd = DMA_MAP_BENCHMARK;
 
-	while ((opt = getopt(argc, argv, "t:s:n:b:d:x:g:")) != -1) {
+	while ((opt = getopt(argc, argv, "t:s:n:b:d:x:g:m:")) != -1) {
 		switch (opt) {
 		case 't':
 			threads = atoi(optarg);
@@ -56,11 +63,20 @@ int main(int argc, char **argv)
 		case 'g':
 			granule = atoi(optarg);
 			break;
+		case 'm':
+			map_mode = atoi(optarg);
+			break;
 		default:
 			return -1;
 		}
 	}
 
+	if (map_mode < 0 || map_mode >= DMA_MAP_BENCH_MODE_MAX) {
+		fprintf(stderr, "invalid map mode, SINGLE_MODE:%d, SG_MODE: %d\n",
+			DMA_MAP_BENCH_SINGLE_MODE, DMA_MAP_BENCH_SG_MODE);
+		exit(1);
+	}
+
 	if (threads <= 0 || threads > DMA_MAP_MAX_THREADS) {
 		fprintf(stderr, "invalid number of threads, must be in 1-%d\n",
 			DMA_MAP_MAX_THREADS);
@@ -110,14 +126,15 @@ int main(int argc, char **argv)
 	map.dma_dir = dir;
 	map.dma_trans_ns = xdelay;
 	map.granule = granule;
+	map.map_mode = map_mode;
 
 	if (ioctl(fd, cmd, &map)) {
 		perror("ioctl");
 		exit(1);
 	}
 
-	printf("dma mapping benchmark: threads:%d seconds:%d node:%d dir:%s granule: %d\n",
-			threads, seconds, node, directions[dir], granule);
+	printf("dma mapping benchmark(%s): threads:%d seconds:%d node:%d dir:%s granule:%d\n",
+			mode[map_mode], threads, seconds, node, directions[dir], granule);
 	printf("average map latency(us):%.1f standard deviation:%.1f\n",
 			map.avg_map_100ns/10.0, map.map_stddev/10.0);
 	printf("average unmap latency(us):%.1f standard deviation:%.1f\n",
Signature · 1 line
2.33.0
#4 lore raw
In reply to Qinxin Xia
Quoted 5 lines · Qinxin Xia

Modify the framework to adapt to more map modes, add benchmark support for dma_map_sg, and add support sg map mode in ioctl.

The result:

Quoted 9 lines
[root@localhost]# ./dma_map_benchmark -m 1 -g 8 -t 8 -s 30 -d 2
dma mapping benchmark(SG_MODE): threads:8 seconds:30 node:-1 dir:FROM_DEVICE granule/sg_nents: 8
average map latency(us):1.4 standard deviation:0.3
average unmap latency(us):1.3 standard deviation:0.3
[root@localhost]# ./dma_map_benchmark -m 0 -g 8 -t 8 -s 30 -d 2
dma mapping benchmark(SINGLE_MODE): threads:8 seconds:30 node:-1 dir:FROM_DEVICE granule/sg_nents: 8
average map latency(us):1.0 standard deviation:0.3
average unmap latency(us):1.3 standard deviation:0.5

+ Marek,

Hi Marek,

Would you be willing to pick up Qinxin's series into the dma-mapping tree? I think that would be helpful, at least for my "dma-mapping: arm64: support batched cache sync" series[1] and for potential further optimizations to dma_map_sg().

[1] https://lore.kernel.org/lkml/[email protected]/

Thanks
Barry

maintainer
#5 lore raw
Quoted 16 lines · Barry Song
Quoted 4 lines · Qinxin Xia

Modify the framework to adapt to more map modes, add benchmark support for dma_map_sg, and add support sg map mode in ioctl.

The result:

Quoted 9 lines
[root@localhost]# ./dma_map_benchmark -m 1 -g 8 -t 8 -s 30 -d 2
dma mapping benchmark(SG_MODE): threads:8 seconds:30 node:-1 dir:FROM_DEVICE granule/sg_nents: 8
average map latency(us):1.4 standard deviation:0.3
average unmap latency(us):1.3 standard deviation:0.3
[root@localhost]# ./dma_map_benchmark -m 0 -g 8 -t 8 -s 30 -d 2
dma mapping benchmark(SINGLE_MODE): threads:8 seconds:30 node:-1 dir:FROM_DEVICE granule/sg_nents: 8
average map latency(us):1.0 standard deviation:0.3
average unmap latency(us):1.3 standard deviation:0.5

+ Marek,

Quoted 8 lines

Hi Marek,

Would you be willing to pick up Qinxin's series into the dma-mapping tree? I think that would be helpful, at least for my "dma-mapping: arm64: support batched cache sync" series[1] and for potential further optimizations to dma_map_sg().

[1] https://lore.kernel.org/lkml/[email protected]/

I would be easier for me to track that work if I were on CC:, but I will take it.

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland
maintainer Applied
#6 lore raw
In reply to Qinxin Xia
Quoted 4 lines · Qinxin Xia

Modify the framework to adapt to more map modes, add benchmark support for dma_map_sg, and add support sg map mode in ioctl.

The result:

Quoted 8 lines
[root@localhost]# ./dma_map_benchmark -m 1 -g 8 -t 8 -s 30 -d 2
dma mapping benchmark(SG_MODE): threads:8 seconds:30 node:-1 dir:FROM_DEVICE granule/sg_nents: 8
average map latency(us):1.4 standard deviation:0.3
average unmap latency(us):1.3 standard deviation:0.3
[root@localhost]# ./dma_map_benchmark -m 0 -g 8 -t 8 -s 30 -d 2
dma mapping benchmark(SINGLE_MODE): threads:8 seconds:30 node:-1 dir:FROM_DEVICE granule/sg_nents: 8
average map latency(us):1.0 standard deviation:0.3
average unmap latency(us):1.3 standard deviation:0.5

Applied to dma-mapping-next. Thanks! Next time please CC: me directly.

Quoted 36 lines

---
Changes since V6:
- Address the comments from Barry, update the comment of the granule.
- Link: https://lore.kernel.org/lkml/[email protected]/

Changes since V5:
- Address the comments from Barry, the incorrect and unnecessary 'prepare_data' judgment is deleted and renamed 'prepare_data()' to 'initialize_data()'. The mode and
other parameters in the output print are placed in the same print. In addition, the incorrect map_mode judgment in ioctrl and the wrong path in sg:prepare() does not release 'params' is fixed.
- Link: https://lore.kernel.org/all/[email protected]/

Changes since V4:
- Address the comments from Barry and Jonathan, irrelevant patches are deleted and the original cache processing logic is restored with add prepare_data().
- Link: https://lore.kernel.org/all/[email protected]/

Changes since V3:
- Address the comments from Barry, change mode to a more specific namespace.
- Link: https://lore.kernel.org/all/[email protected]/

Changes since V2:
- Address the comments from Barry and ALOK, some commit information and function input parameter names are modified to make them more accurate.
- Link: https://lore.kernel.org/all/[email protected]/

Changes since V1:
- Address the comments from Barry, added some comments and changed the unmap type to void.
- Link: https://lore.kernel.org/lkml/[email protected]/

Qinxin Xia (3):
dma-mapping: benchmark: modify the framework to adapt to more map
modes
dma-mapping: benchmark: add support for dma_map_sg tools/dma: Add dma_map_sg support

Quoted 5 lines
  include/uapi/linux/map_benchmark.h |  13 +-
  kernel/dma/map_benchmark.c         | 246 ++++++++++++++++++++++++++---
  tools/dma/dma_map_benchmark.c      |  23 ++-
  3 files changed, 254 insertions(+), 28 deletions(-)

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland
author maintainer
#7 lore raw
Quoted 8 lines · Marek Szyprowski
Quoted 7 lines

dma mapping benchmark(SG_MODE): threads:8 seconds:30 node:-1 dir:FROM_DEVICE granule/sg_nents: 8 average map latency(us):1.4 standard deviation:0.3
average unmap latency(us):1.3 standard deviation:0.3

[root@localhost]# ./dma_map_benchmark -m 0 -g 8 -t 8 -s 30 -d 2
dma mapping benchmark(SINGLE_MODE): threads:8 seconds:30 node:-1 dir:FROM_DEVICE granule/sg_nents: 8
average map latency(us):1.0 standard deviation:0.3
average unmap latency(us):1.3 standard deviation:0.5

Applied to dma-mapping-next. Thanks! Next time please CC: me directly.

Thank you for applying the patch. I apologize for not CC-ing you directly earlier; I'll make sure to do so next time.:-)

Signature · 2 lines
Thanks,
Qinxin