Skip to contentSkip to conversation

dma-mapping: benchmark: Don't starve others when doing the test

PATCH Superseded Yicong Yang 2 participants 5 messages Jun 19, 2024 – Jun 20, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dma-mapping: benchmark: Don't starve others when doing the test

From: Yicong Yang <[email protected]>

The test thread will start N benchmark kthreads and then schedule out until the test time finished and notify the benchmark kthreads to stop. The benchmark kthreads will keep running until notified to stop. There's a problem with current implementation when the benchmark kthreads number is equal to the CPUs on a non-preemptible kernel:
since the scheduler will balance the kthreads across the CPUs and when the test time's out the test thread won't get a chance to be scheduled on any CPU then cannot notify the benchmark kthreads to stop.

This can be easily reproduced on a VM (simulated with 16 CPUs) with PREEMPT_VOLUNTARY:

estuary:/mnt$ ./dma_map_benchmark -t 16 -s 1
 rcu: INFO: rcu_sched self-detected stall on CPU
 rcu:     10-...!: (5221 ticks this GP) idle=ed24/1/0x4000000000000000 softirq=142/142 fqs=0
 rcu:     (t=5254 jiffies g=-559 q=45 ncpus=16)
 rcu: rcu_sched kthread starved for 5255 jiffies! g-559 f0x0 RCU_GP_WAIT_FQS(5) ->state=0x0 ->cpu=12
 rcu:     Unless rcu_sched kthread gets sufficient CPU time, OOM is now expected behavior.
 rcu: RCU grace-period kthread stack dump:
 task:rcu_sched       state:R  running task     stack:0     pid:16    tgid:16    ppid:2      flags:0x00000008
 Call trace
  __switch_to+0xec/0x138
  __schedule+0x2f8/0x1080
  schedule+0x30/0x130
  schedule_timeout+0xa0/0x188
  rcu_gp_fqs_loop+0x128/0x528
  rcu_gp_kthread+0x1c8/0x208
  kthread+0xec/0xf8
  ret_from_fork+0x10/0x20
 Sending NMI from CPU 10 to CPUs 0:
 NMI backtrace for cpu 0
 CPU: 0 PID: 332 Comm: dma-map-benchma Not tainted 6.10.0-rc1-vanilla-LSE #8
 Hardware name: QEMU KVM Virtual Machine, BIOS 0.0.0 02/06/2015
 pstate: 20400005 (nzCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
 pc : arm_smmu_cmdq_issue_cmdlist+0x218/0x730
 lr : arm_smmu_cmdq_issue_cmdlist+0x488/0x730
 sp : ffff80008748b630
 x29: ffff80008748b630 x28: 0000000000000000 x27: ffff80008748b780
 x26: 0000000000000000 x25: 000000000000bc70 x24: 000000000001bc70
 x23: ffff0000c12af080 x22: 0000000000010000 x21: 000000000000ffff
 x20: ffff80008748b700 x19: ffff0000c12af0c0 x18: 0000000000010000
 x17: 0000000000000001 x16: 0000000000000040 x15: ffffffffffffffff
 x14: 0001ffffffffffff x13: 000000000000ffff x12: 00000000000002f1
 x11: 000000000001ffff x10: 0000000000000031 x9 : ffff800080b6b0b8
 x8 : ffff0000c2a48000 x7 : 000000000001bc71 x6 : 0001800000000000
 x5 : 00000000000002f1 x4 : 01ffffffffffffff x3 : 000000000009aaf1
 x2 : 0000000000000018 x1 : 000000000000000f x0 : ffff0000c12af18c
 Call trace:
  arm_smmu_cmdq_issue_cmdlist+0x218/0x730
  __arm_smmu_tlb_inv_range+0xe0/0x1a8
  arm_smmu_iotlb_sync+0xc0/0x128
  __iommu_dma_unmap+0x248/0x320
  iommu_dma_unmap_page+0x5c/0xe8
  dma_unmap_page_attrs+0x38/0x1d0
  map_benchmark_thread+0x118/0x2c0
  kthread+0xec/0xf8
  ret_from_fork+0x10/0x20

Solve this by adding scheduling point in the kthread loop to avoid starving others. This won't affect the test results since we only care about the time consumed by the dma_{map, unmap}_single().

---
 kernel/dma/map_benchmark.c | 9 +++++++++
 1 file changed, 9 insertions(+)
kernel/dma/map_benchmark.c +9 -0
index 02205ab53b7e..2da9326c094c 100644
@@ -89,6 +89,15 @@ static int map_benchmark_thread(void *data)
 		atomic64_add(map_sq, &map->sum_sq_map);
 		atomic64_add(unmap_sq, &map->sum_sq_unmap);
 		atomic64_inc(&map->loops);
+
+		/*
+		 * We may test for a long time so periodically yield the
+		 * CPU to avoid starve the others, especially on the
+		 * non-preemptible kernel. This won't affect the test
+		 * results since we only care about the time consumed by
+		 * the dma_{map, unmap}_single().
+		 */
+		cond_resched();
 	}
 
 out:
Signature · 1 line
2.24.0
maintainer
#1 lore raw
Quoted 77 lines · Yicong Yang

From: Yicong Yang <[email protected]>

The test thread will start N benchmark kthreads and then schedule out until the test time finished and notify the benchmark kthreads to stop. The benchmark kthreads will keep running until notified to stop. There's a problem with current implementation when the benchmark kthreads number is equal to the CPUs on a non-preemptible kernel:
since the scheduler will balance the kthreads across the CPUs and when the test time's out the test thread won't get a chance to be scheduled on any CPU then cannot notify the benchmark kthreads to stop.

This can be easily reproduced on a VM (simulated with 16 CPUs) with PREEMPT_VOLUNTARY:

estuary:/mnt$ ./dma_map_benchmark -t 16 -s 1
 rcu: INFO: rcu_sched self-detected stall on CPU
 rcu:     10-...!: (5221 ticks this GP) idle=ed24/1/0x4000000000000000 softirq=142/142 fqs=0
 rcu:     (t=5254 jiffies g=-559 q=45 ncpus=16)
 rcu: rcu_sched kthread starved for 5255 jiffies! g-559 f0x0 RCU_GP_WAIT_FQS(5) ->state=0x0 ->cpu=12
 rcu:     Unless rcu_sched kthread gets sufficient CPU time, OOM is now expected behavior.
 rcu: RCU grace-period kthread stack dump:
 task:rcu_sched       state:R  running task     stack:0     pid:16    tgid:16    ppid:2      flags:0x00000008
 Call trace
  __switch_to+0xec/0x138
  __schedule+0x2f8/0x1080
  schedule+0x30/0x130
  schedule_timeout+0xa0/0x188
  rcu_gp_fqs_loop+0x128/0x528
  rcu_gp_kthread+0x1c8/0x208
  kthread+0xec/0xf8
  ret_from_fork+0x10/0x20
 Sending NMI from CPU 10 to CPUs 0:
 NMI backtrace for cpu 0
 CPU: 0 PID: 332 Comm: dma-map-benchma Not tainted 6.10.0-rc1-vanilla-LSE #8
 Hardware name: QEMU KVM Virtual Machine, BIOS 0.0.0 02/06/2015
 pstate: 20400005 (nzCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
 pc : arm_smmu_cmdq_issue_cmdlist+0x218/0x730
 lr : arm_smmu_cmdq_issue_cmdlist+0x488/0x730
 sp : ffff80008748b630
 x29: ffff80008748b630 x28: 0000000000000000 x27: ffff80008748b780
 x26: 0000000000000000 x25: 000000000000bc70 x24: 000000000001bc70
 x23: ffff0000c12af080 x22: 0000000000010000 x21: 000000000000ffff
 x20: ffff80008748b700 x19: ffff0000c12af0c0 x18: 0000000000010000
 x17: 0000000000000001 x16: 0000000000000040 x15: ffffffffffffffff
 x14: 0001ffffffffffff x13: 000000000000ffff x12: 00000000000002f1
 x11: 000000000001ffff x10: 0000000000000031 x9 : ffff800080b6b0b8
 x8 : ffff0000c2a48000 x7 : 000000000001bc71 x6 : 0001800000000000
 x5 : 00000000000002f1 x4 : 01ffffffffffffff x3 : 000000000009aaf1
 x2 : 0000000000000018 x1 : 000000000000000f x0 : ffff0000c12af18c
 Call trace:
  arm_smmu_cmdq_issue_cmdlist+0x218/0x730
  __arm_smmu_tlb_inv_range+0xe0/0x1a8
  arm_smmu_iotlb_sync+0xc0/0x128
  __iommu_dma_unmap+0x248/0x320
  iommu_dma_unmap_page+0x5c/0xe8
  dma_unmap_page_attrs+0x38/0x1d0
  map_benchmark_thread+0x118/0x2c0
  kthread+0xec/0xf8
  ret_from_fork+0x10/0x20

Solve this by adding scheduling point in the kthread loop to avoid starving others. This won't affect the test results since we only care about the time consumed by the dma_{map, unmap}_single().

---
 kernel/dma/map_benchmark.c | 9 +++++++++
 1 file changed, 9 insertions(+)
kernel/dma/map_benchmark.c +0 -0
index 02205ab53b7e..2da9326c094c 100644
@@ -89,6 +89,15 @@ static int map_benchmark_thread(void *data)
                atomic64_add(map_sq, &map->sum_sq_map);
                atomic64_add(unmap_sq, &map->sum_sq_unmap);

kernel/dma/map_benchmark.c static int map_benchmark_thread(void *data) · line 100

Quoted 10 lines
kernel/dma/map_benchmark.c +9 -0
                atomic64_inc(&map->loops);
+
+               /*
+                * We may test for a long time so periodically yield the
+                * CPU to avoid starve the others, especially on the
+                * non-preemptible kernel. This won't affect the test
+                * results since we only care about the time consumed by
+                * the dma_{map, unmap}_single().
+                */
+               cond_resched();

We don't care about the time outside of dma_{map, unmap}_single(). However, we do care about the concurrency. We use ndelay(map->bparam.dma_trans_ns); to simulate DMA transmission. Your code entirely changes the concurrency.

Quoted 6 lines
kernel/dma/map_benchmark.c +0 -1
        }
 
 out:
--

2.24.0

Thanks
Barry

#2 lore raw
Quoted 84 lines · Barry Song
Quoted 83 lines · Yicong Yang

From: Yicong Yang <[email protected]>

The test thread will start N benchmark kthreads and then schedule out until the test time finished and notify the benchmark kthreads to stop. The benchmark kthreads will keep running until notified to stop. There's a problem with current implementation when the benchmark kthreads number is equal to the CPUs on a non-preemptible kernel:
since the scheduler will balance the kthreads across the CPUs and when the test time's out the test thread won't get a chance to be scheduled on any CPU then cannot notify the benchmark kthreads to stop.

This can be easily reproduced on a VM (simulated with 16 CPUs) with PREEMPT_VOLUNTARY:

estuary:/mnt$ ./dma_map_benchmark -t 16 -s 1
 rcu: INFO: rcu_sched self-detected stall on CPU
 rcu:     10-...!: (5221 ticks this GP) idle=ed24/1/0x4000000000000000 softirq=142/142 fqs=0
 rcu:     (t=5254 jiffies g=-559 q=45 ncpus=16)
 rcu: rcu_sched kthread starved for 5255 jiffies! g-559 f0x0 RCU_GP_WAIT_FQS(5) ->state=0x0 ->cpu=12
 rcu:     Unless rcu_sched kthread gets sufficient CPU time, OOM is now expected behavior.
 rcu: RCU grace-period kthread stack dump:
 task:rcu_sched       state:R  running task     stack:0     pid:16    tgid:16    ppid:2      flags:0x00000008
 Call trace
  __switch_to+0xec/0x138
  __schedule+0x2f8/0x1080
  schedule+0x30/0x130
  schedule_timeout+0xa0/0x188
  rcu_gp_fqs_loop+0x128/0x528
  rcu_gp_kthread+0x1c8/0x208
  kthread+0xec/0xf8
  ret_from_fork+0x10/0x20
 Sending NMI from CPU 10 to CPUs 0:
 NMI backtrace for cpu 0
 CPU: 0 PID: 332 Comm: dma-map-benchma Not tainted 6.10.0-rc1-vanilla-LSE #8
 Hardware name: QEMU KVM Virtual Machine, BIOS 0.0.0 02/06/2015
 pstate: 20400005 (nzCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
 pc : arm_smmu_cmdq_issue_cmdlist+0x218/0x730
 lr : arm_smmu_cmdq_issue_cmdlist+0x488/0x730
 sp : ffff80008748b630
 x29: ffff80008748b630 x28: 0000000000000000 x27: ffff80008748b780
 x26: 0000000000000000 x25: 000000000000bc70 x24: 000000000001bc70
 x23: ffff0000c12af080 x22: 0000000000010000 x21: 000000000000ffff
 x20: ffff80008748b700 x19: ffff0000c12af0c0 x18: 0000000000010000
 x17: 0000000000000001 x16: 0000000000000040 x15: ffffffffffffffff
 x14: 0001ffffffffffff x13: 000000000000ffff x12: 00000000000002f1
 x11: 000000000001ffff x10: 0000000000000031 x9 : ffff800080b6b0b8
 x8 : ffff0000c2a48000 x7 : 000000000001bc71 x6 : 0001800000000000
 x5 : 00000000000002f1 x4 : 01ffffffffffffff x3 : 000000000009aaf1
 x2 : 0000000000000018 x1 : 000000000000000f x0 : ffff0000c12af18c
 Call trace:
  arm_smmu_cmdq_issue_cmdlist+0x218/0x730
  __arm_smmu_tlb_inv_range+0xe0/0x1a8
  arm_smmu_iotlb_sync+0xc0/0x128
  __iommu_dma_unmap+0x248/0x320
  iommu_dma_unmap_page+0x5c/0xe8
  dma_unmap_page_attrs+0x38/0x1d0
  map_benchmark_thread+0x118/0x2c0
  kthread+0xec/0xf8
  ret_from_fork+0x10/0x20

Solve this by adding scheduling point in the kthread loop to avoid starving others. This won't affect the test results since we only care about the time consumed by the dma_{map, unmap}_single().

---
 kernel/dma/map_benchmark.c | 9 +++++++++
 1 file changed, 9 insertions(+)
kernel/dma/map_benchmark.c +5 -0
index 02205ab53b7e..2da9326c094c 100644
@@ -89,6 +89,15 @@ static int map_benchmark_thread(void *data)
                atomic64_add(map_sq, &map->sum_sq_map);
                atomic64_add(unmap_sq, &map->sum_sq_unmap);
                atomic64_inc(&map->loops);
+
+               /*
+                * We may test for a long time so periodically yield the
+                * CPU to avoid starve the others, especially on the
+                * non-preemptible kernel. This won't affect the test
Quoted 9 lines

kernel/dma/map_benchmark.c static int map_benchmark_thread(void *data) · line 100

Quoted 4 lines
kernel/dma/map_benchmark.c +4 -0
+                * results since we only care about the time consumed by
+                * the dma_{map, unmap}_single().
+                */
+               cond_resched();

We don't care about the time outside of dma_{map, unmap}_single(). However, we do care about the concurrency. We use ndelay(map->bparam.dma_trans_ns); to simulate DMA transmission. Your code entirely changes the concurrency.

I imagine 2 cases here:
1) If only us running on the CPU, cond_resched() will not make us schedule out.
2) Otherwise we'll be managed by the scheduler with other tasks. This will be more realistic in a system.

For testing SMMU the case 1) is more general for us. But I don't think in both case the cocurrency will be broke, the test kthreads still running concurrenctly. But they need to share the cpu time with other threads if we have some other loads in the system.

The initial idea of this patch is to fix the hangup in the case that the test kthreads number is greater or equal to the CPU numaber. In such case the test kthreads will be running infinitely since the thread responsible to notify the end of the test cannot be scheduled in a non-preemptible kernel. This is described in the commit message.

Thanks.

maintainer Acked-by
#3 lore raw
Quoted 101 lines · Yicong Yang
Quoted 84 lines · Barry Song
Quoted 83 lines · Yicong Yang

From: Yicong Yang <[email protected]>

The test thread will start N benchmark kthreads and then schedule out until the test time finished and notify the benchmark kthreads to stop. The benchmark kthreads will keep running until notified to stop. There's a problem with current implementation when the benchmark kthreads number is equal to the CPUs on a non-preemptible kernel:
since the scheduler will balance the kthreads across the CPUs and when the test time's out the test thread won't get a chance to be scheduled on any CPU then cannot notify the benchmark kthreads to stop.

This can be easily reproduced on a VM (simulated with 16 CPUs) with PREEMPT_VOLUNTARY:

estuary:/mnt$ ./dma_map_benchmark -t 16 -s 1
 rcu: INFO: rcu_sched self-detected stall on CPU
 rcu:     10-...!: (5221 ticks this GP) idle=ed24/1/0x4000000000000000 softirq=142/142 fqs=0
 rcu:     (t=5254 jiffies g=-559 q=45 ncpus=16)
 rcu: rcu_sched kthread starved for 5255 jiffies! g-559 f0x0 RCU_GP_WAIT_FQS(5) ->state=0x0 ->cpu=12
 rcu:     Unless rcu_sched kthread gets sufficient CPU time, OOM is now expected behavior.
 rcu: RCU grace-period kthread stack dump:
 task:rcu_sched       state:R  running task     stack:0     pid:16    tgid:16    ppid:2      flags:0x00000008
 Call trace
  __switch_to+0xec/0x138
  __schedule+0x2f8/0x1080
  schedule+0x30/0x130
  schedule_timeout+0xa0/0x188
  rcu_gp_fqs_loop+0x128/0x528
  rcu_gp_kthread+0x1c8/0x208
  kthread+0xec/0xf8
  ret_from_fork+0x10/0x20
 Sending NMI from CPU 10 to CPUs 0:
 NMI backtrace for cpu 0
 CPU: 0 PID: 332 Comm: dma-map-benchma Not tainted 6.10.0-rc1-vanilla-LSE #8
 Hardware name: QEMU KVM Virtual Machine, BIOS 0.0.0 02/06/2015
 pstate: 20400005 (nzCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
 pc : arm_smmu_cmdq_issue_cmdlist+0x218/0x730
 lr : arm_smmu_cmdq_issue_cmdlist+0x488/0x730
 sp : ffff80008748b630
 x29: ffff80008748b630 x28: 0000000000000000 x27: ffff80008748b780
 x26: 0000000000000000 x25: 000000000000bc70 x24: 000000000001bc70
 x23: ffff0000c12af080 x22: 0000000000010000 x21: 000000000000ffff
 x20: ffff80008748b700 x19: ffff0000c12af0c0 x18: 0000000000010000
 x17: 0000000000000001 x16: 0000000000000040 x15: ffffffffffffffff
 x14: 0001ffffffffffff x13: 000000000000ffff x12: 00000000000002f1
 x11: 000000000001ffff x10: 0000000000000031 x9 : ffff800080b6b0b8
 x8 : ffff0000c2a48000 x7 : 000000000001bc71 x6 : 0001800000000000
 x5 : 00000000000002f1 x4 : 01ffffffffffffff x3 : 000000000009aaf1
 x2 : 0000000000000018 x1 : 000000000000000f x0 : ffff0000c12af18c
 Call trace:
  arm_smmu_cmdq_issue_cmdlist+0x218/0x730
  __arm_smmu_tlb_inv_range+0xe0/0x1a8
  arm_smmu_iotlb_sync+0xc0/0x128
  __iommu_dma_unmap+0x248/0x320
  iommu_dma_unmap_page+0x5c/0xe8
  dma_unmap_page_attrs+0x38/0x1d0
  map_benchmark_thread+0x118/0x2c0
  kthread+0xec/0xf8
  ret_from_fork+0x10/0x20

Solve this by adding scheduling point in the kthread loop to avoid starving others. This won't affect the test results since we only care about the time consumed by the dma_{map, unmap}_single().

---
 kernel/dma/map_benchmark.c | 9 +++++++++
 1 file changed, 9 insertions(+)
kernel/dma/map_benchmark.c +5 -0
index 02205ab53b7e..2da9326c094c 100644
@@ -89,6 +89,15 @@ static int map_benchmark_thread(void *data)
                atomic64_add(map_sq, &map->sum_sq_map);
                atomic64_add(unmap_sq, &map->sum_sq_unmap);
                atomic64_inc(&map->loops);
+
+               /*
+                * We may test for a long time so periodically yield the
+                * CPU to avoid starve the others, especially on the
+                * non-preemptible kernel. This won't affect the test
Quoted 9 lines

kernel/dma/map_benchmark.c static int map_benchmark_thread(void *data) · line 100

Quoted 4 lines
kernel/dma/map_benchmark.c +4 -0
+                * results since we only care about the time consumed by
+                * the dma_{map, unmap}_single().
+                */
+               cond_resched();

We don't care about the time outside of dma_{map, unmap}_single(). However, we do care about the concurrency. We use ndelay(map->bparam.dma_trans_ns); to simulate DMA transmission. Your code entirely changes the concurrency.

I imagine 2 cases here:
1) If only us running on the CPU, cond_resched() will not make us schedule out.
2) Otherwise we'll be managed by the scheduler with other tasks. This will be more realistic in a system.

Quoted 8 lines

For testing SMMU the case 1) is more general for us. But I don't think in both case the cocurrency will be broke, the test kthreads still running concurrenctly. But they need to share the cpu time with other threads if we have some other loads in the system.

The initial idea of this patch is to fix the hangup in the case that the test kthreads number is greater or equal to the CPU numaber. In such case the test kthreads will be running infinitely since the thread responsible to notify the end of the test cannot be scheduled in a non-preemptible kernel. This is described in the commit message.

I guess you mean this,

        for (i = 0; i < threads; i++) {
                ret = kthread_stop(tsk[i]);
                if (ret)
                        goto out;
        }

That's what I missed. Sorry about that.

My point is that this is just a test program, not a real workload. Therefore, we don't want it to be
too complex. Allowing others to preempt it changes the degree of concurrency, as we are
intentionally slowing down the DMA map/unmap requests.

However, I agree with your point that we need to ensure the program functions correctly
and does not crash.
As long as we run the benchmark on an idle system, it should be fine.

Please correct the comment "This won't affect the test results since we only care about
the time consumed by the dma_{map, unmap}_single()"which is actually misleading. Alternatively, explain the real problem and note that this benchmark is intended to run
on an idle system.

And w/ that,

Quoted 1 line

Thanks
Barry

#4 lore raw
Quoted 113 lines · Barry Song
Quoted 101 lines · Yicong Yang
Quoted 84 lines · Barry Song
Quoted 83 lines · Yicong Yang

From: Yicong Yang <[email protected]>

The test thread will start N benchmark kthreads and then schedule out until the test time finished and notify the benchmark kthreads to stop. The benchmark kthreads will keep running until notified to stop. There's a problem with current implementation when the benchmark kthreads number is equal to the CPUs on a non-preemptible kernel:
since the scheduler will balance the kthreads across the CPUs and when the test time's out the test thread won't get a chance to be scheduled on any CPU then cannot notify the benchmark kthreads to stop.

This can be easily reproduced on a VM (simulated with 16 CPUs) with PREEMPT_VOLUNTARY:

estuary:/mnt$ ./dma_map_benchmark -t 16 -s 1
 rcu: INFO: rcu_sched self-detected stall on CPU
 rcu:     10-...!: (5221 ticks this GP) idle=ed24/1/0x4000000000000000 softirq=142/142 fqs=0
 rcu:     (t=5254 jiffies g=-559 q=45 ncpus=16)
 rcu: rcu_sched kthread starved for 5255 jiffies! g-559 f0x0 RCU_GP_WAIT_FQS(5) ->state=0x0 ->cpu=12
 rcu:     Unless rcu_sched kthread gets sufficient CPU time, OOM is now expected behavior.
 rcu: RCU grace-period kthread stack dump:
 task:rcu_sched       state:R  running task     stack:0     pid:16    tgid:16    ppid:2      flags:0x00000008
 Call trace
  __switch_to+0xec/0x138
  __schedule+0x2f8/0x1080
  schedule+0x30/0x130
  schedule_timeout+0xa0/0x188
  rcu_gp_fqs_loop+0x128/0x528
  rcu_gp_kthread+0x1c8/0x208
  kthread+0xec/0xf8
  ret_from_fork+0x10/0x20
 Sending NMI from CPU 10 to CPUs 0:
 NMI backtrace for cpu 0
 CPU: 0 PID: 332 Comm: dma-map-benchma Not tainted 6.10.0-rc1-vanilla-LSE #8
 Hardware name: QEMU KVM Virtual Machine, BIOS 0.0.0 02/06/2015
 pstate: 20400005 (nzCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
 pc : arm_smmu_cmdq_issue_cmdlist+0x218/0x730
 lr : arm_smmu_cmdq_issue_cmdlist+0x488/0x730
 sp : ffff80008748b630
 x29: ffff80008748b630 x28: 0000000000000000 x27: ffff80008748b780
 x26: 0000000000000000 x25: 000000000000bc70 x24: 000000000001bc70
 x23: ffff0000c12af080 x22: 0000000000010000 x21: 000000000000ffff
 x20: ffff80008748b700 x19: ffff0000c12af0c0 x18: 0000000000010000
 x17: 0000000000000001 x16: 0000000000000040 x15: ffffffffffffffff
 x14: 0001ffffffffffff x13: 000000000000ffff x12: 00000000000002f1
 x11: 000000000001ffff x10: 0000000000000031 x9 : ffff800080b6b0b8
 x8 : ffff0000c2a48000 x7 : 000000000001bc71 x6 : 0001800000000000
 x5 : 00000000000002f1 x4 : 01ffffffffffffff x3 : 000000000009aaf1
 x2 : 0000000000000018 x1 : 000000000000000f x0 : ffff0000c12af18c
 Call trace:
  arm_smmu_cmdq_issue_cmdlist+0x218/0x730
  __arm_smmu_tlb_inv_range+0xe0/0x1a8
  arm_smmu_iotlb_sync+0xc0/0x128
  __iommu_dma_unmap+0x248/0x320
  iommu_dma_unmap_page+0x5c/0xe8
  dma_unmap_page_attrs+0x38/0x1d0
  map_benchmark_thread+0x118/0x2c0
  kthread+0xec/0xf8
  ret_from_fork+0x10/0x20

Solve this by adding scheduling point in the kthread loop to avoid starving others. This won't affect the test results since we only care about the time consumed by the dma_{map, unmap}_single().

---
 kernel/dma/map_benchmark.c | 9 +++++++++
 1 file changed, 9 insertions(+)
kernel/dma/map_benchmark.c +5 -0
index 02205ab53b7e..2da9326c094c 100644
@@ -89,6 +89,15 @@ static int map_benchmark_thread(void *data)
                atomic64_add(map_sq, &map->sum_sq_map);
                atomic64_add(unmap_sq, &map->sum_sq_unmap);
                atomic64_inc(&map->loops);
+
+               /*
+                * We may test for a long time so periodically yield the
+                * CPU to avoid starve the others, especially on the
+                * non-preemptible kernel. This won't affect the test
Quoted 9 lines

kernel/dma/map_benchmark.c static int map_benchmark_thread(void *data) · line 100

Quoted 4 lines
kernel/dma/map_benchmark.c +4 -0
+                * results since we only care about the time consumed by
+                * the dma_{map, unmap}_single().
+                */
+               cond_resched();

We don't care about the time outside of dma_{map, unmap}_single(). However, we do care about the concurrency. We use ndelay(map->bparam.dma_trans_ns); to simulate DMA transmission. Your code entirely changes the concurrency.

I imagine 2 cases here:
1) If only us running on the CPU, cond_resched() will not make us schedule out.
2) Otherwise we'll be managed by the scheduler with other tasks. This will be more realistic in a system.

Quoted 8 lines

For testing SMMU the case 1) is more general for us. But I don't think in both case the cocurrency will be broke, the test kthreads still running concurrenctly. But they need to share the cpu time with other threads if we have some other loads in the system.

The initial idea of this patch is to fix the hangup in the case that the test kthreads number is greater or equal to the CPU numaber. In such case the test kthreads will be running infinitely since the thread responsible to notify the end of the test cannot be scheduled in a non-preemptible kernel. This is described in the commit message.

I guess you mean this,

Quoted 8 lines
        for (i = 0; i < threads; i++) {
                ret = kthread_stop(tsk[i]);
                if (ret)
                        goto out;
        }

That's what I missed. Sorry about that.

yes problem takes here. In the issue case this won't be executed.

Quoted 11 lines

My point is that this is just a test program, not a real workload. Therefore, we don't want it to be
too complex. Allowing others to preempt it changes the degree of concurrency, as we are
intentionally slowing down the DMA map/unmap requests.

However, I agree with your point that we need to ensure the program functions correctly
and does not crash.
As long as we run the benchmark on an idle system, it should be fine.

Quoted 7 lines

Please correct the comment "This won't affect the test results since we only care about
the time consumed by the dma_{map, unmap}_single()"which is actually misleading. Alternatively, explain the real problem and note that this benchmark is intended to run
on an idle system.

Will update the comments here to get this fixed and mention the restriction.

Quoted 4 lines

And w/ that,

Thanks.