From 07374071d0fa658e5d1482836b7320058eb148bf Mon Sep 17 00:00:00 2001 From: kadmin Date: Thu, 8 Jul 2021 20:55:09 +0000 Subject: [PATCH] net/uring: add probing capability Adds the ability to probe for various capabilities. It will not call into C unless necessary. It also allocates one probe per call to new capability, which may be expensive, so in theory they could be reused instead. Signed-off-by: kadmin --- net/uring/capability_linux.go | 20 ++++++++++++++++++++ net/uring/io_uring_test.go | 11 +++++++++++ 2 files changed, 31 insertions(+) create mode 100644 net/uring/capability_linux.go create mode 100644 net/uring/io_uring_test.go diff --git a/net/uring/capability_linux.go b/net/uring/capability_linux.go new file mode 100644 index 000000000..ea8a96765 --- /dev/null +++ b/net/uring/capability_linux.go @@ -0,0 +1,20 @@ +package uring + +// #cgo CFLAGS: -I${SRCDIR}/liburing/src/include +// #cgo LDFLAGS: -L${SRCDIR}/liburing/src/ -luring +// #include "io_uring.c" +import "C" + +import ( + "syscall" + "unsafe" +) + +// hasUring reports whether it is possible to use io_uring syscalls on the system. +func uringSupported() bool { + probe, err := C.io_uring_get_probe() + if err == nil && probe != nil { + C.free(unsafe.Pointer(probe)) + } + return err != syscall.ENOSYS +} diff --git a/net/uring/io_uring_test.go b/net/uring/io_uring_test.go new file mode 100644 index 000000000..983638e39 --- /dev/null +++ b/net/uring/io_uring_test.go @@ -0,0 +1,11 @@ +// +build linux + +package uring + +import ( + "testing" +) + +func TestUringAvailable(t *testing.T) { + uringSupported() +}