From patchwork Mon Nov 28 19:38:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aniroop Mathur X-Patchwork-Id: 9450079 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 61B256074E for ; Mon, 28 Nov 2016 19:29:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5101727FE4 for ; Mon, 28 Nov 2016 19:29:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44B7A28047; Mon, 28 Nov 2016 19:29:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 302C028068 for ; Mon, 28 Nov 2016 19:29:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754605AbcK1T27 (ORCPT ); Mon, 28 Nov 2016 14:28:59 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:35183 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754600AbcK1T2z (ORCPT ); Mon, 28 Nov 2016 14:28:55 -0500 Received: by mail-pg0-f67.google.com with SMTP id p66so13917433pga.2; Mon, 28 Nov 2016 11:28:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=6sBEcl8cr6SBVeDrKPqiW4zyBLvI4FTiX1nKYyg2XpE=; b=CY9QVxTB8jdDIk7HtsukK1oK+zHloIiQJy2dInkAZLj+WsWTcMM1TbQPU30AmBT09U HNEviNdvl8rjIuT0OYleTtUBahFp/x9sq4XqfDC4Te4/GIwkhFPsGdn96BTNl2kBR4g1 aXnR5TB1PW3R60lYYAw4EWirjJK3WZ64wk7pgxwr32JZnLNxkhEyrj+XX3dgF0ajSEEC I+RvFspKWfh83yoNERuReDsvzWJbLpN/32nA+shBQEW8vmpZs4VP89kN9DfU9VvF83ru HqQohlWVGYIFqCuc+X2pSunDM8pP1mJ9ycWn5jtclU+FkE88bMxh8Tuu8gbs3mRbE0uO QboA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=6sBEcl8cr6SBVeDrKPqiW4zyBLvI4FTiX1nKYyg2XpE=; b=ByluabOgajYos4k3xhgxqXlX8sw6Sksu76odEe1mr4QTZv0th66JwZELwkX5TcSOUr pE2wZOaJ7BGzu3CoLU48pDQtYzQgkxCKK3oQpQZyZQvkwMskmgYMxG3IR1qRYf/ncJ27 LBN1PFbPakqeSZDKsifqrJFRvtmnuZbuHt9x45h6xKMKF40IFq+glSXAKsOwItU5rM1O owW9xZm0soyVwv62+XuMCRCnqWiY81uxZ4w9adszTSDJrZ5ky71tAdiLMrv8oBVDYW1P pksbOQ2V++6xcg02SC4DXCgzISCYvHkkx2ZLwZDj8KGx2Y2P2dk66ltC/0MjGeuZ7ek1 Zd4g== X-Gm-Message-State: AKaTC01dKFPbJGwxH49iYcvF8Hn5NUDXthmhyG5agkGqYj1FF2fh5u4bKKj7QJmSY7+5TA== X-Received: by 10.84.217.216 with SMTP id d24mr53131300plj.101.1480361334584; Mon, 28 Nov 2016 11:28:54 -0800 (PST) Received: from Aniroops-MacBook-Pro.local.name ([110.172.168.122]) by smtp.gmail.com with ESMTPSA id s4sm83057124pfb.55.2016.11.28.11.28.51 (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Nov 2016 11:28:54 -0800 (PST) From: Aniroop Mathur To: vojtech@ucw.cz, dmitry.torokhov@gmail.com, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Cc: s.samuel@samsung.com, r.mahale@samsung.com, aniroop.mathur@gmail.com, Aniroop Mathur Subject: [PATCH] Input: joystick: sidewinder - change msleep to usleep_range for small msecs Date: Tue, 29 Nov 2016 01:08:22 +0530 Message-Id: <1480361902-4671-1-git-send-email-a.mathur@samsung.com> X-Mailer: git-send-email 2.6.2 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(6) will make the process to sleep for a minimum period of 10 ms whereas usleep_range(6000, 6100) will make sure that the process does not sleep for more than 6100 us or 6.1ms Signed-off-by: Aniroop Mathur --- drivers/input/joystick/sidewinder.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c index 4a95b22..e5a1292 100644 --- a/drivers/input/joystick/sidewinder.c +++ b/drivers/input/joystick/sidewinder.c @@ -50,7 +50,7 @@ MODULE_LICENSE("GPL"); #define SW_START 600 /* The time we wait for the first bit [600 us] */ #define SW_STROBE 60 /* Max time per bit [60 us] */ -#define SW_TIMEOUT 6 /* Wait for everything to settle [6 ms] */ +#define SW_TIMEOUT 6000 /* Wait for everything to settle [6000 us] */ #define SW_KICK 45 /* Wait after A0 fall till kick [45 us] */ #define SW_END 8 /* Number of bits before end of packet to kick */ #define SW_FAIL 16 /* Number of packet read errors to fail and reinitialize */ @@ -139,7 +139,7 @@ static int sw_read_packet(struct gameport *gameport, unsigned char *buf, int len unsigned char pending, u, v; i = -id; /* Don't care about data, only want ID */ - timeout = id ? gameport_time(gameport, SW_TIMEOUT * 1000) : 0; /* Set up global timeout for ID packet */ + timeout = id ? gameport_time(gameport, SW_TIMEOUT) : 0; /* Set up global timeout for ID packet */ kick = id ? gameport_time(gameport, SW_KICK) : 0; /* Set up kick timeout for ID packet */ start = gameport_time(gameport, SW_START); strobe = gameport_time(gameport, SW_STROBE); @@ -248,7 +248,7 @@ static void sw_init_digital(struct gameport *gameport) i = 0; do { gameport_trigger(gameport); /* Trigger */ - t = gameport_time(gameport, SW_TIMEOUT * 1000); + t = gameport_time(gameport, SW_TIMEOUT); while ((gameport_read(gameport) & 1) && t) t--; /* Wait for axis to fall back to 0 */ udelay(seq[i]); /* Delay magic time */ } while (seq[++i]); @@ -483,13 +483,13 @@ static int sw_read(struct sw *sw) " - reinitializing joystick.\n", sw->gameport->phys); if (!i && sw->type == SW_ID_3DP) { /* 3D Pro can be in analog mode */ - mdelay(3 * SW_TIMEOUT); + mdelay(3 * (SW_TIMEOUT / 1000)); sw_init_digital(sw->gameport); } - mdelay(SW_TIMEOUT); + mdelay(SW_TIMEOUT / 1000); i = sw_read_packet(sw->gameport, buf, SW_LENGTH, 0); /* Read normal data packet */ - mdelay(SW_TIMEOUT); + mdelay(SW_TIMEOUT / 1000); sw_read_packet(sw->gameport, buf, SW_LENGTH, i); /* Read ID packet, this initializes the stick */ sw->fail = SW_FAIL; @@ -616,14 +616,14 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv) gameport->phys, gameport->io, gameport->speed); i = sw_read_packet(gameport, buf, SW_LENGTH, 0); /* Read normal packet */ - msleep(SW_TIMEOUT); + usleep_range(SW_TIMEOUT, SW_TIMEOUT + 100); dbg("Init 1: Mode %d. Length %d.", m , i); if (!i) { /* No data. 3d Pro analog mode? */ sw_init_digital(gameport); /* Switch to digital */ - msleep(SW_TIMEOUT); + usleep_range(SW_TIMEOUT, SW_TIMEOUT + 100); i = sw_read_packet(gameport, buf, SW_LENGTH, 0); /* Retry reading packet */ - msleep(SW_TIMEOUT); + usleep_range(SW_TIMEOUT, SW_TIMEOUT + 100); dbg("Init 1b: Length %d.", i); if (!i) { /* No data -> FAIL */ err = -ENODEV; @@ -636,7 +636,7 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv) dbg("Init 2: Mode %d. ID Length %d.", m, j); if (j <= 0) { /* Read ID failed. Happens in 1-bit mode on PP */ - msleep(SW_TIMEOUT); + usleep_range(SW_TIMEOUT, SW_TIMEOUT + 100); i = sw_read_packet(gameport, buf, SW_LENGTH, 0); /* Retry reading packet */ m |= sw_guess_mode(buf, i); dbg("Init 2b: Mode %d. Length %d.", m, i); @@ -644,7 +644,7 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv) err = -ENODEV; goto fail2; } - msleep(SW_TIMEOUT); + usleep_range(SW_TIMEOUT, SW_TIMEOUT + 100); j = sw_read_packet(gameport, idbuf, SW_LENGTH, i); /* Retry reading ID */ dbg("Init 2c: ID Length %d.", j); } @@ -655,7 +655,7 @@ static int sw_connect(struct gameport *gameport, struct gameport_driver *drv) do { k--; - msleep(SW_TIMEOUT); + usleep_range(SW_TIMEOUT, SW_TIMEOUT + 100); i = sw_read_packet(gameport, buf, SW_LENGTH, 0); /* Read data packet */ dbg("Init 3: Mode %d. Length %d. Last %d. Tries %d.", m, i, l, k);