SoC
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
  • Arm Cortex M3
  • Contact
Reading: Does setting a section’s attributes using MPU affect the CPU’s ordering of the specific section?
SUBSCRIBE
SoCSoC
Font ResizerAa
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Search
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Have an existing account? Sign In
Follow US
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
© S-O-C.ORG, All Rights Reserved.
Arm

Does setting a section’s attributes using MPU affect the CPU’s ordering of the specific section?

Neil Salmon
Last updated: September 16, 2023 9:47 am
Neil Salmon 6 Min Read
Share
SHARE

Setting a section’s attributes using the Memory Protection Unit (MPU) can affect the CPU’s ordering of that specific section. The MPU allows configuring access permissions and cache policies for different memory regions. Setting strict ordering for a section via the MPU results in the CPU forcing transactions to that section to occur in program order. This prevents reordering optimizations that could cause problems for self-modifying or tightly coupled driver code.

Contents
Overview of Sections and MPUMPU Region Ordering and ReorderingMPU Ordering EffectsSetting Section Attributes with MPUEffects on Memory SubsystemSummary

Overview of Sections and MPU

Sections are independent units of code or data that can be individually configured and mapped into memory. On ARM processors, the MPU allows assigning section-level attributes like:

  • Access permissions (read/write/execute)
  • Caching policies (cacheable/non-cacheable)
  • Memory types (normal, device, strongly ordered)
  • Allocation strategies (static, dynamic)

The MPU provides hardware-level isolation and protection for different memory regions. It divides the memory map into a set of sections called MPU regions. Each MPU region can be configured with different attributes. The attributes control things like:

  • Which CPU modes can access the region (e.g. user mode vs privileged mode)
  • What kind of accesses are allowed (read/write/execute)
  • The caching policy for the region

When the CPU generates a memory access, the MPU hardware checks if the access matches the configured attributes of any region. If not, the MPU triggers a fault exception. This prevents potentially dangerous accesses before they reach memory.

MPU Region Ordering and Reordering

One important MPU region attribute is the shareability attribute. This controls the memory ordering applied to that region. The options are:

  • Non-shareable – System ordering is applied. Allows reordering for performance.
  • Inner Shareable – Inner shareable ordering applied. Some reordering allowed.
  • Outer Shareable – Outer shareable ordering applied. Strictest ordering.
  • Strongly Ordered – Strongest ordering, no reordering of any kind.

Strongly ordered and outer shareable regions have very strict ordering, forcing all transactions to that region occur in program order. This disables any reordering optimizations by the CPU, memory system, or interconnect.

Non-shareable regions allow the most reordering flexibility. The CPU can reorder transactions to different non-shareable regions. Caches and interconnects can also reorder transactions as long as system correctness is maintained.

MPU Ordering Effects

Setting a section to use strongly ordered or outer shareable attributes via the MPU prevents the CPU and memory system from reordering accesses to that section. Some examples include:

  • Self-modifying code sections should use strongly ordered attributes. This ensures instruction fetches get updated data, not stale cached values.
  • Memory-mapped peripheral register sections should use strongly ordered attributes. This prevents reordering that could cause race conditions.
  • Multiprocessor shared memory sections should use outer shareable attributes. This ensures all CPUs see memory accesses in the same order.

For normal data and code sections, non-shareable attributes can be used. This allows the CPU and caches to aggressively reorder accesses to different non-shareable regions for performance. Reordering works safely as long as dependent accesses use full memory barriers as needed.

Setting Section Attributes with MPU

There are a few common ways to set section attributes using the MPU on ARM processors:

  • The MPU driver can configure MPU regions during kernel initialization based on mappings defined in the linker script.
  • Hypervisors may configure the MPU to isolate guest OS memory into different regions.
  • Some MPUs allow section attributes to be dynamically reconfigured at runtime via MPU driver APIs.
  • Higher level APIs like the OS memory protection API can set MPU attributes when creating special memory sections.

For example, to create a strongly ordered shareable memory section, the MPU region would be configured to match the memory address range for that section. The region attributes would be set to permit the required accesses with strongly ordered shareability.

Aligning the MPU regions properly with memory sections prevents accesses from hitting the wrong MPU region. Misalignment could cause unintended faults or reordering for sections.

Effects on Memory Subsystem

The CPU ordering enforced by MPU attributes can influence the broader memory subsystem behavior:

  • Non-cacheable attributes bypass caches, eliminating reordering side effects.
  • Write-through cacheable attributes prevent reordering writes vs later reads.
  • Strongly ordered attributes force interconnect transactions in order.

Conversely, the memory subsystem can limit the MPU’s effects if it reorders transactions across regions. Using strongly ordered attributes ensures strict ordering regardless of the memory system behavior.

Summary

The MPU allows assigning memory ordering attributes like strongly ordered and outer shareable to memory regions. Applying such strict ordering to a section via the MPU prevents the CPU and memory system from reordering transactions to that section. This is essential for self-modifying code, memory-mapped peripherals, shared memory, and other critical sections. Careful use of MPU attributes can enable both optimal performance and correct behavior across interacting sections.

Newsletter Form (#3)

More ARM insights right in your inbox

 


Share This Article
Facebook Twitter Email Copy Link Print
Previous Article Does Normal memory, and Device memory really affect the system behavior? Cortex M0/M0+
Next Article Faster way of multiplying 2 32-bit numbers giving a 64-bit result in Cortex M0/M0+
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

2k Followers Like
3k Followers Follow
10.1k Followers Pin
- Sponsored-
Ad image

You Might Also Like

Which memory acts as data memory in Arm Cortex-M4?

The Arm Cortex-M4 processor utilizes a Harvard architecture, which means…

7 Min Read

FreeRTOS Context Switch

A context switch is a fundamental part of multitasking real-time…

5 Min Read

What are the different types of ARM Cortex-M?

ARM Cortex-M processors are a range of low-power microcontrollers designed…

6 Min Read

Where is the interrupt vector table located in arm?

The interrupt vector table in ARM processors is located at…

7 Min Read
SoCSoC
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
Welcome Back!

Sign in to your account