All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Hilman <khilman@deeprootsystems.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: linux-pm@lists.linux-foundation.org,
	Partha Basak <p-basak2@ti.com>,
	linux-omap@vger.kernel.org
Subject: Re: [linux-pm] runtime_pm_get_sync() from ISR with IRQs disabled?
Date: Fri, 24 Sep 2010 14:52:44 -0700	[thread overview]
Message-ID: <87lj6q3j2r.fsf@deeprootsystems.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1009241547010.1287-100000@iolanthe.rowland.org> (Alan Stern's message of "Fri, 24 Sep 2010 16:27:25 -0400 (EDT)")

Alan Stern <stern@rowland.harvard.edu> writes:

> On Fri, 24 Sep 2010, Kevin Hilman wrote:
>
>> >> So, what is the "right" thing to do here?
>> >
>> > You should call pm_runtime_get(), turn off the interrupt source, and
>> > return.  Then your resume routine should check for an outstanding
>> > interrupt or wakeup request and handle it (the easiest way may be 
>> > simply to call the ISR).
>> 
>> For a "normal" device driver, your solution makes complete sense.  The
>> only catch is that it introduces potentically significant latency in the
>> interrupt handling and it requires the interrupt source to be masked,
>> potentially loosing other interrupts, while waiting for the runtime PM
>> workqueue to schedule.  For chained handlers in particular, this means
>> that *all* interrupts managed by the chained handler would be masked for
>> this additional time.  Not good.
>
> Masking an interrupt source doesn't cause any interrupts to be lost, if 
> you mask it at a time when you couldn't handle the interrupts anyway.

Sure, but the "mask in ISR, handle in ->runtime_resume()" proposal
would keeping them masked while we actually could be handling them.

Even in our current GPIO code, we have a tiny (but bounded) window where
we might miss an edge-triggered GPIO interrupt while we're still
detecting the previous one.  However, this is a very small window in an
interrupts-disabled chained handler.  

>> The problematic device for me as an on-chip GPIO controller, and the ISR
>> in question is a chained handler (run with interrupts disabled) which
>> does the GPIO demux and then dispatches to the actual ISR.  Following the
>> above approach means that all GPIO interrupts (in that bank) would be
>> masked until ->runtime_resume() is called.  For a GPIO bank with
>> multiple edge-triggered IRQs, masked IRQs for that amount of time could
>> mean several missed interrupts while waiting.
>
> Wait a minute, you're confusing me.  I take it that the GPIO controller
> is the device being runtime suspended, right?  

Right.

> And you said that while it is suspended you can't access its
> registers.  So then how can you mask it?

The interrupt to be masked would be the main GPIO bank IRQ (for the
chained handler) and it would be masked at the IRQ controller, which
is not (yet) suspended.

> Do you mean that you have to mask the entire IRQ line because there's
> no way to turn off the interrupt-request source in the GPIO controller?  

Right. Because in order to determine the exact interrupt source, you
have to access the GPIO controller registers and figure out which GPIO
in the GPIO bank was the source.  And then, the only way to turn off the
source is to know which device is connected to that IRQ, and disable it
via the driver for that device (e.g. network driver using a GPIO IRQ.)

IOW, When the bank IRQ fires, all we know is that (at least) one of the 32
GPIOs in the GPIO bank has an interrupt pending.  In order to determine
which one it was, we have to read GPIO controller registers, but we
can't do that until ->runtime_resume().  In order for the bank IRQ not
to continually re-fire, it would have to be kept masked until
the ISR is triggered from ->runtime_resume().

> That's different from what you wrote above.

Right, I should have said the GPIO bank IRQ needs to be masked instead
of all GPIOs in the bank need to be masked.

>>  Hoever, this isn't a
>> major concern as we don't (currently) have IRQF_DISABLED handlers hooked
>> up to GPIO IRQs (that I know of.)
>
> Isn't IRQF_DISABLED on its way out, anyway?

Yes, that's why it's not really a concern.

>> It may seem like I'm trying to fight the design, but I'm actually trying
>> to find ways to use it.  I want to use the API (and we're using it
>> successfully in most of our drivers now.)  The problem is only in a few
>> of these corner cases where using it introduces significant changes from
>> previous behavior like introducing long, unbounded windows for missed
>> interrupts.
>
> Assuming the problem of missed interrupts didn't exist, would you still 
> be unhappy about the latency issue?

Yes.

> In the general case there's no way to avoid it.  Even though a device
> like your GPIO controller may be able to return to full power very
> quickly, the fact that it was suspended may have led the PM core to
> suspend its parent as well.  And the parent may be slow to resume,
> requiring a full process context.

In the general case, I agree.

> It seems as though what you really need is a way to tell the PM core 
> that your device can change its power state quickly with no need for a 
> process context.  Given that, pm_runtime_get() could invoke your 
> runtime_resume callback directly; you wouldn't have to wait for the 
> workqueue.  (Unless your device had a suspended parent that _did_ need 
> a long time to resume.)
>
> Would that solve your problem?  It seems like a reasonable sort of 
> feature to add.

Yes, that would definitely solve the problem, and is basically the
hack/workaround I'm using locally:

  pm_runtime_get_noresume()
  dev->pm->runtime_resume()
  /* handle IRQ */
  pm_runtime_put();

because I know this on-chip device is 1) already suspended, 2) has no
runtime PM capable parents and 3) not runtime_resume'd elsewhere.

Kevin

  parent reply	other threads:[~2010-09-24 21:52 UTC|newest]

Thread overview: 144+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-24  0:05 runtime_pm_get_sync() from ISR with IRQs disabled? Kevin Hilman
2010-09-24 15:13 ` [linux-pm] " Alan Stern
2010-09-24 18:54   ` Kevin Hilman
2010-09-24 18:54   ` [linux-pm] " Kevin Hilman
2010-09-24 20:04     ` Rafael J. Wysocki
2010-09-27 13:57       ` Alan Stern
2010-09-27 13:57       ` [linux-pm] " Alan Stern
2010-09-27 20:00         ` Rafael J. Wysocki
2010-09-27 20:00         ` [linux-pm] " Rafael J. Wysocki
2010-09-27 20:39           ` Alan Stern
2010-09-27 20:39           ` [linux-pm] " Alan Stern
2010-09-27 21:09             ` Rafael J. Wysocki
2010-09-28 14:55               ` Alan Stern
2010-09-28 18:19                 ` Rafael J. Wysocki
2010-09-28 18:19                 ` [linux-pm] " Rafael J. Wysocki
2010-09-30 18:25                   ` [PATCH] PM: add synchronous runtime interface for interrupt handlers Alan Stern
2010-09-30 20:15                     ` Rafael J. Wysocki
2010-09-30 20:15                     ` Rafael J. Wysocki
2010-09-30 21:42                       ` Alan Stern
2010-09-30 21:42                       ` Alan Stern
2010-09-30 21:42                       ` Alan Stern
2010-09-30 22:41                         ` Rafael J. Wysocki
2010-10-01 14:28                           ` Alan Stern
2010-10-01 14:28                           ` Alan Stern
2010-10-01 21:23                             ` Rafael J. Wysocki
2010-10-02 14:12                               ` Alan Stern
2010-10-02 22:06                                 ` Rafael J. Wysocki
2010-10-03 15:52                                   ` Alan Stern
2010-10-03 20:33                                     ` Rafael J. Wysocki
2010-10-03 20:33                                     ` Rafael J. Wysocki
2010-10-03 15:52                                   ` Alan Stern
2010-10-08 23:24                                   ` PATCH: PM / Runtime: Remove idle notification after failing suspend (was: Re: [PATCH] PM: add synchronous ...) Rafael J. Wysocki
2010-10-08 23:24                                   ` PATCH: PM / Runtime: Remove idle notification after failing suspend (was: Re: [linux-pm] " Rafael J. Wysocki
2010-10-10 20:18                                     ` Alan Stern
2010-10-10 20:18                                     ` PATCH: PM / Runtime: Remove idle notification after failing suspend (was: " Alan Stern
2010-10-02 22:06                                 ` [PATCH] PM: add synchronous runtime interface for interrupt handlers Rafael J. Wysocki
2010-10-05 21:44                                 ` Kevin Hilman
2010-10-06 15:58                                   ` Alan Stern
2010-10-06 19:33                                     ` Rafael J. Wysocki
2010-10-06 19:33                                     ` Rafael J. Wysocki
2010-10-06 19:35                                     ` Kevin Hilman
2010-10-06 20:28                                       ` Alan Stern
2010-10-06 20:28                                       ` Alan Stern
2010-10-06 21:47                                         ` Rafael J. Wysocki
2010-10-07 15:26                                           ` Alan Stern
2010-10-07 15:26                                           ` Alan Stern
2010-10-07 16:52                                             ` Kevin Hilman
2010-10-07 17:35                                               ` Alan Stern
2010-10-07 21:11                                                 ` Rafael J. Wysocki
2010-10-07 23:15                                                   ` Kevin Hilman
2010-10-07 23:37                                                     ` Rafael J. Wysocki
2010-10-07 23:37                                                     ` Rafael J. Wysocki
2010-10-07 23:55                                                       ` Kevin Hilman
2010-10-08 16:22                                                         ` Alan Stern
2010-10-08 16:22                                                         ` Alan Stern
2010-10-08 21:04                                                           ` Kevin Hilman
2010-10-08 21:04                                                           ` Kevin Hilman
2010-10-08 19:57                                                         ` Rafael J. Wysocki
2010-10-08 19:57                                                         ` Rafael J. Wysocki
2010-10-07 23:55                                                       ` Kevin Hilman
2010-10-07 23:15                                                   ` Kevin Hilman
2010-10-08 16:18                                                   ` Alan Stern
2010-10-08 19:53                                                     ` Rafael J. Wysocki
2010-10-08 19:53                                                     ` Rafael J. Wysocki
2010-10-09 11:09                                                       ` Rafael J. Wysocki
2010-10-09 11:09                                                       ` [linux-pm] " Rafael J. Wysocki
2010-10-11 17:00                                                         ` Alan Stern
2010-10-11 22:30                                                           ` Rafael J. Wysocki
2010-10-11 22:30                                                           ` Rafael J. Wysocki
2010-10-11 17:00                                                         ` Alan Stern
2010-10-08 16:18                                                   ` Alan Stern
2010-10-07 21:11                                                 ` Rafael J. Wysocki
2010-10-07 17:35                                               ` Alan Stern
2010-10-07 16:52                                             ` Kevin Hilman
2010-11-19 15:45                                           ` [PATCH ver. 2] " Alan Stern
2010-11-20 12:56                                             ` Rafael J. Wysocki
2010-11-20 16:59                                               ` Alan Stern
2010-11-20 16:59                                               ` Alan Stern
2010-11-20 19:41                                                 ` [linux-pm] " Alan Stern
2010-11-21 23:45                                                   ` Rafael J. Wysocki
2010-11-21 23:45                                                   ` [linux-pm] " Rafael J. Wysocki
2010-11-20 19:41                                                 ` Alan Stern
2010-11-21 23:41                                                 ` Rafael J. Wysocki
2010-11-21 23:41                                                 ` Rafael J. Wysocki
2010-11-22 15:38                                                   ` Alan Stern
2010-11-22 15:38                                                   ` Alan Stern
2010-11-22 23:01                                                     ` Rafael J. Wysocki
2010-11-23  3:19                                                       ` Alan Stern
2010-11-23 22:51                                                         ` Rafael J. Wysocki
2010-11-23 22:51                                                         ` Rafael J. Wysocki
2010-11-24  0:11                                                           ` Kevin Hilman
2010-11-24  0:11                                                           ` Kevin Hilman
2010-11-24 16:43                                                             ` Alan Stern
2010-11-24 16:43                                                             ` Alan Stern
2010-11-24 18:03                                                               ` Kevin Hilman
2010-11-24 18:03                                                               ` Kevin Hilman
2010-11-24 14:56                                                           ` Alan Stern
2010-11-24 14:56                                                           ` Alan Stern
2010-11-24 20:33                                                             ` Rafael J. Wysocki
2010-11-24 20:33                                                             ` Rafael J. Wysocki
2010-11-25 15:52                                                               ` [PATCH ver. 3] " Alan Stern
2010-11-25 15:52                                                               ` Alan Stern
2010-11-25 18:58                                                                 ` Oliver Neukum
2010-11-25 18:58                                                                 ` [linux-pm] " Oliver Neukum
2010-11-25 20:03                                                                   ` Rafael J. Wysocki
2010-11-25 20:03                                                                   ` [linux-pm] " Rafael J. Wysocki
2010-11-26 22:23                                                                 ` Rafael J. Wysocki
2010-11-26 22:23                                                                 ` Rafael J. Wysocki
2010-11-23  3:19                                                       ` [PATCH ver. 2] " Alan Stern
2010-11-22 23:01                                                     ` Rafael J. Wysocki
2010-11-20 12:56                                             ` Rafael J. Wysocki
2010-11-19 15:45                                           ` Alan Stern
2011-04-11 15:47                                             ` Sylwester Nawrocki
2011-04-11 16:08                                               ` Alan Stern
2011-04-11 17:20                                                 ` Sylwester Nawrocki
2011-04-11 18:37                                                   ` Alan Stern
2010-10-06 21:47                                         ` [PATCH] " Rafael J. Wysocki
2010-10-06 23:51                                         ` Kevin Hilman
2010-10-06 23:51                                         ` Kevin Hilman
2010-10-06 19:35                                     ` Kevin Hilman
2010-10-06 15:58                                   ` Alan Stern
2010-10-05 21:44                                 ` Kevin Hilman
2010-10-02 14:12                               ` Alan Stern
2010-09-30 22:41                         ` Rafael J. Wysocki
2010-09-30 22:02                     ` Rafael J. Wysocki
2010-10-01 14:12                       ` Alan Stern
2010-10-01 21:14                         ` Rafael J. Wysocki
2010-10-01 21:14                         ` Rafael J. Wysocki
2010-10-01 22:37                           ` [PATCH] PM / Runtime: Reduce code duplication in core helper functions (was: Re: [PATCH] PM: add synchronous ...) Rafael J. Wysocki
2010-10-01 22:37                           ` [PATCH] PM / Runtime: Reduce code duplication in core helper functions (was: Re: [linux-pm] " Rafael J. Wysocki
2010-10-02 14:15                             ` Alan Stern
2010-10-02 14:15                             ` [PATCH] PM / Runtime: Reduce code duplication in core helper functions (was: " Alan Stern
2010-10-01 14:12                       ` [PATCH] PM: add synchronous runtime interface for interrupt handlers Alan Stern
2010-09-30 18:25                   ` Alan Stern
2010-09-28 14:55               ` runtime_pm_get_sync() from ISR with IRQs disabled? Alan Stern
2010-09-27 21:09             ` Rafael J. Wysocki
2010-09-27 21:11             ` [linux-pm] " Kevin Hilman
2010-09-27 21:11             ` Kevin Hilman
2010-09-24 20:04     ` Rafael J. Wysocki
2010-09-24 20:27     ` [linux-pm] " Alan Stern
2010-09-24 21:52       ` Kevin Hilman
2010-09-24 21:52       ` Kevin Hilman [this message]
2010-09-24 20:27     ` Alan Stern
2010-09-24 15:13 ` Alan Stern

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=87lj6q3j2r.fsf@deeprootsystems.com \
    --to=khilman@deeprootsystems.com \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=p-basak2@ti.com \
    --cc=stern@rowland.harvard.edu \
    /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.