Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - API to switch between CPU's?: (10 Items)
   
API to switch between CPU's?  
Related to ClockCycles(). To fix multicore issues I need offsets (i.e. time zero) for all cpus,
kernel has  uint64_t			clockcycles_offset[PROCESSORS_MAX];
which I need but I cannot get it because it is kernel. To do in myself I need to do something like


for (i=0;i<cpunum();i++) {
   bind_to_cpu(i);
   clockcycles_offset[i]=ClockCycles();
}
unbind();

So the problem is I cannot find how to bind to specific cpu programmatically. Anybody knows?
RE: API to switch between CPU's?  
ThreadCtl(_NTO_TCTL_RUNMASK, mask)

Where mask is a bitfield of which cpus the thread is allowed to run on.


So your code could be:

Uint32_t runmask;
for (i=0;i<cpunum();i++){
   runmask = 1UL<<i;
   ThreadCtl(_NTO_TCTL_RUNMASK, *runmask);
   clockcycles_offset[i] = ClockCycles();
} 

To allow the code to run on any CPU, just set the runmask to all FF

runmask = 0xFFFFFFFFUL;
ThreadCtl(_NTO_TCTL_RUNMASK, &runmask);

> -----Original Message-----
> From: Elena Laskavaia [mailto:community-noreply@qnx.com] 
> Sent: May 10, 2010 4:33 PM
> To: ostech-core_os
> Subject: API to switch between CPU's?
> 
> Related to ClockCycles(). To fix multicore issues I need 
> offsets (i.e. time zero) for all cpus,
> kernel has  uint64_t			
> clockcycles_offset[PROCESSORS_MAX];
> which I need but I cannot get it because it is kernel. To do 
> in myself I need to do something like
> 
> 
> for (i=0;i<cpunum();i++) {
>    bind_to_cpu(i);
>    clockcycles_offset[i]=ClockCycles();
> }
> unbind();
> 
> So the problem is I cannot find how to bind to specific cpu 
> programmatically. Anybody knows?
> 
> 
> 
> _______________________________________________
> 
> OSTech
> http://community.qnx.com/sf/go/post54110
> 
> 
RE: API to switch between CPU's?  

> -----Original Message-----
> From: Elena Laskavaia [mailto:community-noreply@qnx.com]
> Sent: Monday, May 10, 2010 4:33 PM
> To: ostech-core_os
> Subject: API to switch between CPU's?
> 
> Related to ClockCycles(). To fix multicore issues I need offsets (i.e.
> time zero) for all cpus,
> kernel has  uint64_t			clockcycles_offset[PROCESSORS_MAX];
> which I need but I cannot get it because it is kernel. To do in myself
> I need to do something like
> 
> 
> for (i=0;i<cpunum();i++) {
>    bind_to_cpu(i);
>    clockcycles_offset[i]=ClockCycles();
> }
> unbind();
> 
> So the problem is I cannot find how to bind to specific cpu
> programmatically. Anybody knows?

ThreadCtl() is your friend.

> 
> 
> 
> _______________________________________________
> 
> OSTech
> http://community.qnx.com/sf/go/post54110
> 
Re: API to switch between CPU's?  
I'd be careful.  I could be wrong but I don't believe all the CPUs will
maintain that offset (especially in a power management scenario)
consistently.  Cores can update their free running counter at slightly
different rates even when they are not in any power management mode
depending on the clock source.

-Adam


On 10/05/10 4:32 PM, "Elena Laskavaia" <community-noreply@qnx.com> wrote:

> Related to ClockCycles(). To fix multicore issues I need offsets (i.e. time
> zero) for all cpus,
> kernel has  uint64_t   clockcycles_offset[PROCESSORS_MAX];
> which I need but I cannot get it because it is kernel. To do in myself I need
> to do something like
> 
> 
> for (i=0;i<cpunum();i++) {
>    bind_to_cpu(i);
>    clockcycles_offset[i]=ClockCycles();
> }
> unbind();
> 
> So the problem is I cannot find how to bind to specific cpu programmatically.
> Anybody knows?
> 
> 
> 
> _______________________________________________
> 
> OSTech
> http://community.qnx.com/sf/go/post54110
> 

-- 
Adam Mallory (amallory@qnx.com)
Manager, Support Services               Phone: +1.613.271.9115
QNX Software Systems                   Mobile: +1.613.614.6612


Re: API to switch between CPU's?  
Be careful not to make any assumptions about the relative frequencies of the counters.  It is entirely possible that 
they are not synchronized on all platforms and that idled processors may make no progress at all....
Re: API to switch between CPU's?  
Ok... So there is no reliable way then? I should forget about ClockCycles than and stick 
to the 
gettimeofday(&timer, NULL);
timer.tv_sec*1000*1000+timer.tv_usec
?
Re: API to switch between CPU's?  
On Mon, 2010-05-10 at 17:08 -0400, Elena Laskavaia wrote:
> Ok... So there is no reliable way then? I should forget about ClockCycles than and stick 
> to the 
> gettimeofday(&timer, NULL);
> timer.tv_sec*1000*1000+timer.tv_usec
> ?

I bumped into David and from speaking to him, I think you may have even
bigger problems.  Counters like ClockCycles() and TOD will, of course,
be running even if your thread isn't.  If you're working on improving
the profiling tools, I think that we're going to need to come up with a
much better way of handling this....
Re: API to switch between CPU's?  
Elena,

what about the RTC (IRQ8) as a common source of time ?
It isn't bound to any core ...

--Armin


Elena Laskavaia wrote:
> Ok... So there is no reliable way then? I should forget about ClockCycles than and stick 
> to the 
> gettimeofday(&timer, NULL);
> timer.tv_sec*1000*1000+timer.tv_usec
> ?
>
>
>
> _______________________________________________
>
> OSTech
> http://community.qnx.com/sf/go/post54121
>
>
>   
RE: API to switch between CPU's?  
I had suggested the offset mechanism, based on what I saw in the kernel
tracing code.

After some hallway discussions, there's a few problems with
ClockCycles()

1. It measures all time spent in the system.  This means that if a
function is pre-empted, the pre-emption time is charged to the function.
2. The value returned by ClockCycles() may change depending on which
core is in use, and the delta between the cores may also vary over time.
3. Any sort of power management that involves modifying a core's clock
is going to make this really really hard.

Benefits of ClockCycles()

1. On some systems, it's a really cheap call.
2. It offers the best resolution time source.

It would be fair to say that any user who is profiling their system,
should bind their threads to specific cores, so that thread migration is
not measured by the profiling tools.

The best solution would be to measure the run_time of each individual
thread, because things like pre-emption, and core migration won't be
included in the total.  I don't think Neutrino records a thread's
runtime with accurate enough resolution to provide meaningful
information on many smaller functions.

Pidin can get the runtime of a specific thread, however that is not a
cheap operation, and I think the runtime is in millisecond resolution.

David 

> -----Original Message-----
> From: Neil Schellenberger [mailto:community-noreply@qnx.com] 
> Sent: May 10, 2010 4:52 PM
> To: ostech-core_os
> Subject: Re: API to switch between CPU's?
> 
> Be careful not to make any assumptions about the relative 
> frequencies of the counters.  It is entirely possible that 
> they are not synchronized on all platforms and that idled 
> processors may make no progress at all....
> 
> 
> 
> 
> _______________________________________________
> 
> OSTech
> http://community.qnx.com/sf/go/post54119
> 
> 
RE: API to switch between CPU's?  
Maybe we should consider adding a TLS field(s) or similar to help
profiling out?  Or figuring out a sensible way to use profiling counters
where they're available?

On Mon, 2010-05-10 at 17:14 -0400, David Sarrazin wrote:
> I had suggested the offset mechanism, based on what I saw in the kernel
> tracing code.
> 
> After some hallway discussions, there's a few problems with
> ClockCycles()
> 
> 1. It measures all time spent in the system.  This means that if a
> function is pre-empted, the pre-emption time is charged to the function.
> 2. The value returned by ClockCycles() may change depending on which
> core is in use, and the delta between the cores may also vary over time.
> 3. Any sort of power management that involves modifying a core's clock
> is going to make this really really hard.
> 
> Benefits of ClockCycles()
> 
> 1. On some systems, it's a really cheap call.
> 2. It offers the best resolution time source.
> 
> It would be fair to say that any user who is profiling their system,
> should bind their threads to specific cores, so that thread migration is
> not measured by the profiling tools.
> 
> The best solution would be to measure the run_time of each individual
> thread, because things like pre-emption, and core migration won't be
> included in the total.  I don't think Neutrino records a thread's
> runtime with accurate enough resolution to provide meaningful
> information on many smaller functions.
> 
> Pidin can get the runtime of a specific thread, however that is not a
> cheap operation, and I think the runtime is in millisecond resolution.
> 
> David 
> 
> > -----Original Message-----
> > From: Neil Schellenberger [mailto:community-noreply@qnx.com] 
> > Sent: May 10, 2010 4:52 PM
> > To: ostech-core_os
> > Subject: Re: API to switch between CPU's?
> > 
> > Be careful not to make any assumptions about the relative 
> > frequencies of the counters.  It is entirely possible that 
> > they are not synchronized on all platforms and that idled 
> > processors may make no progress at all....
> > 
> > 
> > 
> > 
> > _______________________________________________
> > 
> > OSTech
> > http://community.qnx.com/sf/go/post54119
> > 
> > 
> 
> 
> 
> _______________________________________________
> 
> OSTech
> http://community.qnx.com/sf/go/post54123
>