Ubuntu 18.04 LTSのセットアップ7 - JACK優先度とCPU

インストール後のメモその7です。

audioグループへの参加。

$ groups
ohashi adm cdrom sudo dip plugdev lpadmin sambashare

audioがないことを確認。

$ sudo adduser $USER audio
ユーザー `ohashi' をグループ `audio' に追加しています...
ユーザ ohashi をグループ audio に追加
完了。

いったんログアウト。と思ったがアップデートがあったので再起動。

$ groups
ohashi adm cdrom sudo audio dip plugdev lpadmin sambashare

audioが追加された。

$ sudo vi /etc/security/limits.conf 

で以下を追加。

@audio          -       rtprio          99
@audio      -   memlock     unlimited
@audio      -   nice        -19

niceの行はよく分かってないけどググったら出てきたから一応入れてみた。

念のため、またログアウト・ログインする。一緒にやっておけばよかった。

qjackctlを立ち上げて、設定。

f:id:ohac:20180602125927p:plain

f:id:ohac:20180602130152p:plain

リアルタイムをチェック、レイテンシの許容度やPCの性能に合わせてバッファサイズ(フレームとピリオド数)を設定。プライオリティを最高の99に設定。

最後に開始を押して、音が出れば成功。

f:id:ohac:20180602125935p:plain

メトロノームでも鳴らしてみる。

$ jack_metro -b 60

systemにドラッグして接続。

f:id:ohac:20180602125940p:plain

CPUの動作周波数の設定ができるようにする。

$ sudo apt install cpufrequtils

現状こんな感じ。

$ cpufreq-info | head -13
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 0.97 ms.
  hardware limits: 800 MHz - 3.80 GHz
  available cpufreq governors: performance, powersave
  current policy: frequency should be within 800 MHz and 3.80 GHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
  current CPU frequency is 900 MHz.

900 MHzで動作していて、省電力モードっぽい。 なお、linux kernelは事情があり4.4.0-122-lowlatencyを使用している。

governorsにはperformanceとpowersaveがあるので、performanceに切り替えてみる。

$ sudo cpufreq-set -g performance
$ cpufreq-info | head -13
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
  driver: intel_pstate
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 0.97 ms.
  hardware limits: 800 MHz - 3.80 GHz
  available cpufreq governors: performance, powersave
  current policy: frequency should be within 800 MHz and 3.80 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency is 3.65 GHz.
$ cpufreq-info | grep current.CPU
  current CPU frequency is 3.60 GHz.
  current CPU frequency is 3.61 GHz.
  current CPU frequency is 3.67 GHz.
  current CPU frequency is 3.64 GHz.
  current CPU frequency is 3.53 GHz.
  current CPU frequency is 3.56 GHz.
  current CPU frequency is 3.70 GHz.
  current CPU frequency is 3.70 GHz.

ちなみにHyper Threadingは切った方がよいらしい。(今は切ってない)

powersaveに戻してみる。

$ sudo cpufreq-set -g powersave
$ cpufreq-info | grep current.CPU
  current CPU frequency is 900 MHz.
  current CPU frequency is 1.24 GHz.
  current CPU frequency is 922 MHz.
  current CPU frequency is 1.02 GHz.
  current CPU frequency is 900 MHz.
  current CPU frequency is 900 MHz.
  current CPU frequency is 1.12 GHz.
  current CPU frequency is 900 MHz.

コマンドだと面倒くさいが、後でCadenceとCatiaをインストールするので、 そこからGUIで操作可能になる。同じくGUIでJACKのバッファサイズも動的に切り替えられる。

リスニングではバッファ多めのpowersaveで、制作時はバッファ少なめのperformanceでといった運用が可能に。