chapter 1-linux outline - 國立中興大學osnet.cs.nchu.edu.tw/powpoint/embedded94_1/chapter...
TRANSCRIPT
Linux Introduction
Paul Lab Linux Revolution 2
The Birth of Linux
Linux緣起-Linus's unixv 1991年十月,一個名為Linus Torvalds的年輕芬蘭大學生在
comp.os.minix這個新聞群組上發表了這樣的一篇文章:”Hello everybody out there using minix -I'm doing a (free) operation system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones.”,這個Linus的興趣(hobby)就是Linux核心程式0.02版的原始碼。
v 自這個0.02版的Linux核心程式公諸於世後,Internet上許多高手相繼地投注在Linux的相關開發,目前Linux已經成為非常受人歡迎的一個多人多工、免費、穩定、效率高的作業系統,可以在包括 i386、Sparc、Alpha、Mips、Power PC等等眾多不同電腦系統平台上執行,蔚為風潮。
開放性原始碼(Open Source)及GPL(General Public License)v 開放性原始碼很多,如BSD UNIX、X Window等等,Linux的原始碼可以輕易地取得,及自由地散佈。但是讓Linux能風行的原因,應該是基於GNU通用公共許可證(GPL,General Public License)的保護
v 任何根據開放性原始碼軟體所做的任何修改,都有義務要再開放這些修改後的原始碼。如此一來,使得軟體的智慧結晶能夠分享與累積,而開發者的努力也會有所保障,軟體也能更自由地散佈。
v Linux即是遵循GPL的精神,而Linux上的軟體,如Apache server、Netscape等等也都遵循GPL的精神,而軟體愈多,使用者就愈多,開發的人愈多,開發的速度就愈快,Linux也更加地完備,成為total solution,而蔚為風潮。
Linux Versionsv Linux distinguishes stable kernels from
development kernelsv Linux version: X.Y.Z�X.Y: Version number
v If the second number is even: stable kernelv If the second number is odd: development kernel
�Z: release numbervFix bugs reported by Users
Featuresv Freev Open systemv Open sourcev GNU GPL (General Public License)v POSIX standardv High portabilityv High performancev Robustv Large development toolsetv Large number of device driversv Large number of application programs
System Featuresv Multi-taskingv Multi-userv Multi-processorv Virtual memoryv Monolithic kernelv Loadable kernel modulesv Networkingv Shared librariesv Support different file systemsv Support different executable file formatsv Support different networking protocolsv Support different processor architectures
Resourcesv Distributions�RedHat、Slackware、OpenLinux、SuSE、Debian、
TurboLinux、Mandrake、Corel、Embedixv Booksv Magazines�The Linux Journal, Linux Magazine
v Web sites�http://www.linux.org�http://www.linuxdevices.com/
User View of Linux OS
Hardware
Kernel
Shell
Applications
System Structure
System calls interface
File systemsext2fs xiafs proc
minix nfs msdos
iso9660
Task managementSchedulerSignalsLoadable modulesMemory management
Central kernel
Machine interface
ipv4ethernet
...
Network ManagerPeripheral managers
block character
sound card cdrom isdn
scsi pci network
Buffer Cache
Processes
Machine
Linux Kernel Architecture
Kernel Source Code Organization
v Source code web site:http://www.kernel.org
v Source code version:� X.Y.Z� 2.2.17� 2.4.18
Kernel Source Code Organization
Resources for Tracing Linux
v Source code browser�LXR (Source code navigator)
v Books�Understanding the Linux Kernel, D. P. Bovet and M.
Cesati, O'Reilly & Associates, 2000.�Linux Core Kernel – Commentary, In-Depth Code
Annotation, S. Maxwell, Coriolis Open Press, 1999.�The Linux Kernel, Version 0.8-3, D. A Rusling, 1998.�Linux Kernel Internals, 2nd edition, M. Beck et al.,
Addison-Wesley, 1998. �Linux Kernel, R. Card et al., John Wiley & Sons, 1998.
Reentrant KernelsvUnix kernels are reentrant�Several processes may be executing in
Kernel Mode at the same time�On uniprocessor systems, only one
process can progress, but many may be blocked in Kernel Mode waiting for some events
Reentrant Kernels (Cont.)v Reentrant Functions � functions that only modify local variables but do
not alter global data structuresv To provide reentrant kernel� Implement the kernel as a collection of reentrant
functions� Instead, Linux uses the nonreentrant functions
and locking mechanismvTo ensure only one process can execute a nonreentrant
function at a time
Kernel Control Path
vA kernel control path denotes the sequence of instructions executed by the kernel to handle�System call�Exception�Interrupt
Synchronization and Critical Regions
v Implement a reentrant kernel requires synchronization�Different kernel control paths may access
the same kernel data structure�Called Race condition�This section of code is called a critical
region
Synchronization and Critical Regions (Cont.)
vPossible solution�Atomic operationvRead and decrement a variable with a single,
noninterruptible operation�However, many kernel data structures, e.g.
linked list, cannot be accessed with a single operation
Synchronization and Critical Regions (Cont.)
vSolutions�Nonpreemptive Kernels
�Interrupt disabling
�Spin locks
Nonpreemptive KernelsvWhen a process executes in Kernel Mode, it
cannot be arbitrarily suspended and substituted with another process
v Ineffective in multiprocessor system�Two kernel control paths running on different
CPUs may concurrently access the same data structure
Interrupt disablingvApproach�Disable interrupts �Enter critical section�Reenable interrupts
v Ineffective if the critical region is largevCannot work in a multiprocessor
system
Semaphoresv Semaphore
� A counter � Has two atomic operations
v Upv Down
v Each semaphore is associated with a list of waiting process� Link processes that are blocked
v Effective in both uniprocessor and multiprocessor
Spin Locksv In Multiprocessor, semaphores may be inefficient
if the time required to update the data structures is short� Insert a process into a semaphore list is relative
expensivev Spin lock�Executing a tight instruction loop until the lock becomes
openv Used in a multiprocessor system