linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Walleij <linus.walleij@linaro.org>
To: "Felipe Balbi" <felipe.balbi@linux.intel.com>,
	"Bartosz Gołaszewski" <bartekgola@gmail.com>
Cc: linux-iio@vger.kernel.org, Jonathan Cameron <jic23@kernel.org>,
	"thierry.reding@gmail.com" <thierry.reding@gmail.com>,
	linux-pwm@vger.kernel.org, Lars-Peter Clausen <lars@metafoo.de>,
	linux-gpio@vger.kernel.org
Subject: Re: [RFC] Periodic Output, Timestamped Input
Date: Wed, 29 Nov 2017 23:54:32 +0100	[thread overview]
Message-ID: <CACRpkdabNMHgs_ywzrgSg-AgQL1wtQN8SaxuZtCruiXnfrXGQw@mail.gmail.com> (raw)
In-Reply-To: <87shcxw5n3.fsf@linux.intel.com>

On Wed, Nov 29, 2017 at 2:56 PM, Felipe Balbi
<felipe.balbi@linux.intel.com> 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

  reply	other threads:[~2017-11-29 22:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-16  9:29 [RFC] Periodic Output, Timestamped Input Felipe Balbi
2017-11-29 13:31 ` Linus Walleij
2017-11-29 13:56   ` Felipe Balbi
2017-11-29 22:54     ` Linus Walleij [this message]
2017-12-02 13:34       ` Jonathan Cameron
2017-12-05  9:20       ` Felipe Balbi
2017-12-05 11:01         ` Linus Walleij
2017-12-05 11:23           ` Felipe Balbi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CACRpkdabNMHgs_ywzrgSg-AgQL1wtQN8SaxuZtCruiXnfrXGQw@mail.gmail.com \
    --to=linus.walleij@linaro.org \
    --cc=bartekgola@gmail.com \
    --cc=felipe.balbi@linux.intel.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=thierry.reding@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).