From patchwork Wed Nov 16 10:51:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 82467 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp82278qge; Wed, 16 Nov 2016 02:51:25 -0800 (PST) X-Received: by 10.98.76.8 with SMTP id z8mr3544928pfa.167.1479293485086; Wed, 16 Nov 2016 02:51:25 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y10si14783653pgc.243.2016.11.16.02.51.24; Wed, 16 Nov 2016 02:51:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752713AbcKPKvX (ORCPT + 13 others); Wed, 16 Nov 2016 05:51:23 -0500 Received: from mail-wm0-f52.google.com ([74.125.82.52]:37962 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751741AbcKPKvW (ORCPT ); Wed, 16 Nov 2016 05:51:22 -0500 Received: by mail-wm0-f52.google.com with SMTP id f82so64215298wmf.1 for ; Wed, 16 Nov 2016 02:51:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=Zidm6adYuxe6BA9FN8+DamUbDE/misrQShAirFr07U4=; b=AkaFXbwSw+uYQosRgX816D70ERK4XJWH6+SEqmWWLCqIDNtNRcyP6wCZaPf16quqD5 krlkAn3oom7EP1ZbNI0deRVq8GPBRMen04+wO9Vump6kuy4o0WvKgHCDzJwWijRPblqn im+nueNXqVYGIfZQmbzityQ/oeWKsmQUiRA3s= 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=Zidm6adYuxe6BA9FN8+DamUbDE/misrQShAirFr07U4=; b=OFqwKvixe6CvFVjjHX5XMVitkLTyNeGzmeiBazp8qLqsCLZiLIux6xkEg/9QKWDNLh n36cHPKpkr4FG76jjkdHLwwMn0kIlDhic7X/LVSn2y2qNRHxiuA2xDPuPdocXOelVJUc ZmaJ2l8KFquOhVNP21ErmrmFa7RpNTshZWhXz7UAABfi+iAftyPILw12JKkFtj9IlU0U lIeIss/fUmwmXZh282z80JI0xeAd7V1McPtYGXFvRIrDvofWj8MxGrm2ZOr6wjJkIVXz 7Mipch+1tWXFHaAR/TyVkkzRXd2pWjM7EkLMH56A+cgCaO8oufGVeZitx3OuOGa40XtH fVcQ== X-Gm-Message-State: ABUngvfpK/cnCMDwvfwAF7wwRQjEHvJ5ZeFMrI4RkCHwre0YfTCDKOUIl/wWrPZjXsf017e7 X-Received: by 10.25.169.137 with SMTP id s131mr841530lfe.54.1479293481280; Wed, 16 Nov 2016 02:51:21 -0800 (PST) Received: from linuslaptop.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id h3sm7770510lfj.27.2016.11.16.02.51.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Nov 2016 02:51:20 -0800 (PST) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Chunyan Zhang , Baolin Wang , Linus Walleij , linux-pm@vger.kernel.org, "Rafael J . Wysocki" , Russell King , Arnd Bergmann Subject: [PATCH] RFC: mmc: block: replace semaphore with freezing Date: Wed, 16 Nov 2016 11:51:04 +0100 Message-Id: <1479293464-4576-1-git-send-email-linus.walleij@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The MMC/SD block core request processing thread is taking a semaphore in the request processing section and the same semaphore is taken around suspend/resume operations. The purpose of the semaphore is to block any request from being issued to the MMC/SD host controllers when the system is suspended. A semaphore is used in place of a mutex since the calls are coming from different threads. This construction predates the kernel thread freezer mechanism: we can easily replace the semaphore by instead activating the freezer with set_freezable() and call try_to_freeze() instead of the up(); schedule(); down(); construction that is devised to let the suspend/resume calls get in and grab the semaphore. Tested with a few suspend/resume to memory cycles on the Ux500 when doing intense dd operations in the background: the thread thaws and resumes operation after resume. Cc: linux-pm@vger.kernel.org Cc: Rafael J. Wysocki Cc: Russell King Cc: Arnd Bergmann Signed-off-by: Linus Walleij --- I haven't seen any need to preserve the call to schedule() in the request processing thread, but I want advice on whether that has a point. I would guess the thread will just anyway be preempted if needed anyway as it is marked interruptible? --- drivers/mmc/card/queue.c | 13 ++----------- drivers/mmc/card/queue.h | 1 - 2 files changed, 2 insertions(+), 12 deletions(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c index 8037f73a109a..09a932ffe46e 100644 --- a/drivers/mmc/card/queue.c +++ b/drivers/mmc/card/queue.c @@ -55,8 +55,8 @@ static int mmc_queue_thread(void *d) struct request_queue *q = mq->queue; current->flags |= PF_MEMALLOC; + set_freezable(); - down(&mq->thread_sem); do { struct request *req = NULL; @@ -95,12 +95,9 @@ static int mmc_queue_thread(void *d) set_current_state(TASK_RUNNING); break; } - up(&mq->thread_sem); - schedule(); - down(&mq->thread_sem); + try_to_freeze(); } } while (1); - up(&mq->thread_sem); return 0; } @@ -289,8 +286,6 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, goto cleanup_queue; } - sema_init(&mq->thread_sem, 1); - mq->thread = kthread_run(mmc_queue_thread, mq, "mmcqd/%d%s", host->index, subname ? subname : ""); @@ -424,8 +419,6 @@ void mmc_queue_suspend(struct mmc_queue *mq) spin_lock_irqsave(q->queue_lock, flags); blk_stop_queue(q); spin_unlock_irqrestore(q->queue_lock, flags); - - down(&mq->thread_sem); } } @@ -441,8 +434,6 @@ void mmc_queue_resume(struct mmc_queue *mq) if (mq->flags & MMC_QUEUE_SUSPENDED) { mq->flags &= ~MMC_QUEUE_SUSPENDED; - up(&mq->thread_sem); - spin_lock_irqsave(q->queue_lock, flags); blk_start_queue(q); spin_unlock_irqrestore(q->queue_lock, flags); diff --git a/drivers/mmc/card/queue.h b/drivers/mmc/card/queue.h index 3c15a75bae86..fe10f94795de 100644 --- a/drivers/mmc/card/queue.h +++ b/drivers/mmc/card/queue.h @@ -53,7 +53,6 @@ struct mmc_queue_req { struct mmc_queue { struct mmc_card *card; struct task_struct *thread; - struct semaphore thread_sem; unsigned int flags; #define MMC_QUEUE_SUSPENDED (1 << 0) #define MMC_QUEUE_NEW_REQUEST (1 << 1)