logo rtai & ltt choi sung chul. what is the rtai ? realtime application interface a patch to...

24
Logo RTAI & LTT RTAI & LTT Choi Sung Chul Choi Sung Chul

Upload: jeffery-singleton

Post on 12-Jan-2016

228 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

Logo

RTAI & LTTRTAI & LTT

Choi Sung ChulChoi Sung Chul

Page 2: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

What is the RTAI ?

Realtime Application Interface A patch to the Linux kernel which introduces a

hardware abstraction layer A broad variety of services which make realtim

e programmers' lifes easier Working with POSIX compliant or native RTAI

realtime tasks Linux application is able to execute without an

y modification

Page 3: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

What kind of functions does RTAI support?

real time scheduler module - Task functions - Timing functions - Semaphore functions - Mailbox functions - Intertask communication functions

Fifo services Shared memory Posix pthread and pqueue(msg queue)    

Page 4: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

How to make a RTAI program It is a similar to make linux kernel module Use several functions for RTAI program Example RTAI program

int init_module(void){ RTIME tick_period; rt_set_periodic_mode(); rt_task_init(&rt_task, fun, 1, STACK_SIZE, TASK_PRIORITY, 1, 0); rtf_create(FIFO, 8000); tick_period = start_rt_timer(nano2count(TICK_PERIOD)); rt_task_make_periodic(&rt_task, rt_get_time() + tick_period, tick_period); return 0;}

void cleanup_module(void){ stop_rt_timer(); rtf_destroy(FIFO); rt_task_delete(&rt_task); return;}

Page 5: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

What is the LTT?

Linux Trace Toolkit Linux kernel tracing capabilities with 48 unique

Trace Points Variable-length events minimizing overall trace size Minimal performance overhead (< 2.5 %). Micro-second event time-stamps graphical user interface with event graph, system

and per-process analysis, and raw event descriptions.

Support for the Real-Time Application Interface

Page 6: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

Why LTT?

It is too hard to debug kernel like Real Time program

It isn’t able to be checked transmitting and receiving message or signal accuracy

We can see the kernel event and message transferring easily to use LTT

LTT can make user defined event(custom event) it needs not use “printk”!!

LTT can dump selected event and message. So, we can save it and analysis anytime

Page 7: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

Install RTAI & LTT (1)

Need files

- TraceToolkit 0.95a http://www.opersys.com/LTT/

- linux kernel 2.4.16

http://www.kernel.org

- RTAI 24.1.11 http://www.aero.polimi.it/RTAI/

Compiler

- gcc version 2.95.3

Page 8: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

Install RTAI & LTT (2)

Linux Kenel Patch & CompilePatch from LTT patchs directory

- #~/linux>patch -p1 < ~/TraceToolkit-0.9.5a/Patches/patch-ltt-linux-2.4.16-rthal5f-020415-1.14

Modify kernel source (2 files) - linux/arch/i386/kernel/irq.c ,linux/include/asm-i386/system.h

Kernel setting & compile - NO : Set version information on all module symbols - YES : Real-Time Hardware Abstraction Layer - Module : Kernel event tracing support - YES : RTAI event tracing support - APM : disable

Make boot image & Reboot - Add boot image to lilo or grub

Page 9: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

Install RTAI & LTT (3)

Install RTAI - #> Configure –menu Menu Setting

Modify sources (2 files) - arch/i386/rtai.c , upscheduler/rtai_sched.c

Make & make install Load modules

$> modprobe -v rtai /sbin/insmod /lib/modules/2.4.16-rthal5trace/rtai/rtai_tracer.o

Using /lib/modules/2.4.16-rthal5-trace/rtai/rtai_tracer.oSymbol version prefix 'smp_'/sbin/insmod /lib/modules/2.4.16-rthal5-trace/rtai/rtai.oUsing /lib/modules/2.4.16-rthal5-trace/rtai/rtai.o$>lsmodModule Size Used by Tainted: P rtai 56320 0 (unused)rtai_tracer 9024 0 [rtai]binfmt_misc 7524 1 ….

Page 10: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

Install RTAI & LTT (3)

Configire –with-rtai & make install Execute createdev.sh (make node /dev/tracer)

- $> ./createdev.sh Deleting old tracer nodes: /dev/tracer and /dev/tracerU

Found tracer device with major number: 253 Creating new tracer nodes: /dev/tracer and /dev/tracerU

Trace time(sec)- this records data(kernel and app trace event) for require time

Traceview- graphic tool for event graph, system and per-process analysis, and raw event descriptions

Page 11: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

LTT & Traceview Screenshot

Page 12: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

Example1 for using LTT in a RTAI program

Offered ex - /rtai-24.1.11/examples/msgsw This example features NTASKS(8) real-time

tasks running periodically On each period a server task is messaged to

set/reset a bit on the parallel port By choosing an appropriate timing one can

produce a rectangular wave which can be watched on an oscilloscope plugged into it

Page 13: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

Block diagram for example1

TaskDriver

TaskFun 1

TaskFun 2

TaskFun 3

TaskFun 4

TaskFun 5

TaskFun 6

TaskFun 7

rt_send

rt_rpc

rt_rpc

rt_rpc

rt_send

rt_send

rt_send

ParallelPort

Control

Page 14: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

Flow diagram for example1Flow diagram for example1Driver Task Fun Task

rt_send Msg(0)

Parallel Port

LED OFF(Port 1 is OFF)

Task 1

Ack of rt_send from RTAI

rt_rpc Msg(1) Task 2

LED ON(Port 1 is ON)rt_return Msg(0)

rt_task_wait_period

rt_task_wait_period

rt_send Msg(0)LED OFF(Port 1 is OFF)

Task 3

Ack of rt_send from RTAI

rt_rpc Msg(1) Task 4

LED ON(Port 1 is ON)rt_return Msg(0)

rt_task_wait_period

rt_task_wait_period

rt_send Msg(0)LED OFF(Port 1 is OFF)

Task 5

Ack of rt_send from RTAI

rt_rpc Msg(1) Task 6

LED ON(Port 1 is ON)rt_return Msg(0)

rt_task_wait_period

rt_task_wait_period

rt_send Msg(0)LED OFF(Port 1 is OFF)

Task 7

Ack of rt_send from RTAI

Page 15: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

Traceview of example1

Page 16: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

Zoom function of Traceview

Page 17: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

Example2 for using LTT in a RTAI program Simple wave actived generator simulation Let’s wave factor = sin(t) A sensor for wave height Its pen of Turbine changes direction when heig

ht reaches max or min value Turbine always rotate one side direction.

Page 18: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

Simplify model for wave actived generator

Always one side direction

Falling time

Rising time

Turn direction

Turn direction

Page 19: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

Simple SDL for example2 program

TaskWave

Time++Height = 1+GetSin(Time)

TaskSensor

Height reaches MAX value?

Height reaches MIN value?

No

rt_send MSG_TURN_RIGHT

rt_send MSG_TURN_LEFT

TaskTurn

rt_receiveMSG_TURN_RIGHT

rt_receiveMSG_TURN_LEFT

DoTurnRight DoTurnLeft

Page 20: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

User defined custom event

When it can’t be used printk and must be checked variable

LTT support user define eventint trace_create_event ( char* /* String describing event type */,

char* /* String to format standard event description */,int /* Type of formatting used to log event data */,char* /* Data specific to format */);

int trace_destroy_event( int /* The event ID given by trace_create_event() */);int trace_user_event(

int /* The event ID given by trace_create_event() */,int /* The size of the raw data */,void* /* Pointer to the raw event data */);

Page 21: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

Custom event of example1

Make eventtraceId = trace_create_event("WaveActivedGen", "%s", CUSTOM_EVENT_FORMAT_TYPE_STR, NULL); trace_std_formatted_event(traceId, "Trace init_module");

Wave height valuesprintf(dbgMsg, "height:%d", (int)wave_height); trace_std_forma

tted_event(traceId, dbgMsg);

Recv turn event trace_std_formatted_event(traceId, "Do Pen Turn Right!");

trace_std_formatted_event(traceId, "Do Pen Turn Left!");

Page 22: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

Dump event and message

Traceview -> menu -> file ->dump file Select dump message or event Example2 custom message dump

Trace start time: (1097134998, 633202) Trace end time: (1097135001, 614397) Trace duration: (2, 981195)

Number of occurences of:Events: 22029 Scheduling changes: 821 Kernel timer tics: 228 System call entries: 3006 System call exits: 3005 Trap entries: 0 Trap exits: 0 IRQ entries: 337 IRQ exits: 337 Bottom halves: 228 Timer expiries: 73 Page allocations: 417 Page frees: 415 Packets Out: 0 Packets In: 112

Page 23: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

####################################################################Event Time PID Length Description####################################################################Event creation 1,097,134,998,633,204 N/A 391 NEW EVENT TYPE : WaveActivedGen; CUSTOM EVENT ID : 24RT-Timer 1,097,134,998,633,860 N/A 16 TIMER EXPIRYWaveActivedGen 1,097,134,998,633,866 N/A 30 height:183RT-Task 1,097,134,998,633,866 N/A 28 WAIT PERIODRT-Timer 1,097,134,998,640,546 1138 16 TIMER EXPIRYRT-Task 1,097,134,998,640,551 1138 28 WAIT PERIODWaveActivedGen 1,097,134,998,640,558 1138 30 height:185RT-Task 1,097,134,998,640,558 1138 28 WAIT PERIODRT-Timer 1,097,134,998,647,236 1138 16 TIMER EXPIRYWaveActivedGen 1,097,134,998,647,241 1138 30 height:187RT-Task 1,097,134,998,647,242 1138 28 WAIT PERIODRT-Timer 1,097,134,998,653,921 1253 16 TIMER EXPIRYRT-Task 1,097,134,998,653,925 1253 28 WAIT PERIODWaveActivedGen 1,097,134,998,653,932 1253 30 height:189RT-Task 1,097,134,998,653,933 1253 28 WAIT PERIODRT-Timer 1,097,134,998,660,610 1138 16 TIMER EXPIRYWaveActivedGen 1,097,134,998,660,620 1138 30 height:190RT-Task 1,097,134,998,660,620 1138 28 WAIT PERIODRT-Timer 1,097,134,998,667,295 0 16 TIMER EXPIRYRT-Task 1,097,134,998,667,297 0 28 WAIT PERIODWaveActivedGen 1,097,134,998,667,300 0 30 height:192RT-Task 1,097,134,998,667,300 0 28 WAIT PERIODRT-Timer 1,097,134,998,673,985 0 16 TIMER EXPIRYWaveActivedGen 1,097,134,998,673,987 0 30 height:193RT-Task 1,097,134,998,673,987 0 28 WAIT PERIODRT-Timer 1,097,134,998,680,670 0 16 TIMER EXPIRYRT-Task 1,097,134,998,680,672 0 28 WAIT PERIODWaveActivedGen 1,097,134,998,680,676 0 30 height:194RT-Task 1,097,134,998,680,676 0 28 WAIT PERIODRT-Timer 1,097,134,998,687,359 0 16 TIMER EXPIRYWaveActivedGen 1,097,134,998,687,361 0 30 height:195RT-Task 1,097,134,998,687,361 0 28 WAIT PERIODRT-Timer 1,097,134,998,694,046 0 16 TIMER EXPIRYRT-Task 1,097,134,998,694,047 0 28 WAIT PERIODWaveActivedGen 1,097,134,998,694,050 0 30 height:196RT-Task 1,097,134,998,694,051 0 28 WAIT PERIODRT-Timer 1,097,134,998,700,736 0 16 TIMER EXPIRYWaveActivedGen 1,097,134,998,700,739 0 30 height:197

Page 24: Logo RTAI & LTT Choi Sung Chul. What is the RTAI ?  Realtime Application Interface  A patch to the Linux kernel which introduces a hardware abstraction

WaveActivedGen 1,097,134,998,754,238 0 30 height:199RT-Task 1,097,134,998,754,239 0 28 WAIT PERIODRT-Timer 1,097,134,998,760,923 0 16 TIMER EXPIRYRT-Message 1,097,134,998,760,924 0 24 SEND => TASK : 1; MSG : 1dWaveActivedGen 1,097,134,998,760,927 0 38 Do Pen Turn Right!RT-Message 1,097,134,998,760,927 0 24 RECEIVE => TASK : 2RT-Task 1,097,134,998,760,928 0 28 WAIT PERIODWaveActivedGen 1,097,134,998,760,931 0 30 height:199RT-Task 1,097,134,998,760,932 0 28 WAIT PERIODRT-Timer 1,097,134,998,767,612 0 16 TIMER EXPIRYWaveActivedGen 1,097,134,998,767,614 0 30 height:199RT-Task 1,097,134,998,767,614 0 28 WAIT PERIODRT-Timer 1,097,134,998,774,299 0 16 TIMER EXPIRYRT-Task 1,097,134,998,774,300 0 28 WAIT PERIODWaveActivedGen 1,097,134,998,774,303 0 30 height:198