Pigeon RB100-CM3 real-time tests

This page aims to present the real-time tests of Pigeon RB100-CM3.

Global setup

During the test, we used the Pigeon RB100-CM3 with the latest available Raspbian Lite (2017-04-10) installed and a kernel with PREEMPT_RT patches (kernel version 4.4.50-rt63-v7+).

Real-time tests are meaningful only under heavy stress to guarantee the identification of worst-case latencies. The following tools were used to stress the system:

  • stress --cpu 4,
  • ping -f IP_ADDRESS.

Latency from external signal

This test reproduces a common use case. The first GPIO works as input (GPIO1) and the second GPIO is output (GPIO0). Output state changes according to input. The wiring diagram is shown below.

rt-test-schematic

The oscilloscope was set to trigger a rising edge on CH1. During all measurements, the oscilloscope had the 'Persist' option set to 'Infinity' to find worst-case latencies. In all the following oscilloscope snapshots, the input GPIO signal is yellow and the output GPIO signal is blue.

User space pool GPIO

In user space to make the test we use simple pool GPIO example software with processor direct register access [1]. The main loop looks like below

while (1)
{
if (GET_GPIO(GPIO_NR_IN))
GPIO_SET = 1;
else
GPIO_CLR = 1;
}

First, we made the measurement for non real-time policy [2] and no load. On the following oscilloscope snapshot, we can see what we get after 20 minutes: policy = SCHED_OTHER, priority = 0, no stress, time base = 100 us.

NewFile8

It doesn't look bad – the maximum latency is about 50us. Let's see what happens when we add stress. On the following oscilloscope snapshot, we can see what we get after 5 minutes: policy = SCHED_OTHER, priority = 0, stress on, time base = 100 us.

NewFile9

Now it looks hopeless. Maximum latency is greater than 500us.

Next, we made the measurement for real-time policy and stress. On the following oscilloscope snapshot, we can see what we get after 3 hours: policy = SCHED_FIFO, priority = 99, stress on, time base = 100 us.

NewFile10

In this case, maximum latency is below 50us - very good result.

User space interrupt

For user-space interrupt measurement, we use the WiringPi library [3] :

wiringPiISR(GPIO_NR_IN, INT_EDGE_BOTH, &gpio_int)

The gpio_int function looks like this:

void gpio_int(void)
{
if (digitalRead(GPIO_NR_IN))
digitalWrite(GPIO_NR_OUT, 1);
else
digitalWrite(GPIO_NR_OUT, 0);
}

In the following oscilloscope snapshot, we can see what we get after 2 hours: policy = SCHED_RR, priority = 55, stress on, time base = 100 us. Note. WiringPi library sets thread (interrupt handler) policy to SCHED_RR and priority to 55 (see InterruptHandler function in the file wiringPi.c).

NewFile12

As you can see from the above oscilloscope snapshot, the maximum latency in this case is about 240us.

Kernel space interrupt GPIO

For the kernel-space test, we use a kernel module written by Marcin Bis [4] with little modification of pins definitions. This module uses GPIO interrupt. On the following oscilloscope snapshot, we can see what we get after 5 hours: policy = SCHED_FIFO (default for interrupt), priority = 50 (default for interrupt), stress on, time base = 100 us.

NewFile11

In this case, the maximum latency is about 110us. It is possible to increase the priority of the interrupt (chrt command), but we did not notice a significant reduction in maximum latency in this case.

Timer latency

This test measures latency using cyclictest [5], a high-resolution test program. It is part of the test suite rt-tests [6]. To create a latency plot from cyclictest histogram data, we used the mklatencyplot.bash script [7]. In the following chart, we can see what we get after five hours:

plot

Links

[1] http://elinux.org/RPi_GPIO_Code_Samples#Direct_register_access

[2] https://wiki.linuxfoundation.org/realtime/documentation/technical_basics/sched_policy_prio

[3] http://wiringpi.com/reference/priority-interrupts-and-threads/

[4] https://github.com/marcinbis/mb-rt-data/blob/master/rt-tests/01_inout.c

[5] https://rt.wiki.kernel.org/index.php/Cyclictest

[6] https://wiki.linuxfoundation.org/realtime/documentation/howto/tools/rt-tests

[7] https://www.osadl.org/Create-a-latency-plot-from-cyclictest-hi.bash-script-for-latency-plot.0.html