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

cpu/msp430_common: Update to inline-able IRQ API #14362

Merged
merged 2 commits into from
Jul 15, 2020

Conversation

maribu
Copy link
Member

@maribu maribu commented Jun 25, 2020

Contribution description

  • Updated to inline-able IRQ API
  • Improved robustness of functions
    • Added memory barrier to prevent the compiler from moving code outside of
      a critical section guarded by irq_disable() ... irq_restore()
  • Reduced overhead of irq_disable()
    • After clearing the global interrupt enable (GIE) bit, IRQs remain enabled
      for up to one CPU cycle
    • The previous implementation just added a nop to fill that cycle
    • This implementation uses the cycle for masking the return value
  • Reduced overhead of irq_restore()
    • Now only one CPU cycle is needed
  • irq_disable(), irq_restore(), and irq_enable() work now in constant time

Testing procedure

tests/irq_disable_restore

I ran tests/irq_disable_restore on a wsn430-v1_3b board in the FIT/IoT-Lab:

Console output
s
START
main(): This is RIOT! (Version: 2020.07-devel-1557-g22d44-msp430-irq-inline)
Test for irq_disable() / irq_restore()
======================================

Verifying test works: [SUCCESS]
Test result: [SUCCESS]

tests/tests/bench_mutex_pingpong

I ran tests/tests/bench_mutex_pingpong on the same hardware in the FIT/IoT-Lab

Console output with `master`
r
READY
s
START
main(): This is RIOT! (Version: 2020.07-devel-1557-g22d44)
main starting
{ "result" : 9222 }
Console output with this PR
READY
s
START
main(): This is RIOT! (Version: 2020.07-devel-1558-gc5c83-msp430-irq-inline)
main starting
{ "result" : 9910 }

So ~7.5% speedup.

Issues/PRs references

Follow up of: #13999

Tracked in: #14356

- Updated to inline-able IRQ API
- Improved robustness of functions
    - Added memory barrier to prevent the compiler from moving code outside of
      a critical section guarded by irq_disable() ... irq_restore()
- Reduced overhead of `irq_disable()`
    - After clearing the global interrupt enable (GIE) bit, IRQs remain enabled
      for up to one CPU cycle
    - The previous implementation just added a nop to fill that cycle
    - This implementation uses the cycle for masking the return value
- Reduced overhead of `irq_restore()`
    - Now only one CPU cycle is needed
- `irq_disable()`, `irq_restore()`, and `irq_enable()` work now in constant time
@maribu maribu added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Platform: MSP Platform: This PR/issue effects MSP-based platforms Area: cpu Area: CPU/MCU ports labels Jun 25, 2020
@fjmolinas
Copy link
Contributor

I'll test on z1

@aabadie
Copy link
Contributor

aabadie commented Jun 26, 2020

on a wsn430-v1_3b board in the FIT/IoT-Lab:

That might be one of the last experiment on these devices: they are going to be removed during the summer :(

extern "C" {
#endif

extern volatile int __irq_is_in;
Copy link
Contributor

Choose a reason for hiding this comment

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

why is volatile the best choice here?

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO it should not be volatile. But I didn't want to change this, as this not directly related to the API transition.

@kaspar030
Copy link
Contributor

I think this one will conflict a lot with #12457. That'll have to wait until I'm back from vacation, but IMO it would make sense to base this PR on that.

@fjmolinas
Copy link
Contributor

I think this one will conflict a lot with #12457. That'll have to wait until I'm back from vacation, but IMO it would make sense to base this PR on that.

Do the instructions for isr handling change? Where do you see the issues exactly?

@maribu
Copy link
Member Author

maribu commented Jun 26, 2020

I think this one will conflict a lot with #12457.

I just rebased #12457 on top of this PR. These were the conflicts:

  • cpu/msp430_common/include/stdatomic.h
  • boards/chronos/doc.txt
  • boards/chronos/Kconfig
  • tests/gnrc_ipv6_nib/Makefile.ci
  • sys/net/gnrc/transport_layer/tcp/gnrc_tcp_pkt.c

None of them were caused by this PR. (And not was terrible difficult to fix; the first three files have just be removed, the Makefile.ci was trivial, and the gnrc_tcp_pkt.c was just the replacement of abs() with labs(), which can easily be redone on top of the new code.)

@kaspar030
Copy link
Contributor

I just rebased #12457 on top of this PR.

thanks for checking!

@maribu
Copy link
Member Author

maribu commented Jun 26, 2020

Anyway, soft feature freeze in effect since 20 minutes. So I guess this will have to wait until next release :-/

@fjmolinas
Copy link
Contributor

@fjmolinas
Copy link
Contributor

I'm not familiar with the msp430 instruction set, I will need to read on it a bit. But since feautre freeze is in, there is no real urgency :)

Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

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

I've looked at the assembler code and from my understanding looks OK, I had already tested before. With your change there is no usage of __enable_irq() and __disable_irq() is only used in thread_yield_higher, I think those private functions should be removed from cpu/msp430_common/include/cpu.h and the occurrence of __disable_irq replaced by irq_disable().

@fjmolinas
Copy link
Contributor

I've looked at the assembler code and from my understanding looks OK, I had already tested before. With your change there is no usage of __enable_irq() and __disable_irq() is only used in thread_yield_higher, I think those private functions should be removed from cpu/msp430_common/include/cpu.h and the occurrence of __disable_irq replaced by irq_disable().

If you agree that those function should be removed, then please trigger murdock afterwards @maribu!

@maribu maribu added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jul 15, 2020
@fjmolinas
Copy link
Contributor

@maribu Maybe remove those functions in a distinct commit instead of a fixup? We can wait for murdock to finish for that to see if other things pop up.

@maribu
Copy link
Member Author

maribu commented Jul 15, 2020

Some Murdock workers seem to have issues with the network file system right now :-/ Maybe someone from the CI team can take a look?

Drop `__enable_irq()` and `__disable_irq()` and replace single remaining
call of them with the standard IRQ API, as this is now equally fast.
@maribu maribu force-pushed the msp430-irq-inline branch from e87991b to 1a8defd Compare July 15, 2020 11:10
@fjmolinas
Copy link
Contributor

@riot-ci @RIOTCI @aabadie @kaspar030 @cgundogan any ideas what is going on with murdock?

@cgundogan cgundogan added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jul 15, 2020
@cgundogan
Copy link
Member

@riot-ci @RIOTCI @aabadie @kaspar030 @cgundogan any ideas what is going on with murdock?

there was a test server running out of memory. That is removed now from the build queue. I retriggered the affected PRs.

@maribu
Copy link
Member Author

maribu commented Jul 15, 2020

@cgundogan: Thanks! :-)

All green now :-)

Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

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

ACK!

@fjmolinas fjmolinas merged commit 1167867 into RIOT-OS:master Jul 15, 2020
@maribu
Copy link
Member Author

maribu commented Jul 15, 2020

Thanks :-)

@maribu maribu deleted the msp430-irq-inline branch July 15, 2020 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: MSP Platform: This PR/issue effects MSP-based platforms Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants