Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions auto_cpufreq/modules/system_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,36 @@ def current_epp(is_ac_plugged: bool) -> str | None:
if not Path(epp_path).exists():
return None

return config.get_config().get(
"charger" if is_ac_plugged else "battery", "energy_performance_preference", fallback="balance_power"
)
try:
with open(epp_path, "r") as f:
return f.read().strip()
except:
return None
Comment on lines +155 to +156
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bare except clause catches all exceptions including system-exiting exceptions like KeyboardInterrupt and SystemExit. Replace with a specific exception type like except (FileNotFoundError, OSError, IOError) to handle expected file operation errors.

Copilot uses AI. Check for mistakes.

@staticmethod
def current_epb(is_ac_plugged: bool) -> str | None:
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The is_ac_plugged parameter is no longer used in the method implementation. This parameter should be removed to avoid confusion and maintain a clean API, as the method now reads the actual system value rather than configuration-based values.

Copilot uses AI. Check for mistakes.
epb_path = "/sys/devices/system/cpu/intel_pstate"
epb_path = "/sys/devices/system/cpu/cpu0/power/energy_perf_bias"
if not Path(epb_path).exists():
return None

return config.get_config().get(
"charger" if is_ac_plugged else "battery", "energy_perf_bias", fallback="balance_power"
)
try:
with open(epb_path, "r") as f:
value = int(f.read().strip())
# Convert numeric value to string representation
if value == 0:
return "performance"
elif value == 4:
return "balance_performance"
elif value == 6:
return "default"
elif value == 8:
return "balance_power"
elif value == 15:
return "power"
else:
return str(value)
except:
return None
Comment on lines +180 to +181
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bare except clause catches all exceptions including system-exiting exceptions like KeyboardInterrupt and SystemExit. Replace with a specific exception type like except (FileNotFoundError, OSError, ValueError, IOError) to handle expected file operation and conversion errors.

Copilot uses AI. Check for mistakes.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm bit bothered by cpu0 in /sys/devices/system/cpu/cpu0/power/energy_perf_bias line. Would love it could somehow be made more generic, as in some weird situation someone doesn't have cpu0 (crazy, but not impossible). User will get an error.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm running on Intel and using pstate driver, but replacing epb_path = "/sys/devices/system/cpu/intel_pstate" doesn't seem to affect me.

Would also be nice if these changes would be made made in more generic way depending on which driver user is using.


@staticmethod
def cpu_usage() -> float:
Expand Down
Loading