
mTCP Power Management Notes
Michael Brutman, May 2012



Below are my rough notes on power management options and why I
implemented what I did in mTCP.


Power saving stategy

  When the user application decides to poll to see if new packets are
  available to process the macro that does the checking can decide to
  make sleep calls or not.  If there is a packet there to process the
  sleep call is not made, as the application probably has some real work
  to do.  If no packets are found then a sleep call is made.


The sleep mechanisms

  Int 0x28

    Int 0x28 is the DOS "idle" call.  When DOS is reading the keyboard
    it makes this call, with the expectation that TSRs will hook int 0x28
    and use it as a signal that it is a good time to do some background
    work.

    Usually DOS is the only "caller" of int 0x28 and TSRs are supposed to
    hook it.  However, an application can call int 0x28 for the same reason
    that DOS does - to signal to TSRs that there is some idle time to do
    some work.  This usage of int 0x28 is controversial but after doing a
    lot of reading of old archived newsgroups and web pages and doing a
    few experiments I think it is a good thing to do for the same reason
    that DOS does it - to tell TSRs that there are some CPU cycles
    available for background processing.

    mTCP always calls int 0x28 if it polls for a packet to work on
    and does not find anything.

    The FDAPM utility with the APMDOS option is an example of a power
    management utility that detects the usage of int 0x28 and adjusts
    power settings accordingly.


  Int 0x2F function 0x1680

    This is the "Release time slice" signal used by DPMI and Windows.
    This should be used when the application does not have real work
    to do and it can give the CPU to another application.

    If you call this and get a zero back in AL the call is supported
    and it might do something useful.  If you get 0x80 back in AL then
    the call is not supported.

    mTCP calls this once at startup to test if it is available.  If it
    is available it will be called at the same time the int 0x28 call
    is made.  Otherwise, it will be skipped.

    This call is supported by Windows 3+, DOS 5+, DPMI and OS/2 2.0+.
    The affect can be seen when using mTCP applications under Windows
    XP with SwsVpkt.


Disabling power saving

  In the off chance that you think these calls are getting in the way
  of real work or compatibility you can turn them off at run-time using
  the MTCPSLEEP environment variable, or compile the code out entirely.
  If you want to use the environment variable set MTCPSLEEP to zero.

  The default is that they are on and enabled if supported.  (Int 0x28
  is always used; int 0x2f function 0x1680 is used if available.)


Power management and older hardware

  Older machines like the original IBM PC 5150, the PCjr, and the PC AT,
  and the various clones probably don't care if you try to be nice and
  save power.  The clocks run fairly slow and these processors don't
  generate a lot of heat.

  Still, you want to do the int 0x28 call to be nice to TSRs that might
  be looking for it.  Otherwise they are limited to whatever CPU time
  they feel they can use safely during the timer tick interrupt.


Power management and newer hardware

  If you are using a real machine (like a laptop) or a virtual/emulated
  machine that can benefit from power management then you should use it.
  You will either save power or make CPU time available for other, more
  useful things.  The effect on mTCP applications is minimal.

  For example, when running DOS in a virtual machine like VirtualBox or
  VMWare you can expect the virtual machine software to consume a full
  CPU core.  This is normal for DOS when no power management software is
  loaded; it is probably busy polling the keyboard.  Loading power
  management software in the virtual machine will modify the behavior
  of DOS and the applications slightly, allowing the virtual machine
  software to not use a full CPU core.

  DOSBox is the exception - it seems to be doing something right
  all on its own.  No power management software is needed when using
  DOSBox.


Notes on specific power management programs

  FDAPM

    In FreeDOS running under VirtualBox there will be one CPU core
    fully utilized even if the virtual machine is doing nothing.
    Running FDAPM with the APMDOS option will bring the CPU utilization
    of the host machine down to nearly nothing.  Those are now free CPU
    cycles for you to use!  FDAPM keys off of the int 0x28 calls.

    Although FDAPM is shipped with FreeDOS it should be usable on any
    version of DOS.

  POWER 

    Using POWER.EXE with PC-DOS and MS-DOS works while you are at the
    DOS command line but it does not work while mTCP applications are
    running.  In VirtualBox it is worse - the current version of
    VirtualBox must have a bug because when POWER.EXE is loaded the
    FTP client will freeze and hang.

  DOSIDLE

    DOSIDLE seems to work really well - even if you disable the mTCP
    sleep calls it still reduces CPU utilization dramatically.


