Re: [PATCH v2 3/5] hwmon: (tmp102) Improve handling of initial read delay

From: Guenter Roeck
Date: Sun Jun 26 2016 - 10:02:18 EST


On 06/26/2016 06:31 AM, Nishanth Menon wrote:
On 06/25/2016 09:40 PM, Guenter Roeck wrote:
[...]
/* convert left adjusted 13-bit TMP102 register value to milliCelsius */
@@ -78,8 +82,16 @@ static struct tmp102 *tmp102_update_device(struct device *dev)
struct tmp102 *tmp102 = dev_get_drvdata(dev);
struct i2c_client *client = tmp102->client;

+ /* Is it too early to return a conversion ? */
+ if (time_before(jiffies, tmp102->ready_time)) {
+ unsigned long sleeptime = tmp102->ready_time - jiffies;
+
+ msleep(jiffies_to_msecs(sleeptime));
+ }
+

While msleep can indeed work and simplify, in case of usage for
example with thermal framework, if the data is not ready and we return
-EAGAIN, it lets the thermal framework go and read other sensors
instead of being blocked on the tmp102 conversion of data.


My thought was that returning -EAGAIN was more appropriate for the
1/3s wait time we had earlier. With 35ms, it is much more questionable
if we hit this condition in the first place than it was before,
and the impact if waiting is much less severe. Furthermore,
it is no longer unconditional but only occurs if the sensor
was in fact disabled.

But, yes, you have a point. I do prefer to wait, but if Rui and you
both agree that we should return -EAGAIN, I'll be happy to change
the code back to the old behavior.

Thanks,
Guenter