Android internals 04 - “Androdized” kernel, Bionic, Logging subsystem (rev_1.1)

3,922 views

Published on

Course: Android Internals
Lecture 4: “Androdized” kernel, Bionic, Logging subsystem

Published in: Education, Technology
0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,922
On SlideShare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
Downloads
392
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide

Android internals 04 - “Androdized” kernel, Bionic, Logging subsystem (rev_1.1)

  1. 1. Android internals Egor Elizarov SPbSU 2012
  2. 2. Legal info Android internals by Egor Elizarov is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License You are free to – copy, distribute, display, and perform the work – make derivative works Under the following conditions – Attribution. You must give the original author credit – Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one All pictures and trademarks are the property of their respective owners. Use of these trademarks and pictures is subject to owners permissions. Corrections, suggestions, contributions and translations are welcome! 2 Egor Elizarov SPbSU 2012
  3. 3. Lecture 4 “Androidized” kernel, Bionic C library, Logging system yegor.yelizarov(at)gmail.comRev: 1.1Last update: 05/30/2012 http://vk.com/android_internals 3 Egor Elizarov SPbSU 2012
  4. 4. Previous time Makefile structure Android.mk structure Build system stages Steps to add new module Emulator; Qemu; KVM; ADB Target file system structure 4 Egor Elizarov SPbSU 2012
  5. 5. Kernel types Monolithic kernels Microkernels Hybrid kernels Nanokernels Exokernels 5 Egor Elizarov SPbSU 2012
  6. 6. Linux kernel First release 5 October 1991 Vanilla – repository of Linus Torvalds Monolithic kernel with loadable modules support Languages: C, ASM 6 Egor Elizarov SPbSU 2012
  7. 7. Linux drivers Code in drivers/ directory Can be build-in or modules (*.ko) Devices usually have corresponding element in /dev directory Network devices doesnt have /dev/* elements 7 Egor Elizarov SPbSU 2012
  8. 8. “Androidized” kernel Based on Vanilla Not in mainline until 3.x kernels Usually board specific Have android features 8 Egor Elizarov SPbSU 2012
  9. 9. System calls 9 Egor Elizarov SPbSU 2012
  10. 10. SysFS & DevFS 10 Egor Elizarov SPbSU 2012
  11. 11. Android / kernel interaction System calls (Ex: Bionic routines) SysFS (Ex: Power management) DevFS (Ex: Volume deamon) ProcFS (Ex: Debug system) Netlink (Ex: Event hub) 11 Egor Elizarov SPbSU 2012
  12. 12. Wakelocks Early suspend (Go to suspend as often as possible) /sys/power/wake_lock, /sys/power/wake_unlock Could not suspend if wakelock occupied Wake locks have labels (Ex: PowerManagerService) 12 Egor Elizarov SPbSU 2012
  13. 13. Low memory killer Behind Linux Out Of Memory logic Allow to set different OOM thresholds for different kinds of processes Set up user-space policies during init Policies are adjusted in runtime by Activity Manager kernel/drivers/staging/android/lowmemorykiller.c 13 Egor Elizarov SPbSU 2012
  14. 14. Binder RPC/IPC akin to COM Derived from OpenBinder project Transmit “parcels” between processes /dev/binder & /proc/binder Code: kernel/drivers/staging/android/binder.c 14 Egor Elizarov SPbSU 2012
  15. 15. Anonymous SHared MEMory Derived from POSIX SHM part of SysV IPC Named memory block that is shared between processes Have reference counting to destroy memory regions Shrink memory regions if system has lack of memory 15 Egor Elizarov SPbSU 2012
  16. 16. Alarm Based on Linux High-Resolution Timer & Real- Time Clock Allow set system time and adjust alarms Use RTC to exit suspend and HRT to get precise alarm /dev/alarm & /dev/rtc/ & /sys/class/rtc 16 Egor Elizarov SPbSU 2012
  17. 17. Logger Light weight logger Use three ring buffer queues inside kernel No file writes or context switching operations /dev/log/* Code: kernel/drivers/staging/android/logger.c 17 Egor Elizarov SPbSU 2012
  18. 18. More android features Paranoid networking Ram console Physical memory (pmem) Timed output / timed gpio etc. 18 Egor Elizarov SPbSU 2012
  19. 19. Getting & building kernel git clone https://android.googlesource.com/kernel/goldfish.git cd goldfish git checkout -b android-goldfish-2.6.29 origin/android-goldfish- 2.6.29 make goldfish_defconfig make menuconfig make ARCH=arm CROSS_COMPILE=$ANDROID_ROOT/prebuilt/linux- x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi- uImage -j4 19 Egor Elizarov SPbSU 2012
  20. 20. Bionic Small LibC implementation Partially POSIX compatible BSD license Support for x86, ARM, ARM thumb 20 Egor Elizarov SPbSU 2012
  21. 21. Bionic features Not compatible with GNU libc Fast pthread implementation (based on futexes) Access to property values User/group management 21 Egor Elizarov SPbSU 2012
  22. 22. Not in Bionic Wide chars C++ exceptions (limited implementation since NDKr5) C++ STL Full pthread 22 Egor Elizarov SPbSU 2012
  23. 23. Adding syscall ./bionic/libc/README.TXT Find syscall number in kernel (unistd.h) Add line to ./bionic/libc/SYSCALLS.TXT Run bionic/libc/tools/gensyscalls.py Add wrapper to bionic if needed 23 Egor Elizarov SPbSU 2012
  24. 24. Logging system 24 Egor Elizarov SPbSU 2012
  25. 25. Logging in code Kernel: printk() Java: Log.*, SLog.*, EventLog.* 25 Egor Elizarov SPbSU 2012
  26. 26. Logging in code (2) Native code: LOG* (LOGE) Define for native code: LOG_TAG, LOG_NDEBUG 26 Egor Elizarov SPbSU 2012
  27. 27. Obtaining logs dmesg logcat adb logcat 27 Egor Elizarov SPbSU 2012
  28. 28. Next time Dalvik VM Android application live cycle Source: http://android-developers.blogspot.com/ 28 Egor Elizarov SPbSU 2012
  29. 29. Useful links http://vk.com/android_internals K. Yaghmour. Embedded Android. Early Release, OReilly, October 2011 http://wiki.osdev.org/Kernels http://www.kernel.org/ http://cs736-android.pbworks.com/w/page/5834465/ASHMEM http://elinux.org/Android_Kernel_Features R. Love. Linux kernel development. 3rd edition, Addison-Westley, June 2010 http://source.android.com/source/building-kernels.html $ANDROID_ROOT/bionic/libc/README http://codingrelic.geekhold.com/2008/11/six-million-dollar-libc.html 29 Egor Elizarov SPbSU 2012
  30. 30. Thanks to Sergey Matyukevich for review and advices (www.linkedin.com/pub/sergey-matyukevich/31/889/769) Nikolay F. Fominykh for review and advices Nikita Shulga for advices and notes (http://www.linkedin.com/pub/nikita-shulga/8/582/287) Grigory Tolstolytkin for advices and notes (http://www.linkedin.com/pub/grigory- tolstolytkin/2a/b41/74) 30 Egor Elizarov SPbSU 2012

×