Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp301079ybz; Thu, 30 Apr 2020 22:19:12 -0700 (PDT) X-Google-Smtp-Source: APiQypIJ2teSVOEyFn/ztNSIVo8M1w7vxKqrdvuJKsNJc9LQH8ygrFRUbrY1TifEzfgKVZ5cbSxB X-Received: by 2002:a05:6402:1b08:: with SMTP id by8mr2069274edb.286.1588310352522; Thu, 30 Apr 2020 22:19:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588310352; cv=none; d=google.com; s=arc-20160816; b=MlIqRF3De8kKRvggESbmE7Ie6vmPU4uVCrzw1AmhwXHbiLeTvHLLM94k+hgRlXkPgZ 2JS0e58AFrutda6+uNth9pu+3sHOsOeYc6vp8kU9kONBmXZujvO/k8056uzHTt+8rRWn OecpRjlqzB4eQpoFRL5muTnINInOt1xisbAQ8d6MgA7fJL3ZPGOG3dLYi91gsqmUU72E PYjh6OmgPnaZ90Tl/D9W3oGR5y1eIt7FHKreQaP7GDd0pIUM10cj1MlxcpDUy9dNkGK7 CHvgaPJHrCv3npGJnjmLg26L7Lbb1WldcDKzRUih5up0J4M1ZB4l+o7tvYeRoD5xntPT Ml0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version:dkim-signature; bh=Gb5UVWrknkO+6yt6LwWbrza8osaP6Xld9YYD0ScSLPA=; b=yqCYjVRk2euShvfOM1jN36pVbpX2Bp80SPUykFfHIoveITA3zogL51HNR2bMPlyO/j xIyFpbx/lFX732YiuHPY6n6hQy3lB3xsYs8bdSPE6FPiHS+5uIONt+X4LvYHTM6PHOSe I+0rdZk8zVSx1lDSWMnuQ4h0FHl7gnG4dUywqDaFr1XOOk19gz2/mINWXIKQXgvQScFd eTH0TW7mUNfLJTbqFHbiixHvrb2bL2IgjMS3wthboBNGhhkx7qmGGQN167+C4XFfRxPW +3wfrfhR9DKnGq7ZjIFbJZ6COZQm3QrK83WMqGNMNf0UxmjmenQaoK5d45xIstWgLscY K52w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=mzzFIhaK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y8si937597edw.356.2020.04.30.22.18.03; Thu, 30 Apr 2020 22:19:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=mzzFIhaK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728189AbgEAFMW (ORCPT + 99 others); Fri, 1 May 2020 01:12:22 -0400 Received: from mail26.static.mailgun.info ([104.130.122.26]:26681 "EHLO mail26.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727922AbgEAFMV (ORCPT ); Fri, 1 May 2020 01:12:21 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1588309941; h=Message-ID: References: In-Reply-To: Subject: Cc: To: From: Date: Content-Transfer-Encoding: Content-Type: MIME-Version: Sender; bh=Gb5UVWrknkO+6yt6LwWbrza8osaP6Xld9YYD0ScSLPA=; b=mzzFIhaKhODcgxdqY5Ozx4DMbupH+eueG5ea4sH/FRn7yuozY2Xf6VdiGWLPWJ257SNA32fX zcOJmae8NqNAhqDFffAYDUn0cYPJWdaHeMCMod2mkwADwm+UeLw1EYYnMbKMBHD97P79HnyJ 0tJ9aMDkRRPwbfRZCEAH0nDnWlc= X-Mailgun-Sending-Ip: 104.130.122.26 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5eabafb4.7f7e4515ad50-smtp-out-n03; Fri, 01 May 2020 05:12:20 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 80208C4478F; Fri, 1 May 2020 05:12:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: cang) by smtp.codeaurora.org (Postfix) with ESMTPSA id 78AAFC433CB; Fri, 1 May 2020 05:12:17 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 01 May 2020 13:12:17 +0800 From: Can Guo To: Bart Van Assche Cc: asutoshd@codeaurora.org, nguyenb@codeaurora.org, hongwus@codeaurora.org, rnayak@codeaurora.org, stanley.chu@mediatek.com, alim.akhtar@samsung.com, beanhuo@micron.com, Avri.Altman@wdc.com, bjorn.andersson@linaro.org, linux-scsi@vger.kernel.org, kernel-team@android.com, saravanak@google.com, salyzyn@google.com, "James E.J. Bottomley" , "Martin K. Petersen" , open list Subject: Re: [PATCH v3 1/1] scsi: pm: Balance pm_only counter of request queue during system resume In-Reply-To: <226048f7-6ad3-a625-c2ed-d9d13e096803@acm.org> References: <1588219805-25794-1-git-send-email-cang@codeaurora.org> <9e15123e-4315-15cd-3d23-2df6144bd376@acm.org> <1ef85ee212bee679f7b2927cbbc79cba@codeaurora.org> <1e2a2e39dbb3a0f06fe95bbfd66e1648@codeaurora.org> <226048f7-6ad3-a625-c2ed-d9d13e096803@acm.org> Message-ID: <3bfa692ce706c5c198f565e674afb56f@codeaurora.org> X-Sender: cang@codeaurora.org User-Agent: Roundcube Webmail/1.3.9 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-05-01 09:50, Bart Van Assche wrote: > On 2020-04-30 18:42, Can Guo wrote: >> On 2020-05-01 04:32, Bart Van Assche wrote: >> > Has it been considered to test directly whether a SCSI device has been >> > runtime suspended instead of relying on blk_queue_pm_only()? How about >> > using pm_runtime_status_suspended() or adding a function in >> > block/blk-pm.h that checks whether q->rpm_status == RPM_SUSPENDED? >> >> Yes, I used to make the patch like that way, and it also worked well, >> as >> both ways are equal actually. I kinda like the current code because we >> should be confident that after scsi_dev_type_resume() returns, pm_only >> must be 0. Different reviewers may have different opinions, either way >> works well anyways. > > Hi Can, > > Please note that this is not a matter of personal preferences of a > reviewer but a matter of correctness. blk_queue_pm_only() does not only > return a value > 0 if a SCSI device has been runtime suspended but also > returns true if scsi_device_quiesce() was called for another reason. > Hence my request to test the "runtime suspended" status directly and > not > to rely on blk_queue_pm_only(). > > Thanks, > > Bart. Hi Bart, I agree we are pursuing correctness here, but as I said, I think both way are equally correct. I also agree with you that the alternative way, see [2], is much easier to be understood, we can take the alternative way if you are OK with it. [1] Currently, scsi_dev_type_resume() is the hooker for resume, thaw and restore. Per my understanding, when scsi_dev_type_resume() is running, it is not possible that scsi_device_quiesce() can be called to this sdev, at least not possible in current code base. So it is OK to rely on blk_queue_pm_only() in scsi_dev_type_resume(). [2] The alternative way which I have tested with is like below. I think it is what you requested for if my understanding is right, please correct me if I am wrong. diff --git a/drivers/scsi/scsi_pm.c b/drivers/scsi/scsi_pm.c index 3717eea..d18271d 100644 --- a/drivers/scsi/scsi_pm.c +++ b/drivers/scsi/scsi_pm.c @@ -74,12 +74,15 @@ static int scsi_dev_type_resume(struct device *dev, { const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; int err = 0; + bool was_rpm_suspended = false; err = cb(dev, pm); scsi_device_resume(to_scsi_device(dev)); dev_dbg(dev, "scsi resume: %d\n", err); if (err == 0) { + was_rpm_suspended = pm_runtime_suspended(dev); + pm_runtime_disable(dev); err = pm_runtime_set_active(dev); pm_runtime_enable(dev); @@ -93,8 +96,10 @@ static int scsi_dev_type_resume(struct device *dev, */ if (!err && scsi_is_sdev_device(dev)) { struct scsi_device *sdev = to_scsi_device(dev); - - blk_set_runtime_active(sdev->request_queue); + if (was_rpm_suspended) + blk_post_runtime_resume(sdev->request_queue, 0); + else + blk_set_runtime_active(sdev->request_queue); } } Thanks, Can Guo