// SPDX-License-Identifier: GPL-2.0 /* * kernel/power/autosleep.c * * Opportunistic sleep support. * * Copyright (C) 2012 Rafael J. Wysocki <rjw@sisk.pl> */ #include <linux/device.h> #include <linux/mutex.h> #include <linux/pm_wakeup.h> #include "power.h" static suspend_state_t autosleep_state; static struct workqueue_struct *autosleep_wq; /* * Note: it is only safe to mutex_lock(&autosleep_lock) if a wakeup_source * is active, otherwise a deadlock with try_to_suspend() is possible. * Alternatively mutex_lock_interruptible() can be used. This will then fail * if an auto_sleep cycle tries to freeze processes. */ static DEFINE_MUTEX(autosleep_lock); static struct wakeup_source *autosleep_ws;
static void try_to_suspend(struct work_struct *work) { unsigned int initial_count, final_count; if (!pm_get_wakeup_count(&initial_count, true)) goto out; mutex_lock(&autosleep_lock); if (!pm_save_wakeup_count(initial_count) || system_state != SYSTEM_RUNNING) { mutex_unlock(&autosleep_lock); goto out; } if (autosleep_state == PM_SUSPEND_ON) { mutex_unlock(&autosleep_lock); return; } if (autosleep_state >= PM_SUSPEND_MAX) hibernate(); else pm_suspend(autosleep_state); mutex_unlock(&autosleep_lock); if (!pm_get_wakeup_count(&final_count, false)) goto out; /* * If the wakeup occured for an unknown reason, wait to prevent the * system from trying to suspend and waking up in a tight loop. */ if (final_count == initial_count) schedule_timeout_uninterruptible(HZ / 2); out: queue_up_suspend_work(); }Contributors
Person | Tokens | Prop | Commits | CommitProp |
Rafael J. Wysocki | 125 | 96.90% | 1 | 50.00% |
Liu ShuoX | 4 | 3.10% | 1 | 50.00% |
Total | 129 | 100.00% | 2 | 100.00% |
Person | Tokens | Prop | Commits | CommitProp |
Rafael J. Wysocki | 21 | 100.00% | 1 | 100.00% |
Total | 21 | 100.00% | 1 | 100.00% |
Person | Tokens | Prop | Commits | CommitProp |
Rafael J. Wysocki | 10 | 100.00% | 1 | 100.00% |
Total | 10 | 100.00% | 1 | 100.00% |
Person | Tokens | Prop | Commits | CommitProp |
Rafael J. Wysocki | 14 | 100.00% | 1 | 100.00% |
Total | 14 | 100.00% | 1 | 100.00% |
Person | Tokens | Prop | Commits | CommitProp |
Rafael J. Wysocki | 13 | 100.00% | 1 | 100.00% |
Total | 13 | 100.00% | 1 | 100.00% |
Person | Tokens | Prop | Commits | CommitProp |
Rafael J. Wysocki | 76 | 100.00% | 2 | 100.00% |
Total | 76 | 100.00% | 2 | 100.00% |
Person | Tokens | Prop | Commits | CommitProp |
Rafael J. Wysocki | 49 | 100.00% | 1 | 100.00% |
Total | 49 | 100.00% | 1 | 100.00% |
Person | Tokens | Prop | Commits | CommitProp |
Rafael J. Wysocki | 352 | 98.60% | 2 | 50.00% |
Liu ShuoX | 4 | 1.12% | 1 | 25.00% |
Greg Kroah-Hartman | 1 | 0.28% | 1 | 25.00% |
Total | 357 | 100.00% | 4 | 100.00% |