Skip to content

nRF52 serial: Tighten/simplify atomics #9616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2019
Merged

Conversation

kjbracey
Copy link
Contributor

@kjbracey kjbracey commented Feb 5, 2019

Description

Use new atomics (exchange, load, store and bool types) to simplify
and improve the atomics in the nRF52 serial HAL.

  • Ensure mutexes are released last and atomically when done
    done inside a critical section.
  • Compare-and-swap is not required for the spinlock - exchange is
    sufficient. (Not clear a spinlock is needed anyway, but left in).
  • Remove unneeded volatile, and make mutexes bool.

Requires preceding PR #9600.

Pull request type

[ ] Fix
[ ] Refactor
[x] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@marcuschangarm

Use new atomics (exchange, load, store and bool types) to simplify
and improve the atomics in the nRF52 serial HAL.

* Ensure mutexes are released last and atomically when done
  done inside a critical section.
* Compare-and-swap is not required for the spinlock - exchange is
  sufficient. (Not clear a spinlock is needed anyway, but left in).
* Remove unneeded volatile, and make mutexes bool.
@ciarmcom ciarmcom requested review from marcuschangarm and a team February 5, 2019 14:00
@ciarmcom
Copy link
Member

ciarmcom commented Feb 5, 2019

@kjbracey-arm, thank you for your changes.
@marcuschangarm @ARMmbed/mbed-os-maintainers please review.

Copy link
Member

@pan- pan- left a comment

Choose a reason for hiding this comment

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

Changes looks good however I'm concern about the flags tx_async and rx_asynch which are used to determine if a transaction is in progress.

@kjbracey
Copy link
Contributor Author

kjbracey commented Feb 7, 2019

I see what you mean. I was under the impression that the async variables were protected by the in_progress atomic, but that's not really true (any more?), is it? The in_progress is actually only set when it's async anyway.

It might be okay - it's only read by the interrupt handler, and it's written by the async setup code to make it respond differently. As long as it writes to it before enabling interrupts, and the interrupt enable is a memory barrier, you're fine.

But interrupt enables might not be memory barriers: patch coming for that here - ARM-software/CMSIS_5#510

I'm not really sure how much any of this is required - most HALs don't have any sort of protection in this area, and just assume you don't mix async and sync operations, or attempt overlapping async.

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 20, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Feb 20, 2019

Test run: SUCCESS

Summary: 12 of 12 test jobs passed
Build number : 1
Build artifacts

@cmonr
Copy link
Contributor

cmonr commented Feb 22, 2019

cmonr added release-version: 5.12.0-rc1 release-version: 5.11.5 and removed release-version: 5.12.0-rc1 labels a day ago

Ha. Should've known. Preceeding PR was targeting 5.12, so this needs to as well.

@kjbracey kjbracey deleted the nrf52_atomics branch February 22, 2019 08:57
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.

6 participants