Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756208AbcK2GwI (ORCPT ); Tue, 29 Nov 2016 01:52:08 -0500 Received: from jablonecka.jablonka.cz ([91.219.244.36]:33018 "EHLO jablonecka.jablonka.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756080AbcK2Gv5 (ORCPT ); Tue, 29 Nov 2016 01:51:57 -0500 Date: Tue, 29 Nov 2016 07:51:55 +0100 From: Vojtech Pavlik To: Aniroop Mathur Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, s.samuel@samsung.com, r.mahale@samsung.com, aniroop.mathur@gmail.com Subject: Re: [PATCH] Input: joystick: gf2k - change msleep to usleep_range for small msecs Message-ID: <20161129065155.GD10549@suse.com> References: <1480362109-4818-1-git-send-email-a.mathur@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1480362109-4818-1-git-send-email-a.mathur@samsung.com> X-Bounce-Cookie: It's a lemon tree, dear Watson! User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2512 Lines: 66 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 > --- > 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