Patent Publication Number: US-2005138443-A1

Title: Method for C state management

Description:
BACKGROUND INFORMATION  
      Current mainstream operating systems such as Windows 2000 and Windows XP use a C state algorithm as recommended by the ACPI 1.0b specification. In this algorithm, the OS monitors the processor idleness by taking timestamps when the processor goes idle (no threads in the running or ready-to-run state), and taking another timestamp when the processor becomes busy. By accumulating the deltas between timestamps across larger time intervals, the idleness of the processor can be calculated as the ratio of idle time divided by sampling interval. On each entry into the idle loop, the OS enters a C state numbered C 1 , C 2 , C 3  in order to save power. Lower numbered C states have lower latency to enter/exit, but consume more power than higher numbered C states. The OS employs a conservative algorithm to cycle through C states starting with the lowest latency, highest power C 1  state when the processor has just become idle or is exhibiting relatively high utilization, in order to affect performance as little as possible. As the processor becomes more idle for another sampling interval, the OS may decide to promote to a higher C state, and the process repeats, moving to higher or lower numbered C states depending on idleness. In an idle system, it is quite common that the processor spends 99% of the time in the C 3  state.  
      C 3  is defined as a non-snoopable state. This means that the processor is unable to detect cache snoops while the processor is placed in C 3 . The OS is responsible for detecting bus master traffic through the ACPI defined bus master status bit, and disabling bus master traffic through the bus master arbiter disable bit before entering a C 3  state. The general idea is to avoid entering the C 3  state whenever there is bus master traffic occurring, because the long latency to exit C 3  with snoop traffic blocked can cause bus master overruns and underruns, depending upon the device characteristics and buffer capabilities. Unfortunately, the current bus master avoidance policy incorporated into the OS is inefficient in the presence of bus mastering devices. Thus an improved C state policy handler that resolves the problems associated with currently implemented algorithms is needed. 
    
    
     BRIEF DESCRIPTION OF THE DRAWINGS  
      Various features of the invention will be apparent from the following description of preferred embodiments as illustrated in the accompanying drawings, in which like reference numerals generally refer to the same parts throughout the drawings. The drawings are not necessarily to scale, the emphasis instead being placed upon illustrating the principles of the inventions.  
       FIG. 1  is a flowchart of an improved C state policy handler.  
    
    
     DETAILED DESCRIPTION  
      In the following description, for purposes of explanation and not limitation, specific details are set forth such as particular structures, architectures, interfaces, techniques, etc. in order to provide a thorough understanding of the various aspects of the invention. However, it will be apparent to those skilled in the art having the benefit of the present disclosure that the various aspects of the invention may be practiced in other examples that depart from these specific details. In certain instances, descriptions of well-known devices, circuits, and methods are omitted so as not to obscure the description of the present invention with unnecessary detail.  
      A method is described for entering a particular C state to save power based on bus master activities. The OS monitors processor idleness by taking timestamps of when the processor goes idle and taking another timestamp when the processor becomes busy. By accumulating deltas between the timestamps, the idleness of the processor can be calculated. On each entry into the idle loop, the OS enters a C state numbered C 1 , C 2 , C 3  in order to save power. The OS may decide to move to higher or lower numbered C states depending on idleness.  
      Since the C 3  state is a non-snoopable state, the OS is responsible for detecting bus master traffic through ACPI&#39;s bus mater status bit (BM_STS). Currently, the OS takes an instantaneous sample of bus master activity, just prior to attempting an entry into C 3 . Since the bus master status bit is sticky, the OS takes an instantaneous sample by clearing the BM_STS bit and immediately reading the bit back. If the BM_STS comes back clear, this implies that no bus master activity is occurring at this instant in time, and the OS will decide to enter C 3 . If the bit comes back set, this implies that bus master activity is occurring at this instant in time, and the OS demotes to C 2 .  
      By contrast, the present algorithm handles processor utilization by determining Idle% parameter and is not affected by BM_STS. Idle % is the percentage of time a processor has been idle across the last sampling interval. The present algorithm makes better sense as bus master traffic is not an indicator of processor utilization, and thus should not affect the target C state which is set through a promotion/demotion scheme based on processor utilization.  
      The current sampling policy is used only when the current C state has been promoted to C 3  and bus master activity has been detected since the last time BM_STS has been sampled. The C 3  target state is overridden by the C 2  state anytime bus master traffic has occurred since the last time BM_STS has been read and cleared. Instead of taking an instantaneous sample of bus master activity, the new algorithm uses the sticky nature of the BM_STS bit and reads it on every idle entry where the target is C 3 . If the BM_STS is set, the idle handler clears it and enters the C 2  state. If the BM_STS bit is clear, the idle handler enters C 3 . The difference being that the handler will enter C 2  only for one instance, but will still keep the target C state set to C 3 .  FIG. 1  illustrates this new method in more detail.  
       FIG. 1  is a flowchart of an improved C state policy handler. Initially, at step  100 , the OS determines if the CPU is idle. If the CPU is not idle, the OS will keep checking its status. However, if the CPU is idle, then at step  110 , the OS will accumulate the CPU&#39;s idle time as previously described. Next, the OS will determine the target state based on the CPU&#39;s idle time (step  120 ). If the idle time is within the C 1  target state (step  130 ), the system will enter Cl state (step  140 ). If the idle time is not in the target C 1  state, then the system will determine if the idle time is in the target C 2  state (step  150 ). If the idle time is within the C 2  target state, the system will enter C 2  state at step  160 . If the system is not in the C 2  state, then the OS will determine if the target time is in the C 3  state at step  170 . If is not in the C 3  state, the system will exit.  
      If the target state is C 3 , the OS will determine if the bus master is still active at step  180 . The OS will determine if the bus master is active by reading the bus master status bit on every idle entry where the target is C 3 . If the BM_STS bit is clear, the idle handler enters C 3  at step  190 . However, If the BM_STS is set, the idle handler clears it (step  200 ) and enters the C 2  state (step  160 ). The handler will enter C 2  only for one instance, but will still keep the target C state set to C 3 . The following examples illustrates the new algorithm.  
      As a first example, suppose there is a persistent bus mastering device that accesses memory every 1 ms for a short period of time. With the new algorithm, the processor will wake up from C 3  on the first bus master event, the idle handler will be re-entered (bus master traffic has ceased), the handler will sample BM_STS and see that bus master traffic has occurred since the last time it was read, the handler will clear it, and enter the C 2  state. In this case, the target state is still C 3  (C 3  will be immediately re-entered once the bus master stops), but the processor is able to remain in a snoopable state and sleep for longer intervals without waking up. Additionally, the bus mastering device does not see excessive delay to main memory. After the first occurrence, the algorithm effectively detects the bus master traffic pattern and remains in the C 2  state until the bus master traffic ceases. This policy dramatically improves the C state policy handling in the presence of bus mastering devices  
      In a second example, consider an intermittent bus mastering device that transfers a significant amount of data every 1 ms. In this case, the new algorithm will wake up from C 3 , sample BM_STS and detect that bus master traffic is occurring, and enter the C 2  state. While in the C 2  state, the bus mastering device runs unimpeded to main memory, and after the second exit from the C 2  state, the processor will quickly re-enter the C 3  state, rather than wait for a complete promotion interval. As a result of this change, the processor will spend a large amount of time in the C 3  state whereas with the current algorithm the processor would remain entirely within C 2 .  
      A final example is where a device transfers burst like traffic periodically. In this case, the algorithm would avoid re-entering C 3  state. As the periodic transfer initiates, the processor will exit C 3 , sample BM_STS and detect bus master traffic, and enter the C 2  state. Again, after one more exit from C 2 , the processor will re-enter C 3 . This is also a significant improvement over the existing algorithm by avoiding C 3  in a consistent fashion (only one latency event seen by device) only when absolutely necessary.  
      Advantageously, the present algorithm improves C 3  utilization (better battery life) and reduces bus master stress (delay to main memory), without affecting processor performance. The algorithm accomplishes this with the new sampling policy for BM_STS, and thus effectively decouples bus master traffic from the promotion/demotion scheme, which is now entirely based on processor idleness.  
      In the following description, for purposes of explanation and not limitation, specific details are set forth such as particular structures, architectures, interfaces, techniques, etc. in order to provide a thorough understanding of the various aspects of the invention. However, it will be apparent to those skilled in the art having the benefit of the present disclosure that the various aspects of the invention may be practiced in other examples that depart from these specific details. In certain instances, descriptions of well-known devices, circuits, and methods are omitted so as not to obscure the description of the present invention with unnecessary detail.