Skip to contentSkip to conversation

dmaengine: dmatest: Add optional per-stage latency profiling

PATCH New Baineng Shou 2 participants 2 messages Dec 1

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dmaengine: dmatest: Add optional per-stage latency profiling

The aggregate dmatest throughput does not show whether time is spent in DMA mapping, descriptor preparation, execution or completion delivery. This makes it difficult to investigate a low copy rate without adding ad-hoc instrumentation to a test client or a controller driver.

Add a profile parameter to accumulate six consecutive latency intervals per test thread: map, prep, submit, issue-to-callback, callback-to-wait- return, and status-check/unmap. Report the average latency, elapsed time and percentage for each interval after the existing summary, together with the minimum, average and maximum map-to-unmap latency. Derive the effective and execution rates from aggregate bytes and aggregate time.

Publish the callback timestamp before the completion flag using release and acquire ordering. Include issue_pending() in the issue-to-callback interval so that a callback running before the issue call returns does not create overlapping intervals. Stop accumulating samples after the first transfer error, verification failure or invalid timestamp sequence to avoid attributing late callbacks to subsequent samples. Leave the existing test flow and error handling in place.

Keep profiling disabled by default and print only per-thread totals at test completion. Preserve the existing summary and verbose output, and report profiling as unavailable in polled mode. Document the boundaries, the accounting rules and the added measurement overhead. In particular, execution latency includes queueing, interrupt and driver completion processing; neither rate represents hardware-only or whole-run bandwidth.
---
Validation:
- x86-64, GCC 12: minimal vmlinux and modules build, DMATEST=m, W=1.
- i386, GCC 12: dmatest.o build, DMATEST=y, W=1.
- arm64, Clang 19: dmatest.o cross-build, DMATEST=y, W=1.
- Host tests exercise the accounting helpers extracted from this source, with UBSan, including invalid timestamps and early-callback ordering. These tests do not exercise kernel callback concurrency.
- Complete dmatest.rst parsed by Docutils; no full Sphinx build.
- checkpatch --strict --no-signoff and git diff --check.

A downstream port ran on ASR8861 with 1, 2, 4, 8 and 10 channels and 1 MiB copies. It completed 60 verified transfers and 30,000 transfers with verification disabled without reported failures. That port has different error handling and is not a runtime test of this exact patch. This mainline version has not been run on DMA hardware; controlled profile-on/off overhead and late-callback fault injection remain untested.

AI assistance: OpenAI Codex assisted with the implementation, documentation, commit message and validation. The request was to retain the existing summary and DMA controller drivers, add optional per-stage latency accounting in dmatest, and report per-thread totals only when testing finishes. The human submitter must review and certify the DCO.

 .../driver-api/dmaengine/dmatest.rst          |  82 +++++++++
 drivers/dma/dmatest.c                         | 167 +++++++++++++++++-
 2 files changed, 247 insertions(+), 2 deletions(-)
Documentation/driver-api/dmaengine/dmatest.rst +82 -0
index e2a63cefd783..677101bf74b1 100644
@@ -230,3 +230,85 @@ Example::
 
 Channels allocated by previous test runs are automatically freed when a new
 channel is requested after completing a successful test run.
+
+Part 6 - Optional latency profiling
+=====================================
+
+Set ``profile=1`` before selecting channels to collect per-thread latency
+statistics. Profiling is disabled by default and does not require changes to
+the DMA controller driver. For example::
+
+    % modprobe dmatest
+    % echo 1 > /sys/module/dmatest/parameters/profile
+    % echo 100 > /sys/module/dmatest/parameters/iterations
+    % echo 0 > /sys/module/dmatest/parameters/verbose
+    % echo dma0chan0 > /sys/module/dmatest/parameters/channel
+    % echo 1 > /sys/module/dmatest/parameters/run
+    % cat /sys/module/dmatest/parameters/wait
+
+Choose an available channel on the system under test. The existing summary,
+verification, error handling and verbose output are unchanged. Profiling adds
+an aggregate report when each thread finishes; it does not log individual
+samples. Leave verbose logging and dynamic debug disabled when measuring
+latency. Polled tests run normally but report profiling as unavailable, since
+they do not use a completion callback.
+
+Seven monotonic timestamps delimit six consecutive stages:
+
+.. list-table:: Profiling boundaries
+   :header-rows: 1
+   :widths: 15 85
+
+   * - Stage
+     - Interval
+   * - Map
+     - Before allocating unmap metadata through completion of source and
+       destination DMA mappings.
+   * - Prep
+     - After mapping through descriptor preparation and callback setup, ending
+       immediately before submitting the descriptor.
+   * - Submit
+     - Before submission through the cookie check, ending immediately before
+       calling ``dma_async_issue_pending()``.
+   * - Execute
+     - Before ``dma_async_issue_pending()`` through timestamp capture in the
+       completion callback.
+   * - Wakeup
+     - Callback timestamp capture through return from the completion wait.
+   * - Unmap
+     - Return from the wait through completion-status checking and DMA unmap.
+
+Execute includes the issue call, possible queueing, hardware execution,
+interrupt latency and driver completion processing. It is not a measurement
+of hardware-only transfer time. A callback can run before the issue call
+returns; in that case Wakeup also includes the remainder of the issue call
+and must not be interpreted as scheduler latency alone.
+
+Each stage reports its average in microseconds, its percentage of the summed
+stage times and its total in nanoseconds. The sum covers the contiguous
+map-to-unmap interval, including bookkeeping between its boundaries. It
+excludes buffer filling, verification, random parameter generation, initial
+resource allocation and final cleanup. Minimum, average and maximum latency
+refer to this interval. Displayed percentages may not sum to exactly 100 due
+to rounding.
+
+Only successful transfers with ordered timestamps are included. With
+``noverify=0``, a sample must also pass data verification. After the first
+transfer error, verification failure or invalid timestamp sequence, the
+thread stops collecting samples and marks its report ``aborted=1``. This
+prevents a late callback following a timeout from being attributed to a later
+sample. The original test and its error handling continue unchanged.
+
+The report includes the number of samples and their actual transferred byte
+count. For an error-free run with valid samples, Effective BW divides that
+byte count by the summed map-to-unmap time; Execution BW divides it by the
+summed Execute time. Both use MiB/s and count each transfer's data length
+once, without multiplying by the number of source buffers or counting the
+read and write traffic separately. They are ratios of sums, rather than
+averages of individual transfer rates.
+
+These rates have different timing windows from the original summary. Rates
+from different threads must not be added to infer system-wide throughput:
+their measurement windows can overlap and differ in duration. Timestamp
+capture and accumulation add overhead when profiling is enabled, so compare
+with profiling disabled, particularly for small transfers.
drivers/dma/dmatest.c +165 -2

297 lines not on this page · raw message

base-commit: 9437ee8b6cf607e883b36e44bd755968daaebd48

Signature · 1 line
2.34.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] dmaengine: dmatest: missing Signed-off-by trailer in commit message - [Medium] dmaengine: dmatest…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] dmaengine: dmatest: missing Signed-off-by trailer in commit message
- [Medium] dmaengine: dmatest: shared-channel race on PROFILE_EXECUTE in dmatest_func()
--

commit 62ef94a524c9e2bd5d0c52778b817c95279c83ab
Author: Baineng Shou <[email protected]>

Quoted 22 lines

dmaengine: dmatest: Add optional per-stage latency profiling

The aggregate dmatest throughput does not show whether time is spent in DMA mapping, descriptor preparation, execution or completion delivery. This makes it difficult to investigate a low copy rate without adding ad-hoc instrumentation to a test client or a controller driver.

Add a profile parameter to accumulate six consecutive latency intervals per test thread: map, prep, submit, issue-to-callback, callback-to-wait- return, and status-check/unmap. Report the average latency, elapsed time and percentage for each interval after the existing summary, together with the minimum, average and maximum map-to-unmap latency. Derive the effective and execution rates from aggregate bytes and aggregate time.

Publish the callback timestamp before the completion flag using release and acquire ordering. Include issue_pending() in the issue-to-callback interval so that a callback running before the issue call returns does not create overlapping intervals. Stop accumulating samples after the first transfer error, verification failure or invalid timestamp sequence to avoid attributing late callbacks to subsequent samples. Leave the existing test flow and error handling in place.

Quoted 6 lines

Keep profiling disabled by default and print only per-thread totals at test completion. Preserve the existing summary and verbose output, and report profiling as unavailable in polled mode. Document the boundaries, the accounting rules and the added measurement overhead. In particular, execution latency includes queueing, interrupt and driver completion processing; neither rate represents hardware-only or whole-run bandwidth.

[Severity: High]
The commit message is missing a Signed-off-by: trailer certifying the Developer's Certificate of Origin, as required by Documentation/process/submitting-patches.rst.

Quoted 4 lines
drivers/dma/dmatest.c +0 -0
index 2ae3469397f37..e692b41759d67 100644

[ ... ]

Quoted 10 lines
drivers/dma/dmatest.c +2 -0
@@ -826,6 +960,8 @@ static int dmatest_func(void *data)
 			tx->callback = dmatest_callback;
 			tx->callback_param = done;
 		}
+		if (do_profile)
+			ps.ts[PROFILE_SUBMIT] = ktime_get_ns();
 		cookie = tx->tx_submit(tx);
 
 		if (dma_submit_error(cookie)) {

drivers/dma/dmatest.c static int dmatest_func(void *data) · line 982

Quoted 6 lines
drivers/dma/dmatest.c +2 -0
@@ -841,12 +977,17 @@ static int dmatest_func(void *data)
 			if (status == DMA_COMPLETE)
 				done->done = true;
 		} else {
+			if (do_profile)
+				ps.ts[PROFILE_EXECUTE] = ktime_get_ns();
 			dma_async_issue_pending(chan);

[Severity: Medium]
Can a sibling thread sharing chan issue this thread's submitted descriptor before ps.ts[PROFILE_EXECUTE] is recorded?

When multiple dmatest threads share a channel (via threads_per_chan > 1 or when dmatest_add_channel() spawns threads for multiple transaction types on the same channel), tx->tx_submit(tx) places the armed descriptor on the shared channel queue before ps.ts[PROFILE_EXECUTE] is captured:

Thread 0 Thread 1 (same chan) <IRQ / tasklet>
dmatest_func() dmatest_func()
tx->callback = dmatest_callback
tx->tx_submit(tx)

                                  dma_async_issue_pending(chan)
                                                            dmatest_callback()
                                                              callback_ns =
                                                                ktime_get_ns()

ps.ts[PROFILE_EXECUTE] =
ktime_get_ns() <-- after callback_ns

Because ps.ts[PROFILE_WAKEUP] is later set to done->callback_ns, ps.ts[PROFILE_WAKEUP] < ps.ts[PROFILE_EXECUTE]. dmatest_profile_add() then treats the sample as having an invalid timestamp sequence, sets stats->aborted = true, and stops profiling for the remainder of the thread's run.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1