mirror of
https://gitlab.freedesktop.org/upower/power-profiles-daemon.git
synced 2026-05-04 22:18:00 +02:00
amd-pstate: Program minimum frequency to lowest non-linear frequency
Although the system will save more power at lower frequency, AMD SoCs have a point when they can operate most efficiently called the lowest non-linear frequency. Program the minimum frequency to this value in balanced and performance modes to improve responsiveness. Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
This commit is contained in:
parent
05867e84a4
commit
5eb1248927
2 changed files with 108 additions and 0 deletions
|
|
@ -198,6 +198,21 @@ profile_to_cpb_pref (PpdProfile profile)
|
|||
|
||||
}
|
||||
|
||||
static const char *
|
||||
profile_to_min_freq (PpdProfile profile)
|
||||
{
|
||||
switch (profile) {
|
||||
case PPD_PROFILE_POWER_SAVER:
|
||||
return "cpuinfo_min_freq";
|
||||
case PPD_PROFILE_BALANCED:
|
||||
case PPD_PROFILE_PERFORMANCE:
|
||||
return "amd_pstate_lowest_nonlinear_freq";
|
||||
}
|
||||
|
||||
g_return_val_if_reached (NULL);
|
||||
|
||||
}
|
||||
|
||||
static gboolean
|
||||
apply_pref_to_devices (GPtrArray *devices,
|
||||
PpdProfile profile,
|
||||
|
|
@ -207,6 +222,7 @@ apply_pref_to_devices (GPtrArray *devices,
|
|||
const char *epp_pref;
|
||||
const char *gov_pref;
|
||||
const char *cpb_pref;
|
||||
const char *min_freq;
|
||||
|
||||
if (profile == PPD_PROFILE_UNSET)
|
||||
return TRUE;
|
||||
|
|
@ -214,12 +230,14 @@ apply_pref_to_devices (GPtrArray *devices,
|
|||
epp_pref = profile_to_epp_pref (profile, battery);
|
||||
gov_pref = profile_to_gov_pref (profile);
|
||||
cpb_pref = profile_to_cpb_pref (profile);
|
||||
min_freq = profile_to_min_freq (profile);
|
||||
|
||||
for (guint i = 0; i < devices->len; ++i) {
|
||||
const char *base = g_ptr_array_index (devices, i);
|
||||
g_autofree char *epp = NULL;
|
||||
g_autofree char *gov = NULL;
|
||||
g_autofree char *cpb = NULL;
|
||||
g_autofree char *min_freq_path = NULL;
|
||||
|
||||
gov = g_build_filename (base,
|
||||
"scaling_governor",
|
||||
|
|
@ -240,6 +258,20 @@ apply_pref_to_devices (GPtrArray *devices,
|
|||
if (!ppd_utils_write (cpb, cpb_pref, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
min_freq_path = g_build_filename (base, min_freq, NULL);
|
||||
if (g_file_test (min_freq_path, G_FILE_TEST_EXISTS)) {
|
||||
g_autofree char *scaling_freq_path = NULL;
|
||||
g_autofree char *min_freq_val = NULL;
|
||||
|
||||
if (!g_file_get_contents (min_freq_path, &min_freq_val, NULL, NULL))
|
||||
return FALSE;
|
||||
min_freq_val = g_strchomp (min_freq_val);
|
||||
|
||||
scaling_freq_path = g_build_filename (base, "scaling_min_freq", NULL);
|
||||
if (!ppd_utils_write (scaling_freq_path, min_freq_val, error))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
|
|
|||
|
|
@ -1140,6 +1140,82 @@ class Tests(dbusmock.DBusTestCase):
|
|||
self.assert_file_eventually_contains(energy_prefs, "power")
|
||||
self.assert_file_eventually_contains(scaling_governor, "powersave")
|
||||
|
||||
# pylint: disable=too-many-statements
|
||||
def test_amd_pstate_min_freq(self):
|
||||
"""AMD P-State driver min freq support"""
|
||||
# Create 2 CPUs with preferences
|
||||
dir1 = os.path.join(
|
||||
self.testbed.get_root_dir(), "sys/devices/system/cpu/cpufreq/policy0/"
|
||||
)
|
||||
os.makedirs(dir1)
|
||||
self.write_file_contents(os.path.join(dir1, "cpuinfo_min_freq"), "400000\n")
|
||||
self.write_file_contents(os.path.join(dir1, "scaling_min_freq"), "400000\n")
|
||||
self.write_file_contents(
|
||||
os.path.join(dir1, "amd_pstate_lowest_nonlinear_freq"), "1114000\n"
|
||||
)
|
||||
self.write_file_contents(os.path.join(dir1, "scaling_governor"), "powersave\n")
|
||||
self.write_file_contents(
|
||||
os.path.join(dir1, "energy_performance_preference"), "performance\n"
|
||||
)
|
||||
dir2 = os.path.join(
|
||||
self.testbed.get_root_dir(), "sys/devices/system/cpu/cpufreq/policy1/"
|
||||
)
|
||||
os.makedirs(dir2)
|
||||
self.write_file_contents(os.path.join(dir2, "cpuinfo_min_freq"), "400000\n")
|
||||
self.write_file_contents(os.path.join(dir2, "scaling_min_freq"), "400000\n")
|
||||
self.write_file_contents(
|
||||
os.path.join(dir2, "amd_pstate_lowest_nonlinear_freq"), "1114000\n"
|
||||
)
|
||||
self.write_file_contents(os.path.join(dir2, "scaling_governor"), "powersave\n")
|
||||
self.write_file_contents(
|
||||
os.path.join(dir2, "energy_performance_preference"), "performance\n"
|
||||
)
|
||||
|
||||
# Create AMD P-State configuration
|
||||
pstate_dir = os.path.join(
|
||||
self.testbed.get_root_dir(), "sys/devices/system/cpu/amd_pstate"
|
||||
)
|
||||
os.makedirs(pstate_dir)
|
||||
self.write_file_contents(os.path.join(pstate_dir, "status"), "active\n")
|
||||
|
||||
# desktop PM profile
|
||||
dir3 = os.path.join(self.testbed.get_root_dir(), "sys/firmware/acpi/")
|
||||
os.makedirs(dir3)
|
||||
self.write_file_contents(os.path.join(dir3, "pm_profile"), "1\n")
|
||||
|
||||
self.start_daemon()
|
||||
|
||||
profiles = self.get_dbus_property("Profiles")
|
||||
self.assertEqual(len(profiles), 3)
|
||||
|
||||
self.assertEqual(profiles[0]["Driver"], "multiple")
|
||||
self.assertEqual(profiles[0]["CpuDriver"], "amd_pstate")
|
||||
self.assertEqual(profiles[0]["Profile"], "power-saver")
|
||||
|
||||
energy_prefs = os.path.join(dir2, "energy_performance_preference")
|
||||
scaling_governor = os.path.join(dir2, "scaling_governor")
|
||||
scaling_min_freq = os.path.join(dir2, "scaling_min_freq")
|
||||
|
||||
self.assert_file_eventually_contains(energy_prefs, "balance_performance")
|
||||
self.assert_file_eventually_contains(scaling_governor, "powersave")
|
||||
self.assert_file_eventually_contains(scaling_min_freq, "1114000")
|
||||
|
||||
# Set performance mode
|
||||
self.set_dbus_property("ActiveProfile", GLib.Variant.new_string("performance"))
|
||||
self.assertEqual(self.get_dbus_property("ActiveProfile"), "performance")
|
||||
|
||||
self.assert_file_eventually_contains(energy_prefs, "performance")
|
||||
self.assert_file_eventually_contains(scaling_governor, "performance")
|
||||
self.assert_file_eventually_contains(scaling_min_freq, "1114000")
|
||||
|
||||
# Set powersave mode
|
||||
self.set_dbus_property("ActiveProfile", GLib.Variant.new_string("power-saver"))
|
||||
self.assertEqual(self.get_dbus_property("ActiveProfile"), "power-saver")
|
||||
|
||||
self.assert_file_eventually_contains(energy_prefs, "power")
|
||||
self.assert_file_eventually_contains(scaling_governor, "powersave")
|
||||
self.assert_file_eventually_contains(scaling_min_freq, "400000")
|
||||
|
||||
# pylint: disable=too-many-statements
|
||||
def test_amd_pstate_boost(self):
|
||||
"""AMD P-State driver boost support"""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue