Skip to content

Commit

Permalink
legiond: remove use powerprofilectl in powerstate module
Browse files Browse the repository at this point in the history
* since the driver uses /sys/firmware/acpi/platform_profile to show the
  power_profile there no need to use power-profile-daemon
* update acpid event legiond_ppd to use the wmi call

Signed-off-by: Gonçalo Negrier Duarte <[email protected]>
  • Loading branch information
MrDuartePT committed Aug 20, 2024
1 parent e909f13 commit ef427ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 58 deletions.
2 changes: 1 addition & 1 deletion extra/acpi/events/legion_ppd
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
event=D320289E-8FEA- 000000e7 00000000
event=wmi PNP0C14:01 000000e7 00000000
action=/usr/bin/legiond-ctl fanset
74 changes: 17 additions & 57 deletions extra/service/legiond/modules/powerstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,11 @@

#define MATCH(a, b) strcmp(a, b) == 0

static POWER_STATE get_ppdstate()
{
char *cmd = "powerprofilesctl get";
char result[50] = { 0 };
FILE *fp = NULL;
fp = popen(cmd, "r");
if (fp == NULL) {
printf("failed to run powerprofilesctl\n");
}

if (!fread(result, sizeof(char), sizeof(result), fp)) {
printf("failed to parse powerprofile\n");
return -2;
}
pclose(fp);

result[strlen(result) - 1] = 0;

if (MATCH(result, "performance")) {
return P_AC_P;
} else if (MATCH(result, "balanced")) {
return P_AC_B;
} else if (MATCH(result, "power-saver")) {
return P_AC_Q;
}

return -1;
}

POWER_STATE get_powerstate()
{
static bool use_ppd = false;
static bool initialize = false;
POWER_STATE power_state = -1;
FILE *fp;

if (!initialize) {
initialize = true;
if (access(profile_path, F_OK)) {
use_ppd = true;
}
}

fp = fopen(ac_path, "r");
int ac_state;
if (fscanf(fp, "%d", &ac_state) != 1) {
Expand All @@ -57,25 +19,23 @@ POWER_STATE get_powerstate()
}
fclose(fp);

if (use_ppd) {
power_state = get_ppdstate();
} else {
fp = fopen(profile_path, "r");
char profile[30];
if (fscanf(fp, "%s", profile) != 1) {
printf("failed to get power_profile\n");
return P_ERROR_PROFILE;
}
fclose(fp);
if (MATCH(profile, "quiet")) {
power_state = P_AC_Q;
} else if (MATCH(profile, "balanced")) {
power_state = P_AC_B;
} else if (MATCH(profile, "balanced-performance")) {
power_state = P_AC_BP;
} else if (MATCH(profile, "performance")) {
power_state = P_AC_P;
}
fp = fopen(profile_path, "r");
char profile[30];
if (fscanf(fp, "%s", profile) != 1) {
printf("failed to get power_profile\n");
return P_ERROR_PROFILE;
}
fclose(fp);

if (MATCH(profile, "quiet")) {
power_state = P_AC_Q;
} else if (MATCH(profile, "balanced")) {
power_state = P_AC_B;
} else if (MATCH(profile, "performance")) {
power_state = P_AC_P;
} else if (MATCH(profile, "balanced-performance")) {
// Custom Mode
power_state = P_AC_BP;
}

if (!ac_state && power_state != -1) {
Expand Down

0 comments on commit ef427ef

Please sign in to comment.