* RE: [PATCH v37 3/4] scsi: ufs: Prepare HPB read for cached sub-region @ 2021-06-13 23:40 정요한(JOUNG YOHAN) Mobile SE 2021-06-14 6:48 ` Avri Altman 0 siblings, 1 reply; 6+ messages in thread From: 정요한(JOUNG YOHAN) Mobile SE @ 2021-06-13 23:40 UTC (permalink / raw) To: avri.altman@wdc.com Cc: alim.akhtar@samsung.com, asutoshd@codeaurora.org, bvanassche@acm.org, cang@codeaurora.org, d_hyun.kwon@samsung.com, daejun7.park@samsung.com, gregkh@linuxfoundation.org, huobean@gmail.com, j-young.choi@samsung.com, jaemyung.lee@samsung.com, 최재영(CHOI JAE YOUNG) Mobile SE, javier.gonz@samsung.com, jejb@linux.ibm.com, jh.i.park@samsung.com, jieon.seol@samsung.com, keosung.park@samsung.com, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, martin.petersen@oracle.com, stanley.chu@mediatek.com, sungjun07.park@samsung.com, 정요한(JOUNG YOHAN) Mobile SE > > >+ /* > > >+ * If the region state is active, mctx must be allocated. > > >+ * In this case, check whether the region is evicted or > > >+ * mctx allcation fail. > > >+ */ > > >+ if (unlikely(!srgn->mctx)) { > > >+ dev_err(&hpb->sdev_ufs_lu->sdev_dev, > > >+ "no mctx in region %d subregion %d.\n", > > >+ srgn->rgn_idx, srgn->srgn_idx); > > >+ return true; > > >+ } > > >+ > > >+ if ((srgn_offset + cnt) > bitmap_len) > > >+ bit_len = bitmap_len - srgn_offset; > > >+ else > > >+ bit_len = cnt; > > >+ > > >+ if (find_next_bit(srgn->mctx->ppn_dirty, bitmap_len, > > >+ srgn_offset) < bit_len + srgn_offset) > > >+ return true; > > >+ > > > > It seems unnecessary to search through bitmap_len > > How about searching by transfer size? > > > > if (find_next_bit(srgn->mctx->ppn_dirty, > > bit_len + srgn_offset, srgn_offset) < bit_len + srgn_offset) > Isn't bit_len should be used for size, and not bit_len + srgn_offset ? then find_next_bit checks from start to bit_len. find_next_bit stops checking if start is greater than bit_len. it does not check for dirty as transfer_size. Thanks Yohan > > Thanks, > Avri > > > > > Thanks > > Yohan ^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH v37 3/4] scsi: ufs: Prepare HPB read for cached sub-region 2021-06-13 23:40 [PATCH v37 3/4] scsi: ufs: Prepare HPB read for cached sub-region 정요한(JOUNG YOHAN) Mobile SE @ 2021-06-14 6:48 ` Avri Altman 0 siblings, 0 replies; 6+ messages in thread From: Avri Altman @ 2021-06-14 6:48 UTC (permalink / raw) To: yohan.joung@sk.com Cc: alim.akhtar@samsung.com, asutoshd@codeaurora.org, bvanassche@acm.org, cang@codeaurora.org, d_hyun.kwon@samsung.com, daejun7.park@samsung.com, gregkh@linuxfoundation.org, huobean@gmail.com, j-young.choi@samsung.com, jaemyung.lee@samsung.com, jaeyoung21.choi@sk.com, javier.gonz@samsung.com, jejb@linux.ibm.com, jh.i.park@samsung.com, jieon.seol@samsung.com, keosung.park@samsung.com, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, martin.petersen@oracle.com, stanley.chu@mediatek.com, sungjun07.park@samsung.com > > > >+ /* > > > >+ * If the region state is active, mctx must be allocated. > > > >+ * In this case, check whether the region is evicted or > > > >+ * mctx allcation fail. > > > >+ */ > > > >+ if (unlikely(!srgn->mctx)) { > > > >+ dev_err(&hpb->sdev_ufs_lu->sdev_dev, > > > >+ "no mctx in region %d subregion %d.\n", > > > >+ srgn->rgn_idx, srgn->srgn_idx); > > > >+ return true; > > > >+ } > > > >+ > > > >+ if ((srgn_offset + cnt) > bitmap_len) > > > >+ bit_len = bitmap_len - srgn_offset; > > > >+ else > > > >+ bit_len = cnt; > > > >+ > > > >+ if (find_next_bit(srgn->mctx->ppn_dirty, bitmap_len, > > > >+ srgn_offset) < bit_len + srgn_offset) > > > >+ return true; > > > >+ > > > > > > It seems unnecessary to search through bitmap_len > > > How about searching by transfer size? > > > > > > if (find_next_bit(srgn->mctx->ppn_dirty, > > > bit_len + srgn_offset, srgn_offset) < bit_len + srgn_offset) > > Isn't bit_len should be used for size, and not bit_len + srgn_offset ? > > then find_next_bit checks from start to bit_len. > find_next_bit stops checking if start is greater than bit_len. > it does not check for dirty as transfer_size. Right. Size (nbits in _find_next_bit) practically means @end - Confusing... Either way, Is this tad optimization worth another spin in your opinion? Thanks, Avri > > Thanks > Yohan > > > > > Thanks, > > Avri > > > > > > > > Thanks > > > Yohan ^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH v37 3/4] scsi: ufs: Prepare HPB read for cached sub-region @ 2021-06-14 7:44 정요한(JOUNG YOHAN) Mobile SE 0 siblings, 0 replies; 6+ messages in thread From: 정요한(JOUNG YOHAN) Mobile SE @ 2021-06-14 7:44 UTC (permalink / raw) To: avri.altman@wdc.com Cc: alim.akhtar@samsung.com, asutoshd@codeaurora.org, bvanassche@acm.org, cang@codeaurora.org, d_hyun.kwon@samsung.com, daejun7.park@samsung.com, gregkh@linuxfoundation.org, huobean@gmail.com, j-young.choi@samsung.com, jaemyung.lee@samsung.com, 최재영(CHOI JAE YOUNG) Mobile SE, javier.gonz@samsung.com, jejb@linux.ibm.com, jh.i.park@samsung.com, jieon.seol@samsung.com, keosung.park@samsung.com, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, martin.petersen@oracle.com, stanley.chu@mediatek.com, sungjun07.park@samsung.com, 정요한(JOUNG YOHAN) Mobile SE > > > > >+ /* > > > > >+ * If the region state is active, mctx must be allocated. > > > > >+ * In this case, check whether the region is evicted or > > > > >+ * mctx allcation fail. > > > > >+ */ > > > > >+ if (unlikely(!srgn->mctx)) { > > > > >+ dev_err(&hpb->sdev_ufs_lu->sdev_dev, > > > > >+ "no mctx in region %d subregion %d.\n", > > > > >+ srgn->rgn_idx, srgn->srgn_idx); > > > > >+ return true; > > > > >+ } > > > > >+ > > > > >+ if ((srgn_offset + cnt) > bitmap_len) > > > > >+ bit_len = bitmap_len - srgn_offset; > > > > >+ else > > > > >+ bit_len = cnt; > > > > >+ > > > > >+ if (find_next_bit(srgn->mctx->ppn_dirty, bitmap_len, > > > > >+ srgn_offset) < bit_len + srgn_offset) > > > > >+ return true; > > > > >+ > > > > > > > > It seems unnecessary to search through bitmap_len > > > > How about searching by transfer size? > > > > > > > > if (find_next_bit(srgn->mctx->ppn_dirty, > > > > bit_len + srgn_offset, srgn_offset) < bit_len + srgn_offset) > > > Isn't bit_len should be used for size, and not bit_len + srgn_offset ? > > > > then find_next_bit checks from start to bit_len. > > find_next_bit stops checking if start is greater than bit_len. > > it does not check for dirty as transfer_size. > Right. Size (nbits in _find_next_bit) practically means @end - Confusing... > Either way, Is this tad optimization worth another spin in your opinion? Worst case, we have to search every time up to the bitmap_len size. Even though, when bit_len is 1, only 1 bit needs to be checked it can increase the effect, depending on the subregion size. Thanks Yohan > > Thanks, > Avri > > > > > Thanks > > Yohan > > > > > > > > Thanks, > > > Avri > > > > > > > > > > > Thanks > > > > Yohan ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v37 3/4] scsi: ufs: Prepare HPB read for cached sub-region
@ 2021-06-11 5:07 정요한(JOUNG YOHAN) Mobile SE
2021-06-13 10:20 ` Avri Altman
0 siblings, 1 reply; 6+ messages in thread
From: 정요한(JOUNG YOHAN) Mobile SE @ 2021-06-11 5:07 UTC (permalink / raw)
To: daejun7.park@samsung.com
Cc: alim.akhtar@samsung.com, asutoshd@codeaurora.org,
avri.altman@wdc.com, bvanassche@acm.org, cang@codeaurora.org,
d_hyun.kwon@samsung.com, Greg KH, huobean@gmail.com,
j-young.choi@samsung.com, jaemyung.lee@samsung.com,
javier.gonz@samsung.com, jejb@linux.ibm.com,
jh.i.park@samsung.com, jieon.seol@samsung.com,
keosung.park@samsung.com, linux-kernel@vger.kernel.org,
linux-scsi@vger.kernel.org, martin.petersen@oracle.com,
stanley.chu@mediatek.com, sungjun07.park@samsung.com,
최재영(CHOI JAE YOUNG) Mobile SE
>+ /*
>+ * If the region state is active, mctx must be allocated.
>+ * In this case, check whether the region is evicted or
>+ * mctx allcation fail.
>+ */
>+ if (unlikely(!srgn->mctx)) {
>+ dev_err(&hpb->sdev_ufs_lu->sdev_dev,
>+ "no mctx in region %d subregion %d.\n",
>+ srgn->rgn_idx, srgn->srgn_idx);
>+ return true;
>+ }
>+
>+ if ((srgn_offset + cnt) > bitmap_len)
>+ bit_len = bitmap_len - srgn_offset;
>+ else
>+ bit_len = cnt;
>+
>+ if (find_next_bit(srgn->mctx->ppn_dirty, bitmap_len,
>+ srgn_offset) < bit_len + srgn_offset)
>+ return true;
>+
It seems unnecessary to search through bitmap_len
How about searching by transfer size?
if (find_next_bit(srgn->mctx->ppn_dirty,
bit_len + srgn_offset, srgn_offset) < bit_len + srgn_offset)
Thanks
Yohan
^ permalink raw reply [flat|nested] 6+ messages in thread* RE: [PATCH v37 3/4] scsi: ufs: Prepare HPB read for cached sub-region 2021-06-11 5:07 정요한(JOUNG YOHAN) Mobile SE @ 2021-06-13 10:20 ` Avri Altman 0 siblings, 0 replies; 6+ messages in thread From: Avri Altman @ 2021-06-13 10:20 UTC (permalink / raw) To: yohan.joung@sk.com, daejun7.park@samsung.com Cc: alim.akhtar@samsung.com, asutoshd@codeaurora.org, bvanassche@acm.org, cang@codeaurora.org, d_hyun.kwon@samsung.com, Greg KH, huobean@gmail.com, j-young.choi@samsung.com, jaemyung.lee@samsung.com, javier.gonz@samsung.com, jejb@linux.ibm.com, jh.i.park@samsung.com, jieon.seol@samsung.com, keosung.park@samsung.com, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, martin.petersen@oracle.com, stanley.chu@mediatek.com, sungjun07.park@samsung.com, jaeyoung21.choi@sk.com > >+ /* > >+ * If the region state is active, mctx must be allocated. > >+ * In this case, check whether the region is evicted or > >+ * mctx allcation fail. > >+ */ > >+ if (unlikely(!srgn->mctx)) { > >+ dev_err(&hpb->sdev_ufs_lu->sdev_dev, > >+ "no mctx in region %d subregion %d.\n", > >+ srgn->rgn_idx, srgn->srgn_idx); > >+ return true; > >+ } > >+ > >+ if ((srgn_offset + cnt) > bitmap_len) > >+ bit_len = bitmap_len - srgn_offset; > >+ else > >+ bit_len = cnt; > >+ > >+ if (find_next_bit(srgn->mctx->ppn_dirty, bitmap_len, > >+ srgn_offset) < bit_len + srgn_offset) > >+ return true; > >+ > > It seems unnecessary to search through bitmap_len > How about searching by transfer size? > > if (find_next_bit(srgn->mctx->ppn_dirty, > bit_len + srgn_offset, srgn_offset) < bit_len + srgn_offset) Isn't bit_len should be used for size, and not bit_len + srgn_offset ? Thanks, Avri > > Thanks > Yohan ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <CGME20210611022142epcms2p374ea5b82cfe122de69a7fefe27edf856@epcms2p2>]
* [PATCH v37 0/4] scsi: ufs: Add Host Performance Booster Support @ 2021-06-11 2:21 ` Daejun Park 2021-06-11 2:23 ` [PATCH v37 3/4] scsi: ufs: Prepare HPB read for cached sub-region Daejun Park 0 siblings, 1 reply; 6+ messages in thread From: Daejun Park @ 2021-06-11 2:21 UTC (permalink / raw) To: Greg KH, avri.altman@wdc.com, jejb@linux.ibm.com, martin.petersen@oracle.com, asutoshd@codeaurora.org, stanley.chu@mediatek.com, cang@codeaurora.org, bvanassche@acm.org, huobean@gmail.com, ALIM AKHTAR, Daejun Park Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, JinHwan Park, Javier Gonzalez, Sung-Jun Park, Jinyoung CHOI, Dukhyun Kwon, Keoseong Park, Jaemyung Lee, Jieon Seol Changelog: v36 -> v37 1. Fix wrong usage of find_next_bit API. 2. Address Barts' comments. (sysfs, documentation, return type) 3. Change HPB_MULTI_CHUNK_HIGH for 1MB-sized request. v35 -> v36 1. Changed ppn variable type from u64 to __be64. 2. Added WARN_ON_ONCE() to check for HPB read IO size exceeded. v34 -> v35 1. Addressed Bart's comments (type casting) 2. Rebase 5.14 scsi-queue v33 -> v34 Fix warning about NULL check before some freeing functions is not needed. v32 -> v33 1. Fix wrong usage of scsi_command_normalize_sense. 2. Addressed Bart's comments (func. name, type casting, parentheses) v31 -> v32 Delete unused parameter of unmap API. v30 -> v31 Delete unnecessary debug message. v29 -> v30 1. Add support to reuse bio of pre-request. 2. Delete unreached code in the ufshpb_issue_map_req. v28 -> v29 1. Remove unused variable that reported by kernel test robot. v27 -> v28 1. Fix wrong return value of ufshpb_prep. v26 -> v27 1. Fix wrong refernce of sense buffer in pre_req complete function. 2. Fix read_id error. 3. Fix chunk size checking for HPB 1.0. 4. Mute unnecessary messages before HPB initialization. v25 -> v26 1. Fix wrong chunk size checking for HPB 1.0. 2. Fix wrong max data size for HPB single command. 3. Fix typo error. v24 -> v25 1. Change write buffer API for unmap region. 2. Add checking hpb_enable for avoiding unnecessary memory allocation. 3. Change pr_info to dev_info. 4. Change default requeue timeout value for HPB read. 5. Fix wrong offset manipulation on ufshpb_prep_entry. v23 -> v24 1. Fix build error reported by kernel test robot. v22 -> v23 1. Add support compatibility of HPB 1.0. 2. Fix read id for single HPB read command. 3. Fix number of pre-allocated requests for write buffer. 4. Add fast path for response UPIU that has same LUN in sense data. 5. Remove WARN_ON for preventing kernel crash. 7. Fix wrong argument for read buffer command. v21 -> v22 1. Add support processing response UPIU in suspend state. 2. Add support HPB hint from other LU. 3. Add sending write buffer with 0x03 after HPB init. v20 -> v21 1. Add bMAX_DATA_SIZE_FOR_HPB_SINGLE_CMD attr. and fHPBen flag support. v19 -> v20 1. Add documentation for sysfs entries of hpb->stat. 2. Fix read buffer command for under-sized sub-region. 3. Fix wrong condition checking for kick map work. 4. Delete redundant response UPIU checking. 5. Add LUN checking in response UPIU. 6. Fix possible deadlock problem due to runtime PM. 7. Add instant changing of sub-region state from response UPIU. 8. Fix endian problem in prefetched PPN. 9. Add JESD220-3A (HPB v2.0) support. v18 -> 19 1. Fix null pointer error when printing sysfs from non-HPB LU. 2. Apply HPB read opcode in lrbp->cmd->cmnd (from Can Guo's review). 3. Rebase the patch on 5.12/scsi-queue. v17 -> v18 Fix build error which reported by kernel test robot. v16 -> v17 1. Rename hpb_state_lock to rgn_state_lock and move it to corresponding patch. 2. Remove redundant information messages. v15 -> v16 1. Add missed sysfs ABI documentation. v14 -> v15 1. Remove duplicated sysfs ABI entries in documentation. 2. Add experiment result of HPB performance testing with iozone. v13 -> v14 1. Cleanup codes by commentted in Greg's review. 2. Add documentation for sysfs entries (from Greg's review). 3. Add experiment result of HPB performance testing. v12 -> v13 1. Cleanup codes by comments from Can Guo. 2. Add HPB related descriptor/flag/attributes in sysfs. 3. Change base commit from 5.10/scsi-queue to 5.11/scsi-queue. v11 -> v12 1. Fixed to return error value when HPB fails to initialize pinned active region. 2. Fixed to disable HPB feature if HPB fails to allocate essential memory and workqueue. 3. Fixed to change proper sub-region state when region is already evicted. v10 -> v11 Add a newline at end the last line on Kconfig file. v9 -> v10 1. Fixed 64-bit division error 2. Fixed problems commentted in Bart's review. v8 -> v9 1. Change sysfs initialization. 2. Change reading descriptor during HPB initialization 3. Fixed problems commentted in Bart's review. 4. Change base commit from 5.9/scsi-queue to 5.10/scsi-queue. v7 -> v8 Remove wrongly added tags. v6 -> v7 1. Remove UFS feature layer. 2. Cleanup for sparse error. v5 -> v6 Change base commit to b53293fa662e28ae0cdd40828dc641c09f133405 v4 -> v5 Delete unused macro define. v3 -> v4 1. Cleanup. v2 -> v3 1. Add checking input module parameter value. 2. Change base commit from 5.8/scsi-queue to 5.9/scsi-queue. 3. Cleanup for unused variables and label. v1 -> v2 1. Change the full boilerplate text to SPDX style. 2. Adopt dynamic allocation for sub-region data structure. 3. Cleanup. NAND flash memory-based storage devices use Flash Translation Layer (FTL) to translate logical addresses of I/O requests to corresponding flash memory addresses. Mobile storage devices typically have RAM with constrained size, thus lack in memory to keep the whole mapping table. Therefore, mapping tables are partially retrieved from NAND flash on demand, causing random-read performance degradation. To improve random read performance, JESD220-3 (HPB v1.0) proposes HPB (Host Performance Booster) which uses host system memory as a cache for the FTL mapping table. By using HPB, FTL data can be read from host memory faster than from NAND flash memory. The current version only supports the DCM (device control mode). This patch consists of 3 parts to support HPB feature. 1) HPB probe and initialization process 2) READ -> HPB READ using cached map information 3) L2P (logical to physical) map management In the HPB probe and init process, the device information of the UFS is queried. After checking supported features, the data structure for the HPB is initialized according to the device information. A read I/O in the active sub-region where the map is cached is changed to HPB READ by the HPB. The HPB manages the L2P map using information received from the device. For active sub-region, the HPB caches through ufshpb_map request. For the in-active region, the HPB discards the L2P map. When a write I/O occurs in an active sub-region area, associated dirty bitmap checked as dirty for preventing stale read. HPB is shown to have a performance improvement of 58 - 67% for random read workload. [1] [1]: https://www.usenix.org/conference/hotstorage17/program/presentation/jeong Daejun Park (4): scsi: ufs: Introduce HPB feature scsi: ufs: L2P map management for HPB read scsi: ufs: Prepare HPB read for cached sub-region scsi: ufs: Add HPB 2.0 support Documentation/ABI/testing/sysfs-driver-ufs | 162 ++ drivers/scsi/ufs/Kconfig | 9 + drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufs-sysfs.c | 22 + drivers/scsi/ufs/ufs.h | 54 +- drivers/scsi/ufs/ufshcd.c | 74 +- drivers/scsi/ufs/ufshcd.h | 30 + drivers/scsi/ufs/ufshpb.c | 2380 ++++++++++++++++++++ drivers/scsi/ufs/ufshpb.h | 277 +++ 9 files changed, 3007 insertions(+), 2 deletions(-) create mode 100644 drivers/scsi/ufs/ufshpb.c create mode 100644 drivers/scsi/ufs/ufshpb.h -- 2.25.1 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v37 3/4] scsi: ufs: Prepare HPB read for cached sub-region 2021-06-11 2:21 ` [PATCH v37 0/4] scsi: ufs: Add Host Performance Booster Support Daejun Park @ 2021-06-11 2:23 ` Daejun Park 0 siblings, 0 replies; 6+ messages in thread From: Daejun Park @ 2021-06-11 2:23 UTC (permalink / raw) To: Daejun Park, Greg KH, avri.altman@wdc.com, jejb@linux.ibm.com, martin.petersen@oracle.com, asutoshd@codeaurora.org, stanley.chu@mediatek.com, cang@codeaurora.org, bvanassche@acm.org, huobean@gmail.com, ALIM AKHTAR Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, JinHwan Park, Javier Gonzalez, Sung-Jun Park, Jinyoung CHOI, Dukhyun Kwon, Keoseong Park, Jaemyung Lee, Jieon Seol This patch changes the read I/O to the HPB read I/O. If the logical address of the read I/O belongs to active sub-region, the HPB driver modifies the read I/O command to HPB read. It modifies the UPIU command of UFS instead of modifying the existing SCSI command. In the HPB version 1.0, the maximum read I/O size that can be converted to HPB read is 4KB. The dirty map of the active sub-region prevents an incorrect HPB read that has stale physical page number which is updated by previous write I/O. Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Reviewed-by: Can Guo <cang@codeaurora.org> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Bean Huo <beanhuo@micron.com> Reviewed-by: Stanley Chu <stanley.chu@mediatek.com> Acked-by: Avri Altman <Avri.Altman@wdc.com> Tested-by: Bean Huo <beanhuo@micron.com> Tested-by: Can Guo <cang@codeaurora.org> Tested-by: Stanley Chu <stanley.chu@mediatek.com> Signed-off-by: Daejun Park <daejun7.park@samsung.com> --- drivers/scsi/ufs/ufshcd.c | 2 + drivers/scsi/ufs/ufshpb.c | 259 +++++++++++++++++++++++++++++++++++++- drivers/scsi/ufs/ufshpb.h | 2 + 3 files changed, 260 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 02490f8f15d4..da96b7c6b108 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -2721,6 +2721,8 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) lrbp->req_abort_skip = false; + ufshpb_prep(hba, lrbp); + ufshcd_comp_scsi_upiu(hba, lrbp); err = ufshcd_map_sg(hba, lrbp); diff --git a/drivers/scsi/ufs/ufshpb.c b/drivers/scsi/ufs/ufshpb.c index 47ccd63063fc..878b34b02826 100644 --- a/drivers/scsi/ufs/ufshpb.c +++ b/drivers/scsi/ufs/ufshpb.c @@ -46,6 +46,29 @@ static void ufshpb_set_state(struct ufshpb_lu *hpb, int state) atomic_set(&hpb->hpb_state, state); } +static int ufshpb_is_valid_srgn(struct ufshpb_region *rgn, + struct ufshpb_subregion *srgn) +{ + return rgn->rgn_state != HPB_RGN_INACTIVE && + srgn->srgn_state == HPB_SRGN_VALID; +} + +static bool ufshpb_is_read_cmd(struct scsi_cmnd *cmd) +{ + return req_op(cmd->request) == REQ_OP_READ; +} + +static bool ufshpb_is_write_or_discard(struct scsi_cmnd *cmd) +{ + return op_is_write(req_op(cmd->request)) || + op_is_discard(req_op(cmd->request)); +} + +static bool ufshpb_is_supported_chunk(int transfer_len) +{ + return transfer_len <= HPB_MULTI_CHUNK_HIGH; +} + static bool ufshpb_is_general_lun(int lun) { return lun < UFS_UPIU_MAX_UNIT_NUM_ID; @@ -80,8 +103,8 @@ static void ufshpb_kick_map_work(struct ufshpb_lu *hpb) } static bool ufshpb_is_hpb_rsp_valid(struct ufs_hba *hba, - struct ufshcd_lrb *lrbp, - struct utp_hpb_rsp *rsp_field) + struct ufshcd_lrb *lrbp, + struct utp_hpb_rsp *rsp_field) { /* Check HPB_UPDATE_ALERT */ if (!(lrbp->ucd_rsp_ptr->header.dword_2 & @@ -107,6 +130,236 @@ static bool ufshpb_is_hpb_rsp_valid(struct ufs_hba *hba, return true; } +static void ufshpb_set_ppn_dirty(struct ufshpb_lu *hpb, int rgn_idx, + int srgn_idx, int srgn_offset, int cnt) +{ + struct ufshpb_region *rgn; + struct ufshpb_subregion *srgn; + int set_bit_len; + int bitmap_len; + +next_srgn: + rgn = hpb->rgn_tbl + rgn_idx; + srgn = rgn->srgn_tbl + srgn_idx; + + if (likely(!srgn->is_last)) + bitmap_len = hpb->entries_per_srgn; + else + bitmap_len = hpb->last_srgn_entries; + + if ((srgn_offset + cnt) > bitmap_len) + set_bit_len = bitmap_len - srgn_offset; + else + set_bit_len = cnt; + + if (rgn->rgn_state != HPB_RGN_INACTIVE && + srgn->srgn_state == HPB_SRGN_VALID) + bitmap_set(srgn->mctx->ppn_dirty, srgn_offset, set_bit_len); + + srgn_offset = 0; + if (++srgn_idx == hpb->srgns_per_rgn) { + srgn_idx = 0; + rgn_idx++; + } + + cnt -= set_bit_len; + if (cnt > 0) + goto next_srgn; +} + +static bool ufshpb_test_ppn_dirty(struct ufshpb_lu *hpb, int rgn_idx, + int srgn_idx, int srgn_offset, int cnt) +{ + struct ufshpb_region *rgn; + struct ufshpb_subregion *srgn; + int bitmap_len; + int bit_len; + +next_srgn: + rgn = hpb->rgn_tbl + rgn_idx; + srgn = rgn->srgn_tbl + srgn_idx; + + if (likely(!srgn->is_last)) + bitmap_len = hpb->entries_per_srgn; + else + bitmap_len = hpb->last_srgn_entries; + + if (!ufshpb_is_valid_srgn(rgn, srgn)) + return true; + + /* + * If the region state is active, mctx must be allocated. + * In this case, check whether the region is evicted or + * mctx allcation fail. + */ + if (unlikely(!srgn->mctx)) { + dev_err(&hpb->sdev_ufs_lu->sdev_dev, + "no mctx in region %d subregion %d.\n", + srgn->rgn_idx, srgn->srgn_idx); + return true; + } + + if ((srgn_offset + cnt) > bitmap_len) + bit_len = bitmap_len - srgn_offset; + else + bit_len = cnt; + + if (find_next_bit(srgn->mctx->ppn_dirty, bitmap_len, + srgn_offset) < bit_len + srgn_offset) + return true; + + srgn_offset = 0; + if (++srgn_idx == hpb->srgns_per_rgn) { + srgn_idx = 0; + rgn_idx++; + } + + cnt -= bit_len; + if (cnt > 0) + goto next_srgn; + + return false; +} + +static int ufshpb_fill_ppn_from_page(struct ufshpb_lu *hpb, + struct ufshpb_map_ctx *mctx, int pos, + int len, __be64 *ppn_buf) +{ + struct page *page; + int index, offset; + int copied; + + index = pos / (PAGE_SIZE / HPB_ENTRY_SIZE); + offset = pos % (PAGE_SIZE / HPB_ENTRY_SIZE); + + if ((offset + len) <= (PAGE_SIZE / HPB_ENTRY_SIZE)) + copied = len; + else + copied = (PAGE_SIZE / HPB_ENTRY_SIZE) - offset; + + page = mctx->m_page[index]; + if (unlikely(!page)) { + dev_err(&hpb->sdev_ufs_lu->sdev_dev, + "error. cannot find page in mctx\n"); + return -ENOMEM; + } + + memcpy(ppn_buf, page_address(page) + (offset * HPB_ENTRY_SIZE), + copied * HPB_ENTRY_SIZE); + + return copied; +} + +static void +ufshpb_get_pos_from_lpn(struct ufshpb_lu *hpb, unsigned long lpn, int *rgn_idx, + int *srgn_idx, int *offset) +{ + int rgn_offset; + + *rgn_idx = lpn >> hpb->entries_per_rgn_shift; + rgn_offset = lpn & hpb->entries_per_rgn_mask; + *srgn_idx = rgn_offset >> hpb->entries_per_srgn_shift; + *offset = rgn_offset & hpb->entries_per_srgn_mask; +} + +static void +ufshpb_set_hpb_read_to_upiu(struct ufshpb_lu *hpb, struct ufshcd_lrb *lrbp, + u32 lpn, __be64 ppn, u8 transfer_len) +{ + unsigned char *cdb = lrbp->cmd->cmnd; + + cdb[0] = UFSHPB_READ; + + /* ppn value is stored as big-endian in the host memory */ + memcpy(&cdb[6], &ppn, sizeof(__be64)); + cdb[14] = transfer_len; + + lrbp->cmd->cmd_len = UFS_CDB_SIZE; +} + +/* + * This function will set up HPB read command using host-side L2P map data. + * In HPB v1.0, maximum size of HPB read command is 4KB. + */ +void ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) +{ + struct ufshpb_lu *hpb; + struct ufshpb_region *rgn; + struct ufshpb_subregion *srgn; + struct scsi_cmnd *cmd = lrbp->cmd; + u32 lpn; + __be64 ppn; + unsigned long flags; + int transfer_len, rgn_idx, srgn_idx, srgn_offset; + int err = 0; + + hpb = ufshpb_get_hpb_data(cmd->device); + if (!hpb) + return; + + if (ufshpb_get_state(hpb) == HPB_INIT) + return; + + if (ufshpb_get_state(hpb) != HPB_PRESENT) { + dev_notice(&hpb->sdev_ufs_lu->sdev_dev, + "%s: ufshpb state is not PRESENT", __func__); + return; + } + + if (blk_rq_is_scsi(cmd->request) || + (!ufshpb_is_write_or_discard(cmd) && + !ufshpb_is_read_cmd(cmd))) + return; + + transfer_len = sectors_to_logical(cmd->device, + blk_rq_sectors(cmd->request)); + if (unlikely(!transfer_len)) + return; + + lpn = sectors_to_logical(cmd->device, blk_rq_pos(cmd->request)); + ufshpb_get_pos_from_lpn(hpb, lpn, &rgn_idx, &srgn_idx, &srgn_offset); + rgn = hpb->rgn_tbl + rgn_idx; + srgn = rgn->srgn_tbl + srgn_idx; + + /* If command type is WRITE or DISCARD, set bitmap as drity */ + if (ufshpb_is_write_or_discard(cmd)) { + spin_lock_irqsave(&hpb->rgn_state_lock, flags); + ufshpb_set_ppn_dirty(hpb, rgn_idx, srgn_idx, srgn_offset, + transfer_len); + spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); + return; + } + + if (!ufshpb_is_supported_chunk(transfer_len)) + return; + + WARN_ON_ONCE(transfer_len > HPB_MULTI_CHUNK_HIGH); + + spin_lock_irqsave(&hpb->rgn_state_lock, flags); + if (ufshpb_test_ppn_dirty(hpb, rgn_idx, srgn_idx, srgn_offset, + transfer_len)) { + hpb->stats.miss_cnt++; + spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); + return; + } + + err = ufshpb_fill_ppn_from_page(hpb, srgn->mctx, srgn_offset, 1, &ppn); + spin_unlock_irqrestore(&hpb->rgn_state_lock, flags); + if (unlikely(err < 0)) { + /* + * In this case, the region state is active, + * but the ppn table is not allocated. + * Make sure that ppn table must be allocated on + * active state. + */ + dev_err(hba->dev, "get ppn failed. err %d\n", err); + return; + } + + ufshpb_set_hpb_read_to_upiu(hpb, lrbp, lpn, ppn, transfer_len); + + hpb->stats.hit_cnt++; +} static struct ufshpb_req *ufshpb_get_map_req(struct ufshpb_lu *hpb, struct ufshpb_subregion *srgn) { @@ -153,7 +406,7 @@ static struct ufshpb_req *ufshpb_get_map_req(struct ufshpb_lu *hpb, } static void ufshpb_put_map_req(struct ufshpb_lu *hpb, - struct ufshpb_req *map_req) + struct ufshpb_req *map_req) { bio_put(map_req->bio); blk_put_request(map_req->req); diff --git a/drivers/scsi/ufs/ufshpb.h b/drivers/scsi/ufs/ufshpb.h index dcc0ca3b8158..6e6a0252dc15 100644 --- a/drivers/scsi/ufs/ufshpb.h +++ b/drivers/scsi/ufs/ufshpb.h @@ -201,6 +201,7 @@ struct ufs_hba; struct ufshcd_lrb; #ifndef CONFIG_SCSI_UFS_HPB +static void ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) {} static void ufshpb_rsp_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) {} static void ufshpb_resume(struct ufs_hba *hba) {} static void ufshpb_suspend(struct ufs_hba *hba) {} @@ -214,6 +215,7 @@ static bool ufshpb_is_allowed(struct ufs_hba *hba) { return false; } static void ufshpb_get_geo_info(struct ufs_hba *hba, u8 *geo_buf) {} static void ufshpb_get_dev_info(struct ufs_hba *hba, u8 *desc_buf) {} #else +void ufshpb_prep(struct ufs_hba *hba, struct ufshcd_lrb *lrbp); void ufshpb_rsp_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp); void ufshpb_resume(struct ufs_hba *hba); void ufshpb_suspend(struct ufs_hba *hba); -- 2.25.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-06-14 7:44 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-13 23:40 [PATCH v37 3/4] scsi: ufs: Prepare HPB read for cached sub-region 정요한(JOUNG YOHAN) Mobile SE
2021-06-14 6:48 ` Avri Altman
-- strict thread matches above, loose matches on Subject: below --
2021-06-14 7:44 정요한(JOUNG YOHAN) Mobile SE
2021-06-11 5:07 정요한(JOUNG YOHAN) Mobile SE
2021-06-13 10:20 ` Avri Altman
[not found] <CGME20210611022142epcms2p374ea5b82cfe122de69a7fefe27edf856@epcms2p2>
2021-06-11 2:21 ` [PATCH v37 0/4] scsi: ufs: Add Host Performance Booster Support Daejun Park
2021-06-11 2:23 ` [PATCH v37 3/4] scsi: ufs: Prepare HPB read for cached sub-region Daejun Park
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox