Update libxev to use dynamic backend, support Linux configurability

Related to #3224

Previously, Ghostty used a static API for async event handling: io_uring
on Linux, kqueue on macOS. This commit changes the backend to be dynamic
on Linux so that epoll will be used if io_uring isn't available, or if
the user explicitly chooses it.

This introduces a new config `async-backend` (default "auto") which can
be set by the user to change the async backend in use. This is a
best-effort setting: if the user requests io_uring but it isn't
available, Ghostty will fall back to something that is and that choice
is up to us.

Basic benchmarking both in libxev and Ghostty (vtebench) show no
noticeable performance differences introducing the dynamic API, nor
choosing epoll over io_uring.
This commit is contained in:
Mitchell Hashimoto
2025-02-20 21:38:49 -08:00
parent 38908e0126
commit d532a6e260
19 changed files with 95 additions and 29 deletions

View File

@@ -14,7 +14,7 @@ pub const Thread = @This();
const std = @import("std");
const ArenaAllocator = std.heap.ArenaAllocator;
const builtin = @import("builtin");
const xev = @import("xev");
const xev = @import("../global.zig").xev;
const crash = @import("../crash/main.zig");
const termio = @import("../termio.zig");
const renderer = @import("../renderer.zig");
@@ -189,7 +189,7 @@ pub fn threadMain(self: *Thread, io: *termio.Termio) void {
// If our loop is not stopped, then we need to keep running so that
// messages are drained and we can wait for the surface to send a stop
// message.
if (!self.loop.flags.stopped) {
if (!self.loop.stopped()) {
log.warn("abrupt io thread exit detected, starting xev to drain mailbox", .{});
defer log.debug("io thread fully exiting after abnormal failure", .{});
self.flags.drain = true;