본문 바로가기

카테고리 없음

[lisa-qemu] arm64 kernel 개발자를 위한 에뮬레이터 환경

개발자의 절대악 귀차니즘

아무래도 커널 개발을 하다보면 실제 디바이스에 내가 빌드한 이미지를 직접 올려서 테스트 하는 것을 가장 선호하게 된다. 하지만 이렇게 할때 다양한 버전의 커널을 테스트 하기 어렵다는 점이 있고 회사용 개발 디바이스가 아닌 개인용 개발 디바이스의 필요성을 느낄 때가 있다. 회사가 안드로이드 디바이스를 개발하게 되면 구글의 픽셀폰이라든지 레퍼런스가 될만한 디바이스가 필요하게 되는데 이걸 매번 회사에 요청하기도 귀찮고 요청했다가 거절당하거나 디바이스를 받기까지 시간이 엄청 걸리기도 한다. 하지만 테스트용 디바이스를 가지게 되더라도 내가 게으르거나 다른일로 바쁘면 한동안 방치해 두었던 디바이스를 꺼내 내가 원하는 수준의 커널환경을 만드는데 시간이 많이 소모되기도 한다. 다행히 나는 에뮬레이터 환경의 커널로도 충분할 때가 많고 이 버전 저 버전 바꿔가며 테스트 할 때 빠르게 할 수 있는 장점이 있어서 qemu를 사용해왔다. 오랜만에 다시 qemu를 사용할 일이 생겼는데 또다시 환경설정을 해야 하는 상황이었다. 귀차니즘이 발동하여 이리저리 검색해보며 빠르고 쉽게 설치할 수 있는 새로운 프로젝트가 있나 찾아봤는데 arm64 코어 커널 개발자용 lisa-qemu project를 발견하게 되었다. 프로젝트의 git 히스토리를 보니 2019년 12월 9일에 README.md를 추가하며 첫 커밋을 해놓았다. 따끈따끈한 프로젝트로구나.

리사(LISA) & lisa-qemu 란?

LISA는 Linux Integrated/Interactive System Analysis 의 약자로 커널 개발자가 수정한 코드가 시스템 성능에 어느정도 영향을 끼치는지 테스트해주는 툴킷이다. lisa-qemu는 qemu VM 에서 lisa를 돌릴 수 있도록 해준다. 저자 본인은 이 프로젝트로 CFS스케쥴러 성능 테스트에 활용했다고 하는데 커널 시큐리티 엔지니어인 나로서도 정말 활용하기에 딱 맞는 프로젝트였다. qemu VM상에 돌아가는 기본 OS는 우분투이다.

 

테스트 환경

OS: Ubuntu 18.04

Mem: 16G

CPU: 8 core

Storage: 1TB NVME

 

설치 매뉴얼

github.com/rf972/lisa-qemu

 

rf972/lisa-qemu

This repo provides an integration which allows LISA to work with QEMU VMs. - rf972/lisa-qemu

github.com

내가 만난 에러와 해결책

lisa-qemu$ python3 scripts/build_image.py


Image creation starting.  Please be patient, this may take several minutes...
To enable more verbose tracing of each step, please use the --debug option.

Image resized.
guest user:pw qemu:qemupass
ERROR:root:Failed to launch QEMU, command line:
Failed to prepare guest environment
Traceback (most recent call last):
  File "/home/moley/source/kernel/lisa-qemu/lisa-qemu/external/qemu/tests/vm/basevm.py", line 285, in boot
    guest.launch()
  File "/home/moley/source/kernel/lisa-qemu/lisa-qemu/external/qemu/tests/vm/../../python/qemu/machine.py", line 317, in launch
    self._launch()
  File "/home/moley/source/kernel/lisa-qemu/lisa-qemu/external/qemu/tests/vm/../../python/qemu/machine.py", line 344, in _launch
    self._post_launch()
  File "/home/moley/source/kernel/lisa-qemu/lisa-qemu/external/qemu/tests/vm/../../python/qemu/machine.py", line 289, in _post_launch
    self._qmp.accept()
  File "/home/moley/source/kernel/lisa-qemu/lisa-qemu/external/qemu/tests/vm/../../python/qemu/qmp.py", line 184, in accept
    return self.__negotiate_capabilities()
  File "/home/moley/source/kernel/lisa-qemu/lisa-qemu/external/qemu/tests/vm/../../python/qemu/qmp.py", line 88, in __negotiate_capabilities
    raise QMPCapabilitiesError
qemu.qmp.QMPCapabilitiesError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/moley/source/kernel/lisa-qemu/lisa-qemu/external/qemu/tests/vm/basevm.py", line 616, in main
    return vm.build_image(args.image)
  File "../tests/vm/ubuntu.aarch64", line 76, in build_image
    self.boot(img_tmp, extra_args = ["-cdrom", ci_img])
  File "../tests/vm/ubuntu.aarch64", line 67, in boot
    super(UbuntuAarch64VM, self).boot(img, extra_args=extra_args)
  File "/home/moley/source/kernel/lisa-qemu/lisa-qemu/external/qemu/tests/vm/basevm.py", line 288, in boot
    logging.error(" ".join([qemu_bin] + args))
NameError: name 'qemu_bin' is not defined
scripts/build_image.py: cmd failed with status: 2 cmd: env QEMU_LOCAL=1 QEMU_CONFIG=/home/moley/source/kernel/lisa-qemu/lisa-qemu/build/VM-ubuntu.aarch64/conf.yml  python3 -B ../tests/vm/ubuntu.aarch64 --image /home/moley/source/kernel/lisa-qemu/lisa-qemu/build/VM-ubuntu.aarch64/ubuntu.aarch64.img --force --build-path /home/moley/source/kernel/lisa-qemu/lisa-qemu/external/qemu/build  --build-image /home/moley/source/kernel/lisa-qemu/lisa-qemu/build/VM-ubuntu.aarch64/ubuntu.aarch64.img

  

위 에러만 보면 뭐가 잘못되었는지 알기 어렵다. --debug 옵션을 넣어서 다시 빌드해 보았다.

$ python3 scripts/build_image.py --debug
....생략....
DEBUG:qemu.machine:Output: "qemu-system-aarch64: cannot set up guest memory 'mach-virt.ram': Cannot allocate memory\n"
....생략....

결국 메모리가 모자랐다는 것. --debug의 출력들을 자세히 보니 과연 -m 16G 부분이 눈에 들어온다. 내 랩탑의 메모리가 16G인데 가상머신 용으로 16G를 잡으려 하다니... 그래서 아래와 같이 소박하게 다시 조정해 주었다. (CPU 코어수도 조정해 주었다.)

diff --git a/conf/conf_default.yml b/conf/conf_default.yml
index 3933446..c322001 100644
--- a/conf/conf_default.yml
+++ b/conf/conf_default.yml
@@ -21,16 +21,12 @@ qemu-conf:
     cpu: max
     #machine: virt,gic-version=max
     #machine: pc
-    memory: 16G
+    memory: 4G
     #
     # This specifies a 16 core, 8 core/socket machine with 4 numa nodes
     #
-    qemu_args: "-smp cpus=16,sockets=2,cores=8
-                -numa node,cpus=0-3,nodeid=0 -numa node,cpus=4-7,nodeid=1
-                -numa node,cpus=8-11,nodeid=2 -numa node,cpus=12-15,nodeid=3
-                -numa dist,src=0,dst=1,val=15 -numa dist,src=2,dst=3,val=15
-                -numa dist,src=0,dst=2,val=20 -numa dist,src=0,dst=3,val=20
-                -numa dist,src=1,dst=2,val=20 -numa dist,src=1,dst=3,val=20"
+    qemu_args: "-smp cpus=4,sockets=2,cores=2
+                -numa node,cpus=0-1,nodeid=0 -numa node,cpus=2-3,nodeid=1"
     #dns: 1.234.567.89
     # By default install as little as possible since lisa will
     # install whatever it needs.

 

이제 매뉴얼 따라서 만들어진 이미지를 실행해 보았다.

$ python3 scripts/launch_image.py
Conf:        /home/moley/source/kernel/lisa-qemu/lisa-qemu/build/VM-ubuntu.aarch64/conf.yml
Image type:  ubuntu.aarch64
Image path:  /home/moley/source/kernel/lisa-qemu/lisa-qemu/build/VM-ubuntu.aarch64/ubuntu.aarch64.img

Launching Image.  Please be patient, this may take several minutes...
To enable more verbose tracing of each step, please use the --debug option.


qemu@ubuntu-aarch64-guest:~$ uname -a
Linux ubuntu-aarch64-guest 4.15.0-109-generic #110-Ubuntu SMP Tue Jun 23 02:40:18 UTC 2020 aarch64 aarch64 aarch64 GNU/Linux

qemu@ubuntu-aarch64-guest:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            2.0G     0  2.0G   0% /dev
tmpfs           395M  768K  394M   1% /run
/dev/vda1        51G  979M   50G   2% /
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/vda15       98M  122K   98M   1% /boot/efi
tmpfs           395M     0  395M   0% /run/user/1000
qemu@ubuntu-aarch64-guest:~$ pwd
/home/qemu
qemu@ubuntu-aarch64-guest:~$ free
              total        used        free      shared  buff/cache   available
Mem:        4037596       90364     3815184         768      132048     3775652
Swap:             0           0           0
qemu@ubuntu-aarch64-guest:~$ cat /proc/cpuinfo
processor       : 0
BogoMIPS        : 125.00
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm ilrcpc flagm
CPU implementer : 0x00
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0x051
CPU revision    : 0

processor       : 1
BogoMIPS        : 125.00
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm ilrcpc flagm
CPU implementer : 0x00
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0x051
CPU revision    : 0

processor       : 2
BogoMIPS        : 125.00
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm ilrcpc flagm
CPU implementer : 0x00
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0x051
CPU revision    : 0

processor       : 3
BogoMIPS        : 125.00
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm ilrcpc flagm
CPU implementer : 0x00
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0x051
CPU revision    : 0