CSE 451: Operating Systems Section 6 Project 2b; Midterm Review.

Slides:



Advertisements
Similar presentations
Operating Systems ECE344 Midterm review Ding Yuan
Advertisements

More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
CAS3SH3 Midterm Review. The midterm 50 min, Friday, Feb 27 th Materials through CPU scheduling closed book, closed note Types of questions: True & False,
Chapter 6: Process Synchronization
1 CS318 Project #3 Preemptive Kernel. 2 Continuing from Project 2 Project 2 involved: Context Switch Stack Manipulation Saving State Moving between threads,
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
1 CSE451 – Section 5. 2 Reminders/Overview Rest of project 2 due Monday February 13 Turnin code + writeup Midterm Wednesday the 8th Today: Project 2 parts.
Threads 1 CS502 Spring 2006 Threads CS-502 Spring 2006.
CPS110: Implementing threads/locks on a uni-processor Landon Cox.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
CSE 451: Operating Systems Section 5: Synchronization.
Discussion Week 3 TA: Kyle Dewey. Overview Concurrency overview Synchronization primitives Semaphores Locks Conditions Project #1.
CS252: Systems Programming Ninghui Li Final Exam Review.
Cosc 4740 Chapter 6, Part 3 Process Synchronization.
Recitation 9: Section L (1:30pm - 2:20pm) Monday, October 22, 2012 Processes, Signals and Shell Lab Siddharth Dhulipalla.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
30 October Agenda for Today Introduction and purpose of the course Introduction and purpose of the course Organization of a computer system Organization.
CSE 451: Operating Systems Section 5 Midterm review.
Lecture 8 Page 1 CS 111 Online Other Important Synchronization Primitives Semaphores Mutexes Monitors.
CPS110: Implementing threads Landon Cox. Recap and looking ahead Hardware OS Applications Where we’ve been Where we’re going.
1 CSE451 Architectural Supports for Operating Systems Autumn 2002 Gary Kimura Lecture #2 October 2, 2002.
Discussion Week 2 TA: Kyle Dewey. Overview Concurrency Process level Thread level MIPS - switch.s Project #1.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
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.
CSE 451: Operating Systems Section 5 Synchronization.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
What is an Operating System? Various systems and their pros and cons –E.g. multi-tasking vs. Batch OS definitions –Resource allocator –Control program.
Managing Processors Jeff Chase Duke University. The story so far: protected CPU mode user mode kernel mode kernel “top half” kernel “bottom half” (interrupt.
Operating Systems CMPSC 473 Signals, Introduction to mutual exclusion September 28, Lecture 9 Instructor: Bhuvan Urgaonkar.
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
CSE 451: Operating Systems Section 7: Project 2b; Virtual Memory.
1 Lecture 19: Unix signals and Terminal management n what is a signal n signal handling u kernel u user n signal generation n signal example usage n terminal.
CSE 451: Operating Systems Section 6 Project 2b. Midterm  Scores will be on Catalyst and midterms were handed back on Friday(?) in class  Talk to Ed,
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
CPS110: Implementing threads on a uni-processor Landon Cox January 29, 2008.
Process Synchronization. Concurrency Definition: Two or more processes execute concurrently when they execute different activities on different devices.
1 Section 5 Synchronization primitives (Many slides taken from Winter 2006)
Processes and threads.
CSE 120 Principles of Operating
Operating Systems CMPSC 473
CS 6560: Operating Systems Design
CS703 – Advanced Operating Systems
Preemption Set timer interrupts But now, must synchronize Two tools:
Outline Other synchronization primitives
Winter 2k7 Kurtis Heimerl Aaron Kimball
Other Important Synchronization Primitives
Operating Systems ECE344 Lecture 4: Threads Ding Yuan.
Midterm review: closed book multiple choice chapters 1 to 9
CSE451 – Section 6.
Lecture 2 Part 2 Process Synchronization
CSE 451 Autumn 2003 Section 3 October 16.
Threads Chapter 5 2/17/2019 B.Ramamurthy.
CSE451 – Section 5.
Operating Systems Lecture 1.
Major Topics in Operating Systems
Threads Chapter 5 2/23/2019 B.Ramamurthy.
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
First slide Rest of project 2 due next Friday Today:
February 5, 2004 Adrienne Noble
Reminders Homework 4 due next Friday Rest of project 2 due next Friday
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
CS333 Intro to Operating Systems
Project 2, part 4 - web server
CSE 451 Section 1/27/2000.
CS703 – Advanced Operating Systems
CSE 153 Design of Operating Systems Winter 2019
Threads CSE 2431: Introduction to Operating Systems
Presentation transcript:

CSE 451: Operating Systems Section 6 Project 2b; Midterm Review

Project 2b  Parts 4, 5 and 6 of project 2  Due at 11:59pm, Wednesday November 17 11/4/102

Part 4: web server  web/sioux.c – singlethreaded web server  Read in command line args, run the web server loop 11/4/103

Part 4: web server  web/sioux_run.c – the web server loop  Open a socket to listen for connections ( listen(2) )  Wait for a connection ( accept(2) )  Handle connection:  Parse the HTTP request  Find and read the requested file  Send the file back  Close the connection 11/4/104

Thread pools Image from More info: 11/4/105

What you need to do  Make the web server multithreaded  Create a thread pool  Suggestion: create separate thread_pool.h, thread_pool.c  Wait for a connection  Find an available thread to handle the request  Request waits (where?) if all threads busy  Once the request is handed to a thread, it uses the same processing code as before 11/4/106

Hints  Each connection is identified by a socket file descriptor returned by accept(2)  File descriptor (fd) is just an int  Threads should sleep while waiting for a new connection  Condition variables are perfect for this 11/4/107

Hints  Don’t forget to protect any global variables  Use mutexes and CVs from part 2  Develop and test with pthreads initially  Use only the sthread.h interface  Mostly modify sioux_run.c, and your own files 11/4/108

Part 5: preemption  What we give you:  Timer interrupts  Function to turn interrupts on and off  Synchronization primitives atomic_test_and_set, atomic_clear  x86 architecture only 11/4/109

Part 5: preemption  What you have to do:  Add code that will run every time a timer interrupt is generated  Add synchronization to your part 1 and part 2 implementations so that everything works with preemptive thread scheduling  Can be done independently of part 4 11/4/1010

sthread_preempt.h /* Start preemption - func will be called * every period microseconds */ void sthread_preemption_init (sthread_ctx_start_func_t func, int period); /* Turns interrupts on (LOW) or off (HIGH) * Returns the last state of the * interrupts */ int splx(int splval); 11/4/1011

sthread_preempt.h /* atomic_test_and_set - using the native * compare and exchange on the Intel x86. * * Example usage: * lock_t lock; * while(atomic_test_and_set(&lock)) * {} // spin * _critical section_ * atomic_clear(&lock); */ int atomic_test_and_set(lock_t *l); void atomic_clear(lock_t *l); 11/4/1012

Signals  Used to notify processes of events, asynchronously  Every process has a signal handler table  When a signal is sent to a process, OS interrupts that process and calls the handler registered for that signal 11/4/1013

Signal manipulation  A process can:  Override the default signal handlers using sigaction(2)  Block / unblock signals with sigprocmask(2)  Send a signal via kill(2)  Signals:  SIGINT (CTRL-C), SIGQUIT (CTRL-\), SIGKILL, SIGFPE, SIGALRM, SIGSEGV… 11/4/1014

What you need to do  Add a call to sthread_preemption_init() as the last line in your sthread_user_init() function  sthread_preemption_init() takes a pointer to a function that will be called on each timer interrupt  This function should cause thread scheduler to switch to a different thread! 11/4/1015

What you need to do  Add synchronization to critical sections in thread management routines  Think: what would happen if the code was interrupted at this point?  Would it resume later with no problems?  Could the interrupting code mess with any variables that this code is currently using?  Don’t have to worry about simplethreads code that you didn’t write (i.e. sthread_switch): already done for you 11/4/1016

Interrupt disabling Non-thread-safe /* returns next thread * on the ready queue */ sthread_t sthread_user_next() { sthread_t next; next = sthread_dequeue (ready_q); if (next == NULL) exit(0); return next; } Thread-safe sthread_t sthread_user_next() { sthread_t next; int old = splx (HIGH); next = sthread_dequeue (ready_q); splx (old); if (next == NULL) exit(0); return next; } 11/4/1017

Atomic locking  So what is atomic_test_and_set() for?  Primarily to implement higher-level synchronization primitives (mutexes, CVs)  One way to think about preemption-safe thread library:  Disable/enable interrupts in “library” context  Use atomic locking in “application” context 11/4/1018

Race conditions and testing  How can you test your preemption code?  How can you know that you’ve found all of the critical sections? 11/4/1019

Part 6: report  Covers all parts of project 2  Discuss your design decisions  Performance evaluation:  Measure throughput and response time of your web server using web benchmarking tool  Vary the number of threads and number of “clients”  Present results in graphical form  Explain results: expected or not? 11/4/1020

Project 2 questions? 11/4/1021

Midterm  Concepts to know: 11/4/1022

The kernel  Kernel mode vs user mode  How these modes differ conceptually and from the CPU's point of view  How we switch between the two  Interrupts 11/4/1023

System calls  What they are  What they do  How they do it  What hardware is involved  Who uses them and when 11/4/1024

Processes and threads  Kernel processes, kernel threads, and user threads  How these differ from one another  Context switching  Process and thread states  fork, exec, wait 11/4/1025

Scheduling  Different scheduling algorithms and their tradeoffs  Average response time, various “laws”  Starvation  Cooperative vs. preemptive scheduling 11/4/1026

Synchronization  Critical sections  Locks and atomic instructions  Mutexes, semaphores, and condition variables  Monitors  Ways to detect / avoid deadlock 11/4/1027

Memory management  Paging  Segmentation  Address translation  Page tables  Page replacement 11/4/1028

Tips  Focus on lecture slides  Review textbook, section slides and project writeups to emphasize key concepts and fill in gaps  On Friday:  Arrive early  Focus on key points  Work quickly; finish easy problems first 11/4/1029

11/4/1030

Semaphores vs. CVs Semaphores  Used in apps  wait() does not always block the caller  signal() either releases a blocked thread, if any, or increases semaphore counter Condition variables  Typically used in monitors  wait() always blocks caller  signal() either releases a blocked thread, if any, or the signal is lost forever 11/4/1031