From patchwork Mon Jul 23 06:49:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: aaron lu X-Patchwork-Id: 1226391 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 5AA9C3FD4F for ; Mon, 23 Jul 2012 06:51:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752664Ab2GWGvA (ORCPT ); Mon, 23 Jul 2012 02:51:00 -0400 Received: from va3ehsobe004.messaging.microsoft.com ([216.32.180.14]:21460 "EHLO va3outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752616Ab2GWGu5 (ORCPT ); Mon, 23 Jul 2012 02:50:57 -0400 Received: from mail221-va3-R.bigfish.com (10.7.14.243) by VA3EHSOBE007.bigfish.com (10.7.40.11) with Microsoft SMTP Server id 14.1.225.23; Mon, 23 Jul 2012 06:50:56 +0000 Received: from mail221-va3 (localhost [127.0.0.1]) by mail221-va3-R.bigfish.com (Postfix) with ESMTP id 320BFB40146; Mon, 23 Jul 2012 06:50:56 +0000 (UTC) X-Forefront-Antispam-Report: CIP:163.181.249.108; KIP:(null); UIP:(null); IPV:NLI; H:ausb3twp01.amd.com; RD:none; EFVD:NLI X-SpamScore: 0 X-BigFish: VPS0(zzzz1202hzz8275bhz2dh668h839hd24he5bhf0ah107ah) Received: from mail221-va3 (localhost.localdomain [127.0.0.1]) by mail221-va3 (MessageSwitch) id 1343026254735927_6469; Mon, 23 Jul 2012 06:50:54 +0000 (UTC) Received: from VA3EHSMHS038.bigfish.com (unknown [10.7.14.245]) by mail221-va3.bigfish.com (Postfix) with ESMTP id A7451180045; Mon, 23 Jul 2012 06:50:54 +0000 (UTC) Received: from ausb3twp01.amd.com (163.181.249.108) by VA3EHSMHS038.bigfish.com (10.7.99.48) with Microsoft SMTP Server id 14.1.225.23; Mon, 23 Jul 2012 06:50:54 +0000 X-WSS-ID: 0M7LPOS-01-5MN-02 X-M-MSG: Received: from sausexedgep01.amd.com (sausexedgep01-ext.amd.com [163.181.249.72]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by ausb3twp01.amd.com (Axway MailGate 3.8.1) with ESMTP id 23FD41028121; Mon, 23 Jul 2012 01:50:52 -0500 (CDT) Received: from sausexhtp02.amd.com (163.181.3.152) by sausexedgep01.amd.com (163.181.36.54) with Microsoft SMTP Server (TLS) id 8.3.192.1; Mon, 23 Jul 2012 01:50:55 -0500 Received: from sausexmb1.amd.com (163.181.3.156) by sausexhtp02.amd.com (163.181.3.152) with Microsoft SMTP Server id 8.3.213.0; Mon, 23 Jul 2012 01:50:51 -0500 Received: from storexbh1.amd.com ([10.1.1.17]) by sausexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.3959); Mon, 23 Jul 2012 01:50:51 -0500 Received: from sshaexmb1.amd.com ([10.237.2.11]) by storexbh1.amd.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 23 Jul 2012 02:50:50 -0400 Received: from srdclcs1.amd.com ([10.237.73.42]) by sshaexmb1.amd.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 23 Jul 2012 14:50:38 +0800 From: Aaron Lu To: Jeff Garzik , Alan Stern , Lin Ming CC: , , , , Aaron Lu , Aaron Lu Subject: [PATCH 2/5] scsi: sr: runtime pm when ODD is open/closed Date: Mon, 23 Jul 2012 14:49:37 +0800 Message-ID: <1343026180-22236-3-git-send-email-aaron.lu@amd.com> X-Mailer: git-send-email 1.7.11.3 In-Reply-To: <1343026180-22236-1-git-send-email-aaron.lu@amd.com> References: <1343026180-22236-1-git-send-email-aaron.lu@amd.com> X-OriginalArrivalTime: 23 Jul 2012 06:50:38.0295 (UTC) FILETIME=[77D1F670:01CD689F] MIME-Version: 1.0 X-OriginatorOrg: amd.com Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The ODD can either be runtime resumed by the user or by a software request. And for the latter part, we only support runtime resume the ODD when the eject request is received. We did this in sr's block ioctl function, this looks ugly. Change this by runtime resuming the ODD in its open function and runtime suspending it in its release function. The downside of this approach is that in old distros with old udisk daemon, the ODD will be polled by udisk daemon so open/close will constantly be called, which will cause the ODD frequently resume from suspend state, breaking the effect of power saving. User with such a distro is advised to issue a udisk command to inhibit polling of the disk like this: $ udisks --inhibit-polling /dev/sr0 And since newer kernel has in kernel polling, there is no problem regarding ODD's event report. Signed-off-by: Aaron Lu --- drivers/scsi/sr.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 5f4d19a..f7a7635 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -152,8 +152,15 @@ static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk) kref_get(&cd->kref); if (scsi_device_get(cd->device)) goto out_put; + if (pm_runtime_get_sync(&cd->device->sdev_gendev) < 0) { + pm_runtime_put_noidle(&cd->device->sdev_gendev); + goto out_pm; + } goto out; + out_pm: + scsi_device_put(cd->device); + out_put: kref_put(&cd->kref, sr_kref_release); cd = NULL; @@ -169,6 +176,8 @@ static void scsi_cd_put(struct scsi_cd *cd) mutex_lock(&sr_ref_mutex); kref_put(&cd->kref, sr_kref_release); scsi_device_put(sdev); + pm_runtime_mark_last_busy(&cd->device->sdev_gendev); + pm_runtime_put_autosuspend(&cd->device->sdev_gendev); mutex_unlock(&sr_ref_mutex); } @@ -654,13 +663,6 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, void __user *argp = (void __user *)arg; int ret; - /* Make sure the ODD is not suspended */ - ret = pm_runtime_get_sync(&sdev->sdev_gendev); - if (ret < 0) { - pm_runtime_put_noidle(&sdev->sdev_gendev); - return -EACCES; - } - mutex_lock(&sr_mutex); /* @@ -692,8 +694,6 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, out: mutex_unlock(&sr_mutex); - pm_runtime_mark_last_busy(&cd->device->sdev_gendev); - pm_runtime_put_autosuspend(&cd->device->sdev_gendev); return ret; }