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/05/10 13:21:29 UTC

[incubator-nuttx] 03/07: cpuload: nxsched_cpu_process_cpuload: add ticks parameter

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 6facf18a01e530e2757247828b37b1ef2d628a11
Author: zhuyanlin <zh...@xiaomi.com>
AuthorDate: Fri Apr 22 17:10:18 2022 +0800

    cpuload: nxsched_cpu_process_cpuload: add ticks parameter
    
    Signed-off-by: zhuyanlin <zh...@xiaomi.com>
---
 include/nuttx/arch.h        | 27 ++++++++++++++++++++++++++-
 sched/sched/sched_cpuload.c | 37 ++++++++++++++++++++++++++++++++-----
 2 files changed, 58 insertions(+), 6 deletions(-)

diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h
index 7e64e43427..116c3d192b 100644
--- a/include/nuttx/arch.h
+++ b/include/nuttx/arch.h
@@ -1863,7 +1863,7 @@ int up_timer_start(FAR const struct timespec *ts);
 #ifdef CONFIG_SCHED_THREAD_LOCAL
 int up_tls_size(void);
 #else
-#define up_tls_size() sizeof(struct tls_info_s) 
+#define up_tls_size() sizeof(struct tls_info_s)
 #endif
 
 /****************************************************************************
@@ -2303,6 +2303,31 @@ void nxsched_alarm_expiration(FAR const struct timespec *ts);
 void weak_function nxsched_process_cpuload(void);
 #endif
 
+/****************************************************************************
+ * Name: nxsched_process_cpuload_ticks
+ *
+ * Description:
+ *   Collect data that can be used for CPU load measurements.  When
+ *   CONFIG_SCHED_CPULOAD_EXTCLK is defined, this is an exported interface,
+ *   use the the external clock logic.  Otherwise, it is an OS internal
+ *   interface.
+ *
+ * Input Parameters:
+ *   ticks - The ticks that we increment in this cpuload
+ *
+ * Returned Value:
+ *   None
+ *
+ * Assumptions/Limitations:
+ *   This function is called from a timer interrupt handler with all
+ *   interrupts disabled.
+ *
+ ****************************************************************************/
+
+#if defined(CONFIG_SCHED_CPULOAD) && defined(CONFIG_SCHED_CPULOAD_EXTCLK)
+void weak_function nxsched_process_cpuload_ticks(uint32_t ticks);
+#endif
+
 /****************************************************************************
  * Name: irq_dispatch
  *
diff --git a/sched/sched/sched_cpuload.c b/sched/sched/sched_cpuload.c
index 03088251d1..699aff0981 100644
--- a/sched/sched/sched_cpuload.c
+++ b/sched/sched/sched_cpuload.c
@@ -91,7 +91,8 @@ volatile uint32_t g_cpuload_total;
  *   Collect data that can be used for CPU load measurements.
  *
  * Input Parameters:
- *   cpu - The CPU that we are performing the load operations on.
+ *   cpu   - The CPU that we are performing the load operations on.
+ *   ticks - The ticks that we process in this cpuload.
  *
  * Returned Value:
  *   None
@@ -102,19 +103,19 @@ volatile uint32_t g_cpuload_total;
  *
  ****************************************************************************/
 
-static inline void nxsched_cpu_process_cpuload(int cpu)
+static inline void nxsched_cpu_process_cpuload(int cpu, uint32_t ticks)
 {
   FAR struct tcb_s *rtcb = current_task(cpu);
 
   /* Increment the count on the currently executing thread */
 
-  rtcb->ticks++;
+  rtcb->ticks += ticks;
 
   /* Increment tick count.  NOTE that the count is increment once for each
    * CPU on each sample interval.
    */
 
-  g_cpuload_total++;
+  g_cpuload_total += ticks;
 }
 
 /****************************************************************************
@@ -143,6 +144,32 @@ static inline void nxsched_cpu_process_cpuload(int cpu)
  ****************************************************************************/
 
 void weak_function nxsched_process_cpuload(void)
+{
+  nxsched_process_cpuload_ticks(1);
+}
+
+/****************************************************************************
+ * Name: nxsched_process_cpuload_ticks
+ *
+ * Description:
+ *   Collect data that can be used for CPU load measurements.  When
+ *   CONFIG_SCHED_CPULOAD_EXTCLK is defined, this is an exported interface,
+ *   use the the external clock logic.  Otherwise, it is an OS Internal
+ *   interface.
+ *
+ * Input Parameters:
+ *   ticks - The ticks that we increment in this cpuload
+ *
+ * Returned Value:
+ *   None
+ *
+ * Assumptions/Limitations:
+ *   This function is called from a timer interrupt handler with all
+ *   interrupts disabled.
+ *
+ ****************************************************************************/
+
+void weak_function nxsched_process_cpuload_ticks(uint32_t ticks)
 {
   int i;
   irqstate_t flags;
@@ -153,7 +180,7 @@ void weak_function nxsched_process_cpuload(void)
 
   for (i = 0; i < CONFIG_SMP_NCPUS; i++)
     {
-      nxsched_cpu_process_cpuload(i);
+      nxsched_cpu_process_cpuload(i, ticks);
     }
 
   /* If the accumulated tick value exceed a time constant, then shift the