]> git.sesse.net Git - ffmpeg/blob - doc/ffmpeg_powerpc_performance_evaluation_howto.txt
powerpc PMC doc fix by (Romain Dolbeau <dolbeau at irisa dot fr>)
[ffmpeg] / doc / ffmpeg_powerpc_performance_evaluation_howto.txt
1 FFmpeg & evaluating performance on the PowerPC Architecture HOWTO
2
3 (c) 2003-2004 Romain Dolbeau <romain@dolbeau.org>
4
5
6
7 I - Introduction
8
9 The PowerPC architecture and its SIMD extension AltiVec offer some interesting tools to evaluate performance and improve the code. This document try to explain how to use those tools with FFmpeg.
10
11 The architecture itself offers two ways to evaluate the performance of a given piece of code :
12
13 1) The Time Base Registers (TBL)
14 2) The Performance Monitor Counter Registers (PMC)
15
16 The firsts are always available, always active, but they're not very accurate : the registers increment by one every four *bus* cycle. On my 667 Mhz tibook (ppc7450) , this means once every twenty *processor* cycle. So we won't use that.
17
18 The PMC are much more useful : not only they can report cycle-accurate timing, but they can also be used to monitor many other parameters, such as the number of AltiVec stalls for every kind of instructions, 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 dedicated tool. Also, the number of available PMC depend on the procesor : the various 604 have 2, the various 75x (aka. G3) have 4, anbd the various 74xx (aka G4) have 6.
19
20 *WARNING*: The powerpc 970 is not very well documented, and it seems its PMC registers are 64bits wide. The current implementation in FFMpeg assume the register are 32bits wide, and will *not* work on a powerpc 970 (aka G5).
21
22
23 II - Enabling FFmpeg PowerPC performance support
24
25 This need to be done by hand. First, you need to configure FFmpeg as usual, plus using the "--powerpc-perf-enable". for instance :
26
27 #####
28 ./configure --prefix=/usr/local/ffmpeg-cvs --cc=gcc-3.3 --tune=7450 --powerpc-perf-enable
29 #####
30
31 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 gcc), and tuning for the PowerPC7450 (i.e. the newer G4 ; as a rule of thumb, those at 550Mhz and more). It will also enables the PMCs.
32
33 You may also edit the file "config.h" to enable the following line:
34
35 #####
36 // #define ALTIVEC_USE_REFERENCE_C_CODE 1
37 #####
38
39 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 performance between the two versions of the code.
40
41 Also, the number of enabled PMC is defined in "libavcodec/ppc/dsputil_ppc.h" :
42
43 #####
44 #define POWERPC_NUM_PMC_ENABLED 4
45 #####
46
47 If you have a G4 cpus, you can enable all 6 PMCs. DO NOT enable more PMCs than available on your cpu !
48
49 Then, simply compile ffmpeg as usual (make && make install).
50
51
52
53 III - Using FFmpeg PowerPC performance support
54
55 This FFmeg can be used exactly as usual. But before exiting, Ffmpeg will dump a per-function report that looks like this:
56
57 #####
58 PowerPC performance report
59  Values are from the PMC registers, and represent whatever the registers are set to record.
60  Function "gmc1_altivec" (pmc1):
61         min: 231
62         max: 1339867
63         avg: 558.25 (255302)
64  Function "gmc1_altivec" (pmc2):
65         min: 93
66         max: 2164
67         avg: 267.31 (255302)
68  Function "gmc1_altivec" (pmc3):
69         min: 72
70         max: 1987
71         avg: 276.20 (255302)
72 (...)
73 #####
74
75 In this example, PMC1 was set to record CPU cycles, PMC2 was set to record AltiVec Permute Stall Cycle, and PMC3 was set to record AltiVec Issue Stalls.
76
77 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 reasons of it's own :-(
78
79 With the exact same setting and source file, but using the reference C code we get :
80
81 #####
82 PowerPC performance report
83  Values are from the PMC registers, and represent whatever the registers are set to record.
84  Function "gmc1_altivec" (pmc1):
85         min: 592
86         max: 2532235
87         avg: 962.88 (255302)
88  Function "gmc1_altivec" (pmc2):
89         min: 0
90         max: 33
91         avg: 0.00 (255302)
92  Function "gmc1_altivec" (pmc3):
93         min: 0
94         max: 350
95         avg: 0.03 (255302)
96 (...)
97 #####
98
99 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 :-).
100
101 Once you have that kind of report, you can try to improve things by finding what goes wrong and fixing it ; in the example above, one shoud try to diminish the number of AltiVec stalls, as this *may* improve performances.
102
103
104
105 IV) Enabling the PMC in MacOS X
106
107 This is easy. Use "Monster" and "monster". Those tools come from Apple's CHUD package, and can be found hidden in the developer web site & ftp site. "MONster" is the graphical application, use it to 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.
108
109 Note that "MONster" can be used for many other stuff, but it's documented by Apple, it's not my subject.
110
111
112
113 V) Enabling the PMC in Linux
114
115 I don't know how to do it, sorry :-) Any idea very much welcome.
116
117 -- 
118 Romain Dolbeau
119 <romain@dolbeau.org>