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

SpinLock: Overhaul false sharing prevention #99168

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

RandomShaper
Copy link
Member

@RandomShaper RandomShaper commented Nov 13, 2024

This changes how false sharing in SpinLock is prevented. Formerly, alignment attributes were used. The problem with that is objects containing SpinLocks could be allocated in a way that the alignment is not honored, leading to crashes.

This PR also applies the new approach to the Apple implementation.

This approach could be refactored into a more general one that we may want to use in other sync primitives. However, the point is now to fix the only case we have at the moment.

Fixes crashes stated in #85167 (comment).

Bugsquad edit:

@RandomShaper RandomShaper added this to the 4.4 milestone Nov 13, 2024
@RandomShaper RandomShaper requested a review from a team as a code owner November 13, 2024 09:37
@RandomShaper
Copy link
Member Author

@yretenai, following up here. Could you please test this one?

@RandomShaper RandomShaper force-pushed the even_better_spinlock branch 3 times, most recently from 058a1f8 to 5eb30dd Compare November 13, 2024 09:46
@RandomShaper RandomShaper force-pushed the even_better_spinlock branch 3 times, most recently from 557c73e to 67737d5 Compare November 13, 2024 11:06
@RandomShaper
Copy link
Member Author

1000 force-pushes later... 😅

@yretenai
Copy link

yretenai commented Nov 13, 2024

AVX2 and AVX512 builds are fixed with this patchset. Please check if performance is improved or degraded with the new cacheline stuff.

@RandomShaper
Copy link
Member Author

@Calinou, could you please give this a go?

@RandomShaper RandomShaper added the cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release label Dec 6, 2024
@RandomShaper
Copy link
Member Author

Tested myself. Performance stays compared to prior to this PR, noise aside.

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

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

Code looks good to me.

@Repiteo Repiteo merged commit da8b9ba into godotengine:master Dec 9, 2024
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Dec 9, 2024

Thanks!

@RandomShaper
Copy link
Member Author

Still, for the records, we would really like to be able to rely on alignment and base this on it. @hpvb is looking into making Godot allocation aware of alignment.

@hpvb
Copy link
Member

hpvb commented Dec 12, 2024

@RandomShaper I'll make a pr for memory.cpp/h asap. It should be a relatively small fix.

@akien-mga akien-mga added regression and removed cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release labels Jan 30, 2025
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.

32-bit builds of Godot do not work with LLVM MinGW
6 participants