From tmcwill@iat.holonet.net Tue Oct  5 19:05:11 EDT 1993
Article: 1644 of comp.os.linux.development
Newsgroups: comp.os.linux.development
Path: samba.oit.unc.edu!concert!gatech!howland.reston.ans.net!agate!iat.holonet.net!tmcwill
From: tmcwill@iat.holonet.net (Thomas McWilliams)
Subject: [PATCH] BogoBoost speedup for Linux
Message-ID: <CEFu8D.Aun@iat.holonet.net>
Organization: HoloNet National Internet Access System: 510-704-1058/modem
Date: Tue, 5 Oct 1993 19:02:35 GMT
Lines: 139

BogoBoost (tm) is a patch to the Linux kernel setup code that will
boost your system performance. Generally speed increases on the
order of 2 percent to 5 percent are typical. It is based on the time
tested technique of resetting the DRAM refresh timer to an optimal
rate. When used within its guidelines it is perfectly safe. This
technique is in well documented, and has been in widespread use for
many years (see PC Magazine July 1988). Be that as it may I still
must offer the following caveat:

WARNING: There are no guarantees that this patch won't cause your
system harm. It may cause parity errors which will cause your system
to halt, possibly leaving your file system in an indeterminate
state. If you have any doubts, turn back now. If your system is
flaky, don't complicate matters by using this patch. I take no
responsibility for any harm this patch may cause you. Use at your
own risk. MAKE SURE THAT YOU HAVE A GOOD IMAGE TO BOOT FROM IN
CASE OF TROUBLE. You have been warned.

 HOW IT WORKS
 ------------

The greater part of your system memory is composed of DRAM. DRAM
memory is composed of rows upon rows of tiny capacitors that can
store an electrical charge. But these capacitors are not perfect.
They will slowly lose their charge over the time period of a few
hundreds of microseconds. Because of this, your computer must stop
whatever it is doing every few microseconds in order to re-charge
these tiny capacitors. If this memory "refresh" occurs more than
necessary, your computer performance suffers. But if the time
between refresh cycles is too long, you will have corrupted memory.

When the original IBM PC was designed 12 years ago, memory
technology was much cruder. The very earliest IBM PCs shipped with
only 16K bytes of relatively slow DRAM. A very, very conservative
refresh rate was chosen for the IBM PC, about 15 microseconds.
Although DRAM technology is now highly refined, with higher density,
greater yield, and consistency of product, we are still constrained
by a the de facto standard refresh rate of 15 microseconds.

With fast, modern SIMM and SIPP DRAM memory systems a more
reasonable refresh rate is in order. This is accomplished by
changing the time constant that controls the refresh timer. The
refresh timer determines how often your system will be interrupted
to perform memory refresh. The BogoBoost patch changes the refresh
rate during Linux startup to something more reasonable.

What is the optimal refresh constant to feed the timer? The nature
of the refresh system is such that after a certain point, further
increases in the refresh constant cease to yield increases in system
speed. The performance curve becomes asymptotic at this point. The
real beauty is that the constant converges to its optimal value
several orders of magnitude before any danger point is reached. For
most systems this new timer constant is between 200 and 400. Note
that stock refresh constants are set to 18 or 19. On my system,
instability does not occur until the refresh constant is set above
5000. But because the performance curve reaches asymptote at between
200 and 400, further increases offer no benefit. The optimal setting
offers a better than ten-fold margin of safety.
 
The BogoBoost patch sets this constant to 400. But if you are timid
you might want to try lower values. The code works as follows:

1) The timer port is given a control byte to set its operational mode.
   (This byte is fixed and never should be changed).
2) Next, the low-order byte of the constant is output to the timer.
3) Then the high-order byte of the constant is output to the timer.

Although the value 400 seems to give good, safe performance, here is
a table of hexadecimal byte values that you might want to try:

       constant     low-byte   high-byte 
         600          0x58       0x02 
         400          0x90       0x01 
         300          0x2c       0x01 
         200          0xc8       0x00
         100          0x64       0x00
          50          0x32       0x00

Slower machines will generally show the more dramatic boost in
speed. Actual real-world performance as exhibited by compile
times on large, long builds may actually be slightly better
percentage-wise than the BogoMips improvement would suggest. While a
few percent boost in performance may not seem significant, when used
in conjunction with other system tweaks, the total performance boost
will be the compounded product of each tweak multiplied together.

  OTHER TWEAKS
  ------------

Your CMOS setup is another good place to examine when searching for
performance improvements. Pay particular attention to the options
provided for memory wait states, interleave, and refresh width.
Systematically explore each option, measuring the performance each
time you vary a selection. If your plug-in cards can handle it, you
may be able to change your system bus to run at a higher speed.
Also verify that your turbo switch is working and that its cable is
firmly connected to the motherboard.

  THE PATCH
  ---------

The file to be patched is setup.S. This file is located in the kernel
directory /usr/src/linux/boot. After successfully applying the
patch, recompile your kernel. Make sure that you have an emergency
image for booting your system in case there is trouble. Boot with
your old image and note the BogoMips. Now boot with the your new
faster kernel and compare the BogoMips to your old value. You should
see a speed increase of between 2 and 5 percent. Some systems may
actually show more dramatic improvement.

enjoy,

Thomas McWilliams
tmcwill@holonet.net
thomas.mcwilliams@f615.n109.z1.fidonet.org

*** boot/setup.S~       Thu May 13 12:19:57 1993
--- boot/setup.S        Tue Oct  5 14:18:17 1993
***************
*** 91,96 ****
--- 91,105 ----
        mov     [4],bx          ! bh = display page
        mov     [6],ax          ! al = video mode, ah = window width
  
+ ! Set optimal DRAM refresh rate 
+               
+       mov al,#0x74            ! control byte
+       out #0x43,al
+       mov al,#0x90            ! low-order data byte 
+       out #0x41,al    
+       mov al,#0x01            ! high-order data byte 
+       out #0x41,al
+ 
  ! Get hd0 data
  
        xor     ax,ax           ! clear ax





