Skip to content

Commit 5893c2e

Browse files
kishonLorenzo Pieralisi
authored andcommitted
PCI: endpoint: functions/pci-epf-test: Print throughput information
Print throughput information in KB/s after every completed transfer, including information on whether DMA is used or not. Signed-off-by: Kishon Vijay Abraham I <[email protected]> Signed-off-by: Lorenzo Pieralisi <[email protected]> Tested-by: Alan Mikhak <[email protected]>
1 parent 5ebf3fc commit 5893c2e

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,36 @@ static void pci_epf_test_clean_dma_chan(struct pci_epf_test *epf_test)
190190
epf_test->dma_chan = NULL;
191191
}
192192

193+
static void pci_epf_test_print_rate(const char *ops, u64 size,
194+
struct timespec64 *start,
195+
struct timespec64 *end, bool dma)
196+
{
197+
struct timespec64 ts;
198+
u64 rate, ns;
199+
200+
ts = timespec64_sub(*end, *start);
201+
202+
/* convert both size (stored in 'rate') and time in terms of 'ns' */
203+
ns = timespec64_to_ns(&ts);
204+
rate = size * NSEC_PER_SEC;
205+
206+
/* Divide both size (stored in 'rate') and ns by a common factor */
207+
while (ns > UINT_MAX) {
208+
rate >>= 1;
209+
ns >>= 1;
210+
}
211+
212+
if (!ns)
213+
return;
214+
215+
/* calculate the rate */
216+
do_div(rate, (uint32_t)ns);
217+
218+
pr_info("\n%s => Size: %llu bytes\t DMA: %s\t Time: %llu.%09u seconds\t"
219+
"Rate: %llu KB/s\n", ops, size, dma ? "YES" : "NO",
220+
(u64)ts.tv_sec, (u32)ts.tv_nsec, rate / 1024);
221+
}
222+
193223
static int pci_epf_test_copy(struct pci_epf_test *epf_test)
194224
{
195225
int ret;
@@ -198,6 +228,7 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test)
198228
void __iomem *dst_addr;
199229
phys_addr_t src_phys_addr;
200230
phys_addr_t dst_phys_addr;
231+
struct timespec64 start, end;
201232
struct pci_epf *epf = epf_test->epf;
202233
struct device *dev = &epf->dev;
203234
struct pci_epc *epc = epf->epc;
@@ -236,6 +267,7 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test)
236267
goto err_dst_addr;
237268
}
238269

270+
ktime_get_ts64(&start);
239271
use_dma = !!(reg->flags & FLAG_USE_DMA);
240272
if (use_dma) {
241273
if (!epf_test->dma_supported) {
@@ -251,6 +283,8 @@ static int pci_epf_test_copy(struct pci_epf_test *epf_test)
251283
} else {
252284
memcpy(dst_addr, src_addr, reg->size);
253285
}
286+
ktime_get_ts64(&end);
287+
pci_epf_test_print_rate("COPY", reg->size, &start, &end, use_dma);
254288

255289
err_map_addr:
256290
pci_epc_unmap_addr(epc, epf->func_no, dst_phys_addr);
@@ -277,6 +311,7 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test)
277311
bool use_dma;
278312
phys_addr_t phys_addr;
279313
phys_addr_t dst_phys_addr;
314+
struct timespec64 start, end;
280315
struct pci_epf *epf = epf_test->epf;
281316
struct device *dev = &epf->dev;
282317
struct pci_epc *epc = epf->epc;
@@ -322,17 +357,23 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test)
322357
goto err_dma_map;
323358
}
324359

360+
ktime_get_ts64(&start);
325361
ret = pci_epf_test_data_transfer(epf_test, dst_phys_addr,
326362
phys_addr, reg->size);
327363
if (ret)
328364
dev_err(dev, "Data transfer failed\n");
365+
ktime_get_ts64(&end);
329366

330367
dma_unmap_single(dma_dev, dst_phys_addr, reg->size,
331368
DMA_FROM_DEVICE);
332369
} else {
370+
ktime_get_ts64(&start);
333371
memcpy_fromio(buf, src_addr, reg->size);
372+
ktime_get_ts64(&end);
334373
}
335374

375+
pci_epf_test_print_rate("READ", reg->size, &start, &end, use_dma);
376+
336377
crc32 = crc32_le(~0, buf, reg->size);
337378
if (crc32 != reg->checksum)
338379
ret = -EIO;
@@ -358,6 +399,7 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test)
358399
bool use_dma;
359400
phys_addr_t phys_addr;
360401
phys_addr_t src_phys_addr;
402+
struct timespec64 start, end;
361403
struct pci_epf *epf = epf_test->epf;
362404
struct device *dev = &epf->dev;
363405
struct pci_epc *epc = epf->epc;
@@ -406,17 +448,23 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test)
406448
goto err_dma_map;
407449
}
408450

451+
ktime_get_ts64(&start);
409452
ret = pci_epf_test_data_transfer(epf_test, phys_addr,
410453
src_phys_addr, reg->size);
411454
if (ret)
412455
dev_err(dev, "Data transfer failed\n");
456+
ktime_get_ts64(&end);
413457

414458
dma_unmap_single(dma_dev, src_phys_addr, reg->size,
415459
DMA_TO_DEVICE);
416460
} else {
461+
ktime_get_ts64(&start);
417462
memcpy_toio(dst_addr, buf, reg->size);
463+
ktime_get_ts64(&end);
418464
}
419465

466+
pci_epf_test_print_rate("WRITE", reg->size, &start, &end, use_dma);
467+
420468
/*
421469
* wait 1ms inorder for the write to complete. Without this delay L3
422470
* error in observed in the host system.

0 commit comments

Comments
 (0)