Forums

counting cycles, blackfin

Started by Unknown August 10, 2005
Hi all, I'm new to programming the ADSP-BF533 and I would like to know
the recommended way to count the nr of cycles used by a function.

Here's what I'm doing now:

main()
{
    int start, stop, overhead, cycles;

    start = sysreg_read(reg_CYCLES);
    stop = sysreg_read(reg_CYCLES);
    overhead = stop - start;

    sysreg_write(reg_CYCLES, 0x0); // don't want any overflow
    start = sysreg_read(reg_CYCLES);
    filter(); // function I want to profile
    stop = sysreg_read(reg_CYCLES);
    cycles = stop - start - overhead;
}

Will this give an accurate cycle count? Or is there another, better way
to do this?

Thanks,
T.

I don't know about the BlackFin, but on the ADSP SHARC  family, there is a 
"hidden" register called EMUCLK (emulator clock) that is useful for counting 
cycles.  It is read-only, so you can't zero it out, but as long as your function 
won't wrap more than once, you can simply compensate for any wrapping (which is 
unlikely on the SHARC, since it is a 32-bit counter and typically doesn't wrap 
for hours).  But I think your method looks fine.

-- 
Jon Harris
SPAM blocker in place:
Remove 99 (but leave 7) to reply

<t_gatu@hotmail.com> wrote in message 
news:1123662998.742308.233720@g43g2000cwa.googlegroups.com...
> Hi all, I'm new to programming the ADSP-BF533 and I would like to know > the recommended way to count the nr of cycles used by a function. > > Here's what I'm doing now: > > main() > { > int start, stop, overhead, cycles; > > start = sysreg_read(reg_CYCLES); > stop = sysreg_read(reg_CYCLES); > overhead = stop - start; > > sysreg_write(reg_CYCLES, 0x0); // don't want any overflow > start = sysreg_read(reg_CYCLES); > filter(); // function I want to profile > stop = sysreg_read(reg_CYCLES); > cycles = stop - start - overhead; > } > > Will this give an accurate cycle count? Or is there another, better way > to do this? > > Thanks, > T. >