LoginSignup
4
6

More than 5 years have passed since last update.

[メモ] ラズパイ: リアルタイムカーネルを使ってみよう (PREEMPT_RT)

Posted at

概要

https://github.com/raspberrypi/linux を見てると、rpi-4.14.y-rt というブランチが。。

らずぱいのフォーラムの、New RT (Real Time) kernel branch にて、PREEMPT_RTをサポートしたブランチ (-rt) を作った、とのこと。
このブランチからソースを持ってきて、いつも通りカーネルのビルドをすればよいらしい。

ビルドしたバイナリを用意したので、かるく使ってみよう。

  • 特にリアルタイムカーネルを実感するほどのようなことを試していないので、うまいテストがあったら教えてください...

  • archlinux: リアルタイムカーネル

環境

  1. 実行環境
    • Raspberry Pi 3
    • Raspbian: 以下をベースに、sudo sh -c 'apt update && apt upgrade && reboot'
      • 2018-06-27-raspbian-stretch.img
      • 2018-06-27-raspbian-stretch-lite.img
    • カーネルのバージョンが
      Linux raspberrypi 4.14.50-v7+ #1122 SMP Tue Jun 19 12:26:26 BST 2018 armv7l GNU/Linux
      から、
      Linux raspberrypi 4.14.52-v7+ #1123 SMP Wed Jun 27 17:35:49 BST 2018 armv7l GNU/Linux
      になる。(2018/7/30現在)

TL;DR;

  1. Raspbianを焼く
  2. sudo sh -c 'apt update && apt upgrade && reboot'
  3. 以下、実行

    コピペ
    cd
    mkdir -p work
    cd work
    wget https://github.com/mt08xx/files/raw/master/rpi/raspberrypi-kernel-4.14.52-rt34-SMP-PREEMPT-RT-20180730.1.tbz
    tar jxvf ./raspberrypi-kernel-4.14.52-rt34-SMP-PREEMPT-RT-20180730.1.tbz
    sudo cp -rv boot lib /
    sudo reboot
    
  4. 再起動後

    カーネルバージョン確認
    pi@raspberrypi:~ $ uname -a
    Linux raspberrypi 4.14.52-rt34-v7 #1 SMP PREEMPT RT Mon Jul 30 17:20:43 UTC 2018 armv7l GNU/Linux
    pi@raspberrypi:~ $ 
    

手順

  1. ソース取得

    # https://github.com/raspberrypi/linux/tree/rpi-4.14.y-rt
    # v4.14.52-rt34 - hash: 36674db1d99952eb722669a69a659d6ba082847d
    wget https://codeload.github.com/raspberrypi/linux/zip/36674db1d99952eb722669a69a659d6ba082847d -O linux-36674db1d99952eb722669a69a659d6ba082847d.zip
    
  2. あとは、いつも通りビルド。。

  3. ビルド後、アーカイブ作成

    KERNEL=kernel7
    mkdir -p mnt/boot/overlays/
    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=mnt modules_install
    #
    cp arch/arm/boot/zImage mnt/boot/${KERNEL}.img
    cp arch/arm/boot/dts/*.dtb mnt/boot
    cp arch/arm/boot/dts/overlays/*.dtb* mnt/boot/overlays/
    cp arch/arm/boot/dts/overlays/README mnt/boot/overlays/
    #
    # アーカイブ作成
    cd mnt
    tar cjvf ~/raspberrypi-kernel-4.14.52-rt34-SMP-PREEMPT-RT-2018xxxx.y.tbz boot lib
    

テスト

  1. ツールビルド

    sudo apt install git build-essential -y
    cd ~
    git clone git://git.kernel.org/pub/scm/linux/kernel/git/clrkwllms/rt-tests.git
    cd ~/rt-tests
    make -j4
    
  2. 軽くテスト

    # clock固定
    echo performance | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
    # シングルコア
    cd ~/rt-tests && ./hackbench -l 1000000 & sleep 5 ; sudo ./cyclictest -p98 -m -l 50000; sleep 5 ; killall hackbench
    # マルチコア
    cd ~/rt-tests && ./hackbench -l 1000000 & sleep 5 ; sudo ./cyclictest --smp -p98 -m -l 50000; sleep 5 ; killall hackbench
    

その他

  1. 4.14.52のカーネルに戻す。

    4.14.52
    # Linux raspberrypi 4.14.52-v7+ #1123 SMP Wed Jun 27 17:35:49 BST 2018 armv7l GNU/Linux
    # https://github.com/Hexxeh/rpi-firmware/commit/963a31330613a38e160dc98b708c662dd32631d5
    sudo rpi-update 963a31330613a38e160dc98b708c662dd32631d5
    
  2. config.txtにて、kernel=ore-no-rt-kernel.img という感じでファイル名で指定できる。

  3. make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig で、/をおして、PREEMPT_RTを検索してみるのもよいかと。

4
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6