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/esp*: memory clobbers required for irq_* functions #11571

Closed
gschorcht opened this issue May 24, 2019 · 5 comments
Closed

cpu/esp*: memory clobbers required for irq_* functions #11571

gschorcht opened this issue May 24, 2019 · 5 comments
Assignees
Labels
Area: cpu Area: CPU/MCU ports Platform: ESP Platform: This PR/issue effects ESP-based platforms State: stale State: The issue / PR has no activity for >185 days Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Comments

@gschorcht
Copy link
Contributor

Description

Based on discussions in PR #11440 it became clear that it might be also necessary for ESP architecture to add memory barriers to __asm__ volatile statements in irq_* functions.

@gschorcht gschorcht added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Platform: ESP Platform: This PR/issue effects ESP-based platforms Area: cpu Area: CPU/MCU ports labels May 24, 2019
@gschorcht gschorcht self-assigned this May 24, 2019
@jcarrano
Copy link
Contributor

Why? If for some code it is necessary to place a barrier, why not be explicit and place the barrier only where it is needed?

@kaspar030
Copy link
Contributor

kaspar030 commented May 28, 2019

Why? If for some code it is necessary to place a barrier, why not be explicit and place the barrier only where it is needed?

The reason is that irq_*() is used to protect critical sections. The barriers are necessary to prevent the compiler from re-ordering memory orders load/stores over the critical section start/end.

Conceived example:

void list_add(list, new_node) {
  irq_disable();
  while (list->next) { list = list->next;}
  list->next = new_node;
  new_node = NULL;
  irq_restore();
}

Without a memory barrier in irq_restore(), the compiler is (theoretically) free to move the store in list->next = new_node after irq_restore().
If it does that, a parallel list_add(list, other_node) in an ISR or higher priority thread might get scheduled right after irq_restore(), write other_node at the the same position that then gets overwritten.

A lot of code in RIOT depends on this not happening, thus the need for barriers.

@stale
Copy link

stale bot commented Nov 29, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Nov 29, 2019
@gschorcht gschorcht removed the State: stale State: The issue / PR has no activity for >185 days label Nov 29, 2019
@gschorcht
Copy link
Contributor Author

This will be fixed with code deduplication in PR #12955 .

@stale
Copy link

stale bot commented Jun 18, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Jun 18, 2020
@stale stale bot closed this as completed Jul 19, 2020
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 Platform: ESP Platform: This PR/issue effects ESP-based platforms State: stale State: The issue / PR has no activity for >185 days Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

No branches or pull requests

3 participants