Chinaunix首页 | 论坛 | 博客
  • 博客访问: 104037
  • 博文数量: 11
  • 博客积分: 2000
  • 博客等级: 大尉
  • 技术积分: 260
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-31 21:46
文章分类

全部博文(11)

文章存档

2011年(1)

2008年(10)

我的朋友

分类:

2008-04-10 11:01:19

What Is Darwin (and How It Powers Mac OS X)

by Matthew Russell
09/27/2005
Darwin
Darwin is the Unix-derived core that provides the underlyingfoundation for Mac OS X. At Darwin's heart is the XNU kernel--a Mach3.0-based microkernel that has been modified to include portions ofFreeBSD for performance reasons. Darwin includes facilities forcreating device drivers, supports multiple file systems through itsenhanced Virtual File System (VFS) design, and offers premiernetworking facilities such as Bonjour, an implementation ofzero-configuration networking. Apple releases Darwin under the ApplePublic Source License (APSL) 2.0, and organizations such asOpenDarwin.org and GNU-Darwin use this source to periodically releasetheir own custom versions of Darwin in an effort to foster communityinvolvement.

In this article:

  1. Darwin's Evolution
  2. A Quick Overview of the OS X Architecture
  3. XNU--Darwin's Kernel
  4. The Rest of Darwin
  5. Darwin and Open Source
  6. The Intel Switch

Since the introduction of Mac OS X, its Objective-C-based Cocoaframeworks have allowed developers to produce some amazing software atan incredible pace. All of the resulting innovation in the marketplacehas made it pretty easy for us to stay captivated on the desktop andforget all about the engineering marvel that makes all of thispossible. Let's take a trip down into the core of OS X--Darwin--tolearn more about the foundation that gives us one of the best userexperiences in computing.

//

Darwin's Evolution

Mac OS X development started shortly after Apple's acquisition of all the way back in 1996. After the buyout, development on what would evolve into Mac OS X was code-named until Mac OS X was officially released in 2001.

Sometime during Rhapsody's development, its code was forked and opensourced into what we know as Darwin. By April 2000, Apple's team hadalready completed their version 1.0 build. Although they'd beenreleasing the Darwin source prior to that time, the version 1.0 buildwas especially significant because it was based on a new hybrid corethat we now know as the kernel. Like the 's recursive acronym , XNU stands for "XNU is Not Unix."

A Quick Overview of the OS X Architecture

Now that you know a bit about Darwin's past, let's take a moment tolook at where it fits into the overall OS X architecture before divingoff into the details. Generally speaking, most of Darwin fits intowhat's called the Core OS, which sits directly on top of thehardware and comprises the kernel, device drivers, and other low-levelresources of the OS. Other layers, including core services, applicationservices, graphics, and multimedia, sit between the Core OS and theuser experience that is defined by Aqua: the standard that defines theoverall appearance and behavior of Mac OS X apps. For some good readingon all of the ins and outs of how all of the OS X technology fits together, check out the Mac OS X Technology Overview. It's a good way to spend a rainy day.


layered view of os xos x system architecture



XNU--Darwin's Kernel

A good starting point for discussing any OS is the kernel: the coreof the OS that provides access to and scheduling for the underlyinghardware that's available. To fully appreciate Darwin, you'll want toknow some of the details associated with its kernel, XNU, which is aninteresting blend of the 3.0 microkernel that's been modified to include portions of inside the kernel space for performance reasons. Mach's foundations goback to Carnegie Mellon University out of Pittsburgh while FreeBSD is adescendant of (Berkeley Software Distribution), which hails from--you guessed it--the University of California at Berkeley.


//

XNU is the result of an effort to combine the strengths of twodifferent approaches to kernel design: the monolithic approach and themicrokernel approach. While the jargon might already sound complicated,the primary difference between the two is pretty simple and basicallyboils down to what programs run inside the kernel itself and whatprograms run in .Whereas monolithic kernels typically are defined by a fairly completeset of rich abstractions that access the hardware all within the sameaddress space, microkernels tend to provide a fairly minimal set ofservices within the kernel and use daemon (server) processes running in userland for the rest of the core services.

monolithic kernelmicrokernel
Conceptual views of monolithic kernel (left) and microkernel (right) design

There are frequently debated trade-offs between the two approaches,but just about all of them eventually come back to efficiency as thepivotal point of discussion. The tightly coupled nature of a monolithickernel allows it to make very efficient use of the underlying hardware,which is a very desirable thing. The drawbacks of monolithic kernels,however, are that they're very difficult to write and a single mistakein the kernel's code can crash the entire system.

Microkernels, on the other hand, run a lot more of the coreprocesses in userland. This approach simplifies the actual kerneldesign and can provide a great deal of stability in the system.Unfortunately, these benefits come at the cost of the microkernelhaving to pass a lot of information in and out of the kernel spacethrough a process known as a context switch. Context switches introduceconsiderable overhead and therefore result in a performance penalty.

You're probably beginning to see the underpinnings of the debatethat unravels when you start to make a case for one kernel design overthe other. Perhaps the most famous of all these debates was betweenLinus Torvalds and Andrew Tanenbaum. Torvalds makes a case for themonolithic kernel, while Tanenbaum defends the microkernel approach.You can read the original messages that were part of a world famousflame war back in 1992 . (It's fortunate for us that the decision for Darwin's kernel has already been made.)

The Rest of Darwin

We've been harping on XNU for a while now, but there's still a lotmore to be said about Darwin besides its kernel. Some of the mostnotable features worth mentioning include its facilities providedthrough I/O Kit, its Virtual File System (VFS), and its networkingsupport.

I/O Kit

Darwin's I/O Kit (Input/Output Kit) is a Mach-based device driverframework. It's modular, extensible, and offers a true plug-and-playsolution for dynamic device management. Unlike Cocoa, which is writtenin Objective-C, the I/O Kit is written in a restricted subset of C++that's based on the specification. Much of the justification behind the choice of C++ as alanguage for I/O Kit was based upon C++'s mature compiler andlong-standing support for systems programming.

Fitting into the Mach-based kernel methodology, device driversderived from I/O Kit are special types of kernel extensions thatprovide the information necessary to handle a device or entire familyof devices. Unless you're writing device drivers or interfacing tohardware at its lowest levels, you probably won't need to work with I/OKit. But just in case you do, I/O Kit Fundamentals is a great starting point.


File System and Network Support

Darwin's file system and networking support comes from its rich BSDheritage. Its VFS design enables features like long filenames,URL-based volume mounting, and to take place. Darwin's file system can handle just about anything you throw at it: , , , , and .As the web becomes more and more pervasive, complementary networkingsupport for file system support is a must have, and don't worry--youwon't be disappointed.


//

If you've ever tried to set up networking on a Windows box, you knowthat it can often be a nightmare. At one point, you might have beenchanging all sorts of settings on multiple tabs that opened newwindows, which also had tabs that had multiple properties with a poorhelp system. But with Darwin, there's none of that. Darwin's BSD-basedextensible network protocol stack gives rise to OS X features such as ,a zero-configuration networking implementation that eliminates justabout all of the hassles that are normally associated with networking.It really can't get much simpler than that. Although features likethese are easy to take for granted, they really are gems in Darwin'soverall design.

Darwin and Open Source

Apple releases a new version of Darwin on their open source site for each major update to OS X, and it's not long after Apple's release that the folks at provide a corresponding build of OpenDarwin. OpenDarwin is essentiallyApple's latest release with modifications to give it some extrafeatures that Apple doesn't provide. These additional features areusually things like GUI support, device drivers, utilities, and support for legacyhardware--basically features that don't directly support Mac OS X.

Although the releases of Darwin under the versions less than 2.0 of the APSL (Apple Public Source License) were ,the APSL as of version 2.0 does qualify as a free software license, andthis is the license that most of Darwin is released under. The FSF,however, considers the APSL 2.0 to still have : it allows linking with other files that can be entirely proprietary, and it is generally incompatible with the .I don't think we'll be seeing any trade secrets like QuickTime,Spotlight, or the Cocoa frameworks being open sourced anytime (ever),so don't hold your breath on this one.

You can download Apple's version of Darwin or OpenDarwin if you wantto tinker around and get into the guts of Mac OS X. If you'reinterested in trying out yet another possibility that comes with someadditional bells, whistles, and software mods, take a look at --a project that aims to be the "most free" version of Darwin.

The Intel Switch

When Steve Jobs announced the Intel switch, a lot of people freakedout and wondered how on earth an entire OS could be turned around torun on a different architecture in such a short amount of time. Littledid they know that Darwin had been leading the way by alongside of Mac OS X since the conception of OS X--a practice that nodoubt provides a significant boost to the overall effort. In fact, youcan read about Darwin's 1.0 build right herein an old Advogato diary entry. I guess if you couldn't be there, thenthis is the next best thing. In the entry you'll even see a referenceto (universal binaries), a technology we've been hearing a lot about lately that also dates back to the days of NeXT.

For a good grin, check out --a weblog entry that comments on an old Wired news article from 2000. It has some interesting quotes regarding the Intel switch in light of what we now know today.

Now Ya Know

Now you'll never have to wonder what that friendly little messageyou see in Terminal ("Welcome to Darwin!") ever means again. Hopefullythis background has provided you with a better understanding of how MacOS X works, where it comes from, and how it powers OS X. Now get outthere, download the Darwin source, and take a look at how OS X works under the hood.



原文:http://www.macdevcenter.com/pub/a/mac/2005/09/27/what-is-darwin.html?page=1

阅读(1439) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:linux 2.6.25 changelog

给主人留下些什么吧!~~