apache
[Top] [All Lists]

Re: 10xpatch & FreeBSD

To: mja@xxxxxxxxxxxxxxxxxxx
Subject: Re: 10xpatch & FreeBSD
From: Alexander Leidinger <Alexander@xxxxxxxxxxxxx>
Date: Thu, 18 May 2000 15:45:40 +0200 (CEST)
Cc: apache@xxxxxxxxxxx
In-reply-to: <200005180519.WAA71408@xxxxxxxxxxxxxxxxxxx>
Sender: owner-apache@xxxxxxxxxxx
On 17 May, Mike Abbott wrote:
>> I had to add "|| defined(__i386__)" into the
>> conditional in src/main/qsc.c at line 185 (the conditional just before
>> the qsc_cas function):
> 
> This is incorrect.  The cmpxchg instruction exists only on i486 and
> later processors.  Using this instruction on an i386 will cause an
> illegal instruction trap.  Perhaps you need to define __i486__ or
> __i586__ or __i686__ etc. during your build.  I did, on Linux.

It seems gcc has a bug regarding the definition of those defines.

A litte test program:
---snip--(t.c)-
#include <stdio.h>

int main(void)
{
#ifdef __i386__
  printf("i386: %d\n", __i386__);
#endif
#ifdef __i486__
  printf("i486: %d\n", __i486__);
#endif
#ifdef __i586__
  printf("i586: %d\n", __i586__);
#endif
#ifdef __i686__
  printf("i686: %d\n", __i686__);
#endif
#ifdef __pentium__
  printf("pentium: %d\n", __pentium__);
#endif
#ifdef __pentiumpro__
  printf("pentiumpro: %d\n" __pentiumpro__);
#endif
}
---snip---

The tests (the first CFLAGS setting is a subset of the CFLAGS setting
I've used to compile apache+10xpatch):
---snip---
(23) netchild@ttyp1% CFLAGS=-march=pentiumpro gmake t
cc -march=pentiumpro    t.c   -o t

(24) netchild@ttyp1% ./t
i386: 1

(27) netchild@ttyp1% CFLAGS=-m486 gmake t            
cc -m486    t.c   -o t

(28) netchild@ttyp1% ./t                 
i386: 1
i486: 1

(31) netchild@ttyp1% CFLAGS=-mpentium gmake t
cc -mpentium    t.c   -o t

(32) netchild@ttyp1% ./t                     
i386: 1
i586: 1
pentium: 1

(34) netchild@ttyp1% CFLAGS=-march=pentium gmake t 
cc -march=pentium    t.c   -o t

(35) netchild@ttyp1% ./t                          
i386: 1

>From the info page of gcc (order rearranged to explain the above tests):
---snip---
`-march=CPU TYPE'
     Generate instructions for the machine type CPU TYPE.  The choices
     for CPU TYPE are the same as for `-mcpu'.  Moreover, specifying
     `-march=CPU TYPE' implies `-mcpu=CPU TYPE'.

`-m386'
`-m486'
`-mpentium'
`-mpentiumpro'
     Synonyms for -mcpu=i386, -mcpu=i486, -mcpu=pentium, and
     -mcpu=pentiumpro respectively.  These synonyms are deprecated.
   
`-mcpu=CPU TYPE'
     Assume the defaults for the machine type CPU TYPE when scheduling
     instructions.  The choices for CPU TYPE are:

     `i386'        `i486'        `i586'        `i686'
     `pentium'     `pentiumpro'  `k6'          

     While picking a specific CPU TYPE will schedule things
     appropriately for that particular chip, the compiler will not
     generate any code that does not run on the i386 without the
     `-march=CPU TYPE' option being used.  `i586' is equivalent to
     `pentium' and `i686' is equivalent to `pentiumpro'.  `k6' is the
     AMD chip as opposed to the Intel ones.
---snip---

It seems the conditional upon which the i386 qsc_cas function is build
isn't a good solution because gcc (2.95.2 19991024) seems to have bugs
regarding the definition of the i?86 defines. IMHO it isn't good
practice to define a __i?86__ define by myself, they are reserved
defines of the compiler, so I propose the following patches:
---snip---
--- qsc.c.org   Thu May 18 15:22:35 2000
+++ qsc.c       Thu May 18 15:23:25 2000
@@ -181,9 +181,7 @@
  */
 #  define qsc_cas(p, oldval, newval)   __compare_and_swap(p, oldval, newval)
 # endif
-#elif defined(__GNUC__) && __GNUC__ >= 2 && \
-    (defined(__i486__) || defined(__i586__) || defined(__i686__) || \
-    defined(__pentium__) || defined(__pentiumpro__))
+#elif defined(__GNUC__) && __GNUC__ >= 2 && defined(QSC_IA32_CAS)
 /*
  * Use asm statement copied from Linux libpthread's __compare_and_swap().
  */
---snip---

---snip---
--- qsc.html.org        Thu May 18 15:24:30 2000
+++ qsc.html    Thu May 18 15:33:43 2000
@@ -142,6 +142,12 @@
   $ make
 </PRE>
 <P>
+On x86 processors (x &gt;= 4) you have to use:</P>
+<PRE>
+  $ CFLAGS="-DUSE_QSC -DQSC_IA32_CAS" configure --enable-module=mmap_static
+  $ make
+</PRE>
+<P>
 (The QSC is an enhancement to core Apache, while mmap_static is an 
 Apache <A HREF="mod/index.html">module</A>.) There are also advanced 
 options to controlling QSC behavior, described <A 
HREF="#advanced">below</A>.</P>
@@ -600,7 +606,7 @@
 <H2>
 <A NAME="advanced">Advanced Options</A></H2>
 <P>
-All of the following are compile-time options. The first two must be 
+All of the following are compile-time options. The first 3 must be 
 defined manually. The rest are defined in the QSC source code.</P>
 <TABLE BORDER="1" WIDTH="100%">
     <TR>
@@ -610,6 +616,14 @@
             Default: <CODE>USE_QSC</CODE> is not defined so the QSC is 
             disabled.</TD>
     </TR>
+        <TD WIDTH="25%"><CODE>QSC_IA32_CAS</CODE></TD>  
+        <TD><P>
+            Needed on the ia32 architecture (x86 processors, x &gt;= 4)
+            for an atomic compare and swap function.</P>
+            Default: <CODE>QSC_UA32_CAS</CODE> is not defined so you
+            get an error on x86 processors. Unfortunally a bug in
+            gcc disables the possibility to detect the processor type
+            at compile time.</TD>
 </TABLE>
 <H3>
 <A NAME="debug">Debugging</A> / Additional Information</H3>
---snip---

> --
    ^ It seems you have forgotten to add a space after the two dashes.
> Michael J. Abbott        mja@xxxxxxx        http://reality.sgi.com/mja/

Bye,
Alexander.

-- 
            The dark ages were caused by the Y1K problem.

http://www.Leidinger.net                  Alexander+Home @ Leidinger.net
  GPG fingerprint = 7423 F3E6 3A7E B334 A9CC  B10A 1F5F 130A A638 6E7E


<Prev in Thread] Current Thread [Next in Thread>