[PATCH 3/7] i3c: master: Mark last_busy on IBI when runtime PM is allowed

Adrian Hunter posted 7 patches 1 week, 2 days ago
There is a newer version of this series
[PATCH 3/7] i3c: master: Mark last_busy on IBI when runtime PM is allowed
Posted by Adrian Hunter 1 week, 2 days ago
When an IBI can be received after the controller is
pm_runtime_put_autosuspend()'ed, the interrupt may occur just before the
device is auto‑suspended.  In such cases, the runtime PM core may not see
any recent activity and may suspend the device earlier than intended.

Mark the controller as last busy whenever an IBI is queued (when
rpm_ibi_allowed is set) so that the auto-suspend delay correctly reflects
recent bus activity and avoids premature suspension.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 drivers/i3c/master.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index bcc493dc9d04..dcc07ebc50a2 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -2721,9 +2721,14 @@ static void i3c_master_unregister_i3c_devs(struct i3c_master_controller *master)
  */
 void i3c_master_queue_ibi(struct i3c_dev_desc *dev, struct i3c_ibi_slot *slot)
 {
+	struct i3c_master_controller *master = i3c_dev_get_master(dev);
+
 	if (!dev->ibi || !slot)
 		return;
 
+	if (master->rpm_ibi_allowed)
+		pm_runtime_mark_last_busy(master->rpm_dev);
+
 	atomic_inc(&dev->ibi->pending_ibis);
 	queue_work(dev->ibi->wq, &slot->work);
 }
-- 
2.51.0

Re: [PATCH 3/7] i3c: master: Mark last_busy on IBI when runtime PM is allowed
Posted by Frank Li 1 week, 2 days ago
On Thu, Jan 29, 2026 at 08:18:37PM +0200, Adrian Hunter wrote:
> When an IBI can be received after the controller is
> pm_runtime_put_autosuspend()'ed, the interrupt may occur just before the
> device is auto‑suspended.  In such cases, the runtime PM core may not see
> any recent activity and may suspend the device earlier than intended.
>
> Mark the controller as last busy whenever an IBI is queued (when
> rpm_ibi_allowed is set) so that the auto-suspend delay correctly reflects
> recent bus activity and avoids premature suspension.

look like this can't resolve problem. pm_runtime_mark_last_busy() just
change dev->power.last_busy. If suspend before it, nothing happen.

irq use thread irq, in irq thread call pm_runtime_resume() if needs.

And this function call by irq handle, just put to work queue, what's impact
if do nothing here?

Frank

>
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
>  drivers/i3c/master.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index bcc493dc9d04..dcc07ebc50a2 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -2721,9 +2721,14 @@ static void i3c_master_unregister_i3c_devs(struct i3c_master_controller *master)
>   */
>  void i3c_master_queue_ibi(struct i3c_dev_desc *dev, struct i3c_ibi_slot *slot)
>  {
> +	struct i3c_master_controller *master = i3c_dev_get_master(dev);
> +
>  	if (!dev->ibi || !slot)
>  		return;
>
> +	if (master->rpm_ibi_allowed)
> +		pm_runtime_mark_last_busy(master->rpm_dev);
> +
>  	atomic_inc(&dev->ibi->pending_ibis);
>  	queue_work(dev->ibi->wq, &slot->work);
>  }
> --
> 2.51.0
>
Re: [PATCH 3/7] i3c: master: Mark last_busy on IBI when runtime PM is allowed
Posted by Adrian Hunter 1 week, 2 days ago
On 29/01/2026 21:56, Frank Li wrote:
> On Thu, Jan 29, 2026 at 08:18:37PM +0200, Adrian Hunter wrote:
>> When an IBI can be received after the controller is
>> pm_runtime_put_autosuspend()'ed, the interrupt may occur just before the
>> device is auto‑suspended.  In such cases, the runtime PM core may not see
>> any recent activity and may suspend the device earlier than intended.
>>
>> Mark the controller as last busy whenever an IBI is queued (when
>> rpm_ibi_allowed is set) so that the auto-suspend delay correctly reflects
>> recent bus activity and avoids premature suspension.
> 
> look like this can't resolve problem. pm_runtime_mark_last_busy() just
> change dev->power.last_busy. If suspend before it, nothing happen.

It should be effective.

rpm_suspend() recalculates the autosuspend expiry time based on
last_busy (see pm_runtime_autosuspend_expiration()) and restarts
the timer is it is in the future.

> 
> irq use thread irq, in irq thread call pm_runtime_resume() if needs.
> 
> And this function call by irq handle, just put to work queue, what's impact
> if do nothing here?

Just premature runtime suspension inconsistent with autosuspend_delay.

> 
> Frank
> 
>>
>> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
>> ---
>>  drivers/i3c/master.c | 5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
>> index bcc493dc9d04..dcc07ebc50a2 100644
>> --- a/drivers/i3c/master.c
>> +++ b/drivers/i3c/master.c
>> @@ -2721,9 +2721,14 @@ static void i3c_master_unregister_i3c_devs(struct i3c_master_controller *master)
>>   */
>>  void i3c_master_queue_ibi(struct i3c_dev_desc *dev, struct i3c_ibi_slot *slot)
>>  {
>> +	struct i3c_master_controller *master = i3c_dev_get_master(dev);
>> +
>>  	if (!dev->ibi || !slot)
>>  		return;
>>
>> +	if (master->rpm_ibi_allowed)
>> +		pm_runtime_mark_last_busy(master->rpm_dev);
>> +
>>  	atomic_inc(&dev->ibi->pending_ibis);
>>  	queue_work(dev->ibi->wq, &slot->work);
>>  }
>> --
>> 2.51.0
>>

Re: [PATCH 3/7] i3c: master: Mark last_busy on IBI when runtime PM is allowed
Posted by Frank Li 1 week, 2 days ago
On Thu, Jan 29, 2026 at 10:42:32PM +0200, Adrian Hunter wrote:
> On 29/01/2026 21:56, Frank Li wrote:
> > On Thu, Jan 29, 2026 at 08:18:37PM +0200, Adrian Hunter wrote:
> >> When an IBI can be received after the controller is
> >> pm_runtime_put_autosuspend()'ed, the interrupt may occur just before the
> >> device is auto‑suspended.  In such cases, the runtime PM core may not see
> >> any recent activity and may suspend the device earlier than intended.
> >>
> >> Mark the controller as last busy whenever an IBI is queued (when
> >> rpm_ibi_allowed is set) so that the auto-suspend delay correctly reflects
> >> recent bus activity and avoids premature suspension.
> >
> > look like this can't resolve problem. pm_runtime_mark_last_busy() just
> > change dev->power.last_busy. If suspend before it, nothing happen.
>
> It should be effective.
>
> rpm_suspend() recalculates the autosuspend expiry time based on
> last_busy (see pm_runtime_autosuspend_expiration()) and restarts
> the timer is it is in the future.
>
> >
> > irq use thread irq, in irq thread call pm_runtime_resume() if needs.
> >
> > And this function call by irq handle, just put to work queue, what's impact
> > if do nothing here?
>
> Just premature runtime suspension inconsistent with autosuspend_delay.


   CPU 0            CPU 1
1. rpm_suspend()    2. pm_runtime_mark_last_busy(master->rpm_dev)

if 2 happen before 1, it can extend suspend. 2 happen after 1, it should
do nothing.

Frank
>
> >
> > Frank
> >
> >>
> >> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> >> ---
> >>  drivers/i3c/master.c | 5 +++++
> >>  1 file changed, 5 insertions(+)
> >>
> >> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> >> index bcc493dc9d04..dcc07ebc50a2 100644
> >> --- a/drivers/i3c/master.c
> >> +++ b/drivers/i3c/master.c
> >> @@ -2721,9 +2721,14 @@ static void i3c_master_unregister_i3c_devs(struct i3c_master_controller *master)
> >>   */
> >>  void i3c_master_queue_ibi(struct i3c_dev_desc *dev, struct i3c_ibi_slot *slot)
> >>  {
> >> +	struct i3c_master_controller *master = i3c_dev_get_master(dev);
> >> +
> >>  	if (!dev->ibi || !slot)
> >>  		return;
> >>
> >> +	if (master->rpm_ibi_allowed)
> >> +		pm_runtime_mark_last_busy(master->rpm_dev);
> >> +
> >>  	atomic_inc(&dev->ibi->pending_ibis);
> >>  	queue_work(dev->ibi->wq, &slot->work);
> >>  }
> >> --
> >> 2.51.0
> >>
>
Re: [PATCH 3/7] i3c: master: Mark last_busy on IBI when runtime PM is allowed
Posted by Adrian Hunter 1 week, 1 day ago
On 29/01/2026 22:55, Frank Li wrote:
> On Thu, Jan 29, 2026 at 10:42:32PM +0200, Adrian Hunter wrote:
>> On 29/01/2026 21:56, Frank Li wrote:
>>> On Thu, Jan 29, 2026 at 08:18:37PM +0200, Adrian Hunter wrote:
>>>> When an IBI can be received after the controller is
>>>> pm_runtime_put_autosuspend()'ed, the interrupt may occur just before the
>>>> device is auto‑suspended.  In such cases, the runtime PM core may not see
>>>> any recent activity and may suspend the device earlier than intended.
>>>>
>>>> Mark the controller as last busy whenever an IBI is queued (when
>>>> rpm_ibi_allowed is set) so that the auto-suspend delay correctly reflects
>>>> recent bus activity and avoids premature suspension.
>>>
>>> look like this can't resolve problem. pm_runtime_mark_last_busy() just
>>> change dev->power.last_busy. If suspend before it, nothing happen.
>>
>> It should be effective.
>>
>> rpm_suspend() recalculates the autosuspend expiry time based on
>> last_busy (see pm_runtime_autosuspend_expiration()) and restarts
>> the timer is it is in the future.
>>
>>>
>>> irq use thread irq, in irq thread call pm_runtime_resume() if needs.
>>>
>>> And this function call by irq handle, just put to work queue, what's impact
>>> if do nothing here?
>>
>> Just premature runtime suspension inconsistent with autosuspend_delay.
> 
> 
>    CPU 0            CPU 1
> 1. rpm_suspend()    2. pm_runtime_mark_last_busy(master->rpm_dev)
> 
> if 2 happen before 1, it can extend suspend. 2 happen after 1, it should
> do nothing.

2 happening after 1 is a separate issue.  It will never happen
in the wakeup case because the wakeup does a runtime resume:

	pm_runtime_put_autosuspend()
	IBI -> pm_runtime_mark_last_busy()
	another IBI -> pm_runtime_mark_last_busy() and so on
	<autosuspend_delay finally elapses>
	rpm_suspend() -> device suspended, PME activated
	IBI START -> PME -> pm_request_resume()
	IBI is delivered after controller runtime resumes

> 
> Frank
>>
>>>
>>> Frank
>>>
>>>>
>>>> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
>>>> ---
>>>>  drivers/i3c/master.c | 5 +++++
>>>>  1 file changed, 5 insertions(+)
>>>>
>>>> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
>>>> index bcc493dc9d04..dcc07ebc50a2 100644
>>>> --- a/drivers/i3c/master.c
>>>> +++ b/drivers/i3c/master.c
>>>> @@ -2721,9 +2721,14 @@ static void i3c_master_unregister_i3c_devs(struct i3c_master_controller *master)
>>>>   */
>>>>  void i3c_master_queue_ibi(struct i3c_dev_desc *dev, struct i3c_ibi_slot *slot)
>>>>  {
>>>> +	struct i3c_master_controller *master = i3c_dev_get_master(dev);
>>>> +
>>>>  	if (!dev->ibi || !slot)
>>>>  		return;
>>>>
>>>> +	if (master->rpm_ibi_allowed)
>>>> +		pm_runtime_mark_last_busy(master->rpm_dev);
>>>> +
>>>>  	atomic_inc(&dev->ibi->pending_ibis);
>>>>  	queue_work(dev->ibi->wq, &slot->work);
>>>>  }
>>>> --
>>>> 2.51.0
>>>>
>>