Logo RTAI & LTT Choi Sung Chul
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 realtime programmers' lifes easier Working with POSIX compliant or native RTAI realtime tasks Linux application is able to execute without any modification
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)
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; }
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
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
Install RTAI & LTT (1) Need files - TraceToolkit 0.95a - linux kernel - RTAI Compiler - gcc version
Install RTAI & LTT (2) Linux Kenel Patch & Compile Patch from LTT patchs directory - #~/linux>patch -p1 < ~/TraceToolkit-0.9.5a/Patches/patch-ltt-linux rthal5f 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
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/ rthal5trace/rtai/rtai_tracer.o Using /lib/modules/ rthal5-trace/rtai/rtai_tracer.o Symbol version prefix 'smp_' /sbin/insmod /lib/modules/ rthal5-trace/rtai/rtai.o Using /lib/modules/ rthal5-trace/rtai/rtai.o $>lsmod Module Size Used by Tainted: P rtai (unused) rtai_tracer [rtai] binfmt_misc ….
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
LTT & Traceview Screenshot
Example1 for using LTT in a RTAI program Offered ex - /rtai /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
Block diagram for example1
Flow diagram for example1
Traceview of example1
Zoom function of Traceview
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 height reaches max or min value Turbine always rotate one side direction.
Simplify model for wave actived generator
Simple SDL for example2 program
User defined custom event When it can’t be used printk and must be checked variable LTT support user define event int 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 */);
Custom event of example1 Make event traceId = trace_create_event("WaveActivedGen", "%s", CUSTOM_EVENT_FORMAT_TYPE_STR, NULL); trace_std_formatted_event(traceId, "Trace init_module"); Wave height value sprintf(dbgMsg, "height:%d", (int)wave_height); trace_std_formatted_event(traceId, dbgMsg); Recv turn event trace_std_formatted_event(traceId, "Do Pen Turn Right!"); trace_std_formatted_event(traceId, "Do Pen Turn Left!");
Dump event and message Traceview -> menu -> file ->dump file Select dump message or event Example2 custom message dump Trace start time: ( , ) Trace end time: ( , ) Trace duration: (2, ) Number of occurences of: Events: 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
#################################################################### EventTimePIDLengthDescription #################################################################### Event creation 1,097,134,998,633,204 N/A 391 NEW EVENT TYPE : WaveActivedGen; CUSTOM EVENT ID : 24 RT-Timer 1,097,134,998,633,860 N/A 16 TIMER EXPIRY WaveActivedGen 1,097,134,998,633,866 N/A 30 height:183 RT-Task 1,097,134,998,633,866 N/A 28 WAIT PERIOD RT-Timer 1,097,134,998,640, TIMER EXPIRY RT-Task 1,097,134,998,640, WAIT PERIOD WaveActivedGen 1,097,134,998,640, height:185 RT-Task 1,097,134,998,640, WAIT PERIOD RT-Timer 1,097,134,998,647, TIMER EXPIRY WaveActivedGen 1,097,134,998,647, height:187 RT-Task 1,097,134,998,647, WAIT PERIOD RT-Timer 1,097,134,998,653, TIMER EXPIRY RT-Task 1,097,134,998,653, WAIT PERIOD WaveActivedGen 1,097,134,998,653, height:189 RT-Task 1,097,134,998,653, WAIT PERIOD RT-Timer 1,097,134,998,660, TIMER EXPIRY WaveActivedGen 1,097,134,998,660, height:190 RT-Task 1,097,134,998,660, WAIT PERIOD RT-Timer 1,097,134,998,667, TIMER EXPIRY RT-Task 1,097,134,998,667, WAIT PERIOD WaveActivedGen 1,097,134,998,667, height:192 RT-Task 1,097,134,998,667, WAIT PERIOD RT-Timer 1,097,134,998,673, TIMER EXPIRY WaveActivedGen 1,097,134,998,673, height:193 RT-Task 1,097,134,998,673, WAIT PERIOD RT-Timer 1,097,134,998,680, TIMER EXPIRY RT-Task 1,097,134,998,680, WAIT PERIOD WaveActivedGen 1,097,134,998,680, height:194 RT-Task 1,097,134,998,680, WAIT PERIOD RT-Timer 1,097,134,998,687, TIMER EXPIRY WaveActivedGen 1,097,134,998,687, height:195 RT-Task 1,097,134,998,687, WAIT PERIOD RT-Timer 1,097,134,998,694, TIMER EXPIRY RT-Task 1,097,134,998,694, WAIT PERIOD WaveActivedGen 1,097,134,998,694, height:196 RT-Task 1,097,134,998,694, WAIT PERIOD RT-Timer 1,097,134,998,700, TIMER EXPIRY WaveActivedGen 1,097,134,998,700, height:197
WaveActivedGen 1,097,134,998,754, height:199 RT-Task 1,097,134,998,754, WAIT PERIOD RT-Timer 1,097,134,998,760, TIMER EXPIRY RT-Message 1,097,134,998,760, SEND => TASK : 1; MSG : 1d WaveActivedGen 1,097,134,998,760, Do Pen Turn Right! RT-Message 1,097,134,998,760, RECEIVE => TASK : 2 RT-Task 1,097,134,998,760, WAIT PERIOD WaveActivedGen 1,097,134,998,760, height:199 RT-Task 1,097,134,998,760, WAIT PERIOD RT-Timer 1,097,134,998,767, TIMER EXPIRY WaveActivedGen 1,097,134,998,767, height:199 RT-Task 1,097,134,998,767, WAIT PERIOD RT-Timer 1,097,134,998,774, TIMER EXPIRY RT-Task 1,097,134,998,774, WAIT PERIOD WaveActivedGen 1,097,134,998,774, height:198