2008-02-14 12:54:24 Conversion cycles ==> miliseconds
Piggebu Piggebu (ANDORRA)
Message: 51058 Hi all
Probably a easy question... I saw the performance measurement routines on
http://docs.blackfin.uclinux.org/doku.php?id=making_the_blackfin_perform
and there the performance is measured in cycles.
My question: is there a way to tell how many seconds, miliseconds, nanoseconds etc is equal to one cycle?
On the kernel startup it shows the line:
Processor Speed: 525 MHz core clock and 131 MHz System Clock
If one of those is the asked frequency to convert from cycles to time, which one is it?
For example if the conversion frequency is 131MHz, does that mean that the dot product in the above link is executes in:
53 Cycles = 53/131Mhz = 4*10^-7 seconds = 400 nanoseconds?
Thanks for the help
Regards
Piggebu
QuoteReplyEditDelete
2008-02-14 13:27:32 Re: Conversion cycles ==> miliseconds
Robin Getz (UNITED STATES)
Message: 51060 Piggebu:
Are you measuring inside the kernel, or in userspace? There are functions in the kernel to help, and if you are doing it from userspace, there are better ideas.
-Robin
QuoteReplyEditDelete
2008-02-14 13:48:26 Re: Conversion cycles ==> miliseconds
Mike Frysinger (UNITED STATES)
Message: 51063 cycles is in units of core clocks as the cycles instruction is a core instruction ... system clock has no bearing at all
QuoteReplyEditDelete
2008-02-15 02:53:41 Re: Conversion cycles ==> miliseconds
Piggebu Piggebu (ANDORRA)
Message: 51080 Robin, Mike
Thank you for the replies.
Unfortunately I am no expert in this topic. What I try to do is measure the execution time of some code as for example the following (in pseudo code)
//test.cpp
int main()
{
starttime=time_measurement();
[Do some operations to measure]
endtime=time_measurement()
printf("execution time = %f miliseconds", endtime-starttime);
}
=> running ./test from command prompt should then yield the desired output
So, Robin, I guess I need a measurement for the user space.
I did find some functions such as the "int times(tms*)" which should return results in ms. But it is zero for the operation I like to measure (and with get_cycles() from the link in my first post it shows 842269 cycles). I will need a measurement which can display down to 100000 cycles in some time format...
Regards
Piggebu
QuoteReplyEditDelete
2008-02-15 03:19:37 Re: Conversion cycles ==> miliseconds
Jean Navailles (FRANCE)
Message: 51082 Hi
Can this help you?
static void
PrintTime ( void )
{
struct timeval xTimeCur;
if( gettimeofday( &xTimeCur, NULL ) == 0 )
{
printf ( "\n%02ldmn%02lds%03ldm%03ldµ ", (xTimeCur.tv_sec / 60L) % 60L, xTimeCur.tv_sec % 60L, (xTimeCur.tv_usec / 1000L) % 1000L, xTimeCur.tv_usec % 1000L );
}
}
void foo ()
{
struct timeval CurrentTime;
unsigned long ulDeltaMilliSecondes;
if( gettimeofday( &CurrentTime, NULL ) == 0 )
{
ulDeltaMilliSecondes = ( CurrentTime.tv_sec - StartTime.tv_sec ) * 1000L + ( CurrentTime.tv_usec - StartTime.tv_usec ) / 1000L;
if( ulDeltaMilliSecondes > 200L )
{
}
}
TranslateQuoteReplyEditDelete
2008-02-15 07:50:57 Re: Conversion cycles ==> miliseconds
Piggebu Piggebu (ANDORRA)
Message: 51103 Jean,
This would in fact be what I am looking for. I implemented your suggestion as follows:
gettimeofday(&TimePast,NULL);
bef=read_cycles();
set_pic(screen, bgrframe, ScreenDepth, ScreenX, ScreenY, X, Y, Depth, pos_x, pos_y); // function to measure
aft=read_cycles();
printf("displayreference=%i cyc\n",aft-bef);
gettimeofday(&TimeCur,NULL);
printf ( "\n%02ldmn%02lds%03ldm%03ldµ ", ((TimeCur.tv_sec-TimePast.tv_sec) / 60L) % 60L, (TimeCur.tv_sec-TimePast.tv_sec) % 60L, ((TimeCur.tv_sec-TimePast.tv_sec) / 1000L) % 1000L, (TimeCur.tv_sec-TimePast.tv_sec) % 1000L );
This gives the output:
displayreference=810324 cyc
00mn00s000m000µ
When I check the TimePast and TimeCur values separately I note that the time they provide only changes _very_ slow (hence the zeros in the output). They change 1us every second aproximately...
I still think (?) the most reliable way is to convert the measured cycles to a time. All other time measuring functions ended in the problem mentioned: their difference before-after is zero.
Any idea?
Regards
Piggebu
QuoteReplyEditDelete
2008-02-15 08:43:38 Re: Conversion cycles ==> miliseconds
Jean Navailles (FRANCE)
Message: 51107
Hi
For millisecond and µsecond use usec and not sec in the structure.
Regards
Jean.
TranslateQuoteReplyEditDelete
2008-02-15 10:27:22 Re: Conversion cycles ==> miliseconds
Piggebu Piggebu (ANDORRA)
Message: 51111 Hi all!
Hm, I think a break to recover my brain would have solved the problem much faster... ;-)
Mike, now I understand your words in your reply :-) => cycles / core clock = time in seconds
Jean, thank you very much for your help! With your suggestions I come to the result of nearly 525 cycles per second, which is - as Mike stated long before - the core clock frequency...
Well, sorry for all the trouble and thanks again for the help
Regards
Piggebu
QuoteReplyEditDelete
2008-02-15 13:39:54 Re: Conversion cycles ==> miliseconds
Robin Getz (UNITED STATES)
Message: 51115 Piggebu:
I think a quick read of 'man 7 time' would help as well.
For short time - cycles is the best bet. It measures real time.
But this does not look at what happens the if the kernel schedules your process out . You really don't want to count real time.
What you want (I think) is the amount of CPU time iyour process has consumed - which you can get using times(2), getrusage(2), or clock(3). (check out the man pages for each).
The downside of these - is they measure in resolution of jiffies (1, 4, or 10ms intervals - depending on how the clocks are set), so you may have to run small/quick functions many, many times to get an accurate result.
-Robin