Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp339987pxx; Wed, 28 Oct 2020 06:15:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwr271gLorhclct/7PPT39KsJZy3J+/NyRmMyaJZo8JepJxCUxhoEMgvVc5JpoIBX4Qq1p X-Received: by 2002:a17:906:1959:: with SMTP id b25mr7857276eje.283.1603890940676; Wed, 28 Oct 2020 06:15:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603890940; cv=none; d=google.com; s=arc-20160816; b=LmX7nCWAXBPRTH3NoDOPHsGj6dAAQXbuL5HXEhUz2tS3UOreOeGQUvXkmysJ0zNKIN q7JuHu4UPYZeEiadmv9jXkRWInCpKRrRRflyoQSbgBf8Himlaty6SvRyEPBW4e/ee3LV m8hrjjxQiM5AHrGGh1QC++eyix9iUlOh2Cp7uvdrLU7ReluucFJp3Mk4eKiBpj7Hz6dm JRRSxmZYXkndxRDiLjK5rh4gdCtxjr6KVCEbunGoZDosN+vqKvOGOoPkatTcXkZh9XD1 MCjlX4LK48gBs6xhK7Pxa2bmLWs7Juw5Mq7Jfi9PloOZK/s/MjlkH0Y4swUh9dgBLAeC SamA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1NO9JXPZ7wBja0UCiqf8dY0BHu/81k6svF64YH/zfGU=; b=cp8Kyyj45Vu57ZM5Xv7yVhPoT6StwgC7nFOLD/yy6yRYzmO2g4BQqhHQXnIhKWtcRL AfB6n9GWptuF2AzulTyruf0B8QvMKL8PVu1jrfn9m2ob3w1lHgwUMmHESr7J2boHINo1 +jtggk41I+lu2k/37CWh30XIVPin1dFAkWLgz/vuVWl59S2GdMboKkgjiQUSwCico5lh IbtLOEvmBQigX61PgiVRvr0HoOg5fwoVW96+oSt4SY5/+zGOlvq5K4r/xrAhoP3iRw6+ TxaJ3PeTNH5Lmom+7K9LqYZWLjZO1ZLvdxAU6vYTxdD4IOsijuDFcHgQEC45NMrXCgrT PrRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0cQM3huz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jr1si3058858ejb.164.2020.10.28.06.15.17; Wed, 28 Oct 2020 06:15:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0cQM3huz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1800313AbgJ0Pfk (ORCPT + 99 others); Tue, 27 Oct 2020 11:35:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:48668 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1799474AbgJ0Pbk (ORCPT ); Tue, 27 Oct 2020 11:31:40 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BDBA422264; Tue, 27 Oct 2020 15:31:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603812700; bh=e9SVoFbq5ETpwePvF57nUUU5bTuA6KMHrIicaCLdtNY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0cQM3huzdORRZXktEG6TwnAd+JLaUn2cPj+Fkm3pqKb+uUxup1gPdMCgbI9gAPdS4 quDkkHOoV9OiORbJXNLPmvl6B/JB5yi1h7YMUKj3x1kkmJJ3SK3zill5F8bXddb0/0 9VNQEGCXqPzTwErmG+PZinpVZrndvzBzui23dnCo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aswath Govindraju , Mark Brown , Sasha Levin Subject: [PATCH 5.9 300/757] spi: omap2-mcspi: Improve performance waiting for CHSTAT Date: Tue, 27 Oct 2020 14:49:10 +0100 Message-Id: <20201027135504.631695169@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135450.497324313@linuxfoundation.org> References: <20201027135450.497324313@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Aswath Govindraju [ Upstream commit 7b1d96813317358312440d0d07abbfbeb0ef8d22 ] This reverts commit 13d515c796 (spi: omap2-mcspi: Switch to readl_poll_timeout()). The amount of time spent polling for the MCSPI_CHSTAT bits to be set on AM335x-icev2 platform is less than 1us (about 0.6us) in most cases, with or without using DMA. So, in most cases the function need not sleep. Also, setting the sleep_usecs to zero would not be optimal here because ktime_add_us() used in readl_poll_timeout() is slower compared to the direct addition used after the revert. So, it is sub-optimal to use readl_poll_timeout in this case. When DMA is not enabled, this revert results in an increase of about 27% in throughput and decrease of about 20% in CPU usage. However, the CPU usage and throughput are almost the same when used with DMA. Therefore, fix this by reverting the commit which switched to using readl_poll_timeout(). Fixes: 13d515c796ad ("spi: omap2-mcspi: Switch to readl_poll_timeout()") Signed-off-by: Aswath Govindraju Link: https://lore.kernel.org/r/20200910122624.8769-1-a-govindraju@ti.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-omap2-mcspi.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c index 1c9478e6e5d99..d4c9510af3931 100644 --- a/drivers/spi/spi-omap2-mcspi.c +++ b/drivers/spi/spi-omap2-mcspi.c @@ -24,7 +24,6 @@ #include #include #include -#include #include @@ -348,9 +347,19 @@ static void omap2_mcspi_set_fifo(const struct spi_device *spi, static int mcspi_wait_for_reg_bit(void __iomem *reg, unsigned long bit) { - u32 val; - - return readl_poll_timeout(reg, val, val & bit, 1, MSEC_PER_SEC); + unsigned long timeout; + + timeout = jiffies + msecs_to_jiffies(1000); + while (!(readl_relaxed(reg) & bit)) { + if (time_after(jiffies, timeout)) { + if (!(readl_relaxed(reg) & bit)) + return -ETIMEDOUT; + else + return 0; + } + cpu_relax(); + } + return 0; } static int mcspi_wait_for_completion(struct omap2_mcspi *mcspi, -- 2.25.1