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

Add cacheline-alignment to compiler/threading and switch from volatile to std::atomic #1005

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

blonded04
Copy link

Refactor compiler/threading:

  • Switch to std::atomic instead of volatile
  • Use alignas to cache-align shared structs
  • Use proper memory orderings instead of default seq_cst

Signed-off-by: Valery Matskevich <[email protected]>
Signed-off-by: Valery Matskevich <[email protected]>
Copy link
Contributor

@mkornaukhov03 mkornaukhov03 left a comment

Choose a reason for hiding this comment

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

Please, do not break blame

compiler/threading/tls.h Outdated Show resolved Hide resolved
runtime/critical_section.cpp Outdated Show resolved Hide resolved
compiler/threading/hash-table.h Outdated Show resolved Hide resolved

HTNode *at(unsigned long long hash) {
int i = (unsigned)hash % (unsigned)N;
while (true) {
while (nodes[i].hash != 0 && nodes[i].hash != hash) {
while (nodes[i].hash.load(std::memory_order_acquire) != 0 && nodes[i].hash.load(std::memory_order_relaxed) != hash) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why second read is relaxed?

Copy link
Author

@blonded04 blonded04 May 25, 2024

Choose a reason for hiding this comment

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

because it won't be reordered between nodes[i].hash.load(std::memory_order_acquire) before and nodes[i].hash.load(std::memory_order_acquire) after, the only barrier needed here is load-load, which is imposed by reading node hash

Signed-off-by: Valery Matskevich <[email protected]>
Signed-off-by: Valery Matskevich <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants