You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/04/01 16:11:08 UTC

[incubator-nuttx] branch master updated (e4b73d9 -> 79bcc66)

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git.


    from e4b73d9  net/local: change 255 to UINT8_MAX
     new ae21df2  power: unify lock states
     new 79bcc66  power:driver: move pm_auto_update to outer dir

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 drivers/power/Make.defs                            |  2 +-
 drivers/power/activity_governor.c                  |  8 ++--
 drivers/power/greedy_governor.c                    |  4 +-
 drivers/power/pm.h                                 | 39 ++++++-------------
 drivers/power/pm_activity.c                        |  8 ++--
 drivers/power/pm_autoupdate.c                      |  4 +-
 drivers/power/pm_changestate.c                     |  4 +-
 .../src/z80_timerisr.c => drivers/power/pm_lock.c  | 44 ++++++++++++----------
 drivers/power/pm_register.c                        | 15 ++++----
 drivers/power/pm_unregister.c                      | 13 +++----
 include/nuttx/power/pm.h                           | 16 ++++++++
 11 files changed, 79 insertions(+), 78 deletions(-)
 copy boards/z80/z80/z80sim/src/z80_timerisr.c => drivers/power/pm_lock.c (73%)

[incubator-nuttx] 01/02: power: unify lock states

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit ae21df2ed3c560d4ea4ed1f1446fd1f2a396861a
Author: zhuyanlin <zh...@xiaomi.com>
AuthorDate: Tue Mar 15 20:42:34 2022 +0800

    power: unify lock states
    
    unify critical_section and nxsem with pm_lock/pm_unlock
    
    Signed-off-by: zhuyanlin <zh...@xiaomi.com>
---
 drivers/power/Make.defs                      |  2 +-
 drivers/power/activity_governor.c            |  8 ++---
 drivers/power/greedy_governor.c              |  4 +--
 drivers/power/pm.h                           | 41 +++++++++++----------
 drivers/power/pm_activity.c                  |  8 ++---
 drivers/power/pm_autoupdate.c                |  4 +--
 drivers/power/pm_changestate.c               |  4 +--
 drivers/power/{pm_unregister.c => pm_lock.c} | 53 ++++++++++++++--------------
 drivers/power/pm_register.c                  | 15 ++++----
 drivers/power/pm_unregister.c                | 13 +++----
 10 files changed, 74 insertions(+), 78 deletions(-)

diff --git a/drivers/power/Make.defs b/drivers/power/Make.defs
index e012547..7c1ecb0 100644
--- a/drivers/power/Make.defs
+++ b/drivers/power/Make.defs
@@ -23,7 +23,7 @@
 ifeq ($(CONFIG_PM),y)
 
 CSRCS += pm_initialize.c pm_activity.c pm_changestate.c pm_checkstate.c
-CSRCS += pm_register.c pm_unregister.c pm_autoupdate.c pm_governor.c
+CSRCS += pm_register.c pm_unregister.c pm_autoupdate.c pm_governor.c pm_lock.c
 
 # Governor implementations
 
diff --git a/drivers/power/activity_governor.c b/drivers/power/activity_governor.c
index 05b4046..dcd44c1 100644
--- a/drivers/power/activity_governor.c
+++ b/drivers/power/activity_governor.c
@@ -235,7 +235,7 @@ static void governor_activity(int domain, int count)
     {
       /* Add the activity count to the accumulated counts. */
 
-      flags = enter_critical_section();
+      flags = pm_lock();
       accum = (uint32_t)pdomstate->accum + count;
 
       /* Make sure that we do not overflow the underlying representation */
@@ -275,7 +275,7 @@ static void governor_activity(int domain, int count)
           governor_update(domain, tmp);
         }
 
-      leave_critical_section(flags);
+      pm_unlock(flags);
     }
 }
 
@@ -476,7 +476,7 @@ static enum pm_state_e governor_checkstate(int domain)
    * logic in governor_activity().
    */
 
-  flags = enter_critical_section();
+  flags = pm_lock();
 
   /* Check the elapsed time.  In periods of low activity, time slicing is
    * controlled by IDLE loop polling; in periods of higher activity, time
@@ -515,7 +515,7 @@ static enum pm_state_e governor_checkstate(int domain)
         }
     }
 
-  leave_critical_section(flags);
+  pm_unlock(flags);
 
   return pdomstate->recommended;
 }
diff --git a/drivers/power/greedy_governor.c b/drivers/power/greedy_governor.c
index 09b35c0..43c839d 100644
--- a/drivers/power/greedy_governor.c
+++ b/drivers/power/greedy_governor.c
@@ -123,7 +123,7 @@ static enum pm_state_e greedy_governor_checkstate(int domain)
    * invoked, which modifies the stay count which we are about to read
    */
 
-  flags = enter_critical_section();
+  flags = pm_lock();
 
   /* Find the lowest power-level which is not locked. */
 
@@ -132,7 +132,7 @@ static enum pm_state_e greedy_governor_checkstate(int domain)
       state++;
     }
 
-  leave_critical_section(flags);
+  pm_unlock(flags);
 
   /* Return the found state */
 
diff --git a/drivers/power/pm.h b/drivers/power/pm.h
index 42821bf..c067e12 100644
--- a/drivers/power/pm.h
+++ b/drivers/power/pm.h
@@ -42,27 +42,6 @@
  ****************************************************************************/
 
 /****************************************************************************
- * Name: pm_lock
- *
- * Description:
- *   Lock the power management registry.  NOTE: This function may return
- *   an error if a signal is received while what (errno == EINTR).
- *
- ****************************************************************************/
-
-#define pm_lock() nxsem_wait(&g_pmglobals.regsem);
-
-/****************************************************************************
- * Name: pm_unlock
- *
- * Description:
- *   Unlock the power management registry.
- *
- ****************************************************************************/
-
-#define pm_unlock() nxsem_post(&g_pmglobals.regsem);
-
-/****************************************************************************
  * Public Types
  ****************************************************************************/
 
@@ -154,6 +133,26 @@ EXTERN struct pm_global_s g_pmglobals;
 
 void pm_auto_updatestate(int domain);
 
+/****************************************************************************
+ * Name: pm_lock
+ *
+ * Description:
+ *   Lock the power management operation.
+ *
+ ****************************************************************************/
+
+irqstate_t pm_lock(void);
+
+/****************************************************************************
+ * Name: pm_unlock
+ *
+ * Description:
+ *   Unlock the power management operation.
+ *
+ ****************************************************************************/
+
+void pm_unlock(irqstate_t flags);
+
 #undef EXTERN
 #if defined(__cplusplus)
 }
diff --git a/drivers/power/pm_activity.c b/drivers/power/pm_activity.c
index d3c73dc..e0f4a7f 100644
--- a/drivers/power/pm_activity.c
+++ b/drivers/power/pm_activity.c
@@ -111,11 +111,11 @@ void pm_stay(int domain, enum pm_state_e state)
   DEBUGASSERT(domain >= 0 && domain < CONFIG_PM_NDOMAINS);
   pdom = &g_pmglobals.domain[domain];
 
-  flags = enter_critical_section();
+  flags = pm_lock();
   DEBUGASSERT(state < PM_COUNT);
   DEBUGASSERT(pdom->stay[state] < UINT16_MAX);
   pdom->stay[state]++;
-  leave_critical_section(flags);
+  pm_unlock(flags);
 
   pm_auto_updatestate(domain);
 }
@@ -151,11 +151,11 @@ void pm_relax(int domain, enum pm_state_e state)
   DEBUGASSERT(domain >= 0 && domain < CONFIG_PM_NDOMAINS);
   pdom = &g_pmglobals.domain[domain];
 
-  flags = enter_critical_section();
+  flags = pm_lock();
   DEBUGASSERT(state < PM_COUNT);
   DEBUGASSERT(pdom->stay[state] > 0);
   pdom->stay[state]--;
-  leave_critical_section(flags);
+  pm_unlock(flags);
 
   pm_auto_updatestate(domain);
 }
diff --git a/drivers/power/pm_autoupdate.c b/drivers/power/pm_autoupdate.c
index b0d7601..78463f0 100644
--- a/drivers/power/pm_autoupdate.c
+++ b/drivers/power/pm_autoupdate.c
@@ -109,9 +109,9 @@ void pm_auto_update(int domain, bool auto_update)
   DEBUGASSERT(domain >= 0 && domain < CONFIG_PM_NDOMAINS);
   pdom = &g_pmglobals.domain[domain];
 
-  flags = enter_critical_section();
+  flags = pm_lock();
   pdom->auto_update = auto_update;
-  leave_critical_section(flags);
+  pm_unlock(flags);
 }
 
 #endif /* CONFIG_PM */
diff --git a/drivers/power/pm_changestate.c b/drivers/power/pm_changestate.c
index d38dd0d..e9d804c 100644
--- a/drivers/power/pm_changestate.c
+++ b/drivers/power/pm_changestate.c
@@ -213,7 +213,7 @@ int pm_changestate(int domain, enum pm_state_e newstate)
    * re-enabled.
    */
 
-  flags = enter_critical_section();
+  flags = pm_lock();
 
   /* First, prepare the drivers for the state change.  In this phase,
    * drivers may refuse the state state change.
@@ -249,7 +249,7 @@ int pm_changestate(int domain, enum pm_state_e newstate)
 
   /* Restore the interrupt state */
 
-  leave_critical_section(flags);
+  pm_unlock(flags);
   return ret;
 }
 
diff --git a/drivers/power/pm_unregister.c b/drivers/power/pm_lock.c
similarity index 68%
copy from drivers/power/pm_unregister.c
copy to drivers/power/pm_lock.c
index bc9d0a6..0e12224 100644
--- a/drivers/power/pm_unregister.c
+++ b/drivers/power/pm_lock.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * drivers/power/pm_unregister.c
+ * drivers/power/pm_lock.c
  *
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -24,51 +24,52 @@
 
 #include <nuttx/config.h>
 
-#include <queue.h>
-#include <assert.h>
-
+#include <nuttx/arch.h>
+#include <nuttx/irq.h>
 #include <nuttx/power/pm.h>
-
+#include <sched.h>
 #include "pm.h"
 
-#ifdef CONFIG_PM
+#if defined(CONFIG_PM)
 
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
 /****************************************************************************
- * Name: pm_unregister
+ * Name: pm_lock
  *
  * Description:
- *   This function is called by a device driver in order to unregister
- *   previously registered power management event callbacks.
- *
- * Input parameters:
- *   callbacks - An instance of struct pm_callback_s providing the driver
- *               callback functions.
- *
- * Returned Value:
- *    Zero (OK) on success; otherwise a negated errno value is returned.
+ *   Lock the power management operation.
  *
  ****************************************************************************/
 
-int pm_unregister(FAR struct pm_callback_s *callbacks)
+irqstate_t pm_lock(void)
 {
-  int ret;
+  if (!up_interrupt_context() && !sched_idletask())
+    {
+      nxsem_wait_uninterruptible(&g_pmglobals.regsem);
+    }
 
-  DEBUGASSERT(callbacks);
+  return enter_critical_section();
+}
 
-  /* Remove entry from the list of registered callbacks. */
+/****************************************************************************
+ * Name: pm_unlock
+ *
+ * Description:
+ *   Unlock the power management operation.
+ *
+ ****************************************************************************/
 
-  ret = pm_lock();
-  if (ret == OK)
+void pm_unlock(irqstate_t flags)
+{
+  leave_critical_section(flags);
+
+  if (!up_interrupt_context() && !sched_idletask())
     {
-      dq_rem(&callbacks->entry, &g_pmglobals.registry);
-      pm_unlock();
+      nxsem_post(&g_pmglobals.regsem);
     }
-
-  return ret;
 }
 
 #endif /* CONFIG_PM */
diff --git a/drivers/power/pm_register.c b/drivers/power/pm_register.c
index fa95b8e..f676e8c 100644
--- a/drivers/power/pm_register.c
+++ b/drivers/power/pm_register.c
@@ -56,20 +56,19 @@
 
 int pm_register(FAR struct pm_callback_s *callbacks)
 {
-  int ret;
+  irqstate_t flags;
 
   DEBUGASSERT(callbacks);
 
   /* Add the new entry to the end of the list of registered callbacks */
 
-  ret = pm_lock();
-  if (ret == OK)
-    {
-      dq_addlast(&callbacks->entry, &g_pmglobals.registry);
-      pm_unlock();
-    }
+  flags = pm_lock();
 
-  return ret;
+  dq_addlast(&callbacks->entry, &g_pmglobals.registry);
+
+  pm_unlock(flags);
+
+  return 0;
 }
 
 #endif /* CONFIG_PM */
diff --git a/drivers/power/pm_unregister.c b/drivers/power/pm_unregister.c
index bc9d0a6..cf3a963 100644
--- a/drivers/power/pm_unregister.c
+++ b/drivers/power/pm_unregister.c
@@ -55,20 +55,17 @@
 
 int pm_unregister(FAR struct pm_callback_s *callbacks)
 {
-  int ret;
+  irqstate_t flags;
 
   DEBUGASSERT(callbacks);
 
   /* Remove entry from the list of registered callbacks. */
 
-  ret = pm_lock();
-  if (ret == OK)
-    {
-      dq_rem(&callbacks->entry, &g_pmglobals.registry);
-      pm_unlock();
-    }
+  flags = pm_lock();
+  dq_rem(&callbacks->entry, &g_pmglobals.registry);
+  pm_unlock(flags);
 
-  return ret;
+  return 0;
 }
 
 #endif /* CONFIG_PM */

[incubator-nuttx] 02/02: power:driver: move pm_auto_update to outer dir

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 79bcc662d91dddc67bcd638f4419fc3cac944105
Author: zhuyanlin <zh...@xiaomi.com>
AuthorDate: Wed Mar 16 13:39:18 2022 +0800

    power:driver: move pm_auto_update to outer dir
    
    Pm_auto_update maybe called by outter PM users
    
    Signed-off-by: zhuyanlin <zh...@xiaomi.com>
---
 drivers/power/pm.h       | 16 ----------------
 include/nuttx/power/pm.h | 16 ++++++++++++++++
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/power/pm.h b/drivers/power/pm.h
index c067e12..c3cdb67 100644
--- a/drivers/power/pm.h
+++ b/drivers/power/pm.h
@@ -118,22 +118,6 @@ EXTERN struct pm_global_s g_pmglobals;
  ****************************************************************************/
 
 /****************************************************************************
- * Name: pm_auto_updatestate
- *
- * Description:
- *   This function update the domain state and notify the power system.
- *
- * Input Parameters:
- *   domain - The PM domain to check
- *
- * Returned Value:
- *   None.
- *
- ****************************************************************************/
-
-void pm_auto_updatestate(int domain);
-
-/****************************************************************************
  * Name: pm_lock
  *
  * Description:
diff --git a/include/nuttx/power/pm.h b/include/nuttx/power/pm.h
index d3da786..29cc0cf 100644
--- a/include/nuttx/power/pm.h
+++ b/include/nuttx/power/pm.h
@@ -598,6 +598,22 @@ int pm_changestate(int domain, enum pm_state_e newstate);
 
 enum pm_state_e pm_querystate(int domain);
 
+/****************************************************************************
+ * Name: pm_auto_updatestate
+ *
+ * Description:
+ *   This function update the domain state and notify the power system.
+ *
+ * Input Parameters:
+ *   domain - The PM domain to check
+ *
+ * Returned Value:
+ *   None.
+ *
+ ****************************************************************************/
+
+void pm_auto_updatestate(int domain);
+
 #undef EXTERN
 #ifdef __cplusplus
 }