mirror of
https://github.com/followmsi/android_kernel_google_msm.git
synced 2024-11-06 23:17:41 +00:00
1ae5815864
This fixes the issue where LCD takes a long time to come back up since the execution of backlight on and late_resume works by the suspend worker thread is delayed due to one (or more) of the sys_sync calls in early_suspend and suspend paths taking a long time (sometimes 15sec or more) for the below reported scenario(s): Scenario 1 (copy with usb connected): 1. plug usb 2. adb shell 3. busybox cp /sdcard/file1 /sdcard/file2 (copy >= 100MB file1 in sdcard/emmc to file2 in sdcard/emmc) 4. press end key to suspend 5. press end key again and it takes a long time for LCD to come back up Scenario 2 (background copy): 1. plug usb 2. adb shell 3. busybox cp /sdcard/file1 /sdcard/file2 & (copy >= 100MB file1 in sdcard/emmc to file2 in sdcard/emmc) 4. disconnect usb 5. press end key to suspend 6. press end key again and it takes a long time for LCD to come back up A more common form of Scenario 2 is for the user to just use the copy function on the UI to copy large file(s). We address this by moving sys_sync calls to a separate workqueue and having a timeout polling based mechanism to bail out of suspend in case of user invoking a wakeup event (like end key press) while we are waiting for the sys_sync completion at the synchronization point in suspend worker thread context. CRs-Fixed: 283994 Change-Id: I6b54af8432e58fd5442817b7388ce2e0b83354b6 Signed-off-by: Pratik Patel <pratikp@codeaurora.org> (cherry picked from commit 8564b5ebeafa2be276e0004d7d32bd101642fb3d) Conflicts: kernel/power/process.c
183 lines
4.9 KiB
C
183 lines
4.9 KiB
C
/* kernel/power/earlysuspend.c
|
|
*
|
|
* Copyright (C) 2005-2008 Google, Inc.
|
|
*
|
|
* This software is licensed under the terms of the GNU General Public
|
|
* License version 2, as published by the Free Software Foundation, and
|
|
* may be copied, distributed, and modified under those terms.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
*/
|
|
|
|
#include <linux/earlysuspend.h>
|
|
#include <linux/module.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/rtc.h>
|
|
#include <linux/wakelock.h>
|
|
#include <linux/workqueue.h>
|
|
|
|
#include "power.h"
|
|
|
|
enum {
|
|
DEBUG_USER_STATE = 1U << 0,
|
|
DEBUG_SUSPEND = 1U << 2,
|
|
DEBUG_VERBOSE = 1U << 3,
|
|
};
|
|
static int debug_mask = DEBUG_USER_STATE;
|
|
module_param_named(debug_mask, debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP);
|
|
|
|
static DEFINE_MUTEX(early_suspend_lock);
|
|
static LIST_HEAD(early_suspend_handlers);
|
|
static void early_suspend(struct work_struct *work);
|
|
static void late_resume(struct work_struct *work);
|
|
static DECLARE_WORK(early_suspend_work, early_suspend);
|
|
static DECLARE_WORK(late_resume_work, late_resume);
|
|
static DEFINE_SPINLOCK(state_lock);
|
|
enum {
|
|
SUSPEND_REQUESTED = 0x1,
|
|
SUSPENDED = 0x2,
|
|
SUSPEND_REQUESTED_AND_SUSPENDED = SUSPEND_REQUESTED | SUSPENDED,
|
|
};
|
|
static int state;
|
|
|
|
void register_early_suspend(struct early_suspend *handler)
|
|
{
|
|
struct list_head *pos;
|
|
|
|
mutex_lock(&early_suspend_lock);
|
|
list_for_each(pos, &early_suspend_handlers) {
|
|
struct early_suspend *e;
|
|
e = list_entry(pos, struct early_suspend, link);
|
|
if (e->level > handler->level)
|
|
break;
|
|
}
|
|
list_add_tail(&handler->link, pos);
|
|
if ((state & SUSPENDED) && handler->suspend)
|
|
handler->suspend(handler);
|
|
mutex_unlock(&early_suspend_lock);
|
|
}
|
|
EXPORT_SYMBOL(register_early_suspend);
|
|
|
|
void unregister_early_suspend(struct early_suspend *handler)
|
|
{
|
|
mutex_lock(&early_suspend_lock);
|
|
list_del(&handler->link);
|
|
mutex_unlock(&early_suspend_lock);
|
|
}
|
|
EXPORT_SYMBOL(unregister_early_suspend);
|
|
|
|
static void early_suspend(struct work_struct *work)
|
|
{
|
|
struct early_suspend *pos;
|
|
unsigned long irqflags;
|
|
int abort = 0;
|
|
|
|
mutex_lock(&early_suspend_lock);
|
|
spin_lock_irqsave(&state_lock, irqflags);
|
|
if (state == SUSPEND_REQUESTED)
|
|
state |= SUSPENDED;
|
|
else
|
|
abort = 1;
|
|
spin_unlock_irqrestore(&state_lock, irqflags);
|
|
|
|
if (abort) {
|
|
if (debug_mask & DEBUG_SUSPEND)
|
|
pr_info("early_suspend: abort, state %d\n", state);
|
|
mutex_unlock(&early_suspend_lock);
|
|
goto abort;
|
|
}
|
|
|
|
if (debug_mask & DEBUG_SUSPEND)
|
|
pr_info("early_suspend: call handlers\n");
|
|
list_for_each_entry(pos, &early_suspend_handlers, link) {
|
|
if (pos->suspend != NULL) {
|
|
if (debug_mask & DEBUG_VERBOSE)
|
|
pr_info("early_suspend: calling %pf\n", pos->suspend);
|
|
pos->suspend(pos);
|
|
}
|
|
}
|
|
mutex_unlock(&early_suspend_lock);
|
|
|
|
suspend_sys_sync_queue();
|
|
abort:
|
|
spin_lock_irqsave(&state_lock, irqflags);
|
|
if (state == SUSPEND_REQUESTED_AND_SUSPENDED)
|
|
wake_unlock(&main_wake_lock);
|
|
spin_unlock_irqrestore(&state_lock, irqflags);
|
|
}
|
|
|
|
static void late_resume(struct work_struct *work)
|
|
{
|
|
struct early_suspend *pos;
|
|
unsigned long irqflags;
|
|
int abort = 0;
|
|
|
|
mutex_lock(&early_suspend_lock);
|
|
spin_lock_irqsave(&state_lock, irqflags);
|
|
if (state == SUSPENDED)
|
|
state &= ~SUSPENDED;
|
|
else
|
|
abort = 1;
|
|
spin_unlock_irqrestore(&state_lock, irqflags);
|
|
|
|
if (abort) {
|
|
if (debug_mask & DEBUG_SUSPEND)
|
|
pr_info("late_resume: abort, state %d\n", state);
|
|
goto abort;
|
|
}
|
|
if (debug_mask & DEBUG_SUSPEND)
|
|
pr_info("late_resume: call handlers\n");
|
|
list_for_each_entry_reverse(pos, &early_suspend_handlers, link) {
|
|
if (pos->resume != NULL) {
|
|
if (debug_mask & DEBUG_VERBOSE)
|
|
pr_info("late_resume: calling %pf\n", pos->resume);
|
|
|
|
pos->resume(pos);
|
|
}
|
|
}
|
|
if (debug_mask & DEBUG_SUSPEND)
|
|
pr_info("late_resume: done\n");
|
|
abort:
|
|
mutex_unlock(&early_suspend_lock);
|
|
}
|
|
|
|
void request_suspend_state(suspend_state_t new_state)
|
|
{
|
|
unsigned long irqflags;
|
|
int old_sleep;
|
|
|
|
spin_lock_irqsave(&state_lock, irqflags);
|
|
old_sleep = state & SUSPEND_REQUESTED;
|
|
if (debug_mask & DEBUG_USER_STATE) {
|
|
struct timespec ts;
|
|
struct rtc_time tm;
|
|
getnstimeofday(&ts);
|
|
rtc_time_to_tm(ts.tv_sec, &tm);
|
|
pr_info("request_suspend_state: %s (%d->%d) at %lld "
|
|
"(%d-%02d-%02d %02d:%02d:%02d.%09lu UTC)\n",
|
|
new_state != PM_SUSPEND_ON ? "sleep" : "wakeup",
|
|
requested_suspend_state, new_state,
|
|
ktime_to_ns(ktime_get()),
|
|
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
|
|
tm.tm_hour, tm.tm_min, tm.tm_sec, ts.tv_nsec);
|
|
}
|
|
if (!old_sleep && new_state != PM_SUSPEND_ON) {
|
|
state |= SUSPEND_REQUESTED;
|
|
queue_work(suspend_work_queue, &early_suspend_work);
|
|
} else if (old_sleep && new_state == PM_SUSPEND_ON) {
|
|
state &= ~SUSPEND_REQUESTED;
|
|
wake_lock(&main_wake_lock);
|
|
queue_work(suspend_work_queue, &late_resume_work);
|
|
}
|
|
requested_suspend_state = new_state;
|
|
spin_unlock_irqrestore(&state_lock, irqflags);
|
|
}
|
|
|
|
suspend_state_t get_suspend_state(void)
|
|
{
|
|
return requested_suspend_state;
|
|
}
|