All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: linux-pm@lists.linux-foundation.org,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"Neil Brown" <neilb@suse.de>,
	"Matthew Garrett" <mjg59@srcf.ucam.org>,
	"mark gross" <640e9920@gmail.com>,
	"Arve Hjønnevåg" <arve@android.com>,
	"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
	"Florian Mickler" <florian@mickler.org>,
	linux-pci@vger.kernel.org,
	"Jesse Barnes" <jbarnes@virtuousgeek.org>
Subject: Re: [PATCH] PM: Make it possible to avoid wakeup events from being lost
Date: Mon, 28 Jun 2010 01:59:10 +0200	[thread overview]
Message-ID: <201006280159.10885.rjw@sisk.pl> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1006271142190.3772-100000@netrider.rowland.org>

On Sunday, June 27, 2010, Alan Stern wrote:
> On Sat, 26 Jun 2010, Rafael J. Wysocki wrote:
> 
> > +void pm_relax(void)
> > +{
> > +	unsigned long flags;
> > +
> > +	spin_lock_irqsave(&events_lock, flags);
> > +	if (events_in_progress) {
> > +		event_count++;
> > +		if (!--events_in_progress)
> > +			wake_up_all(&events_wait_queue);
> > +	}
> > +	spin_unlock_irqrestore(&events_lock, flags);
> > +}
> 
> > +bool pm_get_wakeup_count(unsigned long *count)
> > +{
> > +	bool ret;
> > +
> > +	spin_lock_irq(&events_lock);
> > +	if (capable(CAP_SYS_ADMIN))
> > +		events_check_enabled = false;
> > +
> > +	if (events_in_progress) {
> > +		DEFINE_WAIT(wait);
> > +
> > +		do {
> > +			prepare_to_wait(&events_wait_queue, &wait,
> > +					TASK_INTERRUPTIBLE);
> > +			if (!events_in_progress)
> > +				break;
> > +			spin_unlock_irq(&events_lock);
> > +
> > +			schedule();
> > +
> > +			spin_lock_irq(&events_lock);
> > +		} while (!signal_pending(current));
> > +		finish_wait(&events_wait_queue, &wait);
> > +	}
> > +	*count = event_count;
> > +	ret = !events_in_progress;
> > +	spin_unlock_irq(&events_lock);
> > +	return ret;
> > +}
> 
> Here's a thought.  Presumably pm_relax() will end up getting called a 
> lot more often than pm_get_wakeup_count().  Instead of using a wait 
> queue, you could make pm_get_wakeup_count() poll at 100-ms intervals.  
> The total overhead would be smaller.

For that I'd need a separate kernel thread or a work item that would reschedule
itself periodically, because pm_get_wakeup_count() is only called via
/sys/power/wakeup_count.  It would complicate things quite a bit which I'm not
sure is worth it at this point.

> Here's another thought.  If event_count and events_in_progress were 
> atomic_t then the new spinlock wouldn't be needed at all.  (But you 
> would need an appropriate pair of memory barriers, to guarantee that 
> when a writer decrements events_in_progress to 0 and increments 
> event_count, a reader won't see events_in_progress == 0 without also 
> seeing the incremented event_count.)  Overall, this may not be a
> significant improvement.

No, I don't think it would be significant.  Still, we can go back to this
if the spinlock turns out to be a problem in future.

Rafael

  parent reply	other threads:[~2010-06-28  0:01 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-26 13:14 [PATCH] PM: Make it possible to avoid wakeup events from being lost Rafael J. Wysocki
2010-06-27 15:50 ` Alan Stern
2010-06-27 23:59   ` Rafael J. Wysocki
2010-06-27 23:59   ` Rafael J. Wysocki [this message]
2010-06-28 14:16     ` Alan Stern
2010-06-28 19:01       ` [update] " Rafael J. Wysocki
2010-06-28 19:01       ` Rafael J. Wysocki
2010-06-28 19:11         ` Jesse Barnes
2010-06-28 19:11         ` Jesse Barnes
2010-06-28 19:19         ` Alan Stern
2010-06-28 21:19           ` Rafael J. Wysocki
2010-06-28 21:19           ` Rafael J. Wysocki
2010-06-28 19:19         ` Alan Stern
2010-06-28 20:38         ` Greg KH
2010-06-28 20:38         ` Greg KH
2010-06-30  7:10         ` Florian Mickler
2010-06-30  7:10         ` Florian Mickler
2010-06-30 13:47           ` mark gross
2010-06-30 13:47           ` mark gross
2010-06-30 18:00         ` Alan Stern
2010-06-30 19:27           ` Rafael J. Wysocki
2010-06-30 19:27           ` Rafael J. Wysocki
2010-06-30 19:58             ` Alan Stern
2010-06-30 19:58             ` Alan Stern
2010-06-30 23:52               ` Rafael J. Wysocki
2010-07-01 13:58                 ` Alan Stern
2010-07-01 13:58                 ` Alan Stern
2010-07-01 20:08                   ` Rafael J. Wysocki
2010-07-01 20:08                   ` Rafael J. Wysocki
2010-07-01 20:44                     ` Alan Stern
2010-07-01 20:44                     ` Alan Stern
2010-07-01 21:05                       ` Rafael J. Wysocki
2010-07-01 21:05                       ` Rafael J. Wysocki
2010-06-30 23:52               ` Rafael J. Wysocki
2010-06-30 18:00         ` Alan Stern
2010-06-28 14:16     ` Alan Stern
2010-06-28 23:28     ` David Brownell
2010-06-28 23:28     ` [linux-pm] " David Brownell
2010-06-29 19:57       ` Alan Stern
2010-06-29 19:57       ` [linux-pm] " Alan Stern
2010-06-27 15:50 ` Alan Stern
2010-06-27 22:28 ` mark gross
2010-06-28 12:50   ` Rafael J. Wysocki
2010-06-29  4:43     ` mark gross
2010-06-29  4:43     ` mark gross
2010-06-28 12:50   ` Rafael J. Wysocki
2010-06-27 22:28 ` mark gross
2010-07-01 13:32 ` Pavel Machek
2010-07-01 13:32 ` Pavel Machek
2010-07-01 15:08   ` Florian Mickler
2010-07-01 15:08   ` Florian Mickler
2010-07-01 19:02   ` Rafael J. Wysocki
2010-07-02 18:14     ` Pavel Machek
2010-07-02 18:14     ` Pavel Machek
2010-07-02 19:21       ` Rafael J. Wysocki
2010-07-02 19:21       ` Rafael J. Wysocki
2010-07-01 19:02   ` Rafael J. Wysocki
  -- strict thread matches above, loose matches on Subject: below --
2010-06-27  2:43 [linux-pm] " David Brownell
2010-06-27  3:06 ` Alan Stern
2010-06-26 18:21 [linux-pm] " Rafael J. Wysocki
2010-06-26 19:58 ` Alan Stern
2010-06-26 17:14 [linux-pm] " Alan Stern
2010-06-26 18:21 ` Rafael J. Wysocki
2010-06-27  2:43 ` David Brownell
2010-06-26 16:54 [linux-pm] " David Brownell
2010-06-26 17:14 ` Alan Stern
2010-06-26 18:20 ` Rafael J. Wysocki
2010-06-26 16:54 David Brownell
2010-06-26 13:14 Rafael J. Wysocki

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=201006280159.10885.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=640e9920@gmail.com \
    --cc=arve@android.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=florian@mickler.org \
    --cc=jbarnes@virtuousgeek.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=mjg59@srcf.ucam.org \
    --cc=neilb@suse.de \
    --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.