From 9decaf13e49a26d0a9ba69be63e3014a09b512dd Mon Sep 17 00:00:00 2001 From: ferreo Date: Tue, 14 Jan 2025 23:29:06 +0000 Subject: [PATCH] Minor fix for race condition during profile reloadings --- .github/release-nest-v3 | 2 +- falcond/debian/changelog | 6 ++++++ falcond/src/daemon.zig | 16 ++++++++++------ falcond/src/profile/manager.zig | 19 ++++++++++++++++++- falcond/src/profile/matcher.zig | 26 -------------------------- 5 files changed, 35 insertions(+), 34 deletions(-) diff --git a/.github/release-nest-v3 b/.github/release-nest-v3 index d8263ee..56a6051 100644 --- a/.github/release-nest-v3 +++ b/.github/release-nest-v3 @@ -1 +1 @@ -2 \ No newline at end of file +1 \ No newline at end of file diff --git a/falcond/debian/changelog b/falcond/debian/changelog index 8cab8fa..243dd36 100644 --- a/falcond/debian/changelog +++ b/falcond/debian/changelog @@ -1,3 +1,9 @@ +falcond (1.0.2-101pika1) pika; urgency=low + + * Minor fix for race condition during profile reloadings + + -- ferreo Sun, 12 Jan 2025 13:48:00 +0300 + falcond (1.0.1-101pika5) pika; urgency=low * Add config and profile autowatching + config for proton system files diff --git a/falcond/src/daemon.zig b/falcond/src/daemon.zig index 6f92a80..5abd6f1 100644 --- a/falcond/src/daemon.zig +++ b/falcond/src/daemon.zig @@ -75,17 +75,21 @@ pub const Daemon = struct { map.clearRetainingCapacity(); } - const config = try Config.load(self.allocator, self.config_path); - const power_profiles = try PowerProfiles.init(self.allocator, config); + if (self.profile_manager.active_profile != null) { + try self.profile_manager.unloadProfile(self.profile_manager.active_profile.?); + } + + self.profile_manager.deinit(); self.power_profiles.deinit(); self.config.deinit(); + + const config = try Config.load(self.allocator, self.config_path); + const power_profiles = try PowerProfiles.init(self.allocator, config); + var profile_manager = ProfileManager.init(self.allocator, power_profiles, config); + try ProfileLoader.loadProfiles(self.allocator, &profile_manager.profiles, &profile_manager.proton_profile, self.oneshot); self.config = config; self.power_profiles = power_profiles; self.performance_mode = self.power_profiles.isPerformanceAvailable(); - - var profile_manager = ProfileManager.init(self.allocator, power_profiles, config); - try ProfileLoader.loadProfiles(self.allocator, &profile_manager.profiles, &profile_manager.proton_profile, self.oneshot); - self.profile_manager.deinit(); self.profile_manager = profile_manager; } diff --git a/falcond/src/profile/manager.zig b/falcond/src/profile/manager.zig index 828eec1..9362f6d 100644 --- a/falcond/src/profile/manager.zig +++ b/falcond/src/profile/manager.zig @@ -34,7 +34,7 @@ pub const ProfileManager = struct { std.log.err("Failed to deactivate profile: {}", .{err}); }; } - + for (self.profiles.items) |profile| { self.allocator.free(profile.name); } @@ -97,6 +97,23 @@ pub const ProfileManager = struct { } } + pub fn unloadProfile(self: *ProfileManager, profile: *const Profile) !void { + if (self.active_profile) |active| { + if (active == profile) { + std.log.info("Unloading profile: {s}", .{profile.name}); + + if (profile.performance_mode and self.power_profiles.isPerformanceAvailable()) { + std.log.info("Disabling performance mode for profile: {s}", .{profile.name}); + self.power_profiles.disablePerformanceMode(); + } + + vcache_setting.applyVCacheMode(.none); + try scx_scheds.deactivateScheduler(self.allocator); + self.active_profile = null; + } + } + } + pub fn matchProcess(self: *ProfileManager, arena: std.mem.Allocator, pid: []const u8, process_name: []const u8) !?*const Profile { return matcher.matchProcess(self.profiles.items, self.proton_profile, arena, pid, process_name, self.config); } diff --git a/falcond/src/profile/matcher.zig b/falcond/src/profile/matcher.zig index 31adf83..999d348 100644 --- a/falcond/src/profile/matcher.zig +++ b/falcond/src/profile/matcher.zig @@ -3,32 +3,6 @@ const types = @import("types.zig"); const Profile = types.Profile; const Config = @import("../config/config.zig").Config; -// Don't match Wine/Proton infrastructure -// const system_processes = [_][]const u8{ -// "steam.exe", -// "services.exe", -// "winedevice.exe", -// "plugplay.exe", -// "svchost.exe", -// "explorer.exe", -// "rpcss.exe", -// "tabtip.exe", -// "wineboot.exe", -// "rundll32.exe", -// "iexplore.exe", -// "conhost.exe", -// "crashpad_handler.exe", -// "iscriptevaluator.exe", -// "VC_redist.x86.exe", -// "VC_redist.x64.exe", -// "cmd.exe", -// "REDEngineErrorReporter.exe", -// "REDprelauncher.exe", -// "SteamService.exe", -// "UnityCrashHandler64.exe", -// "start.exe", -// }; - pub fn isProtonParent(arena: std.mem.Allocator, pid: []const u8) !bool { var path_buf: [std.fs.max_path_bytes]u8 = undefined; const status_path = try std.fmt.bufPrint(&path_buf, "/proc/{s}/status", .{pid});