From 60b5b85db896a86e42ea7710ff80d48eb9a9f3cd Mon Sep 17 00:00:00 2001 From: Ed_ Date: Thu, 27 Aug 2026 19:32:03 -0400 Subject: [PATCH] 1125064645637738496 --- ...e-up-above-also-https-x-com-sebaaltonen.md | 41 +++++++++++++++++ ...issing-exponential-backoff-for-mm-pause.md | 37 ++++++++++++++++ .../index.md | 44 +++++++++++++++++++ archive/threads/SebAaltonen/index.md | 2 + 4 files changed, 124 insertions(+) create mode 100644 archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two/2019-05-05-AndrewJacksonZA-nice-code-up-above-also-https-x-com-sebaaltonen.md create mode 100644 archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two/2019-05-05-lectem-its-missing-exponential-backoff-for-mm-pause.md create mode 100644 archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two/index.md diff --git a/archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two/2019-05-05-AndrewJacksonZA-nice-code-up-above-also-https-x-com-sebaaltonen.md b/archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two/2019-05-05-AndrewJacksonZA-nice-code-up-above-also-https-x-com-sebaaltonen.md new file mode 100644 index 0000000..cc7ec7f --- /dev/null +++ b/archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two/2019-05-05-AndrewJacksonZA-nice-code-up-above-also-https-x-com-sebaaltonen.md @@ -0,0 +1,41 @@ +--- +title: "@SebAaltonen @stewartmoss , nice code up above." +type: archive +source: twitter +source_url: "https://x.com/AndrewJacksonZA/status/1125101399258353665" +author: "Andrew Jackson" +handle: AndrewJacksonZA +post_id: "1125101399258353665" +date: 2019-05-05 +archived: 2026-08-27 +draft: false +tags: + - archive + - twitter + - SebAaltonen +description: "@SebAaltonen @stewartmoss , nice code up above." +in_reply_to: "" +parent_post_id: "1125067183476944896" +--- + +## Source + +- URL: https://x.com/AndrewJacksonZA/status/1125101399258353665 +- Author: Andrew Jackson (@AndrewJacksonZA) +- Posted: 2019-05-05 18:14:11 + +## Branch + +**1/** **@AndrewJacksonZA** ^1125101399258353665 + +**@SebAaltonen** **@stewartmoss** + +, nice code up above. + +Also: https://x.com/SebAaltonen/status/1125075962524262403 + +/CC @STEMsubsistence and @KeithPlaysPC , because exposure to/learning cool out-of-one's-depth stuff is sometimes extremely valuable. :-) + +## Related + +- Spine: [[archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two]] diff --git a/archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two/2019-05-05-lectem-its-missing-exponential-backoff-for-mm-pause.md b/archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two/2019-05-05-lectem-its-missing-exponential-backoff-for-mm-pause.md new file mode 100644 index 0000000..542f545 --- /dev/null +++ b/archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two/2019-05-05-lectem-its-missing-exponential-backoff-for-mm-pause.md @@ -0,0 +1,37 @@ +--- +title: "@SebAaltonen It's missing exponential backoff for mm_pause though" +type: archive +source: twitter +source_url: "https://x.com/lectem/status/1125076786520514563" +author: "Clément Grégoire" +handle: lectem +post_id: "1125076786520514563" +date: 2019-05-05 +archived: 2026-08-27 +draft: false +tags: + - archive + - twitter + - SebAaltonen +description: "@SebAaltonen It's missing exponential backoff for mm_pause though" +in_reply_to: "" +parent_post_id: "1125067183476944896" +--- + +## Source + +- URL: https://x.com/lectem/status/1125076786520514563 +- Author: Clément Grégoire (@lectem) +- Posted: 2019-05-05 16:36:23 + +## Branch + +**1/** **@lectem** ^1125076786520514563 + +**@SebAaltonen** + +It's missing exponential backoff for mm_pause though + +## Related + +- Spine: [[archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two]] diff --git a/archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two/index.md b/archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two/index.md new file mode 100644 index 0000000..aef9af5 --- /dev/null +++ b/archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two/index.md @@ -0,0 +1,44 @@ +--- +title: "This is how you write a good x64 spinlock: Use two stage construct." +type: archive +source: twitter +source_url: "https://x.com/SebAaltonen/status/1125064645637738496" +author: "Sebastian Aaltonen" +handle: SebAaltonen +post_id: "1125064645637738496" +date: 2019-05-05 +archived: 2026-08-27 +draft: false +tags: + - archive + - twitter + - SebAaltonen +description: "This is how you write a good x64 spinlock: Use two stage construct." +in_reply_to: "" +--- + +## Source + +- URL: https://x.com/SebAaltonen/status/1125064645637738496 +- Author: Sebastian Aaltonen (@SebAaltonen) +- Posted: 2019-05-05 15:48:08 + +## Thread + +**1/** **@SebAaltonen** ^1125064645637738496 + +This is how you write a good x64 spinlock: Use two stage construct. Outer test is read. Multiple cores reading same cache line = no contention. Inner = exchange instead of CAS. Pause instruction in the loop body to save power and/or give all cycles to other logical core (SMT). + +![](https://pbs.twimg.com/media/D50IVH0W0AALQ0y?format=jpg&name=orig) + +**2/** **@SebAaltonen** ^1125065316650889217 + +Don’t use spinlock for waits. Use spinlock only to guard something that is guaranteed to return quickly. If you have an operation that is often fast but sometimes slow, use two stage spinlock with internal OS mutex. + +**3/** **@SebAaltonen** ^1125067183476944896 + +Naive (bad) vs optimized (good) performance. See above post for code. + +![](https://pbs.twimg.com/media/D50Ko4mXoAAR97L?format=jpg&name=orig) + +Branches: [[archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two/2019-05-05-lectem-its-missing-exponential-backoff-for-mm-pause]], [[archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two/2019-05-05-AndrewJacksonZA-nice-code-up-above-also-https-x-com-sebaaltonen]] diff --git a/archive/threads/SebAaltonen/index.md b/archive/threads/SebAaltonen/index.md index 49c1d5f..8c64268 100644 --- a/archive/threads/SebAaltonen/index.md +++ b/archive/threads/SebAaltonen/index.md @@ -9,7 +9,9 @@ tags: - SebAaltonen --- +- [[archive/threads/SebAaltonen/2018-12-29-i-wish-i-was-as-productive-blogger-as-aras-p]] - [[archive/threads/SebAaltonen/2019-01-01-now-that-people-have-already-said-highly]] +- [[archive/threads/SebAaltonen/2019-05-05-this-is-how-you-write-a-good-x64-spinlock-use-two]] - [[archive/threads/SebAaltonen/2022-11-22-ive-long-time-talked-about-killing-the-graphics]] - [[archive/threads/SebAaltonen/2024-04-04-this-is-how-slow-code-feels-like]] - [[archive/threads/SebAaltonen/2024-05-03-why-should-one-be-able-to-code-without]]