Android 内核禁止休眠:
一、功能需求:
系统休眠时,sleep函数或定时器都会跟随系统频率发生变化。一进休眠就会变慢或感觉被卡住。
二、解决方案:
这个时候,我们有一种简单的方法就是将系统禁止休眠,当然,也使可以恢复的。
三、实施:
1、可以参考https://blog.csdn.net/mike8825/article/details/80422993 .
2、代码不需要过于复杂,尽量精简,抽取关键作用的函数。
3、使用实例
初始化文件路径和定义:
kernel-4.9\include\linux\pm_wakeup.h
static inline void wakeup_source_init(struct wakeup_source *ws, const char *name)
停止函数文件路径和定义:
kernel-4.9\drivers\base\power\wakeup.c
void __pm_stay_awake(struct wakeup_source *ws);
参数路径和定义:
kernel-4.9\include\linux\pm_wakeup.h
struct wakeup_source {
const char *name;
struct list_head entry;
spinlock_t lock;
struct wake_irq *wakeirq;
struct timer_list timer;
unsigned long timer_expires;
ktime_t total_time;
ktime_t max_time;
ktime_t last_time;
ktime_t start_prevent_time;
ktime_t prevent_sleep_time;
unsigned long event_count;
unsigned long active_count;
unsigned long relax_count;
unsigned long expire_count;
unsigned long wakeup_count;
bool active:1;
bool autosleep_enabled:1;
};
参考代码示例:代码在MT6765(kernel4.9)上验证OK
#include <linux/suspend.h>
struct wakeup_source suspend_lock;
extern void wakeup_source_init(struct wakeup_source *lock, const char *name);
extern void __pm_stay_awake(struct wakeup_source *ws);
......
//保持唤醒状态
static void keep_wakeup(void)
{
wakeup_source_init(&suspend_lock,"my wakelock");
__pm_stay_awake(&suspend_lock);
}
解锁参考代码示例:
//释放解锁
__pm_relax(&suspend_lock);