Closed Bug 1440098 Opened 7 years ago Closed 6 years ago

Experiment with running a kvm-accelerated x86 android emulator in docker

Categories

(Testing :: General, enhancement, P1)

Version 3
enhancement

Tracking

(Not tracked)

RESOLVED WORKSFORME

People

(Reporter: gbrown, Assigned: gbrown)

References

(Blocks 1 open bug)

Details

Recent emulator experiments on moonshot hardware and packet.net did not run docker. Can we run the android emulator with an x86 image and use kvm-acceleration inside a docker container?
Running on my own laptop....

Be sure to run with --privileged:

sudo docker run --privileged -ti

as root (not sure how much of this is necessary yet):

apt-get update
apt-get install kvm
apt-get upgrade
sudo modprobe kvm_intel
mknod /dev/kvm c 10 232
chgrp kvm /dev/kvm
adduser worker kvm
chmod g+w /dev/kvm
modprobe kvm_intel

<download avd, emulator>

worker@cbb9225b6bb6:~$ ls -l /dev/kvm
crw-rw-r-- 1 root kvm 10, 232 Feb 21 21:00 /dev/kvm
worker@cbb9225b6bb6:~$ lsmod | grep kvm
kvm_intel             176128  3
kvm                   544768  1 kvm_intel
irqbypass              16384  1 kvm
worker@cbb9225b6bb6:~$ id
uid=1000(worker) gid=1000(worker) groups=1000(worker),44(video),127(kvm)

worker@cbb9225b6bb6:~$ kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used

worker@cbb9225b6bb6:~$ emulator -accel-check
accel:
0
KVM (version 12) is installed and usable.
accel



export PATH=~/android-sdk-linux/emulator:~/android-sdk-linux/tools:~/android-sdk-linux/platform-tools:$PATH
xvfb-run --server-args="-screen 0 1600x1200x24" emulator -avd test-1 -verbose -show-kernel -gpu swiftshader -skip-adb-auth -ranchu -selinux permissive -memory 3072 >emulator.log &

emulator.log looks okay, except it has no kernel messages; 'adb devices' shows no devices :(
https://tools.taskcluster.net/groups/WuC0r7RzSymy_eximaoMbA/tasks/WuC0r7RzSymy_eximaoMbA/runs/0/logs/public%2Flogs%2Flive.log

[task 2018-05-07T01:09:31.841Z] 01:09:31     INFO - Running command: ['kvm-ok']
[task 2018-05-07T01:09:31.841Z] 01:09:31     INFO - Copy/paste: kvm-ok
[task 2018-05-07T01:09:31.844Z] 01:09:31     INFO -  INFO: /dev/kvm exists
[task 2018-05-07T01:09:31.845Z] 01:09:31     INFO -  KVM acceleration can be used
[task 2018-05-07T01:09:31.845Z] 01:09:31     INFO - Return code: 0

This is based on a slightly-modified desktop1604test docker image running in privileged mode, on packet.net: so far, so good.
Very good news here: Tests running in kvm-accelerated emulator on packet.net.

https://tools.taskcluster.net/groups/TdL5szt4QiS5L1ZE7H4FPw/tasks/TdL5szt4QiS5L1ZE7H4FPw/runs/0/logs/public%2Flogs%2Flive.log

[task 2018-05-09T18:01:06.374Z] 18:01:06     INFO - Copy/paste: emulator -accel-check
[task 2018-05-09T18:01:06.381Z] 18:01:06     INFO -  accel:
[task 2018-05-09T18:01:06.381Z] 18:01:06     INFO -  0
[task 2018-05-09T18:01:06.381Z] 18:01:06     INFO -  KVM (version 12) is installed and usable.
[task 2018-05-09T18:01:06.381Z] 18:01:06     INFO -  accel
[task 2018-05-09T18:01:06.381Z] 18:01:06     INFO - Return code: 0

[task 2018-05-09T18:01:39.737Z] 18:01:39     INFO - Running timeout 30 /builds/worker/workspace/build/android-sdk-linux/platform-tools/adb devices
[task 2018-05-09T18:01:39.740Z] 18:01:39     INFO - List of devices attached
[task 2018-05-09T18:01:39.740Z] 18:01:39     INFO - emulator-5554	device

[task 2018-05-09T18:02:06.179Z] 18:02:06     INFO -  0 INFO SimpleTest START
[task 2018-05-09T18:02:06.179Z] 18:02:06     INFO -  1 INFO TEST-START | dom/bindings/test/test_sequence_wrapping.html
[task 2018-05-09T18:02:06.179Z] 18:02:06     INFO -  2 INFO TEST-OK | dom/bindings/test/test_sequence_wrapping.html | took 1108ms
[task 2018-05-09T18:02:06.180Z] 18:02:06     INFO -  3 INFO TEST-START | Shutdown
[task 2018-05-09T18:02:06.180Z] 18:02:06     INFO -  4 INFO Passed:  4
[task 2018-05-09T18:02:06.180Z] 18:02:06     INFO -  5 INFO Failed:  0
[task 2018-05-09T18:02:06.180Z] 18:02:06     INFO -  6 INFO Todo:    0
[task 2018-05-09T18:02:06.180Z] 18:02:06     INFO -  7 INFO Mode:    non-e10s
[task 2018-05-09T18:02:06.180Z] 18:02:06     INFO -  8 INFO Slowest: 1108ms - /tests/dom/bindings/test/test_sequence_wrapping.html
Requirements:

 - install qemu-kvm package in docker image
 - run privileged: docker run --privileged -- otherwise /dev/kvm is not visible
 - ensure test user (worker:worker) has permissions for /dev/kvm -- had to chmod 666 /dev/kvm in run-task (cannot do that in Dockerfile...need a privileged context)
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.