CS140 Project Session Notes #1: Threads Haobo Xu, TA Fall 2006-07 Based on Ben Sapp’s slides Download these slides from

Slides:



Advertisements
Similar presentations
Real-Time Library: RTX
Advertisements

Pintos: Threads Project Slides by: Vijay Kumar Updated by Godmar Back Presented by: Min Li.
Pintos: Threads Project Slides by: Vijay Kumar Updated by Godmar Back.
 A quantum is the amount of time a thread gets to run before Windows checks.  Length: Windows 2000 / XP: 2 clock intervals Windows Server systems: 12.
1 CS318 Project #3 Preemptive Kernel. 2 Continuing from Project 2 Project 2 involved: Context Switch Stack Manipulation Saving State Moving between threads,
Project 2 – solution code
Introduction to Operating Systems – Windows process and thread management In this lecture we will cover Threads and processes in Windows Thread priority.
Synchronization Principles. Race Conditions Race Conditions: An Example spooler directory out in 4 7 somefile.txt list.c scores.txt Process.
Cs238 CPU Scheduling Dr. Alan R. Davis. CPU Scheduling The objective of multiprogramming is to have some process running at all times, to maximize CPU.
CS533 Concepts of Operating Systems Class 7 Integrated Task and Stack Management.
Preemptive Minithreads Tom Roeder CS sp. Multi-level Feedback Queues Quantum = 2 Quantum = 4 Quantum = 8 Quantum = 16 Lowest priority Highest priority.
CS533 Concepts of Operating Systems Class 3 Monitors.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
1 Advanced Computer Programming Concurrency Multithreaded Programs Copyright © Texas Education Agency, 2013.
Nachos Phase 1 Code -Hints and Comments
CS1550 Assignment 5 Multiprogramming Implementation notes Matt Craven.
1 Previous lecture review n Out of basic scheduling techniques none is a clear winner: u FCFS - simple but unfair u RR - more overhead than FCFS may not.
Not Another Completely Heuristic Operating System
Scheduling Basic scheduling policies, for OS schedulers (threads, tasks, processes) or thread library schedulers Review of Context Switching overheads.
Chapter 11 Heap. Overview ● The heap is a special type of binary tree. ● It may be used either as a priority queue or as a tool for sorting.
CE Operating Systems Lecture 11 Windows – Object manager and process management.
Java Threads. What is a Thread? A thread can be loosely defined as a separate stream of execution that takes place simultaneously with and independently.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
1 Review of Process Mechanisms. 2 Scheduling: Policy and Mechanism Scheduling policy answers the question: Which process/thread, among all those ready.
Pintos: Threads Project
CS140 Project 1: Threads Slides by Kiyoshi Shikuma.
ECGR-6185 µC/OS II Nayana Rao University of North Carolina at Charlotte.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
CSC 322 Operating Systems Concepts Lecture - 7: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
Practice Chapter Five.
Lecture 12 Page 1 CS 111 Online Using Devices and Their Drivers Practical use issues Achieving good performance in driver use.
Managing Processors Jeff Chase Duke University. The story so far: protected CPU mode user mode kernel mode kernel “top half” kernel “bottom half” (interrupt.
CS333 Intro to Operating Systems Jonathan Walpole.
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
Nachos Project 2 Lecturer: Hao-Hua Chu TA: Chun-Po Wang (Artoo) Date: 2008/10/14 Material Provided by Yuan-Hao Chang, Yung-Feng Lu.
Tutorial 3: Homework 2 and Project 2
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Operating System Examples - Scheduling. References r er/ch10.html r bangalore.org/blug/meetings/200401/scheduler-
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Mutual Exclusion Mutexes, Semaphores.
Threads prepared and instructed by Shmuel Wimer Eng. Faculty, Bar-Ilan University 1July 2016Processes.
Tutorial 2: Homework 1 and Project 1
Jim Fawcett CSE 691 – Software Modeling and Analysis Fall 2000
REAL-TIME OPERATING SYSTEMS
CS 6560: Operating Systems Design
Topics Covered What is Real Time Operating System (RTOS)
Chapter 5a: CPU Scheduling
Project 2: Preemption CS 4411 Spring 2017
January 29, 2004 Adrienne Noble
Christo Wilson Project 1: Threads in Pintos
Other Important Synchronization Primitives
Chapter 6: CPU Scheduling
Pintos: Threads Project
A Comparison Study of Process Scheduling in FreeBSD, Linux and Win2k
An Embedded Software Primer
Nachos Assignment#2 Priority Scheduling.
Chapter 2: The Linux System Part 3
Scheduling.
Lecture 2 Part 2 Process Synchronization
CPU scheduling decisions may take place when a process:
Coordination Lecture 5.
Implementing Mutual Exclusion
CS703 – Advanced Operating Systems
CS333 Intro to Operating Systems
Pintos: Threads Project
CS703 – Advanced Operating Systems
CSE 153 Design of Operating Systems Winter 2019
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

CS140 Project Session Notes #1: Threads Haobo Xu, TA Fall Based on Ben Sapp’s slides Download these slides from

Overview ● Getting Started ● Alarm Clock ● Priority Scheduling ● Advanced Scheduler (MLFQS) Ask questions anytime

Getting Started ● Make sure Pintos is up and running – set path = (/usr/class/cs140/`uname -m`/bin $path) – zcat /usr/class/cs140/pintos/pintos.tar.gz | tar x – cd pintos/src/threads/ – make – cd build/ – pintos run alarm-multiple ● Do this on either the Solaris (elaine) or Linux (vine) machines in Sweet Hall

Thread System Overview 4 kB | kernel stack | | | | | V | | grows downward | | | | magic | | : | | status | | tid | 0 kB scheduler timer ready list wait list for keyboard... wait list for hard drive... wait list for some lock... cpu...

Alarm Clock ● reimplement timer_sleep() in devices/timer.c to avoid busy waiting: ● instead, take thread off the ready list /* Suspends execution for approximately TICKS timer ticks. */ void timer_sleep (int64_t ticks){ int64_t start = timer_ticks (); ASSERT (intr_get_level () == INTR_ON); while (timer_elapsed (start) < ticks) thread_yield (); }

Priority Scheduling ● Implement: (a)If a thread is added to the ready list which has a higher priority than the currently running thread, immediately yield the processor to the new thread. (b)Also, when threads are waiting for a lock, semaphore, or condition variable, the highest priority waiting thread should be woken up first. ● How? (a) Check priority whenever adding to the ready list (as in thread_create() ) and choosing next thread to run ( next_thread_to_run()). (b) Each sema, lock, etc. keeps track of the threads that are associated with it...need to check their priority when the lock is released.

Priority Inversion Problem ● But there's a problem – Let's say a high priority thread H needs a lock held by a low priority thread L – H must wait until L runs so L can release its lock. – But L must defer to all higher priorities, so it must wait its turn to run. – In turn, H must wait for all lower priority threads to run before it can run again. – This is bad. H should run first.

Priority Donation Solution ● When a high priority thread waits on a lock held by a lower priority thread, donate the priority level of the high level thread to the low level thread. – Be sure to handle multiple donations, in which multiple priorities are donated to a single thread – Be sure to handle nested donations, e.g., H waits on M which waits on L...

Advanced Scheduler: Multi-Level Feedback Queue ● 64 ready queues, one for each priority ● scheduler chooses a thread from the highest-priority non-empty queue ● priority calculated using the cpu time used by a thread, and it's “niceness”: – priority = PRI_MAX - recent_cpu/4 - nice*2 ● see manual for formulas to calculate recent_cpu ● need to implement fixed point arithmetic library

Synchronization ● keep in mind that threads can be interrupted by other threads – use locks, semas and condition variables to make important updates to shared data ● but, interrupt handlers can't use locks (why?) – this means that you will have to disable interrupts for shared data used by an interrupt handler, i.e., when accessing thread variables, don't want timer interrupt to interfere.

Random Tips ● gdb/cvs: useful tools for the rest of your life – Check out the Debugging Tools section. – Check out the Development Tools section. ● use available data structures, especially list – helpful functions: insert, splice, pop/push front/back, end, begin, next, prev, size, list_empty, sort, max, min... ● read the manual (many times!) ● read the design document template!

Grading ● 50% automatic tests – no exceptions ● 50% design document – where the real grading happens – data structures, algorithms, synchronization, and rationale – coding standards: don't forget to indent and comment!

it's that easy... code to write: devices/timer.c | threads/fixed-point.h | threads/synch.c | threads/thread.c | threads/thread.h | files changed, 440 insertions(+), 29 deletions(-) questions?