Agenda Motivation Boot Time Measurement Android Boot Time Analysis Reduction Approach Hibernation Based Technologies We Dont Need Boot-loader Demo Future Work and Conclusions
Motivation
Boot Time Measurement
Traditional Linux Environment
Printk TimesLinux kernel featureBuilt-in since Linux 2.6.11How to enable? Add CONFIG_PRINTK_TIME=y to .config Or choose from menuconfig Kernel hacking ---> [*] Show timing information on printks
initcall_debugKernel ParameterPrint the time spent for each initcallOutput Examplecalling ipc_init+0x0/0x28 @ 1msgmni has been set to 42initcall ipc_init+0x0/0x28 returned 0 after 1872 usecs
BootchartVisualize the booting processUse “bootchartd” to collect CPU and IO utilizationinformation.On Ubuntu: apt-get install bootchart bootchart-viewOriginal “bootchartd” is not suitable for embeddedusage.
OProfileOProfile is a system-wide profiler for Linux systems.Capable of profiling all running code at low overhead.Supports wide number of hardwares.Profiling daemon ported to Android and available inAOSP.
PerfNew profiling tool based on the performance countersubsystem of Linux.Very powerful and easy to use.Included in Linux source code:tools/perf/
PerfRecording:$ perf record -a -f^C[ perf record: Woken up 1 times to write data ][ perf record: Captured and wrote 0.288 MB perf.data (~12567 samples)]Output$ perf report --sort comm,dso,symbol|head -10# Events: 1K cycles## Overhead Command Shared Object Symbol# ........ ........... ...................... ............# 35.47% firefox libxul.so [.] 0xc1b3a7 3.08% firefox libcairo.so.2.11000.2 [.] 0xff88 2.98% Xorg Xorg (deleted) [.] 0xe201c 2.51% firefox firefox [.] 0x2726 1.49% Xorg [kernel.kallsyms] [k] find_vma 0.93% perf_3.0.0 perf_3.0.0 [.] hex2u64
Perf Timechart$ perf timechart record $ perf timechart
Android Environment
BootchartOriginal “bootchartd” is not suitable on embeddeddevices.Android re-implemented in its “init” program.
BootchartTo build:$ cd system/core/init$ touch init.c$ mm INIT_BOOTCHART=true
BootchartTo run:$ adb shell echo 120 > /data/bootchart-startRemember the /data directory must be write ableduring boot.Use grab-bootchart.sh to retrieve the data.
StraceAfter analyzed the bootchart, can use strace toanalyze individual progarm.Available in AOSP since Éclair
LogcatAndroid log utilityCan output timing informationAdjust loglevel to 6 in init.rc Displays time spent for each command
Dalvik Method TracerMethod tracer is built into DalvikUse DDMS or using calls inside source to collect data.// start tracing to "/sdcard/calc.trace"Debug.startMethodTracing("calc");// ...// stop tracingDebug.stopMethodTracing();
StopwatchNot real stopwatchA utility in Android Framework for measuring C++code.Output result to system log#include <utils/StopWatch.h>…{ StopWatch watch("blah"); /* your codes here */}
Q&A
Android Boot Time Analysis
Boot-loader InitUsually constant timeAvoid init hardware multiple timesEnsure to use maximum CPU frequencyUse faster NAND/MMC reading mechanism
Kernel InitMostly usual suspects ip_auto_config USB init Flash driver initializationFullow the standard Kernel optimizing guide: http://elinux.org/Boot_TimeAvoid loading unneeded kernel module at boot time
Zygote Class PreloadingAndroid Framework has thousands of Java classesPreloaded by Zygote and instantiated in its heapTo improve Application startup time and save memoryControlled by resource: preloaded-classes frameworks/base/preloaded-classes
Zygote Class PreloadingCan use the tool in framework to adjust the list:$ adb logcat > logcat.txt$ java -p preload.jar Compile logcat.txt logcat.compiled$ java -p preload.jar PrintCsv logcat.compiledGoogle Android Developer Dianne Hackborn said: The content of the file is a “black art” You can adjust this as much as you like But the result maybe suboptimal
PackageManager Package ScannigEvery APK is scanned at boot timePackage management code is inefficientUses mmaped files means each access will causepage faultParseZipArchive() scans entire APK for only oneAndroidManifest.xml file
System Services StartingLast stage of Android bootStart every base serviceZygote start SystemServer processStart native service (SurfaceFlinger, AudioFlinger) firstStart each service sequentially
Boot-loaderQi Boot-loader Qi U-Boot + XLoader Boot-oader Size ~30K ~270K+20K Only one stage boot-loader Time to Kernel <1s > 5s Small footprint ~30K Usage Product Engineering Code Simple Complicated Currently support − iMX31 − Samsung 24xx − Beagleboard KISS concept − Boot device and load kernel
Kernel Boot TimeFullow the standard Kernel optimizing guide: http://elinux.org/Boot_TimeMinimize kernel sizeUse compression or notEnable embedded optionsAvoid loading unneeded kernel module at boot time
Optimize Android InitParallize init tasks insmod cannot be parallized Use external scripts to init at backgroundStart services on demand
Optimize Class PreloadingTrade-off between preload class and applicationstartup timeSplit class to more packages to reduce dependencySave inited heap for later useShare heaps between zygote and children
Filesystem OptimizationAccording to reasearch by Linaro Kernel WGUse correct NAND configuration will improve theperformanceMMC controllers are often optimized for particularusage / filesystemAdjust the filesystem partition scheme
Toothpaste EffectObserved by Sony Developer Tim Bird“When you squeeze a tube of toothpaste, sometimesit just moves the toothpaste somewhere else in thetube, and nothing actually comes out.”
Q&A
Hibernation Based Technologies
QuickBootDeveloped by Japanesecompany UbiquitousDemand loading ofrequired page from flashRequires deepintegration of hardwareand software
Fast-OnDeveloped by CCUBased on existing technologies thus requires littlemodification to userspaceRelease clean-pages before suspendSwap out dirty-pages before save imageImage size reduced leads to faster resume time.
Android Wakelocks & TuxOnIce
TuxOnIce PatchTuxOnIce (was Software Suspend 2) is a hibernationpatchsetCan save images to different locationsCan use different compresion algorithmPorting to ARM is possible
Android WakelocksAn aggressive approach to save device powerUse wakelocks to prevent device going suspendPort TOI to Android have to deal with wakelocksbecause MMC driver might hold a wakelock
Linux Suspend ArchitectureDocumentation/power/devices.txt: struct dev_pm_ops { int (*prepare)(struct device *dev); void (*complete)(struct device *dev); int (*suspend)(struct device *dev); int (*resume)(struct device *dev); int (*freeze)(struct device *dev); int (*thaw)(struct device *dev); int (*poweroff)(struct device *dev); int (*restore)(struct device *dev); int (*suspend_noirq)(struct device *dev); int (*resume_noirq)(struct device *dev); int (*freeze_noirq)(struct device *dev); int (*thaw_noirq)(struct device *dev); int (*poweroff_noirq)(struct device *dev); int (*restore_noirq)(struct device *dev); int (*runtime_suspend)(struct device *dev); int (*runtime_resume)(struct device *dev); int (*runtime_idle)(struct device *dev); };
Q&A
We Dont Need Boot-loader
R-LoaderNormal suspend-to-disk approach has manyduplicated effort Boot-loader inits some hardwares Boot-loader loads the normal kernel image Kernel inits some hardwares again Kernel loads the suspended kernel image Kernel resumes, inits some hardwares again
R-Loader0xlab Developer Matt Proposed “Resume-Loader”R-Loader inits some hardware then reads thesuspended kernel image as fast as possibleJump directly to the resume pointKernel will takeover the job and inits reset hardwares
DemoGet 0xdroid 0x7 release https://code.google.com/p/0xdroid/wiki/0x7_leb_gingerbreadGet TOI Patch for 0x7 release https://gitorious.org/0xlab-kernel/kernel/commits/toi/linaro-android.38
Future Work and ConclusionsSave the heap image (like core dump) of Zygote afterpreloading classesModify Dalvik to make hibernation image after systeminit and before Launcher startupParallize Android initCache & Share JITed code fragment