summaryrefslogtreecommitdiff
path: root/nuttx/fs/procfs/fs_procfscpuload.c
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-02-23 10:55:01 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-02-23 10:55:01 -0600
commit7c745cd460ea7361719b9fd18a35491beed92623 (patch)
treeb35642399f2cbe11bbe6c9a57f6cf2d90fea3ffb /nuttx/fs/procfs/fs_procfscpuload.c
parent875b32e8389ac6e06bfb328e992c1865445d96c1 (diff)
downloadpx4-nuttx-7c745cd460ea7361719b9fd18a35491beed92623.tar.gz
px4-nuttx-7c745cd460ea7361719b9fd18a35491beed92623.tar.bz2
px4-nuttx-7c745cd460ea7361719b9fd18a35491beed92623.zip
CPU load calculations now available for all threads. Available in /proc/pid/loadavg
Diffstat (limited to 'nuttx/fs/procfs/fs_procfscpuload.c')
-rw-r--r--nuttx/fs/procfs/fs_procfscpuload.c40
1 files changed, 17 insertions, 23 deletions
diff --git a/nuttx/fs/procfs/fs_procfscpuload.c b/nuttx/fs/procfs/fs_procfscpuload.c
index a1f8179bf..75572dee3 100644
--- a/nuttx/fs/procfs/fs_procfscpuload.c
+++ b/nuttx/fs/procfs/fs_procfscpuload.c
@@ -207,9 +207,6 @@ static ssize_t cpuload_read(FAR struct file *filep, FAR char *buffer,
size_t buflen)
{
FAR struct cpuload_file_s *attr;
- uint32_t cpuload;
- uint32_t cpuload_int;
- uint32_t cpuload_frac;
size_t linesize;
off_t offset;
ssize_t ret;
@@ -230,40 +227,37 @@ static ssize_t cpuload_read(FAR struct file *filep, FAR char *buffer,
if (filep->f_pos == 0)
{
- uint32_t idle;
- uint32_t busycnt;
- uint32_t verify;
+ struct cpuload_s cpuload;
+ uint32_t intpart;
+ uint32_t fracpart;
- /* Sample the counts, repeatedly if necessary to assure that they are
- * in sync.
+ /* Sample the counts for the IDLE thread. clock_cpuload should only
+ * fail if the PID is not valid. This, however, should never happen
+ * for the IDLE thread.
*/
- do
- {
- busycnt = g_cpuload.cnt;
- idle = g_cpuload.idle;
- verify = g_cpuload.cnt;
- }
- while (busycnt != verify);
+ DEBUGVERIFY(clock_cpuload(0, &cpuload));
- /* On the simulator, you may hit busycnt == 0, but probably never on
+ /* On the simulator, you may hit cpuload.total == 0, but probably never on
* real hardware.
*/
- if (busycnt > 0)
+ if (cpuload.total > 0)
{
- cpuload = 1000 - (1000 * idle) / busycnt;
- cpuload_int = cpuload / 10;
- cpuload_frac = cpuload - 10 * cpuload_int;
+ uint32_t tmp;
+
+ tmp = 1000 - (1000 * cpuload.active) / cpuload.total;
+ intpart = tmp / 10;
+ fracpart = tmp - 10 * intpart;
}
else
{
- cpuload_int = 0;
- cpuload_frac = 0;
+ intpart = 0;
+ fracpart = 0;
}
linesize = snprintf(attr->line, CPULOAD_LINELEN, "%3d.%01d%%\n",
- cpuload_int, cpuload_frac);
+ intpart, fracpart);
/* Save the linesize in case we are re-entered with f_pos > 0 */