CS140 Project 1: Threads - PowerPoint PPT Presentation

About This Presentation
Title:

CS140 Project 1: Threads

Description:

CS140 Project 1: Threads Slides by Kiyoshi Shikuma Project: Priority Donation cont d Solution: Priority Donation When H starts waiting on the lock L is holding, it ... – PowerPoint PPT presentation

Number of Views:91
Avg rating:3.0/5.0
Slides: 19
Provided by: k95195155
Category:
Tags: cs140 | project | threads

less

Transcript and Presenter's Notes

Title: CS140 Project 1: Threads


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 threads 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 contd
  • 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
Wait on I/O
  • Thread A ___________
    ________
  • Thread B ______
    _____ _____
  • Kernel __
    __ __ __

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 dont
    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 shouldnt 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 dont 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 contd
  • 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 Hs priority
  • When L releases the lock, it reverts back to its
    original priority
  • Nested Donations H-gtM-gtL
  • Multiple Donations H-gtL lt-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 (dont wait until youre 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
    (its very well documented)
  • Think about design before you start coding
  • Meet often as a group to integrate (dont wait
    until the last second)
  • Maintain good consistent coding style
Write a Comment
User Comments (0)
About PowerShow.com