Skip to content

Conversation

kjbracey
Copy link
Collaborator

__NVIC_DisableIRQ and __NVIC_EnableIRQ can be used to function as a mutex-style protection lock against a particular interrupt handler, similar to __disable_irq and __enable_irq for all interrupts.

However, __NVIC_EnableIRQ, unlike a mutex unlock or __enable_irq, had no compiler barriers. Being just a volatile write, in the following code sequence:

NVIC_DisableIRQ(devx);
// modify some RAM accessed by devx IRQ handler
NVIC_EnableIRQ(devx);

there would be nothing preventing the RAM accesses from moved below the NVIC_EnableIRQ.

Add barriers to NVIC_EnableIRQ, so that the above code works the same as a mutex or __disable_irq, without any added need to mark the shared RAM as volatile.

Fixes issue #493

Add a macro to represent a compiler optimisation barrier - memory loads
and stores can not be reordered across this barrier.
__NVIC_DisableIRQ and __NVIC_EnableIRQ can be used to function as a
mutex-style protection lock against a particular interrupt handler,
similar to __disable_irq and __enable_irq for all interrupts.

However, __NVIC_EnableIRQ, unlike a mutex unlock or __enable_irq, had no
compiler barriers. Being just a volatile write, in the following code
sequence:

    NVIC_DisableIRQ(devx);
    // modify some RAM accessed by devx IRQ handler
    NVIC_EnableIRQ(devx);

there would be nothing preventing the RAM accesses from moved below the
NVIC_EnableIRQ.

Add barriers to NVIC_EnableIRQ, so that the above code works the same as
a mutex or __disable_irq, without any added need to mark the shared RAM
as volatile.

Fixes issue ARM-software#493
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding memory barriers improves NVIC_EnableIRQ().

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 11, 2019

What is needed for this PR to progress?

@JonatanAntoni JonatanAntoni merged commit 72210c6 into ARM-software:develop May 9, 2019
@JonatanAntoni JonatanAntoni added DONE and removed review labels May 9, 2019
@kjbracey kjbracey deleted the nvic_irq_barriers branch May 21, 2019 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants