bc10-router

cpufreq による動的動作周波数変更

Linux カーネルには CPU の動作周波数や動作電圧を動的に変更する cpufreq という仕組みがあります。

周波数や電圧を変更する方法は CPU によって異なり、CPU アーキテクチャごとにデバイスドライバが用意されます。
x86 アーキテクチャの CPU はかなり以前から対応していたのですが、
ARM アーキテクチャは SoC ごとに対応が必要で、
bc10 で使用している Texus Instruments の OMAP3530 では
3.2 kernel あたりから使用可能になりました。

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

driver

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

CPUfreq governor は動作周波数の変更に関する規則を決定するものです。
bc10 で使用している OMAP3530 で使用できる governor は以下のものです。

performance最大動作周波数で CPU を動作させます。
powersave最小動作周波数で CPU を動作させます。
userspaceroot 権を持つユーザーやプログラムが動的に動作周波数を変更できるようにします。
ondemandCPU 負荷に応じて動的に動作周波数を変更します。低遅延で負荷の変化に追従します。
conservativeCPU 負荷に応じて動的に動作周波数を変更します。バッテリー動作向けに動作周波数はゆっくりと段階的に変更します。

cpufreq インタフェース

この設定を有効にした 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_freqgovernor と cpufreq コアから得た現在の動作周波数。kernel はこの値を現在の動作周波数とみなします。(kHz)
scaling_drivercpufreq のハードウェアドライバー。
scaling_governor現在利用中の governor。ここへ利用したい governor を echo することで変更可能。
scaling_max_freq動作ポリシーによって制限された最大動作周波数。ここへ設定したい最大周波数を echo することで変更可能。変更時は先にこちらを設定します。
scaling_min_freq動作ポリシーによって制限された最小動作周波数。ここへ設定したい最小周波数を echo することで変更可能。変更時は max 設定後に設定します。
scaling_setspeedここへ変更したい動作周波数を echo することで動作周波数の変更を行えます。
statstime_in_state設定可能な動作周波数ごとにどれだけの時間動作したかのリスト。
total_trans動作周波数の変更が合計何回行われたかの回数。
trans_table設定可能などの動作周波数からどの動作周波数へ変更が行われたかのテーブル。

cpufrequtils

このインタフェースを直接操作するのは煩雑なので、操作を行うためのユーティリティー 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 が変化するので、
これによっても変更の反映を確認することができます。

動作周波数別ネットワークスループット

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
    12345678910Avg.
    Mbps51.682250.495749.909550.021352.213347.862853.430153.224153.993653.503351.6336
    %TX66666777777
    %RX2424232324222424242424
    retrans00000000000
    msRTT1.512.011.491.491.531.921.381.411.451.401.56
  • 550MHz
    BogoMIPS 533.31
    12345678910Avg.
    Mbps50.639449.483656.459756.842052.981255.749956.556256.347152.726754.833654.2619
    %TX66777777777
    %RX2423252525272627252525
    retrans00000000000
    msRTT3.291.581.342.201.891.651.342.571.621.561.90
  • 500MHz
    BogoMIPS 484.74
    12345678910Avg.
    Mbps56.627057.387257.096656.783657.333155.972256.136455.856256.521855.629356.5343
    %TX67667777777
    %RX2325232424252626262625
    retrans00000000000
    msRTT1.421.603.471.981.421.731.581.541.772.571.90
  • 250MHz
    BogoMIPS 242.87
    12345678910Avg.
    Mbps31.696229.815329.775130.547031.364131.696432.698131.665830.910828.025830.8194
    %TX22222443333
    %RX1415141416111110181814
    retrans00000000000
    msRTT2.312.151.772.321.982.563.731.701.852.032.24
  • 125MHz
    BogoMIPS 121.43
    12345678910Avg.
    Mbps16.327916.013515.192215.618415.822716.698116.557516.419916.173116.143316.0988
    %TX11111111111
    %RX141210141312101391512
    retrans00000000000
    msRTT3.052.442.362.314.315.221.992.332.614.583.11

500MHz動作で nuttcp によるテスト負荷に十分な処理能力に達しているため、
600MHz、550MHz、500MHz動作ではネットワークのスループットに大きな差は見られません。

250MHz動作で処理能力がほぼ半分になるとスループットも 500MHz動作時のおよそ半分になり、
125MHz動作で処理能力が 250MHz のほぼ半分になるとそれに応じてスループットも
250MHz動作時の半分、500MHz動作時の四分の一になっています。

bc10-router の AP に複数の Wi-Fi クライアントが接続して同時に通信するような場合には
最大動作周波数での動作が必要となる場合もあり得ますが、
クライアントが一台だけの場合には 500MHz 動作で必要十分な処理能力に達しているといえます。

ondemand governor での動作

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


BC::labsへの質問は、bc9-dev @ googlegroups.com までお願い致します。
トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   最終更新のRSS
Last-modified: 2013-01-31 (木) 19:45:09 (4093d)