[[bc10-router]]

#contents

*cpufreq による動的動作周波数変更 [#q82a4c8b]
Linux カーネルには CPU の動作周波数や動作電圧を動的に変更する cpufreq という仕組みがあります。~
~
周波数や電圧を変更する方法は CPU によって異なり、CPU アーキテクチャごとにデバイスドライバが用意されます。~
x86 アーキテクチャの CPU はかなり以前から対応していたのですが、~
ARM アーキテクチャは SoC ごとに対応が必要で、~
bc10 で使用している Texus Instruments の OMAP3530 では~
3.2 kernel あたりから使用可能になりました。~

この仕組みを利用して動作クロックを変更した場合に~
ネットワークのスループット(と消費電力)はどのように変化するかを確認しました。~

** driver[#hfd82b95]
cpufreq を使用するためには kernel driver を有効にする必要があります。~
ARCH=arm で menuconfig した際の、~
 -> CPU Power management
   -> CPU Frequency scaling
      [*] CPU Frequency scaling 
      <*>   CPU frequency translation statistics 
      [*]     CPU frequency translation statistics details 
            Default CPUFreq governor (userspace)  ---> 
      <*>   'performance' governor 
      <*>   'powersave' governor 
      -*-   'userspace' governor for userspace frequency scaling 
      <*>   'ondemand' cpufreq policy governor 
      <*>   'conservative' cpufreq governor 
      [*]   Generic CPU0 cpufreq driver 
            ARM CPU frequency scaling drivers  ---> 

で設定します。~
どの governor を有効にするか、有効にした governor のうちのどれをデフォルトにするか、を設定します。~

** governor [#bdee3c6b]
CPUfreq governor は動作周波数の変更に関する規則を決定するものです。~
bc10 で使用している OMAP3530 で使用できる governor は以下のものです。~
|performance  |最大動作周波数で CPU を動作させます。 |
|powersave    |最小動作周波数で CPU を動作させます。 |
|userspace    |root 権を持つユーザーやプログラムが動的に動作周波数を変更できるようにします。 |
|ondemand     |CPU 負荷に応じて動的に動作周波数を変更します。低遅延で負荷の変化に追従します。 |
|conservative |CPU 負荷に応じて動的に動作周波数を変更します。バッテリー動作向けに動作周波数はゆっくりと段階的に変更します。 |

** cpufreq インタフェース [#la7625d4]
この設定を有効にした kerenl で起動し、操作は sysfs の cpufreq インタフェースから行います。~
 # ls /sys/devices/system/cpu/cpu0/cpufreq/
 affected_cpus                  scaling_cur_freq
 cpuinfo_cur_freq               scaling_driver
 cpuinfo_max_freq               scaling_governor
 cpuinfo_min_freq               scaling_max_freq
 cpuinfo_transition_latency     scaling_min_freq
 related_cpus                   scaling_setspeed
 scaling_available_frequencies  stats
 scaling_available_governors
このインタフェースで動作周波数や管理ポリシーを確認し設定することが出来ます。~
各ファイルは以下の内容になっています。
|>|affected_cpus                 |ソフトウェアによる周波数の協調が必要な CPU のリスト。|
|>|cpuinfo_cur_freq              |ハードウェアから得た現在の動作周波数。(kHz)|
|>|cpuinfo_max_freq              |動作可能な最大周波数。(kHz)|
|>|cpuinfo_min_freq              |動作可能な最小周波数。(kHz)|
|>|cpuinfo_transition_latency    |二つの動作周波数を移行するのよう要する時間。(nano秒)|
|>|related_cpus                  |ソフトウェア・ハードウェアに関わらず周波数の協調が必要な CPU のリスト。|
|>|scaling_available_frequencies |動作可能な周波数のリスト。|
|>|scaling_available_governors   |利用可能な governor のリスト。                                                                          |
|>|scaling_cur_freq              |governor と cpufreq コアから得た現在の動作周波数。kernel はこの値を現在の動作周波数とみなします。(kHz)|
|>|scaling_driver                |cpufreq のハードウェアドライバー。                                                                      |
|>|scaling_governor              |現在利用中の governor。ここへ利用したい governor を echo することで変更可能。                           |
|>|scaling_max_freq              |動作ポリシーによって制限された最大動作周波数。ここへ設定したい最大周波数を echo することで変更可能。変更時は先にこちらを設定します。 |
|>|scaling_min_freq              |動作ポリシーによって制限された最小動作周波数。ここへ設定したい最小周波数を echo することで変更可能。変更時は max 設定後に設定します。|
|>|scaling_setspeed              |ここへ変更したい動作周波数を echo することで動作周波数の変更を行えます。 |
|stats |time_in_state            |設定可能な動作周波数ごとにどれだけの時間動作したかのリスト。 |
|      |total_trans              |動作周波数の変更が合計何回行われたかの回数。 |
|      |trans_table              |設定可能などの動作周波数からどの動作周波数へ変更が行われたかのテーブル。 |

** cpufrequtils [#j8b843d0]
このインタフェースを直接操作するのは煩雑なので、操作を行うためのユーティリティー cpufrequtils が用意されています。~
現在の状態の確認は cpufreq-info で行います。
 # cpufreq-info
 cpufrequtils 006: cpufreq-info (C) Dominik Brodowski 2004-2009
 Report errors and bugs to cpufreq@vger.kernel.org, please.
 analyzing CPU 0:
  driver: omap
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 300 us.
  hardware limits: 125 MHz - 600 MHz
  available frequency steps: 125 MHz, 250 MHz, 500 MHz, 550 MHz, 600 MHz
  available cpufreq governors: conservative, ondemand, powersave, userspace, performance
  current policy: frequency should be within 125 MHz and 600 MHz.
                  The governor "userspace" may decide which speed to use
                  within this range.
  current CPU frequency is 600 MHz (asserted by call to hardware).
  cpufreq stats: 125 MHz:0.00%, 250 MHz:0.00%, 500 MHz:0.00%, 550 MHz:0.00%, 600 MHz:100.00%
bc10 の OMAP3530 は 125、250、500、550、600 MHz で動作させられること、~
動作周波数の移行には最大 300 マイクロ秒の遅延が生じること、~
現在の governor は userspace であること、~
現在は 600MHz で動作していること、がわかります。~
~
変更は cpufreq-set で行います。
 # cpufreq-set --help
 cpufrequtils 006: cpufreq-set (C) Dominik Brodowski 2004-2009
 Report errors and bugs to cpufreq@vger.kernel.org, please.
 Usage: cpufreq-set [options]
 Options:
   -c CPU, --cpu CPU        number of CPU where cpufreq settings shall be modified
   -d FREQ, --min FREQ      new minimum CPU frequency the governor may select
   -u FREQ, --max FREQ      new maximum CPU frequency the governor may select
   -g GOV, --governor GOV   new cpufreq governor
   -f FREQ, --freq FREQ     specific frequency to be set. Requires userspace
                            governor to be available and loaded
   -r, --related            Switches all hardware-related CPUs
   -h, --help               Prints out this screen
 
 Notes:
 1. Omitting the -c or --cpu argument is equivalent to setting it to zero
 2. The -f FREQ, --freq FREQ parameter cannot be combined with any other parameter
    except the -c CPU, --cpu CPU parameter
 3. FREQuencies can be passed in Hz, kHz (default), MHz, GHz, or THz
    by postfixing the value with the wanted unit name, without any space
    (FREQuency in kHz =^ Hz * 0.001 =^ MHz * 1000 =^ GHz * 1000000).
c、r はマルチプロセッサーのシステムでしか意味がないので~
bc10 で実質的に有効なのは d、u、g、f オプションです。~
~
500MHz 動作に変更したい場合は以下のように設定します。~
 # cpufreq-set -f 500MHz
変更に成功した場合はメッセージなど何も表示されません。~
反映されたか確認したい場合は再度 cpufreq-info を実行する必要があります。~
 # cpufreq-info
 cpufrequtils 006: cpufreq-info (C) Dominik Brodowski 2004-2009
 Report errors and bugs to cpufreq@vger.kernel.org, please.
 analyzing CPU 0:
   driver: omap
   CPUs which run at the same hardware frequency: 0
   CPUs which need to have their frequency coordinated by software: 0
   maximum transition latency: 300 us.
   hardware limits: 125 MHz - 600 MHz
   available frequency steps: 125 MHz, 250 MHz, 500 MHz, 550 MHz, 600 MHz
   available cpufreq governors: conservative, ondemand, powersave, userspace, performance
   current policy: frequency should be within 125 MHz and 600 MHz.
                   The governor "userspace" may decide which speed to use
                   within this range.
   current CPU frequency is 500 MHz (asserted by call to hardware).
   cpufreq stats: 125 MHz:0.00%, 250 MHz:0.00%, 500 MHz:3.51%, 550 MHz:0.00%, 600 MHz:96.49%  (1)
また、/proc/cpuinfo を確認すると動作周波数によって BogoMIPS が変化するので、~
これによっても変更の反映を確認することができます。~

**動作周波数別ネットワークスループット [#h302f02b]
bc10-router をルーターモードで起動し、~
OMAP3530 の cpufreq で設定可能な 125、250、500、550、600 MHzで動作させた際の~
ネットワークスループットを比較します。~
テストには nuttcp を使用します。~
テストに使用する対抗側の PC は[[bc10-router/ネットワークパフォーマンス測定]] で使用したのと同じものです。~
~
WAN側: bc10-router nuttcp -S~
LAN側:  PC nuttcp 192.168.30.1~

・kernel 3.3.7~
-600MHz
BogoMIPS 581.89~
|回     |      1|      2|      3|      4|      5|      6|      7|      8|      9|     10|   Avg.|h
|Mbps   |51.6822|50.4957|49.9095|50.0213|52.2133|47.8628|53.4301|53.2241|53.9936|53.5033|51.6336|
|%TX    |6      |6      |6      |6      |6      |7      |7      |7      |7      |7      |7      |
|%RX    |24     |24     |23     |23     |24     |22     |24     |24     |24     |24     |24     |
|retrans|0      |0      |0      |0      |0      |0      |0      |0      |0      |0      |0      |
|msRTT  |1.51   |2.01   |1.49   |1.49   |1.53   |1.92   |1.38   |1.41   |1.45   |1.40   |1.56   |

-550MHz~
BogoMIPS 533.31~
|回     |      1|      2|      3|      4|      5|      6|      7|      8|      9|     10|   Avg.|h
|Mbps   |50.6394|49.4836|56.4597|56.8420|52.9812|55.7499|56.5562|56.3471|52.7267|54.8336|54.2619|
|%TX    |6      |6      |7      |7      |7      |7      |7      |7      |7      |7      |7      |
|%RX    |24     |23     |25     |25     |25     |27     |26     |27     |25     |25     |25     |
|retrans|0      |0      |0      |0      |0      |0      |0      |0      |0      |0      |0      |
|msRTT  |3.29   |1.58   |1.34   |2.20   |1.89   |1.65   |1.34   |2.57   |1.62   |1.56   |1.90   |

-500MHz~
BogoMIPS 484.74~
|回     |      1|      2|      3|      4|      5|      6|      7|      8|      9|     10|   Avg.|h
|Mbps   |56.6270|57.3872|57.0966|56.7836|57.3331|55.9722|56.1364|55.8562|56.5218|55.6293|56.5343|
|%TX    |6      |7      |6      |6      |7      |7      |7      |7      |7      |7      |7      |
|%RX    |23     |25     |23     |24     |24     |25     |26     |26     |26     |26     |25     |
|retrans|0      |0      |0      |0      |0      |0      |0      |0      |0      |0      |0      |
|msRTT  |1.42   |1.60   |3.47   |1.98   |1.42   |1.73   |1.58   |1.54   |1.77   |2.57   |1.90   |

-250MHz~
BogoMIPS 242.87~
|回     |      1|      2|      3|      4|      5|      6|      7|      8|      9|     10|   Avg.|h
|Mbps   |31.6962|29.8153|29.7751|30.5470|31.3641|31.6964|32.6981|31.6658|30.9108|28.0258|30.8194|
|%TX    |2      |2      |2      |2      |2      |4      |4      |3      |3      |3      |3      |
|%RX    |14     |15     |14     |14     |16     |11     |11     |10     |18     |18     |14     |
|retrans|0      |0      |0      |0      |0      |0      |0      |0      |0      |0      |0      |
|msRTT  |2.31   |2.15   |1.77   |2.32   |1.98   |2.56   |3.73   |1.70   |1.85   |2.03   |2.24   |

-125MHz~
BogoMIPS 121.43~
|回     |      1|      2|      3|      4|      5|      6|      7|      8|      9|     10|   Avg.|h
|Mbps   |16.3279|16.0135|15.1922|15.6184|15.8227|16.6981|16.5575|16.4199|16.1731|16.1433|16.0988|
|%TX    |1      |1      |1      |1      |1      |1      |1      |1      |1      |1      |1      |
|%RX    |14     |12     |10     |14     |13     |12     |10     |13     |9      |15     |12     |
|retrans|0      |0      |0      |0      |0      |0      |0      |0      |0      |0      |0      |
|msRTT  |3.05   |2.44   |2.36   |2.31   |4.31   |5.22   |1.99   |2.33   |2.61   |4.58   |3.11   |

500MHz動作で nuttcp によるテスト負荷に十分な処理能力に達しているため、~
600MHz、550MHz、500MHz動作ではネットワークのスループットに大きな差は見られません。~
~
250MHz動作で処理能力がほぼ半分になるとスループットも 500MHz動作時のおよそ半分になり、~
125MHz動作で処理能力が 250MHz のほぼ半分になるとそれに応じてスループットも~
250MHz動作時の半分、500MHz動作時の四分の一になっています。~
~
bc10-router の AP に複数の Wi-Fi クライアントが接続して同時に通信するような場合には~
最大動作周波数での動作が必要となる場合もあり得ますが、~
クライアントが一台だけの場合には 500MHz 動作で必要十分な処理能力に達しているといえます。


**ondemand governor での動作 [#b4a88920]
cpufreq governor を ondemand に設定しすると動作周波数は自動的に~
設定可能範囲の下限である 125MHz に下がり、
通信などが行われ負荷が高くなった時だけ動作周波数が高くなるようになります。~
使用電力を少なくする、発熱を抑える、などの効果が期待できます。~
~




BC::labsへの質問は、bc9-dev @ googlegroups.com までお願い致します。
トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   最終更新のRSS