Skip to contentSkip to conversation

drivers: libata-core: Use usleep_range() instead of msleep() for short sleeps (<20 ms)

PATCH Applied Daniel Walker 2 participants 2 messages Jan 8, 2016 libata

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 drivers: libata-core: Use usleep_range() instead of msleep() for short sleeps (<20 ms)

From: Anil Veliyankara Madam <[email protected]>

Since msleep() may sleep longer than intended time for values less than 20ms, this patch allows the use of usleep_range for waits less that 20ms. usleep_range is a finer precision implementation of msleep and is designed to be a drop-in replacement for udelay where a precise sleep/busy-wait is unnecessary.

More details can be found at http://lkml.org/lkml/2007/8/3/250
and in Documentation/timers/timers-howto.txt.

This change has been done to improve the performace in PIO6 mode which is used by viking flash.

---
 drivers/ata/libata-core.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/ata/libata-core.c +7 -1
index b79cb10..3abf0ea 100644
@@ -50,6 +50,7 @@
 #include <linux/blkdev.h>
 #include <linux/delay.h>
 #include <linux/timer.h>
+#include <linux/time.h>
 #include <linux/interrupt.h>
 #include <linux/completion.h>
 #include <linux/suspend.h>
@@ -6697,7 +6698,12 @@ void ata_msleep(struct ata_port *ap, unsigned int msecs)
 	if (owns_eh)
 		ata_eh_release(ap);
 
-	msleep(msecs);
+	if (msecs < 20) {
+		unsigned long usecs = msecs * USEC_PER_MSEC;
+		usleep_range(usecs, usecs + 50);
+	} else {
+		msleep(msecs);
+	}
 
 	if (owns_eh)
 		ata_eh_acquire(ap);
Signature · 1 line
2.1.4
Applied
#1 lore raw
Quoted 11 lines · Daniel Walker

From: Anil Veliyankara Madam <[email protected]>

Since msleep() may sleep longer than intended time for values less than 20ms, this patch allows the use of usleep_range for waits less that 20ms. usleep_range is a finer precision implementation of msleep and is designed to be a drop-in replacement for udelay where a precise sleep/busy-wait is unnecessary.

More details can be found at http://lkml.org/lkml/2007/8/3/250
and in Documentation/timers/timers-howto.txt.

Quoted 6 lines

This change has been done to improve the performace in PIO6 mode which is used by viking flash.

Applied to libata/for-4.5.

Thanks.

Signature · 1 line
tejun