3
3

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.

[Android] Emulator起動時のkernel cmdline parameterを変更する

Last updated at Posted at 2019-09-11

結論

Android SDK付属のemulatorコマンドに対し、
-qemuオプションに続けて-appendオプションを指定することで
Linux kernel cmdline parameterを変更することができる。

$ ~/Android/Sdk/emulator/emulator -avd Nexus_6_API_27 -qemu -append "trace_buf_size=64M trace_event=sched_wakeup,sched_switch,sched_blocked_reason,sched_cpu_hotplug"
$ adb shell cat /proc/cmdline
qemu=1 no_timer_check androidboot.hardware=ranchu androidboot.serialno=EMULATOR29X1X12X0 clocksource=pit no-kvmclock android.qemud=1 console=0 android.checkjni=1 qemu.gles=1 qemu.settings.system.screen_off_timeout=2147483647 qemu.encrypt=1 qemu.opengles.version=131072 cma=314M@0-4G qemu.wifi=1 mac80211_hwsim.channels=2 androidboot.android_dt_dir=/sys/bus/platform/devices/ANDR0001:00/properties/android/ loop.max_part=7 ramoops.mem_address=0xff018000 ramoops.mem_size=0x10000 memmap=0x10000$0xff018000 qemu.dalvik.vm.heapsize=384m trace_buf_size=64M trace_event=sched_wakeup,sched_switch,sched_blocked_reason,sched_cpu_hotplug mac80211_hwsim.mac_prefix=5554

すでに該当のavdが起動状態のスナップショットを保持している場合、
cmdline parameterの変更を反映するためにadb rebootする。

ちなみに、-qemu以降の引数はすべてQEMUに渡される。
そのためemulatorコマンドへの引数は-qemuより前にすべて指定しなければならない。
-qemuを介してQEMUに渡すことができるオプションは-qemu -hで確認可能。

なおAndroid Studio 3.5で確認したところ、
AVD Manager(GUI)からEmulatorを起動する場合はkernel cmdline parameterの指定はできないっぽい。

おまけ

Androidで使われているLinux Kernelではftraceがデフォルト有効になっていることが多い。
実際上記の引数でemulatorを起動したら、以下のように起動直後からのscheduling eventが取れる。

$ adb shell cat /d/tracing/trace
# tracer: nop
#
# entries-in-buffer/entries-written: 12161/12161   #P:2
#
#                              _-----=> irqs-off
#                             / _----=> need-resched
#                            | / _---=> hardirq/softirq
#                            || / _--=> preempt-depth
#                            ||| /     delay
#           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION
#              | |       |   ||||       |         |
          <idle>-0     [000] d..3     0.012470: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=swapper/0 next_pid=2 next_prio=120
        kthreadd-2     [000] d..3     0.012476: sched_switch: prev_comm=kthreadd prev_pid=2 prev_prio=120 prev_state=S ==> next_comm=swapper/0 next_pid=1 next_prio=120
            init-1     [000] dN.3     0.133493: sched_wakeup: comm=kthreadd pid=2 prio=120 success=1 target_cpu=000
            init-1     [000] d..3     0.133497: sched_switch: prev_comm=swapper/0 prev_pid=1 prev_prio=120 prev_state=R+ ==> next_comm=kthreadd next_pid=2 next_prio=120
        kthreadd-2     [000] d..3     0.133511: sched_switch: prev_comm=kthreadd prev_pid=2 prev_prio=120 prev_state=S ==> next_comm=swapper/0 next_pid=1 next_prio=120
            init-1     [000] d..3     0.133512: sched_switch: prev_comm=swapper/0 prev_pid=1 prev_prio=120 prev_state=D|K ==> next_comm=kthreadd next_pid=3 next_prio=120
           <...>-3     [000] d..4     0.133513: sched_blocked_reason: pid=1 iowait=0 caller=kthread_create_on_node+0xd0/0x17c
           <...>-3     [000] dN.4     0.133514: sched_wakeup: comm=swapper/0 pid=1 prio=120 success=1 target_cpu=000
           <...>-3     [000] d..3     0.133514: sched_switch: prev_comm=kthreadd prev_pid=3 prev_prio=120 prev_state=R+ ==> next_comm=swapper/0 next_pid=1 next_prio=120
            init-1     [000] d..3     0.133516: sched_wakeup: comm=ksoftirqd/0 pid=3 prio=120 success=1 target_cpu=000
            init-1     [000] d..3     0.133517: sched_switch: prev_comm=swapper/0 prev_pid=1 prev_prio=120 prev_state=D ==> next_comm=ksoftirqd/0 next_pid=3 next_prio=120
           <...>-3     [000] d..4     0.133518: sched_blocked_reason: pid=1 iowait=0 caller=kthread_park+0x49/0x4f
           <...>-3     [000] dN.4     0.133518: sched_wakeup: comm=swapper/0 pid=1 prio=120 success=1 target_cpu=000
           <...>-3     [000] d..3     0.133518: sched_switch: prev_comm=ksoftirqd/0 prev_pid=3 prev_prio=120 prev_state=R+ ==> next_comm=swapper/0 next_pid=1 next_prio=120
            init-1     [000] d..3     0.133521: sched_switch: prev_comm=swapper/0 prev_pid=1 prev_prio=120 prev_state=D ==> next_comm=ksoftirqd/0 next_pid=3 next_prio=120
           <...>-3     [000] d..3     0.133522: sched_switch: prev_comm=ksoftirqd/0 prev_pid=3 prev_prio=120 prev_state=P ==> next_comm=swapper/0 next_pid=0 next_prio=120

参考

Start the emulator from the command line - Android Developers
Android Emulator source code
Optimizing Boot Times - AOSP

3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?