Context-switch overhead

This benchmark measures the overhead (in µs) required to deliver a signal and switch to the high-priority process varying the particular kernel configuration and the target architecture supported by BeRTOS.

Use Case: a low-priority process sends a signal to a high priority process and performs a context switch.

Experimental result

context-switch benchmark results graph
Cooperative Preemptive
NOPRI PRI NOPRI PRI
Cortex-M3 STM32F103 (72MHz) 2.22 2.58 2.34 2.70
ARM7TDMI LPC2378 (72MHz) 3.11 3.72 3.33 3.94
Cortex-M3 SAM3N (48MHz) 3.68 4.17 4.13 4.54
Cortex-M3 LM3S1968 (50MHz) 2.88 3.28 3.22 3.54
ARM7TDMI AT91SAM7X256 (48MHz) 5.33 6.00 5.33 5.33
ARM7TDMI AT91SAM7S256 (48MHz) 5.33 6.00 5.33 5.33
AVR ATmega328P (16MHz) 14.60 17.90 15.10 18.50
AVR ATmega1281 (14MHz) 17.70 21.59 17.70 21.59
  • Cooperative: cooperative scheduler (kernel preemption disabled)
  • Preemptive: kernel preemption enabled
  • PRI: process priorities enabled
  • NOPRI: process priorities disabled
Note: time is expressed in µs.

Several RTOS and real-time solutions have performed the same testcase on a wide range of different architectures. BeRTOS outperforms many alternatives in this testcase; in the worst-case, the context-switch overhead is still 2x faster compared to other solutions on the ARM7TDMI and Cortex-M3 processors.

NOTE: the source code of this testcase is available under the BeRTOS source package, downloadable at the following URL: http://www.bertos.org/download.

The binary was generated using with the following software versions:

  • BeRTOS: version 2.5.0
  • ARM toolchain: arm-none-eabi-gcc (Sourcery G++ Lite 2010q1-188) 4.4.1
  • AVR toolchain: avr-gcc (GCC) 4.3.2

The optimization level was set to -O2.

How to run the benchmark

To build this test by yourself you can launch the BeRTOS wizard and select your development board. Then, under the tab Benchmarks select the BeRTOS Context Switch benchmark.

This will create a full BeRTOS project, that can be compiled running make directly into the project's main directory.

How to measure using an oscilloscope:

The context switching time can be measured looking at the time between switching the LED off and on.

NOTE: the real context switching time is shorter because of the overhead introduced by the measurement.

To get the results simply connect the oscilloscope to the STATUS LED and look at the time between rising and falling edge of the signal. The context switch is repeated every 100ms.

How to measure using the (hardware) high-precision timer:

The benchmark can try to evaluate the context-switch time using the BeRTOS high-precision timer module. Results are printed out to the first available UART port.

How to connect to the boards:

Olimex STM32-P103

Olimex STM32-P103

  • LED: connect the oscilloscope to the "STAT" LED
  • high-precision timer: not available

Olimex LPC-P2378

Olimex LPC-P2378

  • LED: connect the oscilloscope to the "STAT" LED
  • high-precision timer: connect a serial cable to the RS232 port and open it using a terminal emulator (from a PC)

Luminary EK-LM3S1968

Luminary EK-LM3S1968

  • LED: connect the oscilloscope to the "STATUS" LED
  • high-precision timer: connect a serial cable to UART0 (over USB) and open it using a terminal emulator (from a PC)

Atmel AT91SAM7X-EK

Atmel AT91SAM7X-EK

  • LED: connect the oscilloscope to the "DS4" LED
  • high-precision timer: connect a terminal emulator to "RS232 COM PORT"

Atmel AT91SAM7S-EK

Atmel AT91SAM7S-EK

  • LED: connect the oscilloscope to the "DS1" LED
  • high-precision timer: connect a serial cable to the "UART" port and open it using a terminal emulator (from a PC)

Arduino Duemilanove

Arduino Duemilanove

  • LED: connect the oscilloscope to the "L" LED
  • high-precision timer: connect a serial cable to UART0 (over USB) and open it using a terminal emulator (from a PC)

Develer Triface

Develer Triface

  • LED: connect the oscilloscope to the "D2" LED
  • high-precision timer: connect a serial cable to the P1 (HOST) RS232 port and open it using a terminal emulator (from a PC)