CSE451 – Section 6.

Slides:



Advertisements
Similar presentations
1 Operating Systems, 122 Practical Session 5, Synchronization 1.
Advertisements

CSE 451: Operating Systems Section 6 Project 2b; Midterm Review.
CSE 451: Operating Systems
1 CSE451 Section 3. 2 Reminders Start project 2! It’s long Read the assignment carefully Read it again Project 2 will be done in groups of 3 Today: Form.
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.
CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.
1 Reminders Start project 2! It’s long Read the assignment carefully Read it again Project 2 will be done in groups of 3 groups to me Part 1 due.
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.
1 Reminders Start project 2! It’s long Read the assignment carefully Read it again Make sure your groups are correct Today: Project 2 intro CVS.
CSE451 Section 6: Spring 2006 Web server & preemption.
Wk 2 – Scheduling 1 CS502 Spring 2006 Scheduling The art and science of allocating the CPU and other resources to processes.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
Discussion Week 3 TA: Kyle Dewey. Overview Concurrency overview Synchronization primitives Semaphores Locks Conditions Project #1.
Nachos Phase 1 Code -Hints and Comments
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
Introduction to Threads CS240 Programming in C. Introduction to Threads A thread is a path execution By default, a C/C++ program has one thread called.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
CS333 Intro to Operating Systems Jonathan Walpole.
Kernel Locking Techniques by Robert Love presented by Scott Price.
Discussion Week 2 TA: Kyle Dewey. Overview Concurrency Process level Thread level MIPS - switch.s Project #1.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
For a good summary, visit:
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.
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,
CSE 451: Operating Systems Section 4 Project 2 Intro; Threads.
SE3910 Week 8, Class 3 Week 4 Lab: Please return your graded Lab 4 to me so I can enter it in my gradebook Week 9 Lab: Individual demos of working sub-modules.
CSE 451 Section #3. Questions from Lecture Kinds of threads When threads are used How threads are implemented Scheduling.
REAL-TIME OPERATING SYSTEMS
Homework Assignment #2 J. H. Wang Oct. 25, 2016.
CSE 120 Principles of Operating
CS 6560: Operating Systems Design
CS703 – Advanced Operating Systems
Advanced Topics in Concurrency and Reactive Programming: Asynchronous Programming Majeed Kassis.
Preemption Set timer interrupts But now, must synchronize Two tools:
Processes and Threads Processes and their scheduling
January 29, 2004 Adrienne Noble
CS399 New Beginnings Jonathan Walpole.
Winter 2k7 Kurtis Heimerl Aaron Kimball
Threading and Project 2 (Some slides taken from Sec. 3 Winter 2006)
Lecture 21 Concurrency Introduction
Operating Systems ECE344 Lecture 4: Threads Ding Yuan.
Reminders Form groups of 3 by tomorrow Start project 2! Today:
CSCI1600: Embedded and Real Time Software
Jonathan Walpole Computer Science Portland State University
UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department
Lecture 2 Part 2 Process Synchronization
Chapter 30 Condition Variables
CSE 451 Autumn 2003 Section 3 October 16.
CSE451 – Section 5.
Jonathan Walpole Computer Science Portland State University
CSCI1600: Embedded and Real Time Software
Processes and operating systems
First slide Rest of project 2 due next Friday Today:
Reminders Homework 4 due next Friday Rest of project 2 due next Friday
Why Threads Are A Bad Idea (for most purposes)
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
CSE 153 Design of Operating Systems Winter 19
CSE 153 Design of Operating Systems Winter 2019
CS333 Intro to Operating Systems
Project 2, part 4 - web server
Slide design: Dr. Mark L. Hornick
CSE 451 Section 1/27/2000.
Why Threads Are A Bad Idea (for most purposes)
Why Threads Are A Bad Idea (for most purposes)
Welcome to the world of concurrency!
Threads CSE 2431: Introduction to Operating Systems
Presentation transcript:

CSE451 – Section 6

Project 2, part 4 - web server web/sioux.c – singlethreaded web server Read in command line args, run the web server loop web/sioux_run.c – the webserver loop Open a socket to listen for connections (listen) Wait for a connection (accept) Handle it Parse the HTTP request Find and read the requested file (www root is ./docs) Send the file back Close the connection web/web_queue.c – an empty file for your use

A peek at the code… In web/sioux.c is main: In web/sioux_run.c: int main(int argc, char **argv) { int port; const char *host; const char *docroot; sthread_init(); /* Get the configuration information */ host = web_gethostname(); port = web_getport(); docroot = web_getdocroot(); /* Tell the user where to look for server */ web_printurl(host, port); /* Handle requests forever */ web_runloop(host, port, docroot); return 0; } void web_runloop(const char *host, int port, const char *docroot) { int listen_socket, next_conn; listen_socket = web_setup_socket(port); while ((next_conn = web_next_connection(listen_socket)) >= 0) { web_handle_connection(next_conn, docroot); } close(listen_socket);

What you need to do Make the web server multithreaded Create a thread pool A bunch of threads waiting for work Number of threads = command-line arg Wait for a connection Find an available thread to handle connection Current request waits if all threads busy Once a thread grabs onto connection, it uses the same processing code as before.

What to change? You’ll need a queue (web_queue.c) void web_runloop(const char *host, int port, const char *docroot) { int listen_socket, next_conn; listen_socket = web_setup_socket(port); //create a queue of waiting connections //create a bunch of threads to handle connections while ((next_conn = web_next_connection(listen_socket)) >= 0) { //add connection to queue //wake-up a thread to handle connection //yield to awoken thread } …. You’ll need a queue (web_queue.c) What about critical sections? What shared/global data structures are there? How do I protect them? Cond-vars are good ways to “wake-up” a thread…hint hint

Hints Each connection is identified by a socket returned by accept Which is just an int Simple management of connections among threads Threads should sleep while waiting for a new connection Condition variables are perfect for this Don’t forget to protect any global variables Use part 2 mutexes, CVs Develop + test with pthreads initially Mostly modify sioux_run.c and/or your own files Stick to the sthread.h interface!

Part 5 - Preemption Requires a relatively small amount of code, but tough to get 100% right 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 What we give you: Timer interrupts Primitives to turn interrupts on and off Synch primitives atomic_test_and_set, atomic_clear WARNING: The code that we have provided to support preemption works correctly only on the x86 architecture! Do not attempt this portion of the assignment on a Mac or other non-x86 architecture!

What we give you: sthread_preempt.h (implemented in .c): /* start preemption - func will be called every period microseconds */ void sthread_preemption_init(sthread_ctx_start_func_t func, int period); /* Turns inturrupts ON and off * Returns the last state of the inturrupts * LOW = inturrupts ON * HIGH = inturrupts OFF */ int splx(int splval); /* * 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);

What to do? Add a call to sthread_preemption_init as the last line in your sthread_user_init() function. init specifies a function that is called on each timer interrupt (done for you!) This func should cause thread scheduler to switch to a different thread Hard part: add synchronization to thread management routines Where are the critical sections from part 1 and 2?

Preemption + Critical Sections Safest way: disable interrupts before critical sections Example: Where is the critical section? Why? NON-threadsafe soln threadsafe soln /*returns the 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; } 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; }

Part 6 – Report Design discussion & functionality Results Make it short Results Run a few experiments with the new webserver Use given web benchmark: /cse451/projects/webclient Present results in a graphical easy-to-understand form. Explain Are the results what you expected? Try to justify any discrepancies you see Answer a few of our questions

Real-time scheduling Tasks usually accompany deadlines You can’t naively hop from task to task What happens when you violate deadline? Get penalty Real-time system Hard real-time system Once you miss the deadline, system fails Soft real-time system The quality of your task degrades However, soft/hard boundaries can be changed by requirement

Real-time tasks Periodic task Aperiodic task Must be completed within periodic deadline Regular task Aperiodic task Must be completed within a specific deadline Example real-time task & deadline Hard – periodic Giving insulin to glycosuria patient Hard – aperiodic Course project, breaking your car before collision Soft – periodic Decoding multi-media stream (MPEG) Soft – aperiodic Course project: if you don’t care about your grade 

Real-time scheduling Earliest Deadline First Rate monotonic Greedy approach What you do to survive throughout quarter Guarantees to schedule up to 100% CPU utilization Theoratically Preemptive vs. non-preemptive EDF Rate monotonic Static priorities shorter period/deadline gets higher priority Deadline is exactly the same as period No resource sharing between other processes Guarantees to schedule up to n(2^(1/2)-1) utilization N = number of processes U is about 82% when n=2. About 69% when n=inf. Used in real-time operating systems

Scheduling Assume following tasks Utilization Can EDF schedule them? P1: takes 1 unit time. Period is 10 P2: takes 4 unit time. Period is 9 P3: takes 3 unit time. Period is 13 Utilization 1/10 + 4/9 + 3/13 = 0.7753 Can EDF schedule them? Yes Can rate monotonic schedule them? The limit for 3 processes = 0.779763