It pretty much has to be that way.....
What value should be reported free if malloc has 1000 1000 byte blocks free?
1000 (ie the largest single block one could malloc, or 1000000 the total amount of availible blocks?
It gets really complicated.. so we just report the largest contiguious free block availible...
Getting CPU statistics
-
- Posts: 622
- Joined: Mon May 12, 2008 10:55 am
Re: Getting CPU statistics
I followed pbreed's instructions to modify OSTaskIdle() and added function CpuFreePercentPreviousSecond() with a slight modification. The mod was to subtract the result from 100 to get CPU usage rather than CPU free percentage.
This has been working for a couple years until this morning. On an engineering board that has been running for years, the above function started returning a value of 42949697275. This means that LastLoopCount is larger than MY_MEASURED_CONSTANT.
I ran TaskScan and it reports that "Task #55 Main is waiting on Semaphore for 4291889325 ticks." And doing multiple scans reports the same, with tick values within a few hundred ticks of each other. However, main is not stopped, because I can still communicate with the module and a heartbeat led is blinking normally.
I haven't reset the module yet, because I believe that will clear the problem and I would like to identify the issue if possible.
Regardless of the problem, I think the above function should be modified to not return a value greater than 100%. Seem reasonable?
This is on a NANO using v3.4.0 of the tools.
Code: Select all
DWORD CpuLoadofPreviousSecond()
{
#define MY_MEASURED_CONSTANT 3440815 // Using v3.3.9: Measured: 4301016; Adjusted to Match NB debug tools: 3440815
static DWORD cpu_usage = 0;
if ( LastSecSampled < (Secs - 2) ) return cpu_usage;
cpu_usage = 100 - (100 *LastLoopCount / (MY_MEASURED_CONSTANT));
return cpu_usage;
}
I ran TaskScan and it reports that "Task #55 Main is waiting on Semaphore for 4291889325 ticks." And doing multiple scans reports the same, with tick values within a few hundred ticks of each other. However, main is not stopped, because I can still communicate with the module and a heartbeat led is blinking normally.
I haven't reset the module yet, because I believe that will clear the problem and I would like to identify the issue if possible.
Regardless of the problem, I think the above function should be modified to not return a value greater than 100%. Seem reasonable?
This is on a NANO using v3.4.0 of the tools.
Re: Getting CPU statistics
This is some kind of tick overflow...
IE at 20 ticks per second the high bit of Timetick happens in : 3.4 years
IE at 20 ticks per second the high bit of Timetick happens in : 3.4 years
-
- Posts: 622
- Joined: Mon May 12, 2008 10:55 am
Re: Getting CPU statistics
It's been over three days since I noticed this issue, and the function is still returning a value of 4294967275. Is there anything short of a reboot than can correct a tick overflow?
-
- Posts: 622
- Joined: Mon May 12, 2008 10:55 am
Re: Getting CPU statistics
Do you think that function CpuLoadofPreviousSecond() should use OSLock() & OSUnlock() before accessing LastSecSampled & LastLoopCount?