[CuBox-i] Real-time Kernel and Tuning

*** This page only applies CuBox-i Only ***

You can run MuBox with real-time kernel on CuBox-i. Here is a general guide. This is not bullet proof and your mileage may vary.

Install Real-Time Kernel

Follow CuBox-i page to install real-time kernel on the uSD card. If you are already running vanilla (non-rt) kernel, you can download and install the realtime kernel by the following instructions:

# remountrw
# cd
# wget http://mirror.voyage.hk/download/voyage-mubox/cubox-i/kernel-cubox-i-latest-rt.tar.xz
# tar -Jxvf kernel-cubox-i-latest-rt.tar.xz -C /
# sync
# reboot

After reboot, run the following command to verify your kernel:

# uname -rv
3.14.10-rt7 #1 SMP PREEMPT RT Wed Jul 9 16:38:09 HKT 2014

Please note that the following techniques only applies to CuBox-i4Pro with 4 cores. We will fine-tune the system for the following:

  1. bind all interrupts to core 0
  2. bind USB IRQ handlers to core 1
  3. bind MPD processes to core 2 and 3

Bind all interrupts to core 0

# for IRQ in /proc/irq/* ; do echo 1 > $IRQ/smp_affinity ; done

There are some error popping out. Please ignore them as binding some interrupts to a single core may not be allowed. After all, you should see the almost all interrupt are running on core 0:

root@voyage-mubox:~# cat /proc/interrupts
           CPU0       CPU1       CPU2       CPU3
 29:       9246       8308       2675      16941       GIC  29  twd
 34:       5177          0          0          0       GIC  34  sdma
 51:          0          0          0          0       GIC  51  rtc alarm
 55:      10470          0          0          0       GIC  55  mmc0
 58:       1890          0          0          0       GIC  58  IMX-uart
 70:          0          0          0          0       GIC  70  21a8000.i2c
 71:          0          0          0          0       GIC  71  ahci
 72:          0          0          0          0       GIC  72  ci_hdrc_imx
 75:         67          0          0          0       GIC  75  ci_hdrc_imx
 84:        116          0          0          0       GIC  84  spdif
 87:          0          0          0          0       GIC  87  i.MX Timer Tick
150:     196477          0          0          0       GIC 150  2188000.ethernet
151:          0          0          0          0       GIC 151  2188000.ethernet
164:          0          0          0          0  gpio-mxc   4  2194000.usdhc cd
233:          0          0          0          0  gpio-mxc   9  gpio-ir-recv-irq
384:          0          0          0          0       IPU  23  imx_drm
385:          0          0          0          0       IPU  28  imx_drm
386:          0          0          0          0       IPU  23  imx_drm
387:          0          0          0          0       IPU  28  imx_drm
IPI0:          0          0          0          0  CPU wakeup interrupts
IPI1:          0          0          0          0  Timer broadcast interrupts
IPI2:       9942      14490      46977      17857  Rescheduling interrupts
IPI3:          4          6          6          8  Function call interrupts
IPI4:          0          1          0          1  Single function call interrupts
IPI5:          0          0          0          0  CPU stop interrupts
IPI6:          0          0          0          0  IRQ work interrupts
IPI7:          0          0          0          0  completion interrupts
Err:          0

bind USB IRQ handlers to core 1

In realtime kernel, there is a soft interrupt process for the USB controllers, now new bind these soft interrupt process to core 1:

# for PID in $(pgrep ci_hdrc) ; do taskset -pc 1 $PID ; done
pid 73's current affinity list: 0-3
pid 73's new affinity list: 1
pid 74's current affinity list: 0-3
pid 74's new affinity list: 1

From /proc/interrupts, we see that irq 72 and 75 are for ci_hdrc_imx, the USB controllers. Now, we bind these interrupts to core 1 as well:

echo 2 > /proc/irq/72/smp_affinity
echo 2 > /proc/irq/75/smp_affinity

bind MPD processes to core 2 and 3

Next, for the rest of 2 cores, core 2 and 3, we assign MPD process to them.

# taskset -pca 2,3 $(pgrep mpd)
pid 2652's current affinity list: 0-3
pid 2652's new affinity list: 2,3
pid 2654's current affinity list: 0-3
pid 2654's new affinity list: 2,3
pid 2658's current affinity list: 0-3
pid 2658's new affinity list: 2,3
pid 2659's current affinity list: 0-3
pid 2659's new affinity list: 2,3
pid 2662's current affinity list: 0-3
pid 2662's new affinity list: 2,3

If you mount CIFS shared drive, you should also set the real-time priority for cifsd:

# chrt -f -p 49 $(pgrep cifsd)
# ps -eLo pid,group,lwp,rtprio,priority,time,cmd | egrep "cifsd"
 1518 root      1518     49 -54 00:00:05 [cifsd]