From 9776acfa1d4861ab20d1d6ca8678995cd4c23b79 Mon Sep 17 00:00:00 2001 From: William Edwards Date: Fri, 10 Nov 2023 20:34:29 -0800 Subject: [PATCH] chore(Performance): remove unnecessary components --- core/systems/hardware/cpu.gd | 116 ------------- core/systems/hardware/cpu_core.gd | 32 +--- core/systems/hardware/cpu_test.gd | 45 ----- core/systems/hardware/hardware_manager.gd | 5 - core/systems/performance/ryzenadj.gd | 191 ---------------------- core/systems/performance/ryzenadj_test.gd | 16 -- 6 files changed, 1 insertion(+), 404 deletions(-) delete mode 100644 core/systems/hardware/cpu_test.gd delete mode 100644 core/systems/performance/ryzenadj.gd delete mode 100644 core/systems/performance/ryzenadj_test.gd diff --git a/core/systems/hardware/cpu.gd b/core/systems/hardware/cpu.gd index 53919240..259a6167 100644 --- a/core/systems/hardware/cpu.gd +++ b/core/systems/hardware/cpu.gd @@ -8,45 +8,11 @@ signal boost_updated(enabled: bool) ## Emitted when SMT is updated signal smt_updated(enabled: bool) -const POWERTOOLS_PATH := "/usr/share/opengamepadui/scripts/powertools" -const BOOST_PATH := "/sys/devices/system/cpu/cpufreq/boost" -const SMT_PATH := "/sys/devices/system/cpu/smt/control" const CPUS_PATH := "/sys/bus/cpu/devices" -var mutex := Mutex.new() var core_count := get_total_core_count() -var boost_capable: bool = false -var boost_enabled := false: - get: - mutex.lock() - var prop := boost_enabled - mutex.unlock() - return prop - set(v): - if boost_enabled == v: - return - mutex.lock() - boost_enabled = v - mutex.unlock() - emit_signal.call_deferred("changed") - emit_signal.call_deferred("boost_updated", v) var vendor: String var model: String -var smt_capable: bool = false -var smt_enabled := false: - get: - mutex.lock() - var prop := smt_enabled - mutex.unlock() - return prop - set(v): - if smt_enabled == v: - return - mutex.lock() - smt_enabled = v - mutex.unlock() - emit_signal.call_deferred("changed") - emit_signal.call_deferred("smt_updated", v) var logger := Log.get_logger("CPU") @@ -56,11 +22,6 @@ func _init() -> void: var parts := param.split(" ", false) as Array if parts.is_empty(): continue - if parts[0] == "Flags:": - if "ht" in parts: - smt_capable = true - if "cpb" in parts and FileAccess.file_exists(BOOST_PATH): - boost_capable = true if parts[0] == "Vendor" and parts[1] == "ID:": # Delete parts of the string we don't want parts.remove_at(1) @@ -72,7 +33,6 @@ func _init() -> void: parts.remove_at(0) model = str(" ".join(parts)) # TODO: We can get min/max CPU freq here. - update() ## Returns the count of number of enabled CPU cores @@ -80,54 +40,6 @@ func get_enabled_core_count() -> int: return OS.get_processor_count() -## Returns true if boost is currently enabled -func get_boost_enabled() -> bool: - if not boost_capable: - return false - var value := _get_property(BOOST_PATH).to_lower().strip_edges() - - return value == "on" or value == "1" - - -## Set CPU boost to the given value -func set_boost_enabled(enabled: bool) -> int: - if not boost_capable: - return -1 - var enabled_str := "1" if enabled else "0" - var args := ["cpuBoost", enabled_str] - var cmd := CommandSync.new(POWERTOOLS_PATH, args) - if cmd.execute() != OK: - logger.warn("Failed to set CPU boost") - return cmd.code - update() - - return cmd.code - - -## Returns true if SMT is currently enabled -func get_smt_enabled() -> bool: - if not smt_capable: - return false - var value := _get_property(SMT_PATH).to_lower().strip_edges() - - return value == "on" or value == "1" - - -## Set CPU smt to the given value -func set_smt_enabled(enabled: bool) -> int: - if not smt_capable: - return -1 - var enabled_str := "1" if enabled else "0" - var args := ["smtToggle", enabled_str] - var cmd := CommandSync.new(POWERTOOLS_PATH, args) - if cmd.execute() != OK: - logger.warn("Failed to set CPU smt") - return cmd.code - update() - - return cmd.code - - ## Returns an instance of the given CPU core func get_core(num: int) -> CPUCore: # Try to load the core info if it already exists @@ -175,32 +87,6 @@ func get_online_core_count() -> int: return count -## Called to set the number of enabled CPU's -func set_cpu_core_count(value: int) -> void: - # Update the state of the CPU - update() - var cores := get_cores() - logger.debug("Enable cpu cores: " + str(value) + "/" + str(cores.size())) - - for core in cores: - if core.num == 0: - continue - var online := true - if smt_enabled and core.num >= value: - online = false - elif not smt_enabled: - if core.num % 2 != 0 or core.num >= (value * 2) - 1: - online = false - logger.debug("Set CPU No: " + str(core.num) + " online: " + str(online)) - core.set_online(online) - - -## Fetches the current CPU info -func update() -> void: - boost_enabled = get_boost_enabled() - smt_enabled = get_smt_enabled() - - func _get_property(prop_path: String) -> String: if not FileAccess.file_exists(prop_path): return "" @@ -224,7 +110,5 @@ func _to_string() -> String: + " Vendor: (" + str(vendor) \ + ") Model: (" + str(model) \ + ") Core count: (" + str(core_count) \ - + ") Boost Capable: (" + str(boost_capable) \ - + ") SMT Capable: (" + str(smt_capable) \ + ")>" diff --git a/core/systems/hardware/cpu_core.gd b/core/systems/hardware/cpu_core.gd index b7a0c785..d88b4901 100644 --- a/core/systems/hardware/cpu_core.gd +++ b/core/systems/hardware/cpu_core.gd @@ -5,26 +5,12 @@ class_name CPUCore var path: String var num: int -var online: bool: - get: - var prop := online - return prop - set(v): - if online == v: - return - online = v - changed.emit() func _init(n: int) -> void: num = n path = "/".join([CPU.CPUS_PATH, "cpu" + str(n)]) -## Update the state of the CPU core -func update() -> void: - online = get_online() - - ## Returns whether or not the core is online func get_online() -> bool: if num == 0: @@ -33,22 +19,6 @@ func get_online() -> bool: return online_str == "1" -## Sets the online state of the CPU core -func set_online(enabled: bool) -> int: - var logger := Log.get_logger("CPUInfo") - if num == 0: - logger.warn("Unable to disable CPU 0") - return -1 - var enabled_str := "1" if enabled else "0" - var cmd := CommandSync.new(CPU.POWERTOOLS_PATH, ["cpuToggle", str(num), enabled_str]) - if cmd.execute() != OK: - logger.warn("Failed to update CPU core: " + cmd.stdout) - update() - logger.info("Set core " + str(num) + " enabled: " + str(enabled)) - - return cmd.code - - func _get_property(prop: String) -> String: var prop_path := "/".join([path, prop]) if not FileAccess.file_exists(prop_path): @@ -61,4 +31,4 @@ func _get_property(prop: String) -> String: func _to_string() -> String: - return "" + return "" diff --git a/core/systems/hardware/cpu_test.gd b/core/systems/hardware/cpu_test.gd deleted file mode 100644 index e16005ed..00000000 --- a/core/systems/hardware/cpu_test.gd +++ /dev/null @@ -1,45 +0,0 @@ -extends GutTest - -var hardware_manager := load("res://core/systems/hardware/hardware_manager.tres") as HardwareManager -var cpu := hardware_manager.get_cpu() - -func before_all() -> void: - gut.p(cpu) - - -func test_get_cpu_cores() -> void: - for core in cpu.get_cores(): - gut.p(core) - - pass_test("Skipping") - - -func test_cpu_boost() -> void: - cpu.set_boost_enabled(false) - gut.p("Boost: " + str(cpu.get_boost_enabled())) - cpu.set_boost_enabled(true) - gut.p("Boost: " + str(cpu.get_boost_enabled())) - - pass_test("Skipping") - - -func test_cpu_core_enable() -> void: - var core := cpu.get_core(10) - core.changed.connect(_on_core_changed) - if core.set_online(false) != OK: - gut.p("Failed to turn off core") - if core.set_online(true) != OK: - gut.p("Failed to turn on core") - - pass_test("Skipping") - - -func test_set_cpu_core_count() -> void: - cpu.set_cpu_core_count(2) - cpu.set_cpu_core_count(cpu.get_total_core_count()) - - pass_test("Skipping") - - -func _on_core_changed() -> void: - gut.p("Core state changed!") diff --git a/core/systems/hardware/hardware_manager.gd b/core/systems/hardware/hardware_manager.gd index b133de98..49d7942f 100644 --- a/core/systems/hardware/hardware_manager.gd +++ b/core/systems/hardware/hardware_manager.gd @@ -133,11 +133,6 @@ func get_gpu_info() -> GPUInfo: gpu_info.tdp_max = apu_data.max_tdp gpu_info.max_boost = apu_data.max_boost gpu_info.tdp_capable = true - - # Read the GPU limits - var foo := _read_sys("/sys/class/drm/" + gpu_info.card.name + "/device/pp_od_clk_voltage") - gpu_info.freq_min - gpu_info.freq_max "Intel", "GenuineIntel", "Intel Corporation": apu_data = intel_apu_database.get_apu(cpu.model) diff --git a/core/systems/performance/ryzenadj.gd b/core/systems/performance/ryzenadj.gd deleted file mode 100644 index 7306216b..00000000 --- a/core/systems/performance/ryzenadj.gd +++ /dev/null @@ -1,191 +0,0 @@ -extends RefCounted -class_name RyzenAdj - -## Ryzen Power Management adjust tool -## -## Adjust and query power management settings for Ryzen Mobile Processors - -const POWERTOOLS_PATH := "/usr/share/opengamepadui/scripts/powertools" -const RYZENADJ_BIN := "ryzenadj" - -## Corresponds to the '--max-performance' and '--power-saving' arguments. -enum POWER_PROFILE { - POWER_SAVINGS, - MAX_PERFORMANCE, -} - -var thread := load("res://core/systems/threading/utility_thread.tres") as SharedThread -var logger := Log.get_logger("RyzenAdj") - - -## Set hidden option to improve performance/efficiency -func set_power_profile(profile: POWER_PROFILE) -> int: - var arg := "--power-saving" - if profile == POWER_PROFILE.MAX_PERFORMANCE: - arg = "--max-performance" - var cmd := await exec([arg]) - if cmd.code != OK: - logger.error("Failed to set power profile for: " + arg.replace("--", "")) - - return cmd.code - - -## Sets the sustained power limit (STAPM LIMIT) to the given value -func set_stapm_limit(value: float) -> int: - var cmd := await exec(["-a", str(round(value))]) - if cmd.code != OK: - logger.error("Failed to set stapm limit to: " + str(value)) - - return cmd.code - - -## Sets the actual power limit (PPT LIMIT FAST (mW)) to the given value -func set_fast_limit(value: float) -> int: - var cmd := await exec(["-b", str(round(value))]) - if cmd.code != OK: - logger.error("Failed to set fast limit to: " + str(value)) - - return cmd.code - - -## Sets the average power limit (PPT LIMIT SLOW (mW)) to the given value -func set_slow_limit(value: float) -> int: - var cmd := await exec(["-c", str(round(value))]) - if cmd.code != OK: - logger.error("Failed to set slow limit to: " + str(value)) - - return cmd.code - - -## Sets the tctl temperature limit (degree C) to the given value -func set_tctl_temp(value: float) -> int: - var cmd := await exec(["-f", str(round(value))]) - if cmd.code != OK: - logger.error("Failed to set tctl temperature to: " + str(value)) - - return cmd.code - - -## Execute the ryzenadj command with the given arguments. -func exec(args: PackedStringArray) -> Command: - var cmd := Command.new(POWERTOOLS_PATH, PackedStringArray([RYZENADJ_BIN]) + args, thread) - var err := await cmd.execute() as int - if err != OK: - logger.error("Failed to execute command: " + str(cmd)) - - return cmd - - -## Returns current power metrics. If ryzenadj fails to read a particular value, -## it will be set to -1. -func get_info() -> Info: - # Execute 'ryzenadj -i' - var cmd := await exec(["-i"]) - if cmd.code != OK: - logger.error("Failed to execute ryzenadj info command") - return null - - # Create a structure to store the info - var info := Info.new() - - # Parse the ryzenadj output - var lines := cmd.stdout.split("\n") - for line in lines: - var parts := line.split("|") - for index in parts.size(): - parts[index] = parts[index].strip_edges() - if len(parts) < 3: - continue - var key := parts[1] as String - var value_str := parts[2] as String - - if not value_str.is_valid_float(): - logger.debug("Unable to parse value for " + key) - continue - var value := value_str.to_float() - - match key: - "STAPM LIMIT": - info.stapm_limit = value - "STAPM VALUE": - info.stapm_value = value - "PPT LIMIT FAST": - info.ppt_limit_fast = value - "PPT VALUE FAST": - info.ppt_value_fast = value - "PPT LIMIT SLOW": - info.ppt_limit_slow = value - "PPT VALUE SLOW": - info.ppt_value_slow = value - "StapmTimeConst": - info.stapm_time_const = value - "SlowPPTTimeConst": - info.slow_pptt_time_const = value - "PPT LIMIT APU": - info.ppt_limit_apu = value - "PPT VALUE APU": - info.ppt_value_apu = value - "TDC LIMIT VDD": - info.tdc_limit_vdd = value - "TDC VALUE VDD": - info.tdc_value_vdd = value - "TDC LIMIT SOC": - info.tdc_limit_soc = value - "TDC VALUE SOC": - info.tdc_value_soc = value - "EDC LIMIT VDD": - info.edc_limit_vdd = value - "EDC VALUE VDD": - info.edc_value_vdd = value - "EDC LIMIT SOC": - info.edc_limit_soc = value - "EDC VALUE SOC": - info.edc_value_soc = value - "THM LIMIT CORE": - info.thm_limit_core = value - "THM VALUE CORE": - info.thm_value_core = value - "STT LIMIT APU": - info.stt_limit_apu = value - "STT VALUE APU": - info.stt_value_apu = value - "STT LIMIT dGPU": - info.stt_limit_dgpu = value - "STT VALUE dGPU": - info.stt_value_dgpu = value - "CCLK Boost SETPOINT": - info.cclk_boost_setpoint = value - "CCLK BUSY VALUE": - info.cclk_busy_value = value - - return info - - -## Container for holding power metrics from RyzenAdj -class Info: - var stapm_limit := -1.0 - var stapm_value := -1.0 - var ppt_limit_fast := -1.0 - var ppt_value_fast := -1.0 - var ppt_limit_slow := -1.0 - var ppt_value_slow := -1.0 - var stapm_time_const := -1.0 - var slow_pptt_time_const := -1.0 - var ppt_limit_apu := -1.0 - var ppt_value_apu := -1.0 - var tdc_limit_vdd := -1.0 - var tdc_value_vdd := -1.0 - var tdc_limit_soc := -1.0 - var tdc_value_soc := -1.0 - var edc_limit_vdd := -1.0 - var edc_value_vdd := -1.0 - var edc_limit_soc := -1.0 - var edc_value_soc := -1.0 - var thm_limit_core := -1.0 - var thm_value_core := -1.0 - var stt_limit_apu := -1.0 - var stt_value_apu := -1.0 - var stt_limit_dgpu := -1.0 - var stt_value_dgpu := -1.0 - var cclk_boost_setpoint := -1.0 - var cclk_busy_value := -1.0 diff --git a/core/systems/performance/ryzenadj_test.gd b/core/systems/performance/ryzenadj_test.gd deleted file mode 100644 index 46b62e9b..00000000 --- a/core/systems/performance/ryzenadj_test.gd +++ /dev/null @@ -1,16 +0,0 @@ -extends GutTest - -var ryzenadj := RyzenAdj.new() -var supports_ryzenadj := has_ryzenadj() - - -func has_ryzenadj() -> bool: - return OS.execute("which", ["ryzenadj"]) == OK - - -func test_get_info() -> void: - if not supports_ryzenadj: - pass_test("ryzenadj not installed, skipping") - return - var info := await ryzenadj.get_info() - assert_not_null(info, "should return ryzenadj info")