Power management tools for VIA KT266 and compatibles


1. Legal notice

   No warranties of any kind are made. In no event shall the author be liable
   for any damage resulting from use or misuse of this product, either direct
   or consequential. 

   The  trademarks   mentioned in this document   belong  to their respective
   owners.


2. Introduction 

   The  KT266[A]  chipset  from VIA  Technologies,   Inc.  provides a set  of
   facilities to prevent CPU overheating  and decrease the power consumption.
   In  systems like  Windows  and  Linux, these  facilities are  managed by a
   system  layer known as ACPI (Advanced  Configuration and Power Interface).
   In  OS/2, there is  no ACPI subsystem,  meaning  that the user will either
   have   to involve  APM  BIOS  facilities   or   install additional  system
   monitoring and power management software oneself.

   This package provides a set of tools to  operate KT266[A] power management
   features under OS/2:

   - VIAAPM.SYS:  cools down the CPU, provides kernel-mode fan control
   - APM_NH.SYS:  a version of APM.SYS compatible with VIAAPM.SYS
   - APMCTRL.EXE: a command-line control program for VIAAPM.SYS.

   OS/2 v 4.x or OS/2 v 3.0 with XR_W032 is required. VIAAPM.SYS will  run in
   all pre-XR_W032 versions of Warp 3 but then it could not be  controlled by
   means of APMCTRL.EXE.

   Scope of supported hardware:

   - VIA KT133 (ex-KZ133), KT133A, KX133, KM133, Apollo Pro 133. Support  for
     this  range  of chipsets  is experimental  and  is sometimes  bounded by
     hardware restrictions.

   - VIA KT266 and KT266A (8366[A] + 8233[A]). These were the original target
     platforms.

   - VIA KN266 (8372 + 8233A/8235).

   - VIA KT333 (8367 + 8233A/8235).

   ! VIA KT400 is  NOT supported. Some  earlier models, i.e. 8377 + 8235, may
     still work  but no further development is  planned to cover 8237 and its
     successors, unless  the  datasheets  are  publicly available.   Nor  the
     status is known for 8368, if one exists.

   For  a list  of  changes in  this  version, see the ChangeLog  file in the
   enclosed source code package.

   It is recommended that  you obtain StHwMon v  0.18  or higher,  a freeware
   utility by Stefan Milcke, in addition to  this toolkit, for monitoring the
   temperatures,  fan  speeds and  other   motherboard parameters.   Besides,
   StHwMon may be useful if you wish to keep  the CPU from reaching a certain
   temperature - there is a "smart" throttling algorithm for that.


3. Quick start

   There is no installation program. To use the CPU  cooling features, follow
   these instructions:

   1. Install VIAAPM.SYS in CONFIG.SYS:

      DEVICE=x:\OS2\APMTOOLS\VIAAPM.SYS

   2. If you were using  APM.SYS (e.g. for  the purpose of powering  down the
      computer), replace  its CONFIG.SYS entry  with APM_NH.SYS. For example,
      change:

      DEVICE=x:\OS2\BOOT\APM.SYS
      to
      DEVICE=x:\OS2\APMTOOLS\APM_NH.SYS

   3. Reboot.


4. VIA power management driver (VIAAPM.SYS)

   VIAAPM.SYS provides the following services:

   - CPU idle hook for APM KPI (APM_IdleHookRtn).
   - CPU throttling API.
   - Vendor-specific monitoring and tuning functions.

   The APM idle hook routine replaces the OS/2's standard idle operation (HLT
   x86 instruction). The reason for  it is that HLT  corresponds to ACPI "C1"
   level of  CPU operation (CPU still connected  to bus and consumes its full
   rated power).  The "C2" level, provided  by the idle hook, disconnects the
   CPU from its bus,  dropping the power  consumption by  about 10 times  and
   putting the CPU into so-called "Stop  Grant state".  CPU returns from this
   state in the same ways as from  "C1", therefore the performance losses are
   insignificant.

   If  it  happens that the system  comes  to  a  trap screen with REIPL=OFF,
   VIAAPM.SYS will intercept  the  trap handler  and  force ACPI C2  state to
   prevent the CPU from  overheating  (at the trap  screen  the CPU  runs  an
   eternal loop).  Similarly,  when a SYS1503  (swap file full) error occurs,
   the CPU is forced into  ACPI C3 state (stop CPU  clock) until RESET button
   on the system case is pressed. As OS/2 is not an ACPI-compliant system, it
   gives an advantage: there  are only hardware  ways left to exit  from ACPI
   C3.  An alternate function  of this driver is  to reboot on SYS1503, since
   OS/2 normally does  not reboot  regardless of REIPL  mode.   See below for
   /SYS1503.

   The "throttling API" enables the user to  slow down the CPU by selectively
   filtering  out   CPU clock cycles.    In KT266A   chipset, this method  is
   particularly useful  for cooling down the  8366 memory  controller ("north
   bridge") which imposes a noticeable source of heat besides the CPU.

   Furthermore, VIAAPM.SYS provides a kernel-mode system monitoring interface
   for several KT266[A]-based motherboards that have Winbond W83697HF chip.

   Options:

       /VERBOSE = Verbose  initialization. Tells to display the full progress
                  of startup.

       /SYS1503 = Reboot the system when SYS1503 comes up. This error message
                  is normally a "dead-end" regardless of whether REIPL=ON has
                  been specified in CONFIG.SYS. However, it is sometimes more
                  practical to  allow  the system restart  when the swap file
                  is full.

          /POST = Enable  real-time  display  of CPU temperature  on the POST
                  (power-on  self-test)  indicator, port 80h. The temperature
                  is measured 3 times per second, rounded down to one  degree
                  and  displayed in decimal  form on  the indicator. Use this
                  feature  if  you  have   an  external  POST card,  or  your
                  mainboard comes with a built-in  two-digit POST panel (e.g.
                  some EPoX and ABIT boards).

          /!HLT = Disable  automatic  HLT detection. This  would  revert  the
                  behavior  of VIAAPM.SYS  to  pre-2.00 level. On  some "133"
                  series chipsets  the HLT detection may not  be supported at
                  all, in this case the /!HLT switch won't have any effect.

   Notes:

   1. While  the KT266[A] errata does  not  mention any reliability  problems
      with "C2", VIA KT133, the predecessor of  KT266, imposes several  major
      interoperability restrictions:

        * Intermittent system  hangs when  a poor  power supply unit  is used
          (250W for a  typical  desktop  configuration).
        * AMD  Athlon  Model 4  processors  with  half-frequency  multipliers
          (7.5, 8.5 =  750/850 MHz) have their own problems entering the "C2"
          state.  Please  refer  to  the  technical  documentation  available
          from  your  CPU   and  motherboard   manufacturer if you experience
          stability problems.
        * Some  KT133A boards  are "optimized for  PCI bus performance" - see
          the corresponding topics in troubleshooting section (IDE problems).

   2. Several chipsets and motherboards  provide a BIOS  setting titled  "HLT
      enters  Stop Grant state". In  this  case,  VIAAPM.SYS is  not required
      unless you want to take advantage of throttling.

   3. The driver is hibernation-aware  and will restore  the power management
      configuration  when  exiting   from hibernation  or  trapdoor (with the
      exception that throttling  mode active  during shutdown is not restored
      and the CPU runs at  full speed). You may  also request resets manually 
      (see below for APMCTRL.EXE /RESET switch).


5. APM control program (APMCTRL.EXE)

   APMCTRL.EXE is a front-end  for VIAAPM.SYS. It can be  started with one of
   the following switches: 

   /RESET = reinitialize the chipset for ACPI  "C2" support and reinstall the
   kernel APM hook. Reports error if any problems were found. 

   /T = examine or start/stop CPU throttling.  There are 15 throttling levels
   (1 is the lowest, devoting only 0...6.25% of clock  ticks to CPU and 15 is
   the   highest,  meaning  93.75...100%).  Level  16  stands  for   "disable
   throttling and run CPU at 100% of its clock speed". Examples: 

	/T	Show if throttling is active
	/T:7	Set level 7 (about 43% duty cycle)
        /T:50%  Explicitly set the duty cycle
        /T:16   Disable throttling
        /T:100% Same as above

   /Q = query the chipset type.

   /SHOWFAN = display additional data  for fan  configuration. Used  together
   with /FAN:CTRL parameter.

   /FANS = query or set global fan configuration.  This is an option specific
   to the  Winbond   W83697HF  hardware monitoring  solution.   It   sets the
   hardware monitor sensitivity  to temperature changes during  the automatic
   fan  control course. The syntax  is /FANS:<step-up time>:<step-down time>,
   specifying the  periods of time (in 1/10th  second)  between  readjustment
   of fan  speed, upward and downward respectively.  For example, /FANS:20:50
   means  wait two  second before  spinning up and 5 seconds  before spinning
   down. Note: this parameter has  no  effect with /FAN:CTRL software-managed
   mode.

   /FAN[n][:<settings>] = query  or configure  a  specific fan.   This is  an
   option specific to the Winbond W83697HF hardware monitoring solution.  [n]
   is an optional number of fan socket (the  numbering starts with 1), and it
   can be  omitted to  point  to the "CPU  fan" which  is calculated  as  the
   fastest spinning fan  at startup time.   There are the following  possible
   settings: 

               	 RESET  Resets the fan to its 100% duty cycle and cancels any
                        other settings in effect.
     DUTY:<x>[:<y>][l]  Sets fan  duty cycle  to <x> (0 to 255). This cancels
                        the   software  control  mode  (CTRL).  An   optional
                        argument, <y>, specifies a divisor which can  be 1 to
                        255. Finally, adding  "l" to  the values switches the
                        fan control into low-frequency mode. Usually there is
                        no need for any parameters besides <x>.
           CTRL:<file>  Reads the fan control  graph from a  file, commencing
                        the  software control mode. See below for a dedicated
                        section on this topic.

   Examples of APMCTRL.EXE command-line:

                  /FAN  Display the current state of CPU fan.
                 /FAN2  Display the current state of fan 2.
           /FAN1:RESET  Reset fan 1, which is usually the same as CPU fan.
          /FAN:DUTY=11  Set duty cycle of CPU fan to 11/255 (roughly 4.3%).
        /FAN:DUTY=22:2  Set  duty  cycle  of  fan 1  to (22/255)/2, which  is
                        similar  to the  above, except  that  the duty  cycle
                        itself is longer.
        /FAN:DUTY=128l  Run at half of duty cycle, low frequency mode.
         /FAN:DUTY=255  Run at full duty cycle.
   /FAN:CTRL=c:\cfgs\fan.txt /SHOWFAN
                        Start software fan  control and display  the detailed
                        information about fan control setup.

   Tip: Both VIAAPM.SYS and APMCTRL.EXE provide some undocumented options for
   other  aspects of  fine-tuning.  See  the source code   for details. These
   options are intended for experienced users only.


6. Replacement APM driver (APM_NH.SYS)

   APM_NH.SYS is based on a pre-XR_D004 level of IBM's APM.SYS.  The specific
   job of APM_NH.SYS is to honor the APM hooks  installed by VIAAPM.SYS while
   allowing  usual APM   tasks such  as   power-down or suspend  mode.  It is
   therefore essential that  one installs APM_NH.SYS  rather than APM.SYS, so
   the KT266A idle hook would not be taken out by IBM's driver.


7. Setting up the software fan control on Winbond W83697[H]F

   This section describes setting up the software fan  control mode which can
   be advantageous for reducing the level of noise  and vibrations emitted by
   a running CPU fan. It should be noted  that software fan  control is to be
   avoided  for systems  running in unattended  mode, as it will  be rendered
   inoperable if any ill-behaved driver freezes the system.

   The fan  operation is  usually described  in terms  of "duty cycle", which
   reflects the amount of time when fan is powered by +12V DC relative to the
   amount of time when the +12V DC power supply is  not provided for the fan.
   The  interchange  of   power-on/power-off  states  at   a  relatively high
   frequency constitutes a  rough equivalent of  feeding the fan with reduced
   DC voltage.

   In  software control mode, VIAAPM.SYS queries  the CPU temperature roughly
   31 times per second  and compares it against  a temperature graph to  find
   out the corresponding fan duty  cycle. It then  checks if the current duty
   cycle can still be tolerated (hysteresis loop - see below); if no, the fan
   will be reprogrammed for new duty cycle.

   Notes:

   1. Always  perform  temperature  monitoring   when  experimenting with fan
      speeds! Low airflow volume may  result in malfunction of your CPU! This
      program is not suitable for unattended control of fan speeds!

   2. The  relation  of duty  cycle lenth  to the fan  rotation speed  is not
      linear. For example, a 7000 CPU fan at 10% (25 of 255) duty cycle won't
      yield 700 RPM but likely a  larger  value (about 4000 RPM, depending on
      the particular manufacturer).

   3. After dropping the speed to zero (i.e.  stopping  the fan), there  will
      probably  be  a  significant inactivity  range, where  the fan will not
      start. For example, running the following sequence:

      APMCTRL /FAN:DUTY=0
      APMCTRL /FAN:DUTY=7

      may leave the  fan stopped. However, going from  0 to 255 and then to 7
      will leave  it running at low speed.  It is better that rotation speeds
      within this inactivity  range are avoided. Most modern CPUs  are unable
      to cool down to their  allowed range of  temperatures without a running
      fan.

   4. Not all motherboards have  applicable chips for  fan speed control, and
      not every  motherboard is supplied  with W83697HF. It can be  confirmed
      that  EPoX 8KHA+ motherboard  has  one,  as do  the Shuttle  AK31/AK32;
      information regarding other manufacturers would be welcome.

   5. If your fan is plugged  into the 4-pin PC power connector, it cannot be
      controlled by software. The same usually applies to the onboard chipset
      fan, if  any. Besides, only  two  3-pin  connectors can  be managed  by
      W83697HF, so, if the motherboard offers  more, attention should be paid
      to choosing the right one for CPU fan (normally labeled "FAN1").

   6. The software fan control may  continue after  a trap  with REIPL=OFF if
      the interrupt handler survives. However it should not be counted upon.

   Now,  for a quick start, you  can take a  look at the CPU_FAN.CFG file. It
   shows a  sample configuration for a 7000 RPM Socket A CPU fan. The general
   considerations are as follows:

   1. The X axis reflects temperature (with granularity of 0.5C), the Y axis
      carries the  duty cycle  (0 to 255). The tick-marks  may be  in linear,
      logarithmic  or  any  other  scale you find  appropriate. The  distance
      between two adjacent tick-marks serves as  a linear  scale, e.g. in the
      following graph:

      255 +
      120 +
          |          *
      110 +
        0 +---+----+---+----+
             34   35   45  100

      the "*" point denotes 40C and duty cycle of 115.

   2. The graph scale is rather free-form, so you can just  mark the critical
      temperatures  and  duty cycle  values. In fact, the  following  will be
      sufficient:

          As stored in file:                   As parsed by APMCTRL:

      255 +            *                   255 +            * * * *
          |                		       |         *        
       11 +      *                  =>	    11 +* * * *           
          |                  		       |                   
        0 +------+-----+-----		     0 +------+-----+------
                40     65    		             40     65    

      The temperatures below the leftmost point use the same duty cycle value
      as for the  temperature in  leftmost point. The temperatures  above the
      rightmost point use the same duty cycle value as in rightmost point.

      Tip: Use  the /SHOWFAN parameter  together with /FAN:CTRL=<filename> to
      learn about the exact duty cycle values calculated by APMCTRL.

   3. Now, it may turn out  that the  fan does  not run  smoothly  at several
      duty  cycle values (usually noticed  by excessive  vibration or noise),
      while it runs perfectly at some lower or higher values. This is usually
      the case  with 7000 RPM  fans. So it means that in  lower RPM area, the
      graph may be limited to a  set of "reliable" duty cycle values (usually
      found through manual adjustment with APMCTRL /FAN[n]:DUTY=<x>):

      128 +                            *
       64 +                        *
       32 +                    *
       14 +               *
       11 +       *   *
        3 +   *
        0 +---+---+---+---+----+---+---+
             40  40.5 43  43.5 47  50  60

      It tells to use the lowest possible duty cycle,  3, for temperatures of
      +40C and below, but  at +40.5C it will  immediately switch from 3  to
      11, and run at that duty cycle up to +43C, switching to the next grade
      at +43.5C.  Note  the 0.5C steps -  they  prevent  APMCTRL from using
      approximate (noisy) values  between  the two  tick-marks. Then,  beyond
      duty cycle of 14, we do not care any longer about duty cycle values, as
      fan should run pretty smooth at higher spin rates.

   4. Finally, a hysteresis loop  is possible - when the CPU cools  down, its
      fan might be  left  running  at  higher speed  unless some  appreciable
      temperature has been achieved. For hysteresis  loops, there are two new
      markers: "^"  (temperature  rise  course)  and  "v"  (temperature  fall
      course). Example:

          As stored in file:                   As parsed by APMCTRL:

      255 +        v v *                   255 +        vvvv* * * *
          |                		       |       v   ^      
       11 +      * ^ ^              =>	    11 +* * * *^^^^       
          |                  		       |                   
        0 +------+-----+-----		     0 +------+-----+------
                40     65    		             40     65

      Normally, the "^" markers  should  lie  below the "v"  markers  at  the
      same temperature. The "*" can be thought of as "v" and "^" combined  in
      one point.

   When  you have finished  with  temperature control  course setup, you  can
   modify CONFIG.SYS to enable automatic fan control at system startup:

   DEVICE=C:\OS2\BOOT\VIAAPM.SYS
   CALL=C:\OS2\OS2TOOLS\APMCTRL.EXE /FAN:CTRL=C:\CFGS\CPU_FAN.CFG

   Tip: The closer these lines  are  to  the  beginning  of  CONFIG.SYS,  the
   earlier will software fan control take over during startup. Sometimes it's
   beneficial  to  let  VIAAPM.SYS load before  mounting of other  volumes is
   demanded  and  CHKDSK starts, so the CPU  will already be  in power-saving
   mode during CHKDSK.


8. Troubleshooting suggestions

   Problem:   the driver traps  or   complains about  unknown  chipset during
   startup.

   Solution:

        1. Ensure that you  have the appropriate chipset. Contact the  author
           if  your chipset is   claimed  to be  supported by  this  program.
           Please  include a list of PCI device IDs in  your system. The tool
           to obtain this list is available at:
           http://hobbes.nmsu.edu/pub/os2/util/misc/pci047vk.zip
        2. Some systems, while generally compatible, have permanent  hardware
           limitations, which result in a reboot shortly after the ACPI C2 is
           enabled. Consult your vendor to ensure your system meets the power
           and configuration guidelines for ACPI compliance.


   Problem: the device driver does not cool down the CPU.

   Solution:

        1. Make sure you don't have IBM's APM.SYS  installed - it provides an
           an idle  hook of its own, conflicting  with VIAAPM.SYS. See  above
           for instructions on replacing APM.SYS.
        2. Check if the CPU is  really  idle for appropriate time - use Pulse
           or WarpCenter to determine the CPU load.
        3. Try APM /T:1 to see if  throttling works (if  it works, the system
           will be considerably slowed down). If the throttling does not work
           too, you may be using an incompatible revision of chipset.


   Problem: lockups on KT133 when VIAAPM.SYS is loaded

   Solution:

        1. VIAAPM.SYS  might  not  reliably  operate  on AMD  Athlon  CPUs at
           550/650/750/850/950 MHz.
        2. Ensure that your  power  supply unit  is capable  of dealing  with
           flux of CPU power consumption (9 to 70W).
        3. AMD  Athlon  "Model 4" (650...1000  MHz) has  a  reconnect  timing
           problem. Refer to AMD technical note #24478.
        4. KT133A only: if the IDE  subsystem is failing after  the driver is
           installed (e.g. failure to load a particular driver), follow these
           guidelines:
              1. Run BIOS setup.
              2. Disable "PCI Delay Transaction".
              3. Disable "PCI master READ caching".
              4. Set "PCI Latency" to 0.


   Problem: poor performance - /T:10% seems to be  much less than  actual 10%
   of the full performance!

   Solution: This is  explained by the fact how  throttling works. It is  not
   like running at  the exactly reduced frequency -  instead it runs your CPU
   at full frequency  for several thousand cycles,  then stops its  clock for
   another several thousand  cycles. This  prevents  the CPU  from accurately
   handling microsecond delays associated  with I/O, which in turn  decreases
   the overall responsiveness of the system. 

   There is no  method of selecting the  actual throttling  rate to meet  the
   needs of a specific task.   For example, programmable I/O operations, such
   as  parallel port   transfer, demand  full CPU  power   regardless of  CPU
   frequency.  Therefore,  the only  appropriate action  in this case   is to
   decrease the CPU frequency  via front-side bus, which is  an  undocumented
   vendor-specific feature not discussed in the present document.


   Problem: No effect on KT333 mainboards

   Solution:

        1. Try reinitializing the driver after OS/2 system starts. Type:
           APMCTRL /RESET
           from the OS/2 command prompt, then run a  hardware monitor program
           to ensure that the CPU is now being cooled adequately.
        2. If the step 1 ended up with success, you may use one of three ways
           to complete the initialization:
           (a) from the CONFIG.SYS, with "CALL=<path>\APMCTRL.EXE /RESET"
           (b) from STARTUP.CMD, by adding a line that reads "APMCTRL /RESET"
           (c) from the WPS startup folder, by creating a program object.


9. Contacting the author 

   The author can  be contacted at <andrew_belov@newmail.ru>. Improvements to
   this software package are welcome; if you add support for a specific chip,
   please send in the corresponding source code patch.

   $Id: readme.txt,v 1.16 2004/10/14 15:36:32 root Exp $ 
