diff mbox series

[V3,2/2] mmc: hsq: dynamic adjustment of hsq->depth

Message ID 20230829020451.9828-3-wenchao.chen@unisoc.com
State Superseded
Headers show
Series mmc: hsq: dynamically adjust hsq_depth to improve performance | expand

Commit Message

Wenchao Chen Aug. 29, 2023, 2:04 a.m. UTC
Increasing hsq_depth improves random write performance.

Signed-off-by: Wenchao Chen <wenchao.chen@unisoc.com>
---
 drivers/mmc/host/mmc_hsq.c | 27 +++++++++++++++++++++++++++
 drivers/mmc/host/mmc_hsq.h |  5 +++++
 2 files changed, 32 insertions(+)

Comments

Ulf Hansson Sept. 14, 2023, 12:57 p.m. UTC | #1
On Tue, 29 Aug 2023 at 04:05, Wenchao Chen <wenchao.chen@unisoc.com> wrote:
>
> Increasing hsq_depth improves random write performance.
>
> Signed-off-by: Wenchao Chen <wenchao.chen@unisoc.com>
> ---
>  drivers/mmc/host/mmc_hsq.c | 27 +++++++++++++++++++++++++++
>  drivers/mmc/host/mmc_hsq.h |  5 +++++
>  2 files changed, 32 insertions(+)
>
> diff --git a/drivers/mmc/host/mmc_hsq.c b/drivers/mmc/host/mmc_hsq.c
> index 8556cacb21a1..0984c39108ba 100644
> --- a/drivers/mmc/host/mmc_hsq.c
> +++ b/drivers/mmc/host/mmc_hsq.c
> @@ -21,6 +21,31 @@ static void mmc_hsq_retry_handler(struct work_struct *work)
>         mmc->ops->request(mmc, hsq->mrq);
>  }
>
> +static void mmc_hsq_modify_threshold(struct mmc_hsq *hsq)
> +{
> +       struct mmc_host *mmc = hsq->mmc;
> +       struct mmc_request *mrq;
> +       struct hsq_slot *slot;
> +       int need_change = 0;

Rather than using a variable to keep track of this, why not just do
the below here?

mmc->hsq_depth = HSQ_NORMAL_DEPTH;

> +       int tag;
> +
> +       for (tag = 0; tag < HSQ_NUM_SLOTS; tag++) {
> +               slot = &hsq->slot[tag];
> +               mrq = slot->mrq;
> +               if (mrq && mrq->data &&
> +                       (mrq->data->blksz * mrq->data->blocks == 4096) &&
> +                       (mrq->data->flags & MMC_DATA_WRITE))
> +                       need_change++;

And following above, then we can do the below here:
mmc->hsq_depth = HSQ_PERFORMANCE_DEPTH;
break;

That should simplify and make this more efficient too, right?

> +               else
> +                       break;
> +       }
> +
> +       if (need_change > 1)
> +               mmc->hsq_depth = HSQ_PERFORMANCE_DEPTH;
> +       else
> +               mmc->hsq_depth = HSQ_NORMAL_DEPTH;
> +}
> +

[...]

Kind regards
Uffe
Wenchao Chen Sept. 15, 2023, 11:38 a.m. UTC | #2
On Thu, 14 Sept 2023 at 20:57, Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> On Tue, 29 Aug 2023 at 04:05, Wenchao Chen <wenchao.chen@unisoc.com> wrote:
> >
> > Increasing hsq_depth improves random write performance.
> >
> > Signed-off-by: Wenchao Chen <wenchao.chen@unisoc.com>
> > ---
> >  drivers/mmc/host/mmc_hsq.c | 27 +++++++++++++++++++++++++++
> >  drivers/mmc/host/mmc_hsq.h |  5 +++++
> >  2 files changed, 32 insertions(+)
> >
> > diff --git a/drivers/mmc/host/mmc_hsq.c b/drivers/mmc/host/mmc_hsq.c
> > index 8556cacb21a1..0984c39108ba 100644
> > --- a/drivers/mmc/host/mmc_hsq.c
> > +++ b/drivers/mmc/host/mmc_hsq.c
> > @@ -21,6 +21,31 @@ static void mmc_hsq_retry_handler(struct work_struct *work)
> >         mmc->ops->request(mmc, hsq->mrq);
> >  }
> >
> > +static void mmc_hsq_modify_threshold(struct mmc_hsq *hsq)
> > +{
> > +       struct mmc_host *mmc = hsq->mmc;
> > +       struct mmc_request *mrq;
> > +       struct hsq_slot *slot;
> > +       int need_change = 0;
>
> Rather than using a variable to keep track of this, why not just do
> the below here?
>
> mmc->hsq_depth = HSQ_NORMAL_DEPTH;
>
> > +       int tag;
> > +
> > +       for (tag = 0; tag < HSQ_NUM_SLOTS; tag++) {
> > +               slot = &hsq->slot[tag];
> > +               mrq = slot->mrq;
> > +               if (mrq && mrq->data &&
> > +                       (mrq->data->blksz * mrq->data->blocks == 4096) &&
> > +                       (mrq->data->flags & MMC_DATA_WRITE))
> > +                       need_change++;
>
> And following above, then we can do the below here:
> mmc->hsq_depth = HSQ_PERFORMANCE_DEPTH;
> break;
>
> That should simplify and make this more efficient too, right?
>

Yes, you are right. But need_change = 2, it means more reqs are allowed.
Alternatively, modify it like this:
mmc->hsq_depth = (need_change > 1)  ? HSQ_PERFORMANCE_DEPTH : HSQ_NORMAL_DEPTH;

> > +               else
> > +                       break;
> > +       }
> > +
> > +       if (need_change > 1)
> > +               mmc->hsq_depth = HSQ_PERFORMANCE_DEPTH;
> > +       else
> > +               mmc->hsq_depth = HSQ_NORMAL_DEPTH;
> > +}
> > +
>
> [...]
>
> Kind regards
> Uffe
diff mbox series

Patch

diff --git a/drivers/mmc/host/mmc_hsq.c b/drivers/mmc/host/mmc_hsq.c
index 8556cacb21a1..0984c39108ba 100644
--- a/drivers/mmc/host/mmc_hsq.c
+++ b/drivers/mmc/host/mmc_hsq.c
@@ -21,6 +21,31 @@  static void mmc_hsq_retry_handler(struct work_struct *work)
 	mmc->ops->request(mmc, hsq->mrq);
 }
 
+static void mmc_hsq_modify_threshold(struct mmc_hsq *hsq)
+{
+	struct mmc_host *mmc = hsq->mmc;
+	struct mmc_request *mrq;
+	struct hsq_slot *slot;
+	int need_change = 0;
+	int tag;
+
+	for (tag = 0; tag < HSQ_NUM_SLOTS; tag++) {
+		slot = &hsq->slot[tag];
+		mrq = slot->mrq;
+		if (mrq && mrq->data &&
+			(mrq->data->blksz * mrq->data->blocks == 4096) &&
+			(mrq->data->flags & MMC_DATA_WRITE))
+			need_change++;
+		else
+			break;
+	}
+
+	if (need_change > 1)
+		mmc->hsq_depth = HSQ_PERFORMANCE_DEPTH;
+	else
+		mmc->hsq_depth = HSQ_NORMAL_DEPTH;
+}
+
 static void mmc_hsq_pump_requests(struct mmc_hsq *hsq)
 {
 	struct mmc_host *mmc = hsq->mmc;
@@ -42,6 +67,8 @@  static void mmc_hsq_pump_requests(struct mmc_hsq *hsq)
 		return;
 	}
 
+	mmc_hsq_modify_threshold(hsq);
+
 	slot = &hsq->slot[hsq->next_tag];
 	hsq->mrq = slot->mrq;
 	hsq->qcnt--;
diff --git a/drivers/mmc/host/mmc_hsq.h b/drivers/mmc/host/mmc_hsq.h
index aa5c4543b55f..dd352a6ac32a 100644
--- a/drivers/mmc/host/mmc_hsq.h
+++ b/drivers/mmc/host/mmc_hsq.h
@@ -10,6 +10,11 @@ 
  * flight to avoid a long latency.
  */
 #define HSQ_NORMAL_DEPTH	2
+/*
+ * For 4k random writes, we allow hsq_depth to increase to 5
+ * for better performance.
+ */
+#define HSQ_PERFORMANCE_DEPTH	5
 
 struct hsq_slot {
 	struct mmc_request *mrq;