Skip to content

nanostack-hal: add alternative critical section implementation #6185

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

Conversation

TeroJaasko
Copy link
Contributor

Description

(This PR has the same content as already merged https://github.com/ARMmbed/mbed-os-confidential-m/pull/8 and
#5754, only the target branch differs)

The nanostack hal's critical section uses a mutex for mutual exclusion,
which is nice for many use cases. But when one needs to use the critical
section from interrupts, the RTX will have a assertion failure and panic.

Add a configurable for mbed_lib, which can be used to enable a alternative
version of critical section, which uses the underlying OS primitives, which
disables the interrupts.

Note: the default behavior is not changed, one needs to override the
"nanostack-hal.critical-section-usable-from-interrupt" to have "true".

Reason for this change is that there is a need for sending events using
nanostack event queue from interrupt context, eg. from a socket callback.

Status

READY

Migrations

YES | NO

Related PRs

Todos

  • Tests
  • Documentation

Deploy notes

Note: this should not be the first and/or only fix, as it may cause troubles on drivers which can not tolerate delays on interrupt deliveries.

Steps to test or reproduce

K64F with ESP8266, debug profile:
"Mutex 0x200017ec error -6: Not allowed in ISR context"

kjbracey
kjbracey previously approved these changes Feb 26, 2018
Copy link
Contributor

@kjbracey kjbracey left a comment

Choose a reason for hiding this comment

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

Fine with the change - just wondering if a little more of the big comment, or a pointer to it, should be in the JSON help. That makes no mention of any downside.

@TeroJaasko
Copy link
Contributor Author

Would something like this be better?
"Make critical section API usable from interrupt context. Else a mutex is used as locking primitive. Consult arm_hal_interrupt.c for possible side effects on interrupt latency."

@kjbracey
Copy link
Contributor

I think that's reasonable. Can't really write an essay in there.

The nanostack hal's critical section uses a mutex for mutual exclusion,
which is nice for many use cases. But when one needs to use the critical
section from interrupts, the RTX will have a assertion failure and panic.

Add a configurable for mbed_lib, which can be used to enable a alternative
version of critical section, which uses the underlying OS primitives, which
disables the interrupts.

Note: the default behavior is not changed, one needs to override the
"nanostack-hal.critical-section-usable-from-interrupt" to have "true".

Reason for this change is that there is a need for sending events using
nanostack event queue from interrupt context, eg. from a socket callback.
@TeroJaasko TeroJaasko force-pushed the ns_hal_critical_section_changes_to_master branch from 5643dea to 7bfcf69 Compare February 26, 2018 10:32
@TeroJaasko
Copy link
Contributor Author

Fixed the JSON documentation. It is unfortunate that help in JSON string needs to be a one line inside quotes.

@0xc0170
Copy link
Contributor

0xc0170 commented Feb 26, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Feb 26, 2018

Build : SUCCESS

Build number : 1261
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/6185/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented Feb 26, 2018

@mbed-ci
Copy link

mbed-ci commented Feb 26, 2018

@cmonr
Copy link
Contributor

cmonr commented Feb 27, 2018

/morph export-build

@mbed-ci
Copy link

mbed-ci commented Feb 27, 2018

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