Development of Real-Time Systems with …...2016/12/14  · – CONFIG_PREEMPT_VOLUNTARY: Voluntary...

31
Development of Real - Time Systems with Embedded Linux Brandon Shibley Senior Solutions Architect Toradex Inc.

Transcript of Development of Real-Time Systems with …...2016/12/14  · – CONFIG_PREEMPT_VOLUNTARY: Voluntary...

Development of Real-Time Systems

with Embedded Linux

Brandon ShibleySenior Solutions Architect

Toradex Inc.

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH 2

Overview Toradex

• ARM-based System-on-Modules

• Pin-Compatible SoM Families

• In-house HW and SW Development

• 10+ Year Product Life Cycle

• Free Engineering Support

• Direct Sales

• Global Reach with Local Offices

Introduction to Real-Time

Overview of Solutions

Real-Time Linux

Xenomai

Heterogenous Multicore

Conclusion

Q & A

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH

• Firmness of Real-Time Requirements

– Hard: Missed deadline results in system failure

– Soft: Missed deadline reduces system effectiveness

• Examples

– Periodic

• Deadline is periodic

• Often streaming/buffer related, must avoid buffer overflow/underflow

– Event Driven

• Event triggered, may have event-specific deadline

• Often spontaneous

– Control

• Both measurement & response deadlines

• Often periodic with feedback or other input

Real-Time Requirements

4

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH

The Problem / Opportunity

5

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH

• Latency – The system’s response time from the moment of stimulus

• Jitter – The variability of timing & latency

• Interrupt – An event trigger which can interrupt the system

• Context Switch – The switching of processor control from one thread/process to

another

• Preemption – The act of context switching a thread/process off of the processor to

allow processing a higher priority task

Real-time Terms & Concepts

6

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH

• Determinism

– Predictable Scheduler

– Bounded latencies

– Minimal jitter

• Prioritization

– Priority-base scheduling of tasks &

interrupt requests

• Preemption

– Preempt tasks for higher priority tasks

– Priority inheritance

Real-Time Operating System Concerns

7

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH

• Priority Inversion

Real-Time Operating System Concerns

8

Source: http://www.toulibre.org/pub/2010-11-20-ubuntuparty/slides/petazzoni-linux-temps-reel.pdf

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH 9

Real-Time Evaluation Test

400 µS

Jitter

• Periodic Real-Time Task

– Toggle memory mapped GPIO every 200µs

• Stress processor, bus & interrupt controller

• Measure time between rising/falling edges

– Metrics: Jitter/Latency

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH 10

Colibri iMX7S Colibri iMX7D

A7@800MHz

A7@1GHz

[email protected]

M4@200MHz

RAM: 256MB RAM: 512MB

FLASH: 512MB FLASH: 512MB

Colibri iMX6S Colibri iMX6DL

[email protected]

A7@1GHz

[email protected]

RAM: 256MB RAM: 512MB

eMMC: 4GB eMMC: 4GB

GPU Vivante GC880

GPU Vivante GC880

US 80 @ 1US 67 @ 1k

US 75 @ 1US 59 @ 1k

US 60 @ 1US 49 @ 1k

US 65 @ 1US 54 @ 1k

Colibri VF50 Colibri VF61 IT

A5@400MHz

M4@167MHz

A5@500MHz

RAM: 128MB RAM: 256MB

FLASH: 128MB FLASH: 512MB

US 42 @ 1US 33 @ 1k

US 62 @ 1US 47 @ 1k

M4@200MHz

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH

• Priority-based scheduling with preemption

• Recent kernels support threadable IRQs & IRQ priority setting

• Standard Preemption Levels:

– CONFIG_PREEMPT_NONE: No Forced Preemption (Server)

– CONFIG_PREEMPT_VOLUNTARY: Voluntary Kernel Preemption (Desktop) [DEFAULT]

– CONFIG_PREEMPT: Preemptible Kernel (Low-Latency Desktop)

• Test Configuration

– 3.14.52 kernel on Colibri iMX6

– colibri_imx6_defconfig

• CONFIG_PREEMPT_VOLUNTARY=y

Standard Linux Kernel

Standard Linux

11

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH 12

92% of samples 2% of samples6% of samples

Wo

rst

Cas

e: 1

5.1

81

Wo

rst

Cas

e: -

0.3

77

Qu

anti

ty o

f sa

mp

les

Standard Linux

Samples Histogram

Error (ms)2µs bin size

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH

• Real-Time Linux Kernel

– Make the Linux kernel more Real-Time

– More Preemptable

– PREEMPT_RT

• Real-Time Co-Kernel

– Assign real-time tasks to higher priority co-kernel

– Xenomai

• Real-Time Co-Processor

– Assign real-time tasks to dedicated processor core

– NXP i.MX7 - Heterogenous Multicore Processing

Real-Time Linux Solutions

13

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH

• PREEMPT_RT patch

• Minimizes the amount of kernel code that is non-preemptable

– Sleeping spinlocks

– rt_mutex

– Threaded interrupt handler

• PREEMPT_RT_FULL: Fully Preemptible Kernel (RT)

• Real-time Linux Project at The Linux Foundation:https://wiki.linuxfoundation.org/realtime/start

• PREEMPT_RT patch source:https://www.kernel.org/pub/linux/kernel/projects/rt/

Real-Time Linux Kernel

PREEMPT_RT Linux

14

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH

• Toradex Real-Time iMX6 kernel recipe:

http://git.toradex.com/cgit/meta-toradex-nxp.git/tree/recipes-kernel/linux/linux-

toradex-rt_3.14.52.bb

Real-Time Linux Kernel

PREEMPT_RT Linux

15

• Real-Time Linux article at Toradex Developer site:

http://developer.toradex.com/knowledge-base/real-

time-linux

• Codesys – Software PLC

http://developer.toradex.com/knowledge-

base/codesys-software-plc-solution

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH

Real-Time Linux Kernel Cyclictest

PREEMPT_RT Linux

16

# cyclictest -n -p 80 -t -D30m

policy: fifo: loadavg: 4.31 4.29 3.71 5/114 6286

T: 0 ( 1845) P:80 I:1000 C:1799993 Min: 10 Act: 19 Avg: 44 Max: 23350

T: 1 ( 1846) P:80 I:1500 C:1199995 Min: 10 Act: 35 Avg: 37 Max: 13460

T: 2 ( 1847) P:80 I:2000 C: 899996 Min: 10 Act: 35 Avg: 41 Max: 13631

T: 3 ( 1848) P:80 I:2500 C: 719997 Min: 11 Act: 38 Avg: 46 Max: 10856

# cyclictest -n -p 80 -t -D30m

policy: fifo: loadavg: 4.98 5.07 4.37 5/115 11803

T: 0 ( 2133) P:80 I:1000 C:1799998 Min: 11 Act: 29 Avg: 35 Max: 821

T: 1 ( 2134) P:80 I:1500 C:1199997 Min: 11 Act: 35 Avg: 40 Max: 597

T: 2 ( 2135) P:80 I:2000 C: 899998 Min: 12 Act: 37 Avg: 44 Max: 886

T: 3 ( 2136) P:80 I:2500 C: 719998 Min: 12 Act: 60 Avg: 42 Max: 721

# cyclictest -n -p 80 -t -D30m

policy: fifo: loadavg: 4.62 4.52 3.98 4/163 27123

T: 0 (12907) P:80 I:1000 C:1799985 Min: 10 Act: 24 Avg: 26 Max: 166

T: 1 (12908) P:80 I:1500 C:1199994 Min: 9 Act: 27 Avg: 27 Max: 187

T: 2 (12909) P:80 I:2000 C: 899996 Min: 11 Act: 21 Avg: 25 Max: 135

T: 3 (12910) P:80 I:2500 C: 719996 Min: 10 Act: 30 Avg: 28 Max: 129

• Tests for Apalis iMX6 with 3.14.28 kernel

• CONFIG_PREEMPT_VOLUNTARY

• CONFIG_PREEMPT

• CONFIG_PREEMPT_RT_FULL

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH

PREEMPT_RT Linux

99.998% of samples 0.002% of samples

Wo

rst

Cas

e: 0

.10

6

Wo

rst

Cas

e: 0

.04

0

Samples Histogram

Qu

anti

ty o

f sa

mp

les

Error (ms)2µs bin size

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH

• Supplements Linux with a real-time co-kernel (Cobalt)

– Built into Linux kernel

• Linux runs as a low priority task within

• Linux Userspace real-time API

• Also a native Linux implementation of real-time framework (Mercury)

– May utilize PREEMPT_RT

• Toradex doesn’t currently provide a Xenomai build for download

Xenomai

Xenomai

19

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH 20

Xenomai

Xenomai

Source: http://elinux.org/images/7/76/Kiszka.pdf. © Siemens AG 2015, et al. Creative Commons BY-SA 3.0 license

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH 21

http://xenomai.org/start-here/

http://xenomai.org/api-reference/

Xenomai

Xenomai API

22

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH

Xenomai

100% of samples

Wo

rst

Cas

e: 0

.01

65

Wo

rst

Cas

e: 0

.01

75

Qu

anti

ty o

f sa

mp

les

Samples Histogram

Error (ms)2µs bin size

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH

• i.MX 7 implements a Heterogeneous Asymmetric Multi-

Processing Architecture

– Two independent CPU cores on a single chip:

• 2x ARM Cortex-A7 @ 1GHz

• 1x ARM Cortex-M4 @ 200MHz

– Shared Bus Topology

• Linux on Cortex-A7

• FreeRTOS on Cortex-M4

NXP i.MX7 - Heterogenous Multicore Processing

i.MX7 HMP

24

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH 25

NXP i.MX7 HMP Architecture

i.MX7 HMP

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH

• Linux Kernel

– Linux 4.1.15

– Rpmsg VirtIO-based TTY driver

• FreeRTOS

– FreeRTOS v8.0.0 kernel

– Various build systems supported (DS-5, CMake + gcc, IAR)

– Modified version of OpenAMP

– Drivers: ADC, GPIO, I2C, UART, WDOG, ECSPI, FlexCAN

• Some Mainline Support (starting with 4.4)

• Toradex Developer Website article:

http://developer.toradex.com/knowledge-base/freertos-on-the-cortex-m4-of-a-colibri-imx7

26

NXP i.MX7 Software

i.MX7 HMP

27

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH

i.MX7 HMP

12/15/2016 28

100% of samples

Wo

rst

Cas

e: 0

.00

05

Samples Histogram100% of samples (< 0.25% of period)

Error (ms)2µs bin size

Qu

anti

ty o

f sa

mp

les

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH

TAQ – Balancing Robot

i.MX7 HMP

29

|www.toradex.com Toradex® is a registered trademark of Montadex GmbH

• Multiple Linux-based solutions with a range of real-time capability

– Standard Linux

– Real-Time Linux

– Xenomai

– Heterogenous Multicore

• All solutions have optimization potential

• All solutions require careful design beyond the OS selection

– Requirements, Hardware, Drivers, Application

30

Conclusion