THPP21

Raspberry Pi を用いたEPICS制御システムのリアルタイ
ム性能試験
Real Time Capability Test on The Raspberry Pi based
EPICS Controller
ワンデイ王 迪（総研大 加速器科学），古川 和朗，佐々木 信哉，佐藤 政則，帯名 崇，榎本 嘉範（高エネルギー加速器研究機構）

要旨

Raspberry Pi is a series of small single-board computers designed and published by theRaspberry Pi Foundation. It is also a low cost and popular solution in building the EPICS
Input/output Controller (IOC) owing to its high flexibility, expansion capability and affordability.
EPICS is also adopted in the electron-positron collider, SuperKEKB accelerator. However, therequirement of the real time capability of the control system is critical since the specificdemand of the injection system. The injector linac needs to switch lots of hardware parameters
every 20 millisecond to perform the injection into several different storage rings. To assess thepossibility and stability of Raspberry Pi based EPICS IOC within the 50 Hz beam repetition rate,
we perform a latency test on the Raspberry Pi and compare the standard kernel and real time
kernel.
PASJ2020 THPP21, D. Wang – 1/7

Control System Overview
GUI, CLI(Python, LabVIEW, Tcl/TK, …)ServerApplication Layer

ArchiverEPICS IOC

Controlnetwork

Middle Layer
oscilloscope

PCI/PXIEPICS IOCEPICS IOCPLCVME

PLC

EPICS IOCEPICS IOC

ADC, DAC, SPI, …

Device Layer

PSRFVacuum
pump

Monitor
KlystronPS

Local Controller Layer

PulsedmagnetPASJ2020 THPP21, D. Wang – 2/7

EPICS IOC???

What is Raspberry Pi••••

Low cost
Small
Highly customizable
Tested at several accelerators:• Banana Pi used at TPS, Taiwan1• Raspberry Pi used at SPES, Italy2•••

Raspberry Pi 4 Model B (June, 2019)
CPUBroadcom BCM2711
quad-core Cortex-A72
64-bit SoC @ 1.5GHz

Memory2GB, 4GB or 8GB LPDDR4Network

IEEE 802.11b/g/n/ac wirelessBluetooth 5.0
Gigabit Ethernet

1 LINAC and 4(+1) Ring (HER,LER (+DR), PF, PF-AR)
I/O
50 Hz Pulse-to-Pulse
OS
Modulation (PPM)
Different injection modePowerwith different control
parameters

Detail is described at The fault analysis of timing system in SuperKEKB (WEPP24)

USB, 40-pin GPIO header
Debian, Raspberry Pi OS
5V DC via USB-C connector

Damping Ring (DR)Reference
1, DESIGN AND IMPLEMENTATION OF EMBEDDED APPLICATIONS WITH EPICS SUPPORT FOR ACCELERATOR CONTROLS, IPAC2016, Busan, Korea
2, NEW CONTROL SYSTEM FOR THE SPES OFF-LINE LABORATORY AT LNL-INFN USING EPICS IOCS BASED ON THE RASPBERRY PI, f ICALEPCS2013, San Francisco, CA, USA

PASJ2020 THPP21, D. Wang – 3/7

Real Time Test of RPi with two kernels
••••

•
•

Use `cyclictest` tool in RT-tests toolbox
Open source
Easy to use
Several conditions will be tested:•CPU frequency•CPU stress method•Thread sleep time•
Std kernel and RT kernel
Mostly use `hackbench` to stress the CPU, `cat• Standard kernel supports CPU frequency:/dev/zero > /dev/null ` and `pi_stress (baed on
600MHz, 750MHz, 1000MHz, 1500MHz
Priority Inversion)` also used for comparison• RT kernel supports 600MHz and 1500MHz
Compile the real time kernel from:https://github.com/raspberrypi/linux/tree/rpi4.19.y-rt
The CPU stress method comparison based on Std kernel

No stress

Use `cat /dev/zero > /dev/null`to stress single CPUhackbench
Note that the vertical axis scale changes

PASJ2020 THPP21, D. Wang – 4/7Pi_stressReal Time Test of RPi with two kernelsThe CPU stress method comparison based on RT kernel

Use `cat /dev/zero > /dev/null`to stress single CPUNo stress

Program running time comparisonhackbench•••••Hackbench stress on Stdkernel, runs for 10 minutes

Pi_stress

The average latency remains the same between
Std and RT kernel
The maximal latency of RT kernel is half of theStd kernelStress all CPUs will obviously increase thelatency while stressing one CPU will only
increase one core’s latency
Priority Inversion stress is a little bit difficult for
RPi to handle
The program running time does not affect thelatency both on Std and RT kernel

Hackbench stress on Stdkernel, runs for 50 minutes

PASJ2020 THPP21, D. Wang – 5/7

Real Time Test of RPi with two kernels
CPU frequency comparison of RT kernel••••
CPU: 600 MHz

With the increase of CPU frequency,
the latency decreases
Even on the lowest CPU frequency ofRT kernel, the maximal latency ( 90us) is still smaller than the highperformance CPU of the standard
kernel (110 us)
The best latency is 8 us for averagelatency and 50 us for maximal
latency on RT kernel
CPU temperature is acceptable with
1.5 GHz on RT kernel without cooling( ~65 ℃ )CPU: 1500 MHz

CPU frequency comparison of Std kernel

CPU: 600 MHz

CPU: 750 MHz

CPU: 1000 MHz

PASJ2020 THPP21, D. Wang – 6/7

CPU: 1500 MHz

Real Time Test of RPi IOC with two kernels
•••
••
•
•

25 Hz square wave (half of theSuperKEKB beam repetition rate)
Use hackbench to stress the CPU
EPICS version: 3.14.12.8
Set IOC priority as 90 (by `chrt`
Conclusion: Unlike the `cyclictest` result,command)
there is no much difference between IOC on
CPU frequency is 1.5 GHz
Std kernel and RT kernel. Owing to theTwo PVs only in the IOC
Device driver uses Linux `epoll` interrupt handling and context switch
strategy, EPICS IOC on RT kernel takes lightly
mechanism
longer time while the stability is better.

Std Kernel on 1.5 GHz CPU with hackbench PASJ2020 THPP21, D. Wang – 7/7

RT Kernel on 1.5 GHz CPU with hackbench