From patchwork Tue Dec 17 18:02:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Warren X-Patchwork-Id: 302319 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 813932C00A2 for ; Wed, 18 Dec 2013 05:02:34 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754316Ab3LQSCd (ORCPT ); Tue, 17 Dec 2013 13:02:33 -0500 Received: from avon.wwwdotorg.org ([70.85.31.133]:39428 "EHLO avon.wwwdotorg.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752340Ab3LQSCd (ORCPT ); Tue, 17 Dec 2013 13:02:33 -0500 Received: from severn.wwwdotorg.org (unknown [192.168.65.5]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by avon.wwwdotorg.org (Postfix) with ESMTPS id 580E06317; Tue, 17 Dec 2013 11:02:32 -0700 (MST) Received: from swarren-lx1.nvidia.com (localhost [127.0.0.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by severn.wwwdotorg.org (Postfix) with ESMTPSA id D8C40E45FB; Tue, 17 Dec 2013 11:02:14 -0700 (MST) From: Stephen Warren To: Chris Ball Cc: linux-mmc@vger.kernel.org, linux-tegra@vger.kernel.org, Stephen Warren , Adrian Hunter , Dong Aisheng , Ulf Hansson , Vladimir Zapolskiy Subject: [PATCH] mmc: core: don't decrement qty when calculating max_discard Date: Tue, 17 Dec 2013 11:02:24 -0700 Message-Id: <1387303344-11802-1-git-send-email-swarren@wwwdotorg.org> X-Mailer: git-send-email 1.8.1.5 X-NVConfidentiality: public X-Virus-Scanned: clamav-milter 0.97.8 at avon.wwwdotorg.org X-Virus-Status: Clean Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org From: Stephen Warren In mmc_do_calc_max_discard(), if any value has been assigned to qty, that value must have passed the timeout checks in the loop. Hence, qty is the maximum number of erase blocks that fit within the timeout, not the first value that does not fit into the timeout. In turn, this means we don't need any special case for (qty == 1); any value of qty needs to be multiplied by the card's erase shift, and we don't need to decrement qty before doing so. Without this patch, on the NVIDIA Tegra Cardhu board, the loops result in qty == 1, which is immediately returned. This causes discard to operate a single sector at a time, which is chronically slow. With this patch in place, discard operates a single erase block at a time, which is reasonably fast. Cc: Adrian Hunter Cc: Dong Aisheng Cc: Ulf Hansson Cc: Vladimir Zapolskiy Fixes: e056a1b5b67b "(mmc: queue: let host controllers specify maximum discard timeout") Signed-off-by: Stephen Warren --- If this makes sense, I wonder if it should be Cc: stable? --- drivers/mmc/core/core.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 57a2b403bf8e..dd793cf4ef46 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -2150,16 +2150,13 @@ static unsigned int mmc_do_calc_max_discard(struct mmc_card *card, if (!qty) return 0; - if (qty == 1) - return 1; - /* Convert qty to sectors */ if (card->erase_shift) - max_discard = --qty << card->erase_shift; + max_discard = qty << card->erase_shift; else if (mmc_card_sd(card)) max_discard = qty; else - max_discard = --qty * card->erase_size; + max_discard = qty * card->erase_size; return max_discard; }