2003-07-09 20:22:11 +00:00
|
|
|
FFmpeg & evaluating performance on the PowerPC Architecture HOWTO
|
|
|
|
|
2004-03-22 11:17:33 +00:00
|
|
|
(c) 2003-2004 Romain Dolbeau <romain@dolbeau.org>
|
2003-07-09 20:22:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
I - Introduction
|
|
|
|
|
2005-06-09 19:31:28 +00:00
|
|
|
The PowerPC architecture and its SIMD extension AltiVec offer some
|
|
|
|
interesting tools to evaluate performance and improve the code.
|
2005-06-09 19:56:38 +00:00
|
|
|
This document tries to explain how to use those tools with FFmpeg.
|
2003-07-09 20:22:11 +00:00
|
|
|
|
2005-06-09 19:31:28 +00:00
|
|
|
The architecture itself offers two ways to evaluate the performance of
|
|
|
|
a given piece of code:
|
2003-07-09 20:22:11 +00:00
|
|
|
|
|
|
|
1) The Time Base Registers (TBL)
|
|
|
|
2) The Performance Monitor Counter Registers (PMC)
|
|
|
|
|
2005-06-09 19:56:38 +00:00
|
|
|
The first ones are always available, always active, but they're not very
|
|
|
|
accurate: the registers increment by one every four *bus* cycles. On
|
|
|
|
my 667 Mhz tiBook (ppc7450), this means once every twenty *processor*
|
|
|
|
cycles. So we won't use that.
|
2003-07-09 20:22:11 +00:00
|
|
|
|
2005-06-09 19:56:38 +00:00
|
|
|
The PMC are much more useful: not only can they report cycle-accurate
|
2005-06-09 19:31:28 +00:00
|
|
|
timing, but they can also be used to monitor many other parameters,
|
2005-06-09 19:56:38 +00:00
|
|
|
such as the number of AltiVec stalls for every kind of instruction,
|
2005-06-09 19:31:28 +00:00
|
|
|
or instruction cache misses. The downside is that not all processors
|
|
|
|
support the PMC (all G3, all G4 and the 970 do support them), and
|
|
|
|
they're inactive by default - you need to activate them with a
|
2005-06-09 19:56:38 +00:00
|
|
|
dedicated tool. Also, the number of available PMC depends on the
|
|
|
|
procesor: the various 604 have 2, the various 75x (aka. G3) have 4,
|
|
|
|
and the various 74xx (aka G4) have 6.
|
2003-07-09 20:22:11 +00:00
|
|
|
|
2005-06-09 19:56:38 +00:00
|
|
|
*WARNING*: The PowerPC 970 is not very well documented, and its PMC
|
|
|
|
registers are 64 bits wide. To properly notify the code, you *must*
|
|
|
|
tune for the 970 (using --tune=970), or the code will assume 32 bit
|
2005-06-09 19:31:28 +00:00
|
|
|
registers.
|
2003-07-09 20:22:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
II - Enabling FFmpeg PowerPC performance support
|
|
|
|
|
2005-06-09 19:56:38 +00:00
|
|
|
This needs to be done by hand. First, you need to configure FFmpeg as
|
|
|
|
usual, but add the "--powerpc-perf-enable" option. For instance:
|
2003-07-09 20:22:11 +00:00
|
|
|
|
|
|
|
#####
|
|
|
|
./configure --prefix=/usr/local/ffmpeg-cvs --cc=gcc-3.3 --tune=7450 --powerpc-perf-enable
|
|
|
|
#####
|
|
|
|
|
2005-06-09 19:31:28 +00:00
|
|
|
This will configure FFmpeg to install inside /usr/local/ffmpeg-cvs,
|
|
|
|
compiling with gcc-3.3 (you should try to use this one or a newer
|
2005-06-09 19:56:38 +00:00
|
|
|
gcc), and tuning for the PowerPC 7450 (i.e. the newer G4; as a rule of
|
|
|
|
thumb, those at 550Mhz and more). It will also enable the PMC.
|
2003-07-09 20:22:11 +00:00
|
|
|
|
|
|
|
You may also edit the file "config.h" to enable the following line:
|
|
|
|
|
|
|
|
#####
|
|
|
|
// #define ALTIVEC_USE_REFERENCE_C_CODE 1
|
|
|
|
#####
|
|
|
|
|
2005-06-09 19:31:28 +00:00
|
|
|
If you enable this line, then the code will not make use of AltiVec,
|
|
|
|
but will use the reference C code instead. This is useful to compare
|
2005-06-09 19:56:38 +00:00
|
|
|
performance between two versions of the code.
|
2003-07-09 20:22:11 +00:00
|
|
|
|
2005-06-09 19:56:38 +00:00
|
|
|
Also, the number of enabled PMC is defined in "libavcodec/ppc/dsputil_ppc.h":
|
2003-07-09 20:22:11 +00:00
|
|
|
|
|
|
|
#####
|
|
|
|
#define POWERPC_NUM_PMC_ENABLED 4
|
|
|
|
#####
|
|
|
|
|
2005-06-09 19:56:38 +00:00
|
|
|
If you have a G4 CPU, you can enable all 6 PMC. DO NOT enable more
|
|
|
|
PMC than available on your CPU!
|
2003-07-09 20:22:11 +00:00
|
|
|
|
2005-06-09 19:56:38 +00:00
|
|
|
Then, simply compile FFmpeg as usual (make && make install).
|
2003-07-09 20:22:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
III - Using FFmpeg PowerPC performance support
|
|
|
|
|
2005-06-09 19:56:38 +00:00
|
|
|
This FFmeg can be used exactly as usual. But before exiting, FFmpeg
|
2005-06-09 19:31:28 +00:00
|
|
|
will dump a per-function report that looks like this:
|
2003-07-09 20:22:11 +00:00
|
|
|
|
|
|
|
#####
|
|
|
|
PowerPC performance report
|
2005-06-09 19:31:28 +00:00
|
|
|
Values are from the PMC registers, and represent whatever the
|
|
|
|
registers are set to record.
|
2003-07-09 20:22:11 +00:00
|
|
|
Function "gmc1_altivec" (pmc1):
|
|
|
|
min: 231
|
|
|
|
max: 1339867
|
|
|
|
avg: 558.25 (255302)
|
|
|
|
Function "gmc1_altivec" (pmc2):
|
|
|
|
min: 93
|
|
|
|
max: 2164
|
|
|
|
avg: 267.31 (255302)
|
|
|
|
Function "gmc1_altivec" (pmc3):
|
|
|
|
min: 72
|
|
|
|
max: 1987
|
|
|
|
avg: 276.20 (255302)
|
|
|
|
(...)
|
|
|
|
#####
|
|
|
|
|
2005-06-09 19:31:28 +00:00
|
|
|
In this example, PMC1 was set to record CPU cycles, PMC2 was set to
|
2005-06-09 19:56:38 +00:00
|
|
|
record AltiVec Permute Stall Cycles, and PMC3 was set to record AltiVec
|
2005-06-09 19:31:28 +00:00
|
|
|
Issue Stalls.
|
2003-07-09 20:22:11 +00:00
|
|
|
|
2005-06-09 19:31:28 +00:00
|
|
|
The function "gmc1_altivec" was monitored 255302 times, and the
|
|
|
|
minimum execution time was 231 processor cycles. The max and average
|
|
|
|
aren't much use, as it's very likely the OS interrupted execution for
|
2005-06-09 19:56:38 +00:00
|
|
|
reasons of its own :-(
|
2003-07-09 20:22:11 +00:00
|
|
|
|
2005-06-09 19:56:38 +00:00
|
|
|
With the exact same settings and source file, but using the reference C
|
|
|
|
code we get:
|
2003-07-09 20:22:11 +00:00
|
|
|
|
|
|
|
#####
|
|
|
|
PowerPC performance report
|
2005-06-09 19:31:28 +00:00
|
|
|
Values are from the PMC registers, and represent whatever the
|
|
|
|
registers are set to record.
|
2003-07-09 20:22:11 +00:00
|
|
|
Function "gmc1_altivec" (pmc1):
|
|
|
|
min: 592
|
|
|
|
max: 2532235
|
|
|
|
avg: 962.88 (255302)
|
|
|
|
Function "gmc1_altivec" (pmc2):
|
|
|
|
min: 0
|
|
|
|
max: 33
|
|
|
|
avg: 0.00 (255302)
|
|
|
|
Function "gmc1_altivec" (pmc3):
|
|
|
|
min: 0
|
|
|
|
max: 350
|
|
|
|
avg: 0.03 (255302)
|
|
|
|
(...)
|
|
|
|
#####
|
|
|
|
|
2005-06-09 19:31:28 +00:00
|
|
|
592 cycles, so the fastest AltiVec execution is about 2.5x faster than
|
|
|
|
the fastest C execution in this example. It's not perfect but it's not
|
|
|
|
bad (well I wrote this function so I can't say otherwise :-).
|
2003-07-09 20:22:11 +00:00
|
|
|
|
2005-06-09 19:31:28 +00:00
|
|
|
Once you have that kind of report, you can try to improve things by
|
2005-06-09 19:56:38 +00:00
|
|
|
finding what goes wrong and fixing it; in the example above, one
|
|
|
|
should try to diminish the number of AltiVec stalls, as this *may*
|
|
|
|
improve performance.
|
2003-07-09 20:22:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2005-06-09 19:56:38 +00:00
|
|
|
IV) Enabling the PMC in Mac OS X
|
2003-07-09 20:22:11 +00:00
|
|
|
|
2005-06-09 19:31:28 +00:00
|
|
|
This is easy. Use "Monster" and "monster". Those tools come from
|
|
|
|
Apple's CHUD package, and can be found hidden in the developer web
|
2005-06-09 19:56:38 +00:00
|
|
|
site & FTP site. "MONster" is the graphical application, use it to
|
2005-06-09 19:31:28 +00:00
|
|
|
generate a config file specifying what each register should
|
|
|
|
monitor. Then use the command-line application "monster" to use that
|
|
|
|
config file, and enjoy the results.
|
2003-07-09 20:22:11 +00:00
|
|
|
|
2005-06-09 19:56:38 +00:00
|
|
|
Note that "MONster" can be used for many other things, but it's
|
2005-06-09 19:31:28 +00:00
|
|
|
documented by Apple, it's not my subject.
|
2003-07-09 20:22:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2005-06-09 19:56:38 +00:00
|
|
|
V) Enabling the PMC on Linux
|
2003-07-09 20:22:11 +00:00
|
|
|
|
|
|
|
I don't know how to do it, sorry :-) Any idea very much welcome.
|
|
|
|
|
|
|
|
--
|
|
|
|
Romain Dolbeau
|
|
|
|
<romain@dolbeau.org>
|