From patchwork Fri Mar 17 18:17:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 9631153 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6A6C3602D6 for ; Fri, 17 Mar 2017 18:18:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 658BF2852D for ; Fri, 17 Mar 2017 18:18:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A10C28616; Fri, 17 Mar 2017 18:18:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BEA772852D for ; Fri, 17 Mar 2017 18:18:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751307AbdCQSSM (ORCPT ); Fri, 17 Mar 2017 14:18:12 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:33575 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751221AbdCQSSL (ORCPT ); Fri, 17 Mar 2017 14:18:11 -0400 Received: by mail-pg0-f65.google.com with SMTP id 79so2375880pgf.0 for ; Fri, 17 Mar 2017 11:18:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aqF4zADG6Bp/a6ZpPnUAgjeKo2I3yt4c6/iv34XtAUk=; b=iWYvBiNAcjJ+Brolf08Ff6/leoG/pohamZKw1ZuDoTe4C7ONlMuoQ86cnBOYWU4Zvg EgUnt3Qc9XzN2bQhdykDAA6nuyD2jtk2rPK0uwjccH8C3MxwW+GoTOHJTqPL4EyexRjR G/YiFKHDSGx0I6HdFsjTSG8Ok4KoGQny/NXeKjt6iJt4DrcPECYTZUoYDe7nl25ugolh aF3pcabSjudCYLIEKwLsrTA8TIpcP/1ahLO5tE8FvlGNMq0fonodgaVjNGjepoVObI/f 4ruZANSnbUKun1BWasK6I/Ep6a54gLksjgiaurFIiBPr2TB1g0M1w9JyUJyBy6crXdX4 333w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aqF4zADG6Bp/a6ZpPnUAgjeKo2I3yt4c6/iv34XtAUk=; b=tWSdIRXPjDc8XqBGAQdsGuxPdyQ+WcZ4qZanElU5n56hawju1MFjOidzkJjKydoR9r FgN2y7/OfqK2jpSZVb5w1iVWbJ+MtSF1qqHxcBEyn3M5ouIDHgLPlHkUuvrxh0zauCxV JBtK4CDCsi0QLlHJ8D+AjeGEq9+z9E/r4L63dmnlo3l8vxzysJEhg2HJ8cKQMzqbNwPV DgUnfY4HC9n4sCinLBidPUzU2PNrC6Qfik8HbE1QWMGOlsTI92v7kGNCfNE6p3msMO/Q 29YrgFNnjjC9802njuanjtcCteXwDT0NTAFC4V36R5tzYq+krpoqe2sRdhwmJ5lWd8Wh ampQ== X-Gm-Message-State: AFeK/H1/CNcIX+L+aSrV0Eu5wY5pQynZCIbpPLMkueo7rCqdQRqwd1xxPp5DJMh38HW7BQ== X-Received: by 10.98.110.193 with SMTP id j184mr17857250pfc.228.1489774690241; Fri, 17 Mar 2017 11:18:10 -0700 (PDT) Received: from mita-ThinkPad-T540p.local ([240f:4:c2bc:1:273e:de02:139f:cc26]) by smtp.gmail.com with ESMTPSA id 189sm7104355pgd.39.2017.03.17.11.18.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 17 Mar 2017 11:18:09 -0700 (PDT) From: Akinobu Mita To: linux-spi@vger.kernel.org Cc: Akinobu Mita , Martin Sperl , Mark Brown Subject: [PATCH 5/6] spi: loopback-test: add elapsed time check Date: Sat, 18 Mar 2017 03:17:30 +0900 Message-Id: <1489774651-30170-6-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1489774651-30170-1-git-send-email-akinobu.mita@gmail.com> References: <1489774651-30170-1-git-send-email-akinobu.mita@gmail.com> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Cc: Martin Sperl Cc: Mark Brown Signed-off-by: Akinobu Mita --- drivers/spi/spi-loopback-test.c | 38 ++++++++++++++++++++++++++++++++++++++ drivers/spi/spi-test.h | 2 ++ 2 files changed, 40 insertions(+) diff --git a/drivers/spi/spi-loopback-test.c b/drivers/spi/spi-loopback-test.c index 6df6ddd..66e8cfd0 100644 --- a/drivers/spi/spi-loopback-test.c +++ b/drivers/spi/spi-loopback-test.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -479,6 +480,35 @@ static int spi_check_rx_ranges(struct spi_device *spi, return ret; } +static int spi_test_check_elapsed_time(struct spi_device *spi, + struct spi_test *test) +{ + int i; + unsigned long long estimated_time = 0; + unsigned long long delay_usecs = 0; + + for (i = 0; i < test->transfer_count; i++) { + struct spi_transfer *xfer = test->transfers + i; + unsigned long long nbits = BITS_PER_BYTE * xfer->len; + + delay_usecs += xfer->delay_usecs; + if (!xfer->speed_hz) + continue; + estimated_time += div_u64(nbits * NSEC_PER_SEC, xfer->speed_hz); + } + + estimated_time += delay_usecs * NSEC_PER_USEC; + if (test->elapsed_time < estimated_time) { + dev_err(&spi->dev, + "elapsed time %lld ns is shorter than minimam estimated time %lld ns\n", + test->elapsed_time, estimated_time); + + return -EINVAL; + } + + return 0; +} + static int spi_test_check_loopback_result(struct spi_device *spi, struct spi_message *msg, void *tx, void *rx) @@ -817,12 +847,16 @@ int spi_test_execute_msg(struct spi_device *spi, struct spi_test *test, /* only if we do not simulate */ if (!simulate_only) { + ktime_t start; + /* dump the complete message before and after the transfer */ if (dump_messages == 3) spi_test_dump_message(spi, msg, true); + start = ktime_get(); /* run spi message */ ret = spi_sync(spi, msg); + test->elapsed_time = ktime_to_ns(ktime_sub(ktime_get(), start)); if (ret == -ETIMEDOUT) { dev_info(&spi->dev, "spi-message timed out - reruning...\n"); @@ -848,6 +882,10 @@ int spi_test_execute_msg(struct spi_device *spi, struct spi_test *test, /* run rx-buffer tests */ ret = spi_test_check_loopback_result(spi, msg, tx, rx); + if (ret) + goto exit; + + ret = spi_test_check_elapsed_time(spi, test); } /* if requested or on error dump message (including data) */ diff --git a/drivers/spi/spi-test.h b/drivers/spi/spi-test.h index 82fff4a..6ed7b89 100644 --- a/drivers/spi/spi-test.h +++ b/drivers/spi/spi-test.h @@ -75,6 +75,7 @@ * @fill_option: define the way how tx_buf is filled * @fill_pattern: fill pattern to apply to the tx_buf * (used in some of the @fill_options) + * @elapsed_time: elapsed time in nanoseconds */ struct spi_test { @@ -108,6 +109,7 @@ struct spi_test { #define FILL_TRANSFER_BYTE_32 11 /* fill with the transfer byte - 32 bit */ #define FILL_TRANSFER_NUM 16 /* fill with the transfer number */ u32 fill_pattern; + unsigned long long elapsed_time; }; /* default implementation for @spi_test.run_test */