All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Input: joystick: gf2k - change msleep to usleep_range for small msecs
@ 2016-11-28 19:41 Aniroop Mathur
  2016-11-29  6:51 ` Vojtech Pavlik
  0 siblings, 1 reply; 2+ messages in thread
From: Aniroop Mathur @ 2016-11-28 19:41 UTC (permalink / raw)
  To: vojtech, dmitry.torokhov, linux-input, linux-kernel
  Cc: s.samuel, r.mahale, aniroop.mathur, 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, connection time, probe time,
loops, retry logic, etc
msleep is built on jiffies / legacy timers which are not precise whereas
usleep_range is build on top of hrtimers so the wakeups are precise.
Thus, change msleep to usleep_range for precise wakeups.

For example:
On a machine with tick rate / HZ as 100, msleep(4) will make the process to
sleep for a minimum period of 10 ms whereas usleep_range(4000, 4100) will make
sure that the process does not sleep for more than 4100 us or 4.1ms

Signed-off-by: Aniroop Mathur <a.mathur@samsung.com>
---
 drivers/input/joystick/gf2k.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/input/joystick/gf2k.c b/drivers/input/joystick/gf2k.c
index 0f519db..e9d5095 100644
--- a/drivers/input/joystick/gf2k.c
+++ b/drivers/input/joystick/gf2k.c
@@ -42,7 +42,7 @@ MODULE_LICENSE("GPL");
 
 #define GF2K_START		400	/* The time we wait for the first bit [400 us] */
 #define GF2K_STROBE		40	/* The time we wait for the first bit [40 us] */
-#define GF2K_TIMEOUT		4	/* Wait for everything to settle [4 ms] */
+#define GF2K_TIMEOUT		4000	/* Wait for everything to settle [4000 us] */
 #define GF2K_LENGTH		80	/* Max number of triplets in a packet */
 
 /*
@@ -138,7 +138,7 @@ static void gf2k_trigger_seq(struct gameport *gameport, short *seq)
 	i = 0;
         do {
 		gameport_trigger(gameport);
-		t = gameport_time(gameport, GF2K_TIMEOUT * 1000);
+		t = gameport_time(gameport, GF2K_TIMEOUT);
 		while ((gameport_read(gameport) & 1) && t) t--;
                 udelay(seq[i]);
         } while (seq[++i]);
@@ -259,11 +259,11 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
 
 	gf2k_trigger_seq(gameport, gf2k_seq_reset);
 
-	msleep(GF2K_TIMEOUT);
+	usleep_range(GF2K_TIMEOUT, GF2K_TIMEOUT + 100);
 
 	gf2k_trigger_seq(gameport, gf2k_seq_digital);
 
-	msleep(GF2K_TIMEOUT);
+	usleep_range(GF2K_TIMEOUT, GF2K_TIMEOUT + 100);
 
 	if (gf2k_read_packet(gameport, GF2K_LENGTH, data) < 12) {
 		err = -ENODEV;
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Input: joystick: gf2k - change msleep to usleep_range for small msecs
  2016-11-28 19:41 [PATCH] Input: joystick: gf2k - change msleep to usleep_range for small msecs Aniroop Mathur
@ 2016-11-29  6:51 ` Vojtech Pavlik
  0 siblings, 0 replies; 2+ messages in thread
From: Vojtech Pavlik @ 2016-11-29  6:51 UTC (permalink / raw)
  To: Aniroop Mathur
  Cc: dmitry.torokhov, linux-input, linux-kernel, s.samuel, r.mahale,
	aniroop.mathur

On Tue, Nov 29, 2016 at 01:11:49AM +0530, Aniroop Mathur wrote:

> 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, connection time, probe time,
> loops, retry logic, etc
> msleep is built on jiffies / legacy timers which are not precise whereas
> usleep_range is build on top of hrtimers so the wakeups are precise.
> Thus, change msleep to usleep_range for precise wakeups.
> 
> For example:
> On a machine with tick rate / HZ as 100, msleep(4) will make the process to
> sleep for a minimum period of 10 ms whereas usleep_range(4000, 4100) will make
> sure that the process does not sleep for more than 4100 us or 4.1ms

And once more, patch not needed.

> 
> Signed-off-by: Aniroop Mathur <a.mathur@samsung.com>
> ---
>  drivers/input/joystick/gf2k.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/input/joystick/gf2k.c b/drivers/input/joystick/gf2k.c
> index 0f519db..e9d5095 100644
> --- a/drivers/input/joystick/gf2k.c
> +++ b/drivers/input/joystick/gf2k.c
> @@ -42,7 +42,7 @@ MODULE_LICENSE("GPL");
>  
>  #define GF2K_START		400	/* The time we wait for the first bit [400 us] */
>  #define GF2K_STROBE		40	/* The time we wait for the first bit [40 us] */
> -#define GF2K_TIMEOUT		4	/* Wait for everything to settle [4 ms] */
> +#define GF2K_TIMEOUT		4000	/* Wait for everything to settle [4000 us] */
>  #define GF2K_LENGTH		80	/* Max number of triplets in a packet */
>  
>  /*
> @@ -138,7 +138,7 @@ static void gf2k_trigger_seq(struct gameport *gameport, short *seq)
>  	i = 0;
>          do {
>  		gameport_trigger(gameport);
> -		t = gameport_time(gameport, GF2K_TIMEOUT * 1000);
> +		t = gameport_time(gameport, GF2K_TIMEOUT);
>  		while ((gameport_read(gameport) & 1) && t) t--;
>                  udelay(seq[i]);
>          } while (seq[++i]);
> @@ -259,11 +259,11 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
>  
>  	gf2k_trigger_seq(gameport, gf2k_seq_reset);
>  
> -	msleep(GF2K_TIMEOUT);
> +	usleep_range(GF2K_TIMEOUT, GF2K_TIMEOUT + 100);
>  
>  	gf2k_trigger_seq(gameport, gf2k_seq_digital);
>  
> -	msleep(GF2K_TIMEOUT);
> +	usleep_range(GF2K_TIMEOUT, GF2K_TIMEOUT + 100);
>  
>  	if (gf2k_read_packet(gameport, GF2K_LENGTH, data) < 12) {
>  		err = -ENODEV;
> -- 
> 2.6.2
> 

-- 
Vojtech Pavlik

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-11-29  6:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-28 19:41 [PATCH] Input: joystick: gf2k - change msleep to usleep_range for small msecs Aniroop Mathur
2016-11-29  6:51 ` Vojtech Pavlik

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.