[libc-commits] [libc] [libc] Scan the ports more fairly in the RPC server (PR #66680)

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Tue Sep 19 05:19:31 PDT 2023


================
@@ -560,9 +562,9 @@ template <uint16_t opcode> LIBC_INLINE Client::Port Client::open() {
 template <uint32_t lane_size>
 [[clang::convergent]] LIBC_INLINE
     cpp::optional<typename Server<lane_size>::Port>
-    Server<lane_size>::try_open() {
+    Server<lane_size>::try_open(uint32_t start) {
   // Perform a naive linear scan for a port that has a pending request.
-  for (uint32_t index = 0; index < process.port_count; ++index) {
+  for (uint32_t index = start; index < process.port_count; ++index) {
----------------
jhuber6 wrote:

I wanted to make sure that `handle_server` runs a fixed amount of times because we use the user thread to check it. This prevents the situation where some other kernel's RPC calls perpetually block a user's thread from finishing, e.g.
```
while (!kernel.done)
   server.handle_server() // Could pick up work from other async kernels.
```

I haven't yet introduced sleeping to the busy-wait in OpenMP, which would then probably not want to increase a sleep duration if we just finished a full scan or something.

https://github.com/llvm/llvm-project/pull/66680


More information about the libc-commits mailing list