1. 05 4月, 2019 1 次提交
  2. 20 3月, 2019 1 次提交
    • J
      PM / Domains: Avoid a potential deadlock · 2071ac98
      Jiada Wang 提交于
      Lockdep warns that prepare_lock and genpd->mlock can cause a deadlock
      the deadlock scenario is like following:
      First thread is probing cs2000
      cs2000_probe()
        clk_register()
          __clk_core_init()
            clk_prepare_lock()                            ----> acquires prepare_lock
              cs2000_recalc_rate()
                i2c_smbus_read_byte_data()
                  rcar_i2c_master_xfer()
                    dma_request_chan()
                      rcar_dmac_of_xlate()
                        rcar_dmac_alloc_chan_resources()
                          pm_runtime_get_sync()
                            __pm_runtime_resume()
                              rpm_resume()
                                rpm_callback()
                                  genpd_runtime_resume()   ----> acquires genpd->mlock
      
      Second thread is attaching any device to the same PM domain
      genpd_add_device()
        genpd_lock()                                       ----> acquires genpd->mlock
          cpg_mssr_attach_dev()
            of_clk_get_from_provider()
              __of_clk_get_from_provider()
                __clk_create_clk()
                  clk_prepare_lock()                       ----> acquires prepare_lock
      
      Since currently no PM provider access genpd's critical section
      in .attach_dev, and .detach_dev callbacks, so there is no need to protect
      these two callbacks with genpd->mlock.
      This patch avoids a potential deadlock by moving out .attach_dev and .detach_dev
      from genpd->mlock, so that genpd->mlock won't be held when prepare_lock is acquired
      in .attach_dev and .detach_dev
      Signed-off-by: NJiada Wang <jiada_wang@mentor.com>
      Reviewed-by: NUlf Hansson <ulf.hansson@linaro.org>
      Tested-by: NGeert Uytterhoeven <geert+renesas@glider.be>
      Reviewed-by: NGeert Uytterhoeven <geert+renesas@glider.be>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      2071ac98
  3. 12 3月, 2019 2 次提交
    • R
      PM / wakeup: Drop wakeup_source_drop() · 623217a0
      Rafael J. Wysocki 提交于
      After commit d856f39ac1cc ("PM / wakeup: Rework wakeup source timer
      cancellation") wakeup_source_drop() is a trivial wrapper around
      __pm_relax() and it has no users except for wakeup_source_destroy()
      and wakeup_source_trash() which also has no users, so drop it along
      with the latter and make wakeup_source_destroy() call __pm_relax()
      directly.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Acked-by: NViresh Kumar <viresh.kumar@linaro.org>
      623217a0
    • V
      PM / wakeup: Rework wakeup source timer cancellation · 1fad17fb
      Viresh Kumar 提交于
      If wakeup_source_add() is called right after wakeup_source_remove()
      for the same wakeup source, timer_setup() may be called for a
      potentially scheduled timer which is incorrect.
      
      To avoid that, move the wakeup source timer cancellation from
      wakeup_source_drop() to wakeup_source_remove().
      
      Moreover, make wakeup_source_remove() clear the timer function after
      canceling the timer to let wakeup_source_not_registered() treat
      unregistered wakeup sources in the same way as the ones that have
      never been registered.
      Signed-off-by: NViresh Kumar <viresh.kumar@linaro.org>
      Cc: 4.4+ <stable@vger.kernel.org> # 4.4+
      [ rjw: Subject, changelog, merged two patches together ]
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      1fad17fb
  4. 11 3月, 2019 4 次提交
  5. 07 3月, 2019 3 次提交
  6. 21 2月, 2019 1 次提交
  7. 20 2月, 2019 1 次提交
    • R
      driver core: Fix PM-runtime for links added during consumer probe · 36003d4c
      Rafael J. Wysocki 提交于
      Commit 4c06c4e6 ("driver core: Fix possible supplier PM-usage
      counter imbalance") introduced a regression that causes suppliers
      to be suspended prematurely for device links added during consumer
      driver probe if the initial PM-runtime status of the consumer is
      "suspended" and the consumer is resumed after adding the link and
      before pm_runtime_put_suppliers() is called.  In that case,
      pm_runtime_put_suppliers() will drop the rpm_active refcount for
      the link by one and (since rpm_active is equal to two after the
      preceding consumer resume) the supplier's PM-runtime usage counter
      will be decremented, which may cause the supplier to suspend even
      though the consumer's PM-runtime status is "active".
      
      For this reason, partially revert commit 4c06c4e6 as the problem
      it tried to fix needs to be addressed somewhat differently, and
      change pm_runtime_get_suppliers() and pm_runtime_put_suppliers() so
      that the latter only drops rpm_active references acquired by the
      former.  [This requires adding a new field to struct device_link,
      but I coulnd't find a cleaner way to address the issue that would
      work in all cases.]
      
      This causes pm_runtime_put_suppliers() to effectively ignore device
      links added during consumer probe, so device_link_add() doesn't need
      to worry about ensuring that suppliers will remain active after
      pm_runtime_put_suppliers() for links created with DL_FLAG_RPM_ACTIVE
      set and it only needs to bump up rpm_active by one for those links,
      so pm_runtime_active_link() is not necessary any more.
      
      Fixes: 4c06c4e6 ("driver core: Fix possible supplier PM-usage counter imbalance")
      Reported-by: NJon Hunter <jonathanh@nvidia.com>
      Tested-by: NJon Hunter <jonathanh@nvidia.com>
      Tested-by: NUlf Hansson <ulf.hansson@linaro.org>
      Reviewed-by: NUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Tested-by: NThierry Reding <treding@nvidia.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      36003d4c
  8. 19 2月, 2019 1 次提交
    • S
      PM / core: Add support to skip power management in device/driver model · 85945c28
      Sudeep Holla 提交于
      All device objects in the driver model contain fields that control the
      handling of various power management activities. However, it's not
      always useful. There are few instances where pseudo devices are added
      to the model just to take advantage of many other features like
      kobjects, udev events, and so on. One such example is cpu devices and
      their caches.
      
      The sysfs for the cpu caches are managed by adding devices with cpu
      as the parent in cpu_device_create() when secondary cpu is brought
      online. Generally when the secondary CPUs are hotplugged back in as part
      of resume from suspend-to-ram, we call cpu_device_create() from the cpu
      hotplug state machine while the cpu device associated with that CPU is
      not yet ready to be resumed as the device_resume() call happens bit
      later. It's not really needed to set the flag is_prepared for cpu
      devices as they are mostly pseudo device and hotplug framework deals
      with state machine and not managed through the cpu device.
      
      This often results in annoying warning when resuming:
      Enabling non-boot CPUs ...
      CPU1: Booted secondary processor
       cache: parent cpu1 should not be sleeping
      CPU1 is up
      CPU2: Booted secondary processor
       cache: parent cpu2 should not be sleeping
      CPU2 is up
      .... and so on.
      
      So in order to fix these kind of errors, we could just completely avoid
      doing any power management related initialisations and operations if
      they are not used by these devices.
      
      Add no_pm flags to indicate that the device doesn't require any sort of
      PM activities and all of them can be completely skipped. We can use the
      same flag to also avoid adding not used *power* sysfs entries for these
      devices. For now, lets use this for cpu cache devices.
      Reviewed-by: NUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: NSudeep Holla <sudeep.holla@arm.com>
      Tested-by: NEugeniu Rosca <erosca@de.adit-jv.com>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      85945c28
  9. 15 2月, 2019 2 次提交
  10. 14 2月, 2019 1 次提交
  11. 13 2月, 2019 2 次提交
    • R
      driver core: Fix possible supplier PM-usage counter imbalance · 4c06c4e6
      Rafael J. Wysocki 提交于
      If a stateless device link to a certain supplier with
      DL_FLAG_PM_RUNTIME set in the flags is added and then removed by the
      consumer driver's probe callback, the supplier's PM-runtime usage
      counter will be nonzero after that which effectively causes the
      supplier to remain "always on" going forward.
      
      Namely, device_link_add() called to add the link invokes
      device_link_rpm_prepare() which notices that the consumer driver is
      probing, so it increments the supplier's PM-runtime usage counter
      with the assumption that the link will stay around until
      pm_runtime_put_suppliers() is called by driver_probe_device(),
      but if the link goes away before that point, the supplier's
      PM-runtime usage counter will remain nonzero.
      
      To prevent that from happening, first rework pm_runtime_get_suppliers()
      and pm_runtime_put_suppliers() to use the rpm_active refounts of device
      links and make the latter only drop rpm_active and the supplier's
      PM-runtime usage counter for each link by one, unless rpm_active is
      one already for it.  Next, modify device_link_add() to bump up the
      new link's rpm_active refcount and the suppliers PM-runtime usage
      counter by two, to prevent pm_runtime_put_suppliers(), if it is
      called subsequently, from suspending the supplier prematurely (in
      case its PM-runtime usage counter goes down to 0 in there).
      
      Due to the way rpm_put_suppliers() works, this change does not
      affect runtime suspend of the consumer ends of new device links (or,
      generally, device links for which DL_FLAG_PM_RUNTIME has just been
      set).
      
      Fixes: e2f3cd83 ("driver core: Fix handling of runtime PM flags in device_link_add()")
      Reported-by: NUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-by: NUlf Hansson <ulf.hansson@linaro.org>
      Tested-by: NUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4c06c4e6
    • R
      PM-runtime: Fix __pm_runtime_set_status() race with runtime resume · c1567f81
      Rafael J. Wysocki 提交于
      Commit 4080ab08 ("PM-runtime: Take suppliers into account in
      __pm_runtime_set_status()") introduced a race condition that may
      trigger if __pm_runtime_set_status() is used incorrectly (that is,
      if it is called when PM-runtime is enabled for the target device
      and working).
      
      In that case, if the original PM-runtime status of the device is
      RPM_SUSPENDED, a runtime resume of the device may occur after
      __pm_runtime_set_status() has dropped its power.lock spinlock
      and before deactivating its suppliers, so the suppliers may be
      deactivated while the device is PM-runtime-active which may lead
      to functional issues.
      
      To avoid that, modify __pm_runtime_set_status() to check whether
      or not PM-runtime is enabled for the device before activating its
      suppliers (if the new status is RPM_ACTIVE) and either return an
      error if that's the case or increment the device's disable_depth
      counter to prevent PM-runtime from being enabled for it while
      the remaining part of the function is running (disable_depth is
      then decremented on the way out).
      
      Fixes: 4080ab08 ("PM-runtime: Take suppliers into account in __pm_runtime_set_status()")
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-by: NUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c1567f81
  12. 08 2月, 2019 1 次提交
    • R
      PM-runtime: Take suppliers into account in __pm_runtime_set_status() · 4080ab08
      Rafael J. Wysocki 提交于
      If the target device has any suppliers, as reflected by device links
      to them, __pm_runtime_set_status() does not take them into account,
      which is not consistent with the other parts of the PM-runtime
      framework and may lead to programming mistakes.
      
      Modify __pm_runtime_set_status() to take suppliers into account by
      activating them upfront if the new status is RPM_ACTIVE and
      deactivating them on exit if the new status is RPM_SUSPENDED.
      
      If the activation of one of the suppliers fails, the new status
      will be RPM_SUSPENDED and the (remaining) suppliers will be
      deactivated on exit (the child count of the device's parent
      will be dropped too then).
      
      Of course, adding device links locking to __pm_runtime_set_status()
      means that it cannot be run fron interrupt context, so make it use
      spin_lock_irq() and spin_unlock_irq() instead of spin_lock_irqsave()
      and spin_unlock_irqrestore(), respectively.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4080ab08
  13. 05 2月, 2019 2 次提交
  14. 01 2月, 2019 3 次提交
    • L
      PM-runtime: Optimize pm_runtime_autosuspend_expiration() · f800ea32
      Ladislav Michl 提交于
      pm_runtime_autosuspend_expiration calls ktime_get_mono_fast_ns()
      even when its returned value may be unused. Therefore get the
      current time later and remove gotos while there.
      Signed-off-by: NLadislav Michl <ladis@linux-mips.org>
      Acked-by: NTony Lindgren <tony@atomide.com>
      Acked-by: NVincent Guittot <vincent.guittot@linaro.org>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      f800ea32
    • R
      driver core: Do not call rpm_put_suppliers() in pm_runtime_drop_link() · a1fdbfbb
      Rafael J. Wysocki 提交于
      Calling rpm_put_suppliers() from pm_runtime_drop_link() is excessive
      as it affects all suppliers of the consumer device and not just the
      one pointed to by the device link being dropped.  Worst case it may
      cause the consumer device to stop working unexpectedly.  Moreover, in
      principle it is racy with respect to runtime PM of the consumer
      device.
      
      To avoid these problems drop runtime PM references on the particular
      supplier pointed to by the link in question only and do that after
      the link has been dropped from the consumer device's list of links to
      suppliers, which is in device_link_free().
      
      Fixes: a0504aec ("PM / runtime: Drop usage count for suppliers at device link removal")
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a1fdbfbb
    • R
      driver core: Fix handling of runtime PM flags in device_link_add() · e2f3cd83
      Rafael J. Wysocki 提交于
      After commit ead18c23 ("driver core: Introduce device links
      reference counting"), if there is a link between the given supplier
      and the given consumer already, device_link_add() will refcount it
      and return it unconditionally without updating its flags.  It is
      possible, however, that the second (or any subsequent) caller of
      device_link_add() for the same consumer-supplier pair will pass
      DL_FLAG_PM_RUNTIME, possibly along with DL_FLAG_RPM_ACTIVE, in flags
      to it and the existing link may not behave as expected then.
      
      First, if DL_FLAG_PM_RUNTIME is not set in the existing link's flags
      at all, it needs to be set like during the original initialization of
      the link.
      
      Second, if DL_FLAG_RPM_ACTIVE is passed to device_link_add() in flags
      (in addition to DL_FLAG_PM_RUNTIME), the existing link should to be
      updated to reflect the "active" runtime PM configuration of the
      consumer-supplier pair and extra care must be taken here to avoid
      possible destructive races with runtime PM of the consumer.
      
      To that end, redefine the rpm_active field in struct device_link
      as a refcount, initialize it to 1 and make rpm_resume() (for the
      consumer) and device_link_add() increment it whenever they acquire
      a runtime PM reference on the supplier device.  Accordingly, make
      rpm_suspend() (for the consumer) and pm_runtime_clean_up_links()
      decrement it and drop runtime PM references to the supplier
      device in a loop until rpm_active becones 1 again.
      
      Fixes: ead18c23 ("driver core: Introduce device links reference counting")
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e2f3cd83
  15. 31 1月, 2019 4 次提交
  16. 29 1月, 2019 1 次提交
  17. 24 1月, 2019 1 次提交
  18. 18 1月, 2019 1 次提交
  19. 16 1月, 2019 1 次提交
  20. 10 1月, 2019 2 次提交
  21. 03 1月, 2019 1 次提交
  22. 19 12月, 2018 2 次提交
    • Y
      PM / Domains: remove define_genpd_open_function() and define_genpd_debugfs_fops() · d32dcc6c
      Yangtao Li 提交于
      We already have the DEFINE_SHOW_ATTRIBUTE, There is no need to define
      such a macro, so remove define_genpd_open_function and
      define_genpd_debugfs_fops.
      
      Convert them to DEFINE_SHOW_ATTRIBUTE.
      Signed-off-by: NYangtao Li <tiny.windzz@gmail.com>
      Acked-by: NUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      d32dcc6c
    • V
      PM-runtime: Switch autosuspend over to using hrtimers · 8234f673
      Vincent Guittot 提交于
      PM-runtime uses the timer infrastructure for autosuspend. This implies
      that the minimum time before autosuspending a device is in the range
      of 1 tick included to 2 ticks excluded
       -On arm64 this means between 4ms and 8ms with default jiffies
        configuration
       -And on arm, it is between 10ms and 20ms
      
      These values are quite high for embedded systems which sometimes want
      the duration to be in the range of 1 ms.
      
      It is possible to switch autosuspend over to using hrtimers to get
      finer granularity for short durations and take advantage of slack to
      retain some margins and get long timeouts with minimum wakeups.
      
      On an arm64 platform that uses 1ms for autosuspending timeout of its
      GPU, idle power is reduced by 10% with hrtimer.
      
      The latency impact on arm64 hikey octo cores is:
       - mark_last_busy: from 1.11 us to 1.25 us
       - rpm_suspend: from 15.54 us to 15.38 us
      [Only the code path of rpm_suspend() that starts hrtimer has been
      measured.]
      
      arm64 image (arm64 default defconfig) decreases by around 3KB
      with following details:
      
      $ size vmlinux-timer
         text	   data	    bss	    dec	    hex	filename
      12034646	6869268	 386840	19290754	1265a82	vmlinux
      
      $ size vmlinux-hrtimer
         text	   data	    bss	    dec	    hex	filename
      12030550	6870164	 387032	19287746	1264ec2	vmlinux
      
      The latency impact on arm 32bits snowball dual cores is :
       - mark_last_busy: from 0.31 us usec to 0.77 us
       - rpm_suspend: from 6.83 us to 6.67 usec
      
      The increase of the image for snowball platform that I used for
      testing performance impact, is neglictable (244B).
      
      $ size vmlinux-timer
         text	   data	    bss	    dec	    hex	filename
      7157961	2119580	 264120	9541661	 91981d	build-ux500/vmlinux
      
      size vmlinux-hrtimer
         text	   data	    bss	    dec	    hex	filename
      7157773	21198846	 264248	9541905	 919911	vmlinux-hrtimer
      
      And arm 32bits image (multi_v7_defconfig) increases by around 1.7KB
      with following details:
      
      $ size vmlinux-timer
         text	   data	    bss	    dec	    hex	filename
      13304443	6803420	 402768	20510631	138f7a7	vmlinux
      
      $ size vmlinux-hrtimer
         text	   data	    bss	    dec	    hex	filename
      13304299	6805276	 402768	20512343	138fe57	vmlinux
      Signed-off-by: NVincent Guittot <vincent.guittot@linaro.org>
      Reviewed-by: NUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      8234f673
  23. 14 12月, 2018 2 次提交
    • V
      PM / Domains: Propagate performance state updates · 18edf49c
      Viresh Kumar 提交于
      Currently a genpd only handles the performance state requirements from
      the devices under its control. This commit extends that to also handle
      the performance state requirement(s) put on the master genpd by its
      sub-domains. There is a separate value required for each master that
      the genpd has and so a new field is added to the struct gpd_link
      (link->performance_state), which represents the link between a genpd and
      its master. The struct gpd_link also got another field
      prev_performance_state, which is used by genpd core as a temporary
      variable during transitions.
      
      On a call to dev_pm_genpd_set_performance_state(), the genpd core first
      updates the performance state of the masters of the device's genpd and
      then updates the performance state of the genpd. The masters do the same
      and propagate performance state updates to their masters before updating
      their own. The performance state transition from genpd to its master is
      done with the help of dev_pm_opp_xlate_performance_state(), which looks
      at the OPP tables of both the domains to translate the state.
      Tested-by: NRajendra Nayak <rnayak@codeaurora.org>
      Reviewed-by: NUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: NViresh Kumar <viresh.kumar@linaro.org>
      18edf49c
    • V
      PM / Domains: Factorize dev_pm_genpd_set_performance_state() · cd50c6d3
      Viresh Kumar 提交于
      Separate out _genpd_set_performance_state() and
      _genpd_reeval_performance_state() from
      dev_pm_genpd_set_performance_state() to handle performance state update
      related stuff. This will be used by a later commit.
      Tested-by: NRajendra Nayak <rnayak@codeaurora.org>
      Reviewed-by: NUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: NViresh Kumar <viresh.kumar@linaro.org>
      cd50c6d3