ffmpeg_powerpc_performance_evaluation_howto.txt 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. FFmpeg & evaluating performance on the PowerPC Architecture HOWTO
  2. (c) 2003-2004 Romain Dolbeau <romain@dolbeau.org>
  3. I - Introduction
  4. The PowerPC architecture and its SIMD extension AltiVec offer some
  5. interesting tools to evaluate performance and improve the code.
  6. This document tries to explain how to use those tools with FFmpeg.
  7. The architecture itself offers two ways to evaluate the performance of
  8. a given piece of code:
  9. 1) The Time Base Registers (TBL)
  10. 2) The Performance Monitor Counter Registers (PMC)
  11. The first ones are always available, always active, but they're not very
  12. accurate: the registers increment by one every four *bus* cycles. On
  13. my 667 Mhz tiBook (ppc7450), this means once every twenty *processor*
  14. cycles. So we won't use that.
  15. The PMC are much more useful: not only can they report cycle-accurate
  16. timing, but they can also be used to monitor many other parameters,
  17. such as the number of AltiVec stalls for every kind of instruction,
  18. or instruction cache misses. The downside is that not all processors
  19. support the PMC (all G3, all G4 and the 970 do support them), and
  20. they're inactive by default - you need to activate them with a
  21. dedicated tool. Also, the number of available PMC depends on the
  22. procesor: the various 604 have 2, the various 75x (aka. G3) have 4,
  23. and the various 74xx (aka G4) have 6.
  24. *WARNING*: The PowerPC 970 is not very well documented, and its PMC
  25. registers are 64 bits wide. To properly notify the code, you *must*
  26. tune for the 970 (using --tune=970), or the code will assume 32 bit
  27. registers.
  28. II - Enabling FFmpeg PowerPC performance support
  29. This needs to be done by hand. First, you need to configure FFmpeg as
  30. usual, but add the "--powerpc-perf-enable" option. For instance:
  31. #####
  32. ./configure --prefix=/usr/local/ffmpeg-svn --cc=gcc-3.3 --tune=7450 --powerpc-perf-enable
  33. #####
  34. This will configure FFmpeg to install inside /usr/local/ffmpeg-svn,
  35. compiling with gcc-3.3 (you should try to use this one or a newer
  36. gcc), and tuning for the PowerPC 7450 (i.e. the newer G4; as a rule of
  37. thumb, those at 550Mhz and more). It will also enable the PMC.
  38. You may also edit the file "config.h" to enable the following line:
  39. #####
  40. // #define ALTIVEC_USE_REFERENCE_C_CODE 1
  41. #####
  42. If you enable this line, then the code will not make use of AltiVec,
  43. but will use the reference C code instead. This is useful to compare
  44. performance between two versions of the code.
  45. Also, the number of enabled PMC is defined in "libavcodec/ppc/dsputil_ppc.h":
  46. #####
  47. #define POWERPC_NUM_PMC_ENABLED 4
  48. #####
  49. If you have a G4 CPU, you can enable all 6 PMC. DO NOT enable more
  50. PMC than available on your CPU!
  51. Then, simply compile FFmpeg as usual (make && make install).
  52. III - Using FFmpeg PowerPC performance support
  53. This FFmeg can be used exactly as usual. But before exiting, FFmpeg
  54. will dump a per-function report that looks like this:
  55. #####
  56. PowerPC performance report
  57. Values are from the PMC registers, and represent whatever the
  58. registers are set to record.
  59. Function "gmc1_altivec" (pmc1):
  60. min: 231
  61. max: 1339867
  62. avg: 558.25 (255302)
  63. Function "gmc1_altivec" (pmc2):
  64. min: 93
  65. max: 2164
  66. avg: 267.31 (255302)
  67. Function "gmc1_altivec" (pmc3):
  68. min: 72
  69. max: 1987
  70. avg: 276.20 (255302)
  71. (...)
  72. #####
  73. In this example, PMC1 was set to record CPU cycles, PMC2 was set to
  74. record AltiVec Permute Stall Cycles, and PMC3 was set to record AltiVec
  75. Issue Stalls.
  76. The function "gmc1_altivec" was monitored 255302 times, and the
  77. minimum execution time was 231 processor cycles. The max and average
  78. aren't much use, as it's very likely the OS interrupted execution for
  79. reasons of its own :-(
  80. With the exact same settings and source file, but using the reference C
  81. code we get:
  82. #####
  83. PowerPC performance report
  84. Values are from the PMC registers, and represent whatever the
  85. registers are set to record.
  86. Function "gmc1_altivec" (pmc1):
  87. min: 592
  88. max: 2532235
  89. avg: 962.88 (255302)
  90. Function "gmc1_altivec" (pmc2):
  91. min: 0
  92. max: 33
  93. avg: 0.00 (255302)
  94. Function "gmc1_altivec" (pmc3):
  95. min: 0
  96. max: 350
  97. avg: 0.03 (255302)
  98. (...)
  99. #####
  100. 592 cycles, so the fastest AltiVec execution is about 2.5x faster than
  101. the fastest C execution in this example. It's not perfect but it's not
  102. bad (well I wrote this function so I can't say otherwise :-).
  103. Once you have that kind of report, you can try to improve things by
  104. finding what goes wrong and fixing it; in the example above, one
  105. should try to diminish the number of AltiVec stalls, as this *may*
  106. improve performance.
  107. IV) Enabling the PMC in Mac OS X
  108. This is easy. Use "Monster" and "monster". Those tools come from
  109. Apple's CHUD package, and can be found hidden in the developer web
  110. site & FTP site. "MONster" is the graphical application, use it to
  111. generate a config file specifying what each register should
  112. monitor. Then use the command-line application "monster" to use that
  113. config file, and enjoy the results.
  114. Note that "MONster" can be used for many other things, but it's
  115. documented by Apple, it's not my subject.
  116. If you are using CHUD 4.4.2 or later, you'll notice that MONster is
  117. no longer available. It's been superseeded by Shark, where
  118. configuration of PMCs is available as a plugin.
  119. V) Enabling the PMC on Linux
  120. On linux you may use oprofile from http://oprofile.sf.net, depending on the
  121. version and the cpu you may need to apply a patch[1] to access a set of the
  122. possibile counters from the userspace application. You can always define them
  123. using the kernel interface /dev/oprofile/* .
  124. [1] http://dev.gentoo.org/~lu_zero/development/oprofile-g4-20060423.patch
  125. --
  126. Romain Dolbeau <romain@dolbeau.org>
  127. Luca Barbato <lu_zero@gentoo.org>