On Wed, Nov 29, 2017 at 2:56 PM, Felipe Balbi <felipe.balbi@xxxxxxxxxxxxxxx> wrote: > Me: >> For the other thing: timestamping of GPIO events, we already >> support timestamps for userspace GPIOs, but all it does is use >> the kernel time, see gpiolib.c: >> >> static irqreturn_t lineevent_irq_thread(int irq, void *p) >> { >> struct lineevent_state *le = p; >> struct gpioevent_data ge; >> int ret, level; >> >> ge.timestamp = ktime_get_real_ns(); >> level = gpiod_get_value_cansleep(le->desc); > > this is running as a thread with interrupts enabled, AFAICT. This means > this thread can be preempted at least on PREEMPT_RT kernels, so your > timestamp can be wrong, right? Yes, it can be off. What we should do to get i better is something like what I did in: drivers/iio/gyro/mpu3050-core.c Here I have both a hard and a soft IRQ handler (fast/slow if you like) and take the timestamp in the hard IRQ, then use it in the thread. This should be done identically in gpiolib to increase precision in the general case. I was thinking about it already when implementing it but it fell out of my mind. I'm putting in on my TODO. (CC to bartosz who might be interested, he's using these ABIs quite a bit.) Yours, Linus Walleij -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html