Skip to content

Commit 1754dfd

Browse files
damien-lemoalbjorn-helgaas
authored andcommitted
PCI: epf-test: Simplify transfers result print
In pci_epf_test_print_rate(), instead of open coding a reduction loop to allow for a division by a 32-bits ns value, simply use div64_u64() to calculate the transfer rate. To match the printed unit of KB/s, this calculation divides the rate by 1000 instead of 1024 (that would be KiB/s unit). Change the format of the results printed by pci_epf_test_print_rate() to be more compact without the double new line. Also use dev_info() instead of pr_info(). Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Damien Le Moal <[email protected]> Signed-off-by: Lorenzo Pieralisi <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]>
1 parent 2566cbe commit 1754dfd

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

drivers/pci/endpoint/functions/pci-epf-test.c

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -295,34 +295,23 @@ static void pci_epf_test_clean_dma_chan(struct pci_epf_test *epf_test)
295295
return;
296296
}
297297

298-
static void pci_epf_test_print_rate(const char *ops, u64 size,
298+
static void pci_epf_test_print_rate(struct pci_epf_test *epf_test,
299+
const char *op, u64 size,
299300
struct timespec64 *start,
300301
struct timespec64 *end, bool dma)
301302
{
302-
struct timespec64 ts;
303-
u64 rate, ns;
304-
305-
ts = timespec64_sub(*end, *start);
306-
307-
/* convert both size (stored in 'rate') and time in terms of 'ns' */
308-
ns = timespec64_to_ns(&ts);
309-
rate = size * NSEC_PER_SEC;
310-
311-
/* Divide both size (stored in 'rate') and ns by a common factor */
312-
while (ns > UINT_MAX) {
313-
rate >>= 1;
314-
ns >>= 1;
315-
}
316-
317-
if (!ns)
318-
return;
303+
struct timespec64 ts = timespec64_sub(*end, *start);
304+
u64 rate = 0, ns;
319305

320306
/* calculate the rate */
321-
do_div(rate, (uint32_t)ns);
307+
ns = timespec64_to_ns(&ts);
308+
if (ns)
309+
rate = div64_u64(size * NSEC_PER_SEC, ns * 1000);
322310

323-
pr_info("\n%s => Size: %llu bytes\t DMA: %s\t Time: %llu.%09u seconds\t"
324-
"Rate: %llu KB/s\n", ops, size, dma ? "YES" : "NO",
325-
(u64)ts.tv_sec, (u32)ts.tv_nsec, rate / 1024);
311+
dev_info(&epf_test->epf->dev,
312+
"%s => Size: %llu B, DMA: %s, Time: %llu.%09u s, Rate: %llu KB/s\n",
313+
op, size, dma ? "YES" : "NO",
314+
(u64)ts.tv_sec, (u32)ts.tv_nsec, rate);
326315
}
327316

328317
static void pci_epf_test_copy(struct pci_epf_test *epf_test,
@@ -397,7 +386,7 @@ static void pci_epf_test_copy(struct pci_epf_test *epf_test,
397386
kfree(buf);
398387
}
399388
ktime_get_ts64(&end);
400-
pci_epf_test_print_rate("COPY", reg->size, &start, &end,
389+
pci_epf_test_print_rate(epf_test, "COPY", reg->size, &start, &end,
401390
reg->flags & FLAG_USE_DMA);
402391

403392
err_map_addr:
@@ -481,7 +470,7 @@ static void pci_epf_test_read(struct pci_epf_test *epf_test,
481470
ktime_get_ts64(&end);
482471
}
483472

484-
pci_epf_test_print_rate("READ", reg->size, &start, &end,
473+
pci_epf_test_print_rate(epf_test, "READ", reg->size, &start, &end,
485474
reg->flags & FLAG_USE_DMA);
486475

487476
crc32 = crc32_le(~0, buf, reg->size);
@@ -570,7 +559,7 @@ static void pci_epf_test_write(struct pci_epf_test *epf_test,
570559
ktime_get_ts64(&end);
571560
}
572561

573-
pci_epf_test_print_rate("WRITE", reg->size, &start, &end,
562+
pci_epf_test_print_rate(epf_test, "WRITE", reg->size, &start, &end,
574563
reg->flags & FLAG_USE_DMA);
575564

576565
/*

0 commit comments

Comments
 (0)