Sun Java Solaris Communities My SDN Account Join SDN
 
Article

Technical Case Study: Porting Apache Web Server on Solaris OS From SPARC Platforms to x86 Platforms

 
By Amjad Khan, August 2003  

Contents

Background
The Apache Web Server is a platform commonly used to host web sites. As Apache is open source software, its source code can be compiled and installed on most of the available operating system platforms. The Apache Software Foundation recently released the latest Apache Web Server source (version 2.0.45) for download on its web site.
This case study was undertaken to cover the various aspects of building and installing the Apache Web Server source on both platform editions of the Solaris OS. It compares the build on both the SPARC and x86 platforms, and it offers an analysis of issues that came up during the compilation of source code.

In this case study, the build script for building the Apache web server uses platform-specific back-end compiler options to generate the optimized binaries for the Solaris OS, SPARC Platform Edition. When the same build script is used to compile the source code on the Solaris x86 Platform Edition, these platform-specific back-end compiler options are checked for their utilization on the x86 version.
 

Back to top

Hardware and Software Environment
Source Platform
Machine:
Sun Ultra Enterprise 450 server
Processor:
4 processors (UltraSPARC chips)
Memory:
1024 MB RAM
Operating system:
Solaris 9 OS, SPARC Platform Edition
Application:
Apache Web Server (httpd) 2.0.45
Language:
C
Build tools:
Shell, make, sed, and awk
Compiler:
Sun ONE Studio 8, Compiler Collection
 
Target Platform
Machine:
550-MHz server
Processor:
Single-processor (Intel Pentium III)
Memory:
128 MB RAM
Operating system:
Solaris 9 OS, x86 Platform Edition
Application:
Apache Web Server (httpd) 2.0.45
Language:
C
Build tools:
Shell, make, sed, and awk
Compiler:
Sun ONE Studio 8, Compiler Collection
 

Back to top

The Apache Web Server 2.0.45 source was downloaded in a compressed tar file from the Apache web site. After extracting the downloaded tar file in a tmp directory, a series of steps were followed for compiling and installing the build on the machines running on SPARC and x86 technology. The study used the C compiler found in the Sun ONE Studio 8, Compiler Collection developer tools, as this compiler is supported on both the SPARC and x86 platform editions of the Solaris OS. This compiler contains different option flags for optimizing the code for both platform editions, and you can use it to port source code from one platform to another.
 

First the code was built on the SPARC platform, by following these steps:

  1. configure
    This is a shell script generated by the GNU autoconf utility to configure values for system-dependent variables and create Makefiles. It was used for configuring the Apache source tree, as follows:
          CFLAGS=" -xparallel -fast -xtarget=ultra -xarch=v8plus" \
          LDFLAGS=" -xparallel -fast -xarch=v8plus" \
          ./configure --prefix=/home/testuser/apache/apache2
    
    Here CFLAGS represents options for the C compiler, LDFLAGS are options to be passed to the linker, and --prefix specifies the directory in which to install the Apache files. If not specified, the default is /usr/local/apache2.

    The compiler flags were put in explicitly using the environment variables CFLAGS and LDFLAGS. These flags were used for back-end optimization of code on the SPARC platform:

    • -xparallel was used to parallelize loops for faster performance.


    • -fast is a specially optimized macro option that closely binds the intermediate code generated by the compiler front end to take advantage of the underlying hardware in order to enhance the performance of the application.


    • -xtarget=ultra was used to specify the exact target system for instruction set and optimization. It overrides some of the values specified by the option -fast.


    • -xarch=v8plus was used to override the -xarch option used in the -xtarget macro, because this value is more suitable for enabling the compiler to generate code for good performance on the SPARC architecture.

    The configure utility checked for the path of the build tools that were to be used during the build, and it also verified that the tools worked in the path specified in the PATH environment variable. The utility configured the APR (Apache Portable Runtime) library used for implementing Apache-specific calls in the native implementation of the OS platform.

    configure checked for various executables like gcc and cc, along with the basic options make, awk, ld, sed, and so on. It verified the presence of different header files that would be used during the compilation of the source code. These included header files for libraries implementing threads, shared memory, processes, locking, and networking support (including IPv6). It also read all environment variables that had been set. Finally, the utility created Makefile for each module of Apache Web Server.

  2. make
    The make utility built the various modules and components that form the Apache Web Server package. The compilation process involved basic options for compiling, as well as some platform-specific back-end optimization options, as provided in the environment variable CFLAGS and LDFLAGS. During the compilation process under the make tool, the following warnings were generated when using the optimization flags:

    cc: Warning: -xarch=native has been explicitly specified, or implicitly specified by a macro option, -xarch=native on this architecture implies -xarch=v8plusa, which generates code that does not run on pre UltraSPARC processors

    This warning occurs due to the option -fast, which expands to -xarch=native, and says to optimize code for the native architecture. But this flag is overridden by -xarch=v8plus, to generate code for good performance on the SPARC architecture.

  3. make install
    The make utility uses this option to install the Apache package in the path specified by the option --prefix, during the configure process. This option installed all the executables, libraries, configuration files, documentation, man pages, and so on, in the path specified. This was the final step in the process and the Apache Web Server was installed successfully.

Back to top

Differences in Compiler Options Used

The compiler flags used to compile the application on the SPARC platform were as follows:

  • -xparallel: A macro equivalent to -xautopar, -xdepend, and -xexplicitpar. This option is used to parallelize loops specified automatically by the compiler and explicitly by the programmer. For faster code, this option is used for a multiprocessor machine. If optimization level is not at -xO3, it is raised to that level and a warning is issued.

  • -fast: This macro specifies a collection of options for optimizing the execution of applications. This macro expands to:

    -fns, -fsimple=2, -fsingle, -ftrap=%none, -xalias_level=basic, -xarch=native, -xbuiltin=%all, -xdepend, -xlibmil, -xmemalign=8s, -xO5, -xprefetch=auto, explicit -xtarget=ultra

    The -fast option is used to specify the target system for instruction set and optimization. In this case study, the machine used has value SUNW,Ultra obtained by the command uname -i. That's why -xtarget=ultra and -xarch=v8plus are being used to override these values in the -fast macro.

  • -xtarget=ultra: This option specifies the target platform for instruction set optimization. Each value of -xtarget expands into a specific set of values for the -xarch, -xchip, and -xcache options. The reason to use this option was to override the -target option used in the -fastoption because, based on the target machine, this value is more suitable for enabling the compiler to generate code for good performance on the UltraSPARC architecture.

    When the value of -xtarget is set to ultra then this option expands to:

    -xarch=v8plusa -xchip=ultra -xcache=64/32/4:8192/512/2

  • -xarch=v8plus: This specifies the target instruction set architecture (ISA). This option was used to override the -xarch option used in the -xtarget option because this value is more suitable for enabling the compiler to generate code for good performance on the V8plus ISA.
The abovementioned compiler options worked correctly for the SPARC version, but if the same macros or compiler flags need to be used on the x86 architecture, then not all of them will be supported by the x86 platform. However, sometimes the same macro or option can be used on x86 but with different values.
 

Some of the SPARC options used to compile the Apache Web Server in this case study can be used on the x86 platform, but with different values. The options that can be used on the x86 version of the compiler are as follows:

  • -fast: The purpose of using this option in x86 architecture is not different from the SPARC compiler version, but it expands to a different set of values on the x86 version. On x86, this macro is the equivalent of:

    -fns -fsingle -ftrap=%none -nofstore -xarch=native -xbuiltin=%all -xdepend -xlibmil -xO5

  • -xtarget=pentium_pro: This option is used to specify the target system for instruction set and optimization. In this case study, the processor used on the x86 machine is a Pentium III processor that falls in the Pentium_Pro processor family. The -xtarget macro expands to:

    -xarch=pentium_pro -xchip=pentium_pro -xcache=generic

Back to top

Building the Application on Solaris 9 OS, x86 Platform Edition

The same steps were followed on the x86 machine:

  1. configure
    First the configure utility was run without any modification in the flags what had been used for the SPARC version to obtain the Makefiles. This was done as follows:
    CFLAGS=" -xparallel -fast -xtarget=ultra -xarch=v8plus" \ 
    LDFLAGS=" -xparallel -fast -xarch=v8plus" \ 
    ./configure --prefix=/home/testuser/apache/apache2 
    
  2. make
    Then make was used to build the application from the source code. When the same compiler flags were used on the x86 machine, the option -xparallel was ignored, while the options -xarch, -xtarget gave the following compiler warnings:
    cc: Warning: illegal option -xtarget=ultra4 
    cc: Warning: illegal option -xarch=v8plus 
    
    To prevent these warnings, a different set of compiler flags was used on the x86 platform. See the Solution for Solaris OS, x86 Platform Edition section for the compiler flags used.

  3. make install
    The next step, make install, installed the Apache package in the path specified by the option --prefix during the configure process.

    Solution for Solaris x86:
    When built using the flags given by the SPARC version compiler, the source code gave a warning that improper options had been used. To compile the source on the x86 machine, the flag values were changed to:
    CFLAGS= -fast -xtarget=pentium_pro -xarch=pentium_pro
    LDFLAGS= -fast -xarch=pentium_pro \
    ./configure –prefix=/home/testuser/apache/apache2
    
    The explanation of these options is:

    • -fast: This macro differs from the SPARC platform in the options it expands to.

    • -xtarget=pentium_pro: This option optimizes code for the pentium_pro architecture, since the processor used in the machine (Pentium III 550- MHz) for the case study belongs to the P6 (Pentium Pro) family.


    After we chose these compiler flags, the build successfully completed on the x86 machine without any further compiler warnings.

Back to top

Testing the Compiled Application
After the build of the Apache Web Server was complete on both the SPARC and x86 platforms, a PERL script file sample.pl was run on both platforms. The source code of the script is provided below:
 
#!/usr/local/bin/perl
# get the date!
&get_date; 
 
print "Content-type: text/html\n\n";
print "<font face=Verdana size=2>";
print "$thedate\n";
print "</font>";
sub get_date
{


  
    # assign the variables their respective values from localtime()
    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

    # assign the arrays their values
    @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');

    @months = ('January','February','March','April','May','June','July',
    'August','September','October','November','December');

    # Parse the variables for the output

    if ($sec < 10) {

        $sec = "0$sec";

    }

    if ($min < 10) {

        $min = "0$min";

    }
    if ($hour < 10) {

        $hour = "0$hour";

    }
    if ($mon < 10) {

        $mon = "0$mon";

    }
    if ($mday < 10) {

        $mday = "0$mday";

    }

# set final scalars then set the final date
$month = ($mon + 1);
$year = $year + 1900;
$thedate = "$months[$mon] $mday, $year $hour\:$min";
} 
 
This PERL script file was placed in the cgi-bin directory of the Apache Web Server. The mod_cgi module was activated on Apache Web Server. This file was accessed on both versions using the URL http://localhost/cgi-bin/sample.pl. Here is the output of the test:
 
	May 12, 2003 12:32
 
Thus, the result obtained on both the server versions is identical. Apart from a few changes in the back-end compiler option, the Apache source code was built and installed correctly and in a very similar manner on both the SPARC platform and the x86 platform.
 

Back to top

Conclusion
  1. The Apache 2.0.45 server builds were completed successfully on both the Solaris OS, SPARC Platform Edition and the Solaris OS, x86 Platform Edition.
  2. The compiler generated a few warnings regarding the back-end compiler options, as they were dependent upon the SPARC platform. However, the compiler options were modified so the x86 platform edition could complete the build successfully without any warnings.
  3. To optimize the code generated for different architectures, appropriate back-end options must be used.
  4. It is strongly recommended to use Sun ONE Studio 8 Compiler Collection, as it contains different options for back-end compiler flags on a wide variety of SPARC and x86 architecture processors. Also, the collection can offer convenience when the code is ported from one architecture to another, as equivalent options are available in this compiler for either platform.

Back to top