Presentation is loading. Please wait.

Presentation is loading. Please wait.

Renesas Electronics America Inc. © 2012 Renesas Electronics America Inc. All rights reserved. Class ID: Using ThreadX ® and IAR Embedded Workbench on the.

Similar presentations


Presentation on theme: "Renesas Electronics America Inc. © 2012 Renesas Electronics America Inc. All rights reserved. Class ID: Using ThreadX ® and IAR Embedded Workbench on the."— Presentation transcript:

1 Renesas Electronics America Inc. © 2012 Renesas Electronics America Inc. All rights reserved. Class ID: Using ThreadX ® and IAR Embedded Workbench on the Renesas RX Processor John Carbone, VP Marketing, Express Logic, Inc. Sean Prestridge, Field Applications Engineer, IAR 9C08I

2 © 2012 Renesas Electronics America Inc. All rights reserved.2 Part I - Key Concepts ThreadX RTOS – Threads and Priorities – Context Switching – Types of Scheduling – Multithreading – Preemptive Scheduling – Preemption-Threshold™ Scheduling IAR Embedded Workbench IDE – Compiler – Debugger – RTOS Awareness – Macros – External Tools Agenda

3 © 2012 Renesas Electronics America Inc. All rights reserved.3 Part II – An Example Structure of the Example – 4 Threads – Message-Passing Setting Priorities – Equal Round-Robin Scheduling – Unique Preemptive Scheduling Preemption-Threshold Scheduling Assessing The Results Using TraceX Summary and Conclusion Q/A For More Information Agenda (continued)

4 © 2012 Renesas Electronics America Inc. All rights reserved.4 Presenter: John A. Carbone VP, Marketing, Express Logic, Inc. Responsible for product and corporate marketing, Renesas partner relationship, technical articles, and technical training. Presenter at Renesas DevCon 2008, 2010, and various industry conferences Authored technical papers on real-time multithreading, certification, and measurement of real-time performance PREVIOUS EXPERIENCE: VP, Marketing at Green Hills Software Embedded developer and FAE Member of the IEEE BA, Mathematics, Boston College

5 © 2012 Renesas Electronics America Inc. All rights reserved.5 Shawn A. Prestridge Senior Field Applications Engineer Responsible for Embedded Workbench training Develops applications for many different boards Develops applications for middleware such as: – RTOS – GUI – Projects as examples and for customers PREVIOUS EXPERIENCE: Embedded hardware/software engineer for Texas instruments. Contractual-based development for Ministry of Software Degree work from Southern Methodist University: BSEE, BS Mathematics, MSEE, MS Software Engineering, PhD in EE

6 © 2012 Renesas Electronics America Inc. All rights reserved.6 ThreadX is Express Logic’s small, fast, RTOS for hard real-time applications Small: Under 3KB for RX Fast: Under 1.0us context switch time @ 96MHz Easy-to-Use: Intuitive API, Textbook, User Guide, Training and Commercial Support Full source code, Royalty-free ThreadX Services Scheduling Interrupt Servicing Threads Timers Queues Semaphores Mutexes Event Flag Groups Block/Byte Memory Pools ThreadX

7 © 2012 Renesas Electronics America Inc. All rights reserved.7 Support for all RX devices Hardware FPU support ROPI (position independent code/data) support ThreadX RTOS awerness Renesas ABI (Application Binary Interface) compliant  Link compatible  Renesas libraries can be linked with EW  RPDL compliant (Renesas Peripheral Driver Library) IAR Embedded Workbench for RX

8 © 2012 Renesas Electronics America Inc. All rights reserved.8 Ready-made example projects demonstrating the different peripheral’s of the MCU Most popular boards supported Kickstart version of EW included in Renesas Starterkits Best optimized RX compiler! IAR Embedded Workbench for RX

9 © 2012 Renesas Electronics America Inc. All rights reserved.9 ThreadX is Integrated for use with IAR Embedded Workbench for RX (EWRX) Delivered as EWRX Projects (Library Build and Demo App) EWRX RTOS Awareness for ThreadX EWRX ThreadX Execution Profiling EWRX Launch of TraceX Analysis Tool Build Library Set compile options – Optimization Level – Debug symbols – Event Trace (see TraceX later) – Execution Profiling Link with Application Any C/C++ code Also link initialization code (provided with ThreadX) Download Run Debug Optimize Using ThreadX and IAR EWRX

10 © 2012 Renesas Electronics America Inc. All rights reserved.10 Threads What is a thread? – Semi-independent program segment – Share same memory space – Run “concurrently” How are threads used? – Modularize a program – Minimize stalls Thread Services – Create, Suspend, Relinquish, Terminate, Exit, Prioritize Thread States – READY, RUNNING, SUSPENDED, TERMINATED Thread Priorities Often 0-n, with 0 highest Dynamic or Static Equal priorities – Multiple threads at same priority Unique priorities – Each thread has unique priority Threads and Priorities Process Thread … Process memory space Highest Lowest Priority 0 1 2 … n

11 © 2012 Renesas Electronics America Inc. All rights reserved.11 Context Switch Thread Context Information critical to thread’s operation Register Contents, Program Counter, Stack Pointer Saved when thread is preempted Restored when thread is resumed Context Switch Interrupt running thread and do something else Result of preemption, interrupt, or cooperative service What’s involved in a context switch? See StepOperationCycles 1 Save the current thread’s context (ie: GP and FP register values and PC) on the stack. 20 - 100 2Save the current stack pointer in the thread's control block.2 - 20 3Switch to the system stack pointer.2 - 20 4Return to the scheduler.2 - 20 5Find the highest priority thread that is ready to run.2 - 50 6Switch to the new thread's stack.2 - 50 7Recover the new thread's context.20 - 100 8Return to the new thread at its previous PC.2 - 40 9Other processing0 - 100 TOTAL50 - 500 Registers PC SP

12 © 2012 Renesas Electronics America Inc. All rights reserved.12 Multithreading Enabling an activity to use the CPU while other activities don’t need it – I/O Delay Thread A Thread B Thread A I/O Start I/O Finish Time Thread A has to wait for I/O When I/O is done, Thread A can continue While Thread A is waiting for I/O, Thread B can use CPU Thread A Waits

13 © 2012 Renesas Electronics America Inc. All rights reserved.13 Preemptive Scheduling Preemption Interruption for higher- priority activity – Interrupt – Thread Preemptive Scheduling Always run highest priority thread that is READY to run – Maximum responsiveness – No Polling, so more efficient – Always results in a context switch Thread-1 Begins Thread-2 Runs Thread-1 Resumes Priority Time Context Switch

14 © 2012 Renesas Electronics America Inc. All rights reserved.14 Among threads of a given priority Threads of different priorities use either preemptive or preemption-threshold scheduling Threads take turns Run to Completion Or, relinquish (suspend) Or, until blocked (suspend) Or, until time slice is exhausted (suspend) Round-Robin Scheduling

15 © 2012 Renesas Electronics America Inc. All rights reserved.15 Preemption-Threshold Scheduling A technique to reduce context switches Preemption-Threshold Scheduling establishes a priority for preemption. Preemption requires a priority higher (lower number) than the preemption-threshold. PriorityComment 0 Preemption allowed for threads with priorities from 0 to 14 (inclusive) : 14 15 Thread is assigned Preemption-Threshold = 15 [this has the effect of disabling preemption for threads with priority values from 15 to 19 (inclusive)] : 19 20 Thread is assigned Priority = 20 : 31 For example, assume a thread’s priority is 20, and its preemption threshold is set to 15 Threads with priority lower than (larger number) 14, even if higher than (smaller number) the running thread’s priority (20), will not preempt the running thread

16 © 2012 Renesas Electronics America Inc. All rights reserved.16 Part-II: An example to show how various scheduling techniques affect performance

17 © 2012 Renesas Electronics America Inc. All rights reserved.17 The Application Fully Preemptive, Round-Robin, or Preemption-Threshold Scheduling: What are the consequences of each with respect to context switching? Construct a system to run and observe Producer-consumer application – One producer, three consumers – 9 messages sent, 9 received – Continuous operation Log events Use EWRX and TraceX to debug Count context switches Measure throughput Draw conclusions Producer Consumer

18 © 2012 Renesas Electronics America Inc. All rights reserved.18 An Example To See The Impact Receive A’s Messages Receive B’s Messages Receive C’s Messages Receive C’s Messages Receive B’s Messages Receive A’s Messages Send a Message to Threads A, B, C Thread A Thread B Thread C Thread D Time Cycle 1Cycle 2 Send a Message to Threads A, B, C

19 © 2012 Renesas Electronics America Inc. All rights reserved.19 Priority Assignments Case-1 Preemptive Scheduling Thread A = 1 Thread B = 2 Thread C = 3 Thread D = 4 Case-2 Round-Robin Scheduling Thread A = 1 Thread B = 1 Thread C = 1 Thread D = 1 Case-3 Preemption-Threshold Scheduling Thread A = 1, PT=1 Thread B = 2, PT=2 Thread C = 3, PT=3 Thread D = 4, PT=1 Case-1Case-2 Thread C Thread D Thread B Thread A 12341234 Thread C Thread D Thread B Thread A PriorityPT Thread C Thread B Thread D Priority Case-3 Thread C Thread D Thread B Thread A

20 © 2012 Renesas Electronics America Inc. All rights reserved.20 Open Project in EWRX View Project Files View/Edit Code Build, Download, Debug Build, Run, Debug the Application

21 © 2012 Renesas Electronics America Inc. All rights reserved.21 Stop at Breakpoint View Counters View Thread List View Message Queues, Memory, etc. Analyze results using TraceX Debug View

22 © 2012 Renesas Electronics America Inc. All rights reserved.22 Real-time event trace Shows RTOS events Shows Application events Target trace_buffer EWRX uploads to host at breakpoint via macro Launch from EWRX TraceX

23 © 2012 Renesas Electronics America Inc. All rights reserved.23 Launch TraceX from the Embedded Workbench IDE Analyzing Results Using TraceX

24 © 2012 Renesas Electronics America Inc. All rights reserved.24 Examining The Events Case-1: Preemptive Scheduling Thread D sends a message to Thread A Thread A preempts Thread A reads its message then suspends (queue empty) Thread D sends message to Thread B Thread B preempts Similarly for Thread C 9 Messages 18 Context Switches 14325 67 8 10 11 1415 17 18 9 12 13 16 1 2 3 4 5 6 7 8 9

25 © 2012 Renesas Electronics America Inc. All rights reserved.25 Examining The Events Case-2: Round-Robin Scheduling (Equal Priorities) Thread D sends 3 messages to each queue Thread D then suspends Thread A reads its 3 messages then suspends (queue empty) Similarly, for Threads B and C Thread D then writes another set of messages 9 Messages 4 Context Switches 4 3 2 1

26 © 2012 Renesas Electronics America Inc. All rights reserved.26 Examining The Events Case-3: Preemption- Threshold Scheduling Thread D sends 3 messages to each queue Thread D then suspends Thread A reads its 3 messages then suspends (queue empty) Similarly, for Threads B and C Thread D then writes another set of messages 9 Messages 4 Context Switches 4 3 2 1

27 © 2012 Renesas Electronics America Inc. All rights reserved.27 14325678 10111415 17 18 9 121316 1 3 4 2 Compare Context Switches Case-1 No PTS Case-2 and Case-3 Round-Robin or PTS Context Switches

28 © 2012 Renesas Electronics America Inc. All rights reserved.28 Compare Timing Case-1 shows 7,531 ticks in a cycle Case-2 and Case-3 show 4,420 ticks in a cycle

29 © 2012 Renesas Electronics America Inc. All rights reserved.29 Assessing The Results Context Switches Throughput CaseMessages Context Switches Case-1: Unique Priorities918 Case-2/3: Round- Robin/Preemption-Threshold 94 Measurement Case-1 (Unique Priorities) Case-2/3 (Round- Robin/Preemption -Threshold) Ratio (Case 1 vs Case-2/3) Context Switches184450% Elapsed Time7,531 ticks4,420 ticks170% Messages Sent99No Change Messages Received99No Change

30 © 2012 Renesas Electronics America Inc. All rights reserved.30 Summary And Conclusions Round-Robin or Preemption-Threshold Scheduling can reduce the number of context switches an application must perform Full Preemption delivers maximum responsiveness, but may result in overhead that has a negative impact on throughput Round-Robin and PTS offer solutions to excessive context switch overhead and can increase throughput Good Tools can make RX development easier IAR Embedded Workbench IDE makes building and debugging easy TraceX eases analysis of real-time applications Strong Integration Makes Tools easy To Use ThreadX Kernel Awareness in EWRX TraceX Launch from EWRX ThreadX delivered as EWRX Projects

31 © 2012 Renesas Electronics America Inc. All rights reserved.31 Q/A For further information about ThreadX: Contact Express Logic, Inc. – 1-888-THREADX (1-858-613-6640) – info@expresslogic.com info@expresslogic.com Visit: www.rtos.comwww.rtos.com For further information about IAR Embedded Workbench for RX: Contact IAR – 1-650-287-4250 (Western US) – 1-508-281-6680 (Eastern US) – +46 18 16 78 00 (HQ – Sweden) – info@iar.com info@iar.com Visit www.iar.comwww.iar.com

32 © 2012 Renesas Electronics America Inc. All rights reserved.32 Please utilize the ‘Guidebook’ application to leave feedback or Ask me for the paper feedback form for you to use… Please Provide Your Feedback…

33 Renesas Electronics America Inc. © 2012 Renesas Electronics America Inc. All rights reserved.


Download ppt "Renesas Electronics America Inc. © 2012 Renesas Electronics America Inc. All rights reserved. Class ID: Using ThreadX ® and IAR Embedded Workbench on the."

Similar presentations


Ads by Google