KRNL - An Arduino Kernel - performance

KRNL is written for educational as well as operational purposes.

Many things may be optimized but will make it less easy for people to learn about internals in a realtime kernel

  • Double chain lists may not be the most efficient but gives people easy access to understand KeRNeL.

  • Timed semaphores has some overhead in the Timer2 ISR

  • and you can find other things :-)

Still it works and is more than fast enough to most purposes.

If any body tunes performance please mail me your code so we all can share it (jdnATes.aau.dk)

A test

Two task loops:

  • A low prio task signals a semaphore X

  • A high prio task is waiting on semaphore X

So for every loop there is 2 task shift.

  • LED 13 is toggled for every 100 loop so a full square wave equals 400 task shift.(See picture below)

  • A full square wave is approx 9.6 msec so one task shift takes approx 24 usec

  • which ALSO means that interrupt is disables in intervals of 24 usec !!!

  • An Arduino clocks at 16MHz and most instructions is single cycle.

  • 1 instruction is approx 0.0625 usec

  • 1 task shift takes 21 usec equals approx 336 instructions

  • The task shift saves and restore 32 registers so the raw push and pop takes 34+35 = 69 instructions

  • plus a call and return - so in total 69 +2 = 71 instructions

  • or 4.4 usec

  • or 22% of the process of doing a wait call on a semaphore

First pictures shows the setup where the scope register a square wave generated by the Arduino. It togles output for every 100 pairs of signal wait.

On the bottom picture you see the scope picture.

You can see it takes approx 4.4 msec for 100 pairs of signal and wait each with a task shift.

So 4.4 msec divided by 200 gives approc 22 micro sec pr task shift

16 MHz architecture is a clock cycle time around 63 nano sec/cycle. So 22 micro sec equals 350 clock cycles. PUSH and POP is two cycle instructions so 31 registers or so takes in total 4*31 cycles = 124 cycles (or 1/3 of the 22 micro seconds) Now 226 cycles is left for the kernel stuff.

picture of of my table (toggle every 200 task shift) 
picture of square wave (toggle every 200 task shift)