⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 power.sgml

📁 eCos操作系统源码
💻 SGML
📖 第 1 页 / 共 4 页
字号:
<!-- DOCTYPE reference  PUBLIC "-//OASIS//DTD DocBook V3.1//EN" --><!-- {{{ Banner                         --><!-- =============================================================== --><!--                                                                 --><!--     power.sgml                                                  --><!--                                                                 --><!--     Generic power management documentation.                     --><!--                                                                 --><!-- =============================================================== --><!-- ####COPYRIGHTBEGIN####                                          --><!--                                                                 --><!-- =============================================================== --><!-- Copyright (C) 2001, 2002 Red Hat, Inc.                          --><!-- This material may be distributed only subject to the terms      --><!-- and conditions set forth in the Open Publication License, v1.0  --><!-- or later (the latest version is presently available at          --><!-- http://www.opencontent.org/openpub/)                            --><!-- Distribution of the work or derivative of the work in any       --><!-- standard (paper) book form is prohibited unless prior           --><!-- permission obtained from the copyright holder                   --><!-- =============================================================== --><!--                                                                 -->      <!-- ####COPYRIGHTEND####                                            --><!-- =============================================================== --><!-- #####DESCRIPTIONBEGIN####                                       --><!--                                                                 --><!-- Author(s):   bartv                                              --><!-- Contact(s):  bartv                                              --><!-- Date:        2001/06/26                                         --><!-- Version:     0.01                                               --><!--                                                                 --><!-- ####DESCRIPTIONEND####                                          --><!-- =============================================================== --><!-- }}} --><part id="services-power"><!-- reference id="services-power" -->  <title>eCos Power Management Support</title><!-- {{{ Intro                          --><refentry id="power-intro"><refmeta><refentrytitle>Introduction</refentrytitle></refmeta><refnamediv><refname>Introduction</refname><refpurpose>eCos support for Power Management</refpurpose></refnamediv><!-- {{{ Intro                          --><refsect1 id="power-intro-intro"><title>Introduction</title><para>The eCos Power Management package provides a framework forincorporating power management facilities in an embedded application.However its functionality is deliberately limited.</para><orderedlist><listitem><para>The package does not contain any support for controlling the currentpower mode of any given processor, device or board. Instead it is theresponsibility of the appropriate HAL or device driver package toimplement such support, by implementing <firstterm>powercontrollers</firstterm>. The power management package groups thesepower controllers together and provides an interface for manipulatingthem.</para></listitem><listitem><para>The package does not contain any power management policy support.Specifically, including this package in an application does not byitself ever cause the system to go into low-power mode. Instead it isthe responsibility of a separate policy module, provided byhigher-level application code or by some other package, to decide whenit would be appropriate to switch from one power mode to another. Thepower management package then provides the mechanisms for making ithappen.</para></listitem></orderedlist></refsect1><!-- }}} --><!-- {{{ including                      --><refsect1 id="power-intro-include"><title>Including Power Management</title><para>The power management package is never included automatically in aneCos configuration: it is not part of any target specification or ofany template. Instead it must be added explicitly to a configurationif the intended application requires power management functionality.When using the command-line <command>ecosconfig</command> tool thiscan be achieved using a command such as:</para><screen>$ ecosconfig add power</screen><para>The generic eCos user documentation should be consulted for moreinformation on how to use the various tools. The functionalityprovided by the power management package is defined in the header file<filename class="headerfile">cyg/power/power.h</filename>. This headerfile can be used by both C and C++ code.</para></refsect1><!-- }}} --><!-- {{{ modes                          --><refsect1 id="power-intro-modes"><title>Power Modes</title><para>There are four defined modes of operation:</para><variablelist><varlistentry><term>active</term><listitem><para>The system is fully operational, and power consumption is expected tobe high.</para></listitem></varlistentry><varlistentry><term>idle</term><listitem><para>There has been little or no activity for a short period of time. It isup to the policy module to determine what constitutes a short periodof time, but typically it will be some tenths of a second or somesmall number of seconds. A possible action when entering idle mode isto reduce the system's clock speed, thus reducing the power drawn bythe cpu.</para><para>Note that typically this power mode is not entered automaticallywhenever the idle thread starts running. Instead it is entered whenthe policy module discovers that for a certain period of time thesystem has been spending most of its time in the idle thread.Theoretically it is possible to implement a policy module that wouldcause a switch to idle mode as soon as the idle thread starts running,but that could result in a great many power mode changes for noimmediate benefit.</para></listitem></varlistentry><varlistentry><term>sleep</term><listitem><para>The system has been idle for a significant period of time, perhapssome tens of seconds. It is desirable to shut down any hardware thatis drawing a significant amount of power, for example a screenbacklight.</para></listitem></varlistentry><varlistentry><term>off</term><listitem><para>The system is powered down. Power consumption should be minimized.Some special action may be needed before the system comes back up, forexample the user may need to press a specific button.</para></listitem></varlistentry></variablelist><para>The exact transitions that will happen are decided by the policymodule. One policy module might include transitions from active toidle, from idle to sleep, from sleep to off, and from any of idle,sleep or off directly back to active. Another policy module mightonly use the active and off states, bypassing the intermediate ones.</para></refsect1><!-- }}} --><!-- {{{ Power Controllers              --><refsect1 id="power-intro-controllers"><title>Power Controllers</title><para>The power management package operates primarily on power controllers.The main functionality provided by a power controller is to switch thepower mode for some part of the system, for example the lcd display orthe cpu. A power controller consists primarily of a function whichwill be invoked to switch the power mode for the part of the overallsystem being controlled, plus some auxiliary data. A typical systemwill include a number of different power controllers:</para><orderedlist><listitem><para>Usually there will be one power controller<varname>power_controller_cpu</varname> associated with the processoror with the target platform, and provided by the corresponding HALpackage. It is this controller which is responsible for switching offthe system when entering the <type>off</type> mode, which makes itsomewhat special: attempting to switch off the cpu before otherdevices like the lcd display does not make sense because the cpu wouldno longer be executing any instructions for the latter operation.Therefore this power controller has to be invoked last when switchingto a lower-power mode, and similarly when switching back to ahigher-power mode it will be invoked first.</para><para>It should be noted that providing power management support is not ahard requirement when porting eCos to a new processor or platform, andmany eCos ports predate the availability of power management support.Therefore for any given platform it is distinctly possible that<varname>power_controller_cpu</varname> is not yet provided, and iffull power management functionality is desired then the appropriateHAL package would have to be extended first. System developers shouldexamine the relevant HAL documentation and sources to determine whatis actually available.</para></listitem><listitem><para>Some or all of the device drivers will supply their own powercontrollers, as part of the device driver package. It is not requiredthat all device drivers provide power controllers. In some cases,especially for devices that are integrated with the processor,<varname>power_controller_cpu</varname> will take care of theintegrated devices as a side effect. In other cases the hardware maynot provide any functionality that allows power consumption to becontrolled. For any given device driver it is also possible that nopower controller exists either because it was not required when thedriver was written, or because the driver predates the availability ofpower management. Again the relevant documentation and sources shouldbe consulted for further information.</para></listitem><listitem><para>There may be power controllers which are not associated directly withany specific hardware. For example a TCP/IP stack could provide apower controller so that it gets informed when the system has beenreactivated: by looking at the system clock it can determine for howlong the system has been switched off; using this information it canthen recover from expired dhcp leases, or even to shut down any streamconnections that may have become invalid (although arguably the stackshould have refused to go to <type>off</type> mode while there wereopen connections).</para></listitem></orderedlist></refsect1><!-- }}} --><!-- {{{ Basic Operation                --><refsect1 id="power-intro-operation"><title>Basic Operation</title><para>By default the Power Management package creates a thread duringinitialization. It is also possible for the package to be used withoutsuch a thread, for example in configurations which do not include afull kernel, and this alternative is described below. When a separatethread is used the stacksize and priority for this thread can becontrolled by configuration options<varname>CYGNUM_POWER_THREAD_STACKSIZE</varname> and<varname>CYGNUM_POWER_THREAD_PRIORITY</varname>. Typically the threadwill just wait on a semaphore internal to the package, and will donothing until some other part of the system requests a change to thepower mode.</para><para>At some point the policy module will decide that the system shouldmove into a lower-power mode, for example from active to idle. This isachieved by calling the function <function>power_set_mode</function>,provided by the power management package and declared in <filenameclass="headerfile">cyg/power/power.h</filename>, with a singleargument, <literal>PowerMode_Idle</literal>. This function manipulatessome internal state and posts the semaphore, thus waking up the powermanagement thread. Note that the function returns before the modechange has completed, and in fact depending on thread priorities thisreturn may happen before any power controller has been invoked.</para><para>When the power management thread wakes up it examines the internalstate to figure out what it should be doing. In this case it issupposed to change the global power mode, so it will iterate over allthe power controllers requesting each one to switch to the<type>idle</type> mode. It is up to each power controller to handlethis request appropriately. Optionally the thread will invoke acallback function after processing each power controller, so thathigher-level code such as the policy module can more easily keeptrack of the actual state of each controller. Once the thread hasiterated through all the power controllers it will again wait on theinternal semaphore for the next request to arrive.</para><note><para>At present the power management thread always runs at a singlepriority, which defaults to a low priority. A possible futureenhancement would be to support two separate priorities. Whenswitching to a lower-powered mode the thread would run at a lowpriority as before, thus allowing other threads to run and get achance to cancel this mode change. When switching to a higher-poweredmode the thread would run at a high priority. This could be especiallyimportant when moving out of the <type>off</type> state: for exampleit would ensure that all device drivers get a chance to wake up beforeordinary application threads get to run again and possibly attempt I/Ooperations.</para></note><para>Although usually calls to <function>power_set_mode</function> willcome from just one place in the policy module, this is not a hardrequirement. It is possible for multiple threads to call thisfunction, with no need for any synchronization. If the powermanagement thread is in the middle of performing a mode change and anew request comes in, the thread will detect this, abort the currentoperation, and start iterating through the power controllers againwith the new mode. This check happens between every power controllerinvocation. Usefully this makes it possible for power controllersthemselves to manipulate power modes: a power controller is invoked tochange mode; for some reason it determines that the new mode isinappropriate; it calls <function>power_set_mode</function> to movethe system back to another mode; when the power controller returnsthis event will be detected; the power management thread will abortthe current mode change, and start the new one.</para><para>In addition to changing the power mode for the system as a whole,individual controllers can be manipulated using the function<function>power_set_controller_mode</function>. For example, while thesystem as a whole might be in <type>active</type> mode certain devicesmight be kept in <type>sleep</type> mode until they are explicitlyactivated. It is possible to mix concurrent calls to<function>power_set_mode</function> and<function>power_set_controller_mode</function>, and when a powercontroller is invoked it may use<function>power_set_controller_mode</function> to request furtherchanges to its own or to another controller's mode as required.</para><para>There are some scenarios where the power management package should notuse its own thread. One scenario is if the configuration isspecifically for a single-threaded application such as RedBoot.Another scenario is if the policy module already involves a separatethread: it may make more sense if the various power management

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -