progos ue
play

ProgOS UE Getting Introduction to Pintos Started Pintos Basics - PowerPoint PPT Presentation

ProgOS UE Introduction to Pintos ProgOS UE Getting Introduction to Pintos Started Pintos Basics Daniel Prokesch, Denise Ratasich Threads basierend auf Slides von Synchronization Benedikt Huber, Roland Kammerer, Bernhard Frmel User


  1. ProgOS UE Introduction to Pintos ProgOS UE Getting Introduction to Pintos Started Pintos Basics Daniel Prokesch, Denise Ratasich Threads basierend auf Slides von Synchronization Benedikt Huber, Roland Kammerer, Bernhard Frömel User Processes Memory Institut für Technische Informatik Manage- Technische Universität Wien ment - 182.710 Programmierung von Betriebssystemen UE File System SS16 Building 8. März 2016 Assignments Material 1/50

  2. # Runs in real mode, which i s a 16 − bit segment . ProgOS UE Introduction to . code16 Pintos # Set up segment registers . sub %ax , %ax mov %ax , %ds Getting mov %ax , %ss Started mov $0xf000 , %esp # Configure s e r i a l port so we can report progress w/o connected VGA. Pintos sub %dx , %dx # Serial port 0. Basics mov $0xe3 , %al # 9600 bps , N − 8 − 1. Threads int $0x14 # Destroys AX. c a l l puts Synchronization . string " PiLo " # Read the partition table on each system hard disk User mov $0x80 , %dl # Hard disk 0. Processes read_mbr : sub %ebx , %ebx # Sector 0. Memory mov $0x2000 , %ax # Use 0x20000 for buffer . Manage- mov %ax , %es ment c a l l read_sector jc no_such_drive File System # Print hd[a − z ] . Building c a l l puts . string " hd" Assignments mov %dl , %al add $ ’a ’ − 0x80 , %al Material c a l l putc 2/50

  3. ProgOS UE What is Pintos? Introduction to Pintos Getting Started Pintos ◮ Previous slide shows a code snippet from the x86 boot Basics loader ( threads/loader.S ) Threads ◮ (Un?)Fortunately, you do not need to write assembly Synchronization language code in this course :) User ◮ But you can read well-documented, working assembly Processes language code, if you like Memory ◮ Most of Pintos is written in C Manage- ment File System Building Assignments Material 3/50

  4. ProgOS UE What is Pintos? Introduction to Pintos Getting Started Pintos is an instructional operating system, Pintos ◮ running on simulated, emulated, and physical x86 , Basics ◮ code base small enough to be read and understood by a Threads single person (unlike e.g., Linux), Synchronization ◮ written in C (by Ben Pfaff), User ◮ emphasizing concepts and preferring simple Processes implementations, Memory Manage- ◮ encouraging test driven development , ment ◮ that you will extend and improve during this course File System Building Assignments Material 4/50

  5. ProgOS UE Outline Introduction to Pintos Getting Started Pintos ◮ Getting Started Basics ◮ Threads and Scheduling Threads ◮ Synchronization Synchronization ◮ User Programs User ◮ Memory Management Processes ◮ Pintos Build System Memory Manage- ◮ Assignments ment File System Building Assignments Material 5/50

  6. ProgOS UE Pintos Structure Introduction to Pintos Kernel Mode Tests System Call Layer Getting P0: Alarm Clock Tests Started P0: Process Arguments P2: Memory- Pintos P1: Scheduling Tests Process Mapped Basics Management Files Threads P2: Address Space Manager Synchronization P0: Alarm Clock Basic User Basic Filesystem Memory Manager P1: Priority Scheduler Processes Device Support Threading Keyboard, VGA, USB, Serial Port, Timer, PCI, Memory Basic Scheduling Support IDE Manage- ment Boot Support File System The Pintos Kernel Building Adapted from http://www.pintos-os.org/wp-content/files/SIGCSE2009-Pintos.pdf Assignments Figure : High-Level View on the Pintos Kernel Material 6/50

  7. ProgOS UE Setup Introduction to Pintos Getting ◮ Set PATH environment variable to include Started pintos-progos/utils Pintos ◮ The pintos command-line tool is used to start the Basics emulator with pintos Threads ◮ Synopsis: Synchronization pintos [OPTION..] -- [ARGUMENT..] User Processes ◮ Arguments before -- are passed to the pintos script ◮ Arguments after -- are passed to the pintos kernel Memory ◮ Supports different emulators Manage- ment ◮ Bochs ( --bochs ): Recommended for Project 1 ◮ QEMU ( --qemu ): Recommended for Project 2 and File System debugging Building Assignments Material 7/50

  8. ProgOS UE Running a kernel test Introduction to Pintos Getting Started ◮ Kernel tests are linked into the kernel Pintos ◮ You need to pass --kernel-test to pintos to run a Basics kernel test Threads ◮ Kernel tests may not access the file system Synchronization ◮ They are used for the Project 0 (alarm clock assignment) User Processes and Project 1 Memory cd pintos-progos/intro Manage- ment make pintos --bochs --kernel-test -- -q run alarm-single File System Building Assignments Material 8/50

  9. ProgOS UE Running a user program Introduction to Pintos Getting Started Pintos ◮ User programs are loaded from the (virtual) disk and Basics executed by the main kernel thread Threads ◮ You need to prepare the file system to run a user program Synchronization cd pintos-progos/intro User make Processes pintos --qemu --filesys-size=2 \ Memory -p tests/intro/userprog-args/args-none \ Manage- -a args-none -- -q -f run args-none ment File System Building Assignments Material 9/50

  10. ProgOS UE Paging Introduction to Pintos ◮ Pintos uses paging facilities of x86 ◮ Virtual memory is divided in pages, 4KByte each Getting ◮ Virtual memory address: page number + page offset Started ◮ Processor translates virtual address to physical address, Pintos consulting the page directory to find the right page table, Basics and the page table to find the physical address Threads Linear Address Synchronization 31 22 21 12 11 0 Directory Table Page Offset User Processes Physical Addr. 4-KByte Page Memory PTE Manage- Page Table ment PDE Page Directory File System Building CR3 Assignments Adapted from Intel's IA-32 Architectures Software Developer's Manual Material Figure : Paging 10/50

  11. ProgOS UE Threads Introduction to Pintos ◮ Pintos is multi-threaded; exactly one thread is running at each time ( thread_current() ). Getting ◮ Each thread is represented by one kernel page Started ◮ Thread page includes stack and additional data at the Pintos beginning of the page Basics Threads thread page T1 thread page T2 4Kb grows Synchronization downwards <stack> T1 <stack> T2 User esp Processes running thread Memory end of Manage- struct thread MAGIC MAGIC ment saved sp <data> T1 File System <data> T2 Building <tid> T1 <tid> T2 0 Kb Assignments Figure : Threads Material 11/50

  12. ProgOS UE Interrupts Introduction to Pintos Getting Started ◮ Interrupts notifies CPU of an event Pintos ◮ CPU saves context, then executes interrupt handler routine Basics ◮ Either internal (caused by the CPU itself) or external Threads ◮ Internal: “Belongs” to running thread, synchronized with Synchronization CPU instructions, interrupts should be enabled, nesting is possible. Examples: Page Fault, System Call. User ◮ External, such as Timer Interrupt: asynchronous w.r.t. Processes exection of CPU instructions, interrupts disabled, no Memory nesting Manage- ment ◮ Interrupt frames provide information on the CPU state File System before the interrupt Building Assignments Material 12/50

  13. ProgOS UE Lists ( lib/kernel/list.h ) Introduction to Pintos ◮ Doubly linked lists are ubiquitous in Pintos (e.g., semaphore wait queue) Getting ◮ List pointers need to be embedded in all structures which Started are potential members of a list (sharing possible) Pintos ◮ No need for dynamic memory allocation for list operations Basics Threads struct list thread_list; struct my_thread t Synchronization tid_t id; prev struct list_element User prev head next struct list_element 16 Processes wq_elem bytes next prev struct Memory list_element Manage- prev tail struct next ment list_element thread_list_elem next File System Building Assignments Figure : List Datastructure Material 13/50

  14. ProgOS UE Lists ( lib/kernel/list.h ) Introduction to Pintos struct list_elem Getting { Started struct list_elem *prev; /* Previous element. */ Pintos struct list_elem *next; /* Next list element. */ Basics }; struct list Threads { Synchronization struct list_elem head; /* List head. */ struct list_elem tail; /* List tail. */ User }; Processes Memory struct list all_threads; Manage- ment struct my_thread { File System tid_t tid; Building struct list_elem all_threads_elem; }; Assignments Material 14/50

  15. ProgOS UE List Operations (1) Introduction to Pintos Getting Started ◮ We need to use address arithmetic to obtain data of Pintos stored elements Basics ◮ The macro list_entry 1 calculates pointer to structure Threads embedding list pointers Synchronization for (e = list_begin (& all_blocks ) ; e != list_end (& all_blocks ) ; User e = list_next (e ) ) Processes { struct block ∗ block = list_entry (e , struct block , list_elem ) ; Memory i f ( ! strcmp (name, block − >name) ) Manage- return block ; ment } File System Building Assignments Material 1 cf. Linux, macro container_of 15/50

Recommend


More recommend