From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jonathan Cameron Subject: Re: [RFC] Periodic Output, Timestamped Input Date: Sat, 2 Dec 2017 13:34:03 +0000 Message-ID: <20171202133403.10651f76@archlinux> References: <87ineapo5w.fsf@linux.intel.com> <87shcxw5n3.fsf@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Return-path: Received: from mail.kernel.org ([198.145.29.99]:34166 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751684AbdLBNeI (ORCPT ); Sat, 2 Dec 2017 08:34:08 -0500 In-Reply-To: Sender: linux-gpio-owner@vger.kernel.org List-Id: linux-gpio@vger.kernel.org To: Linus Walleij Cc: Felipe Balbi , Bartosz =?UTF-8?B?R28=?= =?UTF-8?B?xYJhc3pld3NraQ==?= , linux-iio@vger.kernel.org, "thierry.reding@gmail.com" , linux-pwm@vger.kernel.org, Lars-Peter Clausen , linux-gpio@vger.kernel.org, Gregor Boirie On Wed, 29 Nov 2017 23:54:32 +0100 Linus Walleij wrote: > On Wed, Nov 29, 2017 at 2:56 PM, Felipe Balbi > 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