[libc-commits] [libc] 8004ce2 - [libc] Move thread sync when closing port earlier

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Thu Apr 4 11:34:58 PDT 2024


Author: Joseph Huber
Date: 2024-04-04T13:34:52-05:00
New Revision: 8004ce236795d48063c636d1ce4818ebcb526b21

URL: https://github.com/llvm/llvm-project/commit/8004ce236795d48063c636d1ce4818ebcb526b21
DIFF: https://github.com/llvm/llvm-project/commit/8004ce236795d48063c636d1ce4818ebcb526b21.diff

LOG: [libc] Move thread sync when closing port earlier

Summary:
This synchronization should be done before we handle the logic relating
to closing the port. This isn't majorly important now but it would break
if we ever decided to run a server on the GPU.

Added: 
    

Modified: 
    libc/src/__support/RPC/rpc.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/RPC/rpc.h b/libc/src/__support/RPC/rpc.h
index 5dcae518bb6f8f..05506c04fc0791 100644
--- a/libc/src/__support/RPC/rpc.h
+++ b/libc/src/__support/RPC/rpc.h
@@ -198,12 +198,9 @@ template <bool Invert> struct Process {
   /// convergent, otherwise the compiler will sink the store and deadlock.
   [[clang::convergent]] LIBC_INLINE void unlock(uint64_t lane_mask,
                                                 uint32_t index) {
-    // Do not move any writes past the unlock
+    // Do not move any writes past the unlock.
     atomic_thread_fence(cpp::MemoryOrder::RELEASE);
 
-    // Wait for other threads in the warp to finish using the lock
-    gpu::sync_lane(lane_mask);
-
     // Use exactly one thread to clear the nth bit in the lock array Must
     // restrict to a single thread to avoid one thread dropping the lock, then
     // an unrelated warp claiming the lock, then a second thread in this warp
@@ -331,6 +328,9 @@ template <bool T> struct Port {
   LIBC_INLINE uint16_t get_index() const { return index; }
 
   LIBC_INLINE void close() {
+    // Wait for all lanes to finish using the port.
+    gpu::sync_lane(lane_mask);
+
     // The server is passive, if it own the buffer when it closes we need to
     // give ownership back to the client.
     if (owns_buffer && T)


        


More information about the libc-commits mailing list