Skip to contentSkip to conversation

iio: accel: kx022a: Improve reset delay

PATCH Superseded Matti Vaittinen 2 participants 10 messages Nov 14, 2024 – Nov 19, 2024

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Matti Vaittinen

author maintainer
#0 lore raw

PATCH 1/1 iio: accel: kx022a: Improve reset delay

All the sensors supported by kx022a driver seemed to require some delay after software reset to be operational again. More or less a random msleep(1) was added to cause the driver to go to sleep so the sensor has time to become operational again.

Now we have official docuumentation available:
https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf
https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf
https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf

stating the required time is 2 ms.

Due to the nature of the current msleep implementation, the msleep(1) is likely to be sleeping more than 2ms already - but the value "1" is misleading in case someone needs to optimize the start time and change the msleep to a more accurate delay. Hence it is better for "documentation" purposes to use value which actually reflects the specified 2ms wait time.

Change the value of delay after software reset to match the specifications and add links to the power-on procedure specifications.

---
Sorry for not including this to the KX134ACR-LBZ series I sent yesterday. It was only half an hour after I had sent the KX134ACR-LBZ support when I was notified about the existence of the KX022ACR-Z start-up procedure specification... Hence this lone patch to code which I just sent a miscallaneous series for before.

 drivers/iio/accel/kionix-kx022a.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/iio/accel/kionix-kx022a.c +8 -3
index 32387819995d..ccabe2e3b130 100644
@@ -1121,10 +1121,15 @@ static int kx022a_chip_init(struct kx022a_data *data)
 		return ret;
 
 	/*
-	 * I've seen I2C read failures if we poll too fast after the sensor
-	 * reset. Slight delay gives I2C block the time to recover.
+	 * According to the power-on procedure documents, there is (at least)
+	 * 2ms delay required after the software reset. This should be same for
+	 * all, KX022ACR-Z, KX132-1211, KX132ACR-LBZ and KX134ACR-LBZ.
+	 *
+	 * https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf
+	 * https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf
+	 * https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf
 	 */
-	msleep(1);
+	msleep(2);
 
 	ret = regmap_read_poll_timeout(data->regmap, data->chip_info->cntl2, val,
 				       !(val & KX022A_MASK_SRST),

base-commit: 20fd1383cd616d61b2a79967da1221dc6cfb8430

Signature · 1 line
2.47.0
#1 lore raw
Quoted 56 lines · Matti Vaittinen

All the sensors supported by kx022a driver seemed to require some delay after software reset to be operational again. More or less a random msleep(1) was added to cause the driver to go to sleep so the sensor has time to become operational again.

Now we have official docuumentation available:
https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf
https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf
https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf

stating the required time is 2 ms.

Due to the nature of the current msleep implementation, the msleep(1) is likely to be sleeping more than 2ms already - but the value "1" is misleading in case someone needs to optimize the start time and change the msleep to a more accurate delay. Hence it is better for "documentation" purposes to use value which actually reflects the specified 2ms wait time.

Change the value of delay after software reset to match the specifications and add links to the power-on procedure specifications.

---
Sorry for not including this to the KX134ACR-LBZ series I sent yesterday. It was only half an hour after I had sent the KX134ACR-LBZ support when I was notified about the existence of the KX022ACR-Z start-up procedure specification... Hence this lone patch to code which I just sent a miscallaneous series for before.

 drivers/iio/accel/kionix-kx022a.c | 11 ++++++++---

 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/iio/accel/kionix- renamed from drivers/iio/accel/kionix-kx022a.c +0 -0

kx022a.c
index 32387819995d..ccabe2e3b130 100644

drivers/iio/accel/kionix-kx022a.c +0 -0
@@ -1121,10 +1121,15 @@ static int kx022a_chip_init(struct kx022a_data *data)
  		return ret;


  /*

drivers/iio/accel/kionix-kx022a.c +2 -2
-	 * I've seen I2C read failures if we poll too fast after the sensor
-	 * reset. Slight delay gives I2C block the time to recover.
+	 * According to the power-on procedure documents, there is (at least)
+	 * 2ms delay required after the software reset. This should be same

for

drivers/iio/accel/kionix-kx022a.c +3 -0
+	 * all, KX022ACR-Z, KX132-1211, KX132ACR-LBZ and KX134ACR-LBZ.
+	 *
+	 *

https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 *

https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 *

https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf
  */

drivers/iio/accel/kionix-kx022a.c static int kx022a_chip_init(struct kx022a_data *data) · line 1132

Quoted 2 lines
drivers/iio/accel/kionix-kx022a.c +1 -1
-	msleep(1);
+	msleep(2);

msleep() is not advisable for something lower than 20ms. Maybe take the opportunity and change it to fsleep()?

- Nuno Sá

author maintainer
#2 lore raw
Quoted 54 lines · Nuno Sá
Quoted 53 lines · Matti Vaittinen

All the sensors supported by kx022a driver seemed to require some delay after software reset to be operational again. More or less a random msleep(1) was added to cause the driver to go to sleep so the sensor has time to become operational again.

Now we have official docuumentation available:
https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf
https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf
https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf

stating the required time is 2 ms.

Due to the nature of the current msleep implementation, the msleep(1) is likely to be sleeping more than 2ms already - but the value "1" is misleading in case someone needs to optimize the start time and change the msleep to a more accurate delay. Hence it is better for "documentation" purposes to use value which actually reflects the specified 2ms wait time.

Change the value of delay after software reset to match the specifications and add links to the power-on procedure specifications.

---
Sorry for not including this to the KX134ACR-LBZ series I sent yesterday. It was only half an hour after I had sent the KX134ACR-LBZ support when I was notified about the existence of the KX022ACR-Z start-up procedure specification... Hence this lone patch to code which I just sent a miscallaneous series for before.

  drivers/iio/accel/kionix-kx022a.c | 11 ++++++++---
  1 file changed, 8 insertions(+), 3 deletions(-)
drivers/iio/accel/kionix- renamed from drivers/iio/accel/kionix-kx022a.c +0 -0

kx022a.c
index 32387819995d..ccabe2e3b130 100644

drivers/iio/accel/kionix-kx022a.c +2 -2
@@ -1121,10 +1121,15 @@ static int kx022a_chip_init(struct kx022a_data *data)
  		return ret;
 
  	/*
-	 * I've seen I2C read failures if we poll too fast after the sensor
-	 * reset. Slight delay gives I2C block the time to recover.
+	 * According to the power-on procedure documents, there is (at least)
+	 * 2ms delay required after the software reset. This should be same

for

drivers/iio/accel/kionix-kx022a.c +3 -0
+	 * all, KX022ACR-Z, KX132-1211, KX132ACR-LBZ and KX134ACR-LBZ.
+	 *
+	 *

https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 *

https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf

Quoted 8 lines

drivers/iio/accel/kionix-kx022a.c static int kx022a_chip_init(struct kx022a_data *data) · line 1132

Quoted 5 lines
drivers/iio/accel/kionix-kx022a.c +1 -0
+	 *

https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf
  */

drivers/iio/accel/kionix-kx022a.c +1 -1
-	msleep(1);
+	msleep(2);

msleep() is not advisable for something lower than 20ms. Maybe take the opportunity and change it to fsleep()?

Thank you for the suggestion Nuno. I did originally consider using the usleep_range() since the checkpatch knows to warn about msleep with small times.

However, there should be no rush to power-on the sensor at startup. It usually does not matter if the sleep is 2 or 20 milli seconds, as long as it is long enough. I wonder if interrupting the system with hrtimers for _all_ smallish delays (when the longer delay would not really hurt) is a the best design choice. Hence I'd rather keep the msleep when we don't need to guarantee delay to be short instead of defaulting to hrtimers or even busy-loop when it is not required.

Do you think I am mistaken?

Yours,
-- Matti

#3 lore raw
Quoted 68 lines · Matti Vaittinen
Quoted 58 lines · Nuno Sá
Quoted 57 lines · Matti Vaittinen

All the sensors supported by kx022a driver seemed to require some delay after software reset to be operational again. More or less a random msleep(1) was added to cause the driver to go to sleep so the sensor has time to become operational again.

Now we have official docuumentation available:
https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf
https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf
https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf

stating the required time is 2 ms.

Due to the nature of the current msleep implementation, the msleep(1) is likely to be sleeping more than 2ms already - but the value "1" is misleading in case someone needs to optimize the start time and change the msleep to a more accurate delay. Hence it is better for "documentation" purposes to use value which actually reflects the specified 2ms wait time.

Change the value of delay after software reset to match the specifications and add links to the power-on procedure specifications.

---
Sorry for not including this to the KX134ACR-LBZ series I sent yesterday. It was only half an hour after I had sent the KX134ACR-LBZ support when I was notified about the existence of the KX022ACR-Z start-up procedure specification... Hence this lone patch to code which I just sent a miscallaneous series for before.

  drivers/iio/accel/kionix-kx022a.c | 11 ++++++++---

  1 file changed, 8 insertions(+), 3 deletions(-)
drivers/iio/accel/kionix- renamed from drivers/iio/accel/kionix-kx022a.c +0 -0

kx022a.c
index 32387819995d..ccabe2e3b130 100644

drivers/iio/accel/kionix-kx022a.c +0 -0
@@ -1121,10 +1121,15 @@ static int kx022a_chip_init(struct kx022a_data
 *data)
   		return ret;


   /*

drivers/iio/accel/kionix-kx022a.c +0 -1
-	 * I've seen I2C read failures if we poll too fast after the

sensor

drivers/iio/accel/kionix-kx022a.c +1 -1
-	 * reset. Slight delay gives I2C block the time to recover.
+	 * According to the power-on procedure documents, there is (at

least)

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 * 2ms delay required after the software reset. This should be

same
for

drivers/iio/accel/kionix-kx022a.c +3 -0
+	 * all, KX022ACR-Z, KX132-1211, KX132ACR-LBZ and KX134ACR-LBZ.
+	 *
+	 *

https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 *

https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf

Quoted 8 lines

drivers/iio/accel/kionix-kx022a.c static int kx022a_chip_init(struct kx022a_data *data) · line 1132

Quoted 5 lines
drivers/iio/accel/kionix-kx022a.c +1 -0
+	 *

https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf
   */

drivers/iio/accel/kionix-kx022a.c +1 -1
-	msleep(1);
+	msleep(2);

msleep() is not advisable for something lower than 20ms. Maybe take the opportunity and change it to fsleep()?

Quoted 8 lines

Thank you for the suggestion Nuno. I did originally consider using the usleep_range() since the checkpatch knows to warn about msleep with small times.

However, there should be no rush to power-on the sensor at startup. It usually does not matter if the sleep is 2 or 20 milli seconds, as long as it is long enough. I wonder if interrupting the system with hrtimers for _all_ smallish delays (when the longer delay would not really hurt)

That's why you have ranges of about 20% (I think) in usleep() so you minimize hrtimers interrupts.

Other thing is boot time... Sleeping 20ms instead of 2ms is a huge difference. Imagine if everyone thought like this for small sleeps :)?

Quoted 6 lines

is a the best design choice. Hence I'd rather keep the msleep when we don't need to guarantee delay to be short instead of defaulting to hrtimers or even busy-loop when it is not required.

Do you think I am mistaken?

To me this is more about correctness and do what the docs tell us to do :). Sure, here you know what you're doing and you don't care if you end up sleeping more than 2ms but that's not always the case and code like this allows for legit mistakes (if someone just copy paste this for example).

Not a big deal anyways...

- Nuno Sá

author maintainer
#4 lore raw
Quoted 78 lines · Nuno Sá
Quoted 68 lines · Matti Vaittinen
Quoted 58 lines · Nuno Sá
Quoted 57 lines · Matti Vaittinen

All the sensors supported by kx022a driver seemed to require some delay after software reset to be operational again. More or less a random msleep(1) was added to cause the driver to go to sleep so the sensor has time to become operational again.

Now we have official docuumentation available:
https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf
https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf
https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf

stating the required time is 2 ms.

Due to the nature of the current msleep implementation, the msleep(1) is likely to be sleeping more than 2ms already - but the value "1" is misleading in case someone needs to optimize the start time and change the msleep to a more accurate delay. Hence it is better for "documentation" purposes to use value which actually reflects the specified 2ms wait time.

Change the value of delay after software reset to match the specifications and add links to the power-on procedure specifications.

---
Sorry for not including this to the KX134ACR-LBZ series I sent yesterday. It was only half an hour after I had sent the KX134ACR-LBZ support when I was notified about the existence of the KX022ACR-Z start-up procedure specification... Hence this lone patch to code which I just sent a miscallaneous series for before.

   drivers/iio/accel/kionix-kx022a.c | 11 ++++++++---
   1 file changed, 8 insertions(+), 3 deletions(-)
drivers/iio/accel/kionix- renamed from drivers/iio/accel/kionix-kx022a.c +0 -0

kx022a.c
index 32387819995d..ccabe2e3b130 100644

drivers/iio/accel/kionix-kx022a.c +0 -1
@@ -1121,10 +1121,15 @@ static int kx022a_chip_init(struct kx022a_data
 *data)
   		return ret;
 
   	/*
-	 * I've seen I2C read failures if we poll too fast after the

sensor

drivers/iio/accel/kionix-kx022a.c +1 -1
-	 * reset. Slight delay gives I2C block the time to recover.
+	 * According to the power-on procedure documents, there is (at

least)

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 * 2ms delay required after the software reset. This should be

same
for

drivers/iio/accel/kionix-kx022a.c +3 -0
+	 * all, KX022ACR-Z, KX132-1211, KX132ACR-LBZ and KX134ACR-LBZ.
+	 *
+	 *

https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 *

https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf

Quoted 8 lines

drivers/iio/accel/kionix-kx022a.c static int kx022a_chip_init(struct kx022a_data *data) · line 1132

Quoted 5 lines
drivers/iio/accel/kionix-kx022a.c +1 -0
+	 *

https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf
   */

drivers/iio/accel/kionix-kx022a.c +1 -1
-	msleep(1);
+	msleep(2);

msleep() is not advisable for something lower than 20ms. Maybe take the opportunity and change it to fsleep()?

Quoted 8 lines

Thank you for the suggestion Nuno. I did originally consider using the usleep_range() since the checkpatch knows to warn about msleep with small times.

However, there should be no rush to power-on the sensor at startup. It usually does not matter if the sleep is 2 or 20 milli seconds, as long as it is long enough. I wonder if interrupting the system with hrtimers for _all_ smallish delays (when the longer delay would not really hurt)

Quoted 5 lines

That's why you have ranges of about 20% (I think) in usleep() so you minimize hrtimers interrupts.

Other thing is boot time... Sleeping 20ms instead of 2ms is a huge difference. Imagine if everyone thought like this for small sleeps :)?

I think this is interesting question. My thoughts were along the line that, even if small sleeps were extended to longer (where small sleep is not a priority), the CPUs would still (especially during the boot up) have their hands full. I don't know if we might indeed end up a situation where CPUs were idling, waiting for next timer slot.

What comes to boot time, I doubt the CPUs run out of things to do, especially when we use the probe_type = PROBE_PREFER_ASYNCHRONOUS.

Quoted 11 lines
Quoted 6 lines

is a the best design choice. Hence I'd rather keep the msleep when we don't need to guarantee delay to be short instead of defaulting to hrtimers or even busy-loop when it is not required.

Do you think I am mistaken?

To me this is more about correctness and do what the docs tell us to do :). Sure, here you know what you're doing and you don't care if you end up sleeping more than 2ms but that's not always the case and code like this allows for legit mistakes (if someone just copy paste this for example).

Right. I just wonder if always requiring stricter wake-up instead of allowing things to run uninterrupted is the best role model either?

Quoted 1 line

Not a big deal anyways...

Agree :) But I think this is a spot where I could learn a bit. I will gladly switch to the fsleep() if someone explains me relying on hrtimers should be preferred also when there is no real need to wake up quicker than msleep() allows.

Thanks for the discussion!

Yours,
-- Matti

#5 lore raw
Quoted 95 lines · Matti Vaittinen
Quoted 86 lines · Nuno Sá
Quoted 76 lines · Matti Vaittinen
Quoted 66 lines · Nuno Sá
Quoted 65 lines · Matti Vaittinen

All the sensors supported by kx022a driver seemed to require some delay
after software reset to be operational again. More or less a random msleep(1) was added to cause the driver to go to sleep so the sensor has
time to become operational again.

Now we have official docuumentation available:
https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf
https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf
https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf

stating the required time is 2 ms.

Due to the nature of the current msleep implementation, the msleep(1) is
likely to be sleeping more than 2ms already - but the value "1" is misleading in case someone needs to optimize the start time and change the msleep to a more accurate delay. Hence it is better for "documentation" purposes to use value which actually reflects the specified 2ms wait time.

Change the value of delay after software reset to match the specifications and add links to the power-on procedure specifications.

---
Sorry for not including this to the KX134ACR-LBZ series I sent yesterday. It was only half an hour after I had sent the KX134ACR-LBZ support when I was notified about the existence of the KX022ACR-Z start-up procedure specification... Hence this lone patch to code which
I just sent a miscallaneous series for before.

   drivers/iio/accel/kionix-kx022a.c | 11 ++++++++---

   1 file changed, 8 insertions(+), 3 deletions(-)
drivers/iio/accel/kionix- renamed from drivers/iio/accel/kionix-kx022a.c +0 -0

kx022a.c
index 32387819995d..ccabe2e3b130 100644

drivers/iio/accel/kionix-kx022a.c +0 -0
@@ -1121,10 +1121,15 @@ static int kx022a_chip_init(struct kx022a_data
 *data)
    		return ret;


    /*

drivers/iio/accel/kionix-kx022a.c +0 -1
-	 * I've seen I2C read failures if we poll too fast after the

sensor

drivers/iio/accel/kionix-kx022a.c +1 -1
-	 * reset. Slight delay gives I2C block the time to recover.
+	 * According to the power-on procedure documents, there is

(at
least)

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 * 2ms delay required after the software reset. This should

be
same
for

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 * all, KX022ACR-Z, KX132-1211, KX132ACR-LBZ and KX134ACR-

LBZ.

drivers/iio/accel/kionix-kx022a.c +2 -0
+	 *
+	 *

https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 *

https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf

Quoted 8 lines

drivers/iio/accel/kionix-kx022a.c static int kx022a_chip_init(struct kx022a_data *data) · line 1132

Quoted 5 lines
drivers/iio/accel/kionix-kx022a.c +1 -0
+	 *

https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf
    */

drivers/iio/accel/kionix-kx022a.c +1 -1
-	msleep(1);
+	msleep(2);

msleep() is not advisable for something lower than 20ms. Maybe take the opportunity and change it to fsleep()?

Quoted 8 lines

Thank you for the suggestion Nuno. I did originally consider using the usleep_range() since the checkpatch knows to warn about msleep with small times.

However, there should be no rush to power-on the sensor at startup. It usually does not matter if the sleep is 2 or 20 milli seconds, as long as it is long enough. I wonder if interrupting the system with hrtimers for _all_ smallish delays (when the longer delay would not really hurt)

Quoted 7 lines

That's why you have ranges of about 20% (I think) in usleep() so you minimize
hrtimers interrupts.

Other thing is boot time... Sleeping 20ms instead of 2ms is a huge difference.
Imagine if everyone thought like this for small sleeps :)?

Quoted 5 lines

I think this is interesting question. My thoughts were along the line that, even if small sleeps were extended to longer (where small sleep is not a priority), the CPUs would still (especially during the boot up) have their hands full. I don't know if we might indeed end up a situation where CPUs were idling, waiting for next timer slot.

My problem is not the CPU but delaying probing devices as you probe one device at time...

Quoted 3 lines

What comes to boot time, I doubt the CPUs run out of things to do, especially when we use the probe_type = PROBE_PREFER_ASYNCHRONOUS.

Yeah, with this, the above does not apply. Still, spending more time in a worker than needed (and 18ms is huge) seems a waste to me.

Quoted 16 lines
Quoted 9 lines
Quoted 8 lines

is a the best design choice. Hence I'd rather keep the msleep when we don't need to guarantee delay to be short instead of defaulting to hrtimers or even busy-loop when it is not required.

Do you think I am mistaken?

Quoted 6 lines

To me this is more about correctness and do what the docs tell us to do :). Sure, here you know what you're doing and you don't care if you end up sleeping
more than 2ms but that's not always the case and code like this allows for legit
mistakes (if someone just copy paste this for example).

Quoted 2 lines

Right. I just wonder if always requiring stricter wake-up instead of allowing things to run uninterrupted is the best role model either?

Why not :)? If we just need to wait 2ms, why waiting more? I would be very surprised if hrtimers are a deal breaker in here. Otherwise, we should remove it from the docs...

Quoted 8 lines
Quoted 2 lines

Not a big deal anyways...

Agree :) But I think this is a spot where I could learn a bit. I will gladly switch to the fsleep() if someone explains me relying on hrtimers should be preferred also when there is no real need to wake up quicker than msleep() allows.

Personally, I think that sleeping more than needed is always a wast and then it comes back to my correctness comment. In here you know what you're doing but I dunno that switching to hrtimers will do any arm to the device :) and allows proper patterns to be copied.

- Nuno Sá

author maintainer
#6 lore raw
Quoted 106 lines · Nuno Sá
Quoted 95 lines · Matti Vaittinen
Quoted 86 lines · Nuno Sá
Quoted 76 lines · Matti Vaittinen
Quoted 66 lines · Nuno Sá
Quoted 65 lines · Matti Vaittinen

All the sensors supported by kx022a driver seemed to require some delay
after software reset to be operational again. More or less a random msleep(1) was added to cause the driver to go to sleep so the sensor has
time to become operational again.

Now we have official docuumentation available:
https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf
https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf
https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf

stating the required time is 2 ms.

Due to the nature of the current msleep implementation, the msleep(1) is
likely to be sleeping more than 2ms already - but the value "1" is misleading in case someone needs to optimize the start time and change the msleep to a more accurate delay. Hence it is better for "documentation" purposes to use value which actually reflects the specified 2ms wait time.

Change the value of delay after software reset to match the specifications and add links to the power-on procedure specifications.

---
Sorry for not including this to the KX134ACR-LBZ series I sent yesterday. It was only half an hour after I had sent the KX134ACR-LBZ support when I was notified about the existence of the KX022ACR-Z start-up procedure specification... Hence this lone patch to code which
I just sent a miscallaneous series for before.

    drivers/iio/accel/kionix-kx022a.c | 11 ++++++++---
    1 file changed, 8 insertions(+), 3 deletions(-)
drivers/iio/accel/kionix- renamed from drivers/iio/accel/kionix-kx022a.c +0 -0

kx022a.c
index 32387819995d..ccabe2e3b130 100644

drivers/iio/accel/kionix-kx022a.c +0 -1
@@ -1121,10 +1121,15 @@ static int kx022a_chip_init(struct kx022a_data
 *data)
    		return ret;
 
    	/*
-	 * I've seen I2C read failures if we poll too fast after the

sensor

drivers/iio/accel/kionix-kx022a.c +1 -1
-	 * reset. Slight delay gives I2C block the time to recover.
+	 * According to the power-on procedure documents, there is

(at
least)

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 * 2ms delay required after the software reset. This should

be
same
for

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 * all, KX022ACR-Z, KX132-1211, KX132ACR-LBZ and KX134ACR-

LBZ.

drivers/iio/accel/kionix-kx022a.c +2 -0
+	 *
+	 *

https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 *

https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf

Quoted 8 lines

drivers/iio/accel/kionix-kx022a.c static int kx022a_chip_init(struct kx022a_data *data) · line 1132

Quoted 5 lines
drivers/iio/accel/kionix-kx022a.c +1 -0
+	 *

https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf
    */

drivers/iio/accel/kionix-kx022a.c +1 -1
-	msleep(1);
+	msleep(2);

msleep() is not advisable for something lower than 20ms. Maybe take the opportunity and change it to fsleep()?

Quoted 8 lines

Thank you for the suggestion Nuno. I did originally consider using the usleep_range() since the checkpatch knows to warn about msleep with small times.

However, there should be no rush to power-on the sensor at startup. It usually does not matter if the sleep is 2 or 20 milli seconds, as long as it is long enough. I wonder if interrupting the system with hrtimers for _all_ smallish delays (when the longer delay would not really hurt)

Quoted 7 lines

That's why you have ranges of about 20% (I think) in usleep() so you minimize
hrtimers interrupts.

Other thing is boot time... Sleeping 20ms instead of 2ms is a huge difference.
Imagine if everyone thought like this for small sleeps :)?

Quoted 5 lines

I think this is interesting question. My thoughts were along the line that, even if small sleeps were extended to longer (where small sleep is not a priority), the CPUs would still (especially during the boot up) have their hands full. I don't know if we might indeed end up a situation where CPUs were idling, waiting for next timer slot.

My problem is not the CPU but delaying probing devices as you probe one device at time...

Quoted 1 line
Quoted 5 lines
Quoted 2 lines

What comes to boot time, I doubt the CPUs run out of things to do, especially when we use the probe_type = PROBE_PREFER_ASYNCHRONOUS.

Yeah, with this, the above does not apply. Still, spending more time in a worker than needed (and 18ms is huge) seems a waste to me.

This is likely to be my ignorance, but I don't know what is wasted here. (genuine question, not trying to be a smart-ass).

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 6 lines

is a the best design choice. Hence I'd rather keep the msleep when we don't need to guarantee delay to be short instead of defaulting to hrtimers or even busy-loop when it is not required.

Do you think I am mistaken?

To me this is more about correctness and do what the docs tell us to do :). Sure, here you know what you're doing and you don't care if you end up sleeping
more than 2ms but that's not always the case and code like this allows for legit
mistakes (if someone just copy paste this for example).

Quoted 6 lines
Quoted 2 lines

Right. I just wonder if always requiring stricter wake-up instead of allowing things to run uninterrupted is the best role model either?

Why not :)? If we just need to wait 2ms, why waiting more? I would be very surprised if hrtimers are a deal breaker in here. Otherwise, we should remove it from the docs...

Again I may be wrong, but I think each of the interrupts we add, require tiny bit of handling - which I thought is more of a waste than sleeping.

I admit this is all hand-waving as I have no test data to back up my pondering. And, I believe you are right that this surely is not a deal breaker - but neither do I see adding more interrupts (when not really needed) as a good design.

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

Not a big deal anyways...

Agree :) But I think this is a spot where I could learn a bit. I will gladly switch to the fsleep() if someone explains me relying on hrtimers should be preferred also when there is no real need to wake up quicker than msleep() allows.

Quoted 4 lines

Personally, I think that sleeping more than needed is always a wast and then it comes back to my correctness comment. In here you know what you're doing but I dunno that switching to hrtimers will do any arm to the device :) and allows proper patterns to be copied.

I have been thinking that handling the (hrtimer) interrupts generates more overhead (waste) than sleeping.

By the way, thanks for the reviewing work Nuno! :) I appreciate it.

Yours,
-- Matti

#7 lore raw
Quoted 126 lines · Matti Vaittinen
Quoted 125 lines · Nuno Sá
Quoted 110 lines · Matti Vaittinen
Quoted 101 lines · Nuno Sá
Quoted 93 lines · Matti Vaittinen
Quoted 79 lines · Nuno Sá
Quoted 78 lines · Matti Vaittinen

All the sensors supported by kx022a driver seemed to require some delay
after software reset to be operational again. More or less a random
msleep(1) was added to cause the driver to go to sleep so the sensor
has
time to become operational again.

Now we have official docuumentation available:
https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf
https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf
https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf

stating the required time is 2 ms.

Due to the nature of the current msleep implementation, the msleep(1)
is
likely to be sleeping more than 2ms already - but the value "1" is misleading in case someone needs to optimize the start time and change
the msleep to a more accurate delay. Hence it is better for "documentation" purposes to use value which actually reflects the specified 2ms wait time.

Change the value of delay after software reset to match the specifications and add links to the power-on procedure specifications.

---
Sorry for not including this to the KX134ACR-LBZ series I sent yesterday. It was only half an hour after I had sent the KX134ACR- LBZ
support when I was notified about the existence of the KX022ACR-Z start-up procedure specification... Hence this lone patch to code which
I just sent a miscallaneous series for before.

    drivers/iio/accel/kionix-kx022a.c | 11 ++++++++---

    1 file changed, 8 insertions(+), 3 deletions(-)
drivers/iio/accel/kionix- renamed from drivers/iio/accel/kionix-kx022a.c +0 -0

kx022a.c
index 32387819995d..ccabe2e3b130 100644

drivers/iio/accel/kionix-kx022a.c +0 -0
@@ -1121,10 +1121,15 @@ static int kx022a_chip_init(struct

kx022a_data
*data)
     return ret;

     /*

drivers/iio/accel/kionix-kx022a.c +0 -1
-	 * I've seen I2C read failures if we poll too fast after

the
sensor

drivers/iio/accel/kionix-kx022a.c +0 -1
-	 * reset. Slight delay gives I2C block the time to

recover.

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 * According to the power-on procedure documents, there

is
(at
least)

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 * 2ms delay required after the software reset. This

should
be
same
for

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 * all, KX022ACR-Z, KX132-1211, KX132ACR-LBZ and

KX134ACR-
LBZ.

drivers/iio/accel/kionix-kx022a.c +2 -0
+	 *
+	 *

https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 *

https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 *
Quoted 8 lines

drivers/iio/accel/kionix-kx022a.c

Quoted 4 lines

https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf
     */

drivers/iio/accel/kionix-kx022a.c +1 -1
-	msleep(1);
+	msleep(2);

msleep() is not advisable for something lower than 20ms. Maybe take the
opportunity and change it to fsleep()?

Thank you for the suggestion Nuno. I did originally consider using the usleep_range() since the checkpatch knows to warn about msleep with small times.

Quoted 6 lines

However, there should be no rush to power-on the sensor at startup. It usually does not matter if the sleep is 2 or 20 milli seconds, as long as it is long enough. I wonder if interrupting the system with hrtimers
for _all_ smallish delays (when the longer delay would not really hurt)

Quoted 7 lines

That's why you have ranges of about 20% (I think) in usleep() so you minimize
hrtimers interrupts.

Other thing is boot time... Sleeping 20ms instead of 2ms is a huge difference.
Imagine if everyone thought like this for small sleeps :)?

Quoted 5 lines

I think this is interesting question. My thoughts were along the line that, even if small sleeps were extended to longer (where small sleep is not a priority), the CPUs would still (especially during the boot up) have their hands full. I don't know if we might indeed end up a situation where CPUs were idling, waiting for next timer slot.

My problem is not the CPU but delaying probing devices as you probe one device
at time...

Quoted 3 lines

What comes to boot time, I doubt the CPUs run out of things to do, especially when we use the probe_type = PROBE_PREFER_ASYNCHRONOUS.

Quoted 6 lines
Quoted 3 lines

Yeah, with this, the above does not apply. Still, spending more time in a worker
than needed (and 18ms is huge) seems a waste to me.

This is likely to be my ignorance, but I don't know what is wasted here. (genuine question, not trying to be a smart-ass).

Well, AFAIK, async probing is using the async.c API which is based on workers. If you spend (worst case scenario) 18ms more than you need in the handler (and 18ms is __huge__), it means that worker can't go on and do some other useful stuff, right?

Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 8 lines
Quoted 7 lines

is a the best design choice. Hence I'd rather keep the msleep when we don't need to guarantee delay to be short instead of defaulting to hrtimers or even busy-loop when it is not required.

Do you think I am mistaken?

Quoted 8 lines

To me this is more about correctness and do what the docs tell us to do :).
Sure, here you know what you're doing and you don't care if you end up sleeping
more than 2ms but that's not always the case and code like this allows for
legit
mistakes (if someone just copy paste this for example).

Right. I just wonder if always requiring stricter wake-up instead of allowing things to run uninterrupted is the best role model either?

Quoted 8 lines
Quoted 4 lines

Why not :)? If we just need to wait 2ms, why waiting more? I would be very surprised if hrtimers are a deal breaker in here. Otherwise, we should remove it
from the docs...

Again I may be wrong, but I think each of the interrupts we add, require tiny bit of handling - which I thought is more of a waste than sleeping.

Not that it's even every likely that you're not adding a new interrupt necessarily. That's the point of the range in usleep(). So that multiple handlers can be done in one interrupt.

Quoted 20 lines

I admit this is all hand-waving as I have no test data to back up my pondering. And, I believe you are right that this surely is not a deal breaker - but neither do I see adding more interrupts (when not really needed) as a good design.

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

Not a big deal anyways...

Agree :) But I think this is a spot where I could learn a bit. I will gladly switch to the fsleep() if someone explains me relying on hrtimers should be preferred also when there is no real need to wake up quicker than msleep() allows.

Quoted 6 lines

Personally, I think that sleeping more than needed is always a wast and then it
comes back to my correctness comment. In here you know what you're doing but I
dunno that switching to hrtimers will do any arm to the device :) and allows proper patterns to be copied.

Quoted 3 lines

I have been thinking that handling the (hrtimer) interrupts generates more overhead (waste) than sleeping.

Put it this way... if that was true, I would assume it would be somewhere described in the sleeping docs. More, I don't think the rule of thumb would be to use hrtirmers for things < 20ms.

- Nuno Sá

author maintainer
#8 lore raw
Quoted 127 lines · Nuno Sá
Quoted 126 lines · Matti Vaittinen
Quoted 125 lines · Nuno Sá
Quoted 110 lines · Matti Vaittinen
Quoted 101 lines · Nuno Sá
Quoted 93 lines · Matti Vaittinen
Quoted 79 lines · Nuno Sá
Quoted 78 lines · Matti Vaittinen

All the sensors supported by kx022a driver seemed to require some delay
after software reset to be operational again. More or less a random
msleep(1) was added to cause the driver to go to sleep so the sensor
has
time to become operational again.

Now we have official docuumentation available:
https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf
https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf
https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf

stating the required time is 2 ms.

Due to the nature of the current msleep implementation, the msleep(1)
is
likely to be sleeping more than 2ms already - but the value "1" is misleading in case someone needs to optimize the start time and change
the msleep to a more accurate delay. Hence it is better for "documentation" purposes to use value which actually reflects the specified 2ms wait time.

Change the value of delay after software reset to match the specifications and add links to the power-on procedure specifications.

---
Sorry for not including this to the KX134ACR-LBZ series I sent yesterday. It was only half an hour after I had sent the KX134ACR- LBZ
support when I was notified about the existence of the KX022ACR-Z start-up procedure specification... Hence this lone patch to code which
I just sent a miscallaneous series for before.

     drivers/iio/accel/kionix-kx022a.c | 11 ++++++++---
     1 file changed, 8 insertions(+), 3 deletions(-)
drivers/iio/accel/kionix- renamed from drivers/iio/accel/kionix-kx022a.c +0 -0

kx022a.c
index 32387819995d..ccabe2e3b130 100644

drivers/iio/accel/kionix-kx022a.c +0 -0
@@ -1121,10 +1121,15 @@ static int kx022a_chip_init(struct

kx022a_data
*data)
     return ret;

     /*

drivers/iio/accel/kionix-kx022a.c +0 -1
-	 * I've seen I2C read failures if we poll too fast after

the
sensor

drivers/iio/accel/kionix-kx022a.c +0 -1
-	 * reset. Slight delay gives I2C block the time to

recover.

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 * According to the power-on procedure documents, there

is
(at
least)

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 * 2ms delay required after the software reset. This

should
be
same
for

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 * all, KX022ACR-Z, KX132-1211, KX132ACR-LBZ and

KX134ACR-
LBZ.

drivers/iio/accel/kionix-kx022a.c +2 -0
+	 *
+	 *

https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 *

https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 *
Quoted 8 lines

drivers/iio/accel/kionix-kx022a.c

Quoted 4 lines

https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf
     */

drivers/iio/accel/kionix-kx022a.c +1 -1
-	msleep(1);
+	msleep(2);

msleep() is not advisable for something lower than 20ms. Maybe take the
opportunity and change it to fsleep()?

Thank you for the suggestion Nuno. I did originally consider using the usleep_range() since the checkpatch knows to warn about msleep with small times.

Quoted 6 lines

However, there should be no rush to power-on the sensor at startup. It usually does not matter if the sleep is 2 or 20 milli seconds, as long as it is long enough. I wonder if interrupting the system with hrtimers
for _all_ smallish delays (when the longer delay would not really hurt)

Quoted 7 lines

That's why you have ranges of about 20% (I think) in usleep() so you minimize
hrtimers interrupts.

Other thing is boot time... Sleeping 20ms instead of 2ms is a huge difference.
Imagine if everyone thought like this for small sleeps :)?

Quoted 5 lines

I think this is interesting question. My thoughts were along the line that, even if small sleeps were extended to longer (where small sleep is not a priority), the CPUs would still (especially during the boot up) have their hands full. I don't know if we might indeed end up a situation where CPUs were idling, waiting for next timer slot.

My problem is not the CPU but delaying probing devices as you probe one device
at time...

Quoted 3 lines

What comes to boot time, I doubt the CPUs run out of things to do, especially when we use the probe_type = PROBE_PREFER_ASYNCHRONOUS.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Yeah, with this, the above does not apply. Still, spending more time in a worker
than needed (and 18ms is huge) seems a waste to me.

This is likely to be my ignorance, but I don't know what is wasted here. (genuine question, not trying to be a smart-ass).

Well, AFAIK, async probing is using the async.c API which is based on workers.

Yes.

Quoted 3 lines

If you spend (worst case scenario) 18ms more than you need in the handler (and 18ms is __huge__), it means that worker can't go on and do some other useful stuff, right?

I thought there can be more than one concurrent active work items? It would be surprizing to me if aynchronous probe would block other probes. Please, let me know if this is the case.

Quoted 24 lines
Quoted 24 lines
Quoted 23 lines
Quoted 16 lines
Quoted 7 lines
Quoted 6 lines

is a the best design choice. Hence I'd rather keep the msleep when we don't need to guarantee delay to be short instead of defaulting to hrtimers or even busy-loop when it is not required.

Do you think I am mistaken?

Quoted 8 lines

To me this is more about correctness and do what the docs tell us to do :).
Sure, here you know what you're doing and you don't care if you end up sleeping
more than 2ms but that's not always the case and code like this allows for
legit
mistakes (if someone just copy paste this for example).

Quoted 2 lines

Right. I just wonder if always requiring stricter wake-up instead of allowing things to run uninterrupted is the best role model either?

Why not :)? If we just need to wait 2ms, why waiting more? I would be very surprised if hrtimers are a deal breaker in here. Otherwise, we should remove it
from the docs...

Quoted 7 lines
Quoted 3 lines

Again I may be wrong, but I think each of the interrupts we add, require tiny bit of handling - which I thought is more of a waste than sleeping.

Not that it's even every likely that you're not adding a new interrupt necessarily. That's the point of the range in usleep(). So that multiple handlers can be done in one interrupt.

This could be true. Especially if every other "thing" which needs some delay (but has no strict lower limit) defaults to hrtimers.

Quoted 3 lines

Put it this way... if that was true, I would assume it would be somewhere described in the sleeping docs. More, I don't think the rule of thumb would be to use hrtirmers for things < 20ms.

This is exactly why I questioned the rule-of-thumb. I deeply dislike "rules of thumb" - when I don't understand the rationale. If we assume hrtimers came without a cost, then we should have no need for msleep() at all, right?

Everything I read suggests the msleep() is actually lighter (but with the downside it can't guarantee short timeouts). Hence I have preferred it when short timeout does _not_ need to be guaranteed. (I still very much understand the checkpatch warn because one might very well assume msleep() could be used to sleep 1 ms).

After all this discussing, I don't really see point of switching to fsleep() - unless delaying of the (asynchronous) probe proves to be a real problem. If it does, then my assumption that the short timeout does not need to be guaranteed is false and this should be changed.

Thanks for the insight :)

Yours,
-- Matti

#9 lore raw
Quoted 156 lines · Matti Vaittinen
Quoted 147 lines · Nuno Sá
Quoted 146 lines · Matti Vaittinen
Quoted 144 lines · Nuno Sá
Quoted 124 lines · Matti Vaittinen
Quoted 115 lines · Nuno Sá
Quoted 105 lines · Matti Vaittinen
Quoted 89 lines · Nuno Sá
Quoted 88 lines · Matti Vaittinen

All the sensors supported by kx022a driver seemed to require some
delay
after software reset to be operational again. More or less a random
msleep(1) was added to cause the driver to go to sleep so the sensor
has
time to become operational again.

Now we have official docuumentation available:
https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf
https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf
https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf

stating the required time is 2 ms.

Due to the nature of the current msleep implementation, the msleep(1)
is
likely to be sleeping more than 2ms already - but the value "1" is
misleading in case someone needs to optimize the start time and
change
the msleep to a more accurate delay. Hence it is better for "documentation" purposes to use value which actually reflects the
specified 2ms wait time.

Change the value of delay after software reset to match the specifications and add links to the power-on procedure specifications.

---
Sorry for not including this to the KX134ACR-LBZ series I sent yesterday. It was only half an hour after I had sent the KX134ACR-
LBZ
support when I was notified about the existence of the KX022ACR-Z
start-up procedure specification... Hence this lone patch to code
which
I just sent a miscallaneous series for before.

     drivers/iio/accel/kionix-kx022a.c | 11 ++++++++---

     1 file changed, 8 insertions(+), 3 deletions(-)
drivers/iio/accel/kionix- renamed from drivers/iio/accel/kionix-kx022a.c +0 -0

kx022a.c
index 32387819995d..ccabe2e3b130 100644

drivers/iio/accel/kionix-kx022a.c +0 -0
@@ -1121,10 +1121,15 @@ static int kx022a_chip_init(struct

kx022a_data
*data)
      return ret;

      /*

drivers/iio/accel/kionix-kx022a.c +0 -1
-	 * I've seen I2C read failures if we poll too fast

after
the
sensor

drivers/iio/accel/kionix-kx022a.c +0 -1
-	 * reset. Slight delay gives I2C block the time to

recover.

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 * According to the power-on procedure documents,

there
is
(at
least)

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 * 2ms delay required after the software reset. This

should
be
same
for

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 * all, KX022ACR-Z, KX132-1211, KX132ACR-LBZ and

KX134ACR-
LBZ.

drivers/iio/accel/kionix-kx022a.c +2 -0
+	 *
+	 *

https://fscdn.rohm.com/kionix/en/document/AN010_KX022ACR-Z_Power-on_Procedure_E.pdf

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 *

https://fscdn.rohm.com/kionix/en/document/TN027-Power-On-Procedure.pdf

drivers/iio/accel/kionix-kx022a.c +1 -0
+	 *

https://fscdn.rohm.com/kionix/en/document/AN011_KX134ACR-LBZ_Power-on_Procedure_E.pdf

Quoted 8 lines

drivers/iio/accel/kionix-kx022a.c

Quoted 3 lines

      */

drivers/iio/accel/kionix-kx022a.c +1 -1
-	msleep(1);
+	msleep(2);

msleep() is not advisable for something lower than 20ms. Maybe take
the
opportunity and change it to fsleep()?

Thank you for the suggestion Nuno. I did originally consider using the
usleep_range() since the checkpatch knows to warn about msleep with
small times.

Quoted 8 lines

However, there should be no rush to power-on the sensor at startup. It
usually does not matter if the sleep is 2 or 20 milli seconds, as long
as it is long enough. I wonder if interrupting the system with hrtimers
for _all_ smallish delays (when the longer delay would not really hurt)

Quoted 7 lines

That's why you have ranges of about 20% (I think) in usleep() so you minimize
hrtimers interrupts.

Other thing is boot time... Sleeping 20ms instead of 2ms is a huge difference.
Imagine if everyone thought like this for small sleeps :)?

Quoted 6 lines

I think this is interesting question. My thoughts were along the line that, even if small sleeps were extended to longer (where small sleep is
not a priority), the CPUs would still (especially during the boot up) have their hands full. I don't know if we might indeed end up a situation where CPUs were idling, waiting for next timer slot.

My problem is not the CPU but delaying probing devices as you probe one device
at time...

Quoted 3 lines

What comes to boot time, I doubt the CPUs run out of things to do, especially when we use the probe_type = PROBE_PREFER_ASYNCHRONOUS.

Yeah, with this, the above does not apply. Still, spending more time in a
worker
than needed (and 18ms is huge) seems a waste to me.

Quoted 5 lines
Quoted 2 lines

This is likely to be my ignorance, but I don't know what is wasted here. (genuine question, not trying to be a smart-ass).

Well, AFAIK, async probing is using the async.c API which is based on workers.

Yes.

Quoted 8 lines
Quoted 4 lines

If you spend (worst case scenario) 18ms more than you need in the handler (and
18ms is __huge__), it means that worker can't go on and do some other useful stuff, right?

I thought there can be more than one concurrent active work items? It would be surprizing to me if aynchronous probe would block other probes. Please, let me know if this is the case.

Not my point... Naturally it won't as every async schedule has it's own worker. Still a waste of time having a thread sleeping just because.

Quoted 46 lines
Quoted 30 lines
Quoted 30 lines
Quoted 29 lines
Quoted 21 lines
Quoted 9 lines
Quoted 8 lines

is a the best design choice. Hence I'd rather keep the msleep when we
don't need to guarantee delay to be short instead of defaulting to hrtimers or even busy-loop when it is not required.

Do you think I am mistaken?

Quoted 11 lines

To me this is more about correctness and do what the docs tell us to do
:).
Sure, here you know what you're doing and you don't care if you end up
sleeping
more than 2ms but that's not always the case and code like this allows
for
legit
mistakes (if someone just copy paste this for example).

Quoted 2 lines

Right. I just wonder if always requiring stricter wake-up instead of allowing things to run uninterrupted is the best role model either?

Why not :)? If we just need to wait 2ms, why waiting more? I would be very
surprised if hrtimers are a deal breaker in here. Otherwise, we should remove it
from the docs...

Quoted 7 lines
Quoted 3 lines

Again I may be wrong, but I think each of the interrupts we add, require tiny bit of handling - which I thought is more of a waste than sleeping.

Not that it's even every likely that you're not adding a new interrupt necessarily. That's the point of the range in usleep(). So that multiple handlers can be done in one interrupt.

This could be true. Especially if every other "thing" which needs some delay (but has no strict lower limit) defaults to hrtimers.

Quoted 4 lines

Put it this way... if that was true, I would assume it would be somewhere described in the sleeping docs. More, I don't think the rule of thumb would be
to use hrtirmers for things < 20ms.

Quoted 5 lines

This is exactly why I questioned the rule-of-thumb. I deeply dislike "rules of thumb" - when I don't understand the rationale. If we assume hrtimers came without a cost, then we should have no need for msleep() at all, right?

Well that can very well be just because hrtimers came after and no one really cares about changing all of the existing msleep() and friends.

Quoted 5 lines

Everything I read suggests the msleep() is actually lighter (but with the downside it can't guarantee short timeouts). Hence I have preferred it when short timeout does _not_ need to be guaranteed. (I still very much understand the checkpatch warn because one might very well assume msleep() could be used to sleep 1 ms).

Depends on the perspective. If you end up sleeping 18ms more than needed and adding the fact that your handler might not even need any extra IRQ...

Quoted 6 lines

After all this discussing, I don't really see point of switching to fsleep() - unless delaying of the (asynchronous) probe proves to be a real problem. If it does, then my assumption that the short timeout does not need to be guaranteed is false and this should be changed.

Sure and I was doing a suggestion anyways. I feel we're bikeshedding now so let's agree on disagree :)

- Nuno Sá