2019-04-07 03:22:05

by Nicholas Mc Guire

[permalink] [raw]
Subject: [PATCH 1/3] media: smiapp: core: add range to usleep_range

Allow the hrtimer subsystem to coalesce delay timers of lower accuracy
by providing a suitable range

Signed-off-by: Nicholas Mc Guire <[email protected]>
---

Problem located by an experimental coccinelle script

hrtimers in atomic context have limited accuracy due to possible
context-switching and interruption so the accuracy is limited
anyway. Giving the hrtimer subsystem a reasonable range for merging
hrtimers helps to reduce the load on the hrtimer subsystem. As this
delays do not seem to mandate high accuracy the range of a factor
two seems acceptable.

Patch was compile tested with: x86_64_defconfig + MEDIA_SUPPORT=m,
MEDIA_CAMERA_SUPPORT=y, MEDIA_CONTROLLER=y, VIDEO_V4L2_SUBDEV_API=y,
VIDEO_SMIAPP=m
(with a number of sparse warnings on sizeof() usage)

Patch is against 5.1-rc3 (localversion-next is next-20190405)

drivers/media/i2c/smiapp/smiapp-core.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 58a45c3..c0c29ec 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -1222,19 +1222,19 @@ static int smiapp_power_on(struct device *dev)
dev_err(&client->dev, "failed to enable vana regulator\n");
return rval;
}
- usleep_range(1000, 1000);
+ usleep_range(1000, 2000);

rval = clk_prepare_enable(sensor->ext_clk);
if (rval < 0) {
dev_dbg(&client->dev, "failed to enable xclk\n");
goto out_xclk_fail;
}
- usleep_range(1000, 1000);
+ usleep_range(1000, 2000);

gpiod_set_value(sensor->xshutdown, 1);

sleep = SMIAPP_RESET_DELAY(sensor->hwcfg->ext_clk);
- usleep_range(sleep, sleep);
+ usleep_range(sleep, sleep*2);

mutex_lock(&sensor->mutex);

@@ -1381,7 +1381,7 @@ static int smiapp_power_off(struct device *dev)

gpiod_set_value(sensor->xshutdown, 0);
clk_disable_unprepare(sensor->ext_clk);
- usleep_range(5000, 5000);
+ usleep_range(5000, 10000);
regulator_disable(sensor->vana);
sensor->streaming = false;

--
2.1.4


2019-04-07 03:22:03

by Nicholas Mc Guire

[permalink] [raw]
Subject: [PATCH 3/3] media: smiapp: quirk: add range to usleep_range

No need for a high-accuracy delay here as long as it is more than 2
milliseconds this should be ok - as it is non-atomic context it will
be 2+ anyway and streamoff delays in the millisecond range should not
hurt.

Signed-off-by: Nicholas Mc Guire <[email protected]>
---

Problem located by an experimental coccinelle script

Patch was compile tested with: x86_64_defconfig + MEDIA_SUPPORT=m,
MEDIA_CAMERA_SUPPORT=y, MEDIA_CONTROLLER=y, VIDEO_V4L2_SUBDEV_API=y,
VIDEO_SMIAPP=m

Patch is against 5.1-rc3 (localversion-next is next-20190405)

drivers/media/i2c/smiapp/smiapp-quirk.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/i2c/smiapp/smiapp-quirk.c b/drivers/media/i2c/smiapp/smiapp-quirk.c
index 95c0272..21b7fdc 100644
--- a/drivers/media/i2c/smiapp/smiapp-quirk.c
+++ b/drivers/media/i2c/smiapp/smiapp-quirk.c
@@ -202,7 +202,7 @@ static int jt8ev1_post_streamoff(struct smiapp_sensor *sensor)
return rval;

/* Wait for 1 ms + one line => 2 ms is likely enough */
- usleep_range(2000, 2000);
+ usleep_range(2000, 4000);

/* Restore it */
rval = smiapp_write_8(sensor, 0x3205, 0x00);
--
2.1.4

2019-04-07 03:24:34

by Nicholas Mc Guire

[permalink] [raw]
Subject: [PATCH 2/3] media: smiapp: regs: add range to usleep_range

As this is a retry loop for a sender not responding there is no reason
to mandate a high accuracy delay - extend the sleep range to 2-4ms
so that the hrtimer subsystem can work efficiently.

Signed-off-by: Nicholas Mc Guire <[email protected]>
---

Problem located by an experimental coccinelle script

Patch was compile tested with: x86_64_defconfig + MEDIA_SUPPORT=m,
MEDIA_CAMERA_SUPPORT=y, MEDIA_CONTROLLER=y, VIDEO_V4L2_SUBDEV_API=y,
VIDEO_SMIAPP=m

Patch is against 5.1-rc3 (localversion-next is next-20190405)

drivers/media/i2c/smiapp/smiapp-regs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/i2c/smiapp/smiapp-regs.c b/drivers/media/i2c/smiapp/smiapp-regs.c
index 145653d..dfa4f99 100644
--- a/drivers/media/i2c/smiapp/smiapp-regs.c
+++ b/drivers/media/i2c/smiapp/smiapp-regs.c
@@ -276,7 +276,7 @@ int smiapp_write_no_quirk(struct smiapp_sensor *sensor, u32 reg, u32 val)
return 0;
}

- usleep_range(2000, 2000);
+ usleep_range(2000, 4000);
}

dev_err(&client->dev,
--
2.1.4

2019-04-30 13:53:13

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH 1/3] media: smiapp: core: add range to usleep_range

Hi Nicholas,

On Sun, Apr 07, 2019 at 04:16:02AM +0200, Nicholas Mc Guire wrote:
> Allow the hrtimer subsystem to coalesce delay timers of lower accuracy
> by providing a suitable range
>
> Signed-off-by: Nicholas Mc Guire <[email protected]>
> ---
>
> Problem located by an experimental coccinelle script
>
> hrtimers in atomic context have limited accuracy due to possible
> context-switching and interruption so the accuracy is limited
> anyway. Giving the hrtimer subsystem a reasonable range for merging
> hrtimers helps to reduce the load on the hrtimer subsystem. As this
> delays do not seem to mandate high accuracy the range of a factor
> two seems acceptable.
>
> Patch was compile tested with: x86_64_defconfig + MEDIA_SUPPORT=m,
> MEDIA_CAMERA_SUPPORT=y, MEDIA_CONTROLLER=y, VIDEO_V4L2_SUBDEV_API=y,
> VIDEO_SMIAPP=m
> (with a number of sparse warnings on sizeof() usage)
>
> Patch is against 5.1-rc3 (localversion-next is next-20190405)

The delays are exact for the reason that they are user-visible delays in
image capturing related use cases. Sometimes milliseconds matter, or at
least adding more does not help.

>
> drivers/media/i2c/smiapp/smiapp-core.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
> index 58a45c3..c0c29ec 100644
> --- a/drivers/media/i2c/smiapp/smiapp-core.c
> +++ b/drivers/media/i2c/smiapp/smiapp-core.c
> @@ -1222,19 +1222,19 @@ static int smiapp_power_on(struct device *dev)
> dev_err(&client->dev, "failed to enable vana regulator\n");
> return rval;
> }
> - usleep_range(1000, 1000);
> + usleep_range(1000, 2000);
>
> rval = clk_prepare_enable(sensor->ext_clk);
> if (rval < 0) {
> dev_dbg(&client->dev, "failed to enable xclk\n");
> goto out_xclk_fail;
> }
> - usleep_range(1000, 1000);
> + usleep_range(1000, 2000);
>
> gpiod_set_value(sensor->xshutdown, 1);
>
> sleep = SMIAPP_RESET_DELAY(sensor->hwcfg->ext_clk);
> - usleep_range(sleep, sleep);
> + usleep_range(sleep, sleep*2);
>
> mutex_lock(&sensor->mutex);
>
> @@ -1381,7 +1381,7 @@ static int smiapp_power_off(struct device *dev)
>
> gpiod_set_value(sensor->xshutdown, 0);
> clk_disable_unprepare(sensor->ext_clk);
> - usleep_range(5000, 5000);
> + usleep_range(5000, 10000);
> regulator_disable(sensor->vana);
> sensor->streaming = false;
>

--
Sakari Ailus

2019-05-04 09:49:12

by Nicholas Mc Guire

[permalink] [raw]
Subject: Re: [PATCH 1/3] media: smiapp: core: add range to usleep_range

On Tue, Apr 30, 2019 at 04:49:44PM +0300, Sakari Ailus wrote:
> Hi Nicholas,
>
> On Sun, Apr 07, 2019 at 04:16:02AM +0200, Nicholas Mc Guire wrote:
> > Allow the hrtimer subsystem to coalesce delay timers of lower accuracy
> > by providing a suitable range
> >
> > Signed-off-by: Nicholas Mc Guire <[email protected]>
> > ---
> >
> > Problem located by an experimental coccinelle script
> >
> > hrtimers in atomic context have limited accuracy due to possible
> > context-switching and interruption so the accuracy is limited
> > anyway. Giving the hrtimer subsystem a reasonable range for merging
> > hrtimers helps to reduce the load on the hrtimer subsystem. As this
> > delays do not seem to mandate high accuracy the range of a factor
> > two seems acceptable.
> >
> > Patch was compile tested with: x86_64_defconfig + MEDIA_SUPPORT=m,
> > MEDIA_CAMERA_SUPPORT=y, MEDIA_CONTROLLER=y, VIDEO_V4L2_SUBDEV_API=y,
> > VIDEO_SMIAPP=m
> > (with a number of sparse warnings on sizeof() usage)
> >
> > Patch is against 5.1-rc3 (localversion-next is next-20190405)
>
> The delays are exact for the reason that they are user-visible delays in
> image capturing related use cases. Sometimes milliseconds matter, or at
> least adding more does not help.
>

Actually it can be better iwith respect to jitter to let the hrtimer
subsystem use an existing timer event than to have a close by second event
and the accuracy is determined by the non-atomic context anyway -
so while the proposed delay extension might be excessive in your case
I would still suggest to try to get away from a range of 0 - even if
you only end up with (1000,1050) that would be an advantage for the
timer subsystem.

thx!
hofrat

> >
> > drivers/media/i2c/smiapp/smiapp-core.c | 8 ++++----
> > 1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
> > index 58a45c3..c0c29ec 100644
> > --- a/drivers/media/i2c/smiapp/smiapp-core.c
> > +++ b/drivers/media/i2c/smiapp/smiapp-core.c
> > @@ -1222,19 +1222,19 @@ static int smiapp_power_on(struct device *dev)
> > dev_err(&client->dev, "failed to enable vana regulator\n");
> > return rval;
> > }
> > - usleep_range(1000, 1000);
> > + usleep_range(1000, 2000);
> >
> > rval = clk_prepare_enable(sensor->ext_clk);
> > if (rval < 0) {
> > dev_dbg(&client->dev, "failed to enable xclk\n");
> > goto out_xclk_fail;
> > }
> > - usleep_range(1000, 1000);
> > + usleep_range(1000, 2000);
> >
> > gpiod_set_value(sensor->xshutdown, 1);
> >
> > sleep = SMIAPP_RESET_DELAY(sensor->hwcfg->ext_clk);
> > - usleep_range(sleep, sleep);
> > + usleep_range(sleep, sleep*2);
> >
> > mutex_lock(&sensor->mutex);
> >
> > @@ -1381,7 +1381,7 @@ static int smiapp_power_off(struct device *dev)
> >
> > gpiod_set_value(sensor->xshutdown, 0);
> > clk_disable_unprepare(sensor->ext_clk);
> > - usleep_range(5000, 5000);
> > + usleep_range(5000, 10000);
> > regulator_disable(sensor->vana);
> > sensor->streaming = false;
> >
>
> --
> Sakari Ailus

2019-05-07 21:51:28

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH 1/3] media: smiapp: core: add range to usleep_range

On Sat, May 04, 2019 at 11:46:35AM +0200, Nicholas Mc Guire wrote:
> On Tue, Apr 30, 2019 at 04:49:44PM +0300, Sakari Ailus wrote:
> > Hi Nicholas,
> >
> > On Sun, Apr 07, 2019 at 04:16:02AM +0200, Nicholas Mc Guire wrote:
> > > Allow the hrtimer subsystem to coalesce delay timers of lower accuracy
> > > by providing a suitable range
> > >
> > > Signed-off-by: Nicholas Mc Guire <[email protected]>
> > > ---
> > >
> > > Problem located by an experimental coccinelle script
> > >
> > > hrtimers in atomic context have limited accuracy due to possible
> > > context-switching and interruption so the accuracy is limited
> > > anyway. Giving the hrtimer subsystem a reasonable range for merging
> > > hrtimers helps to reduce the load on the hrtimer subsystem. As this
> > > delays do not seem to mandate high accuracy the range of a factor
> > > two seems acceptable.
> > >
> > > Patch was compile tested with: x86_64_defconfig + MEDIA_SUPPORT=m,
> > > MEDIA_CAMERA_SUPPORT=y, MEDIA_CONTROLLER=y, VIDEO_V4L2_SUBDEV_API=y,
> > > VIDEO_SMIAPP=m
> > > (with a number of sparse warnings on sizeof() usage)
> > >
> > > Patch is against 5.1-rc3 (localversion-next is next-20190405)
> >
> > The delays are exact for the reason that they are user-visible delays in
> > image capturing related use cases. Sometimes milliseconds matter, or at
> > least adding more does not help.
> >
>
> Actually it can be better iwith respect to jitter to let the hrtimer
> subsystem use an existing timer event than to have a close by second event
> and the accuracy is determined by the non-atomic context anyway -
> so while the proposed delay extension might be excessive in your case
> I would still suggest to try to get away from a range of 0 - even if
> you only end up with (1000,1050) that would be an advantage for the
> timer subsystem.

Sounds reasonable to me. Would you like to send v2?

Thanks.

--
Sakari Ailus