================== Start of Lecture 5 ====================== Threads Lightweight process Unit of execution stack, registers, etc SHARES the data space with other threads in its TASK SHARES OS state like open files signals Plan 9 is more flexible, might not share these things. (ordinary, heavyweight) process is task+thread But can have many threads inside a task Faster to context switch to a peer thread than to another process. But it is still too slow for some cases Do not have to change memory map But do have to change protection domain twice user --> kernel --> user User mode threads are faster still Can have both kernel and user mode threads Want multiple kernel aware threads since many syscalls can be blocked HOMEWORK 4.5, 4.6 4.7 Interprocess communication (IPC) Message passing Send and receive Can have sender and receiver name the other process Can have sender name the received and receiver be told who sent Can use mailbox Buffering (sync vs async) Zero buffering (an important case) Synchronous semantics Rendezvous Unbuffered (Nonzero) buffering Send does not block unless capacity exceeded Async semantics What to do if capacity exceeded? Block send pretend infinite (throw some away) What to do if issue receive and no msg? Block receive Have receive return a failure msg Permit multiple receipients/mailboxes to be specified Lost/Garbled msgs Perhaps OK for OS to permit this (end-to-end checking) Can detect with acks and timeouts ---------------- The details begin ---------------- Chapter 5 CPU Scheduling Multiprogramming used to permit CPU / I/O overlap Short-Term CPU Scheduler (aka scheduler) Ready Q (might not be FIFO) Items on the Q are PCB Preemptive vs Non-preemptive Without preemption large cpu job can delay every job Sometimes preemption is not safe We saw this before (shared variable) Another question is if the OS itself is preemptable That is, can a syscall be interrupted What if OS working on a process and a higher prio proc becomes ready? Most OS's disable interrupts for some periods (hopefully short and bounded) HOMEWORK 5.2 The scheduler DECIDES which process to switch to. It implements policy. HOMEWORK 5.1 The dispatcher does the switching It implements a mechanism. Scheduling Criteria Contradictory CPU Utilization Really not the right criterion but often used It is good for telling you if you are CPU limited. Throughput Jobs per hour Need to fix a job-mix (workload) to compare sched policies Turnaround time Not the same as throughput Consider running short jobs first Waiting time (in ready Q) Poor criterion to use as figure of merit. System is good if wait is small. Does not matter where you wait. Response time Time to first response not end of output Predictable is good. DTSS Low variance good Max delay vs avg delay real time Algorithms FCFS--First Come First Served Sometimes considered to be no scheduling The simplist Non-preemptive SJF--Shortest Job First Aka SPN--Shortest Process Next Really means shortest "next CPU burst" first Consider case where each job has only one burst SJF has minimum waiting time If also assume that output STARTS right after burst, then it has the min response time as well. When you permit many bursts/process, this still is true but words are harder Difficulty is knowing the "next CPU burst" Can approx (guess) that it is the last burst Can use a waited avg of last n bursts Normally considered Non-preemptive (but not always) Preemptive variant is when you let new processes or newly unblocked processes to preempt the current process An "old" process cannot be eligible to preempt current, why? Called PSJF or PSPN or SRTF (shortest remaining time first) Can starve jobs with long bursts Priority Scheduling Generalization of SJF Preemptive or non-preemptive again depends on newly arriving or unblocked processes again has potential starvation priority aging internal or external (or both) priorities ================ End Lecture 5 ================