From patchwork Tue Feb 4 08:54:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 183056 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp5064143ile; Tue, 4 Feb 2020 00:55:08 -0800 (PST) X-Received: by 2002:a05:651c:448:: with SMTP id g8mr17007807ljg.35.1580806508495; Tue, 04 Feb 2020 00:55:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580806508; cv=none; d=google.com; s=arc-20160816; b=X3F5QnGbRjjwG+7drvam8dL0S9fMuMudrQgNsy2unuc7liF+yJPHP45H1BWyHNbYLE 0nFqhhG9hhOgaFd+zR+U252Z5sZgencfbuUB9vIDr5P33LxzONOwf07ZIbUbpbnM0hjP xY1Dom/Wdrg4ynDt/RiF4dtLSEVVDn47D/AVp730sQY0K2sU9BfTPfNo4ZGz8BH7EIC3 zKXnwdI347KKElegARx7iEQimO/rhWpnNdp21TUySX1wG8958LvNl0wD091sQKn3ZZaw Ohaoj8FESCdP+VpvYFhBk5Zdw0SDWCTIas84bCGuc6t4+EILUs7teDmeUF81JbicNo7p rXEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=vtYL82EUWBDkrP3xF+FQMsvWNrmcMg1IbbGdl9pmLKg=; b=hX2wz60wBdKHl4ySdVOsF5qdjUqTlWdZKYRBN5tgyOlNUMjuAnb8nmWN6M7ORIWIhc iMMxN/v7tPs4wcRQgGerpXHQI3GEIG0jPr3bWWoCIdnW6ZIi75PZEqkOdIPHh2+k5LrR Jl0By7qvmU/VqxkIBHjeGEGK6NwL/Cm9LP6XWfWL3PN9EBHzGwsJbj0CrRzCGH3V47Wf Gbbgy19nNxm0fhXpp4VfimqWE5QAMVQ44YL9BEQ0eKUv2FIx03ivc+CAzZCYNpOZYnq7 uV7msXPgsJFwp6oVuUGmG6iAK1OXdlawfrUCz8TF1IiwDCKM3BciD8/wd072h8rZr142 K+RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i3tDDc6a; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id i11sor12312744ljj.35.2020.02.04.00.55.08 for (Google Transport Security); Tue, 04 Feb 2020 00:55:08 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i3tDDc6a; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vtYL82EUWBDkrP3xF+FQMsvWNrmcMg1IbbGdl9pmLKg=; b=i3tDDc6aNncLBfno+CF9PvHHIe9LC37uz8BU1mB3hoQjRPMCyA818sMS4QVXOcITDi aOBr76AxjAgP4blPOM3eCJR0SxfLPTy85Rr0UiFmTzEKvFd5b3XdDiwjAZt8qOYGE8ND IO1KjvhW3hCtFLSUF9qIv9GUP6vPICSxs3XNonFVP80OlpRJm3EbL1se7otV6D40R8cZ NSbx38+HRnS9/w3MOWOIeKWUOUiirgbNduhbQ6ACapMlhaj6lKhwk+o1ODXS2Wu+IxNf 8yk7rHwj0ccApMqFxv1+q7GJoNjTdQ3anAyimt7kN0IC2moA0yE98rpZ6r4nIb0yAanW PJ+w== 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=vtYL82EUWBDkrP3xF+FQMsvWNrmcMg1IbbGdl9pmLKg=; b=fYWqW4ScEt9HTgPcOoRD5V/+7huOpoCsmcOtnHYFEMQRMR/VTbgUQ7J4KrcFYKYRZ2 Ki7wIcnt4y8DSRCQM1H25EEBjXqm+hBXgyF5SJPunfNvN2NRu//zVcvhSG8R96tt7dgv CxsH6NxPLyle7eilQV7s53Ijun7B0iGKbGceN3XJ4PxarfZgbK4IR/ZwCeHWxm26WmuI 6m+lojs/hP0I4NNMC5xYar7X40vFYVwa1X51VciQpIybS68cCumMzRqsvtsVD9TyJdwX 5IvfSy645bVGB5BvAtSWcnjA4hAA1PlcClVCKkrSoWXOFqxaeEPqSTT5Y/Vvrc9GeObj qruQ== X-Gm-Message-State: APjAAAWzjg/9qtm6yWiQ+vFGrFIxSXaPQ9aoyqjTx50CV39cnsga7bMK gfdT091isGZ6oymPL5M9MszPLarU X-Google-Smtp-Source: APXvYqz5spGAUW9o4w2qNMgMVIQ2JfXKXFKTIuPHMl1XH50sWB5BNVu+ybfkyBGD2CiytzzUTFHinQ== X-Received: by 2002:a05:651c:102c:: with SMTP id w12mr16795849ljm.53.1580806508034; Tue, 04 Feb 2020 00:55:08 -0800 (PST) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id n2sm11156283ljj.1.2020.02.04.00.55.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 00:55:07 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Wolfram Sang , Ludovic Barre , Baolin Wang , Linus Walleij , Chaotian Jing , Shawn Lin , mirq-linux@rere.qmqm.pl Subject: [PATCH 01/12] mmc: core: Throttle polling rate for CMD6 Date: Tue, 4 Feb 2020 09:54:38 +0100 Message-Id: <20200204085449.32585-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200204085449.32585-1-ulf.hansson@linaro.org> References: <20200204085449.32585-1-ulf.hansson@linaro.org> MIME-Version: 1.0 In mmc_poll_for_busy() we loop continuously, either by sending a CMD13 or by invoking the ->card_busy() host ops, as to detect when the card stops signaling busy. This behaviour is problematic as it may cause CPU hogging, especially when the busy signal time reaches beyond a few ms. Let's fix the issue by adding a throttling mechanism, that inserts a usleep_range() in between the polling attempts. The sleep range starts at 16-32us, but increases for each loop by a factor of 2, up until the range reaches ~32-64ms. In this way, we are able to keep the loop fine-grained enough for short busy signaling times, while also not hogging the CPU for longer times. Note that, this change is inspired by the similar throttling mechanism that we already use for mmc_do_erase(). Reported-by: Michał Mirosław Signed-off-by: Ulf Hansson --- drivers/mmc/core/mmc_ops.c | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.17.1 Reviewed-by: Ludovic Barre diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index da425ee2d9bf..446a37cc2a86 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -456,6 +456,7 @@ static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, struct mmc_host *host = card->host; int err; unsigned long timeout; + unsigned int udelay = 32, udelay_max = 32768; u32 status = 0; bool expired = false; bool busy = false; @@ -500,6 +501,13 @@ static int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, mmc_hostname(host), __func__); return -ETIMEDOUT; } + + /* Throttle the polling rate to avoid hogging the CPU. */ + if (busy) { + usleep_range(udelay, udelay * 2); + if (udelay < udelay_max) + udelay *= 2; + } } while (busy); return 0;