2015/02/17

Raspberry Pi 2的效能

只要安裝Raspbian並執行各種應用軟體,就能大概得知Pi 2的硬體效能提昇了多少,CPU從ARMv6到ARMv7、從單核心到四核心,記憶體從512MB到1GB,不消多說也知道變快了,官方號稱執行速度會有六倍之快,不過實際情況還是要看你的程式性質,有無使用多核心、有無運用GPU、等等。

以前若是較大型的應用軟體,例如圖片編輯軟體GIMP、網頁瀏覽器、Scribus、辦公室軟體,光開啟就花去不少時間,使用時反應也非常遲鈍,根本不堪使用,不過現在情況已大為改善,的確可作為個人電腦來用,若再考慮價錢性能比,更是物超所值。

rpi每次都能引爆話題,這次Pi 2也不例外,許多人剛拿到熱騰騰的Pi 2,就迫不及待地進行效能檢測,譬如Ladyada在凌晨三點就以PCSX模擬PlayStation玩遊戲了。

我一拿到Pi 2,就是超頻,預設頻率是900MHz(還是800MHz?),不多說,直接選擇raspi-config超頻選單中的1000MHz。不過重開機、看到登入提示後,居然停住不動了,嘿,檢查之後發現是電源不夠強,更換後便無問題。
然後能以指令cpufreq-info查詢每個核心的運作情況:
pi@raspberrypi ~ $ cpufreq-info
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
  driver: BCM2835 CPUFreq
  CPUs which run at the same hardware frequency: 0 1 2 3
  CPUs which need to have their frequency coordinated by software: 0 1 2 3
  maximum transition latency: 355 us.
  hardware limits: 600 MHz - 1000 MHz
  available frequency steps: 600 MHz, 1000 MHz
  available cpufreq governors: conservative, ondemand, userspace, powersave, performance
  current policy: frequency should be within 600 MHz and 1000 MHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency is 600 MHz.
  cpufreq stats: 600 MHz:49.87%, 1000 MHz:50.13%  (3)
analyzing CPU 1:
  driver: BCM2835 CPUFreq
  CPUs which run at the same hardware frequency: 0 1 2 3
  CPUs which need to have their frequency coordinated by software: 0 1 2 3
  maximum transition latency: 355 us.
  hardware limits: 600 MHz - 1000 MHz
  available frequency steps: 600 MHz, 1000 MHz
  available cpufreq governors: conservative, ondemand, userspace, powersave, performance
  current policy: frequency should be within 600 MHz and 1000 MHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency is 600 MHz.
  cpufreq stats: 600 MHz:49.87%, 1000 MHz:50.13%  (3)
analyzing CPU 2:
  driver: BCM2835 CPUFreq
  CPUs which run at the same hardware frequency: 0 1 2 3
  CPUs which need to have their frequency coordinated by software: 0 1 2 3
  maximum transition latency: 355 us.
  hardware limits: 600 MHz - 1000 MHz
  available frequency steps: 600 MHz, 1000 MHz
  available cpufreq governors: conservative, ondemand, userspace, powersave, performance
  current policy: frequency should be within 600 MHz and 1000 MHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency is 600 MHz.
  cpufreq stats: 600 MHz:49.87%, 1000 MHz:50.13%  (3)
analyzing CPU 3:
  driver: BCM2835 CPUFreq
  CPUs which run at the same hardware frequency: 0 1 2 3
  CPUs which need to have their frequency coordinated by software: 0 1 2 3
  maximum transition latency: 355 us.
  hardware limits: 600 MHz - 1000 MHz
  available frequency steps: 600 MHz, 1000 MHz
  available cpufreq governors: conservative, ondemand, userspace, powersave, performance
  current policy: frequency should be within 600 MHz and 1000 MHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency is 600 MHz.
  cpufreq stats: 600 MHz:49.87%, 1000 MHz:50.13%  (3)


讓我試試nbench,結果如下。
BYTEmark* Native Mode Benchmark ver. 2 (10/95)
Index-split by Andrew D. Balsa (11/97)
Linux/Unix* port by Uwe F. Mayer (12/96,11/97)

TEST                : Iterations/sec.  : Old Index   : New Index
                    :                  : Pentium 90* : AMD K6/233*
--------------------:------------------:-------------:------------
NUMERIC SORT        :          495.76  :      12.71  :       4.18
STRING SORT         :          41.141  :      18.38  :       2.85
BITFIELD            :      1.4135e+08  :      24.25  :       5.06
FP EMULATION        :          77.569  :      37.22  :       8.59
FOURIER             :            5241  :       5.96  :       3.35
ASSIGNMENT          :          7.5314  :      28.66  :       7.43
IDEA                :          1443.8  :      22.08  :       6.56
HUFFMAN             :          725.78  :      20.13  :       6.43
NEURAL NET          :          6.8871  :      11.06  :       4.65
LU DECOMPOSITION    :          250.88  :      13.00  :       9.39
==============ORIGINAL BYTEMARK RESULTS==============

INTEGER INDEX       : 22.234
FLOATING-POINT INDEX: 9.499
Baseline (MSDOS*)   : Pentium* 90, 256 KB L2-cache, Watcom* compiler 10.0
==================LINUX DATA BELOW===================
CPU                 : 4 CPU ARMv7 Processor rev 5 (v7l)
L2 Cache            :
OS                  : Linux 3.18.7-v7+
C compiler          : gcc version 4.6.3 (Debian 4.6.3-14+rpi1)
libc                : libc-2.13.so
MEMORY INDEX        : 4.749
INTEGER INDEX       : 6.235
FLOATING-POINT INDEX: 5.268
Baseline (LINUX)    : AMD K6/233*, 512 KB L2-cache, gcc 2.7.2.3, libc-5.4.38


然後跟舊板子
TEST                : Iterations/sec.  : Old Index   : New Index
                    :                  : Pentium 90* : AMD K6/233*
--------------------:------------------:-------------:------------
NUMERIC SORT        :           200.4  :       5.14  :       1.69
STRING SORT         :          31.472  :      14.06  :       2.18
BITFIELD            :      8.8785e+07  :      15.23  :       3.18
FP EMULATION        :          45.509  :      21.84  :       5.04
FOURIER             :          2056.4  :       2.34  :       1.31
ASSIGNMENT          :          2.3939  :       9.11  :       2.36
IDEA                :          669.29  :      10.24  :       3.04
HUFFMAN             :          414.53  :      11.49  :       3.67
NEURAL NET          :          3.1213  :       5.01  :       2.11
LU DECOMPOSITION    :           72.68  :       3.77  :       2.72
==============ORIGINAL BYTEMARK RESULTS==============
INTEGER INDEX       : 11.448
FLOATING-POINT INDEX: 3.534
Baseline (MSDOS*)   : Pentium* 90, 256 KB L2-cache, Watcom* compiler 10.0
==================LINUX DATA BELOW===================
CPU                 :
L2 Cache            :
OS                  : Linux 3.1.9+
C compiler          : gcc-4.7.real
libc                : libc-2.13.so
MEMORY INDEX        : 2.539
INTEGER INDEX       : 3.121
FLOATING-POINT INDEX: 1.960
可以看見有很明顯的提昇,當然啦,相關因素很多,包括建置編譯nbench的編譯器選項,rpi板子超頻時脈,有無執行其他背景程式,等等,另外也跟測試項目有關,

另外可使用sysbench來測試有無多執行緒的效能,底下是1個執行緒的結果。
pi@raspberrypi ~ $ sysbench --test=threads run
sysbench 0.4.12:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 1

Doing thread subsystem performance test
Thread yields per test: 1000 Locks used: 8
Threads started!
Done.


Test execution summary:
    total time:                          18.5008s
    total number of events:              10000
    total time taken by event execution: 18.4875
    per-request statistics:
         min:                                  1.80ms
         avg:                                  1.85ms
         max:                                  9.61ms
         approx.  95 percentile:               1.89ms

Threads fairness:
    events (avg/stddev):           10000.0000/0.00
    execution time (avg/stddev):   18.4875/0.00


底下是4個執行緒的結果,
pi@raspberrypi ~ $ sysbench --num-threads=4 --test=threads run
sysbench 0.4.12:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 4

Doing thread subsystem performance test
Thread yields per test: 1000 Locks used: 8
Threads started!
Done.


Test execution summary:
    total time:                          4.8727s
    total number of events:              10000
    total time taken by event execution: 19.4634
    per-request statistics:
         min:                                  1.88ms
         avg:                                  1.95ms
         max:                                 10.30ms
         approx.  95 percentile:               1.96ms

Threads fairness:
    events (avg/stddev):           2500.0000/7.68
    execution time (avg/stddev):   4.8659/0.00


非常明顯,有了四核心之後,多執行緒的程式當然就跑得快。其他還有測試JavaScript的評分、測試GPU的效能表現、等等,有興趣者可自行嘗試。

最後提醒一句,跑得快也就代表比較耗電,記得提供穩定的電源與線材。

參考資料:

7 comments:

  1. 葉老師, 請問用Raspberry Pi 2能否用GPIO發送100MHz的固定頻率? 感恩

    ReplyDelete
    Replies
    1. 可以,但我沒做過。
      請拜孤狗大神。
      http://codeandlife.com/2012/07/03/benchmarking-raspberry-pi-gpio-speed/

      https://www.raspberrypi.org/forums/viewtopic.php?t=37770

      http://hackaday.com/2012/12/10/transmit-fm-using-raspberry-pi-and-no-additional-hardware/

      好像「軟體FM」會需要那麼高的頻率。

      Delete
    2. 葉老師, 我有試了以下方法:http://www.icrobotics.co.uk/wiki/index.php/Turning_the_Raspberry_Pi_Into_an_FM_Transmitter
      用一個空的檔案取代聲音檔就可以一直發出100NHz clock,
      但是我發現他是發正弦波而不是方波,而且電壓似乎不能調整

      Delete
    3. 他發的是FM,不是方波吧。

      > 電壓似乎不能調整
      調整?不懂。

      Delete
    4. 我看了他大概的描述.發現他是用DMA的時脈從GPIO吐出來大約振福1.5V(我用Scope量的),用sin的方式產生FM載波.但是最近工作上需要一個400mV 100MHz的方波.本來是希望可以利用這個裝置達到我要的目的.但是我不知道要如何修改...

      Delete
    5. 我也不知道,無法回答。

      Delete