Using PBO

“How to Use PBO” (page 205)

“Instrumenting (+I/-I)” (page 206)

“Profiling” (page 208)

“Optimizing Based on Profile Data (+P/-P)” (page 210)

“Selecting an Optimization Level with PBO” (page 212)

“Using PBO to Optimize Shared Libraries” (page 212)

“Using PBO with ld -r” (page 213)

NOTE: The compiler interface to PBO is currently supported only by the C, C++, and FORTRAN compilers.

When to Use PBO

Profile-Based Optimization must be the last level of optimization you use when building an application. As with other optimizations, it must be performed after an application has been completely debugged.

Most applications benefit from PBO. The two types of applications that benefit the most from PBO are:

Applications that exhibit poor instruction memory locality. These are usually large applications in which the most common paths of execution are spread across multiple compilation units. The loops in these applications typically contain large numbers of statements, procedure calls, or both.

Applications that are branch-intensive. The operations performed in such applications are highly dependent on the input data. User interface managers, database managers, editors, and compilers are examples of such applications.

The best way to determine whether PBO improves an application's performance is to try it.

NOTE: Under some conditions, PBO is incompatible with programs that explicitly load shared libraries. Specifically, PBO does not function properly if the shl_load routine has either the BIND_FIRST or the BIND_NOSTART flags set. For more information about explicit loading of shared libraries, see The shl_load and cxxshl_load Routines .

How to Use PBO

Profile-based optimization involves these steps:

1.Instrument the application - prepare the application so that it generates profile data.

2.Profile the application - create profile data that can be used to optimize the application.

3.Optimize the application - generate optimized code based on the profile data.

A Simple Example Suppose you want to apply PBO to an application called sample. The application is built from a C source file sample.c. Discussed below are the steps involved in optimizing the application. Step 1 Instrument First, compile the application for instrumentation and level 2 optimization:

$ cc -v -c +I -O sample.c /opt/langtools/lbin/cpp sample.c /var/tmp/ctm123 /opt/ansic/lbin/ccom /var/tmp/ctm123 sample.o -O2 -I $ cc -v -o sample.inst +I -O sample.o /usr/ccs/bin/ld /opt/langtools/lib/icrt0.o -u main \ -o sample.inst sample.o -I -lc

At this point, you have an instrumented program called sample.inst.

Step 2 Profile

Linker Optimizations 205

Page 205
Image 205
HP UX Software Transition Kit (STK) manual Using PBO, When to Use PBO, How to Use PBO