[libc-commits] [libc] [libc] Export the RPC interface from `libc` (PR #71432)

Jon Chesterfield via libc-commits libc-commits at lists.llvm.org
Thu Nov 9 09:53:33 PST 2023


================
@@ -1,15 +1,41 @@
+def RPCPortT : NamedType<"rpc_port_t">;
+def RPCPortPtrT : PtrType<RPCPortT>;
+def RPCBufferT : NamedType<"rpc_buffer_t">;
+def RPCBufferPtrT : PtrType<RPCBufferT>;
+def RPCCallbackT : NamedType<"rpc_callback_t">;
+
 def GPUExtensions : StandardSpec<"GPUExtensions"> {
   HeaderSpec RPC = HeaderSpec<
     "gpu/rpc.h",
     [], // Macros
-    [], // Types
+    [RPCPortT, RPCBufferT,  RPCCallbackT, SizeTType], // Types
     [], // Enumerations
     [
         FunctionSpec<
             "rpc_host_call",
             RetValSpec<VoidType>,
             [ArgSpec<VoidPtr>, ArgSpec<VoidPtr>, ArgSpec<SizeTType>]
         >,
+        FunctionSpec<
+            "rpc_open_port",
+            RetValSpec<RPCPortT>,
+            [ArgSpec<UnsignedIntType>]
+        >,
+        FunctionSpec<
+            "rpc_send",
+            RetValSpec<VoidType>,
----------------
JonChesterfield wrote:

No error codes. It is fundamentally crucial that these functions do not and can not fail.

This permits implementing arbitrary functions that execute across the two machines with exactly the interface they have on one machine. No extra integer value to mean "network failed", no replacing double return types with a pair of double and boolean, no extra global variable named rpcerrno that people are supposed to check.

This trickery relative to the usual RPC problem of messing up the interfaces works because communication on a shared memory machine only fails when the whole machine has fallen over, which is non-recoverable, and each function does not dynamically allocate a resource that can fail.

At least by design - in practice we may currently be undersizing the ports structure to guarantee progress in the worst case scheduling, but if so that's fixable by making N large enough for a given machine. The cost is order of a few megabytes of memory which in the scheme of things doesn't matter for a singleton.

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


More information about the libc-commits mailing list