diff --git a/.github/release-nest-v3 b/.github/release-nest-v3 index d00491f..0cfbf08 100644 --- a/.github/release-nest-v3 +++ b/.github/release-nest-v3 @@ -1 +1 @@ -1 +2 diff --git a/falcond/debian/changelog b/falcond/debian/changelog index fcaa292..699e4b3 100644 --- a/falcond/debian/changelog +++ b/falcond/debian/changelog @@ -1,3 +1,9 @@ +falcond (1.0.6-101pika1) pika; urgency=low + + * Add handheld and htpc profiles, split system processes config to live in the profiles repo for easier updates + + -- ferreo Sun, 12 Jan 2025 13:48:00 +0300 + falcond (1.0.5-101pika1) pika; urgency=low * Fix scx scheduler reactivation + improve info logging - actual fix it this time diff --git a/falcond/debian/rules b/falcond/debian/rules index df3b001..fa7a636 100755 --- a/falcond/debian/rules +++ b/falcond/debian/rules @@ -24,7 +24,7 @@ override_dh_install: chmod 755 debian/falcond/usr/bin/falcond chmod +x debian/falcond/usr/bin/falcond # Copy profiles - cp -r falcond-profiles/usr/share/falcond/profiles debian/falcond/usr/share/falcond/ + cp -r falcond-profiles/usr/share/falcond debian/falcond/usr/share/ override_dh_installsystemd: dh_installsystemd --name=falcond --restart-after-upgrade diff --git a/falcond/src/config/config.zig b/falcond/src/config/config.zig index 3223b00..6c92f8a 100644 --- a/falcond/src/config/config.zig +++ b/falcond/src/config/config.zig @@ -4,32 +4,14 @@ const confloader = @import("confloader.zig"); const vcache_setting = @import("../clients/vcache_setting.zig"); const scx_scheds = @import("../clients/scx_scheds.zig"); -const default_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", - "CrashReportClient.exe", - "Battle.net.exe", - "Agent.exe", +pub const ProfileMode = enum { + none, + handheld, + htpc, +}; + +pub const SystemConfig = struct { + system_processes: []const []const u8 = &[_][]const u8{}, }; pub const Config = struct { @@ -37,10 +19,11 @@ pub const Config = struct { scx_sched: scx_scheds.ScxScheduler = .none, scx_sched_props: ?scx_scheds.ScxSchedModes = null, vcache_mode: vcache_setting.VCacheMode = .none, - system_processes: []const []const u8 = &default_system_processes, + system_processes: []const []const u8 = &[_][]const u8{}, + profile_mode: ProfileMode = .none, arena: ?std.heap.ArenaAllocator = null, - pub fn load(allocator: std.mem.Allocator, path: []const u8) !Config { + pub fn load(allocator: std.mem.Allocator, path: []const u8, system_conf_path: ?[]const u8) !Config { var config = Config{}; const file = fs.openFileAbsolute(path, .{}) catch |err| switch (err) { error.FileNotFound => { @@ -55,6 +38,18 @@ pub const Config = struct { errdefer arena.deinit(); config = try confloader.loadConf(Config, arena.allocator(), path); + if (system_conf_path) |sys_path| { + const system_file = fs.openFileAbsolute(sys_path, .{}) catch |err| switch (err) { + error.FileNotFound => null, + else => return err, + }; + if (system_file) |sf| { + defer sf.close(); + const system_config = try confloader.loadConf(SystemConfig, arena.allocator(), sys_path); + config.system_processes = system_config.system_processes; + } + } + config.arena = arena; return config; } @@ -85,11 +80,6 @@ pub const Config = struct { try file.writer().print("enable_performance_mode = {}\n", .{self.enable_performance_mode}); try file.writer().print("scx_sched = {s}\n", .{@tagName(self.scx_sched)}); try file.writer().print("vcache_mode = {s}\n", .{@tagName(self.vcache_mode)}); - - try file.writer().print("system_processes = [\n", .{}); - for (self.system_processes) |proc| { - try file.writer().print(" \"{s}\",\n", .{proc}); - } - try file.writer().print("]\n", .{}); + try file.writer().print("profile_mode = {s}\n", .{@tagName(self.profile_mode)}); } }; diff --git a/falcond/src/daemon.zig b/falcond/src/daemon.zig index 5abd6f1..31799d1 100644 --- a/falcond/src/daemon.zig +++ b/falcond/src/daemon.zig @@ -11,6 +11,7 @@ const scx_scheds = @import("clients/scx_scheds.zig"); pub const Daemon = struct { allocator: std.mem.Allocator, config_path: []const u8, + system_conf_path: []const u8, profile_manager: ProfileManager, oneshot: bool, known_pids: ?std.AutoHashMap(u32, *const Profile), @@ -22,11 +23,14 @@ pub const Daemon = struct { const Self = @This(); - pub fn init(allocator: std.mem.Allocator, config_path: []const u8, oneshot: bool) !*Self { + pub fn init(allocator: std.mem.Allocator, config_path: []const u8, system_conf_path: []const u8, oneshot: bool) !*Self { const config_path_owned = try allocator.dupe(u8, config_path); errdefer allocator.free(config_path_owned); - const config = try Config.load(allocator, config_path); + const system_conf_path_owned = try allocator.dupe(u8, system_conf_path); + errdefer allocator.free(system_conf_path_owned); + + const config = try Config.load(allocator, config_path, system_conf_path); const power_profiles = try PowerProfiles.init(allocator, config); errdefer power_profiles.deinit(); @@ -36,7 +40,7 @@ pub const Daemon = struct { } var profile_manager = ProfileManager.init(allocator, power_profiles, config); - try ProfileLoader.loadProfiles(allocator, &profile_manager.profiles, &profile_manager.proton_profile, oneshot); + try ProfileLoader.loadProfiles(allocator, &profile_manager.profiles, &profile_manager.proton_profile, oneshot, config.profile_mode); const current_time = std.time.nanoTimestamp(); try scx_scheds.init(allocator); @@ -44,15 +48,16 @@ pub const Daemon = struct { const self = try allocator.create(Self); self.* = .{ .allocator = allocator, + .config_path = config_path_owned, + .system_conf_path = system_conf_path_owned, .profile_manager = profile_manager, .oneshot = oneshot, .known_pids = if (!oneshot) std.AutoHashMap(u32, *const Profile).init(allocator) else null, .power_profiles = power_profiles, .last_profiles_check = current_time, .last_config_check = current_time, - .config = config, - .config_path = config_path_owned, .performance_mode = performance_mode, + .config = config, }; return self; @@ -67,6 +72,7 @@ pub const Daemon = struct { } self.config.deinit(); self.allocator.free(self.config_path); + self.allocator.free(self.system_conf_path); self.allocator.destroy(self); } @@ -83,10 +89,11 @@ pub const Daemon = struct { self.power_profiles.deinit(); self.config.deinit(); - const config = try Config.load(self.allocator, self.config_path); + const config = try Config.load(self.allocator, self.config_path, self.system_conf_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); + try ProfileLoader.loadProfiles(self.allocator, &profile_manager.profiles, &profile_manager.proton_profile, self.oneshot, config.profile_mode); + self.config = config; self.power_profiles = power_profiles; self.performance_mode = self.power_profiles.isPerformanceAvailable(); diff --git a/falcond/src/main.zig b/falcond/src/main.zig index e60b15f..5ebba47 100644 --- a/falcond/src/main.zig +++ b/falcond/src/main.zig @@ -26,6 +26,9 @@ const AllocTracker = struct { } }; +const config_path: []const u8 = "/etc/falcond/config.conf"; +const system_conf_path: []const u8 = "/usr/share/falcond/system.conf"; + fn alloc(ctx: *anyopaque, len: usize, ptr_align: u8, ret_addr: usize) ?[*]u8 { var t: *AllocTracker = @ptrCast(@alignCast(ctx)); t.trackAlloc(); @@ -46,7 +49,6 @@ fn free(ctx: *anyopaque, buf: []u8, log2_buf_align: u8, ret_addr: usize) void { var gpa_vtable: *const std.mem.Allocator.VTable = undefined; var gpa_ptr: *anyopaque = undefined; - pub fn main() !void { std.log.info("Starting falcond...", .{}); @@ -85,8 +87,27 @@ pub fn main() !void { if (std.mem.eql(u8, arg, "--oneshot")) break true; } else false; - var daemon = try Daemon.init(allocator, "/etc/falcond/config.conf", oneshot); + try checkAndUpgradeConfig(allocator, config_path); + + var daemon = try Daemon.init(allocator, config_path, system_conf_path, oneshot); defer daemon.deinit(); try daemon.run(); } + +fn checkAndUpgradeConfig(allocator: std.mem.Allocator, conf_path: []const u8) !void { + const file = std.fs.openFileAbsolute(conf_path, .{}) catch |err| switch (err) { + error.FileNotFound => return, + else => return err, + }; + defer file.close(); + + const content = try file.readToEndAlloc(allocator, std.math.maxInt(usize)); + defer allocator.free(content); + + if (std.mem.indexOf(u8, content, "system_processes = ")) |_| { + std.log.info("Upgrading config file to new format", .{}); + file.close(); + try std.fs.deleteFileAbsolute(config_path); + } +} diff --git a/falcond/src/profile/loader.zig b/falcond/src/profile/loader.zig index e8e0288..fe68169 100644 --- a/falcond/src/profile/loader.zig +++ b/falcond/src/profile/loader.zig @@ -2,8 +2,9 @@ const std = @import("std"); const confloader = @import("../config/confloader.zig"); const types = @import("types.zig"); const Profile = types.Profile; +const ProfileMode = @import("../config/config.zig").ProfileMode; -pub fn loadProfiles(allocator: std.mem.Allocator, profiles: *std.ArrayList(Profile), proton_profile: *?*const Profile, oneshot: bool) !void { +pub fn loadProfiles(allocator: std.mem.Allocator, profiles: *std.ArrayList(Profile), proton_profile: *?*const Profile, oneshot: bool, mode: ProfileMode) !void { if (oneshot) { try profiles.append(Profile{ .name = try allocator.dupe(u8, "Hades3.exe"), @@ -19,7 +20,14 @@ pub fn loadProfiles(allocator: std.mem.Allocator, profiles: *std.ArrayList(Profi proton_profile.* = &profiles.items[1]; } else { - var loaded_profiles = try confloader.loadConfDir(Profile, allocator, "/usr/share/falcond/profiles"); + const base_path = "/usr/share/falcond/profiles"; + const profiles_path = if (mode != .none) + try std.fmt.allocPrint(allocator, "{s}/{s}", .{ base_path, @tagName(mode) }) + else + base_path; + defer if (mode != .none) allocator.free(profiles_path); + + var loaded_profiles = try confloader.loadConfDir(Profile, allocator, profiles_path); defer loaded_profiles.deinit(); try profiles.appendSlice(loaded_profiles.items); @@ -27,11 +35,10 @@ pub fn loadProfiles(allocator: std.mem.Allocator, profiles: *std.ArrayList(Profi for (profiles.items) |*profile| { if (std.mem.eql(u8, profile.name, "Proton")) { proton_profile.* = profile; - std.log.info("Found Proton profile: {s}", .{profile.name}); break; } } - std.log.info("Loaded {d} profiles", .{profiles.items.len}); + std.log.info("Loaded {d} profiles (mode: {s})", .{ profiles.items.len, @tagName(mode) }); } } diff --git a/main.sh b/main.sh index 57e3f34..4bfd456 100755 --- a/main.sh +++ b/main.sh @@ -2,7 +2,7 @@ set -e -VERSION="1.0.5" +VERSION="1.0.6" source ./pika-build-config.sh