From patchwork Mon Nov 28 19:41:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aniroop Mathur X-Patchwork-Id: 9450119 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 5C35860756 for ; Mon, 28 Nov 2016 19:32:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B3342684F for ; Mon, 28 Nov 2016 19:32:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DDB9275A2; Mon, 28 Nov 2016 19:32:38 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 C1DCC275A2 for ; Mon, 28 Nov 2016 19:32:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753352AbcK1Tc2 (ORCPT ); Mon, 28 Nov 2016 14:32:28 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:33932 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754911AbcK1TcQ (ORCPT ); Mon, 28 Nov 2016 14:32:16 -0500 Received: by mail-pg0-f66.google.com with SMTP id e9so13891567pgc.1; Mon, 28 Nov 2016 11:32:16 -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=Xi3K9Cgv0bi7pbvKKOZ1RSpDJCwBuXWeHhkLsxt1P3c=; b=cvKB1+0jy9i34FCtqMGepGlL0DyNLpbdWeBeDaKQxd5riVEWxft/dnW04cBF+yEqkv BPE7/P4mbpHP1EC2k3wO2MdhWoQcGWtJ9OZmihUihrjUZfEZw9QmxnZx3TkVe+AGLuRs VkQ06ffP425XN8afTPXM6QGuJZrIbYUABxHJ8JOI+At548XhmH3W0xnxkQQDBM55nIxc WE3PMxLyYzDZ3N0/huk8joji4IgWZYDg4A6JnbH/yu0IzcWlmfAm+bHCKds/3vhhVh3I v04PLejx1tCxQEqhJE8pmTt4TcTo2PZ7GQCpjxxWv4g6+7PrrUdiLwo3Q40WzsOhKZLQ 5pFw== 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=Xi3K9Cgv0bi7pbvKKOZ1RSpDJCwBuXWeHhkLsxt1P3c=; b=TnjxA/0cFS+7ggDVJxjeiZj9aYEnSaq8r/UomD6WwKHgkDQHW0/Ml2GRen0Fa1Gkrk pwds8Ge4PTVjGeL8Y2EkChTKKOUoFIOjg5jemttKF8ySzyGlFjz7eRBuXdOsP1RqIN92 VZK8/rUW5saC96KkYTqB2LjSHzWNM0/nCi23+xclEwUwnh/pELMi/qUC6110+JqCque3 0sfouA2BMOiS65pI38N5HLrm4e2VJWdu22+JQML4sxwDD1rWoCyyfEJhJebMAJjGa+ql IUNnV8VM1BougBW7cgVj+tZ+AO8xzmN4G/2ZFbcm9bZwJA043+Ts4Kl75xzjIJwFOlPW 9k4w== X-Gm-Message-State: AKaTC03pvxSrzz7APcnuVk3pRdqnk50DYxyb7fg4bT05PZyjVqoJClRe5vneJmvzjUmLRA== X-Received: by 10.84.213.150 with SMTP id g22mr52927989pli.11.1480361535502; Mon, 28 Nov 2016 11:32:15 -0800 (PST) Received: from Aniroops-MacBook-Pro.local.name ([110.172.168.122]) by smtp.gmail.com with ESMTPSA id z9sm71361097pge.44.2016.11.28.11.32.12 (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Nov 2016 11:32:15 -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: gf2k - change msleep to usleep_range for small msecs Date: Tue, 29 Nov 2016 01:11:49 +0530 Message-Id: <1480362109-4818-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(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 --- 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;