android kernel issues

34
Android Kernel Issues

Upload: george-massey

Post on 02-Jan-2016

82 views

Category:

Documents


9 download

DESCRIPTION

Android Kernel Issues. Android Kernel Issues. Date : Mar-13-2008, Thu (13:00 ~ ) Location : Seoul Samsung-Dong COEX(1floor Grand Volume ) Presentator : - CTO - S/W Lab - Lim,GeunSik ([email protected]). CONTENTS. - PowerPoint PPT Presentation

TRANSCRIPT

Page 2: Android Kernel Issues

Android Kernel Issues

2008 Korea Android(www.kandroid.org)

CONTENTS

PART 1. Overview

PART 2. OpenBinder

PART 3. EABI

PART 4. Low Memory Killer

Date : Mar-13-2008, Thu (13:00 ~ )Location : Seoul Samsung-Dong COEX(1floor Grand Volume)Presentator : - CTO - S/W Lab - Lim,GeunSik ([email protected])

본 행사는 구글 안드로이드와 같은 오픈 모바일 플랫폼을 구현하기 위해 필요한 여러 기술과 적용 방안에 대해 알아보는 자리입니다 .실제 경험과 Know-how 를 중심으로 구성된 본 행사는 모바일 비즈니스의 새로운 사업 모델을 창출하는 계기가 될 것입니다 .

Page 3: Android Kernel Issues

Overview1.

PART 1. Overview

PART 2. OpenBinder

PART 3. EABI

PART 4. Low Memory Killer

Page 4: Android Kernel Issues

4/34Software Stack for mobile devices (Android)

2008 Korea Android Part 1 Google & OpenSources ‘s Dinner for Open Mobile Platform

Linux Iland’sDalvik

QemuOpenbinder Core

Ant

BSD Libc

OpenGL

OpenGL

SDL

KHTML

Expat

Python

Sqlite3

D-BUS

SSL

zlib Openbinder System

OpenSource License

Linux Kernel GPL2

YAFFS2 GPL

QEMU GPL

QEMU Accelerator

GPL2

Dalvik (JVM) Google (Apache)

OpenBinder (Core)

GPL2

SQLite GPL2

Python Python

ant Apache

SDL LGPL

OpenGLSGI OpenGL (BSD/MPL)

NetBSD C Library BSD

WebkitBSD (including LGPL)

WebCore LGPL

KJS LGPL

KHTML GPL+BSD

DBUS GPL2

Expat MIT

SGL Google (Skia)

•What is Android’s License? •Currently, Android Platform is open source completely. The Android mobile OS will be released under Apache License. This means that anyone can customize the android platform and then keep it proprietary.

Page 5: Android Kernel Issues

5/34Software Stack for mobile devices (Android)

2008 Korea Android Part 1 Android Kernel Features

O : Needed △ : Option

Kernel Feature Option

ARM EABI ( Embedded ABI ) O

Frame Buffer (Device Driver) /dev/fb0 O

OpenBinder ( For IPC between processes ) /dev/binder (251 ~ 253) O

Touch-Screen Device drivers △

Misc Low Memory Killer ( To Manage process When Memory is low) △

Android

Android Log Driver (Android Log Subsystem to display log messages like logcat) /dev/log/{main:log:event}

Android USB Gadget ( Gadget based Android USB Driver) /dev/usb

Android RAM Buffer Console ( for goldfish's audio ) △

Android Power Driver( for power management of goldfish ) /dev/android_power

Emulator

Goldfish (Virtual Machine for QEMU based Emulator ) △

Panic Timeout ( To manage timout value when panic) △

init ramfs source ( To run /init - Exectuable Liking Format ) △

Page 6: Android Kernel Issues

6/34Software Stack for mobile devices (Android)

2008 Korea Android Part 1What is Cross Compiler to build Kernel?

Select Cross Compiler for ARM v6

Did you have Cross Compilr to Compile Android Kernel?

Sourcery G++ Lite Edition (CodeSourcery's version of the GNU Toolchain) arm-2007q3-53-arm-none-eabi-i686-pc-linux-gnu.tar.bz2 export PATH=$PATH :<cross_compiler_install_path>/bin/Android Kernel: http://android.googlecode.com/files/linux-2.6.23-android-m3-rc20.tar.gz

We need opensource for toolchain like Kernel, gcc, glibc, bintuils http://www.codesourcery.com/gnu_toolchains/arm/download.html Download the ARM 2007q3 Release Select "ARM EABI, IA32 GNU /Linux Option (Radio Box)" and Download - Target Platform: ARM EABI - Host Platform: IA32 GNU/Linux - Source Code: UncheckedDefault Floating Point : Soft-Float If you are want to compile hard-float option to enable VFP Instruciton, Use -mfpu=vfp -mfloat-abit=softfp

How to get CodeSourcery’s Toolchain

Page 7: Android Kernel Issues

7/34Software Stack for mobile devices (Android)

2008 Korea Android Part 1How to build Kernel Source for Android Platform

Get default .config file from rootFS of anroid emulator.

fc6#> tar xzf linux-2.6.18-arm1136jf-s.armadillo-500.android.tar.gz fc6#> cd linux-2.6.18-arm1136jf-s.armadillo-500fc6#> cp ./arch/arm/configs/goldfish_defconfig ./.config (GoldFish Config File)fc6#> make ARCH=arm CROSS_COMPILE=arm_none-linux-gnueabi- menuconfig fc6#> make ARCH=arm CROSS_COMPILE=arm_none-linux-gnueabi- zImagefc6#> make ARCH=arm CROSS_COMPILE=arm_none-linux-gnueabi- modulesfc6#> make ARCH=arm CROSS_COMPILE=arm_none-linux-gnueabi- modules_install

fc6#> cp ./arch/arm/boot/zImage /tftpboot/fc6#> cp –rf /lib/modules/ linux-2.6.18-arm1136jf-s.armadillo-500 /tftpboot/target/lib/modules/

Build 2.6 Kernel Source

fc6#> <android_sdk_install_path>/tools/emulator –console –debug-kernel –kernel kernel-qemu fc6#> adb pull /proc/config.gz ./fc6#> gunzip config.gzfc6#> vi ./.config

Page 8: Android Kernel Issues

OpenBinder2.

PART 1. Overview

PART 2. OpenBinder

PART 3. EABI

PART 4. Low Memory Killer

Page 9: Android Kernel Issues

9/34Software Stack for mobile devices (Android)

2008 Korea Android Part 2What is OpenBinder?

OpenBinder is an open-source system component framework.

•A complete open-source solution supporting new kinds of component-based system-level design.

•Resource management between processes.•Binder is system oriented rather than application oriented.•Support a new kind of component-based system-level development.•Component/object representations of various basic system services.•Binder itself does not impose a particular threading model.The Binder has been used to implement a wide variety of commercial-quality system-level services.

Openbiner’s History

OHAOHA

1998 Binder is developed by BeOS.2001 Palm Company acquired BeOS.2001 Palm’s Micro Kernel is consist of Binder.2004 netBSD Cobalt Kernel http://www.netbsd.org/ports/cobalt/ 2005 Contributed by Palm(OHA Member) , 2005 Google used Openbinder for android. (Not Opensource : graphics , user interface , multimedia ramework)2007 Current BeOS (http://www.beosmax.org)

Page 10: Android Kernel Issues

10/34Software Stack for mobile devices (Android)

2008 Korea Android Part 2 Why OpenBinder?

Hardware Scalability

System Customization

Robust Applications

These platforms were designed to run on small handheld or dedicated devices.

• The mobile device world tends to have a much broader range of hardware capabilities than is found on desktops. size and battery life

• ability to run on anything from a 50MHz ARM 7 CPU (without memory protection) up to a 400MHz ARM 9 CPU and beyond. burden on system software

• Both hardware manufacturers and phone carriers want to deeply customize their behavior.

• it much easier to support this kind of customizability in a manageable way.

• Usage of the screen can become a significant problem for more complicated applications, such as web browsers.

• Binder helps address this issue by making it easy for one application to sandbox other parts of itself.

Page 11: Android Kernel Issues

11/34Software Stack for mobile devices (Android)

2008 Korea Android Part 2 How to Use OpenBinder Driver in Kernel

make menuconfig & Device Node & Binding Example

…………………… Upper Omission…………………….VFS: Mounted root (ext3 filesystem).Freeing init memory: 120Kinit: HOW ARE YOU GENTLEMENinit: reading config fileinit: device initinit: mtd partition -1, init: mtd partition 0, "nor.bootlinit: mtd partition 1, "nor.kerneinit: mtd partition 2, "nor.userlinit: mtd partition 3, "nor.confiinit: mtd partition 4, "nand.ipl"init: mtd partition 5, "nand.kerninit: mtd partition 6, "nand.userinit: mtd partition 7, "nand.freesh: can't access tty; job control turned off# binder_open(c3be4438 c053b500) (pid 1593) got c2c81000binder_open(c3be4438 c35291e0) (pid 1605) got c19b8000binder_open(c3be4438 c06a35a0) (pid 1640) got c0cff000binder_open(c3be4438 c06a3c80) (pid 1642) got c0db9000binder_open(c3be4438 c3519e40) (pid 1601) got c099f000binder_open(c3be4438 c09f4ee0) (pid 1654) got c0a9b000…………………… Below Omission …………………

•OpenBinder 의 자체적인 통신은 Kernel 의 Device Driver 으로 통신할 수 있는 주어진 핸들에서 ioctl 를 사용하여 수행 .

* Character Device is 251 ~ 253* http://www.lanana.org/docs/device-list/

• Android 의 Process(Thread) 생성시마다 binder라는 IPC Mechanism 이 부착됨 .

For IPC

Page 12: Android Kernel Issues

12/34Software Stack for mobile devices (Android)

2008 Korea Android Part 2Map info of Google Map Process

dd

• What is IPC Mechenism of Android platform for Mobile ? Both Openbinder and D-bus.

D-BUSVer0.95

OpenBinder Ver 0.8

•System for sending messages between applications. (Systemwide message-bus service) http://www.freedesktop.org/software/dbus/ For example , Broadcast signal and System/Session Bus

•Don't worry about processes or IPC Because of distributed architecture.•Provides resource management between processes.•Handle on an object in another proces.•Powerful facilities for doing multithreaded programming with the Binder.

http://www.open-binder.org

<ps information on android platform> root 1657 1 100512 24852 ffffffff afe0d204 S /system/bin/runtimebluetooth 1658 1 1224 776 c00a34e8 afe0d07c S /system/bin/dbus-daemon

<./dbus-daemon/bus/>activation.c, bus.c, config-loader-expat.cconfig-parser.c, connection.c, desktop-file.c, dispatch.c, driver.c, expirelist.c, bus/policy.c, services.c, signals.c

Page 13: Android Kernel Issues

13/34Software Stack for mobile devices (Android)

2008 Korea Android Part 2 How to combine Openbinder and Udev in rootFS

Priority of Created Thread in Android Kernel

target#> cd /etc/udev/rules.d/ target#> vi binderdev.rules KERNEL=="binder*", NAME="%k", MODE="0666" target#> vi /etc/autobinder.sh # you almost certainly want to run this with sudo depmod modprobe binderdev echo lsmod | grep binder lsmod | grep binder ls /dev/binder

• Do you want to use Dynamic User-space Device in your rootFS?

How to make udev rule

target#> insmod binderdev.kotarget#> lsmod Module Size Used by Not tainted binderdev 63152 0 - Live 0xbf000000target#> mknod /dev/binder c 253 0target#> /bin/chmod -R a+rw /dev/binder

How to make static /dev/ rule

Page 14: Android Kernel Issues

14/34Software Stack for mobile devices (Android)

2008 Korea Android Part 2 OpenBinder

OpenBinder Ver 0.8 Package

Name Description

build_system Makefiles collection (ex:All binder libraries , PackageNamespace [org.openbinder.tools], PackageLeaf [BinderShell])

commands 3way, bomber , bsh

components Kits, services (MemoryDealer) , tools (BinderShell , commands)

docs Quick Start Manual (doxgen)

headers Header files ( app, dmprovider, pacakage ,pacakge_p , services , storage , support support_p , xml , xml_p )

interfaces Interface Definition Language ( app , package , services, storage, support)

libraries binder lib(arm,generic,x86) , binder_component_glue lib , binder_glue lib , dmprovider lib(Schema)

modules Core Openbinder system (Openbinder Kernel Module)

samples Sample Code ( Binder Component , Binder Based System Service , Service Process , Binder Shell Script)

scripts Script Collection ( boot, process_wrapper , setup_env )

servers Binder Process(loop) , Custom Package Manager , Custom Package Manager

toolsmake_strings [OPTIONS] strings.xml, pidgen [flags] foo.idl Google Web APIs (http://api.google.com/search/beta2 SOAP RPC Router )

http://www.mozilla.org/MPL/

※ OpenBinder 는 OS 설계를 위한 객체 지향적 접근 방식을 시도한 기존과는 다른 새로운 방식의 접근 방식으로 , 전통적인 Kernel 에 의해 구성되는 객체 지향적 운영체제 환경을 제공함 .

※ System 의 가장 큰 힘은 Multi Process 들로 작업이 수행될 때이며 ,Android 에서는 Process 들간의 상호작용 및 Object 참조를 효율적으로 관리하기 위하여 Core OpenBinder 에 의해 사용되는 특별한 IPC Mechanism 을 이용 .

Page 15: Android Kernel Issues

15/34Software Stack for mobile devices (Android)

2008 Korea Android Part 2 OpenBinder Contributors

Main Role of Conrtibutor

Author(Contributor)

E-mail Role

Kenneth Albanowski [email protected] Port of user-space code to Linux.

Trey Boudreau [email protected] Linux Binder module, IMemory, Memory Dealer.

John Dance [email protected] Marshalling and pidgen, BCatalogMirror

Dianne Hackborn [email protected] General design, support classes, SValue, SLocker and SAtom debugging , data model, documentation

Arve H j& oslash [email protected]

Binder kernel module (versions 2 and 4).

George Hoffman [email protected] Initial design and implementation. especially of Ibinder / BBinder, the Binder kernel module , gehnaphores (lightweight locks), SAtom, SHandler

Eric Moon [email protected] SBuffer, SBufferChain, SBitstreamReader

Joe Onorato [email protected] General design, XML parser, BBinder, marshalling and pidgen.

Jason Parks [email protected] Package manager, settings catalog, Binder Shell, data model, port to Linux

Jenny Tsai [email protected] Pidgen.

Page 16: Android Kernel Issues

16/34Software Stack for mobile devices (Android)

2008 Korea Android Part 2Core OpenBinder System

File List in Kernel Space

File Name Line Description

binder.c 692 open, mmap , release , ioctl, unlocked ioctl

binder-defs.h 341 cmpxchg32 , compare_and_swap32

binder_node.c 141 Node Global, Node Init , Node AcquireHome, Node Send , Node Destroy

binder_node.h 71 Binder node’s Structure

binder_proc.c 2,216

Process init , Process Spawn Looper , Process wakeup timer , process idle timer , set_thread_priority , Process Stop , Process Destroy , Process Die , Process AddThread , Process RemoteThread , Process Transact , Process FreeBuffter , Etc

binder_proc.h 227Descriptor Sturcture , Reverse_mapping Structure, Local_mapping Structure, Range_map Structure, Death_notification Structure, binder_proc Structure

binder_thread.c 1,576

Thread Cleanup , Thread WaitForReply , Thread WaitForRequest, Thread Return Transaction, Thread init , Thread GloablCount , Thread Released , Thread Die , Thread AttachProcess, Thread Wakeup , Thread Sync, Thread Write, Thread Read , Etc

binder-thread.h 154 binder_thread Structure

binder_transaction.c 542 Transaction Init , Transaction Dtor , Transacton Debug Dump, Transaction Create, Transaction Destroy, Transaction ReleaseTarget

binder.transaction.h 128 binder_transaction Structure

Iobuffer.c 112 Init, Read Raw, Write Raw, Drain, Remaining, Consumed, Remainder

Iobuffer.h 45 i/o buffer Structure

http://w w w .gnu.org/copy left/gpl.htm l/

Page 17: Android Kernel Issues

17/34Software Stack for mobile devices (Android)

2008 Korea Android Part 2Thread’s Priority binding to the OpenBinder

Priority of the Created Thread in Android Kernel

static void set_thread_priority(pid_t thread, int priority){// Android Kernel’s Scheduling is Dynamic Priority(=Normal Priority ) to schedule between threads. int nice; // The following must match SysThreadChangePriority in libbinder. if( priority >= 80 ) Worse Priority or low priority ( map 80..100 to 0..19) { nice = priority - 80; if(nice > 19) nice = 19; } else Better priority or High Priority ( map 0..79 to -20..-1) { nice = priority-3 - 80; nice /= 4; }//printk(“*invain’s DEBUG: set_thread_priority tid %d pri %d == nice %d\n", thread, priority, nice); set_user_nice(find_task_by_pid(thread), nice);

}

• Do you need Realtime Characterestics for Mobile?

• Why does nobody talked about the characteristics of real-time kernel androids not?

• We can use Preemptible Kernel in Kernel Space for Realtime, But UserSpace Realtime?

We can Implement User-space Realtime Application with Locked Mutex Method (FUTEX)

(Ex: Priority Queuing , Priority Inheritance , Robust Mutex )

App’s LatencyApp’s

Throughput

Page 18: Android Kernel Issues

EABI (Embedded Application Binary Interface)3.

PART 1. Overview

PART 2. OpenBinder

PART 3. EABI

PART 4. Low Memory Killer

Page 19: Android Kernel Issues

19/34Software Stack for mobile devices (Android)

2008 Korea Android Part 3 What is EABI?

EABI(Embedded Application Binary Interface) •It sets the standard for the interoperation between relocated files, as well as executable files, for embedded architectures.•the standard makes it possible to combine object files built using different toolchains if both their compilers use EABI. •GCC : CS-2005Q3 release is a modified version of gcc-3.4.4 from gcc-4.1.0 •The commercial ARM RealView C/C++ compiler was the first to support EABI (GCC4.1)•Kernel: EABI is supported in the ARM Linux kernel from version 2.6.16.•Glibc : Earlier glibcs (2.3.3) support EABI userspace but had old-style syscalls to work with older kernels (2.6.0-2.6.15).

No Features

1 Ability to mix soft and hardfloat code. (EX: GCC 4.2’s Hard Floating --with-fpu=vfp --with-float=softfp)

2 Better structure packing capabilities.

3 More compatibility with various development tools.

4 More efficient syscall convention. ( Ref1)

5 Compatability with ARMv5t processors and above (for GCC 4.2).

- http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ihi0036a/ ARM Information Center

Ref 1) Experience showed that those syscall wrappers can not cover all the needed ABI mismatch since some of them are simply hidden from the C library, especially with specialized applications like iptables for example.

The effective features for arm-linux users with the use of EABI are

Page 20: Android Kernel Issues

20/34Software Stack for mobile devices (Android)

2008 Korea Android Part 3Extending the ARM Processor Portfolio

Android

•Continued licensing of both mature and new technology

•Cortex-A9 Ecosystem EDA, OS and Software companies supporting Cortex-A9

년도

In Mobile Market

Page 21: Android Kernel Issues

21/34Software Stack for mobile devices (Android)

2008 Korea Android Part 3Arch & CPU information of GCC about android

…………………………… Upper Omission ………………………… {"armv4t", arm7tdmi, "4T", FL_CO_PROC | FL_FOR_ARCH4T, NULL}, {"armv5", arm10tdmi, "5", FL_CO_PROC | FL_FOR_ARCH5, NULL}, {"armv5t", arm10tdmi, "5T", FL_CO_PROC | FL_FOR_ARCH5T, NULL}, {"armv5e", arm1026ejs, "5E", FL_CO_PROC | FL_FOR_ARCH5E, NULL}, {"armv5te", arm1026ejs, "5TE", FL_CO_PROC | FL_FOR_ARCH5TE, NULL}, {"armv6", arm1136js, "6", FL_CO_PROC | FL_FOR_ARCH6, NULL}, {"armv6j", arm1136js, "6J", FL_CO_PROC | FL_FOR_ARCH6J, NULL}, {"armv6k", mpcore, "6K", FL_CO_PROC | FL_FOR_ARCH6K, NULL}, {"armv6z", arm1176jzs, "6Z", FL_CO_PROC | FL_FOR_ARCH6Z, NULL}, {"armv6zk", arm1176jzs, "6ZK", FL_CO_PROC | FL_FOR_ARCH6ZK, NULL}, {"armv6t2", arm1156t2s, "6T2", FL_CO_PROC | FL_FOR_ARCH6T2, NULL}, {"armv7", cortexa8, "7", FL_CO_PROC | FL_FOR_ARCH7, NULL}, {"armv7-a", cortexa8, "7A", FL_CO_PROC | FL_FOR_ARCH7A, NULL}, {"armv7-r", cortexr4, "7R", FL_CO_PROC | FL_FOR_ARCH7R, NULL}, {"armv7-m", cortexm3, "7M", FL_CO_PROC | FL_FOR_ARCH7M, NULL}, {"ep9312", ep9312, "4T", FL_LDSCHED | FL_CIRRUS | FL_FOR_ARCH4, NULL}, {"iwmmxt", iwmmxt, "5TE", FL_LDSCHED | FL_STRONG | FL_FOR_ARCH5TE | FL_XSCALE | FL_IWMMXT , NULL}, {NULL, arm_none, NULL, 0 , NULL}};

…………………………… Upper Omission ………………………… {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL}, {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL}, {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},

•http://gcc.gnu.org/svn/gcc/branches/gcc-4_3-branch/gcc/config/arm/arm.c

•http://sourceware.org/cgi-bin/cvsweb.cgi/src/gas/config/tc-arm.c?cvsroot=src

Page 22: Android Kernel Issues

22/34Software Stack for mobile devices (Android)

2008 Korea Android

The common gcc command options that are available for EABI are

Part 3Cross Compiler for EABI

ARM syscall entry convention

EABI user space binaries put the syscall number into r7 and use swi 0 to call the kernel. Syscall register arguments are also expected to have EABI arrangements , that is, 64-bit arguments should be put in a pair of registers from an even register number.Example ARM sycall entry convention with long ftruncate64 (unsigned int fd, loff_t length.

GCC Option Description

-mabi=eabi Generate code for the given ABI.

-mcall-sysv-eabi Specify both -mcall-sysv and -meabi options.

-mcall-sysv-noeabi Specify both -mcall-sysv and -mno-eabi options.

-mlibrary-pic Generate position-independent EABI code.

-mlinked-fpFollow the EABI requirement of always creating a frame pointer whenever a stack frame is allocated. This option is enabled by default and can be disabled with -mno-linked-fp.

Page 23: Android Kernel Issues

23/34Software Stack for mobile devices (Android)

2008 Korea Android

• put fd into r0 • put length into r1-r2 • use “swi #(0x900000 + 194)” to call the kernel

Legacy ABI

EABI

Compatibility

Part 3Legacy ABI vs. EABI

Exectuable Binary

EABI

• put fd into r0 • put length into r2-r3 (skipping over r1) • put 194 into r7 • use “swi 0" to call the kernel

It is important to use 0 for the swi argument because backward compatibility with legacy ABI userspace relies on this. The syscall macros in asm-arm/unistd.h were also updated to support both ABIs and implement the right call method automatically.

13 #ifndef __ASM_ARM_UNISTD_H14 #define __ASM_ARM_UNISTD_H15 #define __NR_OABI_SYSCALL_BASE 0x90000016 #if defined(__thumb__) || defined(__ARM_EABI__)17 #define __NR_SYSCALL_BASE 018 #else19 #define __NR_SYSCALL_BASE __NR_OABI_SYSCALL_BA

SE20 #endif

./include/asm-arm/unistd.h

fc6#> arm_v5t_le-objdump -xlD vmlinux | lessprivate flags = 602: [APCS-32] [VFP float format] \[software FP] [has entry point]

fc6#> arm_v5t_le-objdump -xlD vmlinux | grep less or arm_v5t_le-objdump -xlD /tftpboot/target/init | less private flags = 4000002: [Version4 EABI] [has entry point]

Page 24: Android Kernel Issues

24/34Software Stack for mobile devices (Android)

2008 Korea Android Part 3If EABI is not supported in your kernel?

For example, Your kernel is 2.6.15- . So You need EABI Feature.

1 use_mtune_arm1136j-s_for_ARMv6_targets 17 arm-eabi-kconfig

2 arm-remove-udivdi3-from-pxafb 18 arm-update-syscall-table

3 mmc-remove-ref-to-divdi3 19 arm-inotify-ioprio.syscalls

4 arm-remove-udivdi3-from-nwfpe 20 arm-mempolicy-syscalls

5 arm-remove-udivdi3-from-kernel 21 arm-oabi-statfs64

6 arm-optimized-libc-functions 22 arm-oabi-syscall-wrappers

7 slab-add-more-arch-override 23 arm-oabi-multi-abi

8 arm-fix-sys_sendto-and-sys_recvfrom-6-arg 24 arm-oabi-nwfpe

9 arm_mno-thumb-interwork 25 arm-oabi-kconfig

10 arm-eabi-relocs-for-modules 26 arm-eabi-sigreturn-fix

11 arm-eabi-slab-align-to-64bits 27 arm-nptl-compat-mb

12 arm-eabi-sp-align-1 28 arm-oabi-is-experimental

13 arm-eabi-sp-align-2 29 arm-oabi-struct-sockaddr_un

14 arm-eabi-helper-func-names 30 arm_mempolicy_syscalls_compat_hack

15 arm-eabi-syscalls 31 arm_eabi_syscalls_compat_hack

16 arm-eabi-syscall-adjstments  

•On any ARM toolchain (v5t_le, xscale_le), in the Processor Features area, the following new freatures need to be set EABI.

Page 25: Android Kernel Issues

25/34Software Stack for mobile devices (Android)

2008 Korea Android Part 3Legacy ABI vs. EABI

Toolchain&

Binary

• ABI flags passed to binutils: -mabi=apcs-gnu -mfpu=fpa• gcc -dumpmachine: arm-unknown-linux• objdump -x for compiled binary: fc6.abi#>objdump -xlD vmlinux | lessprivate flags = 602: [APCS-32] [VFP float format] [software FP] [has entry point]• "file" on compiled binary (Under Fedora Core 6) ELF 32-bit LSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.20, dynamically linked (uses shared libs), for GNU/Linux 2.4.20, stripped

Toolchain&

Binary

• ABI flags passed by gcc to binutils:• -mabi=aapcs-linux -mfloat-abi=soft -meabi=4• gcc -dumpmachine: arm-unknown-linux-gnueabi• objdump -x for compiled binary: fc6.eabi#> objdump -xlD vmlinux | less private flags = 4000002: [Version4 EABI] [has entry point]• "file" on compiled binary (Under Fedora Core 6) ELF 32-bit LSB executable, ARM, version 1 (SYSV), for GNU/Linux 2.6.18, dymically linked(uses shared libs), for GNU/Linux 2.6.18, stripped

Legacy ABI

New EABI

Page 26: Android Kernel Issues

26/34Software Stack for mobile devices (Android)

2008 Korea Android Part 3Cross Compiler for EABI

Is it possible to run both EABI and non-EABI binaries on the same system?

EABI 관련하여설명하고있는사이트 .

Yes, it is possible. However, running a dual-ABI system requires care. If you have an old-ABI system, and want to run EABI binaries, you have several choices. One option is to link your programs statically, using the -static option. However, linking dynamically is generally a superior approach. Generally, toolchains use a different dynamic loader (ld.so.3), so it is possible for old-ABI and EABI binaries to coexist. However, you will have to ensure that when you install the EABI libraries you do not overwrite existing libraries, and you will have to set LD_LIBRARY_PATH so that the dynamic loader can find them.

※ Support EABI Feature “make menuconfig” – “Kernel Features” – “[*]Use the ARM EABI to compile the kernel”

Page 27: Android Kernel Issues

Low Memory Killer4.

PART 1. Overview

PART 2. OpenBinder

PART 3. EABI

PART 4. Low Memory Killer

Page 28: Android Kernel Issues

28/34Software Stack for mobile devices (Android)

2008 Korea Android Part 4What is Low Memory Killer?

Why Google develop Low Memory Killer without OOM?

TargetBoard 에서 사용가능한 Memory 공간이 고갈 상태에 이르렀을 때 , OOM(Out Of Memory) 을 발생시키는 방법을 사용하지 않고 , Process 들의 중요도에 따라 Group 으로 나눈 후에 중요도가 낮은 Group 에 있는 Process 부터 하나씩 하나씩 Kill 하여 Android 의 전체적인 System 의 운영을 유지시켜주는 Memory 를 확보하는 방법이다 .

………………………… 윗부분 생략 ……………………………… .

printk: 8 messages suppressed.oom-killer: gfp_mask=0x201d2, order=0Mem-info:DMA per-cpu:cpu 0 hot: high 18, batch 3 used:12cpu 0 cold: high 6, batch 1 used:2DMA32 per-cpu: emptyNormal per-cpu: emptyHighMem per-cpu: emptyFree pages: 1436kB (0kB HighMem)Active:6717 inactive:1641 dirty:0 writeback:0 unstable:0 free:359 slab:1458 mapped:61 pagetables:1700DMA free:1436kB min:1024kB low:1280kB high:1536kB active:26868kB inactive:6564kB present:65536kB pages_scanned:14954 all_unreclaimable? no

lowmem_reserve[]: 0 0 0 0DMA32 free:0kB min:0kB low:0kB high:0kB active:0kB inactive:0kB present:0kB pages_scanned:0 all_unreclaimable? nolowmem_reserve[]: 0 0 0 0Normal free:0kB min:0kB low:0kB high:0kB active:0kB inactive:0kB present:0kB pages_scanned:0 all_unreclaimable? nolowmem_reserve[]: 0 0 0 0HighMem free:0kB min:128kB low:128kB high:128kB active:0kB inactive:0kB present:0kB pages_scanned:0 all_unreclaimabl

e? nolowmem_reserve[]: 0 0 0 0DMA: 51*4kB 26*8kB 4*16kB 0*32kB 1*64kB 1*128kB 1*256kB 1*512kB 0*1024kB 0*2048kB 0*4096kB = 1436kBDMA32: emptyNormal: emptyHighMem: emptySwap cache: add 0, delete 0, find 0/0, race 0+0Free swap = 0kBTotal swap = 0kBOut of Memory: Kill process 908 (udevd) score 122 and children.Out of memory: Killed process 1922 (udev).Free swap: 0kB16384 pages of RAM2623 free pages924 reserved pages1458 slab pages279 pages shared0 pages swap cached………………………… 아랫 부분 생략 ……………………………… .

•“ lowmem_reserver” Region ./kernel-2.6/mm/page_alloc.c File 의 show_free_areas( ) Func 안의 for_each_zone() Func 에서 수행 .

EX) 메모리가 고갈 상태에 이르렀을 때 , Low Memory Killer 가 작동되면서 udev 프로세스를 Kill.

Page 29: Android Kernel Issues

29/34Software Stack for mobile devices (Android)

2008 Korea Android Part 4OOM (Out of Memory ) Killer

oom-killer: gfp_mask=0x201d2, order=0 [<c0144b11>] out_of_memory+0x25/0x144 [<c0145fa7>] __alloc_pages+0x1f5/0x275 [<c0147117>] __do_page_cache_readahead+0xc8/0x1e8 [<c01162e5>] __wake_up_common+0x2f/0x53 [<c0116755>] __wake_up+0x2a/0x3d [<c014420e>] filemap_nopage+0x151/0x30b [<c014c731>] __handle_mm_fault+0x24e/0x705 [<c01248a3>] do_gettimeofday+0x31/0xce [<c011554e>] do_page_fault+0x18a/0x46c [<c01153c4>] do_page_fault+0x0/0x46c [<c01037d5>] error_code+0x39/0x40Mem-info:DMA per-cpu:cpu 0 hot: high 0, batch 1 used:0

………… Middle Omission ……………Free pages: 21472kB (340kB HighMem) ………… Below Omission ……………

OOM Example

※ Kernel Messages Analysis: This is caused by DMA problem. Physical HDD’s Problem? In fact , This Memory Allocation Policy Related Problem.

Case1) Program is allocating memory continually.while (1) { if (malloc(1<<50) == NULL) { printf("malloc failure after %d MiB\n", n); return 0; } printf ("Got %d Mb\n", ++n);}Case2) Program allocate memory, and use memory immediately. while (1) { if ((Temp = malloc(1<<50)) == NULL) { printf("malloc failure after %d MiB\n", n); return 0;} memset (p, 0, (1<<50)); printf ("Got %d Mb\n", ++n);}Case3) Allocate needed memory using for(), Use allocated memory using for().for (n = 0; num < 50,000 ; n++) { temp[num] = malloc(1<<50); if (temp[num] == NULL) break;}printf("malloc failure after %d MiB\n", n);for (i = 0; i < num; i++) { memset ( pp[i], 0, (1<<50) ); printf("Got %d Mb\n", i+1);}

Kenrel Messages When OOM

If fail mem allocation, program exit.

If fail mem allocation, program exit.

※ Case 3 에서 OOM killer 는 init 를 제외한 현재 실행중인 모든

Process 들을 검사 Memory Usage 에 따라 Score 부여 이때

superuser Process 나 Hardware 를 Access 중인 Process 는

점수가 1/4 로 삭감됨 Score 가 가장 많은 Process 를 Kill 함 .

Guide for Embedded Memory Programming

• What Every Programmer Should Know About Memory

• Understanding The Linux Virtual Memory manager

• Understanding Virtual Memory in Red Hat Enterprise Linux 4

Page 30: Android Kernel Issues

30/34Software Stack for mobile devices (Android)

2008 Korea Android Part 4 Android Application ‘s Life Cycle

1/2How do we make Application’s life cycle in Mobile/Embedded? Android 의 중요하면서 보편적이지 않은 하나의 특징은 Application 프로세스의 생명주기가 해당 애플리케이션에 의해 직접적으로 제어되지 않는 다는 것이다 . 대신 , Application 이 사용자를 위해서 얼마나 중요한가 ? 그리고 시스템 전체적으로 얼마나 많은 Memory 가 유용한가라는 Application 실행과 관련된 시스템의 인식기반과 관련된 Application 의 조합된 영역들에 의해 결정 남 .

계층구조(Free Mem)

Description

Foreground

(6M)

foreground 프로세스는 사용자와 상호작용을 하고 있는 스크린의 최상위에 있는 Activity 나 현재 수행되고 있는 IntentReceiver 를 점유하고 있는 Process 이다 . 시스템에는 매우 작은 수의 그러한 프로세스들이 존재할 뿐이며 , 이런 프로세스가 계속 실행 되기조차 어려운 최후의 메모리 부족 상태에서만 종료된다 . 일반적으로 디바이스가 메모리 페이징 상태에 도달하는 시점에 , 사용자 인터페이스에 대한 응답을 처리하기 위해서 그러한 행위가 요구된다 .

Visible

(8M)

visible 프로세스는 사용자의 화면상에는 나타나지만 foreground 상태는 아닌 Activity 를 점유하는 Process 이다 . 예를 들어 foreground activity 다이얼로그 형태로 그 뒤에 이전에 보여졌던 activity 를 허용하면서 표시될때 이러한 것은 발생하게 된다 . 그러한 프로세스는 극도록 중요하게 고려되며 더이상 그것을 수행하지 않을 때까지 종료되지 않으며 , 모든 foreground 프로세스들을 실행 상태로 유지하는 것이 요구된다 .

Serivce

(16M)

service 프로세스는 startService() 메쏘드를 가지고 시작된 Service 를 점유하고 있는 Process 이다 . 이러한 프로세스는 사용자에게 직접적으로 보여지는 않지만 , 이것은 일반적으로 사용자와 관련된 어떤 일을 일반적으로 수행하며 , 시스템이 모든 foreground 와 visibile 프로세스를 보유하기에 충분한 메모리가 존재하는 한 , 시스템은 그러한 프로세스들은 항상 실행상태로 유지할 것이다 .

Background

(64M)

background 프로세스는 사용자에게는 현재 보여지지 않는 Activity 를 점유하는 Process 이다 . 이러한 프로세스는 사용자에게 어떤 것도 직접적으로 영향을 미치지 않는다 . activity 생명주기를 정확하게 구현하기 위해서 마련된 것이며 , 시스템은 위의 3 가지 프로세스 타입 중 한 가지를 위한 메모리 반환 요청이 있을 시에만 그러한 프로세스를 종료시킬 것이다 . 일반적으로 많은 수의 이런 프로세스가 실행되고 있으며 , 해당 프로세스들은 메모리 결핍 시 사용자에게 가장 최근에 보여진 것이 가장 마지막에 종료되는 절차를 확립하기 위해 LRU 리스트 상에서 유지된다 .

Empty

(Unlimited)

empty 프로세스는 어떤 활성화 된 애플리케이션 컴포넌트도 점유하지 않는 Process 이다 . 이러한 프로세스를 유지하고 있는 유일한 이유는 다음 번에 해당 애플리케이션을 실행할 필요가 있을 때 시동 (startup) 시간을 개선하기 위한 Cache 로써 사용하기 위함이다 . 그런 이유로 , 시스템은 이러한 Cache 화된 empty 프로세스들과 기반에 있는 커널 Cache 들 사이에서 전반적인 시스템 균형을 유지하기 위해 이러한 프로세스들을 가끔 종료하게 된다 .

http://code.google.com/android/intro/lifecycle.html

Highest

Lowest

Importance

Page 31: Android Kernel Issues

31/34Software Stack for mobile devices (Android)

2008 Korea Android Part 4 Android Application ‘s Life Cycle

2/2Why Application’s life cycle is important in android platform?

Application 개발자가 Application Process 의 생명주기에 얼마나 다른 Application Component ( 특별히 , Activity, Service, IntentReceiver) 가 영향을 미치는가를 이해하는 것은 중요하다 . 이러한 Component 들을 정확하게 사용하지 않는다면 , 시스템이 해당 Application 이 중요한 작업을 수행 하는 동안 해당 Process 를 종료시키는 결과를 야기할 수 있다 . Process 생명주기와 관련된 Bug 중 일반적인 사례가 IntentReceiver 가 onReceveIntent() Method내에서 Intent 를 받을 때 Thread 를 시작한 다음 해당 함수를 리턴하는 경우이다 . 그러한 리턴이 발생 하면 , System 은 IntentReceiver 가 더이상 Active 되어 있지 않다고 간주하고 , 따라서 그 Hosting Process 가 더이상 필요하지 않다고 간주한다 . (단지 , 다른 Application Component 가 그 안에서 Active 되지 않는 한 ) 따라서 , System 은 메모리 반환요청이 있는 어떤 시점에선 해당 Process 를 종료시킬 수 있다 . 이 문제를 해결하기 위한 해법은 System 이 해당 Process 내에서 행해지고 있는 Active화된 작업이 여전히 존재한다는 것을 알도록 IntentReceiver 로부터 Service 를 시작시키는 것이다 .

Maps Service

Android 는 Memory 가 부족할 때 , 어떤 Process 들이 종료되어야 하는가를 결정하기 위해서 , Android 는 Process 를 그것 안에서 실행되는 Component 와 그러한 Component 의 상태에 기반을 둔 "importance hierarchy " 에 추가함 .

Page 32: Android Kernel Issues

32/34Software Stack for mobile devices (Android)

2008 Korea Android

.

Part 4Kernel Module for Low Memory Killer

Location of Low memory killer

•./kernel-2.6/misw/

lowmemorykiller/

File Name Description

Makefile Make file to build Lowmemorykiller.ko kernel module

lowmemorykiller

shrinker lowmem_shrinker Structure

lowmem_shrink()lowmem_print()module_param_named()module_param_array_named()module_param_array_named()module_param_named()lowmem_init()lowmem_exit()

•Process 에 대한 분류방법을 결정할 때 , System 은 Process내에서 현재 활성화 된 모든 Component 중에서 가장 중요한 레벨을 얻어냄 .

•Process 의 모든 생명주기에 이러한 Activity, Service, IntentReceiver 같은 Component 의 각각이 얼마나 영향을 미치는 지에 대해서는 각각에 대한 보다 자세한 문서를 http://code.google.com 을 통해서 열람 .

Page 33: Android Kernel Issues

33/34Software Stack for mobile devices (Android)

2008 Korea Android

.

Part 4About Android’s low memory shrink task

• lowmem_shrink()

if(nr_to_scan > 0)

lowmem_print(3, "lowmem_shrink %d, %x, ofree %d, ma %d\n", nr_to_scan, gfp_mask, other_free, min_adj);read_lock(&tasklist_lock);

for_each_process(p) {if(p->oomkilladj >= 0 && p->mm) {

tasksize = get_mm_rss(p->mm);if(nr_to_scan > 0 && tasksize > 0 && p->oomkilladj >= min_adj) { if(selected == NULL ||

p->oomkilladj > selected->oomkilladj || (p->oomkilladj == selected->oomkilladj && tasksize > selected_tasksize)) { selected = p; selected_tasksize = tasksize;

lowmem_print(2, "select %d (%s), adj %d, size %d , to kill\n", p->pid, p->comm, p->oomkilladj, tasksize);

}}rem += tasksize;

}}if(selected != NULL) {

lowmem_print(1, "send sigkill to %d (%s), adj %d, size %d\n", selected->pid, selected->comm, selected->oomkilladj, selected_tasksize);

force_sig(SIGKILL, selected);rem -= selected_tasksize;

}

lowmem_print(4, "lowmem_shrink %d, %x, return %d\n", nr_to_scan, gfp_mask, rem);read_unlock(&tasklist_lock);return rem;

※ static size_t lowmem_minfree[6]={ 3*512, // 6MB = 3 x 5123 x 4 2*1024, // 8MB = 2 x 1024 x 4 4*1024, // 16MB= 4 x 1024 x 4 16*1024, // 64MB = 16x1024 x 4 };※ Default lowmem_debug_level is 2. If you want to debug , use 3+ value.

※Linux Cross Reference WebTool http://lxr.linux.no/linux

Page 34: Android Kernel Issues

34/34Software Stack for mobile devices (Android)

2008 Korea Android

Open Mind , Share Mind , This is Our Future!