[lkml]   [2016]   [Dec]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH] [media] m5mols: set usleep_range delta greater 0
This delay is in non-atomic context and it does not seem to be
time-critical so relax it to allow the timer subsystem to optimize

Signed-off-by: Nicholas Mc Guire <>
problem was located by coccinelle spatch

The problem is that usleep_range is calculating the delay by
exp = ktime_add_us(ktime_get(), min)
delta = (u64)(max - min) * NSEC_PER_USEC
so delta is set to 0
and then calls
schedule_hrtimeout_range(exp, 0,...)
effectively this means that the clock subsystem has no room to
optimize which makes little sense as this is not atomic context
anyway so there is not guarantee of precision here.

As this is not a critical delay and the jitter of any system is
in the 10s of microseconds range anyway the range is set to 200
to 300 microseconds - this change cold have a negligible impact
on bandwidth (though I doubt this is relevant or even measurable
here) thus it needs a review by someone that knows the details
of the device and preferably would increase that range.

A comment in the second case was added to clarify the intent of
the delay as time between i2c transfers.

Patch was only compile tested against: x86_64_defconfig + CONFIG_MEDIA_SUPPORT=m

Patch is against 4.9.0 (localversion-next is next-20161212)

drivers/media/i2c/m5mols/m5mols_core.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/m5mols/m5mols_core.c b/drivers/media/i2c/m5mols/m5mols_core.c
index acb804b..23e8616 100644
--- a/drivers/media/i2c/m5mols/m5mols_core.c
+++ b/drivers/media/i2c/m5mols/m5mols_core.c
@@ -168,7 +168,7 @@ static int m5mols_read(struct v4l2_subdev *sd, u32 size, u32 reg, u32 *val)
msg[1].buf = rbuf;

/* minimum stabilization time */
- usleep_range(200, 200);
+ usleep_range(200, 300);

ret = i2c_transfer(client->adapter, msg, 2);

@@ -268,7 +268,8 @@ int m5mols_write(struct v4l2_subdev *sd, u32 reg, u32 val)

*buf = m5mols_swap_byte((u8 *)&val, size);

- usleep_range(200, 200);
+ /* minimum stabilization time */
+ usleep_range(200, 300);

ret = i2c_transfer(client->adapter, msg, 1);
if (ret == 1)
 \ /
  Last update: 2016-12-13 06:33    [W:0.038 / U:1.336 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site