From mboxrd@z Thu Jan 1 00:00:00 1970 From: Linus Walleij Subject: Re: [RFC] Periodic Output, Timestamped Input Date: Wed, 29 Nov 2017 23:54:32 +0100 Message-ID: References: <87ineapo5w.fsf@linux.intel.com> <87shcxw5n3.fsf@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Return-path: Received: from mail-io0-f195.google.com ([209.85.223.195]:33142 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753177AbdK2Wyd (ORCPT ); Wed, 29 Nov 2017 17:54:33 -0500 Received: by mail-io0-f195.google.com with SMTP id t196so5524901iof.0 for ; Wed, 29 Nov 2017 14:54:33 -0800 (PST) In-Reply-To: <87shcxw5n3.fsf@linux.intel.com> Sender: linux-gpio-owner@vger.kernel.org List-Id: linux-gpio@vger.kernel.org To: Felipe Balbi , =?UTF-8?Q?Bartosz_Go=C5=82aszewski?= Cc: linux-iio@vger.kernel.org, Jonathan Cameron , "thierry.reding@gmail.com" , linux-pwm@vger.kernel.org, Lars-Peter Clausen , linux-gpio@vger.kernel.org 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. 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