Author: Michael Haberler

I did a few measurements with the Rpi, see below.

Errata notice Nov 21 2012

I have learned since I wrote this that the stock Raspbian kernel I used (Linux raspberrypi 3.2.27+ #102 PREEMPT Sat Sep 1 01:00:50 BST 2012 armv6l GNU/Linux) was not, in fact having the RT_PREEMPT patches applied, so it is a fairly vanilla kernel without provisions for improved realtime behaviour.

I would be interested about pointers to a Raspberry kernel with RT_PREEMPT patches applied.

Also, the reasons for the periodic increase in delay in 125uS intervals are clearer (originally this was under RT-Preempt Kernel - user process, C, now Raspbian kernel - user process, C).

Raspbian Kernel - Python GPIO

First try was to get gpio pin wiggling to work with the http://code.google.com/p/raspberry-gpio-python/ module, just to see what kind of timings one could expect for a Python user HAL component. Not very interesting except establish a baseline.

Kernel was Linux raspberrypi 3.2.27+ #102 PREEMPT Sat Sep 1 01:00:50 BST 2012 armv6l GNU/Linux.

Code

Results from logic analyzer:

gpio-py-lport.png

Raspbian Kernel - user process, C

I tried to find out how fast can we wiggle a GPIO from C. The answer - about every 250nS, if you busy-loop. So that’s the baseline for the IO path delay.

Code

Results from logic analyzer

gpio-c-lport.png

The clock_nanosleep() routine doesnt work below say 50uS, so the delays were done with a busy wait.

Periodic increases in latency

Note that every 125uS the scheduler intervenes and the signal stops for about 4.5uS, after which the CPU is returned to the test program.

The following thread sheds some light on the likely cause: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=7866

which is the dwc_otg driver (USB+Ethernet I/O) requiring this interrupt frequency. I understand that the interrupt service routine since has been recoded to use less resources (http://forum.stmlabs.com/showthread.php?tid=2441) so it might be worthwhile to re-run these tests.

Xenomai Kernel - user process, C

Kernel self-built, based on 3.2.21 and Xenomai 2.6. The source and config for this kernel can be found here: http://git.mah.priv.at/gitweb/linuxcnc-kernel.git/shortlog/refs/heads/rpi-3.2.21-xenomai-mah .

kernel: Linux raspberrypi 3.2.21-ipipe-mah1+ #1 PREEMPT Mon Sep 10 18:18:45 UTC 2012 armv6l GNU/Linux

Results from logic analyzer

Run on an otherwise idle CPU, interval 20uS:

xenomai-c-20us-idle.png

Run on an otherwise idle CPU, interval 30uS:

xenomai-c-30us-idle.png

adding load

I started to compiles, make libzmq and make in the xenomai-2.6 directory in parallel, then xgpio with 20uS timer as above, 3 independent runs (note: my LA only supports 2K samples):

xenomai-c-20us-busy-1.png
xenomai-c-20us-busy-2.png
xenomai-c-20us-busy-3.png

Note the logarithmic scale on the Y axis.