Merge pull request #1192 from ludovic111/perf/linux-helpers-behind

🤖 Agent: merged after integration wave 2 on the desktop (integ/w2 @ 38307d15): fmt, clippy, workspace + launcher tests, release build and every affected parity harness pass. main merged into the branch with the same resolution as the tested tree; verify passes on that head.
This commit is contained in:
Ludovic Marie
2026-10-22 15:21:27 +02:00
committed by GitHub
4 changed files with 20 additions and 20 deletions
+4 -4
View File
@@ -12949,10 +12949,10 @@ pub fn run() -> Result<()> {
if options.dedicated.is_some() && !dedicated::preflight(&mut options)? {
return Ok(());
}
if options.dedicated.is_some() {
// Before any worker starts: on Linux they go behind the server thread.
horizon_threads::put_helpers_behind();
} else {
// Before any worker starts: on Linux they go behind the server thread
// and the render thread.
horizon_threads::put_helpers_behind();
if options.dedicated.is_none() {
// The render thread, like the server thread, ahead of the workers on
// macOS and Windows. While terrain loads, the worker pools (two with
// single player's server thread) and other programs outnumber the
+1 -1
View File
@@ -778,7 +778,7 @@ fn play(c: Connection, shared: &Arc<Shared>, parts: Parts, address: std::net::So
std::thread::Builder::new()
.name(format!("horizon-lan-out-{conn_id}"))
.spawn(move || {
// A dedicated server's tick comes first (horizon_threads).
// Ticks and frames come first (horizon_threads).
horizon_threads::behind_server();
write_loop(writer, rx, alive, latency, pending)
})
+1 -1
View File
@@ -436,7 +436,7 @@ impl Streaming {
thread::Builder::new()
.name(format!("horizon-worker-{i}"))
.spawn(move || {
// A dedicated server's tick comes first (horizon_threads).
// Ticks and frames come first (horizon_threads).
horizon_threads::behind_server();
let mut worker = generator.worker();
// The face visibility table and its occlusion cache stay with
+14 -14
View File
@@ -41,30 +41,30 @@ fn favour() -> bool {
false
}
/// Set once by a dedicated server, before its helper threads start: they
/// then go behind its server thread (`behind_server`).
/// Set once as the game starts, before its helper threads do: they then go
/// behind the server thread and the render thread (`behind_server`).
static HELPERS_BEHIND: AtomicBool = AtomicBool::new(false);
/// How many nice levels a helper thread goes below the process on Linux.
#[cfg(target_os = "linux")]
const BEHIND: i32 = 10;
/// A dedicated server: from now on, the helper threads that call
/// `behind_server` as they start go behind the server thread. Call it
/// before they start.
/// From now on, the helper threads that call `behind_server` as they start
/// go behind the server thread (a dedicated server's or single player's)
/// and the render thread. Call it before they start.
pub fn put_helpers_behind() {
HELPERS_BEHIND.store(true, Ordering::Relaxed);
}
/// Called by a helper thread as it starts (world generation and lighting,
/// a connection's packet writer): work the tick never waits for. In a
/// dedicated server (`put_helpers_behind`) on Linux, where the server thread
/// can't be raised (`favour_current`), the helper lowers itself instead,
/// which an unprivileged thread may: 10 nice levels below the process, or,
/// where nice runs out (a server started under nice 10 or more), the idle
/// class, which runs the thread only when no ordinary thread wants its core.
/// The server thread then gets a core when its tick starts instead of
/// waiting behind them. Nothing elsewhere. Whether the OS took it.
/// Called by a helper thread as it starts (world generation, lighting and
/// meshing, a connection's packet writer): work no tick or frame waits for.
/// Once `put_helpers_behind` was called, on Linux, where the server and
/// render threads can't be raised (`favour_current`), the helper lowers
/// itself instead, which an unprivileged thread may: 10 nice levels below
/// the process, or, where nice runs out (a game started under nice 10 or
/// more), the idle class, which runs the thread only when no ordinary thread
/// wants its core. A tick or a frame then gets a core when it starts instead
/// of waiting behind them. Nothing elsewhere. Whether the OS took it.
pub fn behind_server() -> bool {
HELPERS_BEHIND.load(Ordering::Relaxed) && behind()
}