[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Problems with avrtest simulatorand avr-gcc testsuite.

From: Paulo Marques
Subject: Re: [avr-gcc-list] Problems with avrtest simulatorand avr-gcc testsuite.
Date: Tue, 19 Apr 2011 14:52:59 +0100
User-agent: Thunderbird (X11/20090817)

Weddington, Eric wrote:
>> -----Original Message-----
>> From: address@hidden
>> [mailto:address@hidden On
>> Behalf Of Paulo Marques
>> Sent: Tuesday, April 19, 2011 5:19 AM
>> To: Georg-Johann Lay
>> Cc: address@hidden
>> Subject: Re: [avr-gcc-list] Problems with avrtest simulatorand avr-gcc
>> testsuite.
>> BTW, I was just looking at the repository and it seems that my last
>> change to implement cycle counters (very useful for benchmarking) that I
>> thought I committed is not there. Did I forgot to commit or did the
>> repository went back in time at some point?
> I think that you just forgot to commit. I've never regressed the repository, 
> and I don't think anyone else has touched it.

Weird... :(

Anyway I've attached the patch that implements "performance counters".
I'm having some trouble committing it to sourceforge, so if you can do
it, please go ahead. Otherwise I'll just try again later.

The patch allows one to write code like:

int main(void)




        return 0;

and avrtest will output the time for all the individual functions (using
timer 0) and the total time (timer 1).

There is some overhead in calling the timing functions, so if you need
the _exact_ clock cycles you might want to run an empty count first and
use its value to subtract to the actual count.

"Timer 0" has usually less overhead (usually only one cycle) because the
function call usually translates to "out <control_port>, zero_reg". For
other timers, the compiler will need to load a register with the timer
value and then do the OUT instruction which results in an extra cycle
(and an extra register usage).

Anyway, this has been useful to me when optimizing fast-path code or
lengthy calculations, so I hope you find it useful too.

Paulo Marques
Software Development Department - Grupo PIE, S.A.
Phone: +351 252 290600, Fax: +351 252 290601
Web: www.grupopie.com

"'thinking outside the box' works better if I know what's inside the box."
? patch
Index: avrtest.c
RCS file: /cvsroot/winavr/avrtest/avrtest.c,v
retrieving revision 1.8
diff -u -r1.8 avrtest.c
--- avrtest.c   22 Jul 2008 13:19:22 -0000      1.8
+++ avrtest.c   19 Apr 2011 13:37:27 -0000
@@ -50,6 +50,9 @@
 #define EXIT_PORT      0x4F
 #define ABORT_PORT     0x49
+#define START_PORT     0x53
+#define STOP_PORT      0x54
 #define REGX   26
 #define REGY   28
 #define REGZ   30
@@ -224,6 +227,8 @@
 // cycle counter
 static dword program_cycles;
+static dword counters[256];
 // cpu_data is used to store registers, ioport values and actual SRAM
 static byte cpu_data[MAX_RAM_SIZE];
 static int cpu_PC;
@@ -354,6 +359,13 @@
                case ABORT_PORT:
                        leave(EXIT_STATUS_ABORTED, "abort function called");
+               case START_PORT:
+                       counters[value] = program_cycles;
+                       break;
+               case STOP_PORT:
+                       printf("counter %d: %d cycles\n", value, program_cycles 
- counters[value]);
+                       break;
        // default action, just store the value
Index: dejagnuboards/exit.c
RCS file: /cvsroot/winavr/avrtest/dejagnuboards/exit.c,v
retrieving revision 1.2
diff -u -r1.2 exit.c
--- dejagnuboards/exit.c        23 Jun 2008 03:05:13 -0000      1.2
+++ dejagnuboards/exit.c        19 Apr 2011 13:37:27 -0000
@@ -36,6 +36,9 @@
 #define EXIT_PORT      0x4F
 #define ABORT_PORT     0x49
+#define START_PORT     0x53
+#define STOP_PORT      0x54
 int putchar_exit_c(char c, FILE *stream) 
 int putchar_exit_c(char c, FILE *stream)
@@ -59,6 +62,18 @@
        stderr = stdout = &file_exit_c;
+/* avrtest counter wrappers */
+static void start_perf_counter(int number)
+        *((volatile unsigned char *) START_PORT) = number;
+static void stop_perf_counter(int number)
+        *((volatile unsigned char *) STOP_PORT) = number;
 /* This file simply defines never returning functions exit() and abort() */ 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]