From patchwork Thu Jan 30 14:22:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 183022 Delivered-To: patches@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp1964872ile; Thu, 30 Jan 2020 06:22:06 -0800 (PST) X-Received: by 2002:a2e:b5cb:: with SMTP id g11mr2928381ljn.210.1580394125995; Thu, 30 Jan 2020 06:22:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580394125; cv=none; d=google.com; s=arc-20160816; b=M0lnpEZqix4kgKKU9FBqEnHjsHEU9oHsmkZVG50kzgjNdtq7tj05RIl+YR3T6r0rBQ 6GPfE52BYc+rV/JPxGjuKyl299roqvAeLSe6eh2olQmyzkP4oR3ARdKIS6/Te7ZZw6MY b+1z8VUIXPjkBi5PUEWSor2wNpESsLpQzyxDAZbuub5bb6qZKDYTUPOk0eb3+JIM4Eha KjvkhvgYp4dwur0RSvSqyuNsU+8bvLdIZXUVjZoU9fWacWQZk/ICtLFr9VGlJR39vpda Af1fBKlT+b/nGI8DXmqQhCx7OSfHKRSxG5e2yQQYX2JJ4zqLWimHKEVH5OuX5e2ESCv3 oPPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=9U/q0/AZVShqwSIJ5XHbOARBIimDxx6cqWeMsQ9sFBA=; b=C4l7WYae4Z4IyU71gJw7UVRfcQFuuvAuqfVSRzVmFxGhuL/QV2+QNcUM28ycpyUEWB eQdnlYtOsWc5NzeesZ/ZuI7Y+/SDZJ/OuLjem4cKma9m6xo3fP7rNeMzD7SpBFXcr85w H2Got67tAoKq5Jn2v9RDdkHFDbGLXtfx7w+oCqPf61NAN0d8JkdNZvHJ8Tinxt1yqRTS mAySkR6EAmSX2150d9dX0lJNG9+eCz+Vx1AtQAv+spQ3RLUEx/03WjvKxCAfIlt8/GZk 0CDa5qFgQ3C3c5sf68QW8lwt/J9e6p8ZK+KtDQGVwT252UF4VLiVmKJbqWoiIPxz3Q+v SyTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="GK91sSM/"; 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 e13sor3897941ljg.18.2020.01.30.06.22.05 for (Google Transport Security); Thu, 30 Jan 2020 06:22:05 -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="GK91sSM/"; 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:mime-version :content-transfer-encoding; bh=9U/q0/AZVShqwSIJ5XHbOARBIimDxx6cqWeMsQ9sFBA=; b=GK91sSM/ycZt5/DrNcDL9wG6LE+kiK7XA9XtM4gmoW2HUbY0l2u310xuJVvySLCqwi VxQjFSiEJvHRtL2ntJk0iEXPSvHBwzpsKHbqnIq+Gytl15B0UEVTkl4klFwQmHfSU6CJ frIOMm0kVj0bHWOAkw6jvTXaH9OswGQtLexYPsiIDVHKmFRYtSD7yJ1WTRgqx9rf+2lt 9LYRRVXAQxhEuy8fxue8Eb1hl6Q6xizcihpwlKTlpoBzfyZPkKhosdh6G7vwuB6LHgKE f4PUUD+174qo5G7YzjsrNu7McvJr0faT9xZDUI9Zm9dQIMAnGM6Q4jaKAD7YQWHdOx60 XMZA== 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:mime-version :content-transfer-encoding; bh=9U/q0/AZVShqwSIJ5XHbOARBIimDxx6cqWeMsQ9sFBA=; b=FjfKVMgv00vqTQx/VBRT7/ta/kTXxDj2CCJU079HMHvvk3bpjGSAM68xYSLOhQLQMq mtH1Vnrkp/17QP1mV38ULDIxc+9dby0QiwmHFGRozZyat/2JnZPGqNZl1B0Bgrw76Jto 5vXq4MSO6yIXdPCkNeYMhUHBNfOkLgtmQ82YijowiNSLhW1GZ6M9Tn0nus96qxPYejpf 4b+v5L6fN+Wudir2ALm7Jfr8nwYJjMimUu/xi4CiZUnO5z4rxIaFvuj3qGzeZktYwM8w bxC6UOX/BrLUI5RXIKp3yLSYu5Zkj/ZiXL85H2p16OUQ8A5c47TS/F0yQhBgFHXfLvec nOUQ== X-Gm-Message-State: APjAAAWcRpy/WgNfcIAGECYiKn7z+HnJC39wqzOs75p/Yyvl5QK4nU7y h0aQ1qrzJcixpOT8l/8Pnww2nOxO X-Google-Smtp-Source: APXvYqwOByEWYs6HfBgE1yTgJFE0cJq1rDVa2Lps8ZCTb7np6fEqsf1X4etSY5HEIneQL9iuCAW4PQ== X-Received: by 2002:a2e:3504:: with SMTP id z4mr3012367ljz.273.1580394125476; Thu, 30 Jan 2020 06:22:05 -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 a28sm2882715lfg.86.2020.01.30.06.22.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 06:22:04 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Chaotian Jing , Shawn Lin , mirq-linux@rere.qmqm.pl Subject: [PATCH] mmc: core: Throttle polling rate for CMD6 Date: Thu, 30 Jan 2020 15:22:01 +0100 Message-Id: <20200130142201.28492-1-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 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 --- Hi all, I have tried this on a ux500 platform (using the mmci mmc host driver), which has two different eMMCs connected to the board. I manually checked that the busy loops during boot for the worst CMD6 case, dropped from around ~50 attempts to around 5-6 attempts, while the total loop time stayed to the similar numbers. In general the loop times I observed for all the CMD6 sent during boot, were in the range of 0 - 900us. Any feedback and of course tests are greatly appreciated! Kind regards Ulf Hansson --- drivers/mmc/core/mmc_ops.c | 8 ++++++++ 1 file changed, 8 insertions(+) -- 2.17.1 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;