From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Rafael J. Wysocki" Subject: Re: [RFC][PATCH] PM: Introduce new top level suspend and hibernation callbacks (rev. 2) Date: Sun, 23 Mar 2008 19:41:39 +0100 Message-ID: <200803231941.41079.rjw@sisk.pl> References: Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Return-path: Received: from ogre.sisk.pl ([217.79.144.158]:51499 "EHLO ogre.sisk.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751941AbYCWSmY (ORCPT ); Sun, 23 Mar 2008 14:42:24 -0400 In-Reply-To: Content-Disposition: inline Sender: linux-acpi-owner@vger.kernel.org List-Id: linux-acpi@vger.kernel.org To: Alan Stern Cc: pm list , ACPI Devel Maling List , Greg KH , Len Brown , LKML , Alexey Starikovskiy , David Brownell , Pavel Machek , Benjamin Herrenschmidt On Sunday, 23 of March 2008, Alan Stern wrote: > On Sun, 23 Mar 2008, Rafael J. Wysocki wrote: > > > On Sunday, 23 of March 2008, Alan Stern wrote: > > > On Sat, 22 Mar 2008, Rafael J. Wysocki wrote: > > > > > [--snip--] > > > > > > No, you have missed the entire point. The problem doesn't exist in the > > > current code; it exists only if we switch over to using a single list. > > > Routines like dpm_suspend() won't be able to use list_for_each_entry() > > > to traverse the list because entries may be removed by other threads > > > during the traversal. Even list_for_each_entry_safe() won't work > > > correctly without careful attention to details. > > > > Ah, ok. Thanks for the clarification. > > > > Doesn't it help that we traverse the list under dpm_list_mtx? Anyone who > > removes an entry is required to take dpm_list_mtx that we're holding while > > the list is traversed except when the callbacks are invoked. > > It doesn't help. What _does_ help is the fact that these traversals > are all serialized (since only one thread can carry out a system sleep > at any time). > > > The only problem I see is when the device currently being handled is removed > > from the list by a concurrent thread. Is that you were referring to? > > Yes, that is the problem. If you try to work around it by using > list_for_each_entry_safe() then you run into a problem when a > concurrent thread removes the device _following_ the one being handled > (or when the device being handled is the last one on the list and a > concurrent thread registers a new device, which can only happen in > dpm_prepare()). > > It's not hard to fix. Just something to be aware of. Yes, I've almost finished a new patch taking that into account. I'll send it soon in a separate thread. > P.S.: Oh yes, another related issue... We should call get_device() and > put_device() while holding dpm_list_mtx. Otherwise the device > structure might vanish when the callbacks are invoked. Good idea. Thanks, Rafael