Android Kernel Extensions

Slides:



Advertisements
Similar presentations
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Advertisements

Paging: Design Issues. Readings r Silbershatz et al: ,
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit
Chapter 6 Limited Direct Execution
ECE 526 – Network Processing Systems Design Software-based Protocol Processing Chapter 7: D. E. Comer.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
Process Description and Control A process is sometimes called a task, it is a program in execution.
Case study 2 Android – Mobile OS.
Operating Systems CSE 411 CPU Management Sept Lecture 11 Instructor: Bhuvan Urgaonkar.
Process Description and Control Chapter 3. Major Requirements of an OS Interleave the execution of several processes to maximize processor utilization.
Chapter 3 Operating Systems Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Chapter 41 Processes Chapter 4. 2 Processes  Multiprogramming operating systems are built around the concept of process (also called task).  A process.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
CE Operating Systems Lecture 11 Windows – Object manager and process management.
Unit - VI. Linux and Real Time: Real Time Tasks Hard and Soft Real Time Tasks Linux Scheduling Latency Kernel Preemption Challenges in Kernel Preemption.
REVIEW OF COMMONLY USED DATA STRUCTURES IN OS. NEEDS FOR EFFICIENT DATA STRUCTURE Storage complexity & Computation complexity matter Consider the problem.
Copyright ©: University of Illinois CS 241 Staff1 Threads Systems Concepts.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 4: Processes Process Concept Process Scheduling Types of shedulars Process.
Lecture 6: Process and Threads Topics: Process, Threads, Worker Thread, Async Task Date: Mar 1, 2016.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Chapter 6 Limited Direct Execution Chien-Chung Shen CIS/UD
Android Overview Reference: Embedded Android by Yaghmour.
One of the reasons why people love HP devices is that their battery life is superior to their competitors. But, even the best HP laptop doesn’t have a.
Input/Output (I/O) Important OS function – control I/O
Operating Systems Case Study
Introduction to Operating Systems
Module 12: I/O Systems I/O hardware Application I/O Interface
Processes and threads.
Process Management Process Concept Why only the global variables?
Karthik Dantu and Steve Ko
Operating Systems •The kernel is a program that constitutes the central core of a computer operating system. It has complete control over everything that.
ANDROID AN OPEN HANDSET ALLIANCE PROJECT
Thread Fundamentals Header Advanced .NET Threading, Part 1
CS399 New Beginnings Jonathan Walpole.
Linux 202 Training Module Program and Process.
Lecture 21 Concurrency Introduction
Lecture 6: Process, Thread, Task
The Android Activity Lifecycle
Processes A process is a running program.
Want to play a game? – Linux Kernel Modules
What is an Operating System?
Wakelock detector 1.5.* UzumApps Copyright 2013.
Process management Information maintained by OS for process management
Introduction to Operating Systems
Module 2.2 COP4600 – Operating Systems Richard Newman
Making Virtual Memory Real: The Linux-x86-64 way
Operating System Concepts
13: I/O Systems I/O hardwared Application I/O Interface
CS703 - Advanced Operating Systems
Process & its States Lecture 5.
Mid Term review CSC345.
Process Description and Control
Introduction to Operating Systems
CSE 451 Autumn 2003 Section 3 October 16.
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Chapter 3: Processes.
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes in Unix and Windows
Process Description and Control in Unix
CSE 153 Design of Operating Systems Winter 2019
Process Description and Control in Unix
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment. Phone:
Interrupts and Interrupt Handling
Lecture Topics: 11/1 Hand back midterms
Module 12: I/O Systems I/O hardwared Application I/O Interface
Presentation transcript:

Android Kernel Extensions Karthik Dantu and Steve Ko

Administrivia Assignment 4 is out and due in two weeks. Please stop by during our office hours for your project discussions. Don’t wait until the next Friday meeting!

Today: Android Kernel Extensions Why? Android “OS” is not just a kernel (as we all know). What changes were made to the kernel then? Goal Introduction to some of the interesting kernel extensions of Android

Today: Android Kernel Extensions Resources: AOSP Linux code “Embedded Android” http://elinux.org http://source.android.com http://developer.android.com

Kernel Changes Binder (last time) Wakelock Low memory handler a.k.a. OOM Killer Logger Anonymous shared memory (ASHMEM) Process memory allocator (PMEM) Etc.

User-Kernel Interfaces System calls /sys (wakelock, low memory killer) /dev (logger) /proc (wakelock)

WakeLock

Wakelock /kernel/power/wakelock.c A mechanism to control “opportunistic suspend” or “autosleep” i.e., aggressively going to low-power states Why? Obviously to save power What do we need to make this possible? Can we just go to sleep whenever?

Wakelock A mechanism to prevent the system from entering into the suspend or other low-power states. Telling the system that there’s something important going on, i.e., the system shouldn’t go to low-power states. Can be used from the user space as well as the kernel space.

Wakelock Android App Example PowerManager provides the APIs.

Android App Wakelock Types Flag Value CPU Screen Keyboard PARTIAL_WAKE_LOCK On Off SCREEN_DIM_WAKE_LOCK Dim SCREEN_BRIGHT_WAKE_LOCK Bright FULL_WAKE_LOCK

User Space Wakelock Any user space process can lock/unlock by writing to /sys/power/wake_lock /sys/power/wake_unlock PowerManager does this. /proc/wakelocks shows all the wakelock status

Kernel Space Wakelock #include <linux/wakelock.h> void wake_lock_init(struct wake_lock *lock, int type, const char *name) void wake_lock_destroy(struct wake_lock *lock) void wake_lock(struct wake_lock *lock) void wake_unlock(struct wake_lock *lock)

Wakelock Controversy Many pieces of Android kernel changes are not merged to the mainline Linux source (e.g., “staging” mostly means it’s a temporary directory). It also took much time to merge currently-merged pieces, e.g., wakelocks, with a lot of initial objections from the Linux maintainers. “Wakelocks and the embedded problem” http://lwn.net/Articles/318611/

Initial Objections Code mostly developed behind closed doors. Shipped first before getting into the mainline kernel Much duplication with an existing API (pm_qos) No way to recover if a user process exits while holding a wakelock Etc.

Low Memory Killer

Memory Management Android wants to keep apps around as much as possible. Why? Multi-tasking, fast context switch, etc. What’s the problem with this? Memory size is limited, so we can’t keep everything around. How does a typical OS handle this? Swapping out applications Bad news: Android doesn’t have any swap space.

Memory Management How can we do this? Android does two things. Android app heap size is limited, which prevents an app to grow arbitrarily, e.g., 16MB – 48MB (depending on the device & AndroidManifest.xml config) When memory gets tight, the kernel kills processes.

Low Memory Killer Low memory killer (also called oom killer) does the job. /drivers/staging/android/lowmemorykiller.c ~200 LoC Low memory killer kills processes according to priorities.

Low Memory Killer /init.rc defines priority values & minimum free memory size for each priority. ActivityManagerService updates priority values for the processes in the memory.

Priority examples Foreground application: A process that contains a running Activity (highest priority) Visible application: A process that holds a paused but still visible Activity or a service … Hidden Application: A process that is no longer visible Empty applications: Process that contains no active applications (lowest priority)

Logger

Android Logging System Android has a separate logging system different from Linux’s (e.g., dmesg & /proc/kmsg). A typical user’s point of view android.util.Log API Logcat Kernel-side /drivers/staging/android/logger{.c, .h}

Architecture http://elinux.org/Android_Logging_System (image by Tetsuyuki Kobabayshi, of Kyoto Microcomputer Co.)

Log Buffers Main: main app log android.util.Log Event: system event information android.util.EventLog System: system components android.util.Slog Radio: radio and phone-related events /dev/log

Paranoid Networking Another potentially interesting change GID-based network restrictions #define GID Capability AID_NET_BT_ADMIN 3001 Can create an RFCOMM, SCO, or L2CAPP Bluetooth socket AID_NET_BT 3002 Can create a Bluetooth socket AID_INET 3003 Can create IPv4 or IPv6 socket AID_NET_RAW 3004 Can create raw sockets AID_NET_ADMIN 3005 Allow CAP_NET_ADMIN permissions for process

Summary Wakelock is a mechanism to tell the kernel that it shouldn’t go to sleep because there’s some interesting stuff going on. Low memory killer manages app processes memory usage. Logger has a few buffers for different types of events.