4
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ubuntu lowlatancy kernelを使ってrealtime性の高いコードを書く

4
Posted at

lowlatency kernelを使うと実時間性の高いコードが書ける、らしいです。

インストール

sudo aptitude install inux-lowlatency
sudo reboot
uname -a
Linux hogehogemachine 3.2.0-39-lowlatency #41-Ubuntu SMP PREEMPT Fri Mar 1 16:18:04 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

limits.confの設定

/etc/security/limits.confを修正。以下を追記する

* - rtprio 99
* - nice -10

そんでreboot

sudo reboot

確認

ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 30
file size               (blocks, -f) unlimited
pending signals                 (-i) 30573
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 99
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 30573
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Cのコードで優先度を設定する

以下のコードを仕込む

# include <pthread.h>

/* 中略 */

struct sched_param thread_param;
policy = SCHED_FIFO;
thread_param.sched_priority = sched_get_priority_max(policy);
if ( pthread_setschedparam(pthread_self(), policy, &thread_param) < -1 ) {
  perror("sched_setscheduler");
}

確認

優先度がマイナスの値になっていることを確認

ps alx
F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND
0  1000 24785 24744 -100  - 1048680 15908 hrtime Ssl ?          0:00 my_owesome_program
4
6
0

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?