Guía de las Compaq-Tools en Gentoo Alpha Tavis Ormandy Jorge Paulo Esta guía es una introducción a las herramientas libres Compaq Tools para usuarios de Gentoo Alpha 1.0.2 June 05, 2004 Introducción
Consideraciones sobre Licencias

Antes de continuar leyendo esta guía deberías comprobar si cumples con los requerimientos para usar las Compaq Tools. Si necesitas usar cualquier cosa que no sean las librerías de ejecución dev-libs/libotsy dev-libs/libcpml necesitas ser calificado como usuario académico o un entusiasta.

El Software debe usarse solamente con fin individual, personal y "entusiasta" o 
para educación y estudio de carácter personal. No debe ser usado con fines 
comerciales, empresariales o institucionales ya sea con o sin animo de lucro. 
Cualquier trabajo realizado o resultante del uso de este Software no puede 
usarse en beneficio de terceras personas a cambio de cualquier tipo de pago, 
compensación o cualquier otro método de reembolso o remuneración.
Si no llegas a la calificación y sigues queriendo usar el software puedes comprar unaLicencia Comercial desde HP, la cual te dará mayor flexibilidad en el uso del kit de herramientas.

Si tu calificación es suficiente para una licencia gratuita, debes registrarte en HP usando el formulario ubicado enhttp://h18000.www1.hp.com/products/software/alpha-tools/ee-license.html. Una vez tu petición haya sido procesada, HP te enviara una clave de licencia que puede ser usada para desencriptar e instalar los Compiladores de Compaq.

Compaq Tools Descripción

Si estas familiarizado con la optimización de PC's seguramente habrás oido hablar deIicc, Compilador optimizador de Intel (Intel's optimizing compiler) para sus procesadores pentimum. El equivalente para los usuarios de Alpha es The Professional Linux Developers Tools, (Las Herramientas Profesionales para Desarrolladores Linux) un compendio de librerias de alto rendimiento, compiladores y utilidades especificamente optimizadas para la plataforma Alpha, disponibles para entusiastas de Alpha y para uso educativo. Experimentar usando las Libreiras y Compiladores en las compilaciones de portage es una manera efectiva de mejorar el rendimiento de tu sistema Gentoo Alpha.

Las siguientes herramientas estan disponibles para los usuarios de Gentoo:

libotsCodigo compilado de soporte, una depedencia requerida para el usos del kit de herramientas.dev-libs/libots libcpml Compaq Portable Math Library, libreria matematica de alto rendimiento para usuarios de Alpha que puede ser usada pra mejorar el rendimiento matematico en aplicaciones. dev-libs/libcpml ccc Compaq C Compiler, compilador de C de Compaq, altamente optimizado y ajustado para la plataforma Alpha, contiene un generador de código altamente optimizado y especificamente diseñado para aprovechar al máximo la arquitectura de 64 bits de Alpha. Está particularmente adaptado y contiene soporte para programación de sistemas, programación en paralelo y computación matemáticadev-lang/ccc cxx Compaq's C++ compiler,compilador de C++ de Compaq, ajustado especificamente para la plataforma Alpha, ofrece el mismo generador de código optimizado de Compaq C para los programadores de C++. dev-lang/cxx ladebug El famoso depurador de Compaq para Tru64, portado a Alpha Linux, contiene soporte extendido para aplicaciones compiladas con el compilador de Compaq C. dev-util/ladebug libcxml Compaq's eXtended Math Library, libreria matemática de alto rendimiento para programadores de fortran, c y c++. dev-libs/libcxml
Herramienta Descripción Nombre en Portage
Cuando se redacto este documento, algunas de las herraminetas de Compaq Tolls seguian marcadas como ~alpha. Esto significa que apesar que has sido probadas y parecian funcionar, no han tenido un proceso extensivo de testeo y no puede asegurarse que sea totalmente estable. Si quieres instalar alguna de estas aplicaciones, necesitaras añadir ACCEPT_KEYWORDS="~alpha" delante del comando emerge. Si tienes cualquier problema con ccc o cxx, o cualquiera de las Compaq Tools por favor introduce el fallo engentoo bugzilla y asignamelo a mi -- taviso@gentoo.org
Instalando las Herramientas de Desalloradores(Developers Tools)
Bibliotecas de Ejecución

El primer paso para instalar las Herramientas de Desarrollador es obtener las bibliotecas de ejecucion. A causa de restricciones en la licencia, Gentoo no puede distribuir los RPM y debes descargarlos desde Compaq.

ftp://ftp.compaq.com/pub/products/linuxdevtools/latest/downloads.html

Descarga los rpms libots y libcpml, y ponlos en tu directorio distfiles.

Si tienes un ev6 o un procesador superior, deberias descargarte el rpm libcpml optimizado para ev6, esto te permitira explotar las caracteristicas de tu procesador mas nuevo. Tambien deberias añadir "ev6" a tus parametros USE en /etc/make.conf para notificar al ebuild que use el rpm optimizado. Si no conoces que revision de procesador tienes en tu maquina, usa el comando descrito a continuación para identificarlo.
# uname -p   # comprueba la revision de tu procesador
EV56
# mv libots-2.2.7-2.alpha.rpm cpml_ev?-5.2.0-1.alpha.rpm /usr/portage/distfiles

Ahora los rpms están en tu directorio distfiles, portage será capaz de encontrarlos y de instalarlos en tu sistema. Usar las siguientes instrucciones para emerger las librerias.

# emerge -pv dev-libs/libots dev-libs/libcpml # comprueba que todo este correcto
# emerge dev-libs/libots dev-libs/libcpml

Ahora las librerias están instaladas en tu sistema y estás preprarado para instalar los compiladores y las utilidades.

Instalando los Compiladores

Si todavia no te has registrado para obtener una licencia de entusista o academica en HP, ahora seraia un buen momento. Parece ser que la licencia se obtiene 24 horas despues de rellenar el formulario en la web.

http://h18000.www1.hp.com/products/software/alpha-tools/ee-license.html

Se te pedirá que entres datos personales y una dirección de email. La dirección de email debe ser válida ya que la clave de liciencia sera enviada a esta direccion y debe ser usada para desbloquear los compiladores. También se te pedira que expliques porque pides una licencia gratuita. ej. "Entusiasta de alpha para uso doméstico" o " Para uso academico en la Universidad XYZ".

When your license is issued, your notification email will contain the license key. Use it in the command below to install the ccc and cxx compilers.

# emerge -pv dev-lang/ccc  # check everything looks okay
# CCC_LICENSE_KEY=0123456789 emerge dev-lang/ccc
# ebuild /var/db/pkg/dev-lang/ccc-6.5.9.001.ebuild config
Remember to substitute 0123456789 with the license key emailed to you Check which version of the C compiler you are installing before issuing the ebuild command. Emerge will tell you the command to issue when it completes. The ebuild command configures the compiler for your system, allowing it to locate system files and libraries.

If everything went okay, you now have the Compaq C Compiler installed and can use it to start compiling applications from portage or your own applications. If you would also like to use the C++ compilers, use the commands below to install them.  Don't forget to run "cxx" at the end to agree to the EULA.

# emerge -pv dev-lang/cxx   # check everything looks okay
# CXX_LICENSE_KEY=0123456789 emerge dev-lang/cxx
# ebuild /var/db/pkg/dev-lang/cxx-6.5.9.31-r1.ebuild config
# cxx   # read and agree to the EULA.

If you would like to take advantage of the enhanced debugger ladebug, you should install it now.

# emerge -pv dev-util/ladebug
# emerge dev-util/ladebug
ladebug can be used with gcc executables as well as ccc/cxx executables, If you are from a Tru64 background, you may be familiar with ladebug and might feel more comfortable using it than gdb for general debugging.
Using the Compaq Tools with Portage
Compiling C/C++ Programs with Portage

Compiling programs from portage with ccc is simple. In the following example we will demonstrate installing gzip, an application known to perform very well with ccc.

# emerge -pv gzip   # check everything looks okay
# CC=ccc CFLAGS="-host -fast" emerge gzip

ccc has many optimization features. There is an overview and explanation of the CFLAGS used here and some other common options farther below.

The same method can be used to compile C++ programs. The following example uses groff, which benchmarks much better when compiled with cxx.

# emerge -pv groff   # check everything looks okay
# CXX=cxx CXXFLAGS="-host -fast" emerge groff
Optimizing Your ccc/cxx Compiled Applications

Optimizing applications for Alpha with ccc/cxx is simpler than with gcc. Similar options are grouped together, making command lines shorter and simpler. The table below demonstrates some of the common flags you might want to try in your programs.

-host Optimizes the application for the system being compiled on by taking advantage of any extended instruction set available and scheduling specifically for this machine. Applications compiled with this will probably not function on different alpha machines. Very Safe.-fast Turns on some advanced optimizations; using this will maximize the performance of your applications Safe.-O4 Inserts NOP instructions into your code to improve scheduling. Software pipelining using dependency analysis, vector-ization of some loops on 8-bit and  16-bit data (char and  short). Using this may not always improve code performance and should be compared to -O3 and -fast. Usually Safe, may not always improve performance-std1 Informs the compiler to use the strictest possible interpretation of the standards allowing it to perform more aggressive optimizations that might not have had predictable results in a more liberal interpretation. Not all applications will compile with this and some may not perform as intended if they do compile. May not Compile, but Will Improve Performance.-tune host Fine tunes the compiler scheduling to perform best on the arch specified; using this will not stop you from using the binaries on different machines and will improve performance. Very Safe.
Flag Description Safety
CCC supports interpretation of most gcc compiler flags so if your application Makefile specifies some gcc options, don't worry, CCC will probably understand it. If you have the "doc" USE flag set in your make.conf, the compilers will have installed extensive documentation in /usr/share/doc. You can browse this for more information. There are also excellent man pages.
Notes on the Compaq Compilers
Applications that benefit from CCC/CXX

The compaq compilers really excel at optimizing applications that involve intensive floating point maths. They can also outperform GCC at integer maths in most situations. During my experiments I have found many applications that benchmark almost identically with ccc as with gcc, but I haven't found any applications that perform worse with ccc/cxx.

Remember however that GCC has received more extensive testing and provides many extensions to the standards that programmers might make use of. CCC might not support these extensions or not support them as fully as gcc. You should take this into account when choosing what to optimize with ccc.

Benchmarking CCC

If you want to experiment with different CCC flags and compare them to GCC, you need to benchmark them. For this purpose, I recommend the Freebench benchmark suite. It will compile and run 6 different tests designed to test Integer and Floating Point performance and will also generate html graphs for comparisons.

Here are some examples I have prepared:

CCC Vanilla CCC results with no flags specified. GCC Vanilla GCC results with no flags specified. CCC Normal CCC Results with some common flags GCC Normal GCC Results with some common flags. CCC Best CCC With some more options specified. GCC Best GCC With some more options specified.
Test Summary
Higher is better. A Single page comparison is available here
Advanced Performance Features

If you've been using Alpha for more than a few minutes, you know about Unaligned accesses, programming errors that affect Alpha users and cause applications to incur performance penalties as the kernel fixes them.

Unaligned accesses aren't serious; programs will run fine even with them.  However the kernel can't fix these instantly and every time it does a fix, your application will run slower. Usually this isn't a problem, but on some programs you might notice the slowdown.

Apr 9 01:05:55 amnesiac bash(20147): unaligned trap at 0000039db4526d98: 000003
9db4662e26 28 1
Apr 9 01:05:55 amnesiac bash(20147): unaligned trap at 0000039db4526d9c: 000003
9db4662e2a 28 3
Apr 9 01:06:03 amnesiac snort(23800): unaligned trap at 000000012003fe60: 00000
00120161a92 2c 2
Apr 9 01:06:03 amnesiac snort(23800): unaligned trap at 000000012003fe78: 00000
00120161a96 2c 2
Apr 9 01:06:03 amnesiac snort(23800): unaligned trap at 000000012003feb0: 00000
00120161a9e 2c 4
Apr 9 01:06:03 amnesiac snort(23800): unaligned trap at 000000012003feb4: 00000
00120161aa2 2c 5
You can see these messages on your machine with the dmesg command.

There are 2 ways to fix these errors so as to minimize the performance hit. If you're a programmer, you can fix the errors.  This is usually simple, but some applications are riddled with them or are very subtle. If you think you can do this, HP has some documentation for programmers on how to identify and fix these bugs at the link below.

http://h21007.www2.hp.com/dspp/tech/tech_TechSingleTipDetailPage_IDX/1,2366,161,00.html

The second way is using the Compaq Compiler and the -misalign flag, this will add extra checking code to make sure that all code is aligned. This will make your program run slower, so you need to experiment and check if it's worth it.

If possible run the application through time. When the program completes it should show how much time the kernel spent processing system calls, including fixing misaligned accesses. If this number is high (you can compare it to other platforms) and you are receiving lots of UAC messages, you might benefit from recompiling with the extra checking code.

# time your_application
real 0m2.011s
user 0m0.004s
sys 0m2.007s
# CC=ccc CFLAGS="-host -fast -misalign" emerge your_application
# time your_application
0m0.811s
0m0.804s
0m0.007s
Of course that you don't have to compile your whole application with -misalign You can use the hp documentation above to identify the source file that contains the errors and use misalign on those files specifically. If the UAC messages bother you or you would like to streamline the kernel handling code for maximum performance, you can modify /usr/src/linux/arch/alpha/kernel/traps.c and remove the printk() and switch statements. You can use the following command to check how many times the kernel has fixed these errors since you last rebooted
$ grep unaligned /proc/cpuinfo
kernel unaligned acc : 3 (pc=fffffc000035c7e0,va=120000f1a)
user unaligned acc : 6623 (pc=28d361e4c1c,va=28d36320f62)