Make sleep calls optional and disabled by default

This commit is contained in:
David Gonzalez Martin 2024-05-23 20:24:28 -06:00
parent 8713de03d3
commit e4dd1bb7b9
2 changed files with 16 additions and 6 deletions

View File

@ -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,9 +1310,13 @@ fn control_thread(unit: *Unit) void {
iterations_without_work_done += @intFromBool(task_done_this_iteration == 0);
if (configuration.sleep_on_thread_hot_loops) {
if (iterations_without_work_done > 5) {
std.time.sleep(100);
}
} else {
std.atomic.spinLoopHint();
}
}
var objects = PinnedArray([]const u8){};
@ -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,9 +2099,12 @@ fn worker_thread(thread_index: u32, cpu_count: *u32) void {
assert(thread.task_system.job.worker.completed == c + 1);
}
if (configuration.sleep_on_thread_hot_loops) {
std.time.sleep(1000);
} else {
std.atomic.spinLoopHint();
}
}
}
fn llvm_get_value(thread: *Thread, value: *Value) *LLVM.Value {
@ -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 => {

View File

@ -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",