Elena Laskavaia
05/10/2010 11:24 AM
post54067
|
Is there a way to know in advance capacity of ClockCycles() counter?
I.e. is it really 32bit or 64? I.e. in how many seconds it is going to wrap around?
|
|
|
Brian Stecher
|
Re: ClockCycles() wrapping
|
Brian Stecher
05/10/2010 12:07 PM
post54072
|
Re: ClockCycles() wrapping
0xffffffffffffffffull / SYSPAGE_ENTRY(qtime)->cycles_per_sec
will give you the number of seconds before wrapping.
On Mon, May 10, 2010 at 11:24:25AM -0400, Elena Laskavaia wrote:
> Is there a way to know in advance capacity of ClockCycles() counter?
> I.e. is it really 32bit or 64? I.e. in how many seconds it is going to wrap around?
>
>
>
> _______________________________________________
>
> OSTech
> http://community.qnx.com/sf/go/post54067
>
--
Brian Stecher (bstecher@qnx.com) QNX Software Systems
phone: +1 (613) 591-0931 (voice) 175 Terence Matthews Cr.
+1 (613) 591-3579 (fax) Kanata, Ontario, Canada K2M 1W8
|
|
|
Colin Burgess(deleted)
|
Re: ClockCycles() wrapping
|
Colin Burgess(deleted)
05/10/2010 12:09 PM
post54073
|
Re: ClockCycles() wrapping
CLOCKCYCLES_INCR_BIT is defined in <cpu>/neutrino.h to be the amount
that the raw counter
is shifted up.
On 10-05-10 11:24 AM, Elena Laskavaia wrote:
> Is there a way to know in advance capacity of ClockCycles() counter?
> I.e. is it really 32bit or 64? I.e. in how many seconds it is going to wrap around?
>
>
>
> _______________________________________________
>
> OSTech
> http://community.qnx.com/sf/go/post54067
>
>
--
cburgess@qnx.com
|
|
|
Elena Laskavaia
|
Re: ClockCycles() wrapping
|
Elena Laskavaia
05/10/2010 1:34 PM
post54086
|
Re: ClockCycles() wrapping
I guess I was not clear, but I understand now - it always wrap at 0xffffffff, but if actual counter
is at lower resolution kernel "upconverts" it using CLOCKCYCLES_INCR_BIT .
In general I would like to make a function that prints a time relative to "timeZero"
i.e.
uint64_t cycles = ClockCycles() - timeZero;
But it cannot be negative (because it is unsigned), so I need to do some tricks to
make this expression correct. I am not that good a C if somebody knows easy way to do
it let me know.
Two more problems:
1) ClockCycles on multicore
Apparently ClockCycles() is not synchronized between CPU's. Which makes profiling bogus,
i..e
start = ClockCycles(); // on cpu0
...
stop = ClockCycles(); // on cpu1
stop - start = garbage
How do I deal with that?
a) Can I ask for ClockCycles() from the same cpu always, not the current one?
b) Can I sync them programmatically?
c) Can I sync them on startup on target some how?
2) On some CPU's ClockCycles is inline function, and when I compile app with --instrument-functions it instruments it! I
have re-entry prevention but it still sucks because it is
a lot of overhead. I tried to add another declaration of ClockCycles with __attribute__ ((no_instrument_function)) but
it does not help - it has to be in original declaration I guess.
Any other suggestion (besides fixing the header)?
|
|
|
David Sarrazin
|
RE: ClockCycles() wrapping
|
David Sarrazin
05/10/2010 2:00 PM
post54092
|
RE: ClockCycles() wrapping
> -----Original Message-----
> From: Elena Laskavaia [mailto:community-noreply@qnx.com]
> Sent: May 10, 2010 1:34 PM
> To: ostech-core_os
> Subject: Re: ClockCycles() wrapping
>
> I guess I was not clear, but I understand now - it always
> wrap at 0xffffffff, but if actual counter is at lower
> resolution kernel "upconverts" it using CLOCKCYCLES_INCR_BIT .
>
> In general I would like to make a function that prints a time
> relative to "timeZero"
> i.e.
>
> uint64_t cycles = ClockCycles() - timeZero;
>
> But it cannot be negative (because it is unsigned), so I
> need to do some tricks to make this expression correct. I am
> not that good a C if somebody knows easy way to do it let me know.
How do you determine timeZero? Is it an earlier call to ClockCycles()?
Ignoring the SMP case, ClockCycles() will always return a >= number than
a previous call to ClockCycles().
>
> Two more problems:
> 1) ClockCycles on multicore
> Apparently ClockCycles() is not synchronized between CPU's.
> Which makes profiling bogus, i..e
>
> start = ClockCycles(); // on cpu0
> ...
> stop = ClockCycles(); // on cpu1
>
> stop - start = garbage
>
> How do I deal with that?
>
> a) Can I ask for ClockCycles() from the same cpu always, not
> the current one?
> b) Can I sync them programmatically?
> c) Can I sync them on startup on target some how?
Other than binding the instrumented code to a fixed CPU? I don't' know.
>
>
> 2) On some CPU's ClockCycles is inline function, and when I
> compile app with --instrument-functions it instruments it! I
> have re-entry prevention but it still sucks because it is a
> lot of overhead. I tried to add another declaration of
> ClockCycles with __attribute__ ((no_instrument_function)) but
> it does not help - it has to be in original declaration I guess.
> Any other suggestion (besides fixing the header)?
Is it enough to change services/system/public/<cpu>/neutrino.h and add
the __attribute__ (no_instrument_function)? For at least ARM, the
function body is actually in an asm file in
lib/c/kercover/arm/ClockCycles.S
>
>
>
> _______________________________________________
>
> OSTech
> http://community.qnx.com/sf/go/post54086
>
>
|
|
|
Neil Schellenberger(deleted)
|
RE: ClockCycles() wrapping
|
Neil Schellenberger(deleted)
05/10/2010 2:44 PM
post54096
|
RE: ClockCycles() wrapping
On Mon, 2010-05-10 at 14:00 -0400, David Sarrazin wrote:
> > But it cannot be negative (because it is unsigned), so I
> > need to do some tricks to make this expression correct. I am
> > not that good a C if somebody knows easy way to do it let me know.
>
> How do you determine timeZero? Is it an earlier call to ClockCycles()?
> Ignoring the SMP case, ClockCycles() will always return a >= number than
> a previous call to ClockCycles().
Well, at least until it wraps around ;-)
> > a) Can I ask for ClockCycles() from the same cpu always, not
> > the current one?
> > b) Can I sync them programmatically?
> > c) Can I sync them on startup on target some how?
>
> Other than binding the instrumented code to a fixed CPU? I don't' know.
There is no generic way to sync between processors. (They may not even
be running at the same rate....)
> > 2) On some CPU's ClockCycles is inline function, and when I
> > compile app with --instrument-functions it instruments it! I
> > have re-entry prevention but it still sucks because it is a
> > lot of overhead. I tried to add another declaration of
> > ClockCycles with __attribute__ ((no_instrument_function)) but
> > it does not help - it has to be in original declaration I guess.
> > Any other suggestion (besides fixing the header)?
>
> Is it enough to change services/system/public/<cpu>/neutrino.h and add
> the __attribute__ (no_instrument_function)? For at least ARM, the
> function body is actually in an asm file in
> lib/c/kercover/arm/ClockCycles.S
Instrumentation would only apply to inline C code, so pure assembly
wouldn't be a problem, C declaration notwithstanding. The attribute
should have done the trick, provided it appeared before the definition
was encountered by the compiler. (The simplest way to arrange for this
is, of course, to change the header -- which is almost certainly what
ought to be done.)
|
|
|
David Sarrazin
|
RE: ClockCycles() wrapping
|
David Sarrazin
05/10/2010 2:49 PM
post54098
|
RE: ClockCycles() wrapping
> -----Original Message-----
> From: Neil Schellenberger [mailto:community-noreply@qnx.com]
> Sent: May 10, 2010 2:44 PM
> To: ostech-core_os
> Subject: RE: ClockCycles() wrapping
>
> On Mon, 2010-05-10 at 14:00 -0400, David Sarrazin wrote:
> > > But it cannot be negative (because it is unsigned), so I
> need to do
> > > some tricks to make this expression correct. I am not
> that good a C
> > > if somebody knows easy way to do it let me know.
> >
> > How do you determine timeZero? Is it an earlier call to
> ClockCycles()?
> > Ignoring the SMP case, ClockCycles() will always return a >= number
> > than a previous call to ClockCycles().
>
> Well, at least until it wraps around ;-)
Yes, I kinda flunked kindergarten 101 with that comment. So then the
question becomes "how can an application determine how many times
ClockCycles() has wrapped?"
>
> > > a) Can I ask for ClockCycles() from the same cpu always, not the
> > > current one?
> > > b) Can I sync them programmatically?
> > > c) Can I sync them on startup on target some how?
> >
> > Other than binding the instrumented code to a fixed CPU? I
> don't' know.
>
> There is no generic way to sync between processors. (They
> may not even be running at the same rate....)
>
> > > 2) On some CPU's ClockCycles is inline function, and when
> I compile
> > > app with --instrument-functions it instruments it! I have
> re-entry
> > > prevention but it still sucks because it is a lot of overhead. I
> > > tried to add another declaration of ClockCycles with
> __attribute__
> > > ((no_instrument_function)) but it does not help - it has to be in
> > > original declaration I guess.
> > > Any other suggestion (besides fixing the header)?
> >
> > Is it enough to change
> services/system/public/<cpu>/neutrino.h and add
> > the __attribute__ (no_instrument_function)? For at least ARM, the
> > function body is actually in an asm file in
> > lib/c/kercover/arm/ClockCycles.S
>
> Instrumentation would only apply to inline C code, so pure
> assembly wouldn't be a problem, C declaration
> notwithstanding. The attribute should have done the trick,
> provided it appeared before the definition was encountered by
> the compiler. (The simplest way to arrange for this is, of
> course, to change the header -- which is almost certainly
> what ought to be done.)
>
>
>
>
> _______________________________________________
>
> OSTech
> http://community.qnx.com/sf/go/post54096
>
>
|
|
|
Brian Stecher
|
Re: ClockCycles() wrapping
|
Brian Stecher
05/10/2010 2:54 PM
post54099
|
Re: ClockCycles() wrapping
On Mon, May 10, 2010 at 02:49:33PM -0400, David Sarrazin wrote:
> Yes, I kinda flunked kindergarten 101 with that comment. So then the
> question becomes "how can an application determine how many times
> ClockCycles() has wrapped?"
You can't, but
diff = ClockCyles() - start_cycles;
will produce the right answer as long as you haven't exceeded a
cycle count of 0xffffffffffffffffULL. Making that work is why we scale
up the value when the hardware doesn't provide a full 64 bit counter.
--
Brian Stecher (bstecher@qnx.com) QNX Software Systems
phone: +1 (613) 591-0931 (voice) 175 Terence Matthews Cr.
+1 (613) 591-3579 (fax) Kanata, Ontario, Canada K2M 1W8
|
|
|
Mario Charest
|
RE: ClockCycles() wrapping
|
Mario Charest
05/10/2010 3:23 PM
post54103
|
RE: ClockCycles() wrapping
> -----Original Message-----
> From: David Sarrazin [mailto:community-noreply@qnx.com]
> Sent: Monday, May 10, 2010 2:50 PM
> To: ostech-core_os
> Subject: RE: ClockCycles() wrapping
>
>
>
>
> > -----Original Message-----
> > From: Neil Schellenberger [mailto:community-noreply@qnx.com]
> > Sent: May 10, 2010 2:44 PM
> > To: ostech-core_os
> > Subject: RE: ClockCycles() wrapping
> >
> > On Mon, 2010-05-10 at 14:00 -0400, David Sarrazin wrote:
> > > > But it cannot be negative (because it is unsigned), so I
> > need to do
> > > > some tricks to make this expression correct. I am not
> > that good a C
> > > > if somebody knows easy way to do it let me know.
> > >
> > > How do you determine timeZero? Is it an earlier call to
> > ClockCycles()?
> > > Ignoring the SMP case, ClockCycles() will always return a >= number
> > > than a previous call to ClockCycles().
> >
> > Well, at least until it wraps around ;-)
>
>
> Yes, I kinda flunked kindergarten 101 with that comment. So then the
> question becomes "how can an application determine how many times
> ClockCycles() has wrapped?"
Given a 4G clock, the low 32 bit will wrapped after 1 seconds, that means the 32 upper bit are the number of seconds the
value can represent and it`s a VERY long time ;-) Something like 120 years.
>
>
> >
> > > > a) Can I ask for ClockCycles() from the same cpu always, not the
> > > > current one?
> > > > b) Can I sync them programmatically?
> > > > c) Can I sync them on startup on target some how?
> > >
> > > Other than binding the instrumented code to a fixed CPU? I
> > don't' know.
> >
> > There is no generic way to sync between processors. (They
> > may not even be running at the same rate....)
> >
> > > > 2) On some CPU's ClockCycles is inline function, and when
> > I compile
> > > > app with --instrument-functions it instruments it! I have
> > re-entry
> > > > prevention but it still sucks because it is a lot of overhead. I
> > > > tried to add another declaration of ClockCycles with
> > __attribute__
> > > > ((no_instrument_function)) but it does not help - it has to be in
> > > > original declaration I guess.
> > > > Any other suggestion (besides fixing the header)?
> > >
> > > Is it enough to change
> > services/system/public/<cpu>/neutrino.h and add
> > > the __attribute__ (no_instrument_function)? For at least ARM, the
> > > function body is actually in an asm file in
> > > lib/c/kercover/arm/ClockCycles.S
> >
> > Instrumentation would only apply to inline C code, so pure
> > assembly wouldn't be a problem, C declaration
> > notwithstanding. The attribute should have done the trick,
> > provided it appeared before the definition was encountered by
> > the compiler. (The simplest way to arrange for this is, of
> > course, to change the header -- which is almost certainly
> > what ought to be done.)
> >
> >
> >
> >
> > _______________________________________________
> >
> > OSTech
> > http://community.qnx.com/sf/go/post54096
> >
> >
>
>
>
> _______________________________________________
>
> OSTech
> http://community.qnx.com/sf/go/post54098
>
|
|
|
Elena Laskavaia
|
Re: ClockCycles() wrapping
|
Elena Laskavaia
05/10/2010 3:30 PM
post54105
|
Re: ClockCycles() wrapping
>
> Given a 4G clock, the low 32 bit will wrapped after 1 seconds, that means the 32 upper bit are the number of seconds
the value can represent and it`s a VERY long time ;-) Something like 120 years.
>
>
3 minutes on MIPS
|
|
|
Mario Charest
|
RE: ClockCycles() wrapping
|
Mario Charest
05/10/2010 4:43 PM
post54112
|
RE: ClockCycles() wrapping
> -----Original Message-----
> From: Elena Laskavaia [mailto:community-noreply@qnx.com]
> Sent: Monday, May 10, 2010 3:31 PM
> To: ostech-core_os
> Subject: Re: ClockCycles() wrapping
>
>
> >
> > Given a 4G clock, the low 32 bit will wrapped after 1 seconds, that
> means the 32 upper bit are the number of seconds the value can
> represent and it`s a VERY long time ;-) Something like 120 years.
> >
> >
> 3 minutes on MIPS
Huh? How can that be?
>
>
>
>
> _______________________________________________
>
> OSTech
> http://community.qnx.com/sf/go/post54105
>
|
|
|
Neil Schellenberger(deleted)
|
RE: ClockCycles() wrapping
|
Neil Schellenberger(deleted)
05/10/2010 4:49 PM
post54118
|
RE: ClockCycles() wrapping
On Mon, 2010-05-10 at 16:43 -0400, Mario Charest wrote:
>
> > -----Original Message-----
> > From: Elena Laskavaia [mailto:community-noreply@qnx.com]
> > Sent: Monday, May 10, 2010 3:31 PM
> > To: ostech-core_os
> > Subject: Re: ClockCycles() wrapping
> >
> >
> > >
> > > Given a 4G clock, the low 32 bit will wrapped after 1 seconds, that
> > means the 32 upper bit are the number of seconds the value can
> > represent and it`s a VERY long time ;-) Something like 120 years.
> > >
> > >
> > 3 minutes on MIPS
>
> Huh? How can that be?
We only use a 32 bit counter on MIPS :-)
|
|
|
Elena Laskavaia
|
Re: ClockCycles() wrapping
|
Elena Laskavaia
05/10/2010 3:01 PM
post54100
|
Re: ClockCycles() wrapping
to summarize
0)
diff = ClockCyles() - start_cycles;
does produce right answer. I think I got wrong one because I was doing something like
shift = CLOCKCYCLES_INCR_BIT;
diff = (ClockCyles() >> shift) - (start_cycles >> shift);
1) For synchronization:
there is no way to sync ClockCycles on multi core I need to keeps all
cpu ClockCycles offsets, not just one
now I need to figure our how to get ClockCycles for all cpus...
2) For no instrument functions I need to include my declaration before
header file or send pr to os/lib to fix the header
|
|
|
|