On Wed, 29 Nov 2017 23:54:32 +0100 Linus Walleij <linus.walleij@xxxxxxxxxx> wrote: > 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. I did timing tests for both a long time back but I doubt things have changed much. To do fusion you ideally smooth the result on the basis you are fairly sure the internal clock is better than even then jitter we get in an interrupt. No idea where the absolute numbers went though I'm afraid. Perhaps Gregor can provide more info? Not sure who else is doing sensor fusion currently... > > 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