Unformatted text preview:

ANDROID OSCSE120 (FA10)Xiao Ma([email protected])the definition of open: "mkdir android ; cd android ; repo init -u git://android.git.kernel.org/platform/manifest.git ; repo sync ; make"WHY ANDROID?What does it mean to researchers?What does it mean to users?OUTLINEAndroid platform architectureOS kernel, libraries and devicesAndroid programming modelDelvik Virtual MachineEnergy efficiency How to write efficient codeFIRST THING FIRSTWhat is the difference between a mobile OS and a desktop/server OS?ARCHITECTUREANDROIDANDROIDANDROIDBASED ON LINUXAndroid uses Linux 2.6 kernel as the hardware abstractionWhat are the essences an OS should provide?Memory management, process management, IPCNo virtual memory; specially implemented IPCDrivers and architecture supportHow to port Android to a new device?Using Linux vs. Writing a new OS from scratchDo all Linux kernel implementations work well on mobile devices?APPLICATION LIBRARYGNU libs (glibc) is too big and complicated for mobile phones, so Android implements its own special version of libc - Bionic libc:Smaller size - 200K (glibc is more than 400K)Strip out some complicated C++ features, the most significant one - no C++ exception!Very special and small pthread implementation, heavily based on kernel futexesBionic libc does not fully support POSIX and is not compatible with glibcwhich means ...?PROCESS MANAGEMENTWhat’s the difference between mobile apps cycle and desktop apps cycle?Two key principlesAndroid usually do not kill an app, i.e. apps keep running even after you switch to other appsAndroid kills apps when the memory usage goes too high, but it saves app state for quick restart later onDo they make sense to mobile apps?APPLICATION LIFE CYCLEEXAMPLESystemHomeHomeHomeAt the “Home” screenEXAMPLESystemHomeMailHomeListHomeListStart the “Mail” app and read the listEXAMPLESystemHomeMailHomeListMessageHomeListMessageClick on one of the message and see its contentEXAMPLESystemHomeMailHomeListMessageBrowserBrowserHomeListMessageBrowserClick a link in the messageEXAMPLESystemHomeHomeBrowserBrowserHomeListMessageBrowserNow we have enough space to start the “Map” appEXAMPLESystemHomeHomeBrowserBrowserHomeListMessageBrowserMapMapMapStart the “Map” appEXAMPLESystemHomeHomeBrowserBrowserHomeListMessageBrowserMapGo back to the browserEXAMPLESystemHomeHomeBrowserHomeListMessageMailListMessageThe “Mail” app is resumed and shows the previous messageEXAMPLESystemHomeHomeBrowserHomeListMailListGo back to the mail listEXAMPLESystemHomeHomeBrowserHomeMailGo back to the “Home” screenDEBATESwapping modelVS. Android’s life-cycle modelDISK I/OFlashHard Disk DriveRandom access~0.1ms5-10msFile fragment impactNoGreatly impactedTotal power1/2 to 1/3 of HDDup to 15+ wattsReliabilityReliableLess reliable due to mechanical partsWrite longevityLimited number of writesLess of a problemCapacity<= 512GB2-3TBPrice$1.5-2 / GB$0.1-0.2 / GBLIMITED WRITES?Flash drives have the well-known problem of limited number of writes in the life time - 10,000~100,000 times. Solution?What can applications do?How about operating system?Controllers?Hardware?MEMORY MANAGEMENTLinux kernel does most of the jobPage-based memory managementVirtual address to physical address mappingNO virtual memoryWhy do we still need “virtual to physical” address mapping?Why does Android not support virtual memory?POWER MANAGEMENTDALVIK VMWhy does Android let developers use Java?DALVIK VMA special Java virtual machine (VM) designed to run with limited system resourceMemory efficiencyRegister machine vs. Stack machine (modern JVM)fewer instructions, faster executionwhy does the number of instructions matter?Running multiple VMs more efficientlyDEX FILEJava class files are converted into “.dex” files that Dalvik executesJava byte-code is converted into Dalvik byte-code during this processMEMORY EFFICIENCYShared constant string poolShare clean (even some dirty) memory between processes as much as possible“.dex” files are mapped as read-only by mmap()Memory efficient JIT implementationJIT itself is about 100KCode cache and supporting data structure takes another 100K for each applicationSHARED STRING POOLpublic interface Zapper { public String zap(String s, Object o);}public class Blort implements Zapper { public String zap(String s, Object o) { .... }}public class ZapUser { public void useZap(Zapper z) { z.zap(...); }}SHARED STRING POOLSHARED MEMORYPROGRAMMING MODELEach application is running in its own processAn application can have one or more components:activities, services, broadcast receivers and content providersA task (an “application” from user’s point of view) consists of several activities from one or multiple applicationsAn application keeps running until the system kills it because of memory shortagePOWER SAVINGPicture is from Google I/O 09 talk - Coding for Life -- Battery Life, That IsGZIP TEXT DATAUse GZIP for text data whenever possibleCompressing is implemented by native codeCHECK NETWORK TYPEWifi and 3G are much more energy efficient, so wait for Wifi or 3G when transferring big chunk of dataUPDATE BINPicture is from Google I/O 09 talk - Coding for Life -- Battery Life, That IsUse setInexactRepeating() so the system can bin your update together with othersWORK OFFLOADINGNaive offloadingSpeech-to-text, OCRMore sophisticated offloading - fine-grained offloadingMAUI: Making Smartphones Last Longer with Code Offload (MobiSys ’10)Running two versions of the app on the mobile device and a powerful serverDecide when/what to offload on the flyEFFICIENT CODEfor (int i = initializer; i >= 0; i--)int limit = calculate limit;for (int i = 0; i < limit; i++)Type[] array = get array;for (Type obj : array)for (int i = 0; i < array.length; i++)for (int i = 0; i < this.var; i++)Iterable<Type> list = get list;for (Type obj : list)EFFICIENT CODETry to rest for the most of the timebe nice to other processesAvoid allocationshort-lived objects need to be garbaged collectedlong-lived objects take precious memoryMake a method static if it does not access member variablesAvoid internal getter/settersUse floating point numbers only when you have toPrefer int over enumUse static final for


View Full Document

UCSD CSE 120 - ANDROID OS

Documents in this Course
Threads

Threads

14 pages

Deadlocks

Deadlocks

19 pages

Processes

Processes

14 pages

Paging

Paging

13 pages

Processes

Processes

18 pages

Threads

Threads

29 pages

Security

Security

16 pages

Paging

Paging

13 pages

Processes

Processes

32 pages

Lecture 2

Lecture 2

13 pages

Paging

Paging

8 pages

Threads

Threads

14 pages

Paging

Paging

13 pages

Paging

Paging

26 pages

Paging

Paging

13 pages

Lecture

Lecture

13 pages

Processes

Processes

14 pages

Paging

Paging

13 pages

Security

Security

17 pages

Threads

Threads

15 pages

Processes

Processes

34 pages

Structure

Structure

10 pages

Lecture 3

Lecture 3

13 pages

Lecture 1

Lecture 1

28 pages

Threads

Threads

15 pages

Paging

Paging

30 pages

Load more
Download ANDROID OS
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view ANDROID OS and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view ANDROID OS 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?