400 likes | 816 Views
iPhone. Joseph Del Rocco COP5611 April 2009. Outline. Hardware CPU / GPU / Cache Memory / Storage / Extras Operating System Overview / OS X / Darwin XNU / Mach IPC / Thread Management Differences w/ iPhone Development SDK / Tools / Objective-C / Examples. Hardware (3G).
E N D
iPhone • Joseph Del Rocco • COP5611 • April 2009
Outline • Hardware • CPU / GPU / Cache • Memory / Storage / Extras • Operating System • Overview / OS X / Darwin • XNU / Mach • IPC / Thread Management • Differences w/ iPhone • Development • SDK / Tools / Objective-C / Examples
Samsung S5L8900 (SoC) S3C6400
PowerVR MBX Lite 133 MHz (233 MHz) ~130m pix/s fillrate ~1.7m tri/s fill rate Anti-Aliasing Texture Compression OpenGL ES / D3D M CPU / GPU Specs ARM1176JZ(F)-S • 412 MHz (620 MHz) • 103MHz FS Bus • 32-bit RISC • 32KB L1 (16x2 I/D) • ARM TrustZone • ARM Thumb
L1 Cache • “...evenly addressed double words are stored in one RAM, while oddly addressed double words are stored in the second RAM. • At synthesis time, the designer may choose to implement one, two or three separate RAMs. • Where separate RAMs are implemented, the core can access these in parallel, hence increasing performance.” [6]
Memory (PoP) • DDR-SDRAM • 1Gb (128MB) (16MB reserved for GPU) • 8K blocks • 4 banks • Speed 7.5ns@CL3 • 1.8V core - 1.8V I/O
Storage K9MCG08U5M TH58NVG6D1D (3G) • NAND Flash Memory • 4GB / 8GB / 16GB • 2 GB dies (x2 / x4 / x8) --------------------------------------- NOR faster non-contiguous reads, slow erase/write (read only) NAND faster erase/write, slow non-contiguous reads (serial)NAND prone to single-bit errors; error detection & correction
Touch Screen Broadcom BCM5974 Controller • Multi-touch • No stylus or non-conductive gloves
Extras • STMicro LIS331 DL/AL Accelerometer • click & double-click • wake-up • motion detection • acceleration (x, y, z) axes • high-pass filters • 2 dedicated interrupt lines • Hammerhead II PMB2525 GPS • 2m steady state accuracy • < 50mm2 PCB area • smart power management • multi-path mitigation
iPhone OS (?) • “Remember that OS X on a Mac features a lot of applications that we don’t have to ship on the iPhone.” • Greg Joswiak • Macworld Expo (01/2007) • “The entire Mac OS is gigs, a lot is data. Take out the data -- every desktop pattern, sound sample -- if you look at Safari it's not that big. It's REAL Safari, REAL OS X. We put a different user interface on it to work with a multi-touch screen...” • Steve Jobs • Wall Street Journal: D Conference (05/30/2007)
NeXTSTEP • “... we at id Software developed … DOOM and Quake on the NeXTSTEP 3.3 OS running on a variety of hardware for about 4 years. I still remember the wonderful time I had coding DoomEd and QuakeEd in Objective-C; there was nothing like it before and there still is no environment quite like it even today.” • John Romero • http://rome.ro • “I wrote the program using a NeXT computer. This had the advantage that there were some great tools available -it was a great computing environment in general. In fact, I could do in a couple of months what would take more like a year on other platforms, because on the NeXT, a lot of it was done for me already.” • Tim Berners-Lee • http://www.w3.org/People/Berners-Lee/WorldWideWeb http://www.youtube.com/watch?v=j02b8Fuz73A
NeXTSTEP -> OPENSTEP -> Rhapsody -> Darwin -> OS X http://www.roughlydrafted.com/RD/RDM.Tech.Q1.07/4B800F78-0F75-455A-9681-F186A4365805.html Apple using “System Software” 1984 - 1999 Apple talks w/ Microsoft, Be, Sun, NeXT. Apple acquires NeXT (1996) Apple initially pushes OPENSTEP (epic fail) “Rhapsody” = OPENSTEP, BSD, etc. Apple rushes OS X Server v1.0 (1999) Apple forks Rhapsody as Darwin (2000) Apple releases OS X v10.0 (2001)
Mac OS X Kernel: XNU Layered + modular + simplicity / debugging - layers add overhead - layer order complexity (catch-22 scenarios) Microkernel + ease of extending + hardware portability + reusable w/ OS layers - performance decrease due to extensive IPC Hybrid / Modular + benefits of layered + dynamic-loaded extensions + IPC unnecessary between extensions - too many kernel extensions becomes -> monolithic “...about 70 percent of operating systems consist of device drivers, which have error rates three to seven times higher than ordinary code...”[22]
XNU FreeBSD I/O Kit • process model • user ids, permissions, basic security policies • POSIX API, BSD style system calls • TCP/IP stack, BSD sockets, firewall • VFS, HFS and other file systems • System V IPC • cryptographic framework • various synchronization mechanisms • dynamic matching / loading of drivers / kext • numerous device families (usb, pci, ata, etc.) • i/o registry • object oriented abstractions of devices • power management • an extensive API • plug-and-play and hot-plugging • driver stacking Mach • preemptive multitasking, kernel threads • protected memory • virtual memory management (FIFO w/ second chance) • inter-process communication • interrupt management • kernel debugging support • console I/O
Mach • Simplified kernel structure, easier to extend & modify • BSD compatible; Heterogeneous system support; Mach-O binary format • Support diverse architectures; mutliprocessors (UMA, NUMA, NORMA) • Network transparency; Distributed operation internally & externally • “Fix” UNIX design of “everything-as-a-file”; Generalize pipes to ports “Mach’s design philosophy is to have a simple, extensible kernel, concentrating on communication facilities. For instance, all requests to the kernel, and all data movement among processes, are handled through one communication mechanism. Mach is therefore able to provide system-wide protection to its users by protecting the communications mechanism. Optimizing this one communications path can result in significant performance gains, and it is simpler than trying to optimize several paths.” [21]
Mach: System Components • TaskContains virtual address space, threads, &protected access to system resources via ports. • ThreadBasic unit of execution; shares parent tasks’ resources. • PortKernel-protected communication channel with access rights.Tasks must have proper rights to use the ports.Implemented as a protected, bounded queue within kernel. • Port SetGroup of ports sharing a common message queue. • MessageBasic method of communication between threads; collection of typed data or pointers. • Memory ObjectAny source of memory where memory-mapped access makes sense;Tasks access it by mapping portions into their address spaces.
Mach: IPC • Messages contain typed data for ease of interpretation • Only one task may have receive rights to a port, many tasks may have send rights • Essentially, IPC message passing implemented w/ shared memory (intra-computer) • Note this mechanism can also used for process synchronization! • “All other interprocess communications mechanisms in Mac OS X are implemented using Mach ports at some level” - Mac OS X Technology Overview
Mach: Task Management • One-to-One mapping of User threads to Kernel threads • Only threads that cause page faults or makes a system call is suspended, the rest continue executing • Scheduler only deals w/ threads, has no knowledge of tasks (Sys-ConSco) • Priority Scheduling used (0 -127); “exponential average of CPU usage” • 32 global run queues; Per processor “local” queues (device driver) (priority) • Time quantum varies inversely w/ total # of threads in system (thrds < cpus) • Cthreads API: create threads, destroy, wait, yieldMutual exclusion provided by spinlock mutexesSyncing w/out spinlock provided by condition variables • Cthreads → Pthreads (1995)
I/O Kit • Implemented w/ libkern to provide OOP • Recommended if software is used by the kernel itself, user-space programs, or software needs to respond directly to primary interrupts
Background Processes • “Only one iPhone application can run at a time, and third-party applications never run in the background.” • iPhone Human Interface Guidelines, p16 • [Here's why it's bad: battery life - it'll continue to drain your battery in the background); performance - background applications will suck up CPU cycles, slowing down your foreground application. … Also not supported over the air.] [15] • Scott Forstall, VP iPhone Software, WWDC 2008 • Unified Push Notification • Apple provides server farm for your server apps • Updates clients (“badges”, “alert sounds”, “text messages”)
So... What Did They Take Out? • OS X iPhone = “considerably less” than half a GB [14]OS X v10.0 = 800 MB (minimum) (2001)OS X v10.5.6 = 2.0 GB (atleast) (2009) • A lot of drivers & software???multiple file system formats, multiple drives, multiple volumes on drives, RAID, removable drives, real time system support, FireWire, CD/DVD, R/RW CD/DVD, printers, scanners, multiple users & preferences, Finder, fonts, screen savers, etc. • kernel and driver-level interfaces not exposed • No garbage collector on iPhone imp. of Obj-C • ARM Thumb compiled code is quite compact (~35% smaller)
“...any code written in C could be executed successfully in Thumb state. However, device drivers and exception handlers must often be written at least partly in ARM state.” [4] ARM Thumb “...not all ARM instructions are available in the Thumb subset; [...] there's no way to access status or coprocessor registers. Also, some functions that can be accomplished in a single ARM instruction can only be simulated with a sequence of Thumb instructions.”[4]
“...system libraries and frameworks of iPhone OS […] are a subset of the libraries and frameworks on Mac OS X. For example, there is no Carbon application environment on iPhone OS, there is no command-line access (the BSD environment), there are no printing frameworks and services, and QuickTime is absent from the platform. However, because of the nature of the devices supported by iPhone OS, there are some frameworks, both public and private, that are specific to iPhone OS.” iPhone Reference Library
Objective-C Simula C Small Talk Developed 1985 “interchangeable software components” Licensed by NeXT 1988 Used by Apple (Cocoa API) • Message Handlers vs. Methods • Dynamic Typing (use types according to runtime data) • Categories (method blocks bound @ runtime) • Properties (public instance variables – generate methods) • Protocols = Interfaces C++ Obj-C
References (Hardware) • http://www.apple.com/iphone/specs.html • http://dev.emcelettronica.com/touch-screen • http://www.embeddedstar.com/weblog/2007/12/05/st-lis331dl-lis331al/ • http://www.embedded.com/shared/printableArticle.jhtml?articleID=15200241 • http://www.arm.com/products/CPUs/ARM1176.html • Lewin, Peter, May 2006, Cortex-R4: A comparison with the ARM9E processor family • http://www.imgtec.com/powervr/mbx.asp • http://www.techonline.com/product/underthehood/209000013 • http://insidetronics.blogspot.com/ • http://toucharcade.com/2008/07/07/under-the-hood-the-iphones-gaming-mettle/ • http://reviews.cnet.com/8301-19512_7-10115256-233.html • http://www.eetimes.com/news/semi/showArticle.jhtml?articleID=200900740
References (OS) • Silberschatz, Abraham, Greg Gagne, Peter Galvin; Operating System Concepts: 7th; John Wiley & Sons 2005 • http://www.macworld.co.uk/ipod-itunes/news/index.cfm?newsid=16927 • http://www.macworld.com/article/133867/2008/06/backgroundprocesses.html • http://en.wikipedia.org/wiki/Darwin_(operating_system) • http://osxbook.com/book/bonus/ancient/whatismacosx//arch_xnu.html • Singh, Amit; Mac OS X Internals: A Systems Approach; Addison-Wesley Professional 2006 • http://developer.apple.com/macosx/coredata.html • http://www.roughlydrafted.com/RD/RDM.Tech.Q1.07/4B800F78-0F75-455A-9681-F186A4365805.html • http://codex.cs.yale.edu/avi/os-book/os8/online-dir/b.pdf (http://www.os-book.com) • Tanenbaum, Andrew S; Can We Make Operating Systems Reliable and Secure?; IEEE Computer 2006 • http://www.w3.org/People/Berners-Lee/WorldWideWeb • http://rome.ro/2006/12/apple-next-merger-birthday.html