power命令_kernel power41

power命令_kernel power411/*kernel/power/earlysuspend.c2*3*Copyright(C)2005-2008Google,Inc.4*5*ThissoftwareislicensedunderthetermsoftheGNUGeneralPublic6*Licenseve…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

 

 


  1 /* kernel/power/earlysuspend.c
  2  *
  3  * Copyright (C) 2005-2008 Google, Inc.
  4  *
  5  * This software is licensed under the terms of the GNU General Public
  6  * License version 2, as published by the Free Software Foundation, and
  7  * may be copied, distributed, and modified under those terms.
  8  *
  9  * This program is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12  * GNU General Public License for more details.
 13  *
 14  */
 15 
 16 #include <linux/earlysuspend.h>
 17 #include <linux/module.h>
 18 #include <linux/mutex.h>
 19 #include <linux/rtc.h>
 20 #include <linux/wakelock.h>
 21 #include <linux/workqueue.h>
 22 
 23 #include "power.h"
 24 
 25 enum {
 26     DEBUG_USER_STATE = 1U << 0,
 27     DEBUG_SUSPEND = 1U << 2,
 28     DEBUG_VERBOSE = 1U << 3,
 29 };
 30 static int debug_mask = DEBUG_USER_STATE;
 31 module_param_named(debug_mask, debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP);
 32 
 33 static DEFINE_MUTEX(early_suspend_lock);
 34 static LIST_HEAD(early_suspend_handlers);
 35 static void early_suspend(struct work_struct *work);
 36 static void late_resume(struct work_struct *work);
 37 static DECLARE_WORK(early_suspend_work, early_suspend);
 38 static DECLARE_WORK(late_resume_work, late_resume);
 39 static DEFINE_SPINLOCK(state_lock);
 40 enum {
 41     SUSPEND_REQUESTED = 0x1,
 42     SUSPENDED = 0x2,
 43     SUSPEND_REQUESTED_AND_SUSPENDED = SUSPEND_REQUESTED | SUSPENDED,
 44 };
 45 static int state;
 46 
 47 void register_early_suspend(struct early_suspend *handler)
 48 {
 49     struct list_head *pos;
 50 
 51     mutex_lock(&early_suspend_lock);
 52     list_for_each(pos, &early_suspend_handlers) {
 53         struct early_suspend *e;
 54         e = list_entry(pos, struct early_suspend, link);
 55         if (e->level > handler->level)
 56             break;
 57     }
 58     list_add_tail(&handler->link, pos);
 59     if ((state & SUSPENDED) && handler->suspend)
 60         handler->suspend(handler);
 61     mutex_unlock(&early_suspend_lock);
 62 }
 63 EXPORT_SYMBOL(register_early_suspend);
 64 
 65 void unregister_early_suspend(struct early_suspend *handler)
 66 {
 67     mutex_lock(&early_suspend_lock);
 68     list_del(&handler->link);
 69     mutex_unlock(&early_suspend_lock);
 70 }
 71 EXPORT_SYMBOL(unregister_early_suspend);
 72 
 

register_early_suspend(struct early_suspend *handler)会按照level从小到大的方式,将handler依次挂在early_suspend_handlers链表头上。
if (e->level > handler->level)判断链表节点e的level大于要插入的handler的level时就break当前遍历,用list_add_tail(&handler->link, pos);将handler->link插到pos节点的前面。

 73 static void early_suspend(struct work_struct *work)
 74 {
 75     struct early_suspend *pos;
 76     unsigned long irqflags;
 77     int abort = 0;
 78 
 79     mutex_lock(&early_suspend_lock);
 80     spin_lock_irqsave(&state_lock, irqflags);
 81     if (state == SUSPEND_REQUESTED)
 82         state |= SUSPENDED;
 83     else
 84         abort = 1;
 85     spin_unlock_irqrestore(&state_lock, irqflags);
 86 
 87     if (abort) {
 88         if (debug_mask & DEBUG_SUSPEND)
 89             pr_info("early_suspend: abort, state %d\n", state);
 90         mutex_unlock(&early_suspend_lock);
 91         goto abort;
 92     }
 93 
 94     if (debug_mask & DEBUG_SUSPEND)
 95         pr_info("early_suspend: call handlers\n");
 96     list_for_each_entry(pos, &early_suspend_handlers, link) {
 97         if (pos->suspend != NULL) {
 98             if (debug_mask & DEBUG_VERBOSE)
 99                 pr_info("early_suspend: calling %pf\n", pos->suspend);
100             pos->suspend(pos);
101         }
102     }
103     mutex_unlock(&early_suspend_lock);
104 
105     suspend_sys_sync_queue();
106 abort:
107     spin_lock_irqsave(&state_lock, irqflags);
108     if (state == SUSPEND_REQUESTED_AND_SUSPENDED)
109         wake_unlock(&main_wake_lock);
110     spin_unlock_irqrestore(&state_lock, irqflags);
111 }
112 
113 static void late_resume(struct work_struct *work)
114 {
115     struct early_suspend *pos;
116     unsigned long irqflags;
117     int abort = 0;
118 
119     mutex_lock(&early_suspend_lock);
120     spin_lock_irqsave(&state_lock, irqflags);
121     if (state == SUSPENDED)
122         state &= ~SUSPENDED;
123     else
124         abort = 1;
125     spin_unlock_irqrestore(&state_lock, irqflags);
126 
127     if (abort) {
128         if (debug_mask & DEBUG_SUSPEND)
129             pr_info("late_resume: abort, state %d\n", state);
130         goto abort;
131     }
132     if (debug_mask & DEBUG_SUSPEND)
133         pr_info("late_resume: call handlers\n");
134     list_for_each_entry_reverse(pos, &early_suspend_handlers, link) {
135         if (pos->resume != NULL) {
136             if (debug_mask & DEBUG_VERBOSE)
137                 pr_info("late_resume: calling %pf\n", pos->resume);
138 
139             pos->resume(pos);
140         }
141     }
142     if (debug_mask & DEBUG_SUSPEND)
143         pr_info("late_resume: done\n");
144 abort:
145     mutex_unlock(&early_suspend_lock);
146 }
147 

early_suspend(struct work_struct *work)和late_resume(struct work_struct *work)分别在第37、38行被声明为了early_suspend_work和late_resume_work,以便在
request_suspend_state(suspend_state_t new_state)中的suspend_work_queue工作队列中使用。

ealry_suspend(struct work_struct *work)中最关键的一句list_for_each_entry(pos, &early_suspend_handlers, link),表示按照level等级排列的顺序,依次调用pos所指向的各个
驱动中注册的ealrysuspend 指向的suspend handler。

late_resume(struct work_struct *work)中list_for_each_entry_reverse(pos, &early_suspend_handlers, link),表示按照level等级的逆序,依次调用pos所指向的各个
驱动中注册的earlysuspend 指向的resume handler。
 
这里有一个很有用的调试信息:pr_info("late_resume: calling %pf\n", pos->resume); %pf可以打印被调函数的函数名。
148 void request_suspend_state(suspend_state_t new_state)
149 {
150     unsigned long irqflags;
151     int old_sleep;
152 
153     spin_lock_irqsave(&state_lock, irqflags);
154     old_sleep = state & SUSPEND_REQUESTED;
155     if (debug_mask & DEBUG_USER_STATE) {
156         struct timespec ts;
157         struct rtc_time tm;
158         getnstimeofday(&ts);
159         rtc_time_to_tm(ts.tv_sec, &tm);
160         pr_info("request_suspend_state: %s (%d->%d) at %lld "
161             "(%d-%02d-%02d %02d:%02d:%02d.%09lu UTC)\n",
162             new_state != PM_SUSPEND_ON ? "sleep" : "wakeup",
163             requested_suspend_state, new_state,
164             ktime_to_ns(ktime_get()),
165             tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
166             tm.tm_hour, tm.tm_min, tm.tm_sec, ts.tv_nsec);
167     }
168     if (!old_sleep && new_state != PM_SUSPEND_ON) {
169         state |= SUSPEND_REQUESTED;
170         queue_work(suspend_work_queue, &early_suspend_work);
171     } else if (old_sleep && new_state == PM_SUSPEND_ON) {
172         state &= ~SUSPEND_REQUESTED;
173         wake_lock(&main_wake_lock);
174         queue_work(suspend_work_queue, &late_resume_work);
175     }
176     requested_suspend_state = new_state;
177     spin_unlock_irqrestore(&state_lock, irqflags);
178 }
179 
180 suspend_state_t get_suspend_state(void)
181 {
182     return requested_suspend_state;
183 }


request_suspend_state(suspend_state_t new_state)
会被kernel/power/main.c中的state show调用,main.c将会在下一章详细说明。
request_suspend_state(suspend_state_t new_state)传入的参数new_state的类型suspend_state_t为一个typedef类型的变量:typedef int __bitwise suspend_state_t;

当new_state为0时,request_suspend_state调用queue_work(suspend_work_queue, &late_resume_work);分支进行late唤醒。
当new_state为3时,request_suspend_state调用queue_work(suspend_work_queue, &early_suspend_work);分支进行浅度休眠。

当系统休眠/唤醒时,串口上会出现如下打印:
request_suspend_state: sleep (0->3) at 6442598858519 (2012-02-05 01:31:08.172285684 UTC)
request_suspend_state: wakeup (3->0) at 6464854624023 (2012-02-05 01:31:30.428053438 UTC)

0代表唤醒,3代表休眠。
0->3 从唤醒到休眠(sleep);
3->0 从休眠到唤醒(wakeup);

转载于:https://www.cnblogs.com/watson/p/3780296.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/192188.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • stimulsoft oracle,Stimulsoft Reports

    stimulsoft oracle,Stimulsoft ReportsStimulsoftReports一站式报表解决方案,支持.NET,JavaScript,Java和Php软件商:Stimulsoft当前版本:2020.3发布日期:2020/6/12推荐:以下是”Reports.Web”,如果您需要了解更多信息,您可以联系我们。支持ASP.NET,ASP.NETMVC,原生.NETCore的报表工具StimulsoftRepor…

    2022年7月26日
    11
  • 安装 | MATLAB2020a (64位) 安装教程及安装包下载链接[通俗易懂]

    安装 | MATLAB2020a (64位) 安装教程及安装包下载链接[通俗易懂]博主github:https://github.com/MichaelBeechan博主CSDN:https://blog.csdn.net/u011344545Matlab2020a链接:链接:https://pan.baidu.com/s/1SfoNj2FC4XMfIbJluRuhUA提取码:解压密码:rjzkgzh<!!!!!!!!打赏后私信我,获取提取码!!!!!!!!!!!!!>打赏链接:https://blog.csdn.net/u011344545/artic

    2022年5月20日
    45
  • 2021最新Java基础篇(后续已更新到另一篇文章)

    2021最新Java基础篇(后续已更新到另一篇文章)提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档文章目录前言一、Java基础?1.1什么是变量:1.2类型的分类:1.3类型的大小:1.4类型的转换与强制类型转换:二、使用步骤1.引入库2.读入数据总结前言提示:在这里可以学到Java基础内容。一、Java基础?1.1什么是变量:变量就是系统为程序分配的一块内存单元,用来存储各种类型的数据。由于该存储单元中的数据可以发生改变,因此得名为”变量”1.2类型的分类:1、基本数据类型变量2、引用数据类型变量

    2022年7月9日
    19
  • idea查看激活码-激活码分享[通俗易懂]

    (idea查看激活码)2021最新分享一个能用的的激活码出来,希望能帮到需要激活的朋友。目前这个是能用的,但是用的人多了之后也会失效,会不定时更新的,大家持续关注此网站~IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月26日
    69
  • Activity入门—Activity生命周期及三种状态+案例[通俗易懂]

    Activity入门—Activity生命周期及三种状态+案例[通俗易懂]生命周期就是一个对象从创建到销毁的过程,每个对象都有自己的生命周期。Activity生命周期分为三种状态。运行状态,停止状态,暂停状态。一.运行状态当activity在最前端时,它是可见的,有焦点的,可以用来处理用户的常见的操作。如:点击,双击,长按事件等。系统最不愿回收的就是出于此种状态的活动,这会带来非常差的用户体验。二.暂停状态activity依然可见,但它不再拥有焦点,即用户对它的操

    2022年8月16日
    5
  • eclipse集成svn使用_svn常用命令

    eclipse集成svn使用_svn常用命令在新版本的Eclipse中是没有svn这个插件,如果我们要用,不得不自己去集成SVN(我不知道老版当中有没有这个插件,没太注意这个问题),今天给大家带来2种集成的方式,一种是在线集成,另一种否是离线集成。这也是我目前知道的2种方案,我也不清楚还有没有其它方案。1.在线集成:Name:这个可以任意添,没有硬性规定,最好见名知意。Location:http://subclipse.tigris.org…

    2022年9月26日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号