Energy Efficient, Greener Designs by Adding 1 Line of Code
When using an RTOS, WITTENSTEIN high integrity systems has quantified that using a Wait For Interrupt1 (WFI) instruction in the idle task of a Cortex-M processor can save over a third of the total energy consumed by the processor.
If this RTOS solution was deployed across a million processors, the power saving would be around 480MWh a year- the amount of electricity required to power 165 UK homes2 for the same period.
- Measured power savings of over 37%
- One simple instruction
- 1 million deployments saves enough electricity to power 165 UK homes.
The implementation on an ARM Cortex-M platform is incredibly simple:
When using a pre-emptive, priority based RTOS, whenever the RTOS has no other task to schedule, by default it runs the lowest priority task, which is normally the idle task. The idle task executes an infinite loop, calling the “idle hook function” each time around the loop. To save power in the idle task, the idle hook needs to configure the processor in a way that reduces power consumption.
void vApplicationIdleHook( void )
asm volatile (" WFI \n" );
A simple and effective approach is to add a Wait For Interrupt (WFI) instruction to the idle hook function that sets the processor into a low power mode, from which it can be woken by an interrupt. If the idle task is scheduled, the only possible way a non-idle task will be scheduled is in response to an interrupt, usually the system “tick”. When an interrupt arrives, the processor is restored to full power mode and execution continues.
Should every design minimise power consumption?
The absolute power saved by a single processor is very small, however the potential global power that could be saved does scale, given the huge number of processors deployed each year. A great number of embedded designs do take steps to minimise power consumption, but for those that don’t we would highly recommend designers consider adding WFI instruction within the idle hook function. It’s one line of code, and if all designs optimised for power usage the power saved globally would be considerable
Proof of Concept
We used the simple LED colour cycling application from the Workshop Demo “Upgrading from FreeRTOS to SAFERTOS®” on an off the shelf Cortex-M processor. It has several tasks that are quite busy, but all of them spend most of their time blocked, so the processor spends a large proportion of every tick period in the idle task. We simply created an idle hook function exactly as above with a single WFI in it. To quantify the amount of power we could save we ran it with the WFI in place and then compared it to the same application with the WFI instruction commented out.
To compare power consumption, we modified the board on which the demo runs, breaking a solder bridge in the supply rail to the target CPU and inserting a jumper link that could be replaced with a digital multimeter reading current in milliamps (mA). Power (in Watts) is current (in Amps) times voltage (in Volts), and energy consumption is power (Watts) times time – either Watt Seconds for energy in Joules (J) or typically Watt Hours (W.h) for domestic electricity billing. Current was of the order of 50 mA, and the processor supply is 3.3v, so approximately 150 mW.
|FreeRTOS base task||FreeRTOS Task with solution||SAFERTOS base task||SAFERTOS Task with solution|
|Power used||150.5 mW||90.3 mW||145.0 mW||90.4 mW|
|Energy per year||1.32 kWh||0.79 kWh||1.27 kWh||0.79 kWh|
|Savings/year in 1 deployment||0.53 kWh||0.48 kWh|
|Savings/year in 1,000,000 deployments||528 MWh||480 MWh|
|Savings over 5 years in 1,000,000 deployments||2.64 GWh||2.39 GWh|
Note: The multimeter will have introduced some resistance in order to measure current, and that resistance will have reduced the core voltage from the nominal 3.3v. The core will still use the same power, so the current will be higher than it would be without the meter in circuit, which, when multiplied by the nominal 3.3v gives a power consumption figure slightly higher than actual. The difference is small, though, and all readings are affected the same way, so the comparisons with/without WFI in idle hook are valid. Application differences will be vastly more significant in actual practice.
Power Saving through the Entire Embedded System
In this case, power savings of over a third were made, but when designing an embedded system with power saving in mind the entire design must be considered. This includes, but is not limited to:
- Choice of processor
- Choice of peripherals
- Choice of operating frequency
- Application design
- Whole system design
 This use case and resulting recommendations are based on the Arm architectural feature Wait for Interrupt. More information about the Wait for Interrupt Instruction can be found in Arm’s architecture manuals: https://www.arm.com/ [Accessed on 17/02/22]
 Assuming an average Typical Domestic Consumption Value of 2,900kWh of electricity per year. This figure has been obtained from: https://www.ofgem.gov.uk/publications/record-gas-prices-drive-price-cap-ps139-customers-encouraged-contact-supplier-support-and-switch-better-deal-if-possible [Accessed on 17/02/22]
Free Demos & Manuals
Download fully functional, time-limited SAFERTOS demos, plus manuals, datasheets, and more.