Re: [PATCH v2 6/7] media: imx319: Put usage_count correctly in s_ctrl callback

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Laurent,

On Tue, Nov 21, 2023 at 10:25:35AM +0200, Laurent Pinchart wrote:
> On Tue, Nov 21, 2023 at 08:18:24AM +0000, Sakari Ailus wrote:
> > Hi Laurent,
> > 
> > On Mon, Nov 20, 2023 at 11:45:03AM +0200, Laurent Pinchart wrote:
> > > On Mon, Nov 20, 2023 at 09:32:10AM +0000, Sakari Ailus wrote:
> > > > On Sat, Nov 18, 2023 at 08:52:48PM +0200, Laurent Pinchart wrote:
> > > > > On Fri, Nov 17, 2023 at 01:14:32PM +0200, Sakari Ailus wrote:
> > > > > > pm_runtime_get_if_in_use() returns an error if Runtime PM is disabled for
> > > > > > the device, in which case it won't increment the use count.
> > > > > > pm_runtime_put() does that unconditionally however. Only call
> > > > > > pm_runtime_put() in case pm_runtime_get_if_in_use() has returned a value >
> > > > > > 0.
> > > > > 
> > > > > Why don't you use pm_runtime_get_if_active() ?
> > > > 
> > > > It's only meaningful if the driver uses autosuspend. The imx319 driver does
> > > > not.
> > > 
> > > Does pm_runtime_get_if_active() causes issues with the driver uses
> > > autosuspend ? Standardizing on a single API that covers all the use
> > > cases would increase consistency and make the code base easier to
> > > understand. Beside, the driver should switch to autosuspend :-) Using
> > > the correct RPM calls already is a good thing, if they don't introduce
> > > any issue.
> > 
> > Both are fine but they're there for a different purpose. The driver should
> > consistently use either usage_count or status based calls (for autosuspend
> > to make sense).
> 
> But what's the drawback of using pm_runtime_get_if_active() in all cases
> (for camera sensor drivers) ? The semantics in the .s_ctrl() handler is
> "I want to proceed only if the device is powered on", and that's exactly
> what pm_runtime_get_if_active() gives us. The semantics of using
> pm_runtime_get_if_in_use() is "I want to proceed if someone else is
> holding a reference". It happens to give the same practical result as
> pm_runtime_get_if_active() when not using autosuspend, but it's still
> not the right semantics.

Well, using the _active() variant here may introduce an unneeded write
operation so that isn't actually an issue. But using the _if_in_use()
variant in a driver using autosuspend may lead to missing a write --- as it
returns 0 if the usage_count is 0 even if the device is in active state. Oh
well.

I can change the driver to use autosuspend but I think I'll split the set
into two, one doing the Runtime PM API changes and another to address
issues in sensor drivers.

> 
> > > > > Other than that, same comment as for patch 5/7, I don't like the
> > > > > increased complexity.
> > > > > 
> > > > > These comments apply to 7/7 as well.
> > > > > 
> > > > > > Signed-off-by: Sakari Ailus <sakari.ailus@xxxxxxxxxxxxxxx>
> > > > > > ---
> > > > > >  drivers/media/i2c/imx319.c | 8 +++++---
> > > > > >  1 file changed, 5 insertions(+), 3 deletions(-)
> > > > > > 
> > > > > > diff --git a/drivers/media/i2c/imx319.c b/drivers/media/i2c/imx319.c
> > > > > > index 5378f607f340..e7b2d0c20d29 100644
> > > > > > --- a/drivers/media/i2c/imx319.c
> > > > > > +++ b/drivers/media/i2c/imx319.c
> > > > > > @@ -1880,8 +1880,8 @@ static int imx319_set_ctrl(struct v4l2_ctrl *ctrl)
> > > > > >  	struct imx319 *imx319 = container_of(ctrl->handler,
> > > > > >  					     struct imx319, ctrl_handler);
> > > > > >  	struct i2c_client *client = v4l2_get_subdevdata(&imx319->sd);
> > > > > > +	int ret, pm_status;
> > > > > >  	s64 max;
> > > > > > -	int ret;
> > > > > >  
> > > > > >  	/* Propagate change of current control to all related controls */
> > > > > >  	switch (ctrl->id) {
> > > > > > @@ -1898,7 +1898,8 @@ static int imx319_set_ctrl(struct v4l2_ctrl *ctrl)
> > > > > >  	 * Applying V4L2 control value only happens
> > > > > >  	 * when power is up for streaming
> > > > > >  	 */
> > > > > > -	if (!pm_runtime_get_if_in_use(&client->dev))
> > > > > > +	pm_status = pm_runtime_get_if_in_use(&client->dev);
> > > > > > +	if (!pm_status)
> > > > > >  		return 0;
> > > > > >  
> > > > > >  	switch (ctrl->id) {
> > > > > > @@ -1937,7 +1938,8 @@ static int imx319_set_ctrl(struct v4l2_ctrl *ctrl)
> > > > > >  		break;
> > > > > >  	}
> > > > > >  
> > > > > > -	pm_runtime_put(&client->dev);
> > > > > > +	if (pm_status > 0)
> > > > > > +		pm_runtime_put(&client->dev);
> > > > > >  
> > > > > >  	return ret;
> > > > > >  }
> 

-- 
Regards,

Sakari Ailus




[Index of Archives]     [Linux IBM ACPI]     [Linux Power Management]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]
  Powered by Linux