diff --git a/bootstrap/compiler.zig b/bootstrap/compiler.zig index 2f4908b..e34978a 100644 --- a/bootstrap/compiler.zig +++ b/bootstrap/compiler.zig @@ -1,4 +1,5 @@ const compiler = @This(); +const configuration = @import("configuration"); const std = @import("std"); const builtin = @import("builtin"); const library = @import("library.zig"); @@ -1309,8 +1310,12 @@ fn control_thread(unit: *Unit) void { iterations_without_work_done += @intFromBool(task_done_this_iteration == 0); - if (iterations_without_work_done > 5) { - std.time.sleep(100); + if (configuration.sleep_on_thread_hot_loops) { + if (iterations_without_work_done > 5) { + std.time.sleep(100); + } + } else { + std.atomic.spinLoopHint(); } } @@ -1580,7 +1585,7 @@ pub fn link(options: LinkerOptions) void { _ = argv.append(object); } - const ci = @import("configuration").ci; + const ci = configuration.ci; switch (builtin.os.tag) { .macos => { _ = argv.append("-dynamic"); @@ -2094,8 +2099,11 @@ fn worker_thread(thread_index: u32, cpu_count: *u32) void { assert(thread.task_system.job.worker.completed == c + 1); } - std.time.sleep(1000); - std.atomic.spinLoopHint(); + if (configuration.sleep_on_thread_hot_loops) { + std.time.sleep(1000); + } else { + std.atomic.spinLoopHint(); + } } } @@ -3943,7 +3951,7 @@ pub const LLVM = struct { pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, return_address: ?usize) noreturn { @setCold(true); - const print_stack_trace = @import("configuration").print_stack_trace; + const print_stack_trace = configuration.print_stack_trace; switch (print_stack_trace) { true => @call(.always_inline, std.builtin.default_panic, .{ message, stack_trace, return_address }), false => { diff --git a/build.zig b/build.zig index a00b837..7a6fb51 100644 --- a/build.zig +++ b/build.zig @@ -30,6 +30,7 @@ pub fn build(b: *std.Build) !void { const use_editor = b.option(bool, "editor", "Use the GUI editor to play around the programming language") orelse (!is_ci and enable_editor); const use_debug = b.option(bool, "use_debug", "This option enables the LLVM debug build in the development PC") orelse false; const sanitize = b.option(bool, "sanitize", "This option enables sanitizers for the compiler") orelse false; + const sleep_on_thread_hot_loops = b.option(bool, "sleep_on_thread_hot_loops", "This option enables sleep calls on hot threaded loops") orelse false; const static = b.option(bool, "static", "This option enables the compiler to be built statically") orelse switch (@import("builtin").os.tag) { else => use_debug, .windows => true, @@ -39,6 +40,7 @@ pub fn build(b: *std.Build) !void { compiler_options.addOption(bool, "print_stack_trace", print_stack_trace); compiler_options.addOption(bool, "ci", is_ci); compiler_options.addOption(bool, "editor", use_editor); + compiler_options.addOption(bool, "sleep_on_thread_hot_loops", sleep_on_thread_hot_loops); const fetcher = b.addExecutable(.{ .name = "llvm_fetcher",