1. Oct 17, 2010
    • James Hogan's avatar
      PM: Add sysfs attr for rechecking dev hash from PM trace · d33ac60b
      James Hogan authored
      
      
      If the device which fails to resume is part of a loadable kernel module
      it won't be checked at startup against the magic number stored in the
      RTC.
      
      Add a read-only sysfs attribute /sys/power/pm_trace_dev_match which
      contains a list of newline separated devices (usually just the one)
      which currently match the last magic number. This allows the device
      which is failing to resume to be found after the modules are loaded
      again.
      
      Signed-off-by: default avatarJames Hogan <james@albanarts.com>
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      d33ac60b
    • James Hogan's avatar
      PM: Lock PM device list mutex in show_dev_hash() · 2ac21c6b
      James Hogan authored
      
      
      Lock the PM device list mutex using device_pm_lock() and
      device_pm_unlock() around the list iteration in show_dev_hash().
      
      show_dev_hash() was reverse iterating dpm_list without first locking the
      mutex that the functions in drivers/base/power/main.c lock. I assume
      this was unintentional since there is no comment suggesting why the lock
      might not be necessary.
      
      Signed-off-by: default avatarJames Hogan <james@albanarts.com>
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      2ac21c6b
    • Rafael J. Wysocki's avatar
      PM / Runtime: Remove idle notification after failing suspend · f71648d7
      Rafael J. Wysocki authored
      
      
      If runtime suspend of a device fails returning -EAGAIN or -EBUSY,
      which means that it's safe to try to suspend it again, the PM core
      runs the runtime idle helper function for it.  Unfortunately this may
      lead to problems, for example for PCI devices whose drivers don't
      implement the ->runtime_idle() callback, because in that case the
      PCI bus type's ->runtime_idle() always calls pm_runtime_suspend()
      for the given device.  Then, if there's an automatic idle
      notification after the driver's ->runtime_suspend() returning -EAGAIN
      or -EBUSY, it will make the suspend happen again possibly causing a
      busy loop to appear.  To avoid that, remove the idle notification
      after failing runtime suspend of a device altogether and let the
      callers of pm_runtime_suspend() repeat the operation if need be.
      
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      f71648d7
    • Rafael J. Wysocki's avatar
      PM / Hibernate: Modify signature used to mark swap · 3624eb04
      Rafael J. Wysocki authored
      
      
      Since we are adding compression to the kernel's hibernate code,
      change signature used by it to mark swap spaces, so that earlier
      kernels don't attempt to restore compressed images they cannot
      handle.
      
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      Acked-by: default avatarPavel Machek <pavel@ucw.cz>
      3624eb04
    • Rafael J. Wysocki's avatar
      PM / Runtime: Reduce code duplication in core helper functions · 71c63122
      Rafael J. Wysocki authored
      
      
      Reduce code duplication in rpm_idle(), rpm_suspend() and rpm_resume()
      by using local pointers to store callback addresses and moving some
      duplicated code into a separate function.
      
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      Reviewed-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      71c63122
    • Rafael J. Wysocki's avatar
      PM: Allow wakeup events to abort freezing of tasks · dbeeec5f
      Rafael J. Wysocki authored
      
      
      If there is a wakeup event during the freezing of tasks, suspend or
      hibernation will fail anyway.  Since try_to_freeze_tasks() can take
      up to 20 seconds to complete or fail, aborting it as soon as a wakeup
      event is detected improves the worst case wakeup latency.
      
      Based on a patch from Arve Hjønnevåg.
      
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      Acked-by: default avatarPavel Machek <pavel@ucw.cz>
      dbeeec5f
    • Ming Lei's avatar
      PM: runtime: add missed pm_request_autosuspend · 5fc62aad
      Ming Lei authored
      
      
      The patch "PM / Runtime: Implement autosuspend support" introduces
      "autosuspend" facility for runtime PM, but misses helper function
      of pm_request_autosuspend, so add it.
      
      Signed-off-by: default avatarMing Lei <tom.leiming@gmail.com>
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      5fc62aad
    • Rafael J. Wysocki's avatar
      PM / Hibernate: Make some boot messages look less scary · d0941ead
      Rafael J. Wysocki authored
      
      
      The hibernate resume code checks if there is an image to resume from
      on every boot and, if the kernel is built with CONFIG_PM_DEBUG set
      and the image is not present, it prints some scary messages
      suggesting there was a boot error of some sort.  Apparently, some
      users are confused by them, so make them look less scary and adjust
      the other hibernate resume debug messages to match them.
      
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      d0941ead
    • Alan Stern's avatar
      PM / Runtime: Implement autosuspend support · 15bcb91d
      Alan Stern authored
      
      
      This patch (as1427) implements the "autosuspend" facility for runtime
      PM.  A few new fields are added to the dev_pm_info structure and
      several new PM helper functions are defined, for telling the PM core
      whether or not a device uses autosuspend, for setting the autosuspend
      delay, and for marking periods of device activity.
      
      Drivers that do not want to use autosuspend can continue using the
      same helper functions as before; their behavior will not change.  In
      addition, drivers supporting autosuspend can also call the old helper
      functions to get the old behavior.
      
      The details are all explained in Documentation/power/runtime_pm.txt
      and Documentation/ABI/testing/sysfs-devices-power.
      
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      15bcb91d
    • Alan Stern's avatar
      PM / Runtime: Add no_callbacks flag · 7490e442
      Alan Stern authored
      
      
      Some devices, such as USB interfaces, cannot be power-managed
      independently of their parents, i.e., they cannot be put in low power
      while the parent remains at full power.  This patch (as1425) creates a
      new "no_callbacks" flag, which tells the PM core not to invoke the
      runtime-PM callback routines for the such devices but instead to
      assume that the callbacks always succeed.  In addition, the
      non-debugging runtime-PM sysfs attributes for the devices are removed,
      since they are pretty much meaningless.
      
      The advantage of this scheme comes not so much from avoiding the
      callbacks themselves, but rather from the fact that without the need
      for a process context in which to run the callbacks, more work can be
      done in interrupt context.
      
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      7490e442
    • Alan Stern's avatar
      PM / Runtime: Combine runtime PM entry points · 140a6c94
      Alan Stern authored
      
      
      This patch (as1424) combines the various public entry points for the
      runtime PM routines into three simple functions: one for idle, one for
      suspend, and one for resume.  A new bitflag specifies whether or not
      to increment or decrement the usage_count field.
      
      The new entry points are named __pm_runtime_idle,
      __pm_runtime_suspend, and __pm_runtime_resume, to reflect that they
      are trampolines.  Simultaneously, the corresponding internal routines
      are renamed to rpm_idle, rpm_suspend, and rpm_resume.
      
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      140a6c94
    • Alan Stern's avatar
      PM / Runtime: Merge synchronous and async runtime routines · 1bfee5bc
      Alan Stern authored
      
      
      This patch (as1423) merges the asynchronous routines
      __pm_request_idle(), __pm_request_suspend(), and __pm_request_resume()
      with their synchronous counterparts.  The RPM_ASYNC bitflag argument
      serves to indicate what sort of operation to perform.
      
      In the course of performing this merger, it became apparent that the
      various functions don't all behave consistenly with regard to error
      reporting and cancellation of outstanding requests.  A new routine,
      rpm_check_suspend_allowed(), was written to centralize much of the
      testing, and the other functions were revised to follow a simple
      algorithm:
      
      	If the operation is disallowed because of the device's
      	settings or current state, return an error.
      
      	Cancel pending or scheduled requests of lower priority.
      
      	Schedule, queue, or perform the desired operation.
      
      A few special cases and exceptions are noted in comments.
      
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      1bfee5bc
    • Alan Stern's avatar
      PM / Runtime: Replace boolean arguments with bitflags · 3f9af051
      Alan Stern authored
      
      
      The "from_wq" argument in __pm_runtime_suspend() and
      __pm_runtime_resume() supposedly indicates whether or not the function
      was called by the PM workqueue thread, but in fact it isn't always
      used this way.  It really indicates whether or not the function should
      return early if the requested operation is already in progress.
      
      Along with this badly-named boolean argument, later patches in this
      series will add several other boolean arguments to these functions and
      others.  Therefore this patch (as1422) begins the conversion process
      by replacing from_wq with a bitflag argument.  The same bitflags are
      also used in __pm_runtime_get() and __pm_runtime_put(), where they
      indicate whether or not the operation should be asynchronous.
      
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      3f9af051
    • Alan Stern's avatar
      PM / Runtime: Move code in drivers/base/power/runtime.c · 4769373c
      Alan Stern authored
      
      
      This patch (as1421) moves the PM runtime accounting subroutines up to
      the beginning of runtime.c, taking them out of the middle of the
      functions that do the actual work.  No operational changes.
      
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      4769373c
    • Alan Stern's avatar
      sysfs: Add sysfs_merge_group() and sysfs_unmerge_group() · 69d44ffb
      Alan Stern authored
      
      
      This patch (as1420) adds sysfs_merge_group() and sysfs_unmerge_group()
      functions, allowing drivers easily to add and remove sets of
      attributes to a pre-existing attribute group directory.
      
      Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
      Acked-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      69d44ffb
    • Rafael J. Wysocki's avatar
      PM: Fix potential issue with failing asynchronous suspend · 098dff73
      Rafael J. Wysocki authored
      
      
      There is a potential issue with the asynchronous suspend code that
      a device driver suspending asynchronously may not notice that it
      should back off.  There are two failing scenarions, (1) when the
      driver is waiting for a driver suspending synchronously to complete
      and that second driver returns error code, in which case async_error
      won't be set and the waiting driver will continue suspending and (2)
      after the driver has called device_pm_wait_for_dev() and the waited
      for driver returns error code, in which case the caller of
      device_pm_wait_for_dev() will not know that there was an error and
      will continue suspending.
      
      To fix this issue make __device_suspend() set async_error, so
      async_suspend() doesn't need to set it any more, and make
      device_pm_wait_for_dev() return async_error, so that its callers
      can check whether or not they should continue suspending.
      
      No more changes are necessary, since device_pm_wait_for_dev() is
      not used by any drivers' suspend routines.
      
      Reported-by: default avatarColin Cross <ccross@android.com>
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      Acked-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
      098dff73
    • Rafael J. Wysocki's avatar
      PM / Wakeup: Introduce wakeup source objects and event statistics (v3) · 074037ec
      Rafael J. Wysocki authored
      
      
      Introduce struct wakeup_source for representing system wakeup sources
      within the kernel and for collecting statistics related to them.
      Make the recently introduced helper functions pm_wakeup_event(),
      pm_stay_awake() and pm_relax() use struct wakeup_source objects
      internally, so that wakeup statistics associated with wakeup devices
      can be collected and reported in a consistent way (the definition of
      pm_relax() is changed, which is harmless, because this function is
      not called directly by anyone yet).  Introduce new wakeup-related
      sysfs device attributes in /sys/devices/.../power for reporting the
      device wakeup statistics.
      
      Change the global wakeup events counters event_count and
      events_in_progress into atomic variables, so that it is not necessary
      to acquire a global spinlock in pm_wakeup_event(), pm_stay_awake()
      and pm_relax(), which should allow us to avoid lock contention in
      these functions on SMP systems with many wakeup devices.
      
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      Acked-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
      074037ec
    • Kevin Cernekee's avatar
      PM: Fix signed/unsigned warning in dpm_show_time() · 0702d9ee
      Kevin Cernekee authored
      
      
      Seen on MIPS32, gcc 4.4.3, 2.6.36-rc4:
      
      drivers/base/power/main.c: In function 'dpm_show_time':
      drivers/base/power/main.c:415: warning: comparison of distinct pointer types lacks a cast
      
      do_div() takes unsigned parameters:
      
      uint32_t do_div(uint64_t *n, uint32_t base);
      
      Using an unsigned variable for usecs64 should not cause any problems,
      because calltime >= starttime .
      
      Signed-off-by: default avatarKevin Cernekee <cernekee@gmail.com>
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      0702d9ee
    • Rafael J. Wysocki's avatar
      PM / Hibernate: Make default image size depend on total RAM size · ac5c24ec
      Rafael J. Wysocki authored
      
      
      The default hibernation image size is currently hard coded and euqal
      to 500 MB, which is not a reasonable default on many contemporary
      systems.  Make it equal 2/5 of the total RAM size (this is slightly
      below the maximum, i.e. 1/2 of the total RAM size, and seems to be
      generally suitable).
      
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      Tested-by: default avatarM. Vefa Bicakci <bicave@superonline.com>
      ac5c24ec
    • Rafael J. Wysocki's avatar
      PM / Hibernate: Improve comments in hibernate_preallocate_memory() · 266f1a25
      Rafael J. Wysocki authored
      
      
      One comment in hibernate_preallocate_memory() is wrong, so fix it and
      add one more comment to clarify the meaning of the fixed one.
      
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      266f1a25
    • Rafael J. Wysocki's avatar
      PM / Runtime: Use alloc_workqueue() for creating the PM workqueue · bcb5ba8b
      Rafael J. Wysocki authored
      
      
      Although we need the PM workqueue to be freezable, we don't need it
      to be singlethread.  Also, the number of concurrent work items
      running on a single CPU need not be constrained.  For these reasons
      use alloc_workqueue() directly, with suitable arguments, instead of
      create_freezeable_workqueue(), to create the runtime PM workqueue.
      
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      Acked-by: default avatarTejun Heo <tj@kernel.org>
      bcb5ba8b
    • Rafael J. Wysocki's avatar
      PM: Fix unmet dependency warning from kconfig · ede890c2
      Rafael J. Wysocki authored
      
      
      Fix the following build warning:
      
      warning: (PM_SLEEP_SMP && SMP && (ARCH_SUSPEND_POSSIBLE || \
      ARCH_HIBERNATION_POSSIBLE) && PM_SLEEP) selects HOTPLUG_CPU which \
      has unmet direct dependencies (SMP && HOTPLUG)
      
      by selecting HOTPLUG along with CPU_HOTPLUG.
      
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      Acked-by: default avatarRandy Dunlap <randy.dunlap@oracle.com>
      ede890c2
    • Bojan Smojver's avatar
      PM / Hibernate: Compress hibernation image with LZO · f996fc96
      Bojan Smojver authored
      
      
      Compress hibernation image with LZO in order to save on I/O and
      therefore time to hibernate/thaw.
      
      [rjw: Added hibernate=nocompress command line option instead of just
       nocompress which would be confusing, fixed a couple of compiler
       warnings, fixed kerneldoc comments, minor cleanups.]
      
      Signed-off-by: default avatarBojan Smojver <bojan@rexursive.com>
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      f996fc96
    • Ohad Ben-Cohen's avatar
      PM / Runtime: Lenient generic runtime pm callbacks · 05aa55dd
      Ohad Ben-Cohen authored
      
      
      Allow drivers, that belong to subsystems which use the generic
      runtime pm callbacks, not to define runtime pm suspend/resume handlers,
      by implicitly assuming success in such cases.
      
      This is needed to eliminate nop handlers that would otherwise be
      necessary by drivers which enable runtime pm, but don't need
      to do anything when their devices are runtime-suspended/resumed.
      
      Signed-off-by: default avatarOhad Ben-Cohen <ohad@wizery.com>
      Acked-by: default avatarKevin Hilman <khilman@deeprootsystems.com>
      Acked-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
      Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
      05aa55dd
  2. Oct 16, 2010
  3. Oct 15, 2010