Android Boot Time Optimization
Upcoming SlideShare
Loading in...5

Android Boot Time Optimization






Total Views
Views on SlideShare
Embed Views



1 Embed 14 14



Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Android Boot Time Optimization Android Boot Time Optimization Presentation Transcript

  • Connect your device to application
  • Android Boot TimeOptimizationKan-Ru Chen Sep 09, 2011
  • 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
  • Printk TimesOutput Examplelinux$ dmesg[0.000000] per task-struct memory footprint: 1152 bytes[0.003692] Calibrating delay loop... 506.27 BogoMIPS (lpj=1978368)[0.079833] pid_max: default: 32768 minimum: 301[0.080230] Security Framework initialized[0.080474] Mount-cache hash table entries: 512[0.083892] CPU: Testing write buffer coherency: okAnalysis Toollinux$ dmesg > timefilelinux$ scripts/show_delta timefile...[0.194488 < 0.194488 >] OMAP DMA hardware revision 5.0[0.259948 < 0.065460 >] bio: create slab <bio-0> at 0[0.267822 < 0.007874 >] SCSI subsystem initialized...
  • 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.
  • Bootchart$ bootchart bootchart.tgz -f png
  • StraceTrace system calls during process execution andoutput timing information.$ strace -tt ls15:11:04.243357 execve("/bin/ls", ["ls"], [/* 51 vars */]) = 015:11:04.244252 brk(0) = 0x234f00015:11:04.244458 access("/etc/", F_OK) = -1 ENOENT15:11:04.244676 mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f144479400015:11:04.244852 access("/etc/", R_OK) = -1 ENOENT15:11:04.245096 open("/etc/", O_RDONLY) = 3
  • 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.
  • OProfileOutput Example$ opreport --exclude-dependentCPU: PIII, speed 863.195 MHz (estimated)Counted CPU_CLK_UNHALTED events (clocks processor is not halted)...450385 75.6634 cc1plus 60213 10.1156 lyx 29313 4.9245 XFree86 11633 1.9543 as 10204 1.7142 oprofiled 7289 1.2245 vmlinux 7066 1.1871 bash 6417 1.0780 oprofile 6397 1.0747 vim...
  • 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 (~12567 samples)]Output$ perf report --sort comm,dso,symbol|head -10# Events: 1K cycles## Overhead Command Shared Object Symbol# ........ ........... ...................... ............# 35.47% firefox [.] 0xc1b3a7 3.08% firefox [.] 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 to retrieve the data.
  • StraceAfter analyzed the bootchart, can use strace toanalyze individual progarm.Available in AOSP since Éclair
  • StraceModify init.rc fromservice zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-serverTo service zygote /system/xbin/strace -tt -o/data/boot.strace /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server
  • 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: 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
  • Q&A
  • Reduction Approach
  • Boot-loaderImprove U-Boot Reading multi-mmc-block Cache (I/D) enablement Optimize CRC32 Disable verification
  • 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: 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 TOI Patch for 0x7 release
  • 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
  • Q&A