ARM WFI and WFE directives

Source: Internet
Author: User
1. Preface


The snail has long been known to have WFI and wfe These two instructions exist, but has been indefinitely. Recently prepared to study the CPU idle framework, as WFI is a way to get the CPU into the idle state, make up your mind to figure it out.



WFI (wait for interrupt) and WFE (wait for event) are two instructions for the arm core to enter Low-power Standby mode, defined by ARM architecture and implemented by ARM core. It's easy to hear, but there are two instructions. What is the difference between them. What the usage scenario is. It's kind of interesting to dig up, for example: Can you imagine the relationship between WFE and spinlock? 


2. WFI and Wfe



1) Common Ground



The functions of WFI and WFE are very similar, taking armv8-a as an example (refer to the description of Ddi0487a_d_armv8_arm.pdf), mainly "armv8-a PE (processing element, processing unit) is set to Low-power Standby state ".



It should be stated that ARM architecture does not specify a specific form of "low-power standby state", so it can be performed by ARM core, which can generally be implemented as standby according to ARM's recommendations (turn clock off, maintain power) , dormant, shutdown and so on. But there is a principle that does not cause memory consistency issues. Taking Cortex-a57 ARM Core as an example, it implements WFI and Wfe as "put the core in a low-power state by disabling the clocks in the core while keeping th E Core powered up ", which is what we usually call Standby mode, keeps the power off and turns off the clock.



2) different points



So what's the difference between them? Mainly reflected in the way of entry and exit.



For WFI, when the WFI command is executed, ARM core immediately enters Low-power standby state until WFI Wakeup events occur.



While the WFE is slightly different, after executing the WFE instruction, there are two situations depending on the state of the event register (a single bit register, one per PE): If the event register is 1, the directive will clear it and execute it (not standby) If event Register is 0, similar to WFI, enter Low-power standby state until WFE Wakeup events occur.



The WFI wakeup event and Wfe Wakeup event can be used to wake the core from WFI and WFE respectively, and these two types of event are mostly the same, such as any IRQ interrupt, Fiq interrupt, and so on, with some subtle differences that can be referred to as "Ddi0487a_d_ Description of Armv8_arm.pdf ". The biggest difference is that the WFE can be awakened by SEV instructions executed on any PE.



The so-called SEv Directive, which is an instruction to change the event register, has two: The SEV Modifies all the registers on the PE, and SEVL only modifies the register value of this PE. Let's take a look at the use of this special design for WFE. 


3. Usage Scenarios



1) WFI



WFI is generally used for cpuidle.



2) WFE



A typical usage scenario for WFE is used in Spinlock (refer to Arch_spin_lock, for arm64, in Arm64/include/asm/spinlock.h). The function of spinlock is to protect shared resources between different CPU cores. The process for using WFE is:



A) resource idle



b) Core1 access to resources, acquire lock, access to resources



c) Core2 access to resources, when resources are not idle, execute WFE instructions, let core into Low-power state



D) Core1 frees resources, releases lock, frees up resources, executes SEV commands, wakes Core2



e) Core2 access to resources



In the past spinlock, when the resources are not available, let the core into the busy loop, and by inserting WFE instructions, you can save power, but also because of the curse (loss of performance) blessed (reduced power) bar.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.