2023-08-03 06:26:07

by Wenchao Chen

[permalink] [raw]
Subject: [PATCH] mmc: queue: replace immediate with hsq->depth

Hsq is similar to cqe, using hsq->depth to represent
the maximum processing capacity of hsq. We can adjust
hsq->depth according to the actual situation.

Signed-off-by: Wenchao Chen <[email protected]>
---
drivers/mmc/core/queue.c | 6 +-----
drivers/mmc/host/mmc_hsq.c | 1 +
drivers/mmc/host/mmc_hsq.h | 7 +++++++
include/linux/mmc/host.h | 1 +
4 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c
index b396e3900717..a0a2412f62a7 100644
--- a/drivers/mmc/core/queue.c
+++ b/drivers/mmc/core/queue.c
@@ -260,11 +260,7 @@ static blk_status_t mmc_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
}
break;
case MMC_ISSUE_ASYNC:
- /*
- * For MMC host software queue, we only allow 2 requests in
- * flight to avoid a long latency.
- */
- if (host->hsq_enabled && mq->in_flight[issue_type] > 2) {
+ if (host->hsq_enabled && mq->in_flight[issue_type] > host->hsq_depth) {
spin_unlock_irq(&mq->lock);
return BLK_STS_RESOURCE;
}
diff --git a/drivers/mmc/host/mmc_hsq.c b/drivers/mmc/host/mmc_hsq.c
index 424dc7b07858..7b3952721c17 100644
--- a/drivers/mmc/host/mmc_hsq.c
+++ b/drivers/mmc/host/mmc_hsq.c
@@ -337,6 +337,7 @@ int mmc_hsq_init(struct mmc_hsq *hsq, struct mmc_host *mmc)
hsq->mmc = mmc;
hsq->mmc->cqe_private = hsq;
mmc->cqe_ops = &mmc_hsq_ops;
+ mmc->hsq_depth = HSQ_MAX_DEPTH;

for (i = 0; i < HSQ_NUM_SLOTS; i++)
hsq->tag_slot[i] = HSQ_INVALID_TAG;
diff --git a/drivers/mmc/host/mmc_hsq.h b/drivers/mmc/host/mmc_hsq.h
index 1808024fc6c5..795f6b9421d7 100644
--- a/drivers/mmc/host/mmc_hsq.h
+++ b/drivers/mmc/host/mmc_hsq.h
@@ -5,6 +5,13 @@
#define HSQ_NUM_SLOTS 64
#define HSQ_INVALID_TAG HSQ_NUM_SLOTS

+/*
+ * For MMC host software queue, we usually allow 2 requests in
+ * flight to avoid a long latency. But we can adjust hsq->depth
+ * according to the actual situation.
+ */
+#define HSQ_MAX_DEPTH 2
+
struct hsq_slot {
struct mmc_request *mrq;
};
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index 461d1543893b..1fd8b1dd8698 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -520,6 +520,7 @@ struct mmc_host {

/* Host Software Queue support */
bool hsq_enabled;
+ int hsq_depth;

u32 err_stats[MMC_ERR_MAX];
unsigned long private[] ____cacheline_aligned;
--
2.17.1



2023-08-08 17:57:51

by Wenchao Chen

[permalink] [raw]
Subject: Re: [PATCH] mmc: queue: replace immediate with hsq->depth

On Tue, Aug 8, 2023 at 5:28 PM Ulf Hansson <[email protected]> wrote:
>
> On Thu, 3 Aug 2023 at 07:46, Wenchao Chen <[email protected]> wrote:
> >
> > Hsq is similar to cqe, using hsq->depth to represent
> > the maximum processing capacity of hsq. We can adjust
> > hsq->depth according to the actual situation.
>
> Sorry, but I don't quite follow here.
>
> Are you planning to update the host->hsq_depth dynamically from somewhere?
>
> Kind regards
> Uffe
>
Hi Uffe,
Depending on the mmc device, some devices allow host to send more reqs
to the device.
Also, we use hsq->hsq_depth instead of immediate number "2" to make
the code easier to understand.

Thanks
Wenchao.Chen
> >
> > Signed-off-by: Wenchao Chen <[email protected]>
> > ---
> > drivers/mmc/core/queue.c | 6 +-----
> > drivers/mmc/host/mmc_hsq.c | 1 +
> > drivers/mmc/host/mmc_hsq.h | 7 +++++++
> > include/linux/mmc/host.h | 1 +
> > 4 files changed, 10 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c
> > index b396e3900717..a0a2412f62a7 100644
> > --- a/drivers/mmc/core/queue.c
> > +++ b/drivers/mmc/core/queue.c
> > @@ -260,11 +260,7 @@ static blk_status_t mmc_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
> > }
> > break;
> > case MMC_ISSUE_ASYNC:
> > - /*
> > - * For MMC host software queue, we only allow 2 requests in
> > - * flight to avoid a long latency.
> > - */
> > - if (host->hsq_enabled && mq->in_flight[issue_type] > 2) {
> > + if (host->hsq_enabled && mq->in_flight[issue_type] > host->hsq_depth) {
> > spin_unlock_irq(&mq->lock);
> > return BLK_STS_RESOURCE;
> > }
> > diff --git a/drivers/mmc/host/mmc_hsq.c b/drivers/mmc/host/mmc_hsq.c
> > index 424dc7b07858..7b3952721c17 100644
> > --- a/drivers/mmc/host/mmc_hsq.c
> > +++ b/drivers/mmc/host/mmc_hsq.c
> > @@ -337,6 +337,7 @@ int mmc_hsq_init(struct mmc_hsq *hsq, struct mmc_host *mmc)
> > hsq->mmc = mmc;
> > hsq->mmc->cqe_private = hsq;
> > mmc->cqe_ops = &mmc_hsq_ops;
> > + mmc->hsq_depth = HSQ_MAX_DEPTH;
> >
> > for (i = 0; i < HSQ_NUM_SLOTS; i++)
> > hsq->tag_slot[i] = HSQ_INVALID_TAG;
> > diff --git a/drivers/mmc/host/mmc_hsq.h b/drivers/mmc/host/mmc_hsq.h
> > index 1808024fc6c5..795f6b9421d7 100644
> > --- a/drivers/mmc/host/mmc_hsq.h
> > +++ b/drivers/mmc/host/mmc_hsq.h
> > @@ -5,6 +5,13 @@
> > #define HSQ_NUM_SLOTS 64
> > #define HSQ_INVALID_TAG HSQ_NUM_SLOTS
> >
> > +/*
> > + * For MMC host software queue, we usually allow 2 requests in
> > + * flight to avoid a long latency. But we can adjust hsq->depth
> > + * according to the actual situation.
> > + */
> > +#define HSQ_MAX_DEPTH 2
> > +
> > struct hsq_slot {
> > struct mmc_request *mrq;
> > };
> > diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
> > index 461d1543893b..1fd8b1dd8698 100644
> > --- a/include/linux/mmc/host.h
> > +++ b/include/linux/mmc/host.h
> > @@ -520,6 +520,7 @@ struct mmc_host {
> >
> > /* Host Software Queue support */
> > bool hsq_enabled;
> > + int hsq_depth;
> >
> > u32 err_stats[MMC_ERR_MAX];
> > unsigned long private[] ____cacheline_aligned;
> > --
> > 2.17.1
> >

2023-08-08 18:55:56

by Ulf Hansson

[permalink] [raw]
Subject: Re: [PATCH] mmc: queue: replace immediate with hsq->depth

On Thu, 3 Aug 2023 at 07:46, Wenchao Chen <[email protected]> wrote:
>
> Hsq is similar to cqe, using hsq->depth to represent
> the maximum processing capacity of hsq. We can adjust
> hsq->depth according to the actual situation.

Sorry, but I don't quite follow here.

Are you planning to update the host->hsq_depth dynamically from somewhere?

Kind regards
Uffe

>
> Signed-off-by: Wenchao Chen <[email protected]>
> ---
> drivers/mmc/core/queue.c | 6 +-----
> drivers/mmc/host/mmc_hsq.c | 1 +
> drivers/mmc/host/mmc_hsq.h | 7 +++++++
> include/linux/mmc/host.h | 1 +
> 4 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c
> index b396e3900717..a0a2412f62a7 100644
> --- a/drivers/mmc/core/queue.c
> +++ b/drivers/mmc/core/queue.c
> @@ -260,11 +260,7 @@ static blk_status_t mmc_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
> }
> break;
> case MMC_ISSUE_ASYNC:
> - /*
> - * For MMC host software queue, we only allow 2 requests in
> - * flight to avoid a long latency.
> - */
> - if (host->hsq_enabled && mq->in_flight[issue_type] > 2) {
> + if (host->hsq_enabled && mq->in_flight[issue_type] > host->hsq_depth) {
> spin_unlock_irq(&mq->lock);
> return BLK_STS_RESOURCE;
> }
> diff --git a/drivers/mmc/host/mmc_hsq.c b/drivers/mmc/host/mmc_hsq.c
> index 424dc7b07858..7b3952721c17 100644
> --- a/drivers/mmc/host/mmc_hsq.c
> +++ b/drivers/mmc/host/mmc_hsq.c
> @@ -337,6 +337,7 @@ int mmc_hsq_init(struct mmc_hsq *hsq, struct mmc_host *mmc)
> hsq->mmc = mmc;
> hsq->mmc->cqe_private = hsq;
> mmc->cqe_ops = &mmc_hsq_ops;
> + mmc->hsq_depth = HSQ_MAX_DEPTH;
>
> for (i = 0; i < HSQ_NUM_SLOTS; i++)
> hsq->tag_slot[i] = HSQ_INVALID_TAG;
> diff --git a/drivers/mmc/host/mmc_hsq.h b/drivers/mmc/host/mmc_hsq.h
> index 1808024fc6c5..795f6b9421d7 100644
> --- a/drivers/mmc/host/mmc_hsq.h
> +++ b/drivers/mmc/host/mmc_hsq.h
> @@ -5,6 +5,13 @@
> #define HSQ_NUM_SLOTS 64
> #define HSQ_INVALID_TAG HSQ_NUM_SLOTS
>
> +/*
> + * For MMC host software queue, we usually allow 2 requests in
> + * flight to avoid a long latency. But we can adjust hsq->depth
> + * according to the actual situation.
> + */
> +#define HSQ_MAX_DEPTH 2
> +
> struct hsq_slot {
> struct mmc_request *mrq;
> };
> diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
> index 461d1543893b..1fd8b1dd8698 100644
> --- a/include/linux/mmc/host.h
> +++ b/include/linux/mmc/host.h
> @@ -520,6 +520,7 @@ struct mmc_host {
>
> /* Host Software Queue support */
> bool hsq_enabled;
> + int hsq_depth;
>
> u32 err_stats[MMC_ERR_MAX];
> unsigned long private[] ____cacheline_aligned;
> --
> 2.17.1
>

2023-08-08 18:56:21

by Ulf Hansson

[permalink] [raw]
Subject: Re: [PATCH] mmc: queue: replace immediate with hsq->depth

On Tue, 8 Aug 2023 at 12:41, Wenchao Chen <[email protected]> wrote:
>
> On Tue, Aug 8, 2023 at 5:28 PM Ulf Hansson <[email protected]> wrote:
> >
> > On Thu, 3 Aug 2023 at 07:46, Wenchao Chen <[email protected]> wrote:
> > >
> > > Hsq is similar to cqe, using hsq->depth to represent
> > > the maximum processing capacity of hsq. We can adjust
> > > hsq->depth according to the actual situation.
> >
> > Sorry, but I don't quite follow here.
> >
> > Are you planning to update the host->hsq_depth dynamically from somewhere?
> >
> > Kind regards
> > Uffe
> >
> Hi Uffe,
> Depending on the mmc device, some devices allow host to send more reqs
> to the device.

In that case, please add a patch for that too, to show how this is
going to be useful.

> Also, we use hsq->hsq_depth instead of immediate number "2" to make
> the code easier to understand.

Right, but we don't need a new member in struct mmc_host for that. We
could just be checking HSQ_MAX_DEPTH instead.

Kind regards
Uffe

>
> Thanks
> Wenchao.Chen
> > >
> > > Signed-off-by: Wenchao Chen <[email protected]>
> > > ---
> > > drivers/mmc/core/queue.c | 6 +-----
> > > drivers/mmc/host/mmc_hsq.c | 1 +
> > > drivers/mmc/host/mmc_hsq.h | 7 +++++++
> > > include/linux/mmc/host.h | 1 +
> > > 4 files changed, 10 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c
> > > index b396e3900717..a0a2412f62a7 100644
> > > --- a/drivers/mmc/core/queue.c
> > > +++ b/drivers/mmc/core/queue.c
> > > @@ -260,11 +260,7 @@ static blk_status_t mmc_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
> > > }
> > > break;
> > > case MMC_ISSUE_ASYNC:
> > > - /*
> > > - * For MMC host software queue, we only allow 2 requests in
> > > - * flight to avoid a long latency.
> > > - */
> > > - if (host->hsq_enabled && mq->in_flight[issue_type] > 2) {
> > > + if (host->hsq_enabled && mq->in_flight[issue_type] > host->hsq_depth) {
> > > spin_unlock_irq(&mq->lock);
> > > return BLK_STS_RESOURCE;
> > > }
> > > diff --git a/drivers/mmc/host/mmc_hsq.c b/drivers/mmc/host/mmc_hsq.c
> > > index 424dc7b07858..7b3952721c17 100644
> > > --- a/drivers/mmc/host/mmc_hsq.c
> > > +++ b/drivers/mmc/host/mmc_hsq.c
> > > @@ -337,6 +337,7 @@ int mmc_hsq_init(struct mmc_hsq *hsq, struct mmc_host *mmc)
> > > hsq->mmc = mmc;
> > > hsq->mmc->cqe_private = hsq;
> > > mmc->cqe_ops = &mmc_hsq_ops;
> > > + mmc->hsq_depth = HSQ_MAX_DEPTH;
> > >
> > > for (i = 0; i < HSQ_NUM_SLOTS; i++)
> > > hsq->tag_slot[i] = HSQ_INVALID_TAG;
> > > diff --git a/drivers/mmc/host/mmc_hsq.h b/drivers/mmc/host/mmc_hsq.h
> > > index 1808024fc6c5..795f6b9421d7 100644
> > > --- a/drivers/mmc/host/mmc_hsq.h
> > > +++ b/drivers/mmc/host/mmc_hsq.h
> > > @@ -5,6 +5,13 @@
> > > #define HSQ_NUM_SLOTS 64
> > > #define HSQ_INVALID_TAG HSQ_NUM_SLOTS
> > >
> > > +/*
> > > + * For MMC host software queue, we usually allow 2 requests in
> > > + * flight to avoid a long latency. But we can adjust hsq->depth
> > > + * according to the actual situation.
> > > + */
> > > +#define HSQ_MAX_DEPTH 2
> > > +
> > > struct hsq_slot {
> > > struct mmc_request *mrq;
> > > };
> > > diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
> > > index 461d1543893b..1fd8b1dd8698 100644
> > > --- a/include/linux/mmc/host.h
> > > +++ b/include/linux/mmc/host.h
> > > @@ -520,6 +520,7 @@ struct mmc_host {
> > >
> > > /* Host Software Queue support */
> > > bool hsq_enabled;
> > > + int hsq_depth;
> > >
> > > u32 err_stats[MMC_ERR_MAX];
> > > unsigned long private[] ____cacheline_aligned;
> > > --
> > > 2.17.1
> > >

2023-08-11 08:35:52

by Wenchao Chen

[permalink] [raw]
Subject: Re: [PATCH] mmc: queue: replace immediate with hsq->depth

On Tue, Aug 8, 2023 at 6:57 PM Ulf Hansson <[email protected]> wrote:
>
> On Tue, 8 Aug 2023 at 12:41, Wenchao Chen <[email protected]> wrote:
> >
> > On Tue, Aug 8, 2023 at 5:28 PM Ulf Hansson <[email protected]> wrote:
> > >
> > > On Thu, 3 Aug 2023 at 07:46, Wenchao Chen <[email protected]> wrote:
> > > >
> > > > Hsq is similar to cqe, using hsq->depth to represent
> > > > the maximum processing capacity of hsq. We can adjust
> > > > hsq->depth according to the actual situation.
> > >
> > > Sorry, but I don't quite follow here.
> > >
> > > Are you planning to update the host->hsq_depth dynamically from somewhere?
> > >
> > > Kind regards
> > > Uffe
> > >
> > Hi Uffe,
> > Depending on the mmc device, some devices allow host to send more reqs
> > to the device.
>
> In that case, please add a patch for that too, to show how this is
> going to be useful.
>

OK, I'll update it in the next version.

> > Also, we use hsq->hsq_depth instead of immediate number "2" to make
> > the code easier to understand.
>
> Right, but we don't need a new member in struct mmc_host for that. We
> could just be checking HSQ_MAX_DEPTH instead.
>
> Kind regards
> Uffe
>

Using the definition of host in core makes it feel a little strange.

> >
> > Thanks
> > Wenchao.Chen
> > > >
> > > > Signed-off-by: Wenchao Chen <[email protected]>
> > > > ---
> > > > drivers/mmc/core/queue.c | 6 +-----
> > > > drivers/mmc/host/mmc_hsq.c | 1 +
> > > > drivers/mmc/host/mmc_hsq.h | 7 +++++++
> > > > include/linux/mmc/host.h | 1 +
> > > > 4 files changed, 10 insertions(+), 5 deletions(-)
> > > >
> > > > diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c
> > > > index b396e3900717..a0a2412f62a7 100644
> > > > --- a/drivers/mmc/core/queue.c
> > > > +++ b/drivers/mmc/core/queue.c
> > > > @@ -260,11 +260,7 @@ static blk_status_t mmc_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
> > > > }
> > > > break;
> > > > case MMC_ISSUE_ASYNC:
> > > > - /*
> > > > - * For MMC host software queue, we only allow 2 requests in
> > > > - * flight to avoid a long latency.
> > > > - */
> > > > - if (host->hsq_enabled && mq->in_flight[issue_type] > 2) {
> > > > + if (host->hsq_enabled && mq->in_flight[issue_type] > host->hsq_depth) {
> > > > spin_unlock_irq(&mq->lock);
> > > > return BLK_STS_RESOURCE;
> > > > }
> > > > diff --git a/drivers/mmc/host/mmc_hsq.c b/drivers/mmc/host/mmc_hsq.c
> > > > index 424dc7b07858..7b3952721c17 100644
> > > > --- a/drivers/mmc/host/mmc_hsq.c
> > > > +++ b/drivers/mmc/host/mmc_hsq.c
> > > > @@ -337,6 +337,7 @@ int mmc_hsq_init(struct mmc_hsq *hsq, struct mmc_host *mmc)
> > > > hsq->mmc = mmc;
> > > > hsq->mmc->cqe_private = hsq;
> > > > mmc->cqe_ops = &mmc_hsq_ops;
> > > > + mmc->hsq_depth = HSQ_MAX_DEPTH;
> > > >
> > > > for (i = 0; i < HSQ_NUM_SLOTS; i++)
> > > > hsq->tag_slot[i] = HSQ_INVALID_TAG;
> > > > diff --git a/drivers/mmc/host/mmc_hsq.h b/drivers/mmc/host/mmc_hsq.h
> > > > index 1808024fc6c5..795f6b9421d7 100644
> > > > --- a/drivers/mmc/host/mmc_hsq.h
> > > > +++ b/drivers/mmc/host/mmc_hsq.h
> > > > @@ -5,6 +5,13 @@
> > > > #define HSQ_NUM_SLOTS 64
> > > > #define HSQ_INVALID_TAG HSQ_NUM_SLOTS
> > > >
> > > > +/*
> > > > + * For MMC host software queue, we usually allow 2 requests in
> > > > + * flight to avoid a long latency. But we can adjust hsq->depth
> > > > + * according to the actual situation.
> > > > + */
> > > > +#define HSQ_MAX_DEPTH 2
> > > > +
> > > > struct hsq_slot {
> > > > struct mmc_request *mrq;
> > > > };
> > > > diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
> > > > index 461d1543893b..1fd8b1dd8698 100644
> > > > --- a/include/linux/mmc/host.h
> > > > +++ b/include/linux/mmc/host.h
> > > > @@ -520,6 +520,7 @@ struct mmc_host {
> > > >
> > > > /* Host Software Queue support */
> > > > bool hsq_enabled;
> > > > + int hsq_depth;
> > > >
> > > > u32 err_stats[MMC_ERR_MAX];
> > > > unsigned long private[] ____cacheline_aligned;
> > > > --
> > > > 2.17.1
> > > >