![]() ![]()
Unlike the loader, this code is actually part of the kernel. start.S: Does basic setup needed for memory protection and 32-bit operation on 80×86 CPUs. You should not need to look at this code or modify it. See section A.1.1 The Loader, for details. LAB SCHEDULING ROUND ROBIN WITH A TIMESLICE OF 4 TICKS PCAssembles to 512 bytes of code and data that the PC BIOS loads into memory and which in turn finds the kernel on disk, loads it into memory, and jumps to start() in start.S. You will not need to modify most of this code, but the hope is that presenting this overview will give you a start on what code to look at. Here is a brief overview of the files in the threads directory. Alternatives to stack allocation include the page allocator and the block allocator (see section A.5 Memory Allocation). ![]() You may cause bizarre problems, such as mysterious kernel panics, if you declare large data structures as non-static local variables, e.g. int buf. The kernel tries to detect stack overflow, but it cannot do so perfectly. Warning: In Pintos, each thread is assigned a small, fixed-size execution stack just under 4 kB in size. See section A.2.3 Thread Switching, for more information. You will understand the thread system once you understand why and how the switch_threads() that gets called is different from the switch_threads() that returns. You will notice that when one thread calls switch_threads(), another thread starts running, and the first thing the new thread does is to return from switch_threads(). (2) Be sure to keep track of each thread’s address and state, and what procedures are on the call stack for each thread. You can set a breakpoint on schedule() to start out, and then single-step from there. Using the GDB debugger, slowly trace through a context switch to see what happens (see section E.5 GDB). (You don’t have to understand it.) It saves the state of the currently running thread and restores the state of the thread we’re switching to. The mechanics of a context switch are in threads/switch.S, which is 80×86 assembly code. ![]() (If no thread is ready to run at any given time, then the special “idle” thread, implemented in idle(), runs.) Synchronization primitives can force context switches when one thread needs to wait for another thread to do something. The scheduler decides which thread to run next. Each thread, therefore, acts like a mini-program running inside Pintos, with the function passed to thread_create() acting like main().Īt any given time, exactly one thread runs and the rest, if any, become inactive. When the function returns, the thread terminates. The first time the thread is scheduled and runs, it starts from the beginning of that function and executes in that context. You provide a function to be run in this context as an argument to thread_create(). When a thread is created, you are creating a new context to be scheduled. You can also run the kernel in a debugger and set breakpoints at interesting spots, single-step through code and examine data, and so on. If you like, you can add calls to printf() almost anywhere, then recompile and run to see what happens and in what order. You can read through parts of the source code to see what’s going on. If you haven’t already compiled and run the base system, as described in the introduction (see section 1. Some of this code might seem slightly mysterious. Pintos already implements thread creation and thread completion, a simple scheduler to switch between threads, and synchronization primitives (semaphores, locks, condition variables, and optimization barriers). The first step is to read and understand the code for the initial thread system. 2.1 Background 2.1.1 Understanding Threads To complete this project you will also need to read B. You should at least skim the material from A.1 Loading through A.5 Memory Allocation, especially A.3 Synchronization. Compilation should be done in the threads directory.īefore you read the description of this project, you should read all of the following sections: 1. You will be working primarily in the threads directory for this assignment, with some work in the devices directory on the side. Your job is to extend the functionality of this system to gain a better understanding of synchronization problems. In this assignment, we give you a minimally functional thread system. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |