From patchwork Thu Nov 30 09:26:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 120089 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp431585qgn; Thu, 30 Nov 2017 01:27:06 -0800 (PST) X-Google-Smtp-Source: AGs4zMYRKG/s9fyyaSk7uwxllmJl8G0+7ddpQ+s/1FVWUbfXLAO3yTynOtwxuSKcuQM3P35Tm0gv X-Received: by 10.84.212.1 with SMTP id d1mr1868422pli.91.1512034026221; Thu, 30 Nov 2017 01:27:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512034026; cv=none; d=google.com; s=arc-20160816; b=VwFlm9YDu9WNxKUuRDUrDZwmWXWxsP75EZKfWATTOBiWsulXF8dNf6Xj9Sn5Qtcw+i 73uZjgRaKU5Wvi1QBD2ZyVBiPyU6KnkoXyUB7+85GYFxhax+5AoE++YGgQBUz8rMfamI px1m9rZ8IIrZrJGsjF6i3o45ph4vPKvDe2oF6sFdVjIVxVzudjbkMQQSCcoB8o8ugXE+ oa3I45TiFtYizkGCmZE9UnInNtmEmbySL25fKBKYAerLT68mXq3rdzHCwEV2nQpT31kT mkTWG14T/bFkRvIuk2XUYBDzWrUejalI7GxO/+J+kcOAt8AyKK3rMpRtShVTngsK11Fj a0zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=/DNGxhU69KF07/CqEoGL3pYFgWuB8XyW0tjY+rBti7o=; b=Z1SktsRPE6VocLNaiDlHeYMH5sfFAteyCMOHxJkLGUalmFtpHtokvjiKtJnx5wt4Iu +fHclMRye4bBAWEV/1QI5TmT7oPaFk+HTLa4o9ZaVIO0mmoZor2sAS/Imj8gsPOo76vz n7jkCbwPmFUKtMC8EUPk1LEluD13RLlaxUuIRMqsl3PNUDycaEURMlPN6kKDuCUpt/XL QhlN0/AD6SLSV7u4SVMc3SUcv2kPqwcyvKJCRMIiG0f38m24MSKDMyBsMa2FDUbZvhAw tqVULU7vp0Nd6ii76NsL32C1Bx+cgsA0lmocIy3T7oGyiGZdgsGE+GgjU/BdKB116jgs Hq3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Y0+BaZo5; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w4si2852384plp.270.2017.11.30.01.27.05; Thu, 30 Nov 2017 01:27:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Y0+BaZo5; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750798AbdK3J1E (ORCPT + 6 others); Thu, 30 Nov 2017 04:27:04 -0500 Received: from mail-lf0-f66.google.com ([209.85.215.66]:41832 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750782AbdK3J1B (ORCPT ); Thu, 30 Nov 2017 04:27:01 -0500 Received: by mail-lf0-f66.google.com with SMTP id f18so7101194lfg.8 for ; Thu, 30 Nov 2017 01:27:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=H756GnFHn3cQ5h2lm4lFBR7MbngwkQh9yj8OlUg4l/U=; b=Y0+BaZo5DXvLVTDDbB5eCp/MmwfuKlqJPsgrvMAlmNI/77HEpwC6yZHJYIlF9uCOyl 1i8ua3RqCmVwzVIk5/jHsoeIev29/tYDgghwI9eZJGsiKExCJhvjNvZ06yzacGxJ4qUH 9luJ9lghW0PbyY5u9rAEVYT5oRsIJd9hp6jnQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=H756GnFHn3cQ5h2lm4lFBR7MbngwkQh9yj8OlUg4l/U=; b=miyGD1qvEpQxc2XQAW2XhEZdenp13cM5ZwsHMY7Jj8auV9cJdLflk0sykFnesqndHG Ao+lOc3UCQhfg2QrWhS/JLO0dxap9aKXoQUKQIMhcJLH26mJUWoO/gK3/HjE7XXqb3Op AKyTtMbA0dtL3eZaxxBAsRhuJjHo8nx3plfDQkAvWYUYvMrAlLuEJSjpbZmMZ82qxGub CXdN18jvG3esU7QWUx1HOnrTbCyWgXqeXnocwpulZpmArKWvjIq0F+5ZbvsMgLF+g1ku EVMJRFZtzGJ2II40gnRP++BCMHJ+FGFk5rS54Qsj6cXYMQysR10VjmHFSi7JJWlgu1tP xKOA== X-Gm-Message-State: AJaThX4vxyNJ6CYaCkvkFSzdSdPg1yfq6HVnm9iqBGdeHKgXuLjU7rBi B3SMxoFy5Ip2Bh34E9q9Z+sZYV+WGls= X-Received: by 10.25.109.6 with SMTP id i6mr2308552lfc.73.1512034020146; Thu, 30 Nov 2017 01:27:00 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id d80sm757284ljd.51.2017.11.30.01.26.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 Nov 2017 01:26:59 -0800 (PST) From: Linus Walleij To: linux-gpio@vger.kernel.org Cc: Linus Walleij , Bartosz Golaszewski , Felipe Balbi Subject: [PATCH] gpio: Timestamp events in hardirq handler Date: Thu, 30 Nov 2017 10:26:55 +0100 Message-Id: <20171130092655.25965-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add a hardirq handler to the GPIO userspace event loop, making sure to pick up the timestamp there, as close as possible in time relative to the actual event causing the interrupt. Tested with a simple pushbutton GPIO on ux500 and seems to work fine. Cc: Bartosz Golaszewski Cc: Felipe Balbi Reported-by: Felipe Balbi Signed-off-by: Linus Walleij --- drivers/gpio/gpiolib.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) -- 2.14.3 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Reviewed-by: Felipe Balbi diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index aad84a6306c4..6e006e6df95a 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -587,6 +587,9 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) * @events: KFIFO for the GPIO events * @read_lock: mutex lock to protect reads from colliding with adding * new events to the FIFO + * @timestamp: cache for the timestamp storing it between hardirq + * and IRQ thread, used to bring the timestamp close to the actual + * event */ struct lineevent_state { struct gpio_device *gdev; @@ -597,6 +600,7 @@ struct lineevent_state { wait_queue_head_t wait; DECLARE_KFIFO(events, struct gpioevent_data, 16); struct mutex read_lock; + s64 timestamp; }; #define GPIOEVENT_REQUEST_VALID_FLAGS \ @@ -731,7 +735,7 @@ static irqreturn_t lineevent_irq_thread(int irq, void *p) struct gpioevent_data ge; int ret, level; - ge.timestamp = ktime_get_real_ns(); + ge.timestamp = le->timestamp; level = gpiod_get_value_cansleep(le->desc); if (le->eflags & GPIOEVENT_REQUEST_RISING_EDGE @@ -759,6 +763,19 @@ static irqreturn_t lineevent_irq_thread(int irq, void *p) return IRQ_HANDLED; } +static irqreturn_t lineevent_irq_handler(int irq, void *p) +{ + struct lineevent_state *le = p; + + /* + * Just store the timestamp in hardirq context so we get it as + * close in time as possible to the actual event. + */ + le->timestamp = ktime_get_real_ns(); + + return IRQ_WAKE_THREAD; +} + static int lineevent_create(struct gpio_device *gdev, void __user *ip) { struct gpioevent_request eventreq; @@ -851,7 +868,7 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) /* Request a thread to read the events */ ret = request_threaded_irq(le->irq, - NULL, + lineevent_irq_handler, lineevent_irq_thread, irqflags, le->label,