From: "Asutosh Das (asd)" <asutoshd@codeaurora.org>
To: Bart Van Assche <bvanassche@acm.org>,
"Martin K . Petersen" <martin.petersen@oracle.com>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
linux-scsi@vger.kernel.org,
"James E.J. Bottomley" <jejb@linux.ibm.com>,
Bean Huo <beanhuo@micron.com>, Avri Altman <avri.altman@wdc.com>,
Can Guo <cang@codeaurora.org>,
Stanley Chu <stanley.chu@mediatek.com>,
Keoseong Park <keosung.park@samsung.com>
Subject: Re: [PATCH v4 16/17] scsi: ufs: Optimize the command queueing code
Date: Wed, 8 Dec 2021 09:28:05 -0800 [thread overview]
Message-ID: <e58839a4-7dea-b549-740a-c7b8c9028aa1@codeaurora.org> (raw)
In-Reply-To: <0ba5c50f-3e79-2cae-c502-59f70812cca3@codeaurora.org>
On 12/6/2021 2:41 PM, Asutosh Das (asd) wrote:
> On 12/3/2021 3:19 PM, Bart Van Assche wrote:
>> Remove the clock scaling lock from ufshcd_queuecommand() since it is a
>> performance bottleneck. Instead check the SCSI device budget bitmaps in
>> the code that waits for ongoing ufshcd_queuecommand() calls. A bit is
>> set in sdev->budget_map just before scsi_queue_rq() is called and a bit
>> is cleared from that bitmap if scsi_queue_rq() does not submit the
>> request or after the request has finished. See also the
>> blk_mq_{get,put}_dispatch_budget() calls in the block layer.
>>
>> There is no risk for a livelock since the block layer delays queue
>> reruns if queueing a request fails because the SCSI host has been
>> blocked.
>>
>> Cc: Asutosh Das (asd) <asutoshd@codeaurora.org>
>> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
>> ---
>
> Reviewed-by: Asutosh Das <asutoshd@codeaurora.org>
>
Replying to my own mail.
Hi Bart,
>> drivers/scsi/ufs/ufshcd.c | 33 +++++++++++++++++++++++----------
>> drivers/scsi/ufs/ufshcd.h | 1 +
>> 2 files changed, 24 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
>> index 9f0a1f637030..650dddf960c2 100644
>> --- a/drivers/scsi/ufs/ufshcd.c
>> +++ b/drivers/scsi/ufs/ufshcd.c
>> @@ -1070,13 +1070,31 @@ static bool
>> ufshcd_is_devfreq_scaling_required(struct ufs_hba *hba,
>> return false;
>> }
>> +/*
>> + * Determine the number of pending commands by counting the bits in
>> the SCSI
>> + * device budget maps. This approach has been selected because a bit
>> is set in
>> + * the budget map before scsi_host_queue_ready() checks the
>> host_self_blocked
>> + * flag. The host_self_blocked flag can be modified by calling
>> + * scsi_block_requests() or scsi_unblock_requests().
>> + */
>> +static u32 ufshcd_pending_cmds(struct ufs_hba *hba)
>> +{
>> + struct scsi_device *sdev;
>> + u32 pending = 0;
>> +
>> + shost_for_each_device(sdev, hba->host)
>> + pending += sbitmap_weight(&sdev->budget_map);
>> +
I was porting this change to my downstream code and it occurred to me
that in a high IO rate scenario it's possible that bits in the
budget_map may be set even when that particular IO may not be issued to
driver. So there would unnecessary waiting for that to be cleared.
Do you think it's possible?
I think we should wait only for requests which are already started.
e.g. blk_mq_tagset_busy_iter() ?
PLMK your thoughts on this.
>> + return pending;
>> +}
>> +
>> static int ufshcd_wait_for_doorbell_clr(struct ufs_hba *hba,
>> u64 wait_timeout_us)
>> {
>> unsigned long flags;
>> int ret = 0;
>> u32 tm_doorbell;
>> - u32 tr_doorbell;
>> + u32 tr_pending;
>> bool timeout = false, do_last_check = false;
>> ktime_t start;
>> @@ -1094,8 +1112,8 @@ static int ufshcd_wait_for_doorbell_clr(struct
>> ufs_hba *hba,
>> }
>> tm_doorbell = ufshcd_readl(hba, REG_UTP_TASK_REQ_DOOR_BELL);
>> - tr_doorbell = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL);
>> - if (!tm_doorbell && !tr_doorbell) {
>> + tr_pending = ufshcd_pending_cmds(hba);
>> + if (!tm_doorbell && !tr_pending) {
>> timeout = false;
>> break;
>> } else if (do_last_check) {
>> @@ -1115,12 +1133,12 @@ static int ufshcd_wait_for_doorbell_clr(struct
>> ufs_hba *hba,
>> do_last_check = true;
>> }
>> spin_lock_irqsave(hba->host->host_lock, flags);
>> - } while (tm_doorbell || tr_doorbell);
>> + } while (tm_doorbell || tr_pending);
>> if (timeout) {
>> dev_err(hba->dev,
>> "%s: timedout waiting for doorbell to clear (tm=0x%x,
>> tr=0x%x)\n",
>> - __func__, tm_doorbell, tr_doorbell);
>> + __func__, tm_doorbell, tr_pending);
>> ret = -EBUSY;
>> }
>> out:
>> @@ -2681,9 +2699,6 @@ static int ufshcd_queuecommand(struct Scsi_Host
>> *host, struct scsi_cmnd *cmd)
>> WARN_ONCE(tag < 0, "Invalid tag %d\n", tag);
>> - if (!down_read_trylock(&hba->clk_scaling_lock))
>> - return SCSI_MLQUEUE_HOST_BUSY;
>> -
>> /*
>> * Allows the UFS error handler to wait for prior
>> ufshcd_queuecommand()
>> * calls.
>> @@ -2772,8 +2787,6 @@ static int ufshcd_queuecommand(struct Scsi_Host
>> *host, struct scsi_cmnd *cmd)
>> out:
>> rcu_read_unlock();
>> - up_read(&hba->clk_scaling_lock);
>> -
>> if (ufs_trigger_eh()) {
>> unsigned long flags;
>> diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
>> index 8e942762e668..88c20f3608c2 100644
>> --- a/drivers/scsi/ufs/ufshcd.h
>> +++ b/drivers/scsi/ufs/ufshcd.h
>> @@ -778,6 +778,7 @@ struct ufs_hba_monitor {
>> * @clk_list_head: UFS host controller clocks list node head
>> * @pwr_info: holds current power mode
>> * @max_pwr_info: keeps the device max valid pwm
>> + * @clk_scaling_lock: used to serialize device commands and clock
>> scaling
>> * @desc_size: descriptor sizes reported by device
>> * @urgent_bkops_lvl: keeps track of urgent bkops level for device
>> * @is_urgent_bkops_lvl_checked: keeps track if the urgent bkops
>> level for
>>
>
>
--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
Linux Foundation Collaborative Project
next prev parent reply other threads:[~2021-12-08 17:28 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-03 23:19 [PATCH v4 00/17] UFS patches for kernel v5.17 Bart Van Assche
2021-12-03 23:19 ` [PATCH v4 01/17] scsi: core: Fix scsi_device_max_queue_depth() Bart Van Assche
2021-12-03 23:19 ` [PATCH v4 02/17] scsi: ufs: Rename a function argument Bart Van Assche
2021-12-03 23:19 ` [PATCH v4 03/17] scsi: ufs: Remove is_rpmb_wlun() Bart Van Assche
2021-12-03 23:19 ` [PATCH v4 04/17] scsi: ufs: Remove the sdev_rpmb member Bart Van Assche
2021-12-03 23:19 ` [PATCH v4 05/17] scsi: ufs: Remove dead code Bart Van Assche
2021-12-03 23:19 ` [PATCH v4 06/17] scsi: ufs: Fix race conditions related to driver data Bart Van Assche
2021-12-03 23:19 ` [PATCH v4 07/17] scsi: ufs: Remove ufshcd_any_tag_in_use() Bart Van Assche
2021-12-03 23:19 ` [PATCH v4 08/17] scsi: ufs: Rework ufshcd_change_queue_depth() Bart Van Assche
2021-12-03 23:19 ` [PATCH v4 09/17] scsi: ufs: Fix a deadlock in the error handler Bart Van Assche
2021-12-03 23:19 ` [PATCH v4 10/17] scsi: ufs: Remove hba->cmd_queue Bart Van Assche
2021-12-03 23:19 ` [PATCH v4 11/17] scsi: ufs: Remove the 'update_scaling' local variable Bart Van Assche
2021-12-03 23:19 ` [PATCH v4 12/17] scsi: ufs: Introduce ufshcd_release_scsi_cmd() Bart Van Assche
2021-12-03 23:19 ` [PATCH v4 13/17] scsi: ufs: Improve SCSI abort handling further Bart Van Assche
2021-12-03 23:19 ` [PATCH v4 14/17] scsi: ufs: Fix a kernel crash during shutdown Bart Van Assche
2021-12-03 23:19 ` [PATCH v4 15/17] scsi: ufs: Stop using the clock scaling lock in the error handler Bart Van Assche
2021-12-03 23:19 ` [PATCH v4 16/17] scsi: ufs: Optimize the command queueing code Bart Van Assche
2021-12-06 22:41 ` Asutosh Das (asd)
2021-12-08 17:28 ` Asutosh Das (asd) [this message]
2021-12-08 17:53 ` Bart Van Assche
2021-12-14 4:04 ` Bjorn Andersson
2021-12-14 4:57 ` Bart Van Assche
2021-12-15 3:52 ` Bjorn Andersson
2021-12-15 18:44 ` Bart Van Assche
2021-12-03 23:19 ` [PATCH v4 17/17] scsi: ufs: Implement polling support Bart Van Assche
2021-12-07 3:31 ` [PATCH v4 00/17] UFS patches for kernel v5.17 Martin K. Petersen
2021-12-14 4:40 ` Martin K. Petersen
2021-12-14 7:14 ` Avri Altman
2021-12-14 7:18 ` Martin K. Petersen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e58839a4-7dea-b549-740a-c7b8c9028aa1@codeaurora.org \
--to=asutoshd@codeaurora.org \
--cc=adrian.hunter@intel.com \
--cc=avri.altman@wdc.com \
--cc=beanhuo@micron.com \
--cc=bvanassche@acm.org \
--cc=cang@codeaurora.org \
--cc=jaegeuk@kernel.org \
--cc=jejb@linux.ibm.com \
--cc=keosung.park@samsung.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=stanley.chu@mediatek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox