diff mbox series

gpio: Switch timestamps to ktime_get_ns()

Message ID 20200220150250.46226-1-linus.walleij@linaro.org
State New
Headers show
Series gpio: Switch timestamps to ktime_get_ns() | expand

Commit Message

Linus Walleij Feb. 20, 2020, 3:02 p.m. UTC
The existing use of ktime_get_real_ns() in the timestamps from
the GPIO events is dubious.

We have had several discussions about this timestamp, and it is
unclear whether userspace has ever taken into account that a
timestamp from ktime_get_real_ns() can actually move backwards
in time relative the previous timetamp, and userspace is more
likely to expect a monotonic counter.

Background:
https://lore.kernel.org/linux-gpio/CAK8P3a1Skvm48sje8FNDPLYqyz9Lf8q0qX1QETWtyZTxuX4k1g@mail.gmail.com/
https://marc.info/?l=linux-gpio&m=151661955709074&w=2

The change is ABI incompatible, but incompatible in a way that
is IMO more likely to fix future bugs rather than break current
userspace. To the best of my knowledge all userspace expects
a monotonic timestamp and users are just lucky that they very
seldom move backwards in time.

Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/gpio/gpiolib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Bartosz Golaszewski Feb. 20, 2020, 3:08 p.m. UTC | #1
czw., 20 lut 2020 o 16:03 Linus Walleij <linus.walleij@linaro.org> napisaƂ(a):
>
> The existing use of ktime_get_real_ns() in the timestamps from
> the GPIO events is dubious.
>
> We have had several discussions about this timestamp, and it is
> unclear whether userspace has ever taken into account that a
> timestamp from ktime_get_real_ns() can actually move backwards
> in time relative the previous timetamp, and userspace is more
> likely to expect a monotonic counter.
>
> Background:
> https://lore.kernel.org/linux-gpio/CAK8P3a1Skvm48sje8FNDPLYqyz9Lf8q0qX1QETWtyZTxuX4k1g@mail.gmail.com/
> https://marc.info/?l=linux-gpio&m=151661955709074&w=2
>
> The change is ABI incompatible, but incompatible in a way that
> is IMO more likely to fix future bugs rather than break current
> userspace. To the best of my knowledge all userspace expects
> a monotonic timestamp and users are just lucky that they very
> seldom move backwards in time.
>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---

I too am in favor of this change.

Acked-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
diff mbox series

Patch

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 753283486037..5db16f69c13e 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -945,7 +945,7 @@  static irqreturn_t lineevent_irq_thread(int irq, void *p)
 	 * we didn't get the timestamp from lineevent_irq_handler().
 	 */
 	if (!le->timestamp)
-		ge.timestamp = ktime_get_real_ns();
+		ge.timestamp = ktime_get_ns();
 	else
 		ge.timestamp = le->timestamp;
 
@@ -983,7 +983,7 @@  static irqreturn_t lineevent_irq_handler(int irq, void *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();
+	le->timestamp = ktime_get_ns();
 
 	return IRQ_WAKE_THREAD;
 }