
Transcription
Embedded Linux Conference 2014SMP bring up onARM SoCsGregory CLEMENTFree [email protected] Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com1/31
Gregory CLEMENTIEmbedded Linux engineer and trainer at Free Electrons since2010IIIEmbedded Linux development: kernel and driverdevelopment, system integration, boot time and powerconsumption optimization, consulting, etc.Embedded Linux training, Linux driver development trainingand Android system development training, with materialsfreely available under a Creative Commons license.http://free-electrons.comIContributing to kernel support for the Armada 370, 375,38x and Armada XP ARM SoCs from Marvell.ICo-maintainer of mvebu sub-architecture (SoCs from MarvellEngineering Business Unit)ILiving near Lyon, FranceFree Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com2/31
Motivation and OverviewIMotivationIIIIIAll the new ARM CPUs are now SMP capable.Most of the new ARM SoCs actually uses multiple CPUs.Did SMP bring up for two kinds of ARM SoCs during past year.Documentation I would have like to find.OverviewIIISMP operations and functions.Implementation of these functions.Issues encountered during SMP bring up.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com3/31
SMP on ARM SoC?IA symmetric multiprocessor system (SMP) is a multiprocessorsystem with centralized shared memory called main memory(MM) operating under a single operating system with two ormore homogeneous processors. (Wikipedia)IMost of the SMP code is not architecture dependent (inkernel directory).IMost of the hardware support is related to the ARMspecification.ISoC level: all that is beyond the CPU, mainly initializationand power down the CPUs.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com4/31
AssumptionsISoC support is working on one CPU core.ISupport is following the last requirements(see “Your new ARM SoC Linux support check-list” from Thomas s/2013/elc/arm-socchecklist/)IDatasheet is available.INo hardware bug (or at least they are documented).Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com5/31
SMP operationsIFew SMP functions related to the SoC:struct smp operations {void (*smp init cpus)(void);void (*smp prepare cpus)(unsigned int max cpus);void (*smp secondary init)(unsigned int cpu);int (*smp boot secondary)(unsigned int cpu,struct task struct *idle);[.]};IOnly smp boot secondary() is mandatory, others areoptional and depend on the need of the SoCs.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com6/31
Role of each SMP operations 1/2Ismp init cpus():IIIISetup the set of possible CPUs (via cpu possible()).Can be removed if the CPU topology is up to date in thedevice tree.Called very early during the boot process (fromsetup arch()).smp prepare cpus():IIIIEnables coherency.Initializes cpu possible map.Prepares the resources (power, ram, clock.).Called early during the boot process (before the initcalls butafter setup arch()).Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com7/31
Role of each SMP operations 2/2Ismp secondary init():IIIISupposed to “perform platform specific initialization of thespecified CPU”.Mostly dealing with pen release stuff which seems to be wrong.Russell King: The pen release stuff is only there forplatforms where there’s no proper way of controlling thesecondary CPUs except by using a software method.Called from secondary start kernel() on the CPU whichhas just been started.smp boot secondary():IIActually boots a secondary CPU identified by the CPU numbergiven in parameter.Called from cpu up() on the booting CPU.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com8/31
Booting sequence of the SMP operationsFree Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com9/31
Hotplug SMP operationsIWhen CONFIG HOTPLUG CPU is selected three more functionsare added to smp operations:struct smp operations {[.]int (*cpu kill)(unsigned int cpu);void (*cpu die)(unsigned int cpu);int (*cpu disable)(unsigned int cpu);};ITo support the hotplug features cpu kill() and cpu die()must be provided.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com10/31
Role of each SMP hotplug operations 1/2Icpu kill():IIIIISupposed to do the powering off and/or cutting off clocks tothe dying CPU.Need to be synchronized with cpu die().Needed for kexec (only user ofplatform can cpu hotplug(), which checks the presence ofthis function).Called on the thread which is asking for a CPU to beshutdown.cpu die():IIIISupposed to ensure death of the CPU.Not supposed to return from this function, returns only if theSoC can’t power down the CPU.Either power down the CPU or at least call cpu do idle().Called from the idle thread for the CPU which has beenshutdown.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com11/31
Role of each SMP hotplug operations 2/2Icpu disable():IIICommon ARM code takes care of the shutdown of a CPU: nomore interrupts can be handled by the kernel after the routinereturns, including local timers which are shutdown.By default, the common code allows disabling all CPUs exceptthe first one (the boot CPU). This function can be used tochange this behavior.Runs on the CPU to be shutdown.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com12/31
SMP related features: nice to haveNot mandatory features, but they are usually added in the sametime that SMP support.I IRQ affinity: allows to dedicate one or several CPUs to aninterrupt.IIIPart of the IRQ chip driver.Implemented in the following handler:int (*irq set affinity)(struct irq data *data,const struct cpumask *dest, bool force)Local timer: timer dedicated to a CPU, thanks to this, nomore need to broadcast a tick to all the CPUs.IINo more a specific API to register it since 3.12.Still needs to use the percpu API and the notifiers toimplement it.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com13/31
Use of the PSCI for SMPPSCI stands for Power State Coordination Interface.INeeded for virtualization.IUsed to coordinate OSes and hypervisors.IOnly solution to deal with secure mode.IProvides functions used for SMP bring-up such as CPU ON orCPU OFF.IFunction provided by the firmware, the SMP operations are nomore used.IID of these functions provided through the device tree.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com14/31
Implementing the SMP operations 1/2Ismp init cpus()IIIITypically if an SCU unit is available the number of CPUs isretrieved using scu get core count().And then the CPU possible map is builtusing set cpu possible().However as the cpu topology is supposed to be described inthe device tree, the whole map is already built in the functionarm dt init cpu maps.smp prepare cpus()IIIIf SCU is present then the coherency is enabled by usingscu enable().Most of the time resources are allocated and the registers aremapped using ioremap() and its friends.The way to enable (if needed) the power and the clocks ishighly platform specific and does not involve common code.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com15/31
Implementing the SMP operations 2/2Ismp secondary init()IINo common code used here but a lot of copy/paste of thepen release mechanism.smp boot secondary()IIIReleases the CPU from reset by writing on a powermanagement register.Some time writes “magic” pattern read by the bootrom whichwill release the CPU from reset.Uses the pen release if the secondary CPU has already beenreleased from reset.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com16/31
Implementing the SMP hotplug operations 1/2Icpu kill()IIIIMost of the platforms check that the CPU is going to die, byreading a register of the SoC wrote by the dying CPU.Some platforms really check that the dying CPU went in thereset state.Then it actually powers down the CPU if the dying CPU hasnot done it by itself.cpu die()IIIOn most of the platforms, the dying CPU writes a register ofthe SoC, usually by setting to 0 the jump address of the CPU.Some platforms switch in low power mode.The others just call cpu do idle().Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com17/31
Implementing the SMP hotplug operations 2/2Icpu disable()IIOnly implemented if the behavior of the platforms is differentof the default (ie all CPUs except the first one can be killed).Currently only used by shmobile where any CPU can be killed.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com18/31
Registering the SMP operationsIUsed to be part of the machine description. Thesmp operations structure of the SoC was associated to the.smp field using the smp ops() helper.IFrom 3.16, they should be directly registered using theCPU METHOD OF DECLARE() helper.IThen the operation will be fetched from the device tree.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com19/31
Implementing a local timerIShould be part of a clock source driver indrivers/clocksource/.IEach local timer will be called during the CPU bring up(CPU STARTING), so the setup of the timer must beassociated to a notifier using register cpu notifier().IThe timer must be stopped when the CPU is shutting down(CPU DYING), so this function will be also associated to thenotifier.IThe interrupt has to be registered withrequest percpu irq().IAnd the clock event device has to be allocated withalloc percpu().Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com20/31
Implementing the IRQ affinityIShould be part of an IRQ chip driver in drivers/irqchip/.IThe interrupts associated to (struct irq data *datareceived should be treated only by the CPU represented bystruct cpumask *dest.IThe cpumask can be manipulated using the helpers located ininclude/linux/cpumask.h.IIt is valid, depending of the hardware capabilities, to set theIRQ affinity of only of a subset of the group of the CPUs.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com21/31
SMP and device tree: CPU topology - ”cpus”From Documentation/devicetree/bindings/arm/cpus.txt:The device tree allows to describe the layout of CPUs in a systemthrough the ”cpus” node, which in turn contains a number ofsubnodes (ie ”cpu) defining properties for every cpu.The cpus nodes are composed of:I#address-cells: 1 for 32-bit and 2 for 64-bitI#size-cells: Always 0enable-method:IIIIIOptional for ARM 32-bit, but highly recommended for newimplementations from 3.16.For ARM 32 bits, the string is the one used for registering theSMP operations with CPU METHOD OF DECLARE().Required for ARM v8 and must be "spin-table" or "psci"Possible to use "psci" for ARM 32-bit too.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com22/31
SMP and device tree: CPU bindings - ”cpu”The cpu subnodes are composed of:Idevice type: Always "cpu".Ireg: Related to the MPIDR, more or less the ID of the CPU.Icompatible: The CPU type for example: "arm,cortex-a9"or "marvell,pj4b".Ienable-method: Supposed to be defined at the CPU levelbut can be inherit from the CPUs level.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com23/31
SMP and device tree: CPU bindings - Examplecpus {#address-cells 1 ;#size-cells 0 ;enable-method "marvell,armada-380-smp";[email protected] {device type "cpu";compatible "arm,cortex-a9";reg 0 ;};[email protected] {device type "cpu";compatible "arm,cortex-a9";reg 1 ;};};Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com24/31
SMP and device tree: PSCIFully defined t is more that just supporting SMP.Icompatible: Always "arm,psci"Idevice type: Always "cpu".Imethod: "smc" or "hvc" depending on the method used tocall the PSCI firmware.Icpu off: Function ID for CPU OFF operation.Icpu on: Function ID for CPU ON operation.IThere are other functions defined but they are not used asSMP operations.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com25/31
SMP and device tree: PSCI - Examplepsci {compatible "arm,psci";method "smc";cpu suspend 0x84000002 ;cpu off 0x84000004 ;cpu on 0x84000006 ;};cpus {#address-cells 1 ;#size-cells 0 ;[email protected] {compatible "arm,cortex-a15";device type "cpu";reg 0 ;};[.][email protected] {compatible "arm,cortex-a15";device type "cpu";reg 3 ;};};Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com26/31
Issues encountered during SMP Bring-up: coherencyISymptom: The kernel booted on the CPU 0 but the otherCPUs failed to boot.IIOn the secondary CPUs the L1 cache were corrupted.The L1 cache needed to be invalidated before starting asecondary CPU.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com27/31
Issues encountered during SMP Bring-up: coherencyISymptom: The kernel crashed pretty early during the SMPinitialization.IIIThe registers controlling the coherency were not mapped yet.The initialization of the resources associated to the coherencywere done in an initcall, however the coherency for SMP iscalled before the initcalls.The solution was to move this initialization in the .init timehandler called directly from start kernel.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com28/31
Issues encountered during SMP Bring-up: timersISymptom: The kernel booted but then nothing happened inuserspaceIINo timer ticked at all so no schedule happened.Here the problem was that the field irq of the timer was notfilled.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com29/31
Issues encountered during SMP Bring-up: timersISymptom: Sometimes the kernel hanged, just after booting,sometimes later when we have already switched to userspace.IIThere was no local timer neither broadcast timer: no tick onthe secondary CPUs. As soon as the task ran on a secondaryCPU, then it hanged, as no schedule happened.The reason in our case was that CONFIG HAVE TWD was notselected.Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com30/31
Questions?Gregory [email protected] under CC-BY-SA elc/clement-smp-bringup-on-arm-socFree Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http://free-electrons.com31/31
Motivation and Overview I Motivation I All the new ARM CPUs are now SMP capable. I Most of the new ARM SoCs actually uses multiple CPUs. I Did SMP bring up for two kinds of ARM SoCs during past year. I Documentation I would have like to nd. I Overview I SMP operations and functions. I Implementation of these functions. I I