lkml.org 
[lkml]   [2011]   [Jan]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH 1/3] PM / Wakeup: Add missing memory barriers
Date
On Wednesday, January 26, 2011, Alan Stern wrote:
> On Tue, 25 Jan 2011, Rafael J. Wysocki wrote:
>
> > From: Rafael J. Wysocki <rjw@sisk.pl>
> >
> > The memory barrier in wakeup_source_deactivate() is supposed to
> > prevent the callers of pm_wakeup_pending() and pm_get_wakeup_count()
> > from seeing the new value of events_in_progress (0, in particular)
> > and the old value of event_count at the same time. However, if
> > wakeup_source_deactivate() is executed by CPU0 and, for instance,
> > pm_wakeup_pending() is executed by CPU1, where both processors can
> > reorder operations, the memory barrier in wakeup_source_deactivate()
> > doesn't affect CPU1 which can reorder reads. In that case CPU1 may
> > very well decide to fetch event_count before it's modified and
> > events_in_progress after it's been updated, so pm_wakeup_pending()
> > may fail to detect a wakeup event. This issue can be addressed by
> > adding a read memory barrier in pm_wakeup_pending() that will enforce
> > events_in_progress to be read before event_count.
> >
> > For similar reason, a read memory barrier should be added to
> > pm_get_wakeup_count().
>
> How come this is implemented using memory barriers rather than a lock?
> Is it because this is potentially a fairly hot path?

Yes, that's the reason.

> New memory barriers are supposed to have comments present in the code,
> explaining why they are needed.

Of course I can add them.

> Ideally you could do away with the need for synchronization entirely.
> For example, events_in_progress and event_count could be stored as two
> 16-bit values stuffed into a single atomic variable. Then they could
> both be read or updated simultaneously.

I thought about that too, but didn't actually implement it.

Well, I guess it would be better.

Thanks,
Rafael


\
 
 \ /
  Last update: 2011-01-26 21:39    [W:0.046 / U:0.040 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site