From patchwork Thu Oct 11 05:08:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lu X-Patchwork-Id: 1580991 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 1558240135 for ; Thu, 11 Oct 2012 05:08:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752387Ab2JKFIm (ORCPT ); Thu, 11 Oct 2012 01:08:42 -0400 Received: from mga02.intel.com ([134.134.136.20]:3751 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751967Ab2JKFIl (ORCPT ); Thu, 11 Oct 2012 01:08:41 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 10 Oct 2012 22:08:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.80,569,1344236400"; d="scan'208";a="204188145" Received: from mint-spring.sh.intel.com ([10.239.36.118]) by orsmga001.jf.intel.com with ESMTP; 10 Oct 2012 22:08:39 -0700 From: Aaron Lu To: Alan Stern , "Rafael J. Wysocki" , James Bottomley Cc: linux-scsi@vger.kernel.org, linux-pm@vger.kernel.org, Aaron Lu , Aaron Lu Subject: [PATCH v2 1/5] sd: put to stopped power state when runtime suspend Date: Thu, 11 Oct 2012 13:08:07 +0800 Message-Id: <1349932091-6856-2-git-send-email-aaron.lu@intel.com> X-Mailer: git-send-email 1.7.12.21.g871e293 In-Reply-To: <1349932091-6856-1-git-send-email-aaron.lu@intel.com> References: <1349932091-6856-1-git-send-email-aaron.lu@intel.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org When device is runtime suspended, put it to stopped power state to save some power. This will also make the behaviour consistent with what the scsi_pm.c thinks about sd as the comment says: sd treats runtime suspend, system suspend and system hibernate identical. With this patch, it is now identical. And sd_shutdown will also do nothing when it finds the device has been runtime suspended, if we do not spin down the disk in runtime suspend by putting it into stopped power state, the disk will be shut down incorrectly. And the the same problem can be solved for runtime power off after runtime suspended case by this change. With the current runtime scheme for disk, it will only be runtime suspended when no process opens the disk, so this shouldn't happen a lot, which makes it acceptable to spin down the disk when runtime suspended. If some day a more aggressive runtime scheme is used, like the 'request based runtime pm for disk' that Alan Stern and Lin Ming has been working, we can introduce some policy to control this. But for now, make it simple and correct by spinning down the disk. Signed-off-by: Aaron Lu --- drivers/scsi/sd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 12f6fdf..8b6e004 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -2911,7 +2911,8 @@ static int sd_suspend(struct device *dev, pm_message_t mesg) goto done; } - if ((mesg.event & PM_EVENT_SLEEP) && sdkp->device->manage_start_stop) { + if (((mesg.event & PM_EVENT_SLEEP) || PMSG_IS_AUTO(mesg)) && + sdkp->device->manage_start_stop) { sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n"); ret = sd_start_stop_device(sdkp, 0); }