From patchwork Mon Nov 28 19:41:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aniroop Mathur X-Patchwork-Id: 9450113 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 3D5E260756 for ; Mon, 28 Nov 2016 19:32:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2989B2684F for ; Mon, 28 Nov 2016 19:32:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E63627FA8; Mon, 28 Nov 2016 19:32:17 +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 6FC53275A2 for ; Mon, 28 Nov 2016 19:32:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754710AbcK1TcF (ORCPT ); Mon, 28 Nov 2016 14:32:05 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34534 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754849AbcK1TcA (ORCPT ); Mon, 28 Nov 2016 14:32:00 -0500 Received: by mail-pf0-f196.google.com with SMTP id y68so6904721pfb.1; Mon, 28 Nov 2016 11:32:00 -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=oOC9TW7ZMb0hG+ucrNGZd1tKIW0mUG0BkQssXk2/oR8=; b=o3qRoZOAEf5YHrryv4pDY/yLR5sDrvahgeHhPJBfGgRBowTcMawqCX0pMtz5+MydrK kIpFgUYFENX1yNQ+Ik1sh/+lhDKMNSPSjMGKm1Xtfk/UGttLYW4eHEWTJtzRgtKbevHZ ZYOVjURZT7jPQPc8MAMvxKzNi+eAN+DjXyUohcIUv0EsCAQQzyoHTVeu0pjPZZ5Tmgi6 W9UlA6lexT6zY8BkXf+ygKX0xib9aoqQiAN+pP0PEZKfS1Z1TK0DZ2X1LDgNkJvmnQXL qv/7cX9Q0mIduJVeMhezo0d61Gl/eKlre5ifF5qN1llBt+2JtrqOgM6fGWSplG1Cs5Jv YvUA== 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=oOC9TW7ZMb0hG+ucrNGZd1tKIW0mUG0BkQssXk2/oR8=; b=Uv5Ry9sUeOG/AjAYLIZTEgxHtz3nA3EbpKzoW1zLHLuQ84uxT5y977R10townpzv/x 5AO1e1Bv/QmY0NM9dV6OXHsy28Tspjn6t/vclkAWW13y1S+nj0s+chHIYw4SMVBS+9nY wBnmictVURlISvc8u1xNaoVyj1APaE4hwejXXw2CqaBrm+ZjL4+oFUDjvZR+9Jear2/B AFd6AjUwlYUZCiRhFeYbiJl3/p0/BeZqRT6kdteiAIobWNgdqYDdUNQ7sHUXyqsqJnqD 3W03W2FFowphqkj33PDZzbMoiNCHguGwezvAFutN7N8dfTWaMVsgIQtJS32zTDiSLjYq i0pA== X-Gm-Message-State: AKaTC03bJdcA2Anq5gE5j7nOgJhOgBylhy0zukILv8C18iLtdnPYlqIXGwB+6gwM6dFpnA== X-Received: by 10.98.61.21 with SMTP id k21mr23329245pfa.118.1480361519483; Mon, 28 Nov 2016 11:31:59 -0800 (PST) Received: from Aniroops-MacBook-Pro.local.name ([110.172.168.122]) by smtp.gmail.com with ESMTPSA id y15sm71297231pgc.43.2016.11.28.11.31.56 (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Nov 2016 11:31:59 -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: analog - change msleep to usleep_range for small msecs Date: Tue, 29 Nov 2016 01:11:31 +0530 Message-Id: <1480362091-4768-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(3) will make the process to sleep for a minimum period of 10 ms whereas usleep_range(3000, 3100) will make sure that the process does not sleep for more than 3100 us or 3.1ms Signed-off-by: Aniroop Mathur --- drivers/input/joystick/analog.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c index 3d8ff09..2891704 100644 --- a/drivers/input/joystick/analog.c +++ b/drivers/input/joystick/analog.c @@ -88,7 +88,7 @@ MODULE_PARM_DESC(map, "Describes analog joysticks type/capabilities"); #define ANALOG_EXTENSIONS 0x7ff00 #define ANALOG_GAMEPAD 0x80000 -#define ANALOG_MAX_TIME 3 /* 3 ms */ +#define ANALOG_MAX_TIME 3000 /* 3000 us */ #define ANALOG_LOOP_TIME 2000 /* 2 * loop */ #define ANALOG_SAITEK_DELAY 200 /* 200 us */ #define ANALOG_SAITEK_TIME 2000 /* 2000 us */ @@ -257,7 +257,7 @@ static int analog_cooked_read(struct analog_port *port) int i, j; loopout = (ANALOG_LOOP_TIME * port->loop) / 1000; - timeout = ANALOG_MAX_TIME * port->speed; + timeout = (ANALOG_MAX_TIME / 1000) * port->speed; local_irq_save(flags); gameport_trigger(gameport); @@ -625,20 +625,20 @@ static int analog_init_port(struct gameport *gameport, struct gameport_driver *d gameport_trigger(gameport); t = gameport_read(gameport); - msleep(ANALOG_MAX_TIME); + usleep_range(ANALOG_MAX_TIME, ANALOG_MAX_TIME + 100); port->mask = (gameport_read(gameport) ^ t) & t & 0xf; port->fuzz = (port->speed * ANALOG_FUZZ_MAGIC) / port->loop / 1000 + ANALOG_FUZZ_BITS; for (i = 0; i < ANALOG_INIT_RETRIES; i++) { if (!analog_cooked_read(port)) break; - msleep(ANALOG_MAX_TIME); + usleep_range(ANALOG_MAX_TIME, ANALOG_MAX_TIME + 100); } u = v = 0; - msleep(ANALOG_MAX_TIME); - t = gameport_time(gameport, ANALOG_MAX_TIME * 1000); + usleep_range(ANALOG_MAX_TIME, ANALOG_MAX_TIME + 100); + t = gameport_time(gameport, ANALOG_MAX_TIME); gameport_trigger(gameport); while ((gameport_read(port->gameport) & port->mask) && (u < t)) u++;