You can use profile-directed feedback (PDF) to tune the
performance of your application for a typical usage scenario. The
compiler optimizes the application based on an analysis of how often
branches are taken and blocks of code are executed.
The PDF process is intended to be used after other debugging and
tuning is finished, as one of the last steps before putting the application
into production. Other optimizations such as -qipa and
optimization levels -O4 and -O5 can
also benefit when used in conjunction with PDF.
As of IBM® XL C/C++ for Linux®,
V11.1,
you can compile your application using extended PDF functions with
three new -qpdf suboptions. Descriptions
of these new suboptions are listed below:
- level
- Supports multiple-pass profiling, block
counter, call counter and extended value profiling. You can compile
your application with-qpdf1=level=0|1|2 to generate
profiling data with different levels of optimization. Note that-qpdf=level=0 and -qpdf=level=1 support
single-pass profiling, whereas-qpdf=level=2 supports
multiple-pass profiling. If you want to bind the process to a particular processor,
you can set the environment variable to PDF_BIND_PROCESSOR.
Processor 0 is set by default.
- exename
- Generates the name of the PDF file you specify with the -o parameter.
- defname
- Reverts the PDF file to its default file name.
The following diagram illustrates the PDF process.
Figure 1. Profile-directed feedback
You first compile the program with the -qpdf1 option
(with a minimum optimization level of -O2),
which generates profile data by using the compiled program in the
same ways that users typically use it. You then compile the program
again, with the -qpdf2 option. This optimizes
the program based on the profile data. Alternatively, if you want
to save considerable time by avoiding a full recompilation in the -qpdf2 step,
you can simply relink the object files produced by the -qpdf1 step.
Notes: - You can use old profiling information after you modify your source
file. In previous releases, when you modify the source file and compile
with the -qpdf1 option, the compilation
stops with an error. As of IBM XL C/C++ for Linux,
V11.1,
when you use different compiler options to run different stages of
the PDF process, you see a list of warnings but the compilation does
not stop. However, using different compiler options between different
stages of PDF does not give you any benefits for using PDF.
- When using the -qreport option with
the -qpdf2 option, you can get additional information
added to your listing file to help you tune your program. This information
is written to PDF Report section and includes loop
iteration counts, block and call counts, and cache misses.
To use PDF, follow these steps:
- Compile some or all of the source files
in a program with the -qpdf1 option. You
need to specify at least the -O2 optimizing
option and you also need to link with at least -O2 in
effect. Note the compiler options that you use to compile the files;
you need to use the same options later.
- Run the program all the way through using
data that is representative of the data that is used during a normal
run of your finished program. The program records profiling information
when it finishes. You can run the program multiple times with different
data sets, and the profiling information is accumulated to provide
a count of how often branches are taken and blocks of code are executed,
based on the input data used. When the
application exits, by default, it writes profiling information to
the PDF file in the current working directory or the directory specified
by the PDFDIR environment variable. The default
name for the instrumentation file is ._pdf . To override the defaults,
use -qpdf1=pdfname or -qpdf2=pdfname.
- Recompile your program using the same compiler
options as before, but change -qpdf1 to -qpdf2.
In this second compilation, the accumulated profiling information
is used to fine-tune the optimizations. The resulting program contains
no profiling overhead and runs at full speed.
Note: The
options -L, -l,
and some others are linker options, and you can change them at this
point.
Instead of step 3, you can use -qpdf2 to
link the object files created by the -qpdf1 pass
without recompiling your source on the -qpdf2 pass.
This alternate approach can save considerable time and help tune large
applications for optimization. In both stages of PDF
process for a particular program, you are highly recommended to use
the same compiler options. Otherwise, you may not be able to take
advantage of PDF optimization.
Notes: - You do not need to compile all of the application's code with
the -qpdf1 option to benefit from the PDF
process. In a large application, you might want to concentrate on
those areas of the code that can benefit most from optimization.
- When compiling your program with -qpdf1 or -qpdf2,
by default, the -qipa option is also invoked
with level=0
- To avoid wasting compile and execution
time, make sure that the PDFDIR environment variable
is set to an absolute path. Otherwise, you might run the application
from the wrong directory, and it is not able to locate the profile
data files. When that happens, the program might not be optimized
correctly or might be stopped by a segmentation fault. A segmentation
fault might also happen if you change the value of the PDFDIR variable
and execute the application before finishing the PDF process.
- You are highly recommended to use the same
set of compiler options at all compilation steps for a particular
program. Otherwise, PDF cannot optimize your program correctly and
may even slow it down. All compiler settings must be the same, including
any supplied by configuration files.
- Avoid mixing PDF files created by the current
version level of the XL C/C++ compiler
with PDF files created by other version levels of the compiler.
- If you compile a program with -qpdf1,
remember that it generates profiling information when it runs, which
involves some performance overhead. This overhead goes away when you
recompile with -qpdf2 or with no PDF at
all.
- If compiled with -qpdf1=level=2 and
then -qpdf2 and -qreport a Cache
miss section is added to the listing file.
- You can modify your source code and use -qpdf1 and -qpdf2 to
compile your application. Old profiling information can still be preserved
and used during the second stage of the PDF process.
You can take more control of the PDF file generation, as follows:
- Compile some or all of the source files in the application with -qpdf1 and
a minimum of -O2.
- Run the application using a typical data set or several typical
data sets. By default, this produces
a PDF file in the current directory. The default name of the PDF file
is ._pdf.
- Change the PDF file location specified by the PDFDIR environment variable
or the -qipa=pdfname option to produce
a PDF file in a different location.
- Recompile or relink the application with -qpdf1 and
a minimum of -O2.
- Repeat steps 3 and 4 as often as you want.
- Use the mergepdf utility
to combine the PDF files into one PDF file. For example, if you produce
three PDF files that represent usage patterns that occur 53%, 32%,
and 15% of the time respectively, you can use this command:
mergepdf -r 53 path1 -r 32 path2 -r 15 path3
- Recompile or relink the application with -qpdf2 and
the optimization level used for -qpdf1 in
the previous steps.
To erase the information in the PDF directory,
use the cleanpdf utility or the resetpdf utility.