Hello,

I would like to measure the number of processor cycles a piece of code
needs to be executed. I have found an example code on the web, which I
used in a module to measure the processor cycles within it. 

          rtl_no_interrupts(irqstate);
          cyccounter_start(t);
          i = 0;
 loop:
          if(i >= n){
            goto loopEnd;
          }
          i++;
/* pointer stuff start */
          p1 = test1;
          p2 = test2;
          *(p1++) = test2[5];
          test1[1] = *(p2);
          test2[54] = test1[0];
/* pointer stuff stop */
          goto loop;
 loopEnd:
          cyccounter_stop(t);
          rtl_restore_interrupts(irqstate);
          data = cyccounter_cycles(t);

The number of used cycles is sent via a fifo to the user space and
printed there. (see attachment)

Now I expected (probably naively) that the code should use the same
number of cycles each time. But it is not. When removing the pointer
stuff, the number toggles between two or three different values, whereas
with it, the number changes within a range of about +/- 10%.

Is this behaviour normal? Why? Cache misses? If I stress the system with
a ping -f, the number goes up. Is there really an upper limit for the
number of used cycles? Otherwise it wouldn't be realtime (guaranteed
response time).

By the way: The purpose for this code was to compare the Pentium
architecture to other ones where the number of cycles can be obtained by
debuggers. Does anybody know, how Pentium (II/III), Athlon, ... compares
to PowerPC, StrongARM and others with respect to bit manipulations
(shift, or, and, xor, ...). (In PowerPCs, how to obtain the number of
cycles? Is there any register like in Pentiums?)

I added the rtl_no_interrupts(), rtl_restore_interrupts() functions, but
it didn't change the behaviour. I shouldn't anyway, because I thought
during realtime processes, the linux interrupts are disabled. And there
are no RTLinux interrupts.

Last question for today: Is there a function in RTLinux/RTAI comparable
to the above cyccounter_start/stop?

Thanks for your help
Joachim

-- 
Joachim Herb
mailto:[EMAIL PROTECTED]

<<< gzip;name="testmod.tar.gz": Unrecognized >>>

Reply via email to