Skip to content

Commit

Permalink
fix(PowerStation): Get power profiles from PowerStation
Browse files Browse the repository at this point in the history
- Uses dbus to read the available power profiles from PowerStation
- Renamed PowerTools to Performance and moved everything from the old
  performance menu into it.
- Adds "Advanced Mode" toggle to display CPU and GPU settings. Only the
  power profile will be displayed when this is set to off (default).
  When on, power profile is forced to the highest performance profile.
  If PowerStation is using RyzenAdj to set TDP, "max-performance" will
  sett all TDP to the hardware max milit, and "power-saving" will set
  all TDP to the mid point between max and min.
- Modify makefile to add purge and change clean.
  • Loading branch information
pastaq authored and ShadowApex committed Dec 22, 2024
1 parent e2e41be commit 03f5cce
Show file tree
Hide file tree
Showing 17 changed files with 637 additions and 562 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,17 @@ $(ALL_EXTENSIONS) &: $(ALL_EXTENSION_FILES)
edit: $(IMPORT_DIR) ## Open the project in the Godot editor
$(GODOT) --editor .

.PHONY: purge
purge: clean ## Remove all build artifacts including engine extensions
rm -rf $(ROOTFS)
cd ./extensions && $(MAKE) clean

.PHONY: clean
clean: ## Remove build artifacts
clean: ## Remove Godot build artifacts
rm -rf build
rm -rf $(ROOTFS)
rm -rf $(CACHE_DIR)
rm -rf dist
rm -rf $(IMPORT_DIR)
cd ./extensions && $(MAKE) clean

.PHONY: run run-force
run: build/opengamepad-ui.x86_64 run-force ## Run the project in gamescope
Expand Down
8 changes: 4 additions & 4 deletions assets/state/states/quick_bar_performance.tres
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://xw3l4h1vt0oa"]
[gd_resource type="Resource" script_class="State" load_steps=2 format=3 uid="uid://b2ruoxboq5k6e"]

[ext_resource type="Script" path="res://core/systems/state/state.gd" id="1_pmemp"]
[ext_resource type="Script" path="res://core/systems/state/state.gd" id="1_3a3in"]

[resource]
script = ExtResource("1_pmemp")
name = "performance"
script = ExtResource("1_3a3in")
name = "powertools"
data = null
8 changes: 0 additions & 8 deletions assets/state/states/quick_bar_powertools.tres

This file was deleted.

File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://cqy34r7oni6d4"
path="res://.godot/imported/powertools_icon.svg-652cf7833e5f111e096aaec7055e1d3a.ctex"
path="res://.godot/imported/performance_icon.svg-5082e7fb3c41a1711d81bab95097ecfa.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://assets/ui/icons/powertools_icon.svg"
dest_files=["res://.godot/imported/powertools_icon.svg-652cf7833e5f111e096aaec7055e1d3a.ctex"]
source_file="res://assets/ui/icons/performance_icon.svg"
dest_files=["res://.godot/imported/performance_icon.svg-5082e7fb3c41a1711d81bab95097ecfa.ctex"]

[params]

Expand Down
54 changes: 35 additions & 19 deletions core/systems/performance/performance_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,16 @@ func create_profile(library_item: LibraryLaunchItem = null) -> PerformanceProfil
for card in cards:
if card.class != "integrated":
continue

profile.tdp_current = card.tdp
profile.tdp_boost_current = card.boost
if _hardware_manager.gpu:
profile.tdp_current = round(_hardware_manager.gpu.tdp_max)
profile.tdp_boost_current = round(_hardware_manager.gpu.max_boost)
else:
profile.tdp_current = card.tdp
profile.tdp_boost_current = card.boost
profile.gpu_freq_min_current = card.clock_value_mhz_min
profile.gpu_freq_max_current = card.clock_value_mhz_max
profile.gpu_manual_enabled = card.manual_clock
#profile.gpu_power_profile = card.power_profile # TODO: Fix this
profile.gpu_power_profile = card.power_profile
profile.gpu_temp_current = card.thermal_throttle_limit_c

logger.debug("Created performance profile: " + profile.name)
Expand Down Expand Up @@ -177,23 +180,12 @@ func apply_profile(profile: PerformanceProfile) -> void:
if card.class != "integrated":
continue
logger.debug("Applying GPU performance settings from profile")
if profile.gpu_power_profile >= 0:
var power_profile := "max-performance"
if profile.gpu_power_profile == 0:
power_profile = "max-performance"
if profile.gpu_power_profile == 1:
power_profile = "power-saving"
if card.power_profile != power_profile:
logger.debug("Applying Power Profile: " + power_profile)
card.power_profile = power_profile
if card.power_profile != profile.gpu_power_profile:
logger.debug("Applying Power Profile: " + profile.gpu_power_profile)
card.power_profile = profile.gpu_power_profile
if card.manual_clock != profile.gpu_manual_enabled:
logger.debug("Applying Manual Clock Enabled: " + str(profile.gpu_manual_enabled))
card.manual_clock = profile.gpu_manual_enabled
if profile.tdp_current > 0 and card.tdp != profile.tdp_current:
logger.debug("Applying TDP: " + str(profile.tdp_current))
card.tdp = profile.tdp_current
if profile.tdp_boost_current > 0 and card.boost != profile.tdp_boost_current:
logger.debug("Applying TDP Boost: " + str(profile.tdp_boost_current))
card.boost = profile.tdp_boost_current
if profile.gpu_freq_min_current > 0 and card.clock_value_mhz_min != profile.gpu_freq_min_current:
logger.debug("Applying Clock Freq Min: " + str(profile.gpu_freq_min_current))
card.clock_value_mhz_min = profile.gpu_freq_min_current
Expand All @@ -204,6 +196,15 @@ func apply_profile(profile: PerformanceProfile) -> void:
logger.debug("Applying Thermal Throttle Limit: " + str(profile.gpu_temp_current))
card.thermal_throttle_limit_c = profile.gpu_temp_current

# Only apply GPU TDP settings from the given profile if we're in a mode that supports it
if profile.advanced_mode or "max-performance" in get_power_profiles_available():
if profile.tdp_current > 0 and card.tdp != profile.tdp_current:
logger.debug("Applying TDP: " + str(profile.tdp_current))
card.tdp = profile.tdp_current
if profile.tdp_boost_current > 0 and card.boost != profile.tdp_boost_current:
logger.debug("Applying TDP Boost: " + str(profile.tdp_boost_current))
card.boost = profile.tdp_boost_current

# Apply CPU settings from the given profile
if _power_station.cpu:
logger.debug("Applying CPU performance settings from profile")
Expand Down Expand Up @@ -299,3 +300,18 @@ func _on_app_switched(_from: RunningApp, to: RunningApp) -> void:
current_profile = profile
profile_loaded.emit(profile)
apply_profile(profile)


# Get the currently available power profiles
func get_power_profiles_available() -> PackedStringArray:
# Detect all GPU cards
var cards: Array[GpuCard] = []
if _power_station.gpu:
cards = _power_station.gpu.get_cards()

for card in cards:
if card.class != "integrated":
continue

return card.power_profiles_available
return []
8 changes: 5 additions & 3 deletions core/systems/performance/performance_profile.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ class_name PerformanceProfile
@export var gpu_freq_max_current: float
@export var gpu_freq_min_current: float
@export var gpu_manual_enabled: bool
@export var gpu_power_profile: int
@export var gpu_power_profile: String
@export var gpu_temp_current: float
@export var tdp_boost_current: float
@export var tdp_current: float
@export var thermal_profile: int
@export var advanced_mode: bool = false


func _to_string() -> String:
Expand All @@ -25,8 +26,9 @@ func _to_string() -> String:
+ "gpu_freq_max_current: " + str(gpu_freq_max_current) + ", " \
+ "gpu_freq_min_current: " + str(gpu_freq_min_current) + ", " \
+ "gpu_manual_enabled: " + str(gpu_manual_enabled) + ", " \
+ "gpu_power_profile: " + str(gpu_power_profile) + ", " \
+ "gpu_power_profile: " + gpu_power_profile + ", " \
+ "gpu_temp_current: " + str(gpu_temp_current) + ", " \
+ "tdp_boost_current: " + str(tdp_boost_current) + ", " \
+ "tdp_current: " + str(tdp_current) + ", " \
+ "thermal_profile: " + str(thermal_profile) + ">"
+ "thermal_profile: " + str(thermal_profile) + ", " \
+ "advanced_mode:" + str(advanced_mode) + ">"
22 changes: 4 additions & 18 deletions core/ui/card_ui/quick_bar/performance_card.tscn
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
[gd_scene load_steps=5 format=3 uid="uid://dycb7m0oj13ly"]
[gd_scene load_steps=3 format=3 uid="uid://dycb7m0oj13ly"]

[ext_resource type="PackedScene" uid="uid://b5xnora73yd8x" path="res://core/ui/card_ui/quick_bar/qb_card.tscn" id="1_77cql"]
[ext_resource type="PackedScene" uid="uid://b7piua3snox4i" path="res://core/ui/common/quick_bar/performance_menu.tscn" id="2_k3j2r"]

[sub_resource type="Image" id="Image_asnwl"]
data = {
"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 93, 93, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0),
"format": "RGBA8",
"height": 16,
"mipmaps": false,
"width": 16
}

[sub_resource type="ImageTexture" id="ImageTexture_adlkc"]
image = SubResource("Image_asnwl")
[ext_resource type="PackedScene" uid="uid://dv3dt0j3jketh" path="res://core/ui/common/quick_bar/performance_menu.tscn" id="3_e67l3"]

[node name="PerformanceCard" instance=ExtResource("1_77cql")]
title = "Performance"

[node name="HighlightTexture" parent="." index="4"]
texture = SubResource("ImageTexture_adlkc")

[node name="SectionLabel" parent="MarginContainer/CardVBoxContainer" index="0"]
text = "Performance"

[node name="PerformanceMenu" parent="MarginContainer/CardVBoxContainer/ContentContainer" index="0" instance=ExtResource("2_k3j2r")]
[node name="Performance" parent="MarginContainer/CardVBoxContainer/ContentContainer" index="0" instance=ExtResource("3_e67l3")]
layout_mode = 2
size_flags_vertical = 0
29 changes: 0 additions & 29 deletions core/ui/card_ui/quick_bar/power_tools_card.tscn

This file was deleted.

6 changes: 1 addition & 5 deletions core/ui/card_ui/quick_bar/quick_bar_menu.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=31 format=3 uid="uid://hroo3ll4inrb"]
[gd_scene load_steps=30 format=3 uid="uid://hroo3ll4inrb"]

[ext_resource type="Script" path="res://core/ui/card_ui/quick_bar/quick_bar_menu.gd" id="1_56jo7"]
[ext_resource type="PackedScene" uid="uid://shvyhrv5sx3v" path="res://core/systems/state/state_watcher.tscn" id="2_6rvrx"]
Expand Down Expand Up @@ -29,7 +29,6 @@
[ext_resource type="PackedScene" uid="uid://bjy50kdrebgre" path="res://core/ui/card_ui/quick_bar/notifications_card.tscn" id="19_pppbi"]
[ext_resource type="PackedScene" uid="uid://dxaeufuk7ump2" path="res://core/ui/card_ui/quick_bar/quick_settings_card.tscn" id="20_17ks0"]
[ext_resource type="PackedScene" uid="uid://dycb7m0oj13ly" path="res://core/ui/card_ui/quick_bar/performance_card.tscn" id="21_uw510"]
[ext_resource type="PackedScene" uid="uid://v751ima8r8vg" path="res://core/ui/card_ui/quick_bar/power_tools_card.tscn" id="22_dtanu"]

[node name="QuickBarMenu" type="Control" groups=["quick-bar"]]
z_index = 20
Expand Down Expand Up @@ -236,6 +235,3 @@ layout_mode = 2

[node name="PerformanceCard" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/ScrollContainer/Viewport" instance=ExtResource("21_uw510")]
layout_mode = 2

[node name="PowerToolsCard" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/ScrollContainer/Viewport" instance=ExtResource("22_dtanu")]
layout_mode = 2
Loading

0 comments on commit 03f5cce

Please sign in to comment.