From patchwork Fri Jul 2 13:42:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 469551 Delivered-To: patches@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1400691jao; Fri, 2 Jul 2021 06:42:44 -0700 (PDT) X-Received: by 2002:a05:651c:504:: with SMTP id o4mr3847572ljp.357.1625233364775; Fri, 02 Jul 2021 06:42:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625233364; cv=none; d=google.com; s=arc-20160816; b=hHghLU+psGyJjOll8ssemNI+yfI94PUnToltP9ip+uHCSCLpHJOqJ7DDSpAY1N5F15 jPzkXRgZm4XYtOMQYSviE0ltlEtWDoK66CfZNirp30ZlMFu5EOS9BRYy+IK+LE5FbeH1 l2rgwyOZiVMmGWdV8eFkOQ+zyMd9MO35LMDIK6a3qLuIPVlxVucbHBPz+4Kp1Dw7naBr QHNiEQfYu0QnQxkstbfDqvDODBUNlSfPmt25ijc/Fd11E6DabGw6rYb90yvDqvdfZEvW TfI1pu0gTTFURY3EkQX+pjaDaKGbmoJ/SWxiWZDEZySVT8s9iZl6v528iZ0VIb7TfPhl XeNA== 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=3pL4MvxeWog2IfLGYd7eKX1l2HS5OPUQFZV3aIXsKoU=; b=XRHX3xcuJuV/3/wtYSDAtq4yAGaIBApSZ2gpwcUz7tsjdQ1wohzhVtVSurbw/jd+zJ QFrsX1f2KToWCAZ/vflVXgocYaod7ZnAtyvZPAuZazEzM+7gecwKlCaRQdz6FxABb9eR 1VLFRMFp0Q+xWomK+59reauiyZ+tm14ErABYOqtayyrX8aohpZkLPscFVwiR04nXzCCg QQegBXBAVNXIB87SXCg48idPY880lln40fCr2Q8/IJWQwbXP8lqFp9j24wre1K91+nQm 5zaG4b5SLzciSw0remoMm77vKxenYAx1vYGyXfvbptD4iY3gu8fDKhHbM2gS+FmpKbtW M/Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nv08IjPc; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 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-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id r10sor1386449ljc.58.2021.07.02.06.42.44 for (Google Transport Security); Fri, 02 Jul 2021 06:42:44 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nv08IjPc; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 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=3pL4MvxeWog2IfLGYd7eKX1l2HS5OPUQFZV3aIXsKoU=; b=nv08IjPcm+Hty4Sfpv6VlE2MwUc+YQ6djusyBTlemq2QO4zTYkE5Wliw8U9hmoCNH6 +8OoyCP2c0aigcm2jF8FsL2zPS6ew+KDiNDtTKLepR8Mf9f5x1m+ldINo5Qeqkk/M0Z+ k1b7E6CH4JqzukdAFcOHdOT0YmNi7+rCpogKoz0HLPCbHL4wlBTXrl/5wVPUAn3zI41s DHchW5QY943HsLRExewAcTc9iLyElLN7nVViRLAqyttIbanU973GIDlQtTfxcxfJrqbN S9/9gk9+8T8iCxwVIOSsgXbxWT3YK1xkIhDzUbKDjMOfqvaioD2TYsuOQ8Nin85Wyr4o Psdw== 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=3pL4MvxeWog2IfLGYd7eKX1l2HS5OPUQFZV3aIXsKoU=; b=L6z26igsY3B2BPoUU8GV7UsO83eiSWveFHnaj42aRhq3z14QGO7JbCJpdcOoTM0ve8 d/x1VIvOTccLcFUt8dINSaE1H8xCGptCXoxz8TmFvlngxNkkEx+HuHXij10IGxykN6+b y1oAxVnsyhNnILV8E5ZxUmKccHOtAc9Vr/A2R1i27BuBP/hX0b5OFnuZ5xoi9x7qBnWJ 9uPDlJXAz0GHsimqknEl3MEN27wY7wCKK4IVdOYvKYty/NbADbtWx3WQajxaUgWstolq xOiZ3seSw3btkCc/IrkzfXZfJIEV8ST/i6wzr3Yi+jyOT7iUz3pXlmrzEQJP5FmIL28Q 4c+w== X-Gm-Message-State: AOAM531HEymBywyc5XwwBUP1SWnaWcjKXhrS5EXb/yy+jAOKPjh5SDZQ AzjLkbJ5JejK9HPWIcs2u/0Ngei7 X-Google-Smtp-Source: ABdhPJwD0eRwhqZIHnQ52EyyAN9A8UlJ0xC8X2hYvZ5HvnpXibYcI5DKr+pTGJkxqY2tl1jB1dynPA== X-Received: by 2002:a2e:804d:: with SMTP id p13mr3936926ljg.324.1625233364409; Fri, 02 Jul 2021 06:42:44 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-155-4-129-146.NA.cust.bahnhof.se. [155.4.129.146]) by smtp.gmail.com with ESMTPSA id u5sm277486lfg.268.2021.07.02.06.42.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jul 2021 06:42:43 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Linus Walleij , Wolfram Sang , Shawn Lin , Christian Lohle , linux-kernel@vger.kernel.org Subject: [PATCH 1/3] mmc: core: Avoid hogging the CPU while polling for busy in the I/O err path Date: Fri, 2 Jul 2021 15:42:27 +0200 Message-Id: <20210702134229.357717-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210702134229.357717-1-ulf.hansson@linaro.org> References: <20210702134229.357717-1-ulf.hansson@linaro.org> MIME-Version: 1.0 When mmc_blk_fix_state() sends a CMD12 to try to move the card into the transfer state, it calls card_busy_detect() to poll for the card's state with CMD13. This is done without any delays in between the commands being sent. Rather than fixing card_busy_detect() in this regards, let's instead convert into using the common mmc_poll_for_busy(), which also helps us to avoid open-coding. Signed-off-by: Ulf Hansson --- drivers/mmc/core/block.c | 2 +- drivers/mmc/core/mmc_ops.c | 4 +++- drivers/mmc/core/mmc_ops.h | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) -- 2.25.1 diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 88f4c215caa6..1b5576048cdb 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -1630,7 +1630,7 @@ static int mmc_blk_fix_state(struct mmc_card *card, struct request *req) mmc_blk_send_stop(card, timeout); - err = card_busy_detect(card, timeout, NULL); + err = mmc_poll_for_busy(card, timeout, false, MMC_BUSY_IO); mmc_retune_release(card->host); diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index 973756ed4016..e2c431c0ce5d 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -435,7 +435,7 @@ static int mmc_busy_cb(void *cb_data, bool *busy) u32 status = 0; int err; - if (host->ops->card_busy) { + if (data->busy_cmd != MMC_BUSY_IO && host->ops->card_busy) { *busy = host->ops->card_busy(host); return 0; } @@ -457,6 +457,7 @@ static int mmc_busy_cb(void *cb_data, bool *busy) break; case MMC_BUSY_HPI: case MMC_BUSY_EXTR_SINGLE: + case MMC_BUSY_IO: break; default: err = -EINVAL; @@ -521,6 +522,7 @@ int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, return __mmc_poll_for_busy(card, timeout_ms, &mmc_busy_cb, &cb_data); } +EXPORT_SYMBOL_GPL(mmc_poll_for_busy); bool mmc_prepare_busy_cmd(struct mmc_host *host, struct mmc_command *cmd, unsigned int timeout_ms) diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h index 41ab4f573a31..ae25ffc2e870 100644 --- a/drivers/mmc/core/mmc_ops.h +++ b/drivers/mmc/core/mmc_ops.h @@ -15,6 +15,7 @@ enum mmc_busy_cmd { MMC_BUSY_ERASE, MMC_BUSY_HPI, MMC_BUSY_EXTR_SINGLE, + MMC_BUSY_IO, }; struct mmc_host; From patchwork Fri Jul 2 13:42:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 469552 Delivered-To: patches@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1400713jao; Fri, 2 Jul 2021 06:42:46 -0700 (PDT) X-Received: by 2002:a2e:91cd:: with SMTP id u13mr3840953ljg.421.1625233366645; Fri, 02 Jul 2021 06:42:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625233366; cv=none; d=google.com; s=arc-20160816; b=q8Uhl8D7oP+90egElvgZsaZiqYHeltBkAtQFzYh9IEaIf5d8FcbTebwLj3rAlvmpEk 8MKlHxuVpMitZXdI5jZ2gdl03ln7FA4HQVyrPKG71lBLLu9glqil6lbXvp8Bsa25u2fE wGHFY5homV5FOKWY1neOj65ZSwMUn1zT89Uxe9/fNOxx+pCsORdOfpdg8Fo9vXvU6ibF S/+F59lbTRDhe/A1daQLGzmcL4EAJRBsdTsBIOPu3Ea22SWADox4R1qnwU3RxNvI6eyy J853B9kNM2wbDkHPZBA7o+xy/k7iJzVzd6tXw94yhTYmAsoLj6wEyJHJf9sLYqymsjW9 rTWw== 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=NoI9BTrBB2j37D3MNXSwVMTEwSv5M2czDJC0Zd1MVQU=; b=ApTCXgN/l5c8ULkvCnZ2autujCfUjPFRXe5q0bjOyy3fgnlpqi7uN8DfM8QPU5hlWa L3jvmSgFBqHi5Yg5RuoNTjS1mmrtQOS84DMBlDM71FEEYyFXiovcX08mKWYsLtxjONiw UqHFnXE8s11q/I1cpiMGKnbjLCtRJreHkN5qaBL7rZi/9rP5lcOXI231nZBWOUL/mihO XOlGg5mmWxSsocgh/svEhFcAJgZ2rl1CjEhgwFwofETDJRtxTjh4H3UqMj7U0Mk6anib qhLwqME5n5H/ppEoB7RQgqncIsS6eB7yshoZLPGQIGJwiE9vBqnCk6UH3phVPUm5Aal1 xujQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kIPiqSzO; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 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-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id m11sor822758lfu.93.2021.07.02.06.42.46 for (Google Transport Security); Fri, 02 Jul 2021 06:42:46 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kIPiqSzO; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 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=NoI9BTrBB2j37D3MNXSwVMTEwSv5M2czDJC0Zd1MVQU=; b=kIPiqSzOvGOz6+vds3ovZUM/np0UiY4usyIqfkwIruTbbiB7jfsb59JXiQvjBOtPG7 AzpyvWEpq3Djr5Yw99qCRr57XT9ZMa7NCMpR2FGFZrldljoYSFp1jCpXGut/679U+xF0 eEkjntEQ7xK5R8sZqdkN6AFpKayx8o8lEqK1u8Y//YLck63gs+iJlwnqBpFvuw5/Btny qMFC8MMIAH+2Adr5iOP1x8pPgsjCeeNGzvU/TZ3HZwSdBtavQbNlVJ/N5J6uS0Fe3CBI z9WONDRhmmi7gnhicE8IHWCDegzJ80MMxx79kaNUaB482viXRKR/fm6Aj6azJZJ3KIJk Xe/g== 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=NoI9BTrBB2j37D3MNXSwVMTEwSv5M2czDJC0Zd1MVQU=; b=hC/P0QcU/52NDfTp4ONduvx53CPbNkXt59bCOcl+ticKf0ju+NuGwsExLyhD49n8s5 hQA6ApdrK41U8jVMv4Ls1wbB4/weQl6tE3y97YfW3/p86s+i0TRP9fDF2wSdRMMkTCtB Q6ApyzqrPJQTraJZAPs10gEM+Ki484wRkyp0deb7GmdGtRy7FHsyVH031P2vWdcnpT5E wolUmgpCHiQ0m0lJt8A0BdIYQ98/0XrwGXg9gy7jroXRDBF7geVQ7xYMC/fnezRV/0se sYTZKbuEWTPQpCFKp50odL8V1Tz8FzMXXNVcc3Jv794dK9FqQEDNRAgLhSAhFe3Xsk28 tzaA== X-Gm-Message-State: AOAM532HjhWHv8PEpLkodTIuS5X/Md+TKQ8vcmuRh1bjSK5y+aCZXpbi AzvVMMTJ2+qr8QbTiWVai3vWjoLr X-Google-Smtp-Source: ABdhPJwJOqCe7efbM/lMcm+PNg0kMxyZmH1OrHYVCdAXAbQ8gwaiTDU8d7GiRNDai6Nn/8fCom5gPg== X-Received: by 2002:ac2:42c1:: with SMTP id n1mr3931436lfl.270.1625233366311; Fri, 02 Jul 2021 06:42:46 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-155-4-129-146.NA.cust.bahnhof.se. [155.4.129.146]) by smtp.gmail.com with ESMTPSA id u5sm277486lfg.268.2021.07.02.06.42.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jul 2021 06:42:45 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Linus Walleij , Wolfram Sang , Shawn Lin , Christian Lohle , linux-kernel@vger.kernel.org Subject: [PATCH 2/3] mmc: core: Avoid hogging the CPU while polling for busy for mmc ioctls Date: Fri, 2 Jul 2021 15:42:28 +0200 Message-Id: <20210702134229.357717-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210702134229.357717-1-ulf.hansson@linaro.org> References: <20210702134229.357717-1-ulf.hansson@linaro.org> MIME-Version: 1.0 When __mmc_blk_ioctl_cmd() calls card_busy_detect() to verify that the card's states moves back into transfer state, the polling with CMD13 is done without any delays in between the commands being sent. Rather than fixing card_busy_detect() in this regards, let's instead convert into using the common mmc_poll_for_busy(), which also helps us to avoid open-coding. Signed-off-by: Ulf Hansson --- drivers/mmc/core/block.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.25.1 diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 1b5576048cdb..0f9044cf3aab 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -599,7 +599,8 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, * Ensure RPMB/R1B command has completed by polling CMD13 * "Send Status". */ - err = card_busy_detect(card, MMC_BLK_TIMEOUT_MS, NULL); + err = mmc_poll_for_busy(card, MMC_BLK_TIMEOUT_MS, false, + MMC_BUSY_IO); } return err; From patchwork Fri Jul 2 13:42:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 469553 Delivered-To: patches@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1400747jao; Fri, 2 Jul 2021 06:42:49 -0700 (PDT) X-Received: by 2002:a19:c706:: with SMTP id x6mr4019238lff.265.1625233369094; Fri, 02 Jul 2021 06:42:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625233369; cv=none; d=google.com; s=arc-20160816; b=zaNpEuyWHMmHCOdfZEy/RK96LlMW016+Bg+3H/pbNVxIcWtfYhz2dEVMRuw2O89miD Uaoz9wFyC0jPiPsfwUDzr5Oa4xWtOHLV4Gan0InEwGQ2vUUlKOtn3a8THN25AG+57Ngz GmKJQ4dkaAt2xnc6cIoacWV1tQ286E6pXogWJ+YHdAKJfQ7upJrQZgsfGMb/K7XsFiG/ j5FzLzDY5maPxSNMmS6xkSUdvGlwbkNbbmOcYtfiYDKXnEI/8lBgOVj0EKHZkqDJ6oCR E87ziRSTy23TnYii4ZT0ziF3HVNrsqSY/90THx0hHcizbeN2oevRYLNAAoGCgC4ygxO8 xKag== 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=u3UbKE7Xbmdhqfi5jFjBOgqg0YH0MVXVTmeGRno/rGo=; b=KTi8r39M1B/4xK1lh5dZxKqrzRD5hu/M4TYchr68NE935N5+TGuiJsADcbKIf7j+3o ZPJNgOBLQsyDPvSUk5gsQBBDXr0Yt9osJooinPuXoS0MIVbB564jLQVPzi7RFO4/nBU8 cE0FCCeWROI0PYgvNysFRnOwptITJu5klr+dA5dR39bkM69xmndoVj4seMaCgnOZSoBm SliwIh9HOYDA/LGB4CY62CQ7sjNCox4cvl84NoW4oioKIRtUgx/gYuHmwfFm9byh1+PT 1w2ZJCWzePViHEiMYTeSEFpVTkhuG+6GreybXd3WHCkiplo89bDbyQSL+NQpWJbEjSfh 6nBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nonR9oDG; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 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-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id j9sor1433184ljg.73.2021.07.02.06.42.48 for (Google Transport Security); Fri, 02 Jul 2021 06:42:49 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nonR9oDG; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 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=u3UbKE7Xbmdhqfi5jFjBOgqg0YH0MVXVTmeGRno/rGo=; b=nonR9oDGaUwZHLxPGUO7VPq0gAx71iFtzBCyEZsdo3PrQtXmxWmG9N4RTL1CD/cBas 24G0m29y4NqNUazzcpH2laPVeSh1Sq/NfSb9wwCiGipk7ks2T1AuuGWWlU3dY6m1yXS9 blwO9jElKTaFJ9SrBpB128eH4DdDxvbWeiDDROczpYjD786sVmpf0siLwxKqe81ev6H4 0hsT5q0aUPoHvt8LZrl/S37S2UtZEW3wGgDG4nprj4yAbuClr6rxaQDbWglOjOwT1tKe Lp+RfozgL8cenqU8kt01Njmgv0k9yLj4R4kESzx/8LCs3O0XHjsAznhODDHyKQpLM+yn tfnA== 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=u3UbKE7Xbmdhqfi5jFjBOgqg0YH0MVXVTmeGRno/rGo=; b=mWtwbu0v5oYrwaXEapj2upgP4IOEuJvEMkUhUL3Et42KxR1hfPWW7W15iShRorK/io x2wri1sttJFRyXqEUC5SPKZ04Abeo4Hve02yiGhLc0Swo63FoFKnu4fSLVexeaFhbkhL FRhV5Ndg92V3TnMN8IwS8qc9i+SpxNP1Opg87if9Fjf5q+jbqBQr2+8KROYOw8QgsIp+ 2hsCqchmv7v1Qt/HWn1+21KjZAP5NAP6fiybp0gnCpkmCeuEb5F1txLeat2dNuw9rmSA pNM0PrHmFWW6Sor67gbkKout4Iz8CfJJlbyMc4J5A4sQpOjYYynnGR3dAgEih8M0ZTAc p5Mg== X-Gm-Message-State: AOAM5339eIN8YpCa4hqwkC4KR+QZ+JyvieYCNuqDx1J7H4IXGRnXLiBl YrwfK0FTVkqMJC5KfglDVXAM9hh1 X-Google-Smtp-Source: ABdhPJyQXgCSbpp5kouEiFuJMVySK7ItUJ3kUJyLaC/nXtWIYudghZPPUp+yZp0lFiEVA6bd8/4ePg== X-Received: by 2002:a2e:a4ae:: with SMTP id g14mr4057839ljm.354.1625233368740; Fri, 02 Jul 2021 06:42:48 -0700 (PDT) Return-Path: Received: from localhost.localdomain (h-155-4-129-146.NA.cust.bahnhof.se. [155.4.129.146]) by smtp.gmail.com with ESMTPSA id u5sm277486lfg.268.2021.07.02.06.42.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jul 2021 06:42:47 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Adrian Hunter , Linus Walleij , Wolfram Sang , Shawn Lin , Christian Lohle , linux-kernel@vger.kernel.org Subject: [PATCH 3/3] mmc: core: Avoid hogging the CPU while polling for busy after I/O writes Date: Fri, 2 Jul 2021 15:42:29 +0200 Message-Id: <20210702134229.357717-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210702134229.357717-1-ulf.hansson@linaro.org> References: <20210702134229.357717-1-ulf.hansson@linaro.org> MIME-Version: 1.0 When mmc_blk_card_busy() calls card_busy_detect() to poll for the card's state with CMD13, this is done without any delays in between the commands being sent. Rather than fixing card_busy_detect() in this regards, let's instead convert into using the common __mmc_poll_for_busy(), which also helps us to avoid open-coding. Signed-off-by: Ulf Hansson --- drivers/mmc/core/block.c | 69 ++++++++++++++++---------------------- drivers/mmc/core/mmc_ops.c | 1 + 2 files changed, 30 insertions(+), 40 deletions(-) -- 2.25.1 diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 0f9044cf3aab..c692f2af77f2 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -97,6 +97,11 @@ static int max_devices; static DEFINE_IDA(mmc_blk_ida); static DEFINE_IDA(mmc_rpmb_ida); +struct mmc_blk_busy_data { + struct mmc_card *card; + u32 status; +}; + /* * There is one mmc_blk_data per slot. */ @@ -411,42 +416,6 @@ static int mmc_blk_ioctl_copy_to_user(struct mmc_ioc_cmd __user *ic_ptr, return 0; } -static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms, - u32 *resp_errs) -{ - unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms); - int err = 0; - u32 status; - - do { - bool done = time_after(jiffies, timeout); - - err = __mmc_send_status(card, &status, 5); - if (err) { - dev_err(mmc_dev(card->host), - "error %d requesting status\n", err); - return err; - } - - /* Accumulate any response error bits seen */ - if (resp_errs) - *resp_errs |= status; - - /* - * Timeout if the device never becomes ready for data and never - * leaves the program state. - */ - if (done) { - dev_err(mmc_dev(card->host), - "Card stuck in wrong state! %s status: %#x\n", - __func__, status); - return -ETIMEDOUT; - } - } while (!mmc_ready_for_data(status)); - - return err; -} - static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, struct mmc_blk_ioc_data *idata) { @@ -1846,28 +1815,48 @@ static inline bool mmc_blk_rq_error(struct mmc_blk_request *brq) brq->data.error || brq->cmd.resp[0] & CMD_ERRORS; } +static int mmc_blk_busy_cb(void *cb_data, bool *busy) +{ + struct mmc_blk_busy_data *data = cb_data; + u32 status = 0; + int err; + + err = mmc_send_status(data->card, &status); + if (err) + return err; + + /* Accumulate response error bits. */ + data->status |= status; + + *busy = !mmc_ready_for_data(status); + return 0; +} + static int mmc_blk_card_busy(struct mmc_card *card, struct request *req) { struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req); - u32 status = 0; + struct mmc_blk_busy_data cb_data; int err; if (mmc_host_is_spi(card->host) || rq_data_dir(req) == READ) return 0; - err = card_busy_detect(card, MMC_BLK_TIMEOUT_MS, &status); + cb_data.card = card; + cb_data.status = 0; + err = __mmc_poll_for_busy(card, MMC_BLK_TIMEOUT_MS, &mmc_blk_busy_cb, + &cb_data); /* * Do not assume data transferred correctly if there are any error bits * set. */ - if (status & mmc_blk_stop_err_bits(&mqrq->brq)) { + if (cb_data.status & mmc_blk_stop_err_bits(&mqrq->brq)) { mqrq->brq.data.bytes_xfered = 0; err = err ? err : -EIO; } /* Copy the exception bit so it will be seen later on */ - if (mmc_card_mmc(card) && status & R1_EXCEPTION_EVENT) + if (mmc_card_mmc(card) && cb_data.status & R1_EXCEPTION_EVENT) mqrq->brq.cmd.resp[0] |= R1_EXCEPTION_EVENT; return err; diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index e2c431c0ce5d..90d213a2203f 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -510,6 +510,7 @@ int __mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, return 0; } +EXPORT_SYMBOL_GPL(__mmc_poll_for_busy); int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, bool retry_crc_err, enum mmc_busy_cmd busy_cmd)