From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.65 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796145714; b=J099wILP4FU3MUWkdSnKThwGkKeAqciPaCEzne2hIO790/ht3WPgXgAgVOxBWv1EQKsJ pHvQxomDhUqXXUD7Gw/f9VNR84EAH9/eQwt3MR6pZYA6LdbRDfWwINWueb5QQ3nYrIO3O Pl5Uju0zvrbBS2IAEf6OlBiI33kXKVbzONqOV4ERIxYFF8ltj7D7DfLcK4Fh3vj9q0y8I JSp7Nihc25j17JVw9kzZCI9LiE1yCdbPz3L9knXOAmVNKdBD5rOBhp87LTh8Z0cHeSS+G gczlUcF9u696OwzcqcOW8lbTozgPNkgeD35YvhC5t0W6eOU/d3a3g2FjN8dqlYOLjrQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796145714; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: Content-Type:MIME-Version:Content-Transfer-Encoding; bh=QnyPjKAi+Fzkbottgrw7vWGzJ1lepAXFBW1f7CUorb0=; b=iiZrQQsuEXZRjXkrZn3r8TahCVJVej5ukWlJnoEOotryBSKC3F5mYbr57fSGJL3MeZl2 E7E8foRE9RAcT7/1nX7j+K0Cn5+YslqoX3RK3YWhxIcnresh7Byg8BpC3CSQlvGbc/Tj+ 7LkVEaEypZZMFxQ+3eFYcWM+iQTcCZlosEf7/hEUMh1hOwizx3UXc81swZrBNpN6WjDJa jDmxh5PClMCQ7vksTuwLzq9TN4tki7qpmsh38Ow4dnHIfWaCTeQolJrPxzfF0R49eRTkY TnndzYsc5uQdJluhr0CagcXKIaQgHAO6oJM9EKyo2HrjjnM+bFzQKlCS5+xXsEa3TAw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=lDOUvtXK; arc=none smtp.remote-ip=74.125.224.65 Received: from mail-yx1-f65.google.com (mail-yx1-f65.google.com [74.125.224.65]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5EEF606A691 for ; Tue, 1 Dec 2026 17:21:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B5EEF606A691 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=lDOUvtXK Received: by mail-yx1-f65.google.com with SMTP id 956f58d0204a3-67c246c0c60so9620804d50.0 for ; Tue, 01 Dec 2026 09:21:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796145712; x=1796750512; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:content-type:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=QnyPjKAi+Fzkbottgrw7vWGzJ1lepAXFBW1f7CUorb0=; b=lDOUvtXKtfRKafGZzerqcZdlhVThzWydyBqdWbkE1m1HQ9tJP8Oix//FKwSPcjc8XB YR29ILumRvgFSfsNOP48Y7Ey2ydwYKPe9xIKnxycZpAFTx4cTsLBXYTLwZAj3hZQrSBW j0CWer6oBth4Yb+VkiA5M6YtIY84PRuMuqwhvZ8yd4kzP/ZoQlqrEZpjBHajpl32zjGg e7ZXD23chVluaRp3Y7Ool1ACxBlaFMUxHH33cTyrGN7YCBynbVjY8fJwQ0KjJvEkBExI adcCGIpaCs4TZbE3Vk+vr6Uf4532qqW3KUIyakAfJ8JSKivykk1hdZdf2PbNueNknBkd pWVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796145712; x=1796750512; h=content-transfer-encoding:mime-version:content-type:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=QnyPjKAi+Fzkbottgrw7vWGzJ1lepAXFBW1f7CUorb0=; b=YXrpraIXn1FHPJKwcijbwFo7DfWQQg2zizG/AxZCpyRzzZFhvYXbW1K1c4lS0fLFJ8 8MLpLR+su/6c9BdLLmsJuRfYRLDdCP5zvaOQS+QVCydrigrUEkTS4nxU7mqSy5SF9fXP 6+KglCHuR9UQTjDn/f/RM/dG5WROPG3Y4fIjmTVUApyBsmtLIsSbqg7zK1c5hS+GsFwQ BAcBrfgMXy+Tp2Evn+Y8KZGFl9LTL4mT4lWfGszqXDgRLyz2jlB9nY5NHkcVdxMhbbXK QN5lm1gJjcIY77eZOn4P668ygj+cBWRIReedTp4jrW452c/OWZ4gwAM8ExjXUq/xCXbY AJQA== X-Forwarded-Encrypted: i=1; AL+hErHCmOsOxu8oHvdh6sFxdNmSR5rfaBRh7oD3SY5EUwmwKTlG8KxNPZaql++7EoiqXST85XoaUilfjJ8=@vger.kernel.org X-Gm-Message-State: APuU4Z9/GGhbznY5zKzt9Q+ehS35qEJM14AWecINMVn3YYxScXbPpSq/ 7XK7rsnZauTYsLOpZA/d73GhSNgR2Zdo5jSoCUHOCjIbvs2ppJoz6Oo= X-Gm-Gg: AZFdTZe3+jjXMt/ZIykZY9wfdl8+SAw9dn0LnZcxcYdXrJskH3vltDLqoj0NTYWOj2N fyrz5UvBpQLgB1SSI2oLhRiF0jJ0hXXW+by8+hMTv5sOdxtHGFs67yWIf5NZXivuxL4ZwjOaPPI 2/FdNhxx5kULEs8uZCSdTQNTGTcD8uYgjdR6A9ZlG5frbTmE3m+Y7Q5NDBSekeiOvd0kmqQV4UL GwpJ2tX9PvZSVBBDlOsWSlMY02GFSX40TyHe5TwLbJc+IZyVTgfdgN9H3MLuPQ1hMtQ3Zy8QR/u 45wuRDpd2cNAHY36GjAA2rEmXzpha6TMaIRAzvz0LbBI+jX3T3cubup9Y65+wX4yr/6iyPaff5b 2xtczmpOgMeekijdOjSU/kk1RUCXRKtMt9hlwzkhgYoXVx7K9GPcz+9wRNIUTM5r80sZt74SHX7 4DECi14Q7BKtsoA4GtYd5EGZlDfHV7qGtKptYQuDhmiSWnQlJ6Y7hTJxWJSo24pv4Rl2KhwC3cb j+JfQstqeP2ebPaPGpyB4P04gIdEqhDnkV0BGarV39s7BIXo7nV8GETqLLd5Hw0uDl8w6iAs1/I 0u7jhsoy16n0wipiFrf2OmzYeDrEFrzX/9Yjk/qdScPuiaHk/pR7f0yCRUKf7R581EVTrMBX X-Received: by 2002:a05:690e:11c5:b0:67d:a3c2:c95 with SMTP id 956f58d0204a3-67dec2bd130mr16114257d50.3.1796145711131; Tue, 01 Dec 2026 09:21:51 -0800 (PST) Received: from localhost.localdomain ([2600:1700:4577:1050:c458:4faf:63d8:2884]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-67df3353258sm17442001d50.9.2026.12.01.09.21.49 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 01 Dec 2026 09:21:50 -0800 (PST) From: Ravi Jonnalagadda To: "Lynch, Nathan" Cc: Vinod Koul , Frank Li , Bjorn Helgaas , David Rientjes , John.Kariuki@amd.com, Jonathan Cameron , Kinsey Ho , Mario Limonciello , PradeepVineshReddy.Kodamati@amd.com, Shivank Garg , Stephen Bates , Tycho Andersen , Wei Huang , Wei Xu , dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: Re: [PATCH v4 00/25] dmaengine: Smart Data Accelerator Interface (SDXI) basic support Date: Tue, 1 Dec 2026 09:21:47 -0800 Message-ID: <20261201172147.90681-1-ravis.opensrc@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <7913b752-ab8b-474c-8841-69674de2ff8f@amd.com> References: <20261103-sdxi-base-v4-0-3668ccc7aab8@amd.com> <20261130182942.82006-1-ravis.opensrc@gmail.com> <7913b752-ab8b-474c-8841-69674de2ff8f@amd.com> Content-Type: text/plain; charset="us-ascii" X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Mon, 30 Nov 2026 17:21:03 -0600, Nathan Lynch wrote: > Thanks for sharing these results Ravi. Can you share the code for this > workload, or at least give us more detail about how the transactions are > submitted to the engine? Hi Nathan, Sure. The workload is a small test kernel module that uses the dmaengine client API directly. The patch below adds it, together with tools/dma/dma-copy-bench.sh: - It applies on mm-new 6ec534d64f85, with or without the v4 series, with "git am --scissors". Build the module with CONFIG_DMA_COPY_BENCH=m. - Run with no arguments, the script finds the memcpy provider and the DRAM and CPU-less NUMA nodes, runs the same sweep, and prints the table in the same format as my earlier mail. A full sweep takes under 3 minutes. Setup: mm-new 6ec534d64f85 plus the 25 v4 patches only. How the module submits the copies: - Each channel comes from dma_request_channel() with DMA_MEMCPY and is driven by its own kthread, on a CPU of the DRAM node. - Each thread copies one buffer of the copy size again and again. The buffer is physically contiguous on the source node, and its copy goes to one on the destination node. Both are mapped once. - Each copy is one descriptor, prepared with DMA_PREP_INTERRUPT and a completion callback, then submitted with dma_async_issue_pending(). The thread waits for the callback before it submits the next copy. - So each channel has exactly one copy in flight. The 1-channel rows are therefore one round trip per copy: for 2 MiB at about 41 GB/s, about 52 us. - The module also takes an optional queue depth. With two copies in flight, one channel reaches about 44 GB/s DRAM->CXL and 45 GB/s CXL->DRAM at 2 MiB, against 39-41 GB/s with one. At 64 KiB, two copies in flight about double one channel. - From 4 channels at 2 MiB, the depth changes nothing. Calling dma_async_issue_pending() once per batch instead of once per descriptor did not help. How the table is measured: - GB/s = total bytes / the time from the first submit to the last completion over all channels. - For the posted table, each run was 100,000 copies in bursts of up to 10 s, with the time summed over the bursts. The script's default of about 2 s per run gives the same numbers, within the variation below. - The throughput runs compare only the first and last copy of each burst with the source. Separate runs compared every copy. All 16.2 M copies completed with DMA_COMPLETE, and 0 of the compared copies mismatched. - On this host the rows with small copies (4 KiB, and 64 KiB at 1 or 4 channels) vary by up to about 20 % between runs. The 2 MiB rows and the 64 KiB 16-channel row stay within 3 %. - The numbers are indicative and will differ between setups, for example with the platform and the CXL device. Thanks, Ravi -- >8 -- From: Ravi Jonnalagadda Subject: [PATCH] dmaengine: add a copy throughput test module and script Add dma-copy-bench, a test module that measures the memcpy throughput of DMA engine channels, and tools/dma/dma-copy-bench.sh, which runs a sweep with it. The result is the bytes copied over all channels, divided by the time from the start of the first copy to the end of the last one. Each channel is driven by one kthread on a CPU of the DRAM node. The source and destination buffers are placed on chosen NUMA nodes and mapped once. Every descriptor has a completion callback. By default a channel has one copy in flight; DEPTH allows more, each with its own buffers. The script finds the DMA devices with memcpy channels and the DRAM and memory-only NUMA nodes, loads the module, and runs copy sizes x channel counts x DRAM->DRAM, DRAM->far and far->DRAM. It prints a table of the median GB/s over the runs. -h lists the options. Signed-off-by: Ravi Jonnalagadda --- MAINTAINERS | 1 + drivers/dma/Kconfig | 9 + drivers/dma/Makefile | 1 + drivers/dma/dma-copy-bench.c | 518 ++++++++++++++++++++++++++++++++++ tools/dma/dma-copy-bench.sh | 526 +++++++++++++++++++++++++++++++++++ 5 files changed, 1055 insertions(+) create mode 100644 drivers/dma/dma-copy-bench.c create mode 100755 tools/dma/dma-copy-bench.sh diff --git a/MAINTAINERS b/MAINTAINERS index ce05a32..7d1488e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7898,6 +7898,7 @@ F: include/dt-bindings/dma/ F: include/linux/dma/ F: include/linux/dmaengine.h F: include/linux/of_dma.h +F: tools/dma/dma-copy-bench.sh DMA MAPPING BENCHMARK M: Barry Song diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig index 01f96a8..a7db036 100644 --- a/drivers/dma/Kconfig +++ b/drivers/dma/Kconfig @@ -797,6 +797,15 @@ config DMATEST Simple DMA test client. Say N unless you're debugging a DMA Device driver. +config DMA_COPY_BENCH + tristate "DMA copy throughput test" + depends on DMA_ENGINE + help + Test module that measures the memcpy throughput of DMA channels, + with a chosen number of descriptors in flight per channel. Results + are reported through debugfs. Say N unless you are measuring a DMA + device driver. + config DMA_ENGINE_RAID bool diff --git a/drivers/dma/Makefile b/drivers/dma/Makefile index f62d12b..3cf2ab6 100644 --- a/drivers/dma/Makefile +++ b/drivers/dma/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_DMA_OF) += of-dma.o #dmatest obj-$(CONFIG_DMATEST) += dmatest.o +obj-$(CONFIG_DMA_COPY_BENCH) += dma-copy-bench.o #devices obj-$(CONFIG_ALTERA_MSGDMA) += altera-msgdma.o diff --git a/drivers/dma/dma-copy-bench.c b/drivers/dma/dma-copy-bench.c new file mode 100644 index 0000000..7d1c50a --- /dev/null +++ b/drivers/dma/dma-copy-bench.c @@ -0,0 +1,518 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * DMA engine copy throughput test. + * + * Each channel is driven by one kthread that keeps up to DEPTH memcpy + * descriptors in flight. Each of them copies between its own pair of + * buffers. A new descriptor is submitted when the oldest one completes. + * + * echo "SRCNODE DSTNODE SIZE ITERS_PER_CHAN NCHAN VERIFY_EVERY [DEPTH [BATCH]]" \ + * > /sys/kernel/debug/dma-copy-bench/run + * cat /sys/kernel/debug/dma-copy-bench/result + * + * VERIFY_EVERY = N checks the data of every Nth copy and of the last copy + * of each channel; 0 disables the check. DEPTH defaults to 1. BATCH = 1 + * issues the pending descriptors once per DEPTH submissions instead of + * after each one. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define BENCH_MAX_CHANS 64 +#define BENCH_MAX_DEPTH 64 +#define BENCH_TIMEOUT_MS 10000 + +static char *device = ""; +module_param(device, charp, 0444); +MODULE_PARM_DESC(device, + "Use only channels of this DMA device (dev_name), empty: any"); + +static int cpu_node; +module_param(cpu_node, int, 0444); +MODULE_PARM_DESC(cpu_node, "Run the test threads on CPUs of this NUMA node"); + +struct bench_slot { + struct page *sp, *dp; + dma_addr_t sd, dd; + struct completion done; + dma_cookie_t ck; + long seq; + bool busy, ver; +}; + +struct bench_chan { + struct task_struct *task; + struct dma_chan *ch; + char name[32]; + struct bench_slot *slots; + int depth; + bool batch; + size_t size; + long iters, verify_every; + long done, errs, vfail; + int inflight; + ktime_t busy0; + s64 dma_ns; + s64 first_ns, last_ns; + struct completion fin; + struct completion *go; +}; + +struct bench_result { + int src_node, dst_node; + size_t size; + long iters, verify_every; + int depth; + bool batch; + int nchan; + int ret; + struct bench_chan chans[] __counted_by(nchan); +}; + +static struct dentry *bench_dir; +static struct bench_result *bench_res; +static DEFINE_MUTEX(bench_lock); + +static bool bench_filter(struct dma_chan *chan, void *param) +{ + return !*device || !strcmp(dev_name(chan->device->dev), device); +} + +static void bench_copy_done(void *arg) +{ + complete(arg); +} + +/* Prepare and submit one copy into a free slot. */ +static int bench_submit(struct bench_chan *t, struct bench_slot *sl) +{ + struct dma_async_tx_descriptor *tx; + + reinit_completion(&sl->done); + tx = dmaengine_prep_dma_memcpy(t->ch, sl->dd, sl->sd, t->size, + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); + if (!tx) + return -ENOMEM; + tx->callback = bench_copy_done; + tx->callback_param = &sl->done; + sl->ck = dmaengine_submit(tx); + if (dma_submit_error(sl->ck)) + return -EIO; + return 0; +} + +/* + * Wait up to tmo jiffies for the copy of a busy slot and account for it. + * Returns 0, -ETIMEDOUT or another negative errno. The first timeout + * terminates all copies of the channel, so that no callback runs once the + * thread has returned. The remaining slots are then reaped with tmo 0. + */ +static int bench_reap(struct bench_chan *t, struct bench_slot *sl, long tmo) +{ + enum dma_status st; + ktime_t t1; + int rc = 0; + + sl->busy = false; + if (!wait_for_completion_timeout(&sl->done, tmo)) { + if (tmo) + dmaengine_terminate_sync(t->ch); + rc = -ETIMEDOUT; + } else { + st = dma_async_is_tx_complete(t->ch, sl->ck, NULL, NULL); + if (st != DMA_COMPLETE) + rc = -EIO; + } + t1 = ktime_get(); + /* The channel is busy while at least one of its copies is in flight. */ + if (!--t->inflight) + t->dma_ns += ktime_to_ns(ktime_sub(t1, t->busy0)); + t->last_ns = ktime_to_ns(t1); + if (rc) { + t->errs++; + return rc; + } + t->done++; + if (sl->ver && + memcmp(page_address(sl->sp), page_address(sl->dp), t->size)) + t->vfail++; + return 0; +} + +static int bench_thread(void *arg) +{ + struct bench_chan *t = arg; + long tmo = msecs_to_jiffies(BENCH_TIMEOUT_MS); + long i, nsub = 0, nissued = 0; + struct bench_slot *sl; + ktime_t t0; + int j; + + wait_for_completion(t->go); + + for (i = 0; i < t->iters && !kthread_should_stop(); i++) { + sl = &t->slots[i % t->depth]; + if (sl->busy) { + /* With BATCH, the oldest copy may not be issued yet. */ + if (sl->seq >= nissued) { + dma_async_issue_pending(t->ch); + nissued = nsub; + } + if (bench_reap(t, sl, tmo) == -ETIMEDOUT) { + tmo = 0; + break; + } + } + + sl->ver = t->verify_every && + (i % t->verify_every == 0 || i == t->iters - 1); + if (sl->ver) { + u8 *s = page_address(sl->sp), *d = page_address(sl->dp); + + memset(s, (u8)(i * 7 + 1), t->size); + s[0] = (u8)i; + s[t->size - 1] = (u8)(i >> 8); + memset(d, 0, t->size); + } + t0 = ktime_get(); + if (!t->first_ns) + t->first_ns = ktime_to_ns(t0); + if (bench_submit(t, sl)) { + t->errs++; + continue; + } + if (!t->inflight++) + t->busy0 = t0; + sl->busy = true; + sl->seq = nsub++; + if (!t->batch || nsub - nissued >= t->depth || + i == t->iters - 1) { + dma_async_issue_pending(t->ch); + nissued = nsub; + } + } + + if (nsub > nissued) + dma_async_issue_pending(t->ch); + /* Collect the copies still in flight, oldest first. */ + for (j = 0; j < t->depth; j++) { + sl = &t->slots[(i + j) % t->depth]; + if (sl->busy && bench_reap(t, sl, tmo) == -ETIMEDOUT) + tmo = 0; + } + complete(&t->fin); + return 0; +} + +/* + * Memory that was hot-added as ZONE_MOVABLE, such as CXL memory, is only + * reachable by a movable allocation. The buffers are accessed through the + * direct map, so highmem pages are refused. + */ +static struct page *bench_alloc(int nid, unsigned int order) +{ + struct page *page; + + page = alloc_pages_node( + nid, GFP_HIGHUSER_MOVABLE | __GFP_THISNODE | __GFP_NOWARN, + order); + if (page && PageHighMem(page)) { + __free_pages(page, order); + return NULL; + } + return page; +} + +static void bench_slot_release(struct device *dev, struct bench_slot *sl, + size_t size, unsigned int order) +{ + dma_unmap_page(dev, sl->dd, size, DMA_FROM_DEVICE); + dma_unmap_page(dev, sl->sd, size, DMA_TO_DEVICE); + __free_pages(sl->dp, order); + __free_pages(sl->sp, order); +} + +static int bench_slot_init(struct device *dev, struct bench_slot *sl, int sn, + int dn, size_t size, unsigned int order) +{ + sl->sp = bench_alloc(sn, order); + if (!sl->sp) + return -ENOMEM; + sl->dp = bench_alloc(dn, order); + if (!sl->dp) + goto err_src; + sl->sd = dma_map_page(dev, sl->sp, 0, size, DMA_TO_DEVICE); + if (dma_mapping_error(dev, sl->sd)) + goto err_dst; + sl->dd = dma_map_page(dev, sl->dp, 0, size, DMA_FROM_DEVICE); + if (dma_mapping_error(dev, sl->dd)) + goto err_unmap; + init_completion(&sl->done); + return 0; + +err_unmap: + dma_unmap_page(dev, sl->sd, size, DMA_TO_DEVICE); +err_dst: + __free_pages(sl->dp, order); +err_src: + __free_pages(sl->sp, order); + return -ENOMEM; +} + +static int bench_chan_init(struct bench_chan *bc, int sn, int dn, + unsigned int order) +{ + struct device *dev; + dma_cap_mask_t mask; + int i, ret = -ENOMEM; + + dma_cap_zero(mask); + dma_cap_set(DMA_MEMCPY, mask); + bc->ch = dma_request_channel(mask, bench_filter, NULL); + if (!bc->ch) + return -ENODEV; + strscpy(bc->name, dma_chan_name(bc->ch)); + dev = bc->ch->device->dev; + + bc->slots = kcalloc(bc->depth, sizeof(*bc->slots), GFP_KERNEL); + if (!bc->slots) + goto err_chan; + for (i = 0; i < bc->depth; i++) { + ret = bench_slot_init(dev, &bc->slots[i], sn, dn, bc->size, + order); + if (ret) + goto err_slots; + } + init_completion(&bc->fin); + return 0; + +err_slots: + while (i--) + bench_slot_release(dev, &bc->slots[i], bc->size, order); + kfree(bc->slots); +err_chan: + dma_release_channel(bc->ch); + bc->ch = NULL; + return ret; +} + +static void bench_chan_release(struct bench_chan *bc, unsigned int order) +{ + struct device *dev = bc->ch->device->dev; + int i; + + for (i = 0; i < bc->depth; i++) + bench_slot_release(dev, &bc->slots[i], bc->size, order); + kfree(bc->slots); + dma_release_channel(bc->ch); + bc->ch = NULL; +} + +static bool bench_mem_node(int nid) +{ + return nid >= 0 && nid < MAX_NUMNODES && node_state(nid, N_MEMORY); +} + +static int bench_run(int sn, int dn, size_t size, long iters, int nchan, + long verify_every, int depth, int batch) +{ + const struct cpumask *cpus; + struct bench_result *res; + struct completion go; + unsigned int order; + int i, n, ret = 0; + + if (!bench_mem_node(sn) || !bench_mem_node(dn) || !size || + get_order(size) > MAX_PAGE_ORDER || iters < 1 || nchan < 1 || + nchan > BENCH_MAX_CHANS || verify_every < 0 || depth < 1 || + depth > BENCH_MAX_DEPTH || batch < 0 || batch > 1) + return -EINVAL; + if (cpu_node < 0 || cpu_node >= MAX_NUMNODES || !node_online(cpu_node)) + return -EINVAL; + cpus = cpumask_of_node(cpu_node); + if (cpumask_empty(cpus)) + return -EINVAL; + order = get_order(size); + + kfree(bench_res); + bench_res = NULL; + res = kzalloc(struct_size(res, chans, nchan), GFP_KERNEL); + if (!res) + return -ENOMEM; + res->nchan = nchan; + res->src_node = sn; + res->dst_node = dn; + res->size = size; + res->iters = iters; + res->verify_every = verify_every; + res->depth = depth; + res->batch = batch; + + init_completion(&go); + for (n = 0; n < nchan; n++) { + struct bench_chan *bc = &res->chans[n]; + + bc->size = size; + bc->iters = iters; + bc->verify_every = verify_every; + bc->depth = depth; + bc->batch = batch; + bc->go = &go; + ret = bench_chan_init(bc, sn, dn, order); + if (ret) + goto out_release; + } + + /* Threads are woken only once all exist, then released together. */ + for (i = 0; i < nchan; i++) { + struct task_struct *task; + + task = kthread_create(bench_thread, &res->chans[i], + "dma_bench/%d", i); + if (IS_ERR(task)) { + ret = PTR_ERR(task); + while (i--) + kthread_stop_put(res->chans[i].task); + goto out_release; + } + get_task_struct(task); + kthread_bind(task, cpumask_nth(i % cpumask_weight(cpus), cpus)); + res->chans[i].task = task; + } + for (i = 0; i < nchan; i++) + wake_up_process(res->chans[i].task); + complete_all(&go); + + for (i = 0; i < nchan; i++) { + if (wait_for_completion_killable(&res->chans[i].fin)) { + ret = -EINTR; + break; + } + } + for (i = 0; i < nchan; i++) + kthread_stop_put(res->chans[i].task); + +out_release: + while (n--) + bench_chan_release(&res->chans[n], order); + res->ret = ret; + bench_res = res; + return ret; +} + +static ssize_t run_write(struct file *file, const char __user *ubuf, + size_t count, loff_t *ppos) +{ + int sn, dn, nchan, depth = 1, batch = 0, ret; + long iters, verify_every; + char buf[128]; + size_t size; + + if (count >= sizeof(buf)) + return -EINVAL; + if (copy_from_user(buf, ubuf, count)) + return -EFAULT; + buf[count] = '\0'; + if (sscanf(buf, "%d %d %zu %ld %d %ld %d %d", &sn, &dn, &size, &iters, + &nchan, &verify_every, &depth, &batch) < 6) + return -EINVAL; + + mutex_lock(&bench_lock); + ret = bench_run(sn, dn, size, iters, nchan, verify_every, depth, batch); + mutex_unlock(&bench_lock); + + return ret ? ret : count; +} + +static const struct file_operations run_fops = { + .owner = THIS_MODULE, + .write = run_write, +}; + +static int result_show(struct seq_file *m, void *v) +{ + struct bench_result *res; + s64 first = S64_MAX, last = 0, wall = 0; + long done = 0, errs = 0, vfail = 0; + u64 bytes; + int i; + + mutex_lock(&bench_lock); + res = bench_res; + if (!res) { + seq_puts(m, "no result\n"); + goto out; + } + for (i = 0; i < res->nchan; i++) { + struct bench_chan *bc = &res->chans[i]; + + done += bc->done; + errs += bc->errs; + vfail += bc->vfail; + if (bc->first_ns && bc->first_ns < first) + first = bc->first_ns; + if (bc->last_ns > last) + last = bc->last_ns; + } + if (last > first) + wall = last - first; + bytes = (u64)done * res->size; + + seq_printf( + m, + "src_node %d dst_node %d size %zu iters_per_chan %ld nchan %d verify_every %ld depth %d batch %d ret %d\n", + res->src_node, res->dst_node, res->size, res->iters, res->nchan, + res->verify_every, res->depth, res->batch, res->ret); + seq_printf(m, "copies %ld errors %ld verify_failures %ld\n", done, errs, + vfail); + seq_printf(m, "bytes %llu wall_ns %lld MB/s %llu\n", bytes, wall, + wall ? div64_u64(bytes * 1000, wall) : 0); + for (i = 0; i < res->nchan; i++) { + struct bench_chan *bc = &res->chans[i]; + + seq_printf( + m, + "chan %d %s copies %ld errors %ld busy_ns %lld first_ns %lld last_ns %lld\n", + i, bc->name, bc->done, bc->errs, bc->dma_ns, + bc->first_ns ? bc->first_ns - first : -1, + bc->last_ns ? bc->last_ns - first : -1); + } +out: + mutex_unlock(&bench_lock); + return 0; +} +DEFINE_SHOW_ATTRIBUTE(result); + +static int __init dma_copy_bench_init(void) +{ + bench_dir = debugfs_create_dir("dma-copy-bench", NULL); + debugfs_create_file("run", 0200, bench_dir, NULL, &run_fops); + debugfs_create_file("result", 0400, bench_dir, NULL, &result_fops); + return 0; +} +module_init(dma_copy_bench_init); + +static void __exit dma_copy_bench_exit(void) +{ + debugfs_remove(bench_dir); + kfree(bench_res); +} +module_exit(dma_copy_bench_exit); + +MODULE_DESCRIPTION("DMA engine copy throughput test"); +MODULE_LICENSE("GPL"); diff --git a/tools/dma/dma-copy-bench.sh b/tools/dma/dma-copy-bench.sh new file mode 100755 index 0000000..f874594 --- /dev/null +++ b/tools/dma/dma-copy-bench.sh @@ -0,0 +1,526 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Run a memcpy throughput sweep with the dma-copy-bench module. +# +# The sweep covers copy sizes x channel counts x three directions: +# DRAM->DRAM, DRAM->FAR and FAR->DRAM. FAR is a NUMA node with memory and +# no CPUs, such as CXL memory. Each run lasts about a set time, or does a +# set number of copies. Runs can be split into bursts of a bounded length +# with idle time between them. Each channel can keep several copies in +# flight. + +set -u +start_ns=$(date +%s%N) + +sizes="4K,64K,2M" +chans="1,4,16" +depths="1" +batch=0 +runs=3 +time_s=2 +copies="" +burst_s=0 +gap_s=0 +verify_all=0 +device="" +dram="" +far="" +module="" +csv="" +ranges=0 + +usage() { + cat <&2 + exit 1 +} + +is_uint() { + [[ $1 =~ ^[0-9]+$ ]] +} + +is_num() { + [[ $1 =~ ^[0-9]+(\.[0-9]+)?$ ]] +} + +to_bytes() { + case $1 in + *[kK]) echo $((${1%?} * 1024)) ;; + *[mM]) echo $((${1%?} * 1024 * 1024)) ;; + *) echo "$1" ;; + esac +} + +size_label() { + if (($1 % 1048576 == 0)); then + echo "$(($1 / 1048576)) MiB" + elif (($1 % 1024 == 0)); then + echo "$(($1 / 1024)) KiB" + else + echo "$1 B" + fi +} + +while getopts "d:s:t:z:c:q:Br:T:n:b:g:Vm:o:Rh" opt; do + case $opt in + d) device=$OPTARG ;; + s) dram=$OPTARG ;; + t) far=$OPTARG ;; + z) sizes=$OPTARG ;; + c) chans=$OPTARG ;; + q) depths=$OPTARG ;; + B) batch=1 ;; + r) runs=$OPTARG ;; + T) time_s=$OPTARG ;; + n) copies=$OPTARG ;; + b) burst_s=$OPTARG ;; + g) gap_s=$OPTARG ;; + V) verify_all=1 ;; + m) module=$OPTARG ;; + o) csv=$OPTARG ;; + R) ranges=1 ;; + h) usage; exit 0 ;; + *) usage >&2; exit 2 ;; + esac +done +shift $((OPTIND - 1)) +(($# == 0)) || { usage >&2; exit 2; } + +for v in "$runs" ${copies:+"$copies"}; do + if ! is_uint "$v" || ((v == 0)); then + die "bad count: $v" + fi +done +if ! is_num "$time_s" || ! is_num "$burst_s" || ! is_num "$gap_s"; then + die "bad -T, -b or -g value" +fi +to_ns() { + awk -v s="$1" 'BEGIN { printf "%d", s * 1e9 }' +} +time_ns=$(to_ns "$time_s") +burst_ns=$(to_ns "$burst_s") +gap_ns=$(to_ns "$gap_s") +[ -n "$copies" ] || ((time_ns > 0)) || die "bad -T value: $time_s" +for v in "$dram" "$far"; do + [ -z "$v" ] || is_uint "$v" || die "bad node: $v" +done +IFS=, read -ra size_list <<< "$sizes" +IFS=, read -ra chan_list <<< "$chans" +IFS=, read -ra depth_list <<< "$depths" +for i in "${!size_list[@]}"; do + [[ ${size_list[i]} =~ ^[0-9]+[kKmM]?$ ]] || die "bad size: ${size_list[i]}" + size_list[i]=$(to_bytes "${size_list[i]}") + ((size_list[i] > 0)) || die "bad size: 0" +done +for c in "${chan_list[@]}"; do + if ! is_uint "$c" || ((c == 0)); then + die "bad channel count: $c" + fi +done +for q in "${depth_list[@]}"; do + if ! is_uint "$q" || ((q == 0 || q > 64)); then + die "bad depth: $q (1-64)" + fi +done +((EUID == 0)) || die "must be run as root" + +# Two sweeps at once would share the module and the channels. +exec 9> /run/dma-copy-bench.lock +flock -n 9 || die "another ${0##*/} is running" + +# The module allocates each buffer as one block of pages. +max_order=$(awk '/^Free pages count per migrate type at order/ { print $NF; exit }' \ + /proc/pagetypeinfo 2>/dev/null) +if is_uint "${max_order:-}"; then + max_size=$(($(getconf PAGESIZE) << max_order)) + for s in "${size_list[@]}"; do + ((s <= max_size)) || + die "bad size: $(size_label "$s") (at most $(size_label "$max_size"))" + done +fi + +# DMA devices: channels whose "cap" file, if there is one, lists memcpy. +declare -A dev_chans dev_free dev_node +for c in /sys/class/dma/*; do + [ -e "$c/device" ] || continue + cap="" + [ -r "$c/cap" ] && cap=$c/cap + [ -r "$c/device/cap" ] && cap=$c/device/cap + if [ -n "$cap" ] && ! grep -qi memcpy "$cap"; then + continue + fi + dev=$(basename "$(readlink -f "$c/device")") + dev_chans[$dev]=$((${dev_chans[$dev]:-0} + 1)) + [ "$(cat "$c/in_use" 2>/dev/null)" = 0 ] && + dev_free[$dev]=$((${dev_free[$dev]:-0} + 1)) + dev_node[$dev]=$(cat "$c/device/numa_node" 2>/dev/null || echo -1) +done + +list_devices() { + local d + + for d in "${!dev_chans[@]}"; do + printf ' %-16s node %-3s channels %s (free %s)\n' "$d" \ + "${dev_node[$d]}" "${dev_chans[$d]}" "${dev_free[$d]:-0}" + done | sort +} + +((${#dev_chans[@]})) || die "no DMA device with memcpy channels found" +echo "DMA devices with memcpy channels:" +list_devices +if [ -z "$device" ]; then + if ((${#dev_chans[@]} > 1)); then + echo "Several DMA devices found; choose one with -d." >&2 + exit 1 + fi + device=${!dev_chans[*]} +fi +[ -n "${dev_chans[$device]:-}" ] || die "no memcpy channels on device $device" +free=${dev_free[$device]:-0} +((free > 0)) || die "no free channel on device $device" +((free > 64)) && free=64 + +# NUMA nodes: with CPUs, or memory only. +nodes=() +for p in /sys/devices/system/node/node[0-9]*; do + [ -e "$p" ] && nodes+=("${p##*node}") +done +cpu_nodes=() +mem_nodes=() +for n in $(printf '%s\n' "${nodes[@]}" | sort -n); do + p=/sys/devices/system/node/node$n + if [ -n "$(tr -d '[:space:]' < "$p/cpulist")" ]; then + cpu_nodes+=("$n") + elif (($(awk '/MemTotal/ { print $4 }' "$p/meminfo") > 0)); then + mem_nodes+=("$n") + fi +done +((${#cpu_nodes[@]})) || die "no NUMA node with CPUs found" +echo "Nodes with CPUs: ${cpu_nodes[*]}; memory-only nodes: ${mem_nodes[*]:-none}" + +has_cpus() { + [[ " ${cpu_nodes[*]} " == *" $1 "* ]] +} + +if [ -z "$dram" ]; then + if has_cpus "${dev_node[$device]}"; then + dram=${dev_node[$device]} + why="the node of $device" + else + dram=${cpu_nodes[0]} + why="the first node with CPUs" + fi +else + [ -e "/sys/devices/system/node/node$dram" ] || die "no node $dram" + has_cpus "$dram" || die "node $dram has no CPUs" + why="-s" +fi +echo "DRAM node: $dram ($why)" +if [ -z "$far" ] && ((${#mem_nodes[@]})); then + far=${mem_nodes[0]} + echo "Far node: $far (the first memory-only node)" +elif [ -n "$far" ]; then + [ -e "/sys/devices/system/node/node$far" ] || die "no node $far" + ! has_cpus "$far" || die "node $far has CPUs; -t needs a memory-only node" + [[ " ${mem_nodes[*]} " == *" $far "* ]] || die "node $far has no memory" + echo "Far node: $far (-t)" +else + echo "Far node: none (no memory-only node), running DRAM->DRAM only" +fi + +# Name the far node CXL when a CXL region provides its memory. +far_name=FAR +if [ -n "$far" ]; then + for d in /sys/bus/dax/devices/dax*; do + [ "$(cat "$d/target_node" 2>/dev/null)" = "$far" ] || continue + case $(readlink -f "$d") in + */region[0-9]*) far_name=CXL ;; + esac + done +fi + +dirs=(D2D) +[ -n "$far" ] && dirs+=(D2F F2D) + +# Channel counts above the free channels are capped. +declare -A seen +nchans=() +for c in "${chan_list[@]}"; do + if ((c > free)); then + echo "${0##*/}: $c channels capped to the $free free ones" >&2 + c=$free + fi + [ -n "${seen[$c]:-}" ] && continue + seen[$c]=1 + nchans+=("$c") +done +echo "Device $device: ${dev_chans[$device]} channels, $free free; channel counts: ${nchans[*]}" + +dbgfs=$(awk '$3 == "debugfs" { print $2; exit }' /proc/mounts) +[ -n "$dbgfs" ] || die "debugfs is not mounted (mount -t debugfs none /sys/kernel/debug)" + +loaded=0 +unload() { + if ((loaded)); then + rmmod dma_copy_bench + fi +} +trap unload EXIT +trap 'exit 130' HUP INT TERM + +if [ -d /sys/module/dma_copy_bench ]; then + p=/sys/module/dma_copy_bench/parameters + if [ "$(cat "$p/device")" != "$device" ] || + [ "$(cat "$p/cpu_node")" != "$dram" ]; then + cur="device=$(cat "$p/device") cpu_node=$(cat "$p/cpu_node")" + die "dma-copy-bench is loaded with $cur; unload it first" + fi + echo "dma-copy-bench already loaded; it stays loaded" +elif [ -n "$module" ]; then + insmod "$module" device="$device" cpu_node="$dram" || die "insmod $module failed" + loaded=1 +else + modprobe dma-copy-bench device="$device" cpu_node="$dram" || + die "modprobe dma-copy-bench failed (CONFIG_DMA_COPY_BENCH=m, or use -m)" + loaded=1 +fi +run_file=$dbgfs/dma-copy-bench/run +result_file=$dbgfs/dma-copy-bench/result +[ -w "$run_file" ] || die "$run_file not found" + +if [ -n "$csv" ]; then + cols="size,channels,direction,src_node,dst_node,run" + cols+=",copies,errors,verify_failures,bytes,wall_ns,gbps,bursts" + echo "$cols,depth,batch" > "$csv" +fi + +busy_ns=0 +copy_ns=0 +idle_ns=0 +# burst SRC DST SIZE ITERS NCHAN VERIFY_EVERY DEPTH EST_NS +# Sets b_copies, b_errs, b_vfail, b_bytes and b_wall. Waits for the idle +# time first if this burst would make the copying since the last idle +# time longer than the burst limit. +burst() { + local est=$9 err + + if ((burst_ns && busy_ns && busy_ns + est > burst_ns)); then + sleep "$gap_s" + idle_ns=$((idle_ns + gap_ns)) + busy_ns=0 + fi + if ! err=$({ echo "${@:1:8}" > "$run_file"; } 2>&1); then + echo " run '${*:1:8}' failed: ${err##*: }" >&2 + return 1 + fi + read -r b_copies b_errs b_vfail b_bytes b_wall b_depth < <(awk ' + /^src_node / { q = 1; for (i = 1; i < NF; i++) if ($i == "depth") q = $(i + 1) } + /^copies / { c = $2; e = $4; f = $6 } + /^bytes / { b = $2; w = $4 } + END { print c + 0, e + 0, f + 0, b + 0, w + 0, q + 0 }' "$result_file") + if ((b_depth != $7)); then + echo " run '${*:1:8}': the module does not support DEPTH" >&2 + return 1 + fi + busy_ns=$((busy_ns + b_wall)) + copy_ns=$((copy_ns + b_wall)) +} + +# one_run SRC DST SIZE NCHAN ITERS DEPTH: ITERS copies per channel, in bursts. +# Uses and updates rate_ns, the time of one copy per channel; 0 is unknown. +# Sets r_copies, r_errs, r_vfail, r_bytes, r_wall and r_bursts. +one_run() { + local left=$5 chunk n ve + + r_copies=0 r_errs=0 r_vfail=0 r_bytes=0 r_wall=0 r_bursts=0 + while ((left > 0)); do + chunk=$left + if ((burst_ns)); then + if ((rate_ns)); then + chunk=$((burst_ns / rate_ns)) + else + chunk=200 + fi + ((chunk > 0)) || chunk=1 + fi + n=$((left < chunk ? left : chunk)) + ve=$n + ((verify_all)) && ve=1 + burst "$1" "$2" "$3" "$n" "$4" "$ve" "$6" "$batch" \ + $((n * rate_ns)) || return 1 + left=$((left - n)) + r_bursts=$((r_bursts + 1)) + r_copies=$((r_copies + b_copies)) + r_errs=$((r_errs + b_errs)) + r_vfail=$((r_vfail + b_vfail)) + r_bytes=$((r_bytes + b_bytes)) + r_wall=$((r_wall + b_wall)) + ((rate_ns)) || rate_ns=$((b_wall / n)) + ((rate_ns > 0)) || rate_ns=1 + done +} + +declare -A gbps +declare -A label=([D2D]="DRAM->DRAM" [D2F]="DRAM->$far_name" [F2D]="$far_name->DRAM") +tot_copies=0 +tot_want=0 +tot_errs=0 +tot_vfail=0 +failed=0 + +# one_cell SIZE NCHAN DEPTH DIR: the runs of one table cell. +one_cell() { + local size=$1 nch=$2 q=$3 d=$4 src dst per_chan r g qd row + + case $d in + D2D) src=$dram dst=$dram ;; + D2F) src=$dram dst=$far ;; + F2D) src=$far dst=$dram ;; + esac + rate_ns=0 + if [ -n "$copies" ]; then + per_chan=$((copies / nch)) + else + # Calibrate the copy count of the runs of this cell. + if ! one_run "$src" "$dst" "$size" "$nch" 200 "$q" || + ((r_errs || r_vfail)); then + echo " calibration failed" >&2 + failed=1 + return + fi + per_chan=$((time_ns / rate_ns)) + fi + ((per_chan > 0)) || per_chan=1 + qd="" + ((show_depth)) && qd=" depth $q" + for ((r = 1; r <= runs; r++)); do + one_run "$src" "$dst" "$size" "$nch" "$per_chan" "$q" || + failed=1 + g=$(awk -v b="$r_bytes" -v w="$r_wall" \ + 'BEGIN { printf "%.3f", w ? b / w : 0 }') + gbps[$size,$nch,$q,$d]+="$g " + tot_copies=$((tot_copies + r_copies)) + tot_want=$((tot_want + per_chan * nch)) + tot_errs=$((tot_errs + r_errs)) + tot_vfail=$((tot_vfail + r_vfail)) + printf '%s %2d ch%s %-10s run %d: %s GB/s' \ + "$(size_label "$size")" "$nch" "$qd" \ + "${label[$d]}" "$r" "$g" >&2 + printf ', copies %d, errors %d, verify failures %d\n' \ + "$r_copies" "$r_errs" "$r_vfail" >&2 + [ -n "$csv" ] || continue + row=("$size" "$nch" "${label[$d]}" "$src" "$dst" "$r") + row+=("$r_copies" "$r_errs" "$r_vfail" "$r_bytes") + row+=("$r_wall" "$g" "$r_bursts" "$q" "$batch") + (IFS=,; echo "${row[*]}") >> "$csv" + done +} + +# A depth column is shown only when several depths are measured. +show_depth=0 +((${#depth_list[@]} > 1)) && show_depth=1 + +for size in "${size_list[@]}"; do + for nch in "${nchans[@]}"; do + for q in "${depth_list[@]}"; do + for d in "${dirs[@]}"; do + one_cell "$size" "$nch" "$q" "$d" + done + done + done +done + +cell() { + echo "$1" | tr ' ' '\n' | sed '/^$/d' | sort -g | awk -v r="$ranges" ' + { v[NR] = $1 } + END { + if (!NR) { printf "-"; exit } + m = NR % 2 ? v[(NR + 1) / 2] : (v[NR / 2] + v[NR / 2 + 1]) / 2 + if (r) + printf "%.1f [%.1f-%.1f]", m, v[1], v[NR] + else + printf "%.1f", m + }' +} + +stat=median +((ranges)) && stat="median [min-max]" +echo +qnote="" +((!show_depth && depth_list[0] != 1)) && qnote+=", depth ${depth_list[0]}" +((batch)) && qnote+=", issued once per depth" +if [ -n "$copies" ]; then + echo "GB/s, $stat of $runs runs of $copies copies$qnote" +else + echo "GB/s, $stat of $runs runs of about $time_s s$qnote" +fi +echo "DRAM = node $dram${far:+, $far_name = node $far}" +echo +declare -A width +hdr="size | channels" +sep="-------+---------" +if ((show_depth)); then + hdr+=" | depth" + sep+="-+------" +fi +for d in "${dirs[@]}"; do + w=${#label[$d]} + ((ranges && w < 17)) && w=17 + width[$d]=$w + hdr+=$(printf ' | %*s' "$w" "${label[$d]}") + sep+="-+-$(printf '%*s' "$w" '' | tr ' ' -)" +done +echo "$hdr" +echo "$sep" +for size in "${size_list[@]}"; do + for nch in "${nchans[@]}"; do + for q in "${depth_list[@]}"; do + line=$(printf '%-6s | %-8s' "$(size_label "$size")" "$nch") + ((show_depth)) && line+=$(printf ' | %-5s' "$q") + for d in "${dirs[@]}"; do + line+=$(printf ' | %*s' "${width[$d]}" \ + "$(cell "${gbps[$size,$nch,$q,$d]:-}")") + done + echo "$line" + done + done +done +echo +echo "copies $tot_copies of $tot_want, errors $tot_errs, verify failures $tot_vfail" +awk -v t="$(($(date +%s%N) - start_ns))" -v c="$copy_ns" -v i="$idle_ns" 'BEGIN { + printf "time %.1f s: copying %.1f s, idle %.1f s\n", t / 1e9, c / 1e9, i / 1e9 +}' + +if ((failed || tot_errs || tot_vfail || tot_copies != tot_want)); then + exit 1 +fi