Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1062472ybt; Wed, 1 Jul 2020 17:46:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4Z0mOTchQqcTkQzR6zdBxmQuiwkehiJLKfYamj8oRFMBi90y4U+y7uvET+sqvNppdFI5S X-Received: by 2002:a17:906:f20d:: with SMTP id gt13mr500352ejb.117.1593650804455; Wed, 01 Jul 2020 17:46:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593650804; cv=none; d=google.com; s=arc-20160816; b=pBOv++VeAG1VNCekluEgRO/FgTXxl17NP0Snr7Uf7j1zQBbt8+kocZ86CXkPF3OvLC X/i7kg593/2zCKgBZSgxnuObCV/eWXeiC9XnRpo9wJ/w8bNzx5E0LQiENPrNznQQ6E3y svHTFCtb1UckJH7uLa2dZfMQqtWsELkxHPlEuFoSSAT85frPMnh7l25CJ885ZDuBIv3X 5CE6kOQKc0iAexBFwOgDcKPsqgPonOpFeetqWuo5PNOn1Ps8fcKdkCo/WC34g+cHH7we aE/dhu2NecP1cd3QLB92HtiT0H+YgPdHeba6ETMllRnISGGmF6qM4j34f8mSdPoTfXZy kXkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jkGcjxRkJ6dCPuaybiPstZAyKU85uMADDKqqgUxYero=; b=vplFIYnT0y/ZoD0k9hX6ScUjtBvpsnIIW/aAKDn59me37hDQMUvpuWd/uU1489brxO YmThoqzxKm7J0UajDmr/0TKdM729AuEyJxABoT/FuVBc6G/M5AYQkjXIJ5B/htIEieUH UN8EOIdsm7ZPrEcp9FHu7KXNETfCFSCkIZjf++4PzEbKRkGP9R1SkGTDE4SbeZw5AgPM Ka7HUvDO0OA4DIZUYyCDRuRs7ED2YsgM9vO+eZnQ8lcVfXc9x2+IWFF9ldmqdX0ycO/a ZxvlS8pist5Hx2H/sjWfIeqtSXL5ZzkaBEOJJPnW2Pa6UO8SwutZ/XVmXKajZpJmPhez 5nPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AKIHQJeQ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id do11si6289128ejc.450.2020.07.01.17.46.22; Wed, 01 Jul 2020 17:46:44 -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=@chromium.org header.s=google header.b=AKIHQJeQ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728106AbgGBApq (ORCPT + 99 others); Wed, 1 Jul 2020 20:45:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728003AbgGBApe (ORCPT ); Wed, 1 Jul 2020 20:45:34 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DE86C08C5DC for ; Wed, 1 Jul 2020 17:45:34 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id l6so8576754pjq.1 for ; Wed, 01 Jul 2020 17:45:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jkGcjxRkJ6dCPuaybiPstZAyKU85uMADDKqqgUxYero=; b=AKIHQJeQnAOPNI2gGQrvqd9S3Y7bK1oz1xUxjXASgco2p5Jnkbd+JOewpSZ4lCXVg4 onxJ3xvwbcwmLysRT7TDcyysWiMh4Ozitkz6tPoOlIS40R2T00KA+cqLdghcXBdL8FnW jveDSJpqRdDLw9TAHu5CGsM5eclZzjtUsdpOU= 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:mime-version:content-transfer-encoding; bh=jkGcjxRkJ6dCPuaybiPstZAyKU85uMADDKqqgUxYero=; b=GnouTTV7znOAL381qSCIny8xkIqSB8FWyrXATANucH6iUGoXhGfvyWWBJTsvFc6Bky h54XWo5c0w/m2GaRYZ+lETZEMiRxxSfu8kV1Lk2Ju2RzrK+n7omKI7NUuM9yolvXi5wq D5TdTdQKzjnKgVz4Y5qDbA393DSm78bXdFjODEpU/qS3BXRpRE76U4ioyVQ6y0/bvne+ awq6fP1/Odqu+ykM2bdu0i9/mQpI2nDNTZs3HyP1d02YszC+B7nt2pFnq2lqs+33icfl I1S2y/4ERraq4WRMFfA9gkuJxsmwzO/9UtdrLH6EqOKaGnXoiqhxcmtiBH3c3LT9GDbb j7iQ== X-Gm-Message-State: AOAM531bh4fxLojF8Ao9Gw7tlgfsAii9QroSfjcHapsacbYq4CcJo5uA NPDKLWhdeBdMEZv+xamiM79mWw== X-Received: by 2002:a17:902:b216:: with SMTP id t22mr23734470plr.181.1593650733748; Wed, 01 Jul 2020 17:45:33 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:42b0:34ff:fe3d:58e6]) by smtp.gmail.com with ESMTPSA id w4sm6966212pfd.39.2020.07.01.17.45.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2020 17:45:33 -0700 (PDT) From: Douglas Anderson To: Mark Brown , Andy Gross , Bjorn Andersson Cc: akashast@codeaurora.org, linux-arm-msm@vger.kernel.org, mkshah@codeaurora.org, swboyd@chromium.org, georgi.djakov@linaro.org, ctheegal@codeaurora.org, mka@chromium.org, Douglas Anderson , linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org Subject: [PATCH 1/3] spi: spi-geni-qcom: Avoid clock setting if not needed Date: Wed, 1 Jul 2020 17:45:07 -0700 Message-Id: <20200701174506.1.Icfdcee14649fc0a6c38e87477b28523d4e60bab3@changeid> X-Mailer: git-send-email 2.27.0.383.g050319c2ae-goog In-Reply-To: <20200702004509.2333554-1-dianders@chromium.org> References: <20200702004509.2333554-1-dianders@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Every SPI transfer could have a different clock rate. The spi-geni-qcom controller code to deal with this was never very well optimized and has always had a lot of code plus some calls into the clk framework which, at the very least, would grab a mutex. However, until recently, the overhead wasn't _too_ much. That changed with commit 0e3b8a81f5df ("spi: spi-geni-qcom: Add interconnect support") we're now calling geni_icc_set_bw(), which leads to a bunch of math plus: geni_icc_set_bw() icc_set_bw() apply_constraints() qcom_icc_set() qcom_icc_bcm_voter_commit() rpmh_invalidate() rpmh_write_batch() ...and those rpmh commands can be a bit beefy if you call them too often. We already know what speed we were running at before, so if we see that nothing has changed let's avoid the whole pile of code. On my hardware, this made spi_geni_prepare_message() drop down from ~145 us down to ~14 us. NOTE: Potentially it might also make sense to add some code into the interconnect framework to avoid executing so much code when bandwidth isn't changing, but even if we did that we still want to short circuit here to save the extra math / clock calls. Fixes: 0e3b8a81f5df ("spi: spi-geni-qcom: Add interconnect support") Signed-off-by: Douglas Anderson --- drivers/spi/spi-geni-qcom.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi-geni-qcom.c b/drivers/spi/spi-geni-qcom.c index e01c782ef7d0..bb4cdda2dec8 100644 --- a/drivers/spi/spi-geni-qcom.c +++ b/drivers/spi/spi-geni-qcom.c @@ -201,6 +201,9 @@ static int geni_spi_set_clock_and_bw(struct spi_geni_master *mas, struct geni_se *se = &mas->se; int ret; + if (clk_hz == mas->cur_speed_hz) + return 0; + ret = get_spi_clk_cfg(clk_hz, mas, &idx, &div); if (ret) { dev_err(mas->dev, "Err setting clk to %lu: %d\n", clk_hz, ret); @@ -339,11 +342,9 @@ static void setup_fifo_xfer(struct spi_transfer *xfer, } /* Speed and bits per word can be overridden per transfer */ - if (xfer->speed_hz != mas->cur_speed_hz) { - ret = geni_spi_set_clock_and_bw(mas, xfer->speed_hz); - if (ret) - return; - } + ret = geni_spi_set_clock_and_bw(mas, xfer->speed_hz); + if (ret) + return; mas->tx_rem_bytes = 0; mas->rx_rem_bytes = 0; -- 2.27.0.383.g050319c2ae-goog