Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 45 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
45
Dung lượng
124 KB
Nội dung
6 THE OPERATING SYSTEM MACHINE LEVEL CuuDuongThanCong.com https://fb.com/tailieudientucntt Level Operating system machine level Operating system Level Instruction set architecture level Microprogram or hardware Level Microarchitecture level Figure 6-1 Positioning of the operating system machine level CuuDuongThanCong.com https://fb.com/tailieudientucntt Address space Address Mapping 8191 4096 4K Main memory 4095 0 Figure 6-2 A mapping in which virtual addresses 4096 to 8191 are mapped onto main memory addresses to 4095 CuuDuongThanCong.com https://fb.com/tailieudientucntt Page Virtual addresses 15 61440 – 65535 14 57344 – 61439 13 53248 – 57343 12 49152 – 53247 11 45056 – 49151 10 40960 – 45055 36864 – 40959 Bottom 32K of main memory 32768 – 36863 Page frame Physical addresses 28672 – 32767 28672 – 32767 24576 – 28671 24576 – 28671 20480 – 24575 20480 – 24575 16384 – 20479 16384 – 20479 12288 – 16383 12288 – 16383 8192 – 12287 8192 – 12287 4096 – 8191 4096 – 8191 0 – 4095 0 – 4095 (a) (b) Figure 6-3 (a) The first 64K of virtual address space divided into 16 pages, with each page being 4K (b) A 32K main memory divided up into eight page frames of 4K each CuuDuongThanCong.com https://fb.com/tailieudientucntt 15-bit Memory address 1 0 0 0 0 1 Output register 0 0 0 0 0 0 0 0 0 1 0 0 0 1 Input register Virtual page Page table Present/absent bit 15 14 13 12 11 10 110 20-bit virtual page 12-bit offset 32-bit virtual address Figure 6-4 Formation of a main memory address from a virtual address CuuDuongThanCong.com https://fb.com/tailieudientucntt Page table Virtual page Page frame 15 0 14 13 0 12 0 11 10 0 0 Main memory Page frame 0 Virtual page 7 Virtual page 6 Virtual page 11 0 Virtual page 14 Virtual page 0 Virtual page 1 Virtual page 1 Virtual page 1 = Present in main memory = Absent from main memory Figure 6-5 A possible mapping of the first 16 virtual pages onto a main memory with eight page frames CuuDuongThanCong.com https://fb.com/tailieudientucntt Virtual page Virtual page Virtual page Virtual page Virtual page Virtual page Virtual page Virtual page Virtual page Virtual page Virtual page Virtual page Virtual page Virtual page Virtual page Virtual page Virtual page Virtual page Virtual page Virtual page Virtual page Virtual page Virtual page Virtual page (a) (b) (c) Figure 6-6 Failure of the LRU algorithm CuuDuongThanCong.com https://fb.com/tailieudientucntt Virtual address space Free Currently used Call stack Address space allocated to the call stack Parse tree Constant table Source text Symbol table Figure 6-7 In a one-dimensional address space with growing tables, one table may bump into another CuuDuongThanCong.com https://fb.com/tailieudientucntt 20K 16K 12K Symbol table 8K Source text 4K Segment Segment Constant table Segment Parse tree Segment Call stack Segment Figure 6-8 A segmented memory allows each table to grow or shrink independently of the other tables CuuDuongThanCong.com https://fb.com/tailieudientucntt Consideration Need the programmer be aware of it? How many linear addresses spaces are there? Can virtual address space exceed memory size? Can variable-sized tables be handled easily? Why was the technique invented? Paging No Yes No To simulate large memories Segmentation Yes Many Yes Yes To provide multiple address spaces Figure 6-9 Comparison of paging and segmentation CuuDuongThanCong.com https://fb.com/tailieudientucntt Shell User program User mode System call interface File system Process management Block cache IPC Scheduling Device drivers Signals Memory mgmt Hardware Figure 6-30 The structure of a typical UNIX system CuuDuongThanCong.com https://fb.com/tailieudientucntt Kernel mode POSIX program Win32 program OS/2 program POSIX subsystem Win32 subsystem OS/2 subsystem User mode System interface System services Executive File cache I/O File systems Virtual memory Processes and threads Security and Object management Device drivers Win32 Microkernel Graphics device interface Hardware abstraction layer Hardware Figure 6-31 The structure of Windows NT CuuDuongThanCong.com https://fb.com/tailieudientucntt Kernel mode Item Win32 API? Full 32-bit system? Security? Protected file mappings? Sep addr space for each MS-DOS program? Plug and play? Unicode? Runs on Multiprocessor support? Re-entrant code inside OS? Some critical OS data writable by user? Windows 95/98 Yes No No No No Yes No Intel 80x86 No No Yes Figure 6-32 Some differences between versions of Windows CuuDuongThanCong.com https://fb.com/tailieudientucntt NT 5.0 Yes Yes Yes Yes Yes Yes Yes 80x86, Alpha Yes Yes No Address 0xFFFFFFFF Stack Data Code Figure 6-33 The address space of a single UNIX process CuuDuongThanCong.com https://fb.com/tailieudientucntt API function VirtualAlloc VirtualFree VirtualProtect VirtualQuery VirtualLock VirtualUnlock CreateFileMapping MapViewOfFile UnmapViewOfFile OpenFileMapping Meaning Reserve or commit a region Release or decommit a region Change the read/write/execute protection on a region Inquire about the status of a region Make a region memory resident (i.e., disable paging for it) Make a region pageable in the usual way Create a file mapping object and (optionally) assign it a name Map (part of) a file into the address space Remove a mapped file from the address space Open a previously created file mapping object Figure 6-34 The principal API functions for managing virtual memory in Windows NT CuuDuongThanCong.com https://fb.com/tailieudientucntt System call Meaning creat(name, mode) Create a file; mode specifies the protection mode unlink(name) Delete a file (assuming that there is only link to it) open(name, mode) Open or create a file and return a file descriptor close(fd) Close a file read(fd, buffer, count) Read count bytes into buffer write(fd, buffer, count) Write count bytes from buffer lseek(fd, offset, w) Move the file pointer as required by offset and w stat(name, buffer) Return information about a file chmod(name, mode) Change the protection mode of a file fcntl(fd, cmd, ) Do various control operations such as locking (part of) a file Figure 6-35 The principal UNIX file system calls CuuDuongThanCong.com https://fb.com/tailieudientucntt // Open the file descriptors infd = open(′′data′′, 0); outfd = creat(′′newf′′, ProtectionBits); // Copy loop { count = read(infd, buffer, bytes); if (count > 0) write(outfd, buffer, count); } while (count > 0); // Close the files close(infd); close(outfd); Figure 6-36 A program fragment for copying a file using the UNIX system calls This fragment is in C because Java hides the low-level system calls and we are trying to expose them CuuDuongThanCong.com https://fb.com/tailieudientucntt Root directory bin dev lib usr … /lib /usr /dev /bin ast jim /usr/jim bin jotto … … … … /usr/ast data foo.c … … /usr/ast/bin game game game game … Data files Figure 6-37 Part of a typical UNIX directory system CuuDuongThanCong.com https://fb.com/tailieudientucntt System call mkdir(name, mode) rmdir(name) opendir(name) readdir(dirpointer) closedir(dirpointer) chdir(dirname) link(name1, name2) unlink(name) Meaning Create a new directory Delete an empty directory Open a directory for reading Read the next entry in a directory Close a directory Change working directory to dirname Create a directory entry name2 pointing to name1 Remove name from its directory Figure 6-38 The principal UNIX directory management calls CuuDuongThanCong.com https://fb.com/tailieudientucntt API function CreateFile DeleteFile CloseHandle ReadFile WriteFile SetFilePointer GetFileAttributes LockFile UnlockFile UNIX open unlink close read write lseek stat fcntl fcntl Meaning Create a file or open an existing file; return a handle Destroy an existing file Close a file Read data from a file Write data to a file Set the file pointer to a specific place in the file Return the file properties Lock a region of the file to provide mutual exclusion Unlock a previously locked region of the file Figure 6-39 The principal Win32 API functions for file I/O The second column gives the nearest UNIX equivalent CuuDuongThanCong.com https://fb.com/tailieudientucntt // Open files for input and output inhandle = CreateFile(′′data′′, GENERIC READ, 0, NULL, OPEN EXISTING, 0, NULL); outhandle = CreateFile(′′newf′′, GENERIC WRITE, 0, NULL, CREATE ALWAYS, FILE ATTRIBUTE NORMAL, NULL); // Copy the file { s = ReadFile(inhandle, buffer, BUF SIZE, &count, NULL); if (s > && count > 0) WriteFile(outhandle, buffer, count, &ocnt, NULL); while (s > && count > 0); // Close the files CloseHandle(inhandle); CloseHandle(outhandle); Figure 6-40 A program fragment for copying a file using the Windows NT API functions This fragment is in C because Java hides the low-level system calls and we are trying to expose them CuuDuongThanCong.com https://fb.com/tailieudientucntt API function CreateDirectory RemoveDirectory FindFirstFile FindNextFile MoveFile SetCurrentDirectory UNIX mkdir rmdir opendir readdir chdir Meaning Create a new directory Remove an empty directory Initialize to start reading the entries in a directory Read the next directory entry Move a file from one directory to another Change the current working directory Figure 6-41 The principal Win32 API functions for directory management The second column gives the nearest UNIX equivalent, when one exists CuuDuongThanCong.com https://fb.com/tailieudientucntt Standard MS-DOS information File name name Security Data MFT entry for one file MFT header Master file table Figure 6-42 The Windows NT master file table CuuDuongThanCong.com https://fb.com/tailieudientucntt A A A A Original process A Children of A A Grandchildren of A Figure 6-43 A process tree in UNIX CuuDuongThanCong.com https://fb.com/tailieudientucntt Thread call pthread create pthread exit pthread join pthread mutex init pthread mutex destroy pthread mutex lock pthread mutex unlock pthread cond init pthread cond destroy pthread cond wait pthread cond signal Meaning Create a new thread in the caller’s address space Terminate the calling thread Wait for a thread to terminate Create a new mutex Destroy a mutex Lock a mutex Unlock a mutex Create a condition variable Destroy a condition variable Wait on a condition variable Release one thread waiting on a condition variable Figure 6-44 The principal POSIX thread calls CuuDuongThanCong.com https://fb.com/tailieudientucntt .. .Level Operating system machine level Operating system Level Instruction set architecture level Microprogram or hardware Level Microarchitecture level Figure 6- 1 Positioning of the operating system. .. memory 32 768 – 368 63 Page frame Physical addresses 2 867 2 – 32 767 2 867 2 – 32 767 245 76 – 2 867 1 245 76 – 2 867 1 20480 – 24575 20480 – 24575 163 84 – 20479 163 84 – 20479 12288 – 163 83 12288 – 163 83 8192... CuuDuongThanCong .com https://fb .com/ tailieudientucntt Page Virtual addresses 15 61 440 – 65 535 14 57344 – 61 439 13 53248 – 57343 12 49152 – 53247 11 450 56 – 49151 10 40 960 – 45055 368 64 – 40959 Bottom