DSPRelated.com
Forums

reg. measuring cycle counts ADSP TS201

Started by dsp newbie April 23, 2007
Hi,

I am trying to calculate the number of cycle counts in my
program for a particular section of the code. But I am not getting the
total cycle count for some reason. I followed the instructions in the
document VDSP++ 4.5 C/C++ compiler and library manual under section
"measuring cycle counts". I am trying to use "Basic cycle counting
facility". The part of the code I have written is as follows. I am
using cycle_count.h header file.
cycle_t cycle_count;
.................
............

START_CYCLE_COUNT(cycle_count);
...................

STOP_CYCLE_COUNT(cycle_count, cycle_count);
cout << cycle_count;
//PRINT_CYCLES("number of cycle counts:",cycle_count);
My problem is I am always getting the same value for
cycle_count as 2779324877496216 irrespective of where I am starting
and stopping it and how much ever code I am executing in between them.
I wonder what I am doing wrong? I am not getting any other value.
Please help on this! Does it have anything to do with the
-DDO_CYCLE_COUNTS switch? How can I invoke or enable this switch?
Thanks a lot
Hi:

If you want to enable the definition and try it out, just add identifier
DO_CYCLE_COUNTS to the preprocessor definitions section in the project
settings for your VisualDSP++ project. Although not too sure if this will
solve your problem as I haven't done cycle counting myself. But I guess you
can give it a try and see if it works.

HTH,

Chamira.

On 4/23/07, dsp newbie wrote:
>
> Hi,
>
> I am trying to calculate the number of cycle counts in my program for a
> particular section of the code. But I am not getting the total cycle count
> for some reason. I followed the instructions in the document VDSP++ 4.5C/C++ compiler and library manual under section "measuring cycle counts". I
> am trying to use "Basic cycle counting facility". The part of the code I
> have written is as follows. I am using cycle_count.h header file.
> cycle_t cycle_count;
> .................
> ............
>
> START_CYCLE_COUNT(cycle_count);
> ...................
>
> STOP_CYCLE_COUNT(cycle_count, cycle_count);
> cout << cycle_count;
> //PRINT_CYCLES("number of cycle counts:",cycle_count);
>
> My problem is I am always getting the same value for cycle_count as
> 2779324877496216 irrespective of where I am starting and stopping it and how
> much ever code I am executing in between them. I wonder what I am doing
> wrong? I am not getting any other value. Please help on this! Does it have
> anything to do with the -DDO_CYCLE_COUNTS switch? How can I invoke or enable
> this switch?
>
> Thanks a lot
>
>
>
On Mon, 23 Apr 2007, dsp newbie wrote:

>
> My problem is I am always getting the same value for
> cycle_count as 2779324877496216 irrespective of where I am starting
> and stopping it and how much ever code I am executing in between them.
> I wonder what I am doing wrong? I am not getting any other value.
> Please help on this! Does it have anything to do with the
> -DDO_CYCLE_COUNTS switch? How can I invoke or enable this switch?

I haven't a clue what is wrong, but if you convert that to hex you get
9dfc80009df98 which is suspiciously like a pointer, or two. Maybe you are
missing a level of indirection??

Patience, persistence, truth,
Dr. mike
Hi. See answers between quotes...

> Hi,
>
> I am trying to calculate the number of cycle counts in my
> program for a particular section of the code. But I am not getting the
> total cycle count for some reason. I followed the instructions in the
> document VDSP++ 4.5 C/C++ compiler and library manual under section
> "measuring cycle counts". I am trying to use "Basic cycle counting
> facility". The part of the code I have written is as follows.
> I am using cycle_count.h header file.
See also files xcycle_count.h, and cycle_count_ts.h for details
If you look into these files you'll find out that
1) START..., STOP..., PRINT... are macros which evaluate to NOTHING if the
DO_CYCLE_COUNTS switch is not set, otherwise they lead to a sequence of
assembler commands, which work mainly with the registers CCNT0, CCNT1

>
> cycle_t cycle_count;
perfect.
> .................
> ............
>
> START_CYCLE_COUNT(cycle_count);
fine.
> ...................
>
> STOP_CYCLE_COUNT(cycle_count, cycle_count);
that's it. Here you should see that the contents of cycle_count are correct.
> cout << cycle_count;
Ohhh. This is C++ code.
Be aware that C++ mangles variable names, and that it might blow up variables
by adding additional information. I would suggest that you watch the variable
cycle_count in an expression window, and watch in the disassembler what
START_... and STOP_.. do with this variable.

> //PRINT_CYCLES("number of cycle counts:",cycle_count);
This line might fail as cout <<... does, if the above macros wouldn't write
the value correctly.
> My problem is I am always getting the same value for
> cycle_count as 2779324877496216 irrespective of where I am starting
> and stopping it and how much ever code I am executing in between them.
> I wonder what I am doing wrong? I am not getting any other value.
> Please help on this! Does it have anything to do with the
> -DDO_CYCLE_COUNTS switch? How can I invoke or enable this switch?
You have different possibilities to set this variable.
1) In the properties for the project (Alt+F7) define it in the preprocessor
definitions (first line of this tab) by just writing DO_CYCLE_COUNTS here.
2) If you need START_... STOP_... only in one file, just place a define like:
#define DO_CYCLE_COUNTS
before ! the include line for the cycle_count.h header

I'd prefer the 2nd approach, because you see at one glance what happens.
>
> Thanks a lot

Just to mention this:
Your approach was correct (if you have set the define).
It would have worked correctly on a SHARC target (I used it like this),
but I don't know if it works on TigerSharc, since implementation is different
there.
Supposed that the implementation is correct for that target, check the
following things:
1) Is there any concurrent use of the CCNT0, CCNT1 registers?
Then you're on your own...
2) Would your code work correctly in a C program and fails in a C++ program?
If so, try using an extern "C" { } bracket and/or wrap the calls in a C
subroutine.
3) There might be an interrupt corrupting the calculations. To check for this:
set a breakpoint before and one after START_CYCLE_COUNT() and STOP_...
When the first breakpoint of each is hit, switch off all interrupts, run to
2nd breakpoint, then enable them again.
Disabling them during the macros will avoid any possible interference.

If all these hints don't help, search for another solution and avoid the
counter. It might cost you too much of your time to save some of the
processor's!

Bernhard
Institut Dr. Foerster GmbH & Co. KG
Sitz Reutlingen, Amtsgericht Stuttgart HRA 350774,
persönlich haftende Gesellschafterin und Geschäftsführung
Institut Dr. Foerster-Verwaltungsgesellschaft mbH,
Sitz Reutlingen, Amtsgericht Stuttgart HRB 350328
Geschäftsführer: Felix Förster, Stefan Flores

--------------------------
This E-mail may contain confidential and/or privileged information.
If you are not the intended recipient or have received this E-mail
in error, please notify the sender immediately and destroy this
E-mail. Any unauthorized copying, disclosure or distribution of the
material in this E-mail is strictly forbidden. E-mails via Internet
can easily be prepared or manipulated by third persons. For this
reason we trust you will understand that, for your own and our
protection, we rule out the legal validity of the foregoing
statements and comments.
Hi Bernhard,

Thanks a lot for your response. It worked. I did try placing #define DO_CYCLE_COUNT yesterday but dint work.
As you just said, I tried placing it before including cycle_count.h also, dint work either.
But using DO_CYCLE_COUNT in the project options (Alt +F7) under compiler, preprocessor directives, its working. I wonder why its not working for the 2nd alternative though. But as you said I don't want to hang on to this for long and I should keep going :) now the problem is solved.

Thanks a lot for your timely help!

Thanks for Mike and others who replied too!

Regards,
Dan

----- Original Message ----
From: Bernhard Holzmayer
To: a...
Sent: Monday, April 23, 2007 11:29:30 PM
Subject: Re: [adsp] reg. measuring cycle counts ADSP TS201

Hi. See answers between quotes...

> Hi,

>

> I am trying to calculate the number of cycle counts in my

> program for a particular section of the code. But I am not getting the

> total cycle count for some reason. I followed the instructions in the

> document VDSP++ 4.5 C/C++ compiler and library manual under section

> "measuring cycle counts". I am trying to use "Basic cycle counting

> facility". The part of the code I have written is as follows.

> I am using cycle_count. h header file.

See also files xcycle_count. h, and cycle_count_ ts.h for details

If you look into these files you'll find out that

1) START..., STOP..., PRINT... are macros which evaluate to NOTHING if the

DO_CYCLE_COUNTS switch is not set, otherwise they lead to a sequence of

assembler commands, which work mainly with the registers CCNT0, CCNT1

>

> cycle_t cycle_count;

perfect.

> ............ .....

> ............

>

> START_CYCLE_ COUNT(cycle_ count);

fine.

> ............ .......

>

> STOP_CYCLE_COUNT( cycle_count, cycle_count) ;

that's it. Here you should see that the contents of cycle_count are correct.

> cout << cycle_count;

Ohhh. This is C++ code.

Be aware that C++ mangles variable names, and that it might blow up variables

by adding additional information. I would suggest that you watch the variable

cycle_count in an expression window, and watch in the disassembler what

START_... and STOP_.. do with this variable.

> //PRINT_CYCLES( "number of cycle counts:",cycle_ count);

This line might fail as cout <<... does, if the above macros wouldn't write

the value correctly.

>

>

> My problem is I am always getting the same value for

> cycle_count as 2779324877496216 irrespective of where I am starting

> and stopping it and how much ever code I am executing in between them.

> I wonder what I am doing wrong? I am not getting any other value.

> Please help on this! Does it have anything to do with the

> -DDO_CYCLE_COUNTS switch? How can I invoke or enable this switch?

You have different possibilities to set this variable.

1) In the properties for the project (Alt+F7) define it in the preprocessor

definitions (first line of this tab) by just writing DO_CYCLE_COUNTS here.

2) If you need START_... STOP_... only in one file, just place a define like:

#define DO_CYCLE_COUNTS

before ! the include line for the cycle_count. h header

I'd prefer the 2nd approach, because you see at one glance what happens.

>

> Thanks a lot

Just to mention this:

Your approach was correct (if you have set the define).

It would have worked correctly on a SHARC target (I used it like this),

but I don't know if it works on TigerSharc, since implementation is different

there.

Supposed that the implementation is correct for that target, check the

following things:

1) Is there any concurrent use of the CCNT0, CCNT1 registers?

Then you're on your own...

2) Would your code work correctly in a C program and fails in a C++ program?

If so, try using an extern "C" { } bracket and/or wrap the calls in a C

subroutine.

3) There might be an interrupt corrupting the calculations. To check for this:

set a breakpoint before and one after START_CYCLE_ COUNT() and STOP_...

When the first breakpoint of each is hit, switch off all interrupts, run to

2nd breakpoint, then enable them again.

Disabling them during the macros will avoid any possible interference.

If all these hints don't help, search for another solution and avoid the

counter. It might cost you too much of your time to save some of the

processor's!

Bernhard

Institut Dr. Foerster GmbH & Co. KG

Sitz Reutlingen, Amtsgericht Stuttgart HRA 350774,

perslich haftende Gesellschafterin und Geschtsfrung

Institut Dr. Foerster-Verwaltung sgesellschaft mbH,

Sitz Reutlingen, Amtsgericht Stuttgart HRB 350328

Geschtsfrer: Felix Fster, Stefan Flores

------------ --------- --------- --------- --------- --------- -

This E-mail may contain confidential and/or privileged information.

If you are not the intended recipient or have received this E-mail

in error, please notify the sender immediately and destroy this

E-mail. Any unauthorized copying, disclosure or distribution of the

material in this E-mail is strictly forbidden. E-mails via Internet

can easily be prepared or manipulated by third persons. For this

reason we trust you will understand that, for your own and our

protection, we rule out the legal validity of the foregoing

statements and comments.



__________________________________________________
Hi
You may try to use following function that I used many times

#include "defts201.h"
#include "sysreg.h"

long long GetCycleCount( )
{
long long ccnt0, ccnt1;
long long cycles;
/* read cycle count register */
ccnt0 = __builtin_sysreg_read(__UNDER__(CCNT0));
ccnt1 = __builtin_sysreg_read(__UNDER__(CCNT1));
/* merge registers */
cycles = (ccnt1<<32) + ccnt0 ;
return cycles;
}

fdd
----- Original Message ----
From: dsp newbie
To: a...
Sent: Tuesday, April 24, 2007 9:39:01 PM
Subject: Re: [adsp] reg. measuring cycle counts ADSP TS201

Hi Bernhard,

Thanks a lot for your response. It worked. I did try placing #define DO_CYCLE_COUNT yesterday but dint work.
As you just said, I tried placing it before including cycle_count. h also, dint work either.
But using DO_CYCLE_COUNT in the project options (Alt +F7) under compiler, preprocessor directives, its working. I wonder why its not working for the 2nd alternative though. But as you said I don't want to hang on to this for long and I should keep going :) now the problem is solved.

Thanks a lot for your timely help!

Thanks for Mike and others who replied too!

Regards,
Dan
----- Original Message ----
From: Bernhard Holzmayer
To: adsp@yahoogroups. com
Sent: Monday, April 23, 2007 11:29:30 PM
Subject: Re: [adsp] reg. measuring cycle counts ADSP TS201
Hi. See answers between quotes...

> Hi,
>
> I am trying to calculate the number of cycle counts in my
> program for a particular section of the code. But I am not getting the
> total cycle count for some reason. I followed the instructions in the
> document VDSP++ 4.5 C/C++ compiler and library manual under section
> "measuring cycle counts". I am trying to use "Basic cycle counting
> facility". The part of the code I have written is as follows.
> I am using cycle_count. h header file.
See also files xcycle_count. h, and cycle_count_ ts.h for details
If you look into these files you'll find out that
1) START..., STOP..., PRINT... are macros which evaluate to NOTHING if the
DO_CYCLE_COUNTS switch is not set, otherwise they lead to a sequence of
assembler commands, which work mainly with the registers CCNT0, CCNT1

>
> cycle_t cycle_count;
perfect.
> ............ .....
> ............
>
> START_CYCLE_ COUNT(cycle_ count);
fine.
> ............ .......
>
> STOP_CYCLE_COUNT( cycle_count, cycle_count) ;
that's it. Here you should see that the contents of cycle_count are correct.
> cout << cycle_count;
Ohhh. This is C++ code.
Be aware that C++ mangles variable names, and that it might blow up variables
by adding additional information. I would suggest that you watch the variable
cycle_count in an expression window, and watch in the disassembler what
START_... and STOP_.. do with this variable.

> //PRINT_CYCLES( "number of cycle counts:",cycle_ count);
This line might fail as cout <<... does, if the above macros wouldn't write
the value correctly.
> My problem is I am always getting the same value for
> cycle_count as 2779324877496216 irrespective of where I am starting
> and stopping it and how much ever code I am executing in between them.
> I wonder what I am doing wrong? I am not getting any other value.
> Please help on this! Does it have anything to do with the
> -DDO_CYCLE_COUNTS switch? How can I invoke or enable this switch?
You have different possibilities to set this variable.
1) In the properties for the project (Alt+F7) define it in the preprocessor
definitions (first line of this tab) by just writing DO_CYCLE_COUNTS here.
2) If you need START_... STOP_... only in one file, just place a define like:
#define DO_CYCLE_COUNTS
before ! the include line for the cycle_count. h header

I'd prefer the 2nd approach, because you see at one glance what happens.
>
> Thanks a lot

Just to mention this:
Your approach was correct (if you have set the define).
It would have worked correctly on a SHARC target (I used it like this),
but I don't know if it works on TigerSharc, since implementation is different
there.
Supposed that the implementation is correct for that target, check the
following things:
1) Is there any concurrent use of the CCNT0, CCNT1 registers?
Then you're on your own...
2) Would your code work correctly in a C program and fails in a C++ program?
If so, try using an extern "C" { } bracket and/or wrap the calls in a C
subroutine.
3) There might be an interrupt corrupting the calculations. To check for this:
set a breakpoint before and one after START_CYCLE_ COUNT() and STOP_...
When the first breakpoint of each is hit, switch off all interrupts, run to
2nd breakpoint, then enable them again.
Disabling them during the macros will avoid any possible interference.

If all these hints don't help, search for another solution and avoid the
counter. It might cost you too much of your time to save some of the
processor's!

Bernhard
Institut Dr. Foerster GmbH & Co. KG
Sitz Reutlingen, Amtsgericht Stuttgart HRA 350774,
perslich haftende Gesellschafterin und Geschtsfrung
Institut Dr. Foerster-Verwaltung sgesellschaft mbH,
Sitz Reutlingen, Amtsgericht Stuttgart HRB 350328
Geschtsfrer: Felix Fster, Stefan Flores

------------ --------- --------- --------- --------- --------- -
This E-mail may contain confidential and/or privileged information.
If you are not the intended recipient or have received this E-mail
in error, please notify the sender immediately and destroy this
E-mail. Any unauthorized copying, disclosure or distribution of the
material in this E-mail is strictly forbidden. E-mails via Internet
can easily be prepared or manipulated by third persons. For this
reason we trust you will understand that, for your own and our
protection, we rule out the legal validity of the foregoing
statements and comments.

Ahhh...imagining that irresistible "new car" smell?
Check out new cars at Yahoo! Autos.