팬 정책 데몬 전환과 관측 로그 정리

This commit is contained in:
seo committed 2026-08-02 00:49:38 +09:00
1 parent cfd5bb9b94
commit 309c10f1a1
4 files changed
+65 -11

No files matched your search

+38 -6
View File
@@ -3,6 +3,8 @@ declare(strict_types=1);
require_once __DIR__ . '/config/config.php';
const FAN_POLICY_INTERVAL_SECONDS = 1.0;
function local_fan_paths(): array
{
$candidates = glob('/sys/devices/platform/cooling_fan/hwmon/hwmon*/pwm1') ?: [];
@@ -169,7 +171,8 @@ function dmesg_log_throttled(string $key, string $message, int $seconds = 30): v
dmesg_log($message);
}
try {
function run_fan_policy_once(): bool
{
sync_presence_fan_policy();
$state = get_control_state();
@@ -200,15 +203,12 @@ try {
usleep(80000);
$actualPwm = read_int_file($paths['pwm']);
$rpm = read_int_file($paths['rpm']);
$load = sys_getloadavg() ?: [0, 0, 0];
$mem = local_mem();
$disk = local_disk('/');
$cpuPower = cpu_power_status();
$battery = battery_status();
$ok = $enableOk && $pwmOk;
add_sensor_log([
@@ -254,8 +254,11 @@ try {
);
}
exit($ok ? 0 : 1);
} catch (Throwable $e) {
return $ok;
}
function report_fan_policy_exception(Throwable $e): void
{
try {
add_fan_action(
'apply_policy_exception',
@@ -268,5 +271,34 @@ try {
}
fwrite(STDERR, $e->getMessage() . PHP_EOL);
}
function run_fan_policy_daemon(): int
{
while (true) {
$started = microtime(true);
try {
run_fan_policy_once();
} catch (Throwable $e) {
report_fan_policy_exception($e);
}
$elapsed = microtime(true) - $started;
$sleep = max(0.05, FAN_POLICY_INTERVAL_SECONDS - $elapsed);
usleep((int)round($sleep * 1000000));
}
}
$daemon = in_array('--daemon', $argv ?? [], true);
if ($daemon) {
exit(run_fan_policy_daemon());
}
try {
exit(run_fan_policy_once() ? 0 : 1);
} catch (Throwable $e) {
report_fan_policy_exception($e);
exit(1);
}