본문 바로가기

임베디드

쾌속 부팅 3차 도전

오늘의 부팅속도 목표는 5.5초에서 4.9초 미만으로 줄이는 것이다. 

 

시리얼 콘솔로만 분석할때에는 init에서 ffmpeg 어플리케이션이 시작할때까지 약 1.3초가 걸리는 것으로 보인다.

5.49 - 4.14 = 1.3초

[4.141249 0.009120] [    2.243069] Run /sbin/bootchartd as init process
[4.282580 0.141331] [    2.384207] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
[4.341134 0.058554] App Starting..
[4.365064 0.023930] App Started..
[4.407797 0.042733] [    2.509193] usb 1-1: new high-speed USB device number 2 using ehci-platform
[4.631074 0.223277] [    2.732835] hub 1-1:1.0: USB hub found
[4.643731 0.012657] [    2.745561] hub 1-1:1.0: 4 ports detected
[4.931290 0.287559] [    3.029724] dwmac-sun8i 1c30000.ethernet eth0: PHY [0.1:01] driver [Generic PHY]
[4.958673 0.027383] [    3.030973] dwmac-sun8i 1c30000.ethernet eth0: No Safety Features support found
[4.973068 0.014395] [    3.030990] dwmac-sun8i 1c30000.ethernet eth0: No MAC Management Counters available
[4.986550 0.013482] [    3.030999] dwmac-sun8i 1c30000.ethernet eth0: PTP not supported by HW
[4.999714 0.013164] [    3.031013] dwmac-sun8i 1c30000.ethernet eth0: configuring for phy/mii link mode
[5.013771 0.014057] [    3.113720] random: dhcpcd: uninitialized urandom read (120 bytes read)
[5.170690 0.156919] 
[5.174141 0.003451] 
[5.179140 0.004999] [    3.581073] cma: cma_alloc: alloc failed, req-size: 150 pages, ret: -12
[5.492169 0.313029] [    3.592939] sun6i-csi 1cb4000.csi: dma_alloc_coherent of size 614400 failed

 

그러나 Bootchart를 자세히 들여다 보면 init의 시작부터 ffmpeg 구동까지 2.3초 정도의 지연이 있음을 알수 있다.

Disk throughput에 보이는 2.3초의 지연중 상당 부분은 root파일 시스템이 마운트 될때까지 대기하는 시간으로 보인다.

마운트 속도가 빠르다면 상당히 많은 시간 절약이 가능할 수도 있다. 

그리고 ffmpeg 어플리케이션과 관련 라이브러리가 로딩되는 시간도 무시하지 못하겠지만, 0.5초 미만으로 느껴진다.

따라서 rootfs (EXT4) 관련 부분의 최적화를 먼저 시도해 보자.

 

170MB일때와 50MB일때 차이가 있는지 먼저 보았으며 약 50msec 정도 줄어드는 것으로 관측되었다.

그 다음 read only인 SqaushFS를 rootfs로 사용해보면 어떨까? 커널에 Sqaushfs-4를 빌트인으로 설정하고 테스트를 하였다.

 Read-only로 마운트 됨을 아래와 같이 확인하였다.

# mount
/dev/root on / type squashfs (ro,relatime)
devtmpfs on /dev type devtmpfs (rw,relatime,size=50712k,nr_inodes=12678,mode=755)
proc on /proc type proc (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620,ptmxmode=666)
tmpfs on /dev/shm type tmpfs (rw,relatime,mode=777)
tmpfs on /tmp type tmpfs (rw,relatime)
tmpfs on /run type tmpfs (rw,nosuid,nodev,relatime,mode=755)
sysfs on /sys type sysfs (rw,relatime)

그러나 부팅 시간은 EXT4와 거의 동일하다. 개발 과정에 편리한 EXT4는 변경없이 사용해 보자.

파일시스템 보다는 USB host 드라이버 이더넷 드라이버 관련 서비스때문에 어플리케이션 구동이 느려질 수도 있다.

 

커널 관련 수정을 해보자.

커널 부팅중 bogo mips 계산을 skip넘기기 위해 bootargs에 "lpj=240000"을 넣는다.

그럼 아래 커널 메시지가 더이상 보이지 않는다.

[    0.000901] Calibrating delay loop (skipped), value calculated using timer frequency.. 48.00 BogoMIPS (lpj=240000)

테스트에 사용하였던 squashfs와 bootchart 관련 내용도 모두 제거한다.

그리고 i3/S3는 싱글코어 이므로 SMP 관련 드라이버도 제거한다.

/etc/init.d/ 아래에 있는 몇 가지 서비스 구동 스크립트를 삭제하였다. 

 

5.5초에서 5.3초로 줄었다. ㅠㅠ

그리고 마침내 Kernel message출력을 없애기 위해 bootargs에 "quiet" 옵션을 추가하였다.

$ grabserial -v -d "/dev/ttyUSB0" -b 115200 -w 8 -p N -s 1 -e 30 -t -m "U-Boot SPL"
Opening serial port /dev/ttyUSB0
115200:8N1:xonxoff=0:rtscts=0
Program will end in 30 seconds
Printing timing information for each line
Matching pattern 'U-Boot SPL' to set base time
Use Control-C to stop...
[0.000000 0.000000] 
[0.000464 0.000464] U-Boot SPL 2017.01-rc2 (Jan 15 2020 - 14:05:36)
[0.004777 0.004777] DRAM: 128 MiB
[0.013199 0.008422] Trying to boot from MMC1
[0.320223 0.307024] 
[0.320300 0.000077] U-Boot 2017.01-rc2 (Jan 15 2020 - 14:05:36 +0900) Allwinner Technology
[0.326333 0.006033] 
[0.326421 0.000088] CPU:   Allwinner S3/V3s (SUN8I 1681)
[0.329415 0.002994] Model: FoxNux One
[0.332665 0.003250] DRAM:  128 MiB
[0.367577 0.034912] MMC:   SUNXI SD/MMC: 0
[0.459511 0.091934] Setting up a 1024x600 lcd console (overscan 0x0)
[0.503631 0.044120] dotclock: 51000kHz = 51000kHz: (1 * 3MHz * 102) / 6
[0.563294 0.059663] In:    serial@01c28000
[0.564516 0.001222] Out:   serial@01c28000
[0.566995 0.002479] Err:   serial@01c28000
[0.569203 0.002208] 
[0.569298 0.000095] 
[0.569374 0.000076] U-Boot 2017.01-rc2 (Jan 15 2020 - 14:05:36 +0900) Allwinner Technology
[0.575346 0.005972] 
[0.575413 0.000067] CPU:   Allwinner S3/V3s (SUN8I 1681)
[0.578693 0.003280] Model: FoxNux One
[0.580589 0.001896] DRAM:  128 MiB
[0.581431 0.000842] MMC:   SUNXI SD/MMC: 0
[0.583746 0.002315] Setting up a 1024x600 lcd console (overscan 0x0)
[0.588627 0.004881] dotclock: 51000kHz = 51000kHz: (1 * 3MHz * 102) / 6
[0.592370 0.003743] In:    serial@01c28000
[0.594818 0.002448] Out:   serial@01c28000
[0.597099 0.002281] Err:   serial@01c28000
[0.600367 0.003268] Net:   phy interface0
[0.601454 0.001087] eth0: ethernet@1c30000
[0.604133 0.002679] starting USB...
[0.606307 0.002174] No controllers found
[0.607508 0.001201] Press SPACE key two times to abort autoboot in 0 seconds
[0.692600 0.085092] switch to partitions #0, OK
[0.694311 0.001711] mmc0 is current device
[1.251749 0.557438] Scanning mmc 0:1...
[1.305648 0.053899] Found U-Boot script /boot.scr
[1.316365 0.010717] reading /boot.scr
[1.333930 0.017565] 596 bytes read in 19 ms (30.3 KiB/s)
[1.336976 0.003046] ## Executing script at 41900000
[1.349839 0.012863] reading zImage
[1.570621 0.220782] 4551264 bytes read in 221 ms (19.6 MiB/s)
[1.582610 0.011989] reading sun8i-s3-foxnux-one.dtb
[1.608761 0.026151] 14138 bytes read in 26 ms (530.3 KiB/s)
[1.611899 0.003138] ## Flattened Device Tree blob at 41800000
[1.615119 0.003220]    Booting using the fdt blob at 0x41800000
[1.619799 0.004680]    Loading Device Tree to 42df9000, end 42dff739 ... OK
[1.626008 0.006209] Cannot setup simplefb: node not found
[1.632380 0.006372] 
[1.632468 0.000088] Starting kernel ...
[1.633799 0.001331] 
[2.023983 0.390184] [    0.081681] sun4i-usb-phy 1c19400.phy: Couldn't request ID GPIO
[2.102170 0.078187] [    0.233333] dwmac-sun8i 1c30000.ethernet: IRQ eth_wake_irq not found
[2.108150 0.005980] [    0.239760] dwmac-sun8i 1c30000.ethernet: IRQ eth_lpi not found
[2.549505 0.441355] [    0.680621] sun4i-codec 1c22c00.codec: Failed to register our card
[2.871373 0.321868] [    1.002263] debugfs: Directory '1c22c00.codec' with parent 'V3s Audio Codec' already present!
[3.100349 0.228976] App Starting..
[3.128287 0.027938] App Started..
[3.274329 0.004870] [    1.929379] cma: cma_alloc: alloc failed, req-size: 150 pages, ret: -12
[3.810088 0.535759] [    1.936168] sun6i-csi 1cb4000.csi: dma_alloc_coherent of size 614400 failed

총 부팅시간은 4초 이하가 되었다. Kernel의 quiet 옵션만으로 1.2초 정도 줄어들었다 ! 

115200bps라는 시리얼 통신은 1초에 약 10,000개의 문자를 출력할 수 있는 속도이다.

커널의 printk 함수 및 IO에 의한 CPU 로드와 5000여개의 문자를 합하면 그 정도 시간이 필요한것 같다.

init에서 어플리케이션 구동 사이의 시간도 줄어들었다.

 

오늘의 목표는 초과 달성하였지만 시스템 안정성은 어떤지 장시간 테스트 해보아야겠다.

 

예상으로는 u-boot에서 falcon 모드가 잘 동작한다면 3.5초 미만으로 만들수 있겠다.

금요일에는 3초 이하로 달성하여 이 지겹고 고단한 과정을 아름답게 끝내면 좋겠다.

 

추신: buildroot 튜닝할때 유용하게 사용한 명령어 몇개를 기록해 본다.

<1> Kernel 설정을 변경할때

make linux-menuconfig
make linux-rebuild

<2> u-boot 설정을 변경할때

make uboot-menuconfig

make uboot-rebuild

<3> busybox 설정을 변경할때

make busybox-menuconfig

 

 

 

'임베디드' 카테고리의 다른 글

SD-card 메모리 맵  (0) 2020.01.22
쾌속 임베디드 리눅스 부팅 4차 도전  (0) 2020.01.16
쾌속 부팅 2차 도전  (0) 2020.01.14
쾌속 부팅을 향한 첫 걸음  (0) 2020.01.13
USB 무선랜 드라이버 구동  (0) 2020.01.11