Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754072Ab0AXQhV (ORCPT ); Sun, 24 Jan 2010 11:37:21 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754045Ab0AXQhS (ORCPT ); Sun, 24 Jan 2010 11:37:18 -0500 Received: from netrider.rowland.org ([192.131.102.5]:37801 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1753874Ab0AXQhR (ORCPT ); Sun, 24 Jan 2010 11:37:17 -0500 Date: Sun, 24 Jan 2010 11:37:14 -0500 (EST) From: Alan Stern X-X-Sender: stern@netrider.rowland.org To: "Rafael J. Wysocki" cc: LKML , Linus Torvalds , Linux PCI , pm list , , Greg KH , Jesse Barnes , James Bottomley , Linux SCSI , Arjan van de Ven , ACPI Devel Maling List , Len Brown , Nigel Cunningham Subject: Re: [PATCH 2/8] PM: Asynchronous suspend and resume of devices In-Reply-To: <201001240035.37550.rjw@sisk.pl> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2307 Lines: 54 On Sun, 24 Jan 2010, Rafael J. Wysocki wrote: > The async threads started for different devices as a result of > calling async_schedule() are synchronized with each other and with > the main suspend/resume thread with the help of completions, in the > following way: > (1) There is a completion, power.completion, for each device object. > (2) Each device's completion is reset before calling async_schedule() > for the device or, in the case of devices with the > power.async_suspend flags unset, before executing the device's > suspend and resume callbacks. > (3) During suspend, right before running the bus type, device type > and device class suspend callbacks for the device, the PM core > waits for the completions of all the device's children to be > completed. > (4) During resume, right before running the bus type, device type and > device class resume callbacks for the device, the PM core waits > for the completion of the device's parent to be completed. > (5) The PM core completes power.completion for each device right > after the bus type, device type and device class suspend (or > resume) callbacks executed for the device have returned. ... > /** > + * dpm_wait - Wait for a PM operation to complete. > + * @dev: Device to wait for. > + * @async: If unset, wait only if the device's power.async_suspend flag is set. > + */ > +static void dpm_wait(struct device *dev, bool async) > +{ > + if (!dev) > + return; > + > + if (async || dev->power.async_suspend) > + wait_for_completion(&dev->power.completion); > +} There needs to be a public interface to this function available for drivers that have non-tree constraints. The arguments should be the device to wait for and the device doing the waiting (needed only to determine whether the caller is running synchronously or not). This will be necessary for USB. In fact, your current code (with patch 7/8 applied) is subject to a race that will sometimes cause a non-high-speed USB device to fail to resume from hibernation. Alan Stern -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/