From: Jonathan Cameron <jic23@kernel.org>
To: Peter Rosin <peda@axentia.se>, Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org, Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Daniel Baluta <daniel.baluta@intel.com>,
Slawomir Stepien <sst@poczta.fm>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v4 8/8] iio: envelope-detector: ADC driver based on a DAC and a comparator
Date: Sat, 12 Nov 2016 17:27:22 +0000 [thread overview]
Message-ID: <a4b0eeec-9a4c-d72f-2678-82059ea76153@kernel.org> (raw)
In-Reply-To: <d8237286-d2ff-3146-d718-f54d05b0101d@axentia.se>
On 08/11/16 17:03, Peter Rosin wrote:
> On 2016-11-08 16:59, Thomas Gleixner wrote:
>> On Tue, 8 Nov 2016, Peter Rosin wrote:
>>> +/*
>>> + * The envelope_detector_comp_latch function works together with the compare
>>> + * interrupt service routine below (envelope_detector_comp_isr) as a latch
>>> + * (one-bit memory) for if the interrupt has triggered since last calling
>>> + * this function.
>>> + * The ..._comp_isr function disables the interrupt so that the cpu does not
>>> + * need to service a possible interrupt flood from the comparator when no-one
>>> + * cares anyway, and this ..._comp_latch function reenables them again if
>>> + * needed.
>>> + */
>>> +static int envelope_detector_comp_latch(struct envelope *env)
>>> +{
>>> + int comp;
>>> +
>>> + spin_lock_irq(&env->comp_lock);
>>> + comp = env->comp;
>>> + env->comp = 0;
>>> + spin_unlock_irq(&env->comp_lock);
>>> +
>>> + if (!comp)
>>> + return 0;
>>> +
>>> + /*
>>> + * The irq was disabled, and is reenabled just now.
>>> + * But there might have been a pending irq that
>>> + * happened while the irq was disabled that fires
>>> + * just as the irq is reenabled. That is not what
>>> + * is desired.
>>> + */
>>> + enable_irq(env->comp_irq);
>>> +
>>> + /* So, synchronize this possibly pending irq... */
>>> + synchronize_irq(env->comp_irq);
>>> +
>>> + /* ...and redo the whole dance. */
>>> + spin_lock_irq(&env->comp_lock);
>>> + comp = env->comp;
>>> + env->comp = 0;
>>> + spin_unlock_irq(&env->comp_lock);
>>> +
>>> + if (comp)
>>> + enable_irq(env->comp_irq);
>>
>> So you need that whole dance including the delayed work because you cannot
>> call iio_write_channel_raw() from hard interrupt context, right?
>
> It's not the "cannot call from hard irq context" that made me do that, it's...
>
>> So you might just register a threaded interrupt handler, which should make
>> this whole thing way simpler.
>>
>> devm_request_threaded_irq(dev, irq, NULL, your_isr, IRQF_ONESHOT, ...);
>>
>> The core will mask the interrupt line until the threaded handler is
>> finished. The threaded handler is invoked with preemption enabled, so you
>> can sleep there as long as you want. So you can do everything in your
>> handler and the above dance is just not required.
>
> ...that I couldn't work out how to reenable a oneshot irq once it had fired,
> short of freeing the irq and requesting it again. That seemed entirely
> bogus, the driver shouldn't risk losing a resource like that so I don't know
> what I didn't see? Or maybe it was that I had a hard time resolving the race
> between the irq and the timeout in a nice way. I honestly don't remember
> why exactly I abandoned oneshot irqs, but this enable/sync/enable dance
> was much nicer than what I came up with for the oneshot irq solution I
> originally worked on.
>
> Or maybe I had problems with the possibly pending irq also when using a
> oneshot irq, but didn't realize it? That was something I discovered quite
> late in the process, some time after moving away from oneshot irqs. Are
> pending irqs cleared when requesting (or reenabling, however that is done)
> a oneshot irq?
>
> Anyway, I do not want the interrupt to be serviced when no one is interested,
> since I'm afraid that nasty input might generate a flood of interrupts that
> might disturb other things that the cpu is doing. Which means that I need
> to enable/disable the interrupt as needed.
>
> However, what *I* thought Jonathan wanted input on was the part where the
> interrupt edge/level is flipped when requesting "inverted" signals in
> envelope_store_invert(). That could perhaps be seen as unorthodox and in
> need of more eyes?
Nope, as far as I can recall it was precisely this dance that was
I wanted Thomas to comment on :) The inverted bit isn't as novel as
this ;)
Anyhow, thread ended up with a good conclusion so I'm happy.
Jonathan
>
> Cheers,
> Peter
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
WARNING: multiple messages have this Message-ID (diff)
From: Jonathan Cameron <jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Peter Rosin <peda-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>,
Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Hartmut Knaack <knaack.h-Mmb7MZpHnFY@public.gmane.org>,
Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>,
Peter Meerwald-Stadler
<pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org>,
Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
Daniel Baluta
<daniel.baluta-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
Slawomir Stepien <sst-IjDXvh/HVVUAvxtiuMwx3w@public.gmane.org>,
linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v4 8/8] iio: envelope-detector: ADC driver based on a DAC and a comparator
Date: Sat, 12 Nov 2016 17:27:22 +0000 [thread overview]
Message-ID: <a4b0eeec-9a4c-d72f-2678-82059ea76153@kernel.org> (raw)
In-Reply-To: <d8237286-d2ff-3146-d718-f54d05b0101d-koto5C5qi+TLoDKTGw+V6w@public.gmane.org>
On 08/11/16 17:03, Peter Rosin wrote:
> On 2016-11-08 16:59, Thomas Gleixner wrote:
>> On Tue, 8 Nov 2016, Peter Rosin wrote:
>>> +/*
>>> + * The envelope_detector_comp_latch function works together with the compare
>>> + * interrupt service routine below (envelope_detector_comp_isr) as a latch
>>> + * (one-bit memory) for if the interrupt has triggered since last calling
>>> + * this function.
>>> + * The ..._comp_isr function disables the interrupt so that the cpu does not
>>> + * need to service a possible interrupt flood from the comparator when no-one
>>> + * cares anyway, and this ..._comp_latch function reenables them again if
>>> + * needed.
>>> + */
>>> +static int envelope_detector_comp_latch(struct envelope *env)
>>> +{
>>> + int comp;
>>> +
>>> + spin_lock_irq(&env->comp_lock);
>>> + comp = env->comp;
>>> + env->comp = 0;
>>> + spin_unlock_irq(&env->comp_lock);
>>> +
>>> + if (!comp)
>>> + return 0;
>>> +
>>> + /*
>>> + * The irq was disabled, and is reenabled just now.
>>> + * But there might have been a pending irq that
>>> + * happened while the irq was disabled that fires
>>> + * just as the irq is reenabled. That is not what
>>> + * is desired.
>>> + */
>>> + enable_irq(env->comp_irq);
>>> +
>>> + /* So, synchronize this possibly pending irq... */
>>> + synchronize_irq(env->comp_irq);
>>> +
>>> + /* ...and redo the whole dance. */
>>> + spin_lock_irq(&env->comp_lock);
>>> + comp = env->comp;
>>> + env->comp = 0;
>>> + spin_unlock_irq(&env->comp_lock);
>>> +
>>> + if (comp)
>>> + enable_irq(env->comp_irq);
>>
>> So you need that whole dance including the delayed work because you cannot
>> call iio_write_channel_raw() from hard interrupt context, right?
>
> It's not the "cannot call from hard irq context" that made me do that, it's...
>
>> So you might just register a threaded interrupt handler, which should make
>> this whole thing way simpler.
>>
>> devm_request_threaded_irq(dev, irq, NULL, your_isr, IRQF_ONESHOT, ...);
>>
>> The core will mask the interrupt line until the threaded handler is
>> finished. The threaded handler is invoked with preemption enabled, so you
>> can sleep there as long as you want. So you can do everything in your
>> handler and the above dance is just not required.
>
> ...that I couldn't work out how to reenable a oneshot irq once it had fired,
> short of freeing the irq and requesting it again. That seemed entirely
> bogus, the driver shouldn't risk losing a resource like that so I don't know
> what I didn't see? Or maybe it was that I had a hard time resolving the race
> between the irq and the timeout in a nice way. I honestly don't remember
> why exactly I abandoned oneshot irqs, but this enable/sync/enable dance
> was much nicer than what I came up with for the oneshot irq solution I
> originally worked on.
>
> Or maybe I had problems with the possibly pending irq also when using a
> oneshot irq, but didn't realize it? That was something I discovered quite
> late in the process, some time after moving away from oneshot irqs. Are
> pending irqs cleared when requesting (or reenabling, however that is done)
> a oneshot irq?
>
> Anyway, I do not want the interrupt to be serviced when no one is interested,
> since I'm afraid that nasty input might generate a flood of interrupts that
> might disturb other things that the cpu is doing. Which means that I need
> to enable/disable the interrupt as needed.
>
> However, what *I* thought Jonathan wanted input on was the part where the
> interrupt edge/level is flipped when requesting "inverted" signals in
> envelope_store_invert(). That could perhaps be seen as unorthodox and in
> need of more eyes?
Nope, as far as I can recall it was precisely this dance that was
I wanted Thomas to comment on :) The inverted bit isn't as novel as
this ;)
Anyhow, thread ended up with a good conclusion so I'm happy.
Jonathan
>
> Cheers,
> Peter
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
next prev parent reply other threads:[~2016-11-12 17:27 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-08 11:58 [PATCH v4 0/8] IIO wrapper drivers, dpot-dac and envelope-detector Peter Rosin
2016-11-08 11:58 ` Peter Rosin
2016-11-08 11:58 ` [PATCH v4 1/8] iio:core: add a callback to allow drivers to provide _available attributes Peter Rosin
2016-11-08 11:58 ` Peter Rosin
2016-11-12 17:17 ` Jonathan Cameron
2016-11-12 17:17 ` Jonathan Cameron
2016-11-08 11:58 ` [PATCH v4 2/8] iio: inkern: add helpers to query available values from channels Peter Rosin
2016-11-08 11:58 ` Peter Rosin
2016-11-12 17:17 ` Jonathan Cameron
2016-11-08 11:58 ` [PATCH v4 3/8] iio: mcp4531: provide range of available raw values Peter Rosin
2016-11-08 11:58 ` Peter Rosin
2016-11-12 17:22 ` Jonathan Cameron
2016-11-12 17:22 ` Jonathan Cameron
2016-11-08 11:58 ` [PATCH v4 4/8] dt-bindings: add axentia to vendor-prefixes Peter Rosin
2016-11-08 11:58 ` Peter Rosin
2016-11-12 17:23 ` Jonathan Cameron
2016-11-12 17:23 ` Jonathan Cameron
2016-11-08 11:58 ` [PATCH v4 5/8] dt-bindings: iio: document dpot-dac bindings Peter Rosin
2016-11-08 11:58 ` Peter Rosin
2016-11-08 11:58 ` [PATCH v4 6/8] iio: dpot-dac: DAC driver based on a digital potentiometer Peter Rosin
2016-11-08 11:58 ` Peter Rosin
2016-11-12 17:24 ` Jonathan Cameron
2016-11-12 17:24 ` Jonathan Cameron
2016-11-08 11:58 ` [PATCH v4 7/8] dt-bindings: iio: document envelope-detector bindings Peter Rosin
2016-11-08 11:58 ` Peter Rosin
2016-11-12 17:25 ` Jonathan Cameron
2016-11-08 11:58 ` [PATCH v4 8/8] iio: envelope-detector: ADC driver based on a DAC and a comparator Peter Rosin
2016-11-08 11:58 ` Peter Rosin
2016-11-08 15:59 ` Thomas Gleixner
2016-11-08 15:59 ` Thomas Gleixner
2016-11-08 17:03 ` Peter Rosin
2016-11-08 17:03 ` Peter Rosin
2016-11-08 18:38 ` Thomas Gleixner
2016-11-08 20:44 ` Peter Rosin
2016-11-08 20:44 ` Peter Rosin
2016-11-08 21:47 ` Thomas Gleixner
2016-11-08 21:47 ` Thomas Gleixner
2016-11-09 15:01 ` Peter Rosin
2016-11-09 15:01 ` Peter Rosin
2016-11-09 15:06 ` Thomas Gleixner
2016-11-11 11:37 ` Peter Rosin
2016-11-11 11:37 ` Peter Rosin
2016-11-12 17:29 ` Jonathan Cameron
2016-11-12 17:29 ` Jonathan Cameron
2016-11-12 17:27 ` Jonathan Cameron [this message]
2016-11-12 17:27 ` Jonathan Cameron
2016-11-12 17:15 ` [PATCH v4 0/8] IIO wrapper drivers, dpot-dac and envelope-detector Jonathan Cameron
2016-11-12 17:15 ` Jonathan Cameron
2016-11-15 14:03 ` Peter Rosin
2016-11-15 14:03 ` Peter Rosin
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=a4b0eeec-9a4c-d72f-2678-82059ea76153@kernel.org \
--to=jic23@kernel.org \
--cc=daniel.baluta@intel.com \
--cc=devicetree@vger.kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=peda@axentia.se \
--cc=pmeerw@pmeerw.net \
--cc=robh+dt@kernel.org \
--cc=sst@poczta.fm \
--cc=tglx@linutronix.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.