Skip to content
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

Assembler atomics #10147

Merged
merged 4 commits into from
May 13, 2019
Merged

Assembler atomics #10147

merged 4 commits into from
May 13, 2019

Conversation

kjbracey
Copy link
Contributor

@kjbracey kjbracey commented Mar 18, 2019

Description

Reimplement atomic code in inline assembly. This can improve optimisation, and avoids potential architectural problems with using LDREX/STREX intrinsics.

API further extended:

  • Bitwise operations (fetch_and/fetch_or/fetch_xor)
  • fetch_add and fetch_sub (like incr/decr, but returning old value - aligning with C++11)
  • compare_exchange_weak
  • Explicit memory order specification
  • Basic freestanding template overloads for C++

This gives our existing C implementation essentially all the functionality needed by C++11.

An actual Atomic<T> template based upon these C functions could follow.

Preliminary work for #10104.

Pull request type

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

Release Notes

  • Atomic APIs separated into mbed_atomic.h from mbed_critical.h. Code not including mbed.h may need to to check their includes.
  • Atomic fetch_add, fetch_sub, fetch_and, fetch_or, fetch_xor and compare_exchange_weak operations added.
  • Explicit memory ordering specification added (don't use unless familiar with C++11 memory model)
  • Freestanding atomic function templates added.

@ciarmcom ciarmcom requested review from a team March 18, 2019 16:01
@ciarmcom
Copy link
Member

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

@kjbracey
Copy link
Contributor Author

I'm now looking at a full rework here, which will reduce the source size and turn it into assembler, with the possibility of better code generation.

@kjbracey
Copy link
Contributor Author

Will close temporarily.

@kjbracey kjbracey closed this Mar 20, 2019
@kjbracey kjbracey reopened this Mar 25, 2019
@kjbracey kjbracey changed the title Atomic bitwise operations Assembler atomics Mar 25, 2019
@cmonr
Copy link
Contributor

cmonr commented Mar 25, 2019

Hmm, this got nicked with the Astyle update bork.

Incoming fix from: #10221

@cmonr
Copy link
Contributor

cmonr commented Mar 26, 2019

Hmm... The astyle fix is missing this fix: #10222

@NirSonnenschein
Copy link
Contributor

@kjbracey-arm please re-base when you have time, it should resolve the astyle issue

@mbed-ci
Copy link

mbed-ci commented Apr 25, 2019

Test run: FAILED

Summary: 3 of 7 test jobs failed
Build number : 6
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-GCC_ARM
  • jenkins-ci/mbed-os-ci_build-IAR
  • jenkins-ci/mbed-os-ci_build-ARM

@adbridge
Copy link
Contributor

@kjbracey-arm Please look at test failures

Reimplement atomic code in inline assembly. This can improve
optimisation, and avoids potential architectural problems with using
LDREX/STREX intrinsics.

API further extended:
* Bitwise operations (fetch_and/fetch_or/fetch_xor)
* fetch_add and fetch_sub (like incr/decr, but returning old value -
  aligning with C++11)
* compare_exchange_weak
* Explicit memory order specification
* Basic freestanding template overloads for C++

This gives our existing C implementation essentially all the functionality
needed by C++11.

An actual Atomic<T> template based upon these C functions could follow.
These are platform tests, but rely on the RTOS to run multiple threads
to exercise it.

(The atomics are still useful in non-RTOS, to protect against interrupt
handlers, but testing versus other threads is easier. The implementation
is the same either way, so doesn't seem worth testing non-RTOS
specifically).
Get rid of a volatile, and use atomics to synchronise with the interrupt
routine instead.

Useful as a non-RTOS basic compilation check for the atomics - the
fuller atomic test relies on the RTOS.
Volatile makes no real difference when we're using assembler, or locked
functions, but leaving it off could be more efficient for the basic
loads and stores. So add non-volatile overloads in C++ for them.
@kjbracey
Copy link
Contributor Author

Thought I'd done enough fork tests to find all the glitches, but apparently not.

Fixed the flash_api.c build failure there for LPC55S69_NS. Didn't see anything else.

@adbridge
Copy link
Contributor

@ARMmbed/mbed-os-core Could somebody please review this ?

@0xc0170
Copy link
Contributor

0xc0170 commented May 2, 2019

@ARMmbed/mbed-os-core Could somebody please review this ?

@donatieng @bulislaw Can you help reviewing these?

@0xc0170 0xc0170 requested review from donatieng and bulislaw May 2, 2019 14:02
Copy link
Member

@bulislaw bulislaw left a comment

Choose a reason for hiding this comment

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

Looks good, but to be fair I didn't dive into the implementation file.

@adbridge
Copy link
Contributor

adbridge commented May 7, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented May 7, 2019

Test run: FAILED

Summary: 2 of 11 test jobs failed
Build number : 7
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_dynamic-memory-usage
  • jenkins-ci/mbed-os-ci_greentea-test

@0xc0170
Copy link
Contributor

0xc0170 commented May 10, 2019

CI restarted (py3 problem should be gone now)

@mbed-ci
Copy link

mbed-ci commented May 10, 2019

Test run: FAILED

Summary: 1 of 11 test jobs failed
Build number : 8
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_exporter

@0xc0170
Copy link
Contributor

0xc0170 commented May 12, 2019

Exporters restarted

@0xc0170 0xc0170 merged commit 3ea1c56 into ARMmbed:master May 13, 2019
@kjbracey kjbracey deleted the atomic_bitwise branch May 14, 2019 08:38
@SanaMasood
Copy link

SanaMasood commented May 16, 2019

Build errors in mbed-os tests with ARMC5 toolchain started to come from 13th of May.
Seems like this pull request(#10147) is breaking everything. Build error started to appear in this file 'mbed_atomic_impl.h' with ARMC5 toolchain.

Can you please check why this pull request is effecting the build? and they seem related too!

[DEBUG] Output: "./mbed-os/platform/internal/mbed_atomic_impl.h", line 306: Error: #52: expected a macro parameter name
[DEBUG] Output: "./mbed-os/platform/internal/mbed_atomic_impl.h", line 498: Warning: #3732-D: use of this instruction in inline assembler is deprecated
[DEBUG] Output: "./mbed-os/platform/internal/mbed_atomic_impl.h", line 498: Error: #3081: expected end of line or a ";"

The build was passing on May 13, 2019 2:06:40 AM but after that it failed on May 13, 2019 2:43 PM (UK time)

@kjbracey
Copy link
Contributor Author

@SanaMasood - thanks for notification, I've made a PR for the fix.

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.

9 participants