Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
BroadcastCommunity.qnx.com will be offline from May 31 6:00pm until June 2 12:00AM for upcoming system upgrades. For more information please go to https://community.qnx.com/sf/discussion/do/listPosts/projects.bazaar/discussion.bazaar.topc28418
Forum Topic - how to get accurate IDLE Times per core?: (4 Items)
   
how to get accurate IDLE Times per core?  
Hello,

is there a way to get accurate information of the free cpu time (= the idle time of a core)? 

My problem is the resolution of the qnx accounting. Using clock_gettime() or devctl(..., DCMD_PROC_INFO, ) information, 
one get's very vague values. 

For example a process is triggered by an interrupt and is running with a period of 1ms + the system's period is 1ms, the
 process is running for 500us / cycle. This would be around 50% load on one core. But the /proc/<pid>/as information is 
wrong.

As far as I know, this is because the cpu usage is updated with each system tick and thus has a resolution of 1ms. This 
leads to an enormous error in case some processes are running periodically with a period >= the system clock...

I tried using itel's APERF/MPERF using rdmsr, which works pretty well. But it needs to executed in priviledge level 0, 
so I used an isr, but all isr are running on core0 -> no way for me to get the information of core1 ... coreN


Any Ideas? 

Thanks!
Matthias

Re: how to get accurate IDLE Times per core?  
> Hello,
> 
> is there a way to get accurate information of the free cpu time (= the idle 
> time of a core)? 
> 
> My problem is the resolution of the qnx accounting. Using clock_gettime() or 
> devctl(..., DCMD_PROC_INFO, ) information, one get's very vague values. 
> 
> For example a process is triggered by an interrupt and is running with a 
> period of 1ms + the system's period is 1ms, the process is running for 500us /
>  cycle. This would be around 50% load on one core. But the /proc/<pid>/as 
> information is wrong.
> 
> As far as I know, this is because the cpu usage is updated with each system 
> tick and thus has a resolution of 1ms. This leads to an enormous error in case
>  some processes are running periodically with a period >= the system clock...
> 
> I tried using itel's APERF/MPERF using rdmsr, which works pretty well. But it 
> needs to executed in priviledge level 0, so I used an isr, but all isr are 
> running on core0 -> no way for me to get the information of core1 ... coreN
> 
> 
> Any Ideas? 
> 
> Thanks!
> Matthias
> 
Scheduler and time accounting - an endless riddle ...
Take a look at the sched and you'll see that it uses not just a time value, but also some micro billing on kernel calls 
for your thread.
If you don't want to rely on hw specific things, you can use "Dynamic Event Filtering" from the TraceEvent() API.
You can use this without having tracelogger active.
Your app will have to look for RUNNING Events from each idle thread and has to check for the next 'other' RUNNING for 
each core.
You'll have to fiddle with TraceEvent callback data, and you also you hace to take care about Interrupt Events (the 
active process does not get a state change on an interrupt).
Other solutions will require HW related implementations.
This is the most accurate accounting with lowest possoible runtime impact I know - without using HW specifics.

I did this in the past - but I can't share the source.

HTH
/hp
Re: how to get accurate IDLE Times per core?  
Thanks!

seems to be a solution, though is it possible to start tracelogger (e.g. take a kernel event tracing snapshot), while 
running this kind of "free-cpu" measuring? 

Do I need to add a 

TraceEvent(_NTO_TRACE_ADDEVENTHANDLER, 
           class, 
           event, 
           int (*event_hdlr)(event_data_t*), 
           event_data_t* data_struct)

handler to achieve this task? 

Any other ideas on how to execute a rdmsr on a specific core? 

Cheers!
Matthias
Re: how to get accurate IDLE Times per core?  
> Thanks!
> 
> seems to be a solution, though is it possible to start tracelogger (e.g. take 
> a kernel event tracing snapshot), while running this kind of "free-cpu" 
> measuring? 
Yes - that is still possible.

> 
> Do I need to add a 
> 
> TraceEvent(_NTO_TRACE_ADDEVENTHANDLER, 
>            class, 
>            event, 
>            int (*event_hdlr)(event_data_t*), 
>            event_data_t* data_struct)
> 
> handler to achieve this task? 
exactly
Keep in mind that this event handler is running in an ISR like context, and be carefull using libc functions.

/hp