summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nuttx/fs/procfs/fs_procfsproc.c2
-rw-r--r--nuttx/sched/os_internal.h4
-rw-r--r--nuttx/sched/sched_cpuload.c57
-rw-r--r--nuttx/sched/sched_processtimer.c65
-rw-r--r--nuttx/sched/sched_releasetcb.c7
5 files changed, 76 insertions, 59 deletions
diff --git a/nuttx/fs/procfs/fs_procfsproc.c b/nuttx/fs/procfs/fs_procfsproc.c
index a1ec1b898..0782479b0 100644
--- a/nuttx/fs/procfs/fs_procfsproc.c
+++ b/nuttx/fs/procfs/fs_procfsproc.c
@@ -573,7 +573,7 @@ static ssize_t proc_loadavg(FAR struct proc_file_s *procfile,
{
uint32_t tmp;
- tmp = 1000 - (1000 * cpuload.active) / cpuload.total;
+ tmp = (1000 * cpuload.active) / cpuload.total;
intpart = tmp / 10;
fracpart = tmp - 10 * intpart;
}
diff --git a/nuttx/sched/os_internal.h b/nuttx/sched/os_internal.h
index 999e7c3df..662b42e51 100644
--- a/nuttx/sched/os_internal.h
+++ b/nuttx/sched/os_internal.h
@@ -255,8 +255,10 @@ int sched_reprioritize(FAR struct tcb_s *tcb, int sched_priority);
#else
# define sched_reprioritize(tcb,sched_priority) sched_setpriority(tcb,sched_priority)
#endif
+#ifdef CONFIG_SCHED_CPULOAD
+void weak_function sched_process_cpuload(void);
+#endif
bool sched_verifytcb(FAR struct tcb_s *tcb);
-
int sched_releasetcb(FAR struct tcb_s *tcb, uint8_t ttype);
#endif /* __SCHED_OS_INTERNAL_H */
diff --git a/nuttx/sched/sched_cpuload.c b/nuttx/sched/sched_cpuload.c
index 03f7656c1..b02db1d64 100644
--- a/nuttx/sched/sched_cpuload.c
+++ b/nuttx/sched/sched_cpuload.c
@@ -65,6 +65,12 @@
* Private Variables
************************************************************************/
+/* This is the total number of clock tick counts. Essentially the
+ * 'denominator' for all CPU load calculations.
+ */
+
+volatile uint32_t g_cpuload_total;
+
/************************************************************************
* Private Functions
************************************************************************/
@@ -73,6 +79,57 @@
* Public Functions
************************************************************************/
+/************************************************************************
+ * Name: sched_process_cpuload
+ *
+ * Description:
+ * Collect data that can be used for CPU load measurements.
+ *
+ * Inputs:
+ * None
+ *
+ * Return Value:
+ * None
+ *
+ ************************************************************************/
+
+void weak_function sched_process_cpuload(void)
+{
+ FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head;
+ int hash_index;
+ int i;
+
+ /* Increment the count on the currently executing thread
+ *
+ * NOTE also that CPU load measurement data is retained in the g_pidhash
+ * table vs. in the TCB which would seem to be the more logic place. It
+ * is place in the hash table, instead, to facilitate CPU load adjustments
+ * on all threads during timer interrupt handling. sched_foreach() could
+ * do this too, but this would require a little more overhead.
+ */
+
+ hash_index = PIDHASH(rtcb->pid);
+ g_pidhash[hash_index].ticks++;
+
+ /* Increment tick count. If the accumulated tick value exceed a time
+ * constant, then shift the accumulators.
+ */
+
+ if (++g_cpuload_total > (CONFIG_SCHED_CPULOAD_TIMECONSTANT * CLOCKS_PER_SEC))
+ {
+ /* Divide the tick count for every task by two */
+
+ for (i = 0; i < CONFIG_MAX_TASKS; i++)
+ {
+ g_pidhash[i].ticks >>= 1;
+ }
+
+ /* Divide the total tick count by two */
+
+ g_cpuload_total >>= 1;
+ }
+}
+
/****************************************************************************
* Function: clock_cpuload
*
diff --git a/nuttx/sched/sched_processtimer.c b/nuttx/sched/sched_processtimer.c
index c03077c21..d65112948 100644
--- a/nuttx/sched/sched_processtimer.c
+++ b/nuttx/sched/sched_processtimer.c
@@ -66,14 +66,6 @@
* Public Variables
************************************************************************/
-#ifdef CONFIG_SCHED_CPULOAD
-/* This is the total number of clock tick counts. Essentially the
- * 'denominator' for all CPU load calculations.
- */
-
-volatile uint32_t g_cpuload_total;
-#endif
-
/************************************************************************
* Private Variables
************************************************************************/
@@ -159,54 +151,6 @@ static inline void sched_process_timeslice(void)
#endif
/************************************************************************
- * Name: sched_process_cpuload
- *
- * Description:
- * Collect data that can be used for CPU load measurements.
- *
- * Inputs:
- * None
- *
- * Return Value:
- * None
- *
- ************************************************************************/
-
-#ifdef CONFIG_SCHED_CPULOAD
-static inline void sched_process_cpuload(void)
-{
- FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head;
- int hash_index;
- int i;
-
- /* Increment the count on the currently executing thread */
-
- hash_index = PIDHASH(rtcb->pid);
- g_pidhash[hash_index].ticks++;
-
- /* Increment tick count. If the accumulated tick value exceed a time
- * constant, then shift the accumulators.
- */
-
- if (++g_cpuload_total > (CONFIG_SCHED_CPULOAD_TIMECONSTANT * CLOCKS_PER_SEC))
- {
- /* Divide the tick count for every task by two */
-
- for (i = 0; i < CONFIG_MAX_TASKS; i++)
- {
- g_pidhash[i].ticks >>= 1;
- }
-
- /* Divide the total tick count by two */
-
- g_cpuload_total >>= 1;
- }
-}
-#else
-# define sched_process_cpuload()
-#endif
-
-/************************************************************************
* Public Functions
************************************************************************/
@@ -253,7 +197,14 @@ void sched_process_timer(void)
* can occur)
*/
- sched_process_cpuload();
+#ifdef CONFIG_SCHED_CPULOAD
+#ifdef CONFIG_HAVE_WEAKFUNCTIONS
+ if (sched_process_cpuload != NULL)
+#endif
+ {
+ sched_process_cpuload();
+ }
+#endif
/* Process watchdogs (if in the link) */
diff --git a/nuttx/sched/sched_releasetcb.c b/nuttx/sched/sched_releasetcb.c
index 2b184fbda..21854c83d 100644
--- a/nuttx/sched/sched_releasetcb.c
+++ b/nuttx/sched/sched_releasetcb.c
@@ -70,7 +70,14 @@ static void sched_releasepid(pid_t pid)
g_pidhash[hash_ndx].tcb = NULL;
g_pidhash[hash_ndx].pid = INVALID_PROCESS_ID;
+
#ifdef CONFIG_SCHED_CPULOAD
+ /* Decrement the total CPU load count held by this thread from the
+ * total for all threads. Then we can reset the count on this
+ * defunct thread to zero.
+ */
+
+ g_cpuload_total -= g_pidhash[hash_ndx].ticks;
g_pidhash[hash_ndx].ticks = 0;
#endif
}