1
T IMING 1. CLASS T 1 – state of the art timing suite GLIWA embedded systems www. gliwa.com GLIWA GmbH embedded systems | Winterstr. 9a | D-82362 Weilheim Multi-core processors have been used for decades in domains other than automotive. Every PC and every smartphone comes with at least a dual-core processor. The main reason for using more than one core within the processor is the ever increasing need for more computation power. [1] Moore’s law – stated 1965 – says: “The number of tran- sistors in a dense integrated circuit doubles approximately every two years.” AUTOSAR originally was designed for single-core processors but has been extended with a number of multi-core features. • Starting and shutting down other cores r e v e w o h ( g n i n i a h c k s a t d n a n o i t a v i t c a k s a t e r o c - s s o r C task-migration is not supported and also not expected) • Spinlocks (“cross-core semaphore”, explained later) • IOC (Inter-OS-Application Communicator) The term “parallelism” refers to two or more fragments of a program being executed at the same time on several cores. Parallelism can take place at different levels. 6.1 APPLICATION PARALLELISM Each application runs on one core only. One core can still handle more than one application though. The applications come with low cohesion i.e. they are largely independent. Example 1: To reduce costs, two single-core ECUs are merged into one dual-core (= multi-core) ECU. With application parallelism, the software of each single-core ECU gets its own dedicated core on the multi-core ECU. Example 2: AUTOSAR concept [7]. Each core comes with its own set of TASKs and ISRs i.e. its own AUTOSAR application. The AUTOSAR OS allows e.g. cross-core TASK activations and inter-core communication through the IOC (Inter-OS-Application Commu- nicator). It explicitly requires data to be copied and thus might be inefficient for large data. Communication through the RTE can be opti- mized (e.g. direct accesses instead of working on copies) as long as it is intra-core communication. Example 3: When migrating a single-core appli- cation to multi-core, one sensible approach is to have “AUTOSAR cores” and “non-AUTOSAR cores”. This approach is used with early AUTOSAR standards that do not support multi- core. The AUTOSAR software communicates with the non-AUTOSAR software via complex device drivers (CDD). A non-AUTOSAR core could, for example, handle time-critical and/or very frequent interrupts, reducing the number of cache misses and pipeline stalls. There is no need for complicated function parallelism. 6.2 FUNCTION PARALLELISM Function parallelism executes closely related fragments (with potentially high cohesion) of an application in parallel. In or- der to find/design suitable fragments, dependencies have to be analyzed/specified • DFA (data-flow-analysis) • Execution order constraints Function parallelism is largely absent in Windows/Linux/Mac software, mobile devices etc. These use application parallelism mainly! There are very few examples of successful function parallelism and these include 3D rendering software, mainframe database software, computationally intensive sci- entific software at research institutes and universities, etc. Fragmenting software so that it supports function parallelism is not easy and, when done poorly, can result in massive use of protection mechanisms like spinlocks, with a negative impact on the overall performance. As Amdahl’s law shows, the benefit does not scale with the number of cores! Good reasons for more computing power include: - i s s i m e - o r e z ( s e r u t a e f e l c i h e v d e c n a v d a e r o m d n a e r o M on, autonomous driving, car-to-X communication, etc.) y r o m e m , g n i t u p m o c e s r e v i d ( s t n e m e r i u q e r y t e f a s r e t c i r t S protection, on-target supervision, etc.) s t i m i l e d o c d e t a r e n e g d n a s d r a d n a t s f o e s u g n i s a e r c n I the scope of optimization Building faster (higher clock-speed f) single-core processors becomes too expensive at some point due to the following reasons. • Power consumption: P ~ f³ (limiting-case) • EMC (Electromagnetic compatibility) problems • Power dissipation “Melting dashboard” AUTOSAR does not (yet) support y r a s s e c e n n u ( s e r o c s s o r c a n o i t a z i m i t p o E T R R A S O T U A resource locks can be optimized away on a single-core system but unnecessary spinlocks cannot be optimized away on multi-core systems) g n i y p o c y l t n e r r u c ( e c n e r e f e r y b g n i s s a p - a t a d e r o c - r e t n I data is mandatory which becomes an issue when dealing with large data) 6.3 INSTRUCTION PARALLELISM Processor cores have pipelines which process typically 4 to 7 instructions in parallel. However, just because you have a pipeline does not mean you exploit instruction parallelism, which relies on being able to fetch enough instructions to fill the pipeline. The following techniques can reduce flow changes that stall the pipeline and so they support efficient instruction paralle- lism: g n i n i l n i e r e h w s o r c a m t s a e l t a e s u ( s l l a c n o i t c n u f e n i l n i is not possible) • fewer interrupts (use polling where applicable) y b d e m r o f r e p n o i t a z i m i t p o ( g n i r e d r o e r n o i t c u r t s n i the compiler) Amdahl’s law: “The speedup of a program using multiple processors in parallel computing is limited by the time needed for the sequential fraction of the program.” [2] In other words: It takes a woman nine month to carry a child to term. Nine women are not going to do it in a month. Amdahl‘s law applies when there is a significant portion of code which cannot be parallelized. Gustafson’s law: “Programmers tend to set the size of problems to use the available equipment to solve pro- blems within a practical fixed time. Therefore, if faster (more parallel) equipment is available, larger problems can be solved in the same time.” [3] Gustafson’s law applies when a given problem can be repla- ced by a bigger problem solving the old problem plus other problems. Heterogeneous multi-core processors have different cores of different types. Examples: • Infineon TC1797 (TC1.3.1 and PCP) • Freescale MPC5xx with TPU • Freescale S12X with XGATE • Infineon TC277 (several different cores, see next section) Homogeneous multi-core processors have a number of cores of the same type. Examples: • Freescale MPC5xxx • Infineon TC277 (two TC1.6P cores, see next section) Lock-step multi-core processors execute the same single- core software on two separate cores at the same time, for safety reasons. The results of the two cores get continuously compared by the hardware. When a mismatch (=error) occurs, the processor can switch to a safe state. Chip designers spend a lot of effort to avoid common mode failures: slight execution delay between the cores, separate clock-trees, rotated and flipped 2 nd CPU, potential guard ring around each CPU, etc. [4] Example: Texas Instruments TMS570, Infineon AURIX™ (TC1.6.1 core with checker core, see next section) Amdahl’s law and Gustafson’s law seem to contradict. Which one applies to automotive projects? f o s r o s s e c c u s y l t s o m e r a s t c e j o r p e r o c - i t l u m e v i t o m o t u A existing single-core projects. e r a h s t a e r g a h t i w e m o c y l l a c i p y t s t c e j o r p e r o c - e l g n i S - of sequential code. - Thus, Amdahl’s law is more appropriate. t e s d e n e d a h t i w e m o c s t c e j o r p e r o c - i t l u m e v i t o m o t u A of features. e w : s d r o w r e h t o n I . e z i s d e x a s a h m e l b o r p e h T - are not going to add just any code in order to increase the throughput of the cores. - Thus, Gustafson’s law does not apply. -> Amdahl’s law matches the automotive situation better, limiting the speed increase that we can realistically expect with multi-core processors. INTRODUCTION MULTI-CORE THEORY MULTI-CORE HARDWARE ARCHITECTURES 01 03 04 A fable of parallel processing: y a d e n o n i t l i u b n e h c t i k a e v a h o t t n a w u o y e n i g a m I (~ 8 hours). e k a t l l i w t I : s y a s e h t u b t i o d o t n a m s t f a r c a k s a u o Y me 16 hours.” a e r i h t h g i m u o y o S second one in order to get the job done in time. s m e t i c i r t c e l e e h t s t c e n n o c n a m s t f a r c e n o e l i h w : T U B (and therefore takes the fuses out), the other one can- not use his power tools and is blocked. They also spend a lot of the time talking to each other. d n a ) t u o d e s s e r t s y l e t e l p m o c ( s r u o h 1 1 r e t f a h s i n y e h T you agree to plan next time. This poster sheds a light on automotive multi-core embedded software timing aspects. Proper multi-core know-how helps to avoid software projects running into situations as descri- bed above. : s e r o c g n i s s e c o r p n i a m e e r h T two homogeneous ( ) d n a s e r o c e c n a m r o f r e p P 6 . 1 one 1.6E “efficiency” core. Since all three share the same instruction set, you could also regard them as three homoge- neous TC1.6.1 cores. n a e v a h s e r o c 1 . 6 . 1 C T o w T additional lock-step ( ) core. r e h t o l a r e v e s e r a e r e h T heterogeneous ( ) cores. Each TriCore has local program memory and local data memory that it can access with no delay. With significant delay (up to 5 CPU stall cycles), each TriCore can also access data/program memory of other cores, see also section “09 Cloning”. Accesses to peripherals “cost” up to 4 or 7 CPU stall cycles depending on the peripheral bus configuration. The shared program flash and the shared data flash cause a maximum of (5 + number of wait-states) CPU stall cycles [6]. These numbers show that location of data and code has a significant impact on the timing. 20 10 0 8 64 512 4096 SPEEDUP NUMBER OF CORES Parallel Portion 100 50 0 20 40 60 80 100 SPEEDUP NUMBER OF CORES Parallel Portion EXAMPLE INFINEON TC27X “AURIX™” [5] 05 WHY MULTI-CORE? WHY DOES MULTI-CORE SEEM TO BE SO DIFFICULT? AUTOSAR AND MULTI-CORE DIFFERENT KINDS OF PARALLELISM 02 10 07 06 32 bit LOCK STEP LOCK STEP 32 bit 32 bit 32 bit 32 bit 8 bit Homogeneous Checker Core Checker Core Standby controller Generic Timer Module (GTM) TriCore 1.6 P performance TriCore 1.6 E efficiency TriCore 1.6 P performance Hardware Security Module (HSM) SC SC C0 C1 Core 0 Core 1 BSW CDD OS RTE AUTOSAR application non AUTOSAR application Core 0 Core 1 cross-core task activation etc. BSW BSW OS OS RTE AUTOSAR application AUTOSAR application optimization possible optimization possible GLIWA GmbH is an AUTOSAR development member Whilst a single-core application can use interrupt locking to ensure data-consistency, this is not sufficient for multi-core systems sharing data between cores. A command “disable all interrupts” only affects the core executing the command. AUTOSAR introduces spinlocks for synchronization in multi- core systems. Example: assume an application has two, frequent interrupts and it needs to know the total number of executions of both interrupts. The spinlock related AUTOSAR services are: s k c o l n i p s d e n i a t b O . k c o l n i p s a s e s a e l e r k c o l n i p S e s a e l e R must be released in the correct order, the last obtained spinlock must be released first. s i e r o c r e h t o o n n e h w k c o l n i p s a s n i a t b o k c o l n i p S t e G using it. If another core is using it then GetSpinlock loops (spins) until the spinlock can be correctly obtained. - n i p S t e G f o n o i s r e v g n i k c o l b - n o n a s i k c o l n i p S t e G o T y r T lock. It always returns immediately with no spinning. Without any protection, data-consistency cannot be guaranteed. The straight-forward implementation shown in Example (b) is rarely suitable for real applications and can cause significant, unintended delays when one core occupies a spinlock and then handles one or more interrupts. A better implementa- tion is shown below and can be used as a design pattern for spinlock-usage. DATA-CONSISTENCY, SPINLOCKS 08 ISR (myISR<x>) { DisableAllInterrupts(); counter++; EnableAllInterrupts(); } ISR (myISR<x>) { GetSpinlock(spinlock); counter++; ReleaseSpinlock(spinlock); } 10 10 11 11 myISR1 t myISR2 Shared memory ++ ++ t e g s t p u r r e t n i h t o B ) a executed on a single core. t e g s t p u r r e t n i h t o B ) b executed on different cores. StatusType ReleaseSpinlock (SpinlockIdType SpinlockId); StatusType GetSpinlock (SpinlockIdType SpinlockId); StatusType TryToGetSpinlock (SpinlockIdType SpinlockId, TryToGetSpinlockType* Success); TryToGetSpinlockType success; DisableOSInterrupts( ); ( void ) TryToGetSpinlock ( spinlock, &success ); while( TRYTOGETSPINLOCK_NOSUCCESS == success ) { EnableOSInterrupts( ); /* Allow preemption. Optionally insert delays to reduce the number of memory conicts caused by TryToGetSpinlock. */ DisableOSInterrupts( ); ( void ) TryToGetSpinlock ( spinlock, &success ); } /* Region with spinlock obtained and interrupts disabled. */ ... /* do what you need to do with spinlock obtained */ ReleaseSpinlock ( ); EnableOSInterrupts( ); Cloning is a very powerful concept. On the one hand it al- lows unmodified, single-core software to execute correctly on different cores at the same time. On the other hand, it provides an easy way to create efficient, dedicated, multi- core software guaranteed safe from certain kinds of data access conflict. With cloning, all cores see their own, local memory at the same start address, e.g. 0xD0000000 for the DSPR (data scratch pad RAM) of the AURIX™ TriCores. These memories have the same addresses (overlaying) but can have different contents and are, in some sense, clones. Any load or store instruction using this address range accesses the memory lo- cal to the core on which the instruction executes. Existing, single-core software with internal data can be exe- cuted simultaneously by each core as each core uses its own copy of internal data. No modification of the code is requi- red, we simply locate the internal data in the cloned address range. Processors not supporting cloning have to allocate an array rather than a single variable and, at run-time, have to get the core identifier and access the corresponding array element, if they running the same code on different cores. The AURIX™ additionally maps each DSPR address onto the linear shared address-space (mirroring) so that each core can also access the DSPR of other cores, although memory pro- tection may be used to limit cross-core accesses. CLONING 09 Multi-core is the standard in many other domains and the parallel paradigm is rather old, very well understood and not really complicated. So how can it be that so many automoti- ve projects seem to struggle with multi-core? Other domains mostly use application parallelism and in most cases, the software has always been organized in threads. Such applications can easily be ported from single- core to multi-core because parallelism has been made explicit in the threading architecture and the multi-core complexity can be devolved to the OS. The application is not even aware of the number of cores it runs on and there is no attempt to guarantee improved per- formance on a multi-core processor. Automotive engineers additionally want function parallelism, even if they are not aware of this and the resulting impact. Their “old”, single-core application is not designed for multi- core and their code generators do not indicate any inherent parallelism in the code. [1] Dr. Karsten Schmidt, Rolf Schneider, André Kohn, Sven Schönberg et al.: Efficient Virtualization for Functional In- tegration on Modern Microcontrollers in Safety-Relevant Domains, SAE 2014, Detroit, Jan. ‚14 [2] WIKIPEDIA: en.wikipedia.org/wiki/Moore%27s_law [3] WIKIPEDIA: en.wikipedia.org/wiki/Gustafson%27s_law [4] : s t n e m u r t s n I s a x e T Overview for Hercules TMS570 MCUs; www.ti.com [5] n a i l u J , h c s i n r a H s n e J , a w i l G r e t e P , r e z b u e D l e a h c i M . r D Kienberger, Stefan Schmidhuber: Multicore Engineering Tools and Methods, ESE Congress, Sindelfingen, Dec.‘14 [6] : s e i g o l o n h c e T n o e n n I AURIX™ TC27xT data sheet: www.infineon.com [7] : y l s u o i v e r p ( n o i t u b i r t s i D W S B o t e d i u G : R A S O T U A Guide to Multi-Core Systems); www.autosar.org Multi-core EMBEDDED SOFTWARE TIMING AN INTRODUCTION TO AUTOMOTIVE The golden rules for creating simple, easy-to- develop and efficient multi-core software are: s e r o c o t a t a d d n a e d o c e t a c o l l a y l l a c i t a t S so that you can analyze and optimize that allocation e z i m i n i m o t e r o c e n o n o a t a d d n a e d o c e z i l a c o L cross-core accesses o t e t a i r p o r p p a e r e h w e d o c d n a a t a d e t a c i l p u D - achieve this goal • De-couple code on different cores - i p y t ( a t a d d e s s e c c a y l l a c i m o t a t a h t r e b m e m e R - cally up to 64 bits) can be accessed by one wri- ter and ‘n’ readers with no synchronization • Schedule g n i z i n o r h c n y s y b s t c i n o c f o r e b m u n e h t e c u d e R - the schedule across all (related) cores and using offsets so that tasks that access shared data run at mutually exclusive, or at least different, times d n a t s r e d n u , e l b a d i o v a n u s i n o i t a z i n o r h c n y s e r e h W the relevant mechanisms - Spinlocks for very short delays - Spinlock with delay for longer delay d e t c e p x e e r a s y a l e d r e g n o l n e v e n e h w h c t i w s k s a T - As of today (2015) neither the AUTOSAR standard nor the code-generators exploit the multi-core potential to a high degree. The first and most important step towards successful multi-core projects is a sound understanding of multi-core aspects. With this, developers will learn two things: There is no “silver bullet” that allows legacy designs to suddenly exploit parallel processing. Exploiting the great potential of multi-core performance requires parallelism to be designed in from the ground up and support from a range of tools to predict and vali- date timing effects.With proper understanding of multi- core aspects and the right tools, it is possible and very worthwhile to pursue multi-core designs. As with the introduction of other fundamental technolo- gies (compilers, code-generators), the period of transi- tion requires extra know-how and brings some discom- fort. Before long, we can expect ubiquitous multi-core sup- port, including the AUTOSAR standards and code-gene- rators. Complex, single-core projects will be the excepti- on and will be regarded fondly as antiques. GOLDEN RULES SUMMARY GLOSSARY 11 12 13 ABBR. EXPANSION AMP | Asymmetric multiprocessing A multi-core system with a separate operating system per core. AURIX TM Infineon family of multi-core processors based on up to three TriCore CPUs. Cohesion Degree to interdependency (data, code and control flow) within a given software component. Coupling Degree to interdependency (data, code and control flow) between different software components. IOC Inter-OS-Application Communicator. Part of the AUTOSAR OS responsible for managing communications from one OS-Application to another and, by implication, from one core to another. ISR Interrupt Service Routine. A short piece software that executes sequentially to handle an interrupt. Multi-core Having more than one core in a processor. With no explicit qualifiers it generally implies homogeneous multi-core. Non-blocking An implementation of some kind of communication that is guaranteed not to OS Operating System. An ambiguous term used either to mean just a (multitasking) kernel or the combination of a kernel and low-level support software, such as device drivers. The AUTOSAR OS is just a kernel. OS-Application AUTOSAR term for a collection of application software. More than one OS-Application can run on one core but an OS-Application cannot span more than one core. Pipeline Set of processing stages for handling a sequence of data items. As soon as the first data item is passed from the first state to the second stage, the first stage can start to process the second item, introducing true parallelism. Spinlock Mechanism for achieving mutual exclusion. AUTOSAR uses spinlocks for mutual exclusion across multiple cores in the same processor. Symmetric Multiprocessor System (SMP) A multi-core system operating under a single operating system with two or more homogeneous cores. TASK Collection of software that executes sequentially and often, but not necessarily periodically. 95% 90% 50% 10% 90% 50% (SINGLE-)Core Core 0 Core 1 X X Peripherals Heterogeneous REFERENCES 14 Execution of myISR1 gets lost! CORE 0 CORE 1 CORE 2 Accesses to 0xD... reach the core-local DSPR Accesses to 0x5..., 0x6..., 0x7... DSPRs of other cores too DSPR 0 DSPR 1 DSPR 2 0xD000_0000... 0xD000_0000... 0xD700_0000... 0xD600_0000... 0xD500_0000... 0xD000_0000... IOC

Gliwa Multi-corePoster Web · Example: Texas Instruments TMS570, Infi neon AURIX™ (TC1.6.1 core with checker core, see next section) Amdahl’s law and Gustafson’s law seem to

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

  • T IMING 1. CLASST1 – state of the art timing suite

    G L I W Ae m b e d d e d s y s t e m s

    w ww. g l iw a . c omGLIWA GmbH embedded systems | Winterstr. 9a | D-82362 Weilheim

    Multi-core processors have been used for decades in domains other than automotive. Every PC and every smartphone comes with at least a dual-core processor. The main reason for using more than one core within the processor is the ever increasing need for more computation power. [1] Moore’s law – stated 1965 – says: “The number of tran-sistors in a dense integrated circuit doubles approximately every two years.”

    AUTOSAR originally was designed for single-coreprocessors but has been extended with a number ofmulti-core features. • Starting and shutting down other cores

    revewoh( gniniahc ksat dna noitavitca ksat eroc-ssorC • task-migration is not supported and also not expected)

    • Spinlocks (“cross-core semaphore”, explained later) • IOC (Inter-OS-Application Communicator)

    The term “parallelism” refers to two or more fragments of a program being executed at the same time on several cores. Parallelism can take place at different levels.

    6 .1 A PP L I C AT I O N PA R A L L E L I S MEach application runs on one core only. One core can still handle more than one application though. The applications come with low cohesion i.e. they are largely independent.

    Example 1: To reduce costs, two single-core ECUs are merged into one dual-core (= multi-core) ECU. With application parallelism, the software of each single-core ECU gets its own dedicated core on the multi-core ECU.

    Example 2: AUTOSAR concept [7]. Each core comes with its own set of TASKs and ISRs i.e. its own AUTOSAR application.The AUTOSAR OS allows e.g. cross-core TASK activations and inter-core communication through the IOC (Inter-OS-Application Commu-nicator). It explicitly requires data to be copied and thus might be ineffi cient for large data.Communication through the RTE can be opti-mized (e.g. direct accesses instead of working on copies) as long as it is intra-core communication.

    Example 3: When migrating a single-core appli-cation to multi-core, one sensible approach is to have “AUTOSAR cores” and “non-AUTOSAR cores”. This approach is used with earlyAUTOSAR standards that do not support multi-core. The AUTOSAR software communicates with the non-AUTOSAR software via complex device drivers (CDD). A non-AUTOSAR core could, for example, handle time-critical and/or very frequent interrupts, reducing the number of cache misses and pipeline stalls. There is no need for complicated function parallelism.

    6 .2 F U N C T IO N PA R A L L E L I S MFunction parallelism executes closely related fragments (with potentially high cohesion) of an application in parallel. In or-der to fi nd/design suitable fragments, dependencies have to be analyzed/specifi ed • DFA (data-fl ow-analysis) • Execution order constraints

    Function parallelism is largely absent in Windows/Linux/Mac software, mobile devices etc. These use applicationparallelism mainly! There are very few examples of successful function parallelism and these include 3D rendering software, mainframe database software, computationally intensive sci-entifi c software at research institutes and universities, etc.

    Fragmenting software so that it supports functionparallelism is not easy and, when done poorly, canresult in massive use of protection mechanisms likespinlocks, with a negative impact on the overallperformance. As Amdahl’s law shows, the benefi tdoes not scale with the number of cores!

    Good reasons for more computing power include:-issime-orez( serutaef elcihev decnavda erom dna eroM •

    on, autonomous driving, car-to-X communication, etc.) yromem ,gnitupmoc esrevid( stnemeriuqer ytefas retcirtS •

    protection, on-target supervision, etc.) stimil edoc detareneg dna sdradnats fo esu gnisaercnI •

    the scope of optimizationBuilding faster (higher clock-speed f) single-core processors becomes too expensive at some point due to the following reasons. • Power consumption: P ~ f³ (limiting-case) • EMC (Electromagnetic compatibility) problems • Power dissipation “Melting dashboard”

    AUTOSAR does not (yet) support yrassecennu( seroc ssorca noitazimitpo ETR RASOTUA •

    resource locks can be optimized away on a single-core system but unnecessary spinlocks cannot be optimized away on multi-core systems)

    gniypoc yltnerruc( ecnerefer yb gnissap-atad eroc-retnI • data is mandatory which becomes an issue when dealing with large data)

    6 . 3 I N ST RU C T I O N PA RA LLEL I SMProcessor cores have pipelines which process typically 4 to 7 instructions in parallel. However, just because you have a pipeline does not mean you exploit instruction parallelism, which relies on being able to fetch enough instructions to fi ll the pipeline.The following techniques can reduce fl ow changes that stall the pipeline and so they support effi cient instruction paralle-lism:

    gninilni erehw sorcam tsael ta esu( sllac noitcnuf enilni • is not possible)

    • fewer interrupts (use polling where applicable)yb demrofrep noitazimitpo( gniredroer noitcurtsni •

    the compiler)

    Amdahl’s law:“The speedup of a program using multiple processors in parallel computing is limited by the time needed for the sequential fraction of the program.” [2]In other words:It takes a woman nine month to carry a child to term. Nine women are not going to do it in a month.

    Amdahl‘s law applies when there is a signifi cant portion of code which cannot be parallelized.

    Gustafson’s law:“Programmers tend to set the size of problems to use the available equipment to solve pro-blems within a practical fi xed time. Therefore, if faster (more parallel) equipment is available, larger problems can be solved in the same time.” [3]

    Gustafson’s law applies when a given problem can be repla-ced by a bigger problem solving the old problem plus other problems.

    Heterogeneous multi-core processors have different cores of different types.Examples: • Infi neon TC1797 (TC1.3.1 and PCP) • Freescale MPC5xx with TPU • Freescale S12X with XGATE • Infi neon TC277 (several different cores, see next section)

    Homogeneous multi-core processors have a numberof cores of the same type.Examples: • Freescale MPC5xxx • Infi neon TC277 (two TC1.6P cores, see next section)

    Lock-step multi-core processors execute the same single-core software on two separate cores at the same time, for safety reasons. The results of the two cores get continuously compared by the hardware. When a mismatch (=error)occurs, the processor can switch to a safe state. Chip designers spend a lot of effort to avoid common mode failures: slight execution delay between the cores, separate clock-trees, rotated and fl ipped 2nd CPU, potential guardring around each CPU, etc. [4]Example: Texas Instruments TMS570, Infi neon AURIX™ (TC1.6.1 core with checker core, see next section)

    Amdahl’s law and Gustafson’s law seem to contradict. Which one applies to automotive projects?

    fo srosseccus yltsom era stcejorp eroc-itlum evitomotuA • existing single-core projects.

    erahs taerg a htiw emoc yllacipyt stcejorp eroc-elgniS - of sequential code.

    - Thus, Amdahl’s law is more appropriate.

    tes den fied a htiw emoc stcejorp eroc-itlum evitomotuA • of features.

    ew :sdrow rehto nI .ezis dex fi a sah ”melborp“ ehT - are not going to add just any code in order to increase the throughput of the cores.

    - Thus, Gustafson’s law does not apply.

    -> Amdahl’s law matches the automotive situation better, limiting the speed increase that we can realistically expect with multi-core processors.

    IN T RO D U C T I O N

    M U LT I - C O RE TH EO RY

    M U LT I - C O RE H A RD WA RE A R C H ITEC TU R ES

    01

    03

    04

    A fable of parallel processing: yad eno ni tliub nehctik a evah ot tnaw uoy enigamI •

    (~ 8 hours). ekat lliw tI“ :syas eh tub ti od ot namstfarc a ksa uoY •

    me 16 hours.” a erih thgim uoy oS • second one in order to get the job

    done in time. smeti cirtcele eht stcennoc namstfarc eno elihw :TUB •

    (and therefore takes the fuses out), the other one can-not use his power tools and is blocked.

    • They also spend a lot of the time talking to each other. dna )tuo desserts yletelpmoc( sruoh 11 retfa hsin fi yehT •

    you agree to plan next time.This poster sheds a light on automotive multi-core embedded software timing aspects. Proper multi-core know-how helps to avoid software projects running into situations as descri-bed above.

    :seroc gnissecorp niam eerhT •two homogeneous ( )

    dna seroc ”ecnamrofrep“ P6.1 one 1.6E “effi ciency” core. Since all three share the same instruction set, you could also regard them as three homoge-neous TC1.6.1 cores.

    na evah seroc 1.6.1CT owT •additional lock-step ( )core.

    rehto lareves era erehT •heterogeneous ( )cores.

    Each TriCore has local program memory and local datamemory that it can access with no delay. With signifi cant delay (up to 5 CPU stall cycles), each TriCore can also access data/program memory of other cores, see also section“09 Cloning”.

    Accesses to peripherals “cost” up to 4 or 7 CPU stall cycles depending on the peripheral bus confi guration.

    The shared program fl ash and the shared data fl ash cause a maximum of (5 + number of wait-states) CPU stall cycles [6]. These numbers show that location of data and code has asignifi cant impact on the timing.

    20

    10

    08 64 512 4096

    SPEEDUP

    NUMBER OF CORES

    Parallel Portion

    100

    50

    020 40 60 80 100

    SPEEDUP

    NUMBER OF CORES

    Parallel Portion

    E XA M P L E IN F IN E O N TC 27 X “A U R I X™ ” [ 5 ]05

    W H Y M U LT I - C O RE ?

    W H Y D O E S M U LT I - C O RE S E E M T O BE S O D I FF I C U LT ?

    A U T O S A R A N D M U LT I - C O RE

    D IF F ER E N T K IN D S O F PA R A L L E L I SM

    02

    10

    07

    06

    32 bitLOCKSTEP

    LOCKSTEP

    32 bit 32 bit

    32 bit

    32 bit

    8 bit

    Homogeneous

    CheckerCore

    CheckerCore

    Standbycontroller

    Generic TimerModule (GTM)

    TriCore1.6 P

    performance

    TriCore1.6 E

    effi ciency

    TriCore1.6 P

    performance

    HardwareSecurity

    Module (HSM)

    SC

    SC

    C0 C1

    Core 0 Core 1

    BSW CDDOS

    RTE

    AUTOSARapplication non

    AUTOSARapplication

    Core 0 Core 1

    cross-core task activation etc.

    BSW BSWOS OS

    RTE

    AUTOSARapplication

    AUTOSARapplication

    optimizationpossible

    optimizationpossible

    GLIWA GmbH is an AUTOSAR development member

    Whilst a single-core application can use interrupt locking to ensure data-consistency, this is not suffi cient for multi-core systems sharing data between cores. A command “disable all interrupts” only affects the core executing the command. AUTOSAR introduces spinlocks for synchronization in multi-core systems.Example: assume an application has two, frequent interrupts and it needs to know the totalnumber of executions of bothinterrupts.

    The spinlock related AUTOSAR services are:

    skcolnips deniatbO .kcolnips a sesaeler kcolnipSesaeleR • must be released in the correct order, the last obtained spinlock must be released fi rst.

    si eroc rehto on nehw kcolnips a sniatbo kcolnipSteG • using it. If another core is using it then GetSpinlock loops (spins) until the spinlock can be correctly obtained.

    -nipSteG fo noisrev gnikcolb-non a si kcolnipSteGoTyrT • lock. It always returns immediately with no spinning.

    Without any protection,data-consistency cannot be guaranteed.

    The straight-forward implementation shown in Example (b) is rarely suitable for real applications and can cause signifi cant, unintended delays when one core occupies a spinlock and then handles one or more interrupts. A better implementa-tion is shown below and can be used as a design pattern for spinlock-usage.

    D ATA - C O N S IS TE N C Y, SP IN L O C KS08

    ISR (myISR){ DisableAllInterrupts(); counter++; EnableAllInterrupts();}

    ISR (myISR){ GetSpinlock(spinlock); counter++; ReleaseSpinlock(spinlock);}

    10

    10

    11

    11

    myISR1

    t

    myISR2

    Sharedmemory

    ++

    ++

    teg stpurretni htoB )aexecuted on a single core.

    teg stpurretni htoB )bexecuted on different cores.

    StatusType ReleaseSpinlock (SpinlockIdType SpinlockId);StatusType GetSpinlock (SpinlockIdType SpinlockId);StatusType TryToGetSpinlock (SpinlockIdType SpinlockId, TryToGetSpinlockType* Success);

    TryToGetSpinlockType success;DisableOSInterrupts( );( void )TryToGetSpinlock( spinlock, &success );while( TRYTOGETSPINLOCK_NOSUCCESS == success ){ EnableOSInterrupts( ); /* Allow preemption. Optionally insert delays to reduce the number of memory confl icts caused by TryToGetSpinlock. */ DisableOSInterrupts( ); ( void )TryToGetSpinlock( spinlock, &success );}/* Region with spinlock obtained and interrupts disabled. */... /* do what you need to do with spinlock obtained */ReleaseSpinlock( );EnableOSInterrupts( );

    Cloning is a very powerful concept. On the one hand it al-lows unmodifi ed, single-core software to execute correctly on different cores at the same time. On the other hand, it provides an easy way to create effi cient, dedicated, multi-core software guaranteed safe from certain kinds of data access confl ict.

    With cloning, all cores see their own, local memory at the same start address, e.g. 0xD0000000 for the DSPR (data scratch pad RAM) of the AURIX™ TriCores. These memories have the same addresses (overlaying) but can have different contents and are, in some sense, clones. Any load or store instruction using this address range accesses the memory lo-cal to the core on which the instruction executes.

    Existing, single-core software with internal data can be exe-cuted simultaneously by each core as each core uses its own copy of internal data. No modifi cation of the code is requi-red, we simply locate the internal data in the cloned address range. Processors not supporting cloning have to allocate an array rather than a single variable and, at run-time, have to get the core identifi er and access the corresponding array element, if they running the same code on different cores.

    The AURIX™ additionally maps each DSPR address onto the linear shared address-space (mirroring) so that each core can also access the DSPR of other cores, although memory pro-tection may be used to limit cross-core accesses.

    C L O N I N G09

    Multi-core is the standard in many other domains and the parallel paradigm is rather old, very well understood and not really complicated. So how can it be that so many automoti-ve projects seem to struggle with multi-core?

    Other domains mostly use application parallelism and in most cases, the software has always been organized inthreads. Such applications can easily be ported from single-core to multi-core because parallelism has been made explicit in the threading architecture and the multi-core complexity can be devolved to the OS.

    The application is not even aware of the number of cores it runs on and there is no attempt to guarantee improved per-formance on a multi-core processor.

    Automotive engineers additionally want function parallelism, even if they are not aware of this and the resulting impact. Their “old”, single-core application is not designed for multi-core and their code generators do not indicate any inherent parallelism in the code.

    [1] Dr. Karsten Schmidt, Rolf Schneider, André Kohn, Sven Schönberg et al.: Effi cient Virtualization for Functional In-tegration on Modern Microcontrollers in Safety-Relevant Domains, SAE 2014, Detroit, Jan. ‚14

    [2] WIKIPEDIA: en.wikipedia.org/wiki/Moore%27s_law[3] WIKIPEDIA: en.wikipedia.org/wiki/Gustafson%27s_law[4] :stnemurtsnI saxeT Overview for Hercules TMS570

    MCUs; www.ti.com

    [5] nailuJ ,hcsinraH sneJ ,awilG reteP ,rezbueD leahciM .rD Kienberger, Stefan Schmidhuber: Multicore Engineering Tools and Methods, ESE Congress, Sindelfi ngen, Dec.‘14

    [6] :seigolonhceT noen finI AURIX™ TC27xT data sheet: www.infi neon.com

    [7] :ylsuoiverp( noitubirtsiD WSB ot ediuG :RASOTUA Guide to Multi-Core Systems); www.autosar.org

    Multi-core EMBEDDEDSOFTWARETIMINGAN INTRODUCTIONTO AUTOMOTIVE The golden rules for creating simple, easy-to-develop and effi cient multi-core software are:

    seroc ot atad dna edoc etacolla yllacitatS • so that you can analyze and optimize thatallocation

    eziminim ot eroc eno no atad dna edoc ezilacoL • cross-core accesses

    ot etairporppa erehw edoc dna atad etacilpuD - achieve this goal

    • De-couple code on different cores-ipyt( atad dessecca yllacimota taht rebmemeR -

    cally up to 64 bits) can be accessed by one wri-ter and ‘n’ readers with no synchronization

    • Schedule gnizinorhcnys yb stci flnoc fo rebmun eht ecudeR -

    the schedule across all (related) cores and using offsets so that tasks that access shared data run at mutually exclusive, or at least different, times

    dnatsrednu ,elbadiovanu si noitazinorhcnys erehW • the relevant mechanisms

    - Spinlocks for very short delays - Spinlock with delay for longer delay

    detcepxe era syaled regnol neve nehw hctiws ksaT -

    As of today (2015) neither the AUTOSAR standard nor the code-generators exploit the multi-core potential to a high degree. The fi rst and most important step towards successful multi-core projects is a sound understanding of multi-core aspects. With this, developers will learn two things:There is no “silver bullet” that allows legacy designs to suddenly exploit parallel processing. Exploiting the great potential of multi-core performance requires parallelism to be designed in from the ground up and support from a range of tools to predict and vali-date timing effects.With proper understanding of multi-core aspects and the right tools, it is possible and very worthwhile to pursue multi-core designs. As with the introduction of other fundamental technolo-gies (compilers, code-generators), the period of transi-tion requires extra know-how and brings some discom-fort.Before long, we can expect ubiquitous multi-core sup-port, including the AUTOSAR standards and code-gene-rators. Complex, single-core projects will be the excepti-on and will be regarded fondly as antiques.

    G O L D E N R U L E S

    S U M M A RY

    G LO S S A RY

    11

    12

    13

    A BB R . E X PA N S I O NAMP | Asymmetric multiprocessing

    A multi-core system with a separate operating system per core.

    AURIXTM Infi neon family of multi-core processors based on up to three TriCore CPUs.

    Cohesion Degree to interdependency (data, code and control fl ow) within a given software component.

    Coupling Degree to interdependency (data, code and control fl ow) between different software components.

    IOC

    Inter-OS-Application Communicator. Part of the AUTOSAR OS responsible for managing communications from one OS-Application to another and, by implication, from one core to another.

    ISR Interrupt Service Routine. A short piece software that executes sequentially to handle an interrupt.

    Multi-core Having more than one core in a processor. With no explicit qualifi ers it generally implies homogeneous multi-core.

    Non-blocking An implementation of some kind of communication that is guaranteed not to block.

    OS

    Operating System. An ambiguous term used either to mean just a (multitasking) kernel or the combination of a kernel and low-level support software, such as device drivers. The AUTOSAR OS is just a kernel.

    OS-Application

    AUTOSAR term for a collection of application software. More than one OS-Application can run on one core but an OS-Application cannot span more than one core.

    Pipeline

    Set of processing stages for handling a sequence of data items. As soon as the fi rst data item is passed from the fi rst state to the second stage, the fi rst stage can start to process the second item, introducing true parallelism.

    Spinlock Mechanism for achieving mutual exclusion. AUTOSAR uses spinlocks for mutual exclusion across multiple cores in the same processor.

    Symmetric Multiprocessor System (SMP)

    A multi-core system operating under a single operating system with two or more homogeneous cores.

    TASK Collection of software that executes sequentially and often, but not necessarily periodically.

    95%

    90%

    50%

    10%

    90%

    50%

    (SINGLE-)Core Core 0 Core 1

    X

    X

    Peripherals

    Heterogeneous

    RE F E RE N C E S14

    Execution ofmyISR1 gets lost!

    CORE 0

    CORE 1

    CORE 2

    Accesses to 0xD...reach the core-local DSPR

    Accesses to 0x5..., 0x6..., 0x7...DSPRs of other cores too

    DSPR 0

    DSPR 1

    DSPR 2

    0xD000_0000...

    0xD000_0000...

    0xD700_0000...

    0xD600_0000...

    0xD500_0000...

    0xD000_0000...

    IOC