📄 power-intro.html
字号:
CLASS="VARNAME">power_controller_cpu</TT> 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.</P></LI><LI><P>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,<TTCLASS="VARNAME">power_controller_cpu</TT> 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.</P></LI><LI><P>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 <SPANCLASS="TYPE">off</SPAN> mode while there wereopen connections).</P></LI></OL></DIV><DIVCLASS="REFSECT1"><ANAME="POWER-INTRO-OPERATION"></A><H2>Basic Operation</H2><P>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<TTCLASS="VARNAME">CYGNUM_POWER_THREAD_STACKSIZE</TT> and<TTCLASS="VARNAME">CYGNUM_POWER_THREAD_PRIORITY</TT>. 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.</P><P>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 <TTCLASS="FUNCTION">power_set_mode</TT>,provided by the power management package and declared in <TTCLASS="FILENAME">cyg/power/power.h</TT>, with a singleargument, <TTCLASS="LITERAL">PowerMode_Idle</TT>. 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.</P><P>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<SPANCLASS="TYPE">idle</SPAN> 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.</P><DIVCLASS="NOTE"><BLOCKQUOTECLASS="NOTE"><P><B>Note: </B>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 <SPANCLASS="TYPE">off</SPAN> 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.</P></BLOCKQUOTE></DIV><P>Although usually calls to <TTCLASS="FUNCTION">power_set_mode</TT> 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 <TTCLASS="FUNCTION">power_set_mode</TT> 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.</P><P>In addition to changing the power mode for the system as a whole,individual controllers can be manipulated using the function<TTCLASS="FUNCTION">power_set_controller_mode</TT>. For example, while thesystem as a whole might be in <SPANCLASS="TYPE">active</SPAN> mode certain devicesmight be kept in <SPANCLASS="TYPE">sleep</SPAN> mode until they are explicitlyactivated. It is possible to mix concurrent calls to<TTCLASS="FUNCTION">power_set_mode</TT> and<TTCLASS="FUNCTION">power_set_controller_mode</TT>, and when a powercontroller is invoked it may use<TTCLASS="FUNCTION">power_set_controller_mode</TT> to request furtherchanges to its own or to another controller's mode as required.</P><P>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 managementoperations are synchronous with respect to the calling thread. The useof a separate thread inside the power management package is controlledby the configuration option <TTCLASS="VARNAME">CYGPKG_POWER_THREAD</TT>,which is active only if the kernel package is present and enabled bydefault.</P><P>If no separate power management thread is used then obviously theimplementations of <TTCLASS="FUNCTION">power_set_mode</TT> and<TTCLASS="FUNCTION">power_set_controller_mode</TT> will be somewhatdifferent: instead of waking up a separate thread to do the work,these functions will now manipulate the power controllers directly. Ifthe system does still involve multiple threads then only one threadmay call <TTCLASS="FUNCTION">power_set_mode</TT> or<TTCLASS="FUNCTION">power_set_controller_mode</TT> at a time: the powermanagement package will not provide any synchronization, that musthappen at a higher level. However when a power controller is invokedit can still call these functions as required.</P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="services-power.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-ref.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="power-info.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">eCos Power Management Support</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="services-power.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Power Management Information</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -