Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp5042279pxu; Wed, 21 Oct 2020 11:40:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw85tsiT1dv0GDRDq9Yy8d70DY16MXeVUFJ3wjS5Vcd4SBW8/WYr3VbR8mJ7KLacxuTRafZ X-Received: by 2002:a17:906:d41:: with SMTP id r1mr4678420ejh.383.1603305603556; Wed, 21 Oct 2020 11:40:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603305603; cv=none; d=google.com; s=arc-20160816; b=iZuU1yojVX/bNzKBO+TtrUjoPzV+5LGx5abqy5wdknP8YwMiNnWMChOOvid2thKGUz 7ueqzRKcR8KddadcfQl9nYk56G36Gt++1mqnjPLO3XsDfZvtLP+WV7ywzQwM+LXki39V hs+kGYa9vPxvncNMIVm/qVea4mz2UZE7Z3mh8hGFgcMQec6DaMZEmZVypITxTwUhCdFM k0chKIXjs9DbD7m85qtcyR/XhJPIdUC1krmgQG5n3YU+GkWJoWzTqN/Dwj1Nv34TZs1C BmqiJcUm0rAwSKg8vAF0AKudLHn5HqAjCmARefsHCh+h7xxDffgyP2KWP79bWoC4HXHU DLUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=agHTVvWNaKczg4axC2mU1BzPKPXMplVP4siwW0qHZkM=; b=pAKBaA8vJXPS724CuCjVVakdqg9VvpSJi8uSRI1ZStDChSkhLtei6EHVZ4U4yId6xP bagYXSjDlv67JAitG+MMhuUHe1H/POi3rgcFfsx8OfJpr/Do36ttpvegDnyU+a+HyF3b il1bAOaiCx8/yP/HCPN0Yva0fNfyG0hpE5fRWpTiS8baN+S/lzEQgGU3CesDRndyg6cb PzaoocS+ZiqvBwOMiaPEe2NwYG5Q0de4wr0rCMe5KhkOW9V+geDcZJFb+Fx8ZeDs4u+O kN1RIIIvGY/ukSsFZ9RsjhPz+KOO80ocpjoND5lAqYl9++lAl72DHCcu7YYbr29Gw2VA ns8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2RG30yAT; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q5si2014224edv.293.2020.10.21.11.39.41; Wed, 21 Oct 2020 11:40:03 -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=pass header.i=@kernel.org header.s=default header.b=2RG30yAT; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2440266AbgJUEwO (ORCPT + 99 others); Wed, 21 Oct 2020 00:52:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:57540 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2411687AbgJUEwO (ORCPT ); Wed, 21 Oct 2020 00:52:14 -0400 Received: from localhost (unknown [104.132.1.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C788D22200; Wed, 21 Oct 2020 04:52:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603255933; bh=Uxranx5I3OGhkPHJfsPFLNiWaCpoSwTMv15+EX3IyVg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=2RG30yAT64+MikDZWgfeUXZeTbDEo6N56hFWAK5sLWxFvpVhyL8Dpgf9GRL2ASc+s w2WVwgIIXqVuZ0qTH3KxBqDN2HkWvQdmmKcg81cfrjS2RqLJ0KtmwXTMnv/kdeYavk nzVMccfgvlCvP2FEQd/2e7k7pn0RdOHv6FMUE+y8= Date: Tue, 20 Oct 2020 21:52:13 -0700 From: jaegeuk@kernel.org To: Can Guo Cc: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com, Alim Akhtar , Avri Altman Subject: Re: [PATCH v2 5/5] scsi: ufs: fix clkgating on/off correctly Message-ID: <20201021045213.GB3004521@google.com> References: <20201020195258.2005605-1-jaegeuk@kernel.org> <20201020195258.2005605-6-jaegeuk@kernel.org> <2a8ecc4185b3a5411077f4e3fc66000f@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2a8ecc4185b3a5411077f4e3fc66000f@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/21, Can Guo wrote: > On 2020-10-21 03:52, Jaegeuk Kim wrote: > > The below call stack prevents clk_gating at every IO completion. > > We can remove the condition, ufshcd_any_tag_in_use(), since > > clkgating_work > > will check it again. > > > > I think checking ufshcd_any_tag_in_use() in either ufshcd_release() or > gate_work() can break UFS clk gating's functionality. > > ufshcd_any_tag_in_use() was introduced to replace hba->lrb_in_use. However, > they are not exactly same - ufshcd_any_tag_in_use() returns true if any tag > assigned from block layer is still in use, but tags are released > asynchronously > (through block softirq), meaning it does not reflect the real occupation of > UFS host. > That is after UFS host finishes all tasks, ufshcd_any_tag_in_use() can still > return true. > > This change only removes the check of ufshcd_any_tag_in_use() in > ufshcd_release(), > but having the check of it in gate_work() can still prevent gating from > happening. > The current change works for you maybe because the tags are release before > hba->clk_gating.delay_ms expires, but if hba->clk_gating.delay_ms is shorter > or > somehow block softirq is retarded, gate_work() may have chance to see > ufshcd_any_tag_in_use() > returns true. What do you think? I don't think this breaks clkgating, but fix the wrong condition check which prevented gate_work at all. As you mentioned, even if this schedules gate_work by racy conditions, gate_work will handle it as a last resort. > > Thanks, > > Can Guo. > > In __ufshcd_transfer_req_compl > Ihba->lrb_in_use is cleared immediately when UFS driver > finishes all tasks > > > ufshcd_complete_requests(struct ufs_hba *hba) > > ufshcd_transfer_req_compl() > > __ufshcd_transfer_req_compl() > > __ufshcd_release(hba) > > if (ufshcd_any_tag_in_use() == 1) > > return; > > ufshcd_tmc_handler(hba); > > blk_mq_tagset_busy_iter(); > > > > Cc: Alim Akhtar > > Cc: Avri Altman > > Cc: Can Guo > > Signed-off-by: Jaegeuk Kim > > --- > > drivers/scsi/ufs/ufshcd.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c > > index b5ca0effe636..cecbd4ace8b4 100644 > > --- a/drivers/scsi/ufs/ufshcd.c > > +++ b/drivers/scsi/ufs/ufshcd.c > > @@ -1746,7 +1746,7 @@ static void __ufshcd_release(struct ufs_hba *hba) > > > > if (hba->clk_gating.active_reqs || hba->clk_gating.is_suspended || > > hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL || > > - ufshcd_any_tag_in_use(hba) || hba->outstanding_tasks || > > + hba->outstanding_tasks || > > hba->active_uic_cmd || hba->uic_async_done) > > return;