1 / 18

CS140 Project 1: Threads

CS140 Project 1: Threads. Slides by Kiyoshi Shikuma. Overview. Quick Review Threads Scheduling Synchronization Project Pintos Alarm Clock Priority Scheduling Advanced Scheduler. Quick Review: Threads. Threads are an execution stream Execution Context: Current location in program

ura
Download Presentation

CS140 Project 1: Threads

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS140 Project 1: Threads Slides by Kiyoshi Shikuma

  2. Overview Quick Review Threads Scheduling Synchronization Project Pintos Alarm Clock Priority Scheduling Advanced Scheduler

  3. Quick Review: Threads Threads are an execution stream Execution Context: Current location in program Values of Variables All maintained on thread’s stack Pintos: Struct thread { name ID stack pointer page directory etc. } This struct is defined in thread.h (a very useful file for this project)

  4. Quick Review: Scheduling New terminated admitted interrupt Exit Ready Running scheduled I/O or Event completion I/O Event or wait Waiting

  5. Quick Review: Scheduling cont’d Scheduling Policy FIFO Round Robin Priority Preemption (Remove the “running” thread and schedule a new one) Timer Interrupt Device Interrupt (i.e. network, disk, etc)

  6. Quick Review: Thread Scheduling Thread A ___________ ________ Thread B ______ _____ _____ Kernel __ __ __ __ Wait on I/O Timer Interrupt

  7. Quick Background: Synchronization Will be covered in lecture next week Synchronization used to prevent race conditions, avoid concurrency problems One way to avoid synchronization issues is turn off interrupts (only one thing running so no issues), but don’t want to do this Better solution: Use synchronization primitives Locks Semaphores Condition Variables You will probably be modifying synch.h/c

  8. Project: Pintos Simple OS created by Ben Pfaff Could run on x86 hardware but we are using emulators (makes debugging and running easier) Bochs Qemu For Threads project you will be (surprise!) working in the threads directory. Alarm Clock will require modification of timer.c in the devices folder but you shouldn’t need to modify any other files outside threads

  9. Project: Getting Started • Follow website instructions to install and set the path variable (suggest adding to .cshrc so you don’t have to set every time) • To build run “make” in pintos/src/threads • To run tests run “make check” in pintos/src/threads/build • 7/27 tests should pass when you first download and run • “pintos” script simplifies usage of simulators: • i.e. “pintos –v -- -q run alarm-single” • Follow instructions to use two terminals to use GDB on pintos • Printf debugging is good too

  10. Project: Alarm Clock Function: void timer_sleep (int64_t ticks) You will be modifying this function in timer.c Currently busy waits Need to instead put thread to sleep and wake it up when enough time has elapsed Notice that testing suite already passes (most) of the alarm clock tests, so make sure your implementation is correct.

  11. Project: Priority Scheduling Each thread is assigned one of 64 priorities. Current implementation uses a round robin scheduler Change this to instead schedule the highest priority thread that can run (Useful file is thread.h/c)

  12. Project Priority Scheduling • Need to consider all cases: • When scheduling the next thread, choose one with highest priority • A thread lowers its priority (should yield if there is a higher-priority thread in the ready list) • A higher priority thread wakes up (such as alarm clock or after waiting on a lock/semaphore) it should preempt the lower priority thread. • Etc.

  13. Project: Priority Donation • Problem: Priority Inversion • L acquires a lock • H becomes ready, preempts L and starts running • M becomes ready • H waits for the lock held by L • M starts running • M runs, then L, then H • After H begins waiting on the lock, L should run (until it releases lock), then H, then M

  14. Project: Priority Donation cont’d • Solution: Priority Donation • When H starts waiting on the lock L is holding, it “donates” its priority to L such that L now runs with H’s priority • When L releases the lock, it reverts back to its original priority • Nested Donations: H->M->L • Multiple Donations: H->L <-M

  15. Project: Advanced Scheduler BSD Scheduler (Read doc linked on site) Attempts to reduce the average response time of jobs Calculates statistics during thread execution and sets priorities based on these Does NOT do priority donation

  16. Design Document • Template is on website • Start early (don’t wait until you’re done coding to write this) • Thinking through the questions will help you guide your coding • Do NOT skimp on this, it is worth just as much as the code

  17. Project: Submission • Save design doc as DESIGNDOC in threads directory (no extension) • Run “make grade” • Copy build/grade to GRADE in threads directory • Run “make clean” • Run “/usr/class/cs140/bin/submit 1” • Submission instructions here

  18. Some Advice: Start early Read through the (relevant) docs and code first (it’s very well documented) Think about design before you start coding Meet often as a group to integrate (don’t wait until the last second) Maintain good consistent coding style

More Related