Hello.

This patch implements pause for spin locks at two places in the codebase: 
winsup/cygwin/local_includes/cygtls.h and winsup/cygwin/thread.cc 
b/winsup/cygwin/thread.cc.

Radek

---
>From 0f82052a8c60811f784bbc76f6df1e0d9a971947 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Radek=20Barto=C5=88?= <[email protected]>
Date: Thu, 5 Jun 2025 12:41:37 +0200
Subject: [PATCH] Cygwin: implement spinlock pause for AArch64

---
 winsup/cygwin/local_includes/cygtls.h | 4 +++-
 winsup/cygwin/thread.cc               | 4 ++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/local_includes/cygtls.h 
b/winsup/cygwin/local_includes/cygtls.h
index 4698352ae..74ff92971 100644
--- a/winsup/cygwin/local_includes/cygtls.h
+++ b/winsup/cygwin/local_includes/cygtls.h
@@ -242,8 +242,10 @@ public: /* Do NOT remove this public: line, it's a marker 
for gentls_offsets. */
   {
     while (InterlockedExchange (&stacklock, 1))
       {
-#ifdef __x86_64__
+#if defined(__x86_64__)
        __asm__ ("pause");
+#elif defined(__aarch64__)
+       __asm__ ("yield");
 #else
 #error unimplemented for this target
 #endif
diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
index fea6079b8..a504e13b5 100644
--- a/winsup/cygwin/thread.cc
+++ b/winsup/cygwin/thread.cc
@@ -1968,7 +1968,11 @@ pthread_spinlock::lock ()
       else if (spins < FAST_SPINS_LIMIT)
         {
           ++spins;
+#if defined(__x86_64__)
           __asm__ volatile ("pause":::);
+#elif defined(__aarch64__)
+          __asm__ volatile ("yield":::);
+#endif
         }
       else
        {
-- 
2.49.0.vfs.0.3                       

Attachment: 0001-Cygwin-implement-spinlock-pause-for-AArch64.patch
Description: 0001-Cygwin-implement-spinlock-pause-for-AArch64.patch

Reply via email to