From patchwork Tue Dec 1 15:15:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 57505 Delivered-To: patches@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp2239274lbb; Tue, 1 Dec 2015 07:15:24 -0800 (PST) X-Received: by 10.112.137.101 with SMTP id qh5mr8910963lbb.81.1448982924012; Tue, 01 Dec 2015 07:15:24 -0800 (PST) Return-Path: Received: from mail-lf0-x22f.google.com (mail-lf0-x22f.google.com. [2a00:1450:4010:c07::22f]) by mx.google.com with ESMTPS id 35si32523350lfr.63.2015.12.01.07.15.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Dec 2015 07:15:23 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::22f as permitted sender) client-ip=2a00:1450:4010:c07::22f; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c07::22f as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dkim=pass header.i=@linaro-org.20150623.gappssmtp.com Received: by lffu14 with SMTP id u14so12415910lff.1 for ; Tue, 01 Dec 2015 07:15:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=QlXkIbz+Irvo0HkHqkmfJBX0F3sHDmhKiuCbTxtj/gI=; b=U2VUtImoeBEK9OWK7x4U7XB3PEQ7Kqqg1jkGXuBr45p5919EJo0u7bT4KGllpPHO/T bY71Bvx3i3qOETJvSfKAMTRpte06iB90noiU8cEFXma0lpCHpSmNB76Kqau+BhFMHKI7 +xJWdu+yR1mPYxLRD3QxNJUB0iDlaGiHzyDLt2sqJCucWM39uaxJ3z1TXqGjFX4HuywV O5S2XsQe48KHuvdGlliSlONMLJy/8C+WHKQUFC7pyMXqYDJmVCzqf0djOy7OHKeyapwk sJavnZJ/T/7yL9baCuRDLvK9FgdHri8FyfW0hooTZK/TZnEDhvXgmu5vDiF4kPqrSvWu pZ+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=QlXkIbz+Irvo0HkHqkmfJBX0F3sHDmhKiuCbTxtj/gI=; b=W4cKzot/UM7+7SWDrm/wBHQSPeLZmYzygbDYtu76K28ln31mzqCM8Vn9UZ420DbZlI xfMWjG5tgJZb1OrUVaoiuM+OXMrttoMMJxYM6C5YcNrrJiNmeaUiI5tu7WzpyyqYyOAw RhBi7Ob/giY2AdWbn4/3laB0iHUUJxP1IQFdNHVe8DNP8iUNnq44SOCoYH9i/V3tw9rp qH4WJ9L2Dt1E9/J6vEKTBCR+16vVSY/+q9ZaoKBX88LeVsbbWUHy0hNheXn/+qXWjeru WJ2qb2z6rlff/0SPBdAAqiBNTne6Mf6hKICfJdMl5mGLX/Tf8fDxDeeGwcYkFkyOSdoF CFOw== X-Gm-Message-State: ALoCoQmzkbLBM/0d3aIPTcUsY86/MuR+bGQkAZCNw+S9hJgQ9+jZSiaZ6aWkuwnCXP+G8fu0uN/5 X-Received: by 10.112.129.134 with SMTP id nw6mr29687001lbb.10.1448982923788; Tue, 01 Dec 2015 07:15:23 -0800 (PST) Return-Path: Received: from uffe-Latitude-E6430s.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id aa4sm7781575lbc.10.2015.12.01.07.15.22 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 01 Dec 2015 07:15:23 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Jaehoon Chung Subject: [PATCH] mmc: core: Optimize boot time by detecting cards simultaneously Date: Tue, 1 Dec 2015 16:15:16 +0100 Message-Id: <1448982916-21485-1-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 The mmc workqueue is an ordered workqueue, allowing only one work to execute per given time. As this workqueue is used for card detection, the conseqeunce is that cards will be detected one by one waiting for each other. Moreover, most of the time spent during card initialization is waiting for the card's internal firmware to be ready. From a CPU perspective this typically means waiting for a completion variable to be kicked via an IRQ-handler or waiting for a sleep timer to finish. This behaviour of detecting/initializing cards is sub-optimal, especially for SOCs having several controllers/cards. Let's convert to use the system_freezable_wq for the mmc detect works. This enables several works to be executed simultaneously and thus also cards to be detected like so. Tests on UX500, which holds two eMMC cards and an SD-card (actually also an SDIO card, currently not detected), shows a significant improved behaviour due to this change. Before this change, both the eMMC cards waited for the SD card to be initialized as its detect work entered the workqueue first. In some cases, depending on the characteristic of the SD-card, they got delayed 1-1.5 s. Additionally for the second eMMC, it needed to wait for the first eMMC to be initialized which added another 120-190 ms. Converting to the system_freezable_wq, removed these delays and made both the eMMC cards available far earlier in the boot sequence. Selecting the system_freezable_wq, in favour of for example the system_wq, is because we need card detection mechanism to be disabled once userspace are frozen during system PM. Currently the mmc core deal with this via PM notifiers, but following patches may utilize the behaviour of the system_freezable_wq, to simplify the use of the PM notifiers. Signed-off-by: Ulf Hansson --- drivers/mmc/core/core.c | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) -- 1.9.1 diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 910aa25..f95d41f 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -55,7 +55,6 @@ */ #define MMC_BKOPS_MAX_TIMEOUT (4 * 60 * 1000) /* max time to wait in ms */ -static struct workqueue_struct *workqueue; static const unsigned freqs[] = { 400000, 300000, 200000, 100000 }; /* @@ -66,21 +65,16 @@ static const unsigned freqs[] = { 400000, 300000, 200000, 100000 }; bool use_spi_crc = 1; module_param(use_spi_crc, bool, 0); -/* - * Internal function. Schedule delayed work in the MMC work queue. - */ static int mmc_schedule_delayed_work(struct delayed_work *work, unsigned long delay) { - return queue_delayed_work(workqueue, work, delay); -} - -/* - * Internal function. Flush all scheduled work from the MMC work queue. - */ -static void mmc_flush_scheduled_work(void) -{ - flush_workqueue(workqueue); + /* + * We use the system_freezable_wq, because of two reasons. + * First, it allows several works (not the same work item) to be + * executed simultaneously. Second, the queue becomes frozen when + * userspace becomes frozen during system PM. + */ + return queue_delayed_work(system_freezable_wq, work, delay); } #ifdef CONFIG_FAIL_MMC_REQUEST @@ -2669,7 +2663,6 @@ void mmc_stop_host(struct mmc_host *host) host->rescan_disable = 1; cancel_delayed_work_sync(&host->detect); - mmc_flush_scheduled_work(); /* clear pm flags now and let card drivers set them as needed */ host->pm_flags = 0; @@ -2852,13 +2845,9 @@ static int __init mmc_init(void) { int ret; - workqueue = alloc_ordered_workqueue("kmmcd", 0); - if (!workqueue) - return -ENOMEM; - ret = mmc_register_bus(); if (ret) - goto destroy_workqueue; + return ret; ret = mmc_register_host_class(); if (ret) @@ -2874,9 +2863,6 @@ unregister_host_class: mmc_unregister_host_class(); unregister_bus: mmc_unregister_bus(); -destroy_workqueue: - destroy_workqueue(workqueue); - return ret; } @@ -2885,7 +2871,6 @@ static void __exit mmc_exit(void) sdio_unregister_bus(); mmc_unregister_host_class(); mmc_unregister_bus(); - destroy_workqueue(workqueue); } subsys_initcall(mmc_init);