Tutorial 2: Homework 1 and Project 1

Slides:



Advertisements
Similar presentations
1 Friday, June 16, 2006 "In order to maintain secrecy, this posting will self-destruct in five seconds. Memorize it, then eat your computer." - Anonymous.
Advertisements

CPS110: Implementing threads/locks on a uni-processor Landon Cox.
Using Two Queues. Using Multiple Queues Suspended Processes Processor is faster than I/O so all processes could be waiting for I/O Processor is faster.
1 Race Conditions/Mutual Exclusion Segment of code of a process where a shared resource is accessed (changing global variables, writing files etc) is called.
General System Architecture and I/O.  I/O devices and the CPU can execute concurrently.  Each device controller is in charge of a particular device.
2.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Chapter 2: Computer-System Structures Computer System Operation I/O Structure.
CHAPTER 2: COMPUTER-SYSTEM STRUCTURES Computer system operation Computer system operation I/O structure I/O structure Storage structure Storage structure.
1 CSE Department MAITSandeep Tayal Computer-System Structures Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection.
2: Computer-System Structures
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Operating Systems CSE 411 Multi-processor Operating Systems Multi-processor Operating Systems Dec Lecture 30 Instructor: Bhuvan Urgaonkar.
Process by Dr. Amin Danial Asham. References Operating System Concepts ABRAHAM SILBERSCHATZ, PETER BAER GALVIN, and GREG GAGNE.
CPS110: Implementing threads Landon Cox. Recap and looking ahead Hardware OS Applications Where we’ve been Where we’re going.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 2 Computer-System Structures Slide 1 Chapter 2 Computer-System Structures.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Silberschatz, Galvin and Gagne  Applied Operating System Concepts Chapter 2: Computer-System Structures Computer System Architecture and Operation.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
1 Critical Section Problem CIS 450 Winter 2003 Professor Jinhua Guo.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
CPS110: Implementing threads on a uni-processor Landon Cox January 29, 2008.
1.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 1: Introduction What Operating Systems Do √ Computer-System Organization.
Threads prepared and instructed by Shmuel Wimer Eng. Faculty, Bar-Ilan University 1July 2016Processes.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Threaded Programming in Python
Chapter 2: Computer-System Structures(Hardware)
Chapter 2: Computer-System Structures
Processes and threads.
Process concept.
Process Management Process Concept Why only the global variables?
Chapter 3: Process Concept
Background on the need for Synchronization
Operating Systems (CS 340 D)
Practice Chapter Four.
Day 08 Processes.
Day 09 Processes.
Process Management Presented By Aditya Gupta Assistant Professor
Lecture 21 Concurrency Introduction
CS 3305 System Calls Lecture 7.
Intro to Processes CSSE 332 Operating Systems
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage.
Real-time Software Design
Operating Systems (CS 340 D)
CS 143A Quiz 1 Solution.
Computer-System Architecture
Module 2: Computer-System Structures
Multithreading.
Process & its States Lecture 5.
Process Description and Control
Concurrency: Mutual Exclusion and Process Synchronization
Module 2: Computer-System Structures
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
Chapter 3: Processes.
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
CS510 Operating System Foundations
CSE 153 Design of Operating Systems Winter 19
CS333 Intro to Operating Systems
Foundations and Definitions
Chapter 2: Computer-System Structures
Chapter 2: Computer-System Structures
Module 2: Computer-System Structures
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment. Phone:
Module 2: Computer-System Structures
COMP755 Advanced Operating Systems
Chapter 3: Process Management
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.
Sarah Diesburg Operating Systems CS 3430
Presentation transcript:

Tutorial 2: Homework 1 and Project 1

Homework 1 Q1. . There are several design goals in building an operating system, for example, resource utilization, timeliness, robustness, and so on. Give an example of two design goals that may contradict one another. A: Consider fairness and real time. Fairness requires that each process be allocated its resources in a fair way, with no process getting more than its fair share. On the other hand, real time requires that resources be allocated based on the times when different processes must complete their execution. A real-time process may get a disproportionate share of the resources.

Homework 1 Q2: What is the difference between kernel and user mode? Explain how having two distinct modes aids in designing an operating system. A: Most modern CPUs provide two modes of execution: kernel mode and user mode. The CPU can execute every instruction in its instruction set and use every feature of the hardware when executing in kernel mode. However, it can execute only a subset of instructions and use only subset of features when executing in the user mode. Having two modes allows designers to run user programs in user mode and thus deny them access to critical instructions.

Homework 1 Q3: List some differences between personal computer operating systems and mainframes. A: …

An answer: Mainframes: PC: Designed for throughput and reliability Can run multiple OS at the same time (?) Designed to handle hundreds of users concurrently PC: Designed for convenience and user experience (nice gui etc.) Typically has to manage a single user at a time What else?

Homework 1 Q4: What is the difference between a trap and an interrupt? A: A trap instruction switches the execution mode of a CPU from the user mode to the kernel mode. This instruction allows a user program to invoke functions in the operating system kernel.

A better answer? Going by stack overflow: A trap is an exception, whereas an interrupt is generated by hardware. When an exception occurs, e.g. a divide by 0, a trap is used to start a kernel routine to resolve the problem. This is synchronous, so user code is stopped until it is resolved. An interrupt can be generated by a disk coming back with data and is managed asynchronously.

Homework 1 Q5: When an interrupt or system call transfers control to the operating system, a kernel stack area separate from the stack of the interrupted process is generally used. Why? A: There are several reasons for using a separate stack for the kernel. Two of them are as follows. First, you do not want the operating system to crash because a poorly written user program does not allow for enough stack space. Second, if the kernel leaves stack data in a user program’s memory space upon return from a system call, a malicious user might be able to use this data to find out information about other processes.

Homework 1 Q6: Multiple jobs can run in parallel and finish faster than if they had run sequentially. Suppose that two jobs, each needing 10 minutes of CPU time, start simultaneously. How long will the last one take to complete if they run sequentially? How long if they run in parallel? Assume 50% I/O wait. A: If each job has 50% I/O wait, then it will take 40 minutes to complete in the absence of competition. If run sequentially, the second one will finish 80 minutes after the first one starts. With two jobs, the approximate CPU utilization is 1 − 0. 52 accumulate 20 minutes of CPU time, a job must run for 20/0.375 minutes, or about 53.33 minutes. Thus running sequentially the jobs finish after 80 minutes, but running in parallel they finish after 53.33 minutes. Thus, each one gets 0.375 CPU minute per minute of real time. To accumulate 20 minutes of CPU time, a job must run for 20/0.375 minutes, or about 53.33 minutes. Thus running sequentially the jobs finish after 80 minutes, but running in parallel they finish after 53.33 minutes.

Project 1 From scratch: Your job is to make the timer_sleep function stop busy waiting. Currently it calls thread_yield() Thread_yield() is the command used to put a thread of the ready queue to run. Thus, putting it in that queue just makes it run the loop again (especially if there are no other threads) What we want to do is block (thread_block()) until we wake the thread up again To do this we need to keep track of threads we block, so we can check if they should wake up, and wake them if necessary

Project 1 How to start: Timer_sleep(): Waking threads: You need a list to keep track of the threads. You can initiate this in timer.c (there is an initilisation function there that would work). You probably have to define it somewhere before initiating it Timer_sleep(): When a thread is meant to stop, you want to add it to the list and block the thread (thread_block()) However, you also need to keep track of when it should wake up… Waking threads: You need to store when a thread should wake up. The thread itself should maintain this information (a variable in its structure). You should assign it before you block the thread (start + ticks). There is a little work related to turning off interrupts for the blocked threads, then turning them back on later. Make it handle waking one thread, then worry about making it work for multiple (correct order etc.)

Monitors How do java monitors work? Java uses wait(), notify(), and notifyAll() Wait(): When wait() is invoked, the current thread is suspended. The Java run-time system places the thread in an internal wait queue associated with an object. The JRM is running, not the object* Notify(): A waiting thread is picked at random (if exists) and removed from the internal wait queue. The new thread must re-obtain the synchronization lock for the target object. This will always cause it to block at least until the thread calling notify() releases the lock. It will continue to block if a different thread gets the lock before it. NotifyAll(): Does the same thing as notify but unblocks all threads Other: You can pass an argument to wait() which specifies the maximim time to wait in the queue. If that time passes, notify() is called automatically.

Hardware supported concurrency Swap (a, b) Switch two memory locations Compare and Swap (a, b, c) A different atomic function from Swap Compare a given value with a memory location. If they are the same, modify the memory location with a new value.

Mutual Exclusion - Swap lock = false; // global var want= true; // local var while(want) { swap(lock,want) } // critical section lock = false; If it wants it, it will switch the the lock and the want value. If the lock is taken (lock = true), it will sit there spinning until the lock is released (lock = false). Then it will switch them (lock = true, want = false), and exit the loop into the CS.