Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1110904pxx; Tue, 27 Oct 2020 08:29:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRfpPzrAYbQiHwCrlNrpXBG6eJz6DrxClSdelLnpgPGs/QS/h4FX6OYJX1A0QhQBJlQ8+0 X-Received: by 2002:a17:906:383:: with SMTP id b3mr2841747eja.351.1603812565487; Tue, 27 Oct 2020 08:29:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603812565; cv=none; d=google.com; s=arc-20160816; b=wPBcqdGd0q9AEHX69qbIE096QgTe3FJFz/nP59WZCFQnggso+Y7gdrd3Nl8fb0CB80 ybE5WDLF5m5JfmLLA9UfUYe9wGdMYXMDBLK92Vd6k/PDaAA76agLPj+QQRoov3RPx0RT I7TSj74v4ZscNdbGXfDQSP6l70IlsT83y0+Ig7Uef1U1H8sJTxji2/YzUGgFWNMubmQF w9dmAF2q7mwX3VKy4m4iWSXKe5bFHrsdjOLnlUGqu1dpXovr/2t7vp9R5qsJTTBUV3d6 NVuclzx+Nd54EJQZUEdeLUnN3m1O2wpcVOIo9Vw7JuKvF0ZBPe2Xp33vZO6lD5qedoR8 2JRA== 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=j9ADwMMyVAyi/reLoq+aV+RaJ2/gWuv4xX/9e2gR/8o=; b=WEEHJpOtitQd5FG/hRZOpKTrn+GlAJUvXrYnHj+AW4Ze8XHOKA0l8FukIDhxnkr9n5 lubiaSHh/d1k4b8dweP08ZsYsSKGsROXh6/SW1Eu24Jm2D9m3RWJRYvh3DAEk5rSN8hn aYPSiPKllUwmFVKlOxS7rncaS603Hd7ajUfmagCtMThvWAY+H3/KmLvV5pRH+7S+Z3tP Dlzy4YdcKNvcvtVjVIjMxJMKMc7IPmnCHuyAPHcvMV1yNGHUBpjYuQ1WO+LV7qkffvwY iZDGiQeiJOqlT4TgRqP85aYiTf5CJZghVPXUbNkZJwIvYRX6/dTC/Gb90o3McVykb3cT Nz8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iEqnzTm9; 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 i2si1145425edt.203.2020.10.27.08.29.03; Tue, 27 Oct 2020 08:29:25 -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=iEqnzTm9; 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 S1760728AbgJ0OgK (ORCPT + 99 others); Tue, 27 Oct 2020 10:36:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:34214 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760619AbgJ0Ofa (ORCPT ); Tue, 27 Oct 2020 10:35:30 -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 E6178207BB; Tue, 27 Oct 2020 14:35:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809329; bh=EgbG8939x54jC/rOVlyRwTqvBNMYsEeSwPgAzubUMt8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iEqnzTm9k6/fE68E2M+RRuVJtueFdAfPoMAUgv8gzCzvQ33CSY6Uv7y8cuizU38Oy tvoQ002O3EmPMZSw9eGyCWUJMbkD+Jxm2yvDl/m+LdCHMaq9zwlA5J5mFG+gkZ8xIh dgIpyniNzpsdz5N554UE9/EBgmJVntgCUt5ndmOA= 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.4 158/408] spi: omap2-mcspi: Improve performance waiting for CHSTAT Date: Tue, 27 Oct 2020 14:51:36 +0100 Message-Id: <20201027135502.423189837@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@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 4433cb4de564e..7646b4b56bed9 100644 --- a/drivers/spi/spi-omap2-mcspi.c +++ b/drivers/spi/spi-omap2-mcspi.c @@ -24,7 +24,6 @@ #include #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