Skip to contentSkip to conversation

IIO: Change msleep to usleep_range for small msecs

PATCH In review Aniroop Mathur 5 participants 9 messages Nov 26, 2016 – Dec 3, 2016 1 message not in the archive

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 IIO: Change msleep to usleep_range for small msecs

msleep(1~20) may not do what the caller intends, and will often sleep longer. (~20 ms actual sleep for any value given in the 1~20ms range) This is not the desired behaviour for many cases like device resume time, device suspend time, device enable time, data reading time, etc. Thus, change msleep to usleep_range for precise wakeups.

---
 drivers/iio/adc/exynos_adc.c             |  2 +-
 drivers/iio/pressure/bmp280-core.c       | 14 +++++++-------
 drivers/staging/iio/meter/ade7753.c      |  2 +-
 drivers/staging/iio/meter/ade7753.h      |  2 +-
 drivers/staging/iio/meter/ade7754.c      |  2 +-
 drivers/staging/iio/meter/ade7754.h      |  2 +-
 drivers/staging/iio/meter/ade7758.h      |  2 +-
 drivers/staging/iio/meter/ade7758_core.c |  2 +-
 drivers/staging/iio/meter/ade7759.c      |  2 +-
 drivers/staging/iio/meter/ade7759.h      |  2 +-
 drivers/staging/iio/meter/ade7854.c      |  2 +-
 drivers/staging/iio/meter/ade7854.h      |  2 +-
 12 files changed, 18 insertions(+), 18 deletions(-)
drivers/iio/adc/exynos_adc.c +1 -1
index c15756d..ad1775b 100644
@@ -632,7 +632,7 @@ static irqreturn_t exynos_ts_isr(int irq, void *dev_id)
 		input_report_key(info->input, BTN_TOUCH, 1);
 		input_sync(info->input);
 
-		msleep(1);
+		usleep_range(1000, 1100);
 	};
 
 	writel(0, ADC_V1_CLRINTPNDNUP(info->regs));
drivers/iio/pressure/bmp280-core.c +7 -7
index e5a533c..4d18826 100644
@@ -65,7 +65,7 @@ struct bmp280_data {
 	struct bmp180_calib calib;
 	struct regulator *vddd;
 	struct regulator *vdda;
-	unsigned int start_up_time; /* in milliseconds */
+	unsigned int start_up_time; /* in microseconds */
 
 	/* log of base 2 of oversampling rate */
 	u8 oversampling_press;
@@ -935,14 +935,14 @@ int bmp280_common_probe(struct device *dev,
 		data->chip_info = &bmp180_chip_info;
 		data->oversampling_press = ilog2(8);
 		data->oversampling_temp = ilog2(1);
-		data->start_up_time = 10;
+		data->start_up_time = 10000;
 		break;
 	case BMP280_CHIP_ID:
 		indio_dev->num_channels = 2;
 		data->chip_info = &bmp280_chip_info;
 		data->oversampling_press = ilog2(16);
 		data->oversampling_temp = ilog2(2);
-		data->start_up_time = 2;
+		data->start_up_time = 2000;
 		break;
 	case BME280_CHIP_ID:
 		indio_dev->num_channels = 3;
@@ -950,7 +950,7 @@ int bmp280_common_probe(struct device *dev,
 		data->oversampling_press = ilog2(16);
 		data->oversampling_humid = ilog2(16);
 		data->oversampling_temp = ilog2(2);
-		data->start_up_time = 2;
+		data->start_up_time = 2000;
 		break;
 	default:
 		return -EINVAL;
@@ -979,7 +979,7 @@ int bmp280_common_probe(struct device *dev,
 		goto out_disable_vddd;
 	}
 	/* Wait to make sure we started up properly */
-	mdelay(data->start_up_time);
+	usleep_range(data->start_up_time, data->start_up_time + 100);
 
 	/* Bring chip out of reset if there is an assigned GPIO line */
 	gpiod = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
@@ -1038,7 +1038,7 @@ int bmp280_common_probe(struct device *dev,
 	 * Set autosuspend to two orders of magnitude larger than the
 	 * start-up time.
 	 */
-	pm_runtime_set_autosuspend_delay(dev, data->start_up_time *100);
+	pm_runtime_set_autosuspend_delay(dev, data->start_up_time / 10);
 	pm_runtime_use_autosuspend(dev);
 	pm_runtime_put(dev);
 
@@ -1101,7 +1101,7 @@ static int bmp280_runtime_resume(struct device *dev)
 	ret = regulator_enable(data->vdda);
 	if (ret)
 		return ret;
-	msleep(data->start_up_time);
+	usleep_range(data->start_up_time, data->start_up_time + 100);
 	return data->chip_info->chip_config(data);
 }
 #endif /* CONFIG_PM */
drivers/staging/iio/meter/ade7753.c +1 -1
index 4b5f05f..671dc99 100644
@@ -377,7 +377,7 @@ static int ade7753_initial_setup(struct iio_dev *indio_dev)
 	}
 
 	ade7753_reset(dev);
-	msleep(ADE7753_STARTUP_DELAY);
+	usleep_range(ADE7753_STARTUP_DELAY, ADE7753_STARTUP_DELAY + 100);
 
 err_ret:
 	return ret;
drivers/staging/iio/meter/ade7753.h +1 -1
index a9d93cc..bfe7491 100644
@@ -49,7 +49,7 @@
 
 #define ADE7753_MAX_TX    4
 #define ADE7753_MAX_RX    4
-#define ADE7753_STARTUP_DELAY 1
+#define ADE7753_STARTUP_DELAY 1000
 
 #define ADE7753_SPI_SLOW	(u32)(300 * 1000)
 #define ADE7753_SPI_BURST	(u32)(1000 * 1000)
drivers/staging/iio/meter/ade7754.c +1 -1
index c46bef6..49eb10b 100644
@@ -396,7 +396,7 @@ static int ade7754_initial_setup(struct iio_dev *indio_dev)
 	}
 
 	ade7754_reset(dev);
-	msleep(ADE7754_STARTUP_DELAY);
+	usleep_range(ADE7754_STARTUP_DELAY, ADE7754_STARTUP_DELAY + 100);
 
 err_ret:
 	return ret;
drivers/staging/iio/meter/ade7754.h +1 -1
index e42ffc3..28f71c2 100644
@@ -67,7 +67,7 @@
 
 #define ADE7754_MAX_TX    4
 #define ADE7754_MAX_RX    4
-#define ADE7754_STARTUP_DELAY 1
+#define ADE7754_STARTUP_DELAY 1000
 
 #define ADE7754_SPI_SLOW	(u32)(300 * 1000)
 #define ADE7754_SPI_BURST	(u32)(1000 * 1000)
drivers/staging/iio/meter/ade7758.h +1 -1
index 1d04ec9..6ae78d8 100644
@@ -89,7 +89,7 @@
 
 #define ADE7758_MAX_TX    8
 #define ADE7758_MAX_RX    4
-#define ADE7758_STARTUP_DELAY 1
+#define ADE7758_STARTUP_DELAY 1000
 
 #define AD7758_NUM_WAVSEL	5
 #define AD7758_NUM_PHSEL	3
drivers/staging/iio/meter/ade7758_core.c +1 -1
index ebb8a19..3767246 100644
@@ -459,7 +459,7 @@ static int ade7758_initial_setup(struct iio_dev *indio_dev)
 	}
 
 	ade7758_reset(dev);
-	msleep(ADE7758_STARTUP_DELAY);
+	usleep_range(ADE7758_STARTUP_DELAY, ADE7758_STARTUP_DELAY + 100);
 
 err_ret:
 	return ret;
drivers/staging/iio/meter/ade7759.c +1 -1
index 80144d4..944ee34 100644
@@ -338,7 +338,7 @@ static int ade7759_initial_setup(struct iio_dev *indio_dev)
 	}
 
 	ade7759_reset(dev);
-	msleep(ADE7759_STARTUP_DELAY);
+	usleep_range(ADE7759_STARTUP_DELAY, ADE7759_STARTUP_DELAY + 100);
 
 err_ret:
 	return ret;
drivers/staging/iio/meter/ade7759.h +1 -1
index f9ff1f8..f0716d2 100644
@@ -30,7 +30,7 @@
 
 #define ADE7759_MAX_TX    6
 #define ADE7759_MAX_RX    6
-#define ADE7759_STARTUP_DELAY 1
+#define ADE7759_STARTUP_DELAY 1000
 
 #define ADE7759_SPI_SLOW	(u32)(300 * 1000)
 #define ADE7759_SPI_BURST	(u32)(1000 * 1000)
drivers/staging/iio/meter/ade7854.c +1 -1
index 75e8685..58a05ec 100644
@@ -444,7 +444,7 @@ static int ade7854_initial_setup(struct iio_dev *indio_dev)
 	}
 
 	ade7854_reset(dev);
-	msleep(ADE7854_STARTUP_DELAY);
+	usleep_range(ADE7854_STARTUP_DELAY, ADE7854_STARTUP_DELAY + 100);
 
 err_ret:
 	return ret;
drivers/staging/iio/meter/ade7854.h +1 -1
index 52f4195..dbd97de 100644
@@ -136,7 +136,7 @@
 
 #define ADE7854_MAX_TX    7
 #define ADE7854_MAX_RX    7
-#define ADE7854_STARTUP_DELAY 1
+#define ADE7854_STARTUP_DELAY 1000
 
 #define ADE7854_SPI_SLOW	(u32)(300 * 1000)
 #define ADE7854_SPI_BURST	(u32)(1000 * 1000)
Signature · 1 line
2.6.2
maintainer
#1 lore raw
Quoted 7 lines · Aniroop Mathur

msleep(1~20) may not do what the caller intends, and will often sleep longer. (~20 ms actual sleep for any value given in the 1~20ms range) This is not the desired behaviour for many cases like device resume time, device suspend time, device enable time, data reading time, etc. Thus, change msleep to usleep_range for precise wakeups.

As these need individual review by the various original authors and driver maintainers to establish the intent of the sleep, it would have been better to have done a series of patches (one per driver) with the relevant maintainers cc'd on the ones that they care about.

Most of these are ADI parts looked after by Lars though so perhaps wait for his comments before respining.

Quoted 20 lines
---
 drivers/iio/adc/exynos_adc.c             |  2 +-
 drivers/iio/pressure/bmp280-core.c       | 14 +++++++-------
 drivers/staging/iio/meter/ade7753.c      |  2 +-
 drivers/staging/iio/meter/ade7753.h      |  2 +-
 drivers/staging/iio/meter/ade7754.c      |  2 +-
 drivers/staging/iio/meter/ade7754.h      |  2 +-
 drivers/staging/iio/meter/ade7758.h      |  2 +-
 drivers/staging/iio/meter/ade7758_core.c |  2 +-
 drivers/staging/iio/meter/ade7759.c      |  2 +-
 drivers/staging/iio/meter/ade7759.h      |  2 +-
 drivers/staging/iio/meter/ade7854.c      |  2 +-
 drivers/staging/iio/meter/ade7854.h      |  2 +-
 12 files changed, 18 insertions(+), 18 deletions(-)
drivers/iio/adc/exynos_adc.c +0 -0
index c15756d..ad1775b 100644

drivers/iio/adc/exynos_adc.c static irqreturn_t exynos_ts_isr(int irq, void *dev_id) · line 635

Quoted 5 lines
drivers/iio/adc/exynos_adc.c +1 -1
@@ -632,7 +632,7 @@ static irqreturn_t exynos_ts_isr(int irq, void *dev_id)
 		input_report_key(info->input, BTN_TOUCH, 1);
 		input_sync(info->input);
 
-		msleep(1);
+		usleep_range(1000, 1100);

This needs feedback on what an appropriate range actually is. Also in this particular case they will have a better idea of what msleep delivers as it's on a SoC where the clocks are entirely under their control. Worth adding a cc for Naveen as well as the original driver author (may well bounce - I have no idea!)

drivers/iio/pressure/bmp280-core.c struct bmp280_data { · line 68

Quoted 13 lines
drivers/iio/adc/exynos_adc.c +0 -0
 	};
 
 	writel(0, ADC_V1_CLRINTPNDNUP(info->regs));
drivers/iio/pressure/bmp280-core.c +1 -1
index e5a533c..4d18826 100644
@@ -65,7 +65,7 @@ struct bmp280_data {
 	struct bmp180_calib calib;
 	struct regulator *vddd;
 	struct regulator *vdda;
-	unsigned int start_up_time; /* in milliseconds */
+	unsigned int start_up_time; /* in microseconds */

Would have been less invasive to leave this alone and just multiply by 1000 where relevant for the sleep.

Quoted 30 lines
drivers/iio/pressure/bmp280-core.c +3 -3
 	/* log of base 2 of oversampling rate */
 	u8 oversampling_press;
@@ -935,14 +935,14 @@ int bmp280_common_probe(struct device *dev,
 		data->chip_info = &bmp180_chip_info;
 		data->oversampling_press = ilog2(8);
 		data->oversampling_temp = ilog2(1);
-		data->start_up_time = 10;
+		data->start_up_time = 10000;
 		break;
 	case BMP280_CHIP_ID:
 		indio_dev->num_channels = 2;
 		data->chip_info = &bmp280_chip_info;
 		data->oversampling_press = ilog2(16);
 		data->oversampling_temp = ilog2(2);
-		data->start_up_time = 2;
+		data->start_up_time = 2000;
 		break;
 	case BME280_CHIP_ID:
 		indio_dev->num_channels = 3;
@@ -950,7 +950,7 @@ int bmp280_common_probe(struct device *dev,
 		data->oversampling_press = ilog2(16);
 		data->oversampling_humid = ilog2(16);
 		data->oversampling_temp = ilog2(2);
-		data->start_up_time = 2;
+		data->start_up_time = 2000;
 		break;
 	default:
 		return -EINVAL;

drivers/iio/pressure/bmp280-core.c int bmp280_common_probe(struct device *dev, · line 982

Quoted 5 lines
drivers/iio/pressure/bmp280-core.c +1 -1
@@ -979,7 +979,7 @@ int bmp280_common_probe(struct device *dev,
 		goto out_disable_vddd;
 	}
 	/* Wait to make sure we started up properly */
-	mdelay(data->start_up_time);
+	usleep_range(data->start_up_time, data->start_up_time + 100);

As this in probe I doubt we really care. Could just set it longer to shut up the warnings. Still would like some input from say Linus on this...

Quoted 26 lines
drivers/iio/pressure/bmp280-core.c +2 -2
 	/* Bring chip out of reset if there is an assigned GPIO line */
 	gpiod = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
@@ -1038,7 +1038,7 @@ int bmp280_common_probe(struct device *dev,
 	 * Set autosuspend to two orders of magnitude larger than the
 	 * start-up time.
 	 */
-	pm_runtime_set_autosuspend_delay(dev, data->start_up_time *100);
+	pm_runtime_set_autosuspend_delay(dev, data->start_up_time / 10);
 	pm_runtime_use_autosuspend(dev);
 	pm_runtime_put(dev);
 
@@ -1101,7 +1101,7 @@ static int bmp280_runtime_resume(struct device *dev)
 	ret = regulator_enable(data->vdda);
 	if (ret)
 		return ret;
-	msleep(data->start_up_time);
+	usleep_range(data->start_up_time, data->start_up_time + 100);
 	return data->chip_info->chip_config(data);
 }
 #endif /* CONFIG_PM */
drivers/staging/iio/meter/ade7753.c +0 -0
index 4b5f05f..671dc99 100644

drivers/staging/iio/meter/ade7753.c static int ade7753_initial_setup(struct iio_dev *indio_dev) · line 380

Quoted 5 lines
drivers/staging/iio/meter/ade7753.c +1 -1
@@ -377,7 +377,7 @@ static int ade7753_initial_setup(struct iio_dev *indio_dev)
 	}
 
 	ade7753_reset(dev);
-	msleep(ADE7753_STARTUP_DELAY);
+	usleep_range(ADE7753_STARTUP_DELAY, ADE7753_STARTUP_DELAY + 100);

Again these are in slow paths really so may be perfectly acceptable to wait much longer...

Quoted 112 lines
drivers/staging/iio/meter/ade7753.c +0 -0
 err_ret:
 	return ret;
drivers/staging/iio/meter/ade7753.h +1 -1
index a9d93cc..bfe7491 100644
@@ -49,7 +49,7 @@
 
 #define ADE7753_MAX_TX    4
 #define ADE7753_MAX_RX    4
-#define ADE7753_STARTUP_DELAY 1
+#define ADE7753_STARTUP_DELAY 1000
 
 #define ADE7753_SPI_SLOW	(u32)(300 * 1000)
 #define ADE7753_SPI_BURST	(u32)(1000 * 1000)
drivers/staging/iio/meter/ade7754.c +1 -1
index c46bef6..49eb10b 100644
@@ -396,7 +396,7 @@ static int ade7754_initial_setup(struct iio_dev *indio_dev)
 	}
 
 	ade7754_reset(dev);
-	msleep(ADE7754_STARTUP_DELAY);
+	usleep_range(ADE7754_STARTUP_DELAY, ADE7754_STARTUP_DELAY + 100);
 
 err_ret:
 	return ret;
drivers/staging/iio/meter/ade7754.h +1 -1
index e42ffc3..28f71c2 100644
@@ -67,7 +67,7 @@
 
 #define ADE7754_MAX_TX    4
 #define ADE7754_MAX_RX    4
-#define ADE7754_STARTUP_DELAY 1
+#define ADE7754_STARTUP_DELAY 1000
 
 #define ADE7754_SPI_SLOW	(u32)(300 * 1000)
 #define ADE7754_SPI_BURST	(u32)(1000 * 1000)
drivers/staging/iio/meter/ade7758.h +1 -1
index 1d04ec9..6ae78d8 100644
@@ -89,7 +89,7 @@
 
 #define ADE7758_MAX_TX    8
 #define ADE7758_MAX_RX    4
-#define ADE7758_STARTUP_DELAY 1
+#define ADE7758_STARTUP_DELAY 1000
 
 #define AD7758_NUM_WAVSEL	5
 #define AD7758_NUM_PHSEL	3
drivers/staging/iio/meter/ade7758_core.c +1 -1
index ebb8a19..3767246 100644
@@ -459,7 +459,7 @@ static int ade7758_initial_setup(struct iio_dev *indio_dev)
 	}
 
 	ade7758_reset(dev);
-	msleep(ADE7758_STARTUP_DELAY);
+	usleep_range(ADE7758_STARTUP_DELAY, ADE7758_STARTUP_DELAY + 100);
 
 err_ret:
 	return ret;
drivers/staging/iio/meter/ade7759.c +1 -1
index 80144d4..944ee34 100644
@@ -338,7 +338,7 @@ static int ade7759_initial_setup(struct iio_dev *indio_dev)
 	}
 
 	ade7759_reset(dev);
-	msleep(ADE7759_STARTUP_DELAY);
+	usleep_range(ADE7759_STARTUP_DELAY, ADE7759_STARTUP_DELAY + 100);
 
 err_ret:
 	return ret;
drivers/staging/iio/meter/ade7759.h +1 -1
index f9ff1f8..f0716d2 100644
@@ -30,7 +30,7 @@
 
 #define ADE7759_MAX_TX    6
 #define ADE7759_MAX_RX    6
-#define ADE7759_STARTUP_DELAY 1
+#define ADE7759_STARTUP_DELAY 1000
 
 #define ADE7759_SPI_SLOW	(u32)(300 * 1000)
 #define ADE7759_SPI_BURST	(u32)(1000 * 1000)
drivers/staging/iio/meter/ade7854.c +1 -1
index 75e8685..58a05ec 100644
@@ -444,7 +444,7 @@ static int ade7854_initial_setup(struct iio_dev *indio_dev)
 	}
 
 	ade7854_reset(dev);
-	msleep(ADE7854_STARTUP_DELAY);
+	usleep_range(ADE7854_STARTUP_DELAY, ADE7854_STARTUP_DELAY + 100);
 
 err_ret:
 	return ret;
drivers/staging/iio/meter/ade7854.h +0 -0
index 52f4195..dbd97de 100644

drivers/staging/iio/meter/ade7854.h line 139

Quoted 5 lines
drivers/staging/iio/meter/ade7854.h +1 -1
@@ -136,7 +136,7 @@
 
 #define ADE7854_MAX_TX    7
 #define ADE7854_MAX_RX    7
-#define ADE7854_STARTUP_DELAY 1
+#define ADE7854_STARTUP_DELAY 1000

This particular define seems rather pointless. Would be more readable inline within the code! Same for the other cases.

Quoted 4 lines
drivers/staging/iio/meter/ade7854.h +0 -0
 #define ADE7854_SPI_SLOW	(u32)(300 * 1000)
 #define ADE7854_SPI_BURST	(u32)(1000 * 1000)
 
#2 lore raw
Quoted 1 line · Jonathan Cameron

On 26/11/16 03:47, Aniroop Mathur wrote:

[bmp280.c]

Quoted 6 lines

drivers/iio/pressure/bmp280-core.c int bmp280_common_probe(struct device *dev, · line 982

Quoted 3 lines
      /* Wait to make sure we started up properly */
drivers/iio/pressure/bmp280-core.c +1 -1
-     mdelay(data->start_up_time);
+     usleep_range(data->start_up_time, data->start_up_time + 100);

As this in probe I doubt we really care. Could just set it longer to shut up the warnings. Still would like some input from say Linus on this...

Hm, I don't think it's a big issue... this works too it just looks overworked.

On the runtime_resume() path we use msleep() instead which I guess is why it is not changed in this patch, but they have the same purpose.

Yours,
Linus Walleij

#3 lore raw
Quoted 9 lines · Linus Walleij
Quoted 1 line · Jonathan Cameron

On 26/11/16 03:47, Aniroop Mathur wrote:

[bmp280.c]

Quoted 4 lines
Quoted 3 lines
      /* Wait to make sure we started up properly */
drivers/iio/pressure/bmp280-core.c +1 -1
-     mdelay(data->start_up_time);
+     usleep_range(data->start_up_time, data->start_up_time + 100);
Quoted 8 lines
Quoted 2 lines

As this in probe I doubt we really care. Could just set it longer to shut up the warnings. Still would like some input from say Linus on this...

Hm, I don't think it's a big issue... this works too it just looks overworked.

On the runtime_resume() path we use msleep() instead which I guess is why it is not changed in this patch, but they have the same purpose.

I did change msleep to usleep_range in runtime_resume() in bmp280.c as you know resume time is critical indeed.

Quoted 2 lines

Yours,
Linus Walleij

#4 lore raw
In reply to Jonathan Cameron
Quoted 7 lines · Jonathan Cameron
Quoted 6 lines · Aniroop Mathur

msleep(1~20) may not do what the caller intends, and will often sleep longer. (~20 ms actual sleep for any value given in the 1~20ms range) This is not the desired behaviour for many cases like device resume time, device suspend time, device enable time, data reading time, etc. Thus, change msleep to usleep_range for precise wakeups.

Quoted 7 lines
Quoted 1 line

As these need individual review by the various original authors and driver maintainers to establish the intent of the sleep, it would have been better to have done a series of patches (one per driver) with the relevant maintainers cc'd on the ones that they care about.

Most of these are ADI parts looked after by Lars though so perhaps wait for his comments before respining.

I agree with what Jonathan said. For most of these extending the maximum sleep time a bit further is ok.

A message that is not in the archive (sent off-list or not yet received): CGME20161130133557epcas2p2caca5d58770bf31614812d14b809fe8f@epcas2p2.samsung.com

#6 lore raw
Quoted 14 lines · Lars-Peter Clausen
Quoted 12 lines · Jonathan Cameron
Quoted 7 lines · Aniroop Mathur

msleep(1~20) may not do what the caller intends, and will often sleep longer. (~20 ms actual sleep for any value given in the 1~20ms range) This is not the desired behaviour for many cases like device resume time, device suspend time, device enable time, data reading time, etc. Thus, change msleep to usleep_range for precise wakeups.

As these need individual review by the various original authors and driver maintainers to establish the intent of the sleep, it would have been better to have done a series of patches (one per driver) with the relevant maintainers cc'd on the ones that they care about.

Quoted 6 lines
Quoted 2 lines

Most of these are ADI parts looked after by Lars though so perhaps wait for his comments before respining.

I agree with what Jonathan said. For most of these extending the maximum sleep time a bit further is ok.

Well, its right that sleep a bit further is okay but this patch is not trying to solve any major bug. This patch is only trying to make the wake up more precise than before. So like with msleep(1), process could sleep for 20 ms so this patch only making the making the process to sleep for 1 ms as mentioned in the parameter. So I think, changing to usleep_range is only advantageous and does not cause any harm here.
We have also applied the same change in enable/disable/suspend/resume functions in accel, gyro, mag, etc drivers and found decent results like the first sesor data is generated much faster than before so response time increased. This is critical as sensor can run at a rate of 200Hz / 5ms or even more now a days in new devices. We even applied in probe as doing the same in many drivers contribute to a little saving overall in kernel boot up. Also, it is recommended and mentioned in kernel documentation to use usleep_range for 1-10 ms.
Sources -
https://www.kernel.org/doc/Documentation/timers/timers-howto.txt
https://lkml.org/lkml/2007/8/3/250

Thanks.

BR,
Aniroop Mathur

#7 lore raw
Quoted 31 lines · Aniroop Mathur
Quoted 14 lines · Lars-Peter Clausen
Quoted 12 lines · Jonathan Cameron
Quoted 7 lines · Aniroop Mathur

msleep(1~20) may not do what the caller intends, and will often sleep longer. (~20 ms actual sleep for any value given in the 1~20ms range) This is not the desired behaviour for many cases like device resume time, device suspend time, device enable time, data reading time, etc. Thus, change msleep to usleep_range for precise wakeups.

As these need individual review by the various original authors and driver maintainers to establish the intent of the sleep, it would have been better to have done a series of patches (one per driver) with the relevant maintainers cc'd on the ones that they care about.

Quoted 6 lines
Quoted 2 lines

Most of these are ADI parts looked after by Lars though so perhaps wait for his comments before respining.

I agree with what Jonathan said. For most of these extending the maximum sleep time a bit further is ok.

Well, its right that sleep a bit further is okay but this patch is not trying to solve any major bug. This patch is only trying to make the wake up more precise than before. So like with msleep(1), process could sleep for 20 ms so this patch only making the making the process to sleep for 1 ms as mentioned in the parameter. So I think, changing to usleep_range is only advantageous and does not cause any harm here.
We have also applied the same change in enable/disable/suspend/resume functions in accel, gyro, mag, etc drivers and found decent results like the first sesor data is generated much faster than before so response time

Quoted 9 lines

increased. This is critical as sensor can run at a rate of 200Hz / 5ms or even more now a days in new devices. We even applied in probe as doing the same in many drivers contribute to a little saving overall in kernel boot up. Also, it is recommended and mentioned in kernel documentation to use usleep_range for 1-10 ms.
Sources -
https://www.kernel.org/doc/Documentation/timers/timers-howto.txt
https://lkml.org/lkml/2007/8/3/250

Hello Mr. Jonathan / Mr. Lars / All,

Would you kindly update further about this change?

Quoted 4 lines

Thanks.

BR,
Aniroop Mathur

maintainer
#8 lore raw
Quoted 43 lines · Aniroop Mathur
Quoted 31 lines · Aniroop Mathur
Quoted 14 lines · Lars-Peter Clausen
Quoted 12 lines · Jonathan Cameron
Quoted 7 lines · Aniroop Mathur

msleep(1~20) may not do what the caller intends, and will often sleep longer. (~20 ms actual sleep for any value given in the 1~20ms range) This is not the desired behaviour for many cases like device resume time, device suspend time, device enable time, data reading time, etc. Thus, change msleep to usleep_range for precise wakeups.

As these need individual review by the various original authors and driver maintainers to establish the intent of the sleep, it would have been better to have done a series of patches (one per driver) with the relevant maintainers cc'd on the ones that they care about.

Quoted 6 lines
Quoted 2 lines

Most of these are ADI parts looked after by Lars though so perhaps wait for his comments before respining.

I agree with what Jonathan said. For most of these extending the maximum sleep time a bit further is ok.

Well, its right that sleep a bit further is okay but this patch is not trying to solve any major bug. This patch is only trying to make the wake up more precise than before. So like with msleep(1), process could sleep for 20 ms so this patch only making the making the process to sleep for 1 ms as mentioned in the parameter. So I think, changing to usleep_range is only advantageous and does not cause any harm here.
We have also applied the same change in enable/disable/suspend/resume functions in accel, gyro, mag, etc drivers and found decent results like the first sesor data is generated much faster than before so response time

Quoted 9 lines

increased. This is critical as sensor can run at a rate of 200Hz / 5ms or even more now a days in new devices. We even applied in probe as doing the same in many drivers contribute to a little saving overall in kernel boot up. Also, it is recommended and mentioned in kernel documentation to use usleep_range for 1-10 ms.
Sources -
https://www.kernel.org/doc/Documentation/timers/timers-howto.txt
https://lkml.org/lkml/2007/8/3/250

Quoted 4 lines

Hello Mr. Jonathan / Mr. Lars / All,

Would you kindly update further about this change?

Hi Aniroop,

Quite a few of us only manage to get to kernel patches once or twice a week (in my case only on weekends most weeks).

Anyhow, I've applied this patch as is. I don't necessarily think the change is that important in the probe paths, but as you said it does little harm.

So what the heck ;)

Applied to the togreg branch of iio.git which I'll push out as testing once I have a net connection (currently on a train).

Thanks,

Jonathan

Quoted 6 lines
Quoted 6 lines

Thanks.

BR,
Aniroop Mathur

#9 lore raw
Quoted 53 lines · Jonathan Cameron
Quoted 43 lines · Aniroop Mathur
Quoted 31 lines · Aniroop Mathur
Quoted 14 lines · Lars-Peter Clausen
Quoted 12 lines · Jonathan Cameron
Quoted 7 lines · Aniroop Mathur

msleep(1~20) may not do what the caller intends, and will often sleep longer. (~20 ms actual sleep for any value given in the 1~20ms range) This is not the desired behaviour for many cases like device resume time, device suspend time, device enable time, data reading time, etc. Thus, change msleep to usleep_range for precise wakeups.

As these need individual review by the various original authors and driver maintainers to establish the intent of the sleep, it would have been better to have done a series of patches (one per driver) with the relevant maintainers cc'd on the ones that they care about.

Quoted 6 lines
Quoted 2 lines

Most of these are ADI parts looked after by Lars though so perhaps wait for his comments before respining.

I agree with what Jonathan said. For most of these extending the maximum sleep time a bit further is ok.

Well, its right that sleep a bit further is okay but this patch is not trying to solve any major bug. This patch is only trying to make the wake up more precise than before. So like with msleep(1), process could sleep for 20 ms so this patch only making the making the process to sleep for 1 ms as mentioned in the parameter. So I think, changing to usleep_range is only advantageous and does not cause any harm here.
We have also applied the same change in enable/disable/suspend/resume functions in accel, gyro, mag, etc drivers and found decent results like the first sesor data is generated much faster than before so response time

Quoted 9 lines

increased. This is critical as sensor can run at a rate of 200Hz / 5ms or even more now a days in new devices. We even applied in probe as doing the same in many drivers contribute to a little saving overall in kernel boot up. Also, it is recommended and mentioned in kernel documentation to use usleep_range for 1-10 ms.
Sources -
https://www.kernel.org/doc/Documentation/timers/timers-howto.txt
https://lkml.org/lkml/2007/8/3/250

Quoted 4 lines

Hello Mr. Jonathan / Mr. Lars / All,

Would you kindly update further about this change?

Hi Aniroop,

Quite a few of us only manage to get to kernel patches once or twice a week (in my case only on weekends most weeks).

Quoted 8 lines

Anyhow, I've applied this patch as is. I don't necessarily think the change is that important in the probe paths, but as you said it does little harm.

So what the heck ;)

Applied to the togreg branch of iio.git which I'll push out as testing once I have a net connection (currently on a train).

This sounds great !! Thanks a lot :)

BR,
Aniroop Mathur

Quoted 10 lines

Thanks,

Jonathan

Quoted 6 lines
Quoted 6 lines

Thanks.

BR,
Aniroop Mathur