Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spi: loopback-test: add elapsed time check

This adds checks whether the elapsed time is longer than the minimam
estimated time. The estimated time is calculated with the total
transfer length per clock rate and optional spi_transfer.delay_usecs.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Akinobu Mita and committed by
Mark Brown
ea9936f3 0bd7fda5

+40
+38
drivers/spi/spi-loopback-test.c
··· 20 20 21 21 #include <linux/delay.h> 22 22 #include <linux/kernel.h> 23 + #include <linux/ktime.h> 23 24 #include <linux/list.h> 24 25 #include <linux/list_sort.h> 25 26 #include <linux/module.h> ··· 480 479 return ret; 481 480 } 482 481 482 + static int spi_test_check_elapsed_time(struct spi_device *spi, 483 + struct spi_test *test) 484 + { 485 + int i; 486 + unsigned long long estimated_time = 0; 487 + unsigned long long delay_usecs = 0; 488 + 489 + for (i = 0; i < test->transfer_count; i++) { 490 + struct spi_transfer *xfer = test->transfers + i; 491 + unsigned long long nbits = BITS_PER_BYTE * xfer->len; 492 + 493 + delay_usecs += xfer->delay_usecs; 494 + if (!xfer->speed_hz) 495 + continue; 496 + estimated_time += div_u64(nbits * NSEC_PER_SEC, xfer->speed_hz); 497 + } 498 + 499 + estimated_time += delay_usecs * NSEC_PER_USEC; 500 + if (test->elapsed_time < estimated_time) { 501 + dev_err(&spi->dev, 502 + "elapsed time %lld ns is shorter than minimam estimated time %lld ns\n", 503 + test->elapsed_time, estimated_time); 504 + 505 + return -EINVAL; 506 + } 507 + 508 + return 0; 509 + } 510 + 483 511 static int spi_test_check_loopback_result(struct spi_device *spi, 484 512 struct spi_message *msg, 485 513 void *tx, void *rx) ··· 847 817 848 818 /* only if we do not simulate */ 849 819 if (!simulate_only) { 820 + ktime_t start; 821 + 850 822 /* dump the complete message before and after the transfer */ 851 823 if (dump_messages == 3) 852 824 spi_test_dump_message(spi, msg, true); 853 825 826 + start = ktime_get(); 854 827 /* run spi message */ 855 828 ret = spi_sync(spi, msg); 829 + test->elapsed_time = ktime_to_ns(ktime_sub(ktime_get(), start)); 856 830 if (ret == -ETIMEDOUT) { 857 831 dev_info(&spi->dev, 858 832 "spi-message timed out - reruning...\n"); ··· 882 848 883 849 /* run rx-buffer tests */ 884 850 ret = spi_test_check_loopback_result(spi, msg, tx, rx); 851 + if (ret) 852 + goto exit; 853 + 854 + ret = spi_test_check_elapsed_time(spi, test); 885 855 } 886 856 887 857 /* if requested or on error dump message (including data) */
+2
drivers/spi/spi-test.h
··· 75 75 * @fill_option: define the way how tx_buf is filled 76 76 * @fill_pattern: fill pattern to apply to the tx_buf 77 77 * (used in some of the @fill_options) 78 + * @elapsed_time: elapsed time in nanoseconds 78 79 */ 79 80 80 81 struct spi_test { ··· 109 108 #define FILL_TRANSFER_BYTE_32 11 /* fill with the transfer byte - 32 bit */ 110 109 #define FILL_TRANSFER_NUM 16 /* fill with the transfer number */ 111 110 u32 fill_pattern; 111 + unsigned long long elapsed_time; 112 112 }; 113 113 114 114 /* default implementation for @spi_test.run_test */