Patchwork [RESEND,v3,2/3] drivers: qcom: rpmh-rsc: return if the controller is idle

login
register
mail settings
Submitter Raju P L S S S N
Date Feb. 21, 2019, 12:18 p.m.
Message ID <20190221121827.32427-3-rplsssn@codeaurora.org>
Download mbox | patch
Permalink /patch/732217/
State New
Headers show

Comments

Raju P L S S S N - Feb. 21, 2019, 12:18 p.m.
From: Lina Iyer <ilina@codeaurora.org>

Allow the controller status be queried. The controller is busy if it is
actively processing request. Also allow the controller state be read by
platform drivers. This is useful for PM drivers which can choose to
disallow idle modes when the controller is busy.

Signed-off-by: Lina Iyer <ilina@codeaurora.org>
Signed-off-by: Raju P.L.S.S.S.N <rplsssn@codeaurora.org>
---
 drivers/soc/qcom/rpmh-internal.h |  1 +
 drivers/soc/qcom/rpmh-rsc.c      | 24 ++++++++++++++++++++++++
 drivers/soc/qcom/rpmh.c          | 13 +++++++++++++
 include/soc/qcom/rpmh.h          |  5 +++++
 4 files changed, 43 insertions(+)
Stephen Boyd - Feb. 27, 2019, 12:49 a.m.
Quoting Raju P.L.S.S.S.N (2019-02-21 04:18:26)
> diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c
> index d6b834eeeb37..9cc303e88a06 100644
> --- a/drivers/soc/qcom/rpmh-rsc.c
> +++ b/drivers/soc/qcom/rpmh-rsc.c
> @@ -524,6 +524,30 @@ static int tcs_ctrl_write(struct rsc_drv *drv, const struct tcs_request *msg)
>         return ret;
>  }
>  
> +/**
> + *  rpmh_rsc_ctrlr_is_idle: Check if any of the AMCs are busy.
> + *
> + *  @drv: The controller
> + *
> + *  Returns true if the TCSes are engaged in handling requests.
> + */
> +bool rpmh_rsc_ctrlr_is_idle(struct rsc_drv *drv)
> +{

This API seems inherently racy. How do we know that nothing else is
going to be inserted into the TCS after this function returns true? Do
you have a user of this API? It would be good to know how it is used
instead of adding some code that never gets called.

> +       int m;
> +       struct tcs_group *tcs = get_tcs_of_type(drv, ACTIVE_TCS);
> +
> +       spin_lock(&drv->lock);
> +       for (m = tcs->offset; m < tcs->offset + tcs->num_tcs; m++) {
> +               if (!tcs_is_free(drv, m)) {
> +                       spin_unlock(&drv->lock);
> +                       return false;
> +               }
> +       }
> +       spin_unlock(&drv->lock);
> +
> +       return true;
> +}
> +
>  /**
>   * rpmh_rsc_write_ctrl_data: Write request to the controller
>   *
Lina Iyer - Feb. 27, 2019, 10:29 p.m.
Hi Stephen,

On Tue, Feb 26 2019 at 17:49 -0700, Stephen Boyd wrote:
>Quoting Raju P.L.S.S.S.N (2019-02-21 04:18:26)
>> diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c
>> index d6b834eeeb37..9cc303e88a06 100644
>> --- a/drivers/soc/qcom/rpmh-rsc.c
>> +++ b/drivers/soc/qcom/rpmh-rsc.c
>> @@ -524,6 +524,30 @@ static int tcs_ctrl_write(struct rsc_drv *drv, const struct tcs_request *msg)
>>         return ret;
>>  }
>>
>> +/**
>> + *  rpmh_rsc_ctrlr_is_idle: Check if any of the AMCs are busy.
>> + *
>> + *  @drv: The controller
>> + *
>> + *  Returns true if the TCSes are engaged in handling requests.
>> + */
>> +bool rpmh_rsc_ctrlr_is_idle(struct rsc_drv *drv)
>> +{
>
>This API seems inherently racy. How do we know that nothing else is
>going to be inserted into the TCS after this function returns true? Do
>you have a user of this API? It would be good to know how it is used
>instead of adding some code that never gets called.
>
This API is called from the last CPU that is powering down in an
interrupt locked context (say during suspend). If we are waiting on a
request, we would bail out of the suspend process. There can be no issue
requested during the last step in suspend. The PM driver itself does not
make any TCS request. Currently, this API is used by the downstream code
in its last man activities. The usage by platform coordinated mode is
still under discussion.

-- Lina
>> +       int m;
>> +       struct tcs_group *tcs = get_tcs_of_type(drv, ACTIVE_TCS);
>> +
>> +       spin_lock(&drv->lock);
>> +       for (m = tcs->offset; m < tcs->offset + tcs->num_tcs; m++) {
>> +               if (!tcs_is_free(drv, m)) {
>> +                       spin_unlock(&drv->lock);
>> +                       return false;
>> +               }
>> +       }
>> +       spin_unlock(&drv->lock);
>> +
>> +       return true;
>> +}
>> +
>>  /**
>>   * rpmh_rsc_write_ctrl_data: Write request to the controller
>>   *
>
Stephen Boyd - March 1, 2019, 5:58 p.m.
Quoting Lina Iyer (2019-02-27 14:29:13)
> Hi Stephen,
> 
> On Tue, Feb 26 2019 at 17:49 -0700, Stephen Boyd wrote:
> >Quoting Raju P.L.S.S.S.N (2019-02-21 04:18:26)
> >> diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c
> >> index d6b834eeeb37..9cc303e88a06 100644
> >> --- a/drivers/soc/qcom/rpmh-rsc.c
> >> +++ b/drivers/soc/qcom/rpmh-rsc.c
> >> @@ -524,6 +524,30 @@ static int tcs_ctrl_write(struct rsc_drv *drv, const struct tcs_request *msg)
> >>         return ret;
> >>  }
> >>
> >> +/**
> >> + *  rpmh_rsc_ctrlr_is_idle: Check if any of the AMCs are busy.
> >> + *
> >> + *  @drv: The controller
> >> + *
> >> + *  Returns true if the TCSes are engaged in handling requests.

By the way, this says AMCs are busy and then TCSes are engaged. Which
one is it?

> >> + */
> >> +bool rpmh_rsc_ctrlr_is_idle(struct rsc_drv *drv)
> >> +{
> >
> >This API seems inherently racy. How do we know that nothing else is
> >going to be inserted into the TCS after this function returns true? Do
> >you have a user of this API? It would be good to know how it is used
> >instead of adding some code that never gets called.
> >
> This API is called from the last CPU that is powering down in an
> interrupt locked context (say during suspend). If we are waiting on a
> request, we would bail out of the suspend process. There can be no issue
> requested during the last step in suspend. The PM driver itself does not
> make any TCS request. Currently, this API is used by the downstream code
> in its last man activities. The usage by platform coordinated mode is
> still under discussion.
> 

Ok, can you explain why it's even a problem for the TCSes to be active
during suspend? I would hope that for suspend/resume, if this is
actually a problem, the RPMh driver itself can block suspend with a
driver suspend callback that checks for idleness. But I suspect that in
the system wide suspend/resume case, any callers that could make TCS
requests are child devices of the RPMh controller and therefore they
would already be suspended if they didn't have anything pending they're
waiting for a response on or they would be blocking suspend themselves
if they're waiting for the response. So why are we even checking the
TCSes in system suspend path at all? Assume that callers know what
they're doing and will block suspend if they care?

Following that same logic, is this more of an API that is planned for
use by CPU idle? Where the case is much more of a runtime PM design.
Even then, I don't get it. A device that's runtime active and making
RPMh requests might need to block some forms of CPU idle states because
a request hasn't been processed yet that may change the decision for
certain deep idle states?
Lina Iyer - March 4, 2019, 5:14 p.m.
On Fri, Mar 01 2019 at 10:58 -0700, Stephen Boyd wrote:
>Quoting Lina Iyer (2019-02-27 14:29:13)
>> Hi Stephen,
>>
>> On Tue, Feb 26 2019 at 17:49 -0700, Stephen Boyd wrote:
>> >Quoting Raju P.L.S.S.S.N (2019-02-21 04:18:26)
>> >> diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c
>> >> index d6b834eeeb37..9cc303e88a06 100644
>> >> --- a/drivers/soc/qcom/rpmh-rsc.c
>> >> +++ b/drivers/soc/qcom/rpmh-rsc.c
>> >> @@ -524,6 +524,30 @@ static int tcs_ctrl_write(struct rsc_drv *drv, const struct tcs_request *msg)
>> >>         return ret;
>> >>  }
>> >>
>> >> +/**
>> >> + *  rpmh_rsc_ctrlr_is_idle: Check if any of the AMCs are busy.
>> >> + *
>> >> + *  @drv: The controller
>> >> + *
>> >> + *  Returns true if the TCSes are engaged in handling requests.
>
>By the way, this says AMCs are busy and then TCSes are engaged. Which
>one is it?
>
>> >> + */
>> >> +bool rpmh_rsc_ctrlr_is_idle(struct rsc_drv *drv)
>> >> +{
>> >
>> >This API seems inherently racy. How do we know that nothing else is
>> >going to be inserted into the TCS after this function returns true? Do
>> >you have a user of this API? It would be good to know how it is used
>> >instead of adding some code that never gets called.
>> >
>> This API is called from the last CPU that is powering down in an
>> interrupt locked context (say during suspend). If we are waiting on a
>> request, we would bail out of the suspend process. There can be no issue
>> requested during the last step in suspend. The PM driver itself does not
>> make any TCS request. Currently, this API is used by the downstream code
>> in its last man activities. The usage by platform coordinated mode is
>> still under discussion.
>>
>
>Ok, can you explain why it's even a problem for the TCSes to be active
>during suspend? I would hope that for suspend/resume, if this is
>actually a problem, the RPMh driver itself can block suspend with a
>driver suspend callback that checks for idleness.
The RSC can transmit TCS executed from Linux and when all the CPUs have
powered down, could execute a firmware in the RSC to deliver the sleep
state requests. The firmware cannot run when there are active requests
being processed. To ensure that case, we bail out of sleep or suspend,
when the last CPU is powering down, if there are active requests.

>But I suspect that in
>the system wide suspend/resume case, any callers that could make TCS
>requests are child devices of the RPMh controller and therefore they
>would already be suspended if they didn't have anything pending they're
>waiting for a response on or they would be blocking suspend themselves
>if they're waiting for the response. So why are we even checking the
>TCSes in system suspend path at all? Assume that callers know what
>they're doing and will block suspend if they care?
>
In suspend, they probably would do what you mention above. All CPUs
might conincidentally be idle at the same idle, when a request is being
processed.

>Following that same logic, is this more of an API that is planned for
>use by CPU idle? Where the case is much more of a runtime PM design.
>Even then, I don't get it. A device that's runtime active and making
>RPMh requests might need to block some forms of CPU idle states because
>a request hasn't been processed yet that may change the decision for
>certain deep idle states?
>
A process waiting on a RPMH request, may let the CPU go to sleep and
therefore this is a possibility.

--Lina
Stephen Boyd - March 6, 2019, 10:12 p.m.
Quoting Lina Iyer (2019-03-04 09:14:50)
> On Fri, Mar 01 2019 at 10:58 -0700, Stephen Boyd wrote:
> >Quoting Lina Iyer (2019-02-27 14:29:13)
> >> Hi Stephen,
> >>
> >> On Tue, Feb 26 2019 at 17:49 -0700, Stephen Boyd wrote:
> >
> >Ok, can you explain why it's even a problem for the TCSes to be active
> >during suspend? I would hope that for suspend/resume, if this is
> >actually a problem, the RPMh driver itself can block suspend with a
> >driver suspend callback that checks for idleness.
> The RSC can transmit TCS executed from Linux and when all the CPUs have
> powered down, could execute a firmware in the RSC to deliver the sleep
> state requests. The firmware cannot run when there are active requests
> being processed. To ensure that case, we bail out of sleep or suspend,
> when the last CPU is powering down, if there are active requests.

Ok, do we actually bail out or just pick a shallower idle state that
wouldn't trigger the firmware to run something that may conflict with
the active requests (i.e. some light CPU sleep mode)? The commit text
seems to imply we block certain idle states.

> 
> >But I suspect that in
> >the system wide suspend/resume case, any callers that could make TCS
> >requests are child devices of the RPMh controller and therefore they
> >would already be suspended if they didn't have anything pending they're
> >waiting for a response on or they would be blocking suspend themselves
> >if they're waiting for the response. So why are we even checking the
> >TCSes in system suspend path at all? Assume that callers know what
> >they're doing and will block suspend if they care?
> >
> In suspend, they probably would do what you mention above. All CPUs
> might conincidentally be idle at the same idle, when a request is being
> processed.
> 
> >Following that same logic, is this more of an API that is planned for
> >use by CPU idle? Where the case is much more of a runtime PM design.
> >Even then, I don't get it. A device that's runtime active and making
> >RPMh requests might need to block some forms of CPU idle states because
> >a request hasn't been processed yet that may change the decision for
> >certain deep idle states?
> >
> A process waiting on a RPMH request, may let the CPU go to sleep and
> therefore this is a possibility.
> 

Ok thanks for the info. Can these details be included in the commit text
so we don't lose sight of the bigger picture? And can this patch series
be combined with a larger cpuidle/suspend patch series so we don't have
to review this in isolation? I don't understand the need to add more
APIs that aren't used yet.
Lina Iyer - March 6, 2019, 10:19 p.m.
On Wed, Mar 06 2019 at 15:12 -0700, Stephen Boyd wrote:
>Quoting Lina Iyer (2019-03-04 09:14:50)
>> On Fri, Mar 01 2019 at 10:58 -0700, Stephen Boyd wrote:
>> >Quoting Lina Iyer (2019-02-27 14:29:13)
>> >> Hi Stephen,
>> >>
>> >> On Tue, Feb 26 2019 at 17:49 -0700, Stephen Boyd wrote:
>> >
>> >Ok, can you explain why it's even a problem for the TCSes to be active
>> >during suspend? I would hope that for suspend/resume, if this is
>> >actually a problem, the RPMh driver itself can block suspend with a
>> >driver suspend callback that checks for idleness.
>> The RSC can transmit TCS executed from Linux and when all the CPUs have
>> powered down, could execute a firmware in the RSC to deliver the sleep
>> state requests. The firmware cannot run when there are active requests
>> being processed. To ensure that case, we bail out of sleep or suspend,
>> when the last CPU is powering down, if there are active requests.
>
>Ok, do we actually bail out or just pick a shallower idle state that
>wouldn't trigger the firmware to run something that may conflict with
>the active requests (i.e. some light CPU sleep mode)? The commit text
>seems to imply we block certain idle states.
>
We bail out of idle and let cpuidle determine the state again. We don't
go into a shallower state.
>>
>> >But I suspect that in
>> >the system wide suspend/resume case, any callers that could make TCS
>> >requests are child devices of the RPMh controller and therefore they
>> >would already be suspended if they didn't have anything pending they're
>> >waiting for a response on or they would be blocking suspend themselves
>> >if they're waiting for the response. So why are we even checking the
>> >TCSes in system suspend path at all? Assume that callers know what
>> >they're doing and will block suspend if they care?
>> >
>> In suspend, they probably would do what you mention above. All CPUs
>> might conincidentally be idle at the same idle, when a request is being
>> processed.
>>
>> >Following that same logic, is this more of an API that is planned for
>> >use by CPU idle? Where the case is much more of a runtime PM design.
>> >Even then, I don't get it. A device that's runtime active and making
>> >RPMh requests might need to block some forms of CPU idle states because
>> >a request hasn't been processed yet that may change the decision for
>> >certain deep idle states?
>> >
>> A process waiting on a RPMH request, may let the CPU go to sleep and
>> therefore this is a possibility.
>>
>
>Ok thanks for the info. Can these details be included in the commit text
>so we don't lose sight of the bigger picture? And can this patch series
>be combined with a larger cpuidle/suspend patch series so we don't have
>to review this in isolation? I don't understand the need to add more
>APIs that aren't used yet.
>
Agreed.

--Lina

Patch

diff --git a/drivers/soc/qcom/rpmh-internal.h b/drivers/soc/qcom/rpmh-internal.h
index 2e3ffcdf220e..4b891c23b4cd 100644
--- a/drivers/soc/qcom/rpmh-internal.h
+++ b/drivers/soc/qcom/rpmh-internal.h
@@ -109,6 +109,7 @@  int rpmh_rsc_write_ctrl_data(struct rsc_drv *drv,
 			     const struct tcs_request *msg);
 int rpmh_rsc_invalidate(struct rsc_drv *drv);
 int rpmh_rsc_write_pdc_data(struct rsc_drv *drv, const struct tcs_request *msg);
+bool rpmh_rsc_ctrlr_is_idle(struct rsc_drv *drv);
 void rpmh_tx_done(const struct tcs_request *msg, int r);
 
 #endif /* __RPM_INTERNAL_H__ */
diff --git a/drivers/soc/qcom/rpmh-rsc.c b/drivers/soc/qcom/rpmh-rsc.c
index d6b834eeeb37..9cc303e88a06 100644
--- a/drivers/soc/qcom/rpmh-rsc.c
+++ b/drivers/soc/qcom/rpmh-rsc.c
@@ -524,6 +524,30 @@  static int tcs_ctrl_write(struct rsc_drv *drv, const struct tcs_request *msg)
 	return ret;
 }
 
+/**
+ *  rpmh_rsc_ctrlr_is_idle: Check if any of the AMCs are busy.
+ *
+ *  @drv: The controller
+ *
+ *  Returns true if the TCSes are engaged in handling requests.
+ */
+bool rpmh_rsc_ctrlr_is_idle(struct rsc_drv *drv)
+{
+	int m;
+	struct tcs_group *tcs = get_tcs_of_type(drv, ACTIVE_TCS);
+
+	spin_lock(&drv->lock);
+	for (m = tcs->offset; m < tcs->offset + tcs->num_tcs; m++) {
+		if (!tcs_is_free(drv, m)) {
+			spin_unlock(&drv->lock);
+			return false;
+		}
+	}
+	spin_unlock(&drv->lock);
+
+	return true;
+}
+
 /**
  * rpmh_rsc_write_ctrl_data: Write request to the controller
  *
diff --git a/drivers/soc/qcom/rpmh.c b/drivers/soc/qcom/rpmh.c
index 297d6cc4e395..43eb9816041a 100644
--- a/drivers/soc/qcom/rpmh.c
+++ b/drivers/soc/qcom/rpmh.c
@@ -535,3 +535,16 @@  int rpmh_invalidate(const struct device *dev)
 	return ret;
 }
 EXPORT_SYMBOL(rpmh_invalidate);
+
+/**
+ * rpmh_ctrlr_idle: Return the controller idle status
+ *
+ * @dev: the device making the request
+ */
+int rpmh_ctrlr_idle(const struct device *dev)
+{
+	struct rpmh_ctrlr *ctrlr = get_rpmh_ctrlr(dev);
+
+	return rpmh_rsc_ctrlr_is_idle(ctrlr_to_drv(ctrlr));
+}
+EXPORT_SYMBOL(rpmh_ctrlr_idle);
diff --git a/include/soc/qcom/rpmh.h b/include/soc/qcom/rpmh.h
index b05e31aaf047..4c4b013f0226 100644
--- a/include/soc/qcom/rpmh.h
+++ b/include/soc/qcom/rpmh.h
@@ -27,6 +27,8 @@  int rpmh_invalidate(const struct device *dev);
 int rpmh_write_pdc_data(const struct device *dev,
 			const struct tcs_cmd *cmd, u32 n);
 
+int rpmh_ctrlr_idle(const struct device *dev);
+
 #else
 
 static inline int rpmh_write(const struct device *dev, enum rpmh_state state,
@@ -53,6 +55,9 @@  static inline int rpmh_write_pdc_data(const struct device *dev,
 				      const struct tcs_cmd *cmd, u32 n)
 { return -ENODEV; }
 
+static inline int rpmh_ctrlr_idle(const struct device *dev)
+{ return -ENODEV; }
+
 #endif /* CONFIG_QCOM_RPMH */
 
 #endif /* __SOC_QCOM_RPMH_H__ */