Getting CPU statistics

Discussion to talk about software related topics only.
User avatar
pbreed
Posts: 1088
Joined: Thu Apr 24, 2008 3:58 pm

Re: Getting CPU statistics

Post by pbreed »

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...
SeeCwriter
Posts: 622
Joined: Mon May 12, 2008 10:55 am

Re: Getting CPU statistics

Post by SeeCwriter »

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.

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;
  }
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.
User avatar
pbreed
Posts: 1088
Joined: Thu Apr 24, 2008 3:58 pm

Re: Getting CPU statistics

Post by pbreed »

This is some kind of tick overflow...
IE at 20 ticks per second the high bit of Timetick happens in : 3.4 years
SeeCwriter
Posts: 622
Joined: Mon May 12, 2008 10:55 am

Re: Getting CPU statistics

Post by SeeCwriter »

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?
SeeCwriter
Posts: 622
Joined: Mon May 12, 2008 10:55 am

Re: Getting CPU statistics

Post by SeeCwriter »

Do you think that function CpuLoadofPreviousSecond() should use OSLock() & OSUnlock() before accessing LastSecSampled & LastLoopCount?
Post Reply