Project 2 Non- preemptive Kernel. COS 318 Fall 2016

Similar documents
Precept 2: Non-preemptive Scheduler. COS 318: Fall 2018

CSC369 Lecture 2. Larry Zhang, September 21, 2015

CSC369 Lecture 2. Larry Zhang

Precept 3: Preemptive Scheduler. COS 318: Fall 2018

Precept 5: Virtual Memory. COS 318: Fall 2018

Today s Topics. u Thread implementation. l Non-preemptive versus preemptive threads. l Kernel vs. user threads

Project 4 Inter-Process Communication and Process Management. COS 318 Fall 2016

Announcement. Exercise #2 will be out today. Due date is next Monday

Today s Topics. u Thread implementation. l Non-preemptive versus preemptive threads. l Kernel vs. user threads

Lecture 4: Mechanism of process execution. Mythili Vutukuru IIT Bombay

Review: Easy Piece 1

AC59/AT59/AC110/AT110 OPERATING SYSTEMS & SYSTEMS SOFTWARE DEC 2015

The Kernel Abstraction

Lecture 5: Synchronization w/locks

CSE 153 Design of Operating Systems Fall 2018

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski

x86 architecture et similia

Threads Implementation. Jo, Heeseung

Lectures 5. Announcements: Today: Oops in Strings/pointers (example from last time) Functions in MIPS

Lecture 5. Announcements: Today: Finish up functions in MIPS

Function Calls COS 217. Reading: Chapter 4 of Programming From the Ground Up (available online from the course Web site)

What the CPU Sees Basic Flow Control Conditional Flow Control Structured Flow Control Functions and Scope. C Flow Control.

3. Process Management in xv6

KERNEL THREAD IMPLEMENTATION DETAILS. CS124 Operating Systems Winter , Lecture 9

Chap.6 Limited Direct Execution. Dongkun Shin, SKKU

Digital Forensics Lecture 3 - Reverse Engineering

Functions in MIPS. Functions in MIPS 1

Stacks and Frames Demystified. CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han

ECE 391 Exam 1 Review Session - Spring Brought to you by HKN

The Process Abstraction. CMPU 334 Operating Systems Jason Waterman

Process Description and Control

Subroutines. int main() { int i, j; i = 5; j = celtokel(i); i = j; return 0;}

Project 5 Virtual Memory. COS 318 Fall 2015

The Kernel Abstraction. Chapter 2 OSPP Part I

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

Lecture 4: Threads; weaving control flow

CSC 2400: Computer Systems. Using the Stack for Function Calls

Today. Putting it all together

Processes Prof. James L. Frankel Harvard University. Version of 6:16 PM 10-Feb-2017 Copyright 2017, 2015 James L. Frankel. All rights reserved.

Section 4: Threads CS162. September 15, Warmup Hello World Vocabulary 2

Questions answered in this lecture: CS 537 Lecture 19 Threads and Cooperation. What s in a process? Organizing a Process

Threads Implementation. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

by Marina Cholakyan, Hyduke Noshadi, Sepehr Sahba and Young Cha

CSE 153 Design of Operating Systems

Processes and Threads

OS 1 st Exam Name Solution St # (Q1) (19 points) True/False. Circle the appropriate choice (there are no trick questions).

Objectives. Explain non-preemptive scheduling Explain step-by-step how a context switch works in TOS

Bootstrapping. Steve Muckle Dave Eckhardt

Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar

CS 318 Principles of Operating Systems

Objectives. Introduction to process management of an operating system Explain step-by-step how processes are created in TOS

Mutex Implementation

Implementation of Processes

CS 318 Principles of Operating Systems

OS lpr. www. nfsd gcc emacs ls 1/27/09. Process Management. CS 537 Lecture 3: Processes. Example OS in operation. Why Processes? Simplicity + Speed

What You Need to Know for Project Three. Dave Eckhardt Steve Muckle

CSE 120 Principles of Operating Systems

Processes. Dr. Yingwu Zhu

Process. Discussion session 3 1/30/2016

Preemptive Scheduling

CS 537 Lecture 2 - Processes

EECE.4810/EECE.5730: Operating Systems Spring 2017 Homework 2 Solution

Operating Systems, Assignment 2 Threads and Synchronization

CSE 153 Design of Operating Systems Fall 2018

Mon Sep 17, 2007 Lecture 3: Process Management

Synchronization COMPSCI 386

* What are the different states for a task in an OS?

CSC 2400: Computing Systems. X86 Assembly: Function Calls

ò Paper reading assigned for next Tuesday ò Understand low-level building blocks of a scheduler User Kernel ò Understand competing policy goals

CS 326: Operating Systems. Process Execution. Lecture 5

Introduction to PThreads and Basic Synchronization

Student Name:.. Student ID... Course Code: CSC 227 Course Title: Semester: Fall Exercises Cover Sheet:

Threads Chapter 5 1 Chapter 5

ELEC 377 Operating Systems. Week 1 Class 2

Processes. Johan Montelius KTH

1 PROCESSES PROCESS CONCEPT The Process Process State Process Control Block 5

Section 4: Threads and Context Switching

Processes. OS Structure. OS Structure. Modes of Execution. Typical Functions of an OS Kernel. Non-Kernel OS. COMP755 Advanced Operating Systems

CSE 153 Design of Operating Systems

A process. the stack

CSE 120 Principles of Operating Systems

CSE 120 Principles of Operating Systems

CS140 Project 3: Virtual Memory. TA: Diveesh Singh

Real-Time Programming

CS153: Midterm (Fall 16)

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

Operating Systems. Objective. Background

Practical Malware Analysis

Midterm Exam Solutions and Grading Guidelines March 3, 1999 CS162 Operating Systems

OS Structure, Processes & Process Management. Don Porter Portions courtesy Emmett Witchel

Computer architecture. A simplified model

CS 31: Introduction to Computer Systems : Threads & Synchronization April 16-18, 2019

x86 Assembly Tutorial COS 318: Fall 2017

Processes and Non-Preemptive Scheduling. Otto J. Anshus

Computer Systems Assignment 2: Fork and Threads Package

High Performance Computing Course Notes Shared Memory Parallel Programming

Parallel Programming Languages COMP360

TCSS 422: OPERATING SYSTEMS

OPERATING SYSTEMS ASSIGNMENT 2 SIGNALS, USER LEVEL THREADS AND SYNCHRONIZATION

Processes. CS3026 Operating Systems Lecture 05

Transcription:

Project 2 Non- preemptive Kernel COS 318 Fall 2016

Project 2: Schedule Design Review: - Monday, 10/10; - Answer the questions: ü ü ü ü ü Process Control Block: What will be in your PCB and what will it be initialized to? Context Switching: How will you save and restore a task s context? Should anything special be done for the first task? Processes: What, if any, are the differences between threads and processes and how they are handled? Mutual Exclusion: What s your plan for implementing mutual exclusion? Scheduling: Look at the project web page for an execution example.

Project 2: Schedule Design Review: - Sign up on the project page; - Please, draw pictures and write your idea down (1 piece of paper). Due date: Tuesday, 10/18, 11:55pm.

Project 2: Overview Goal: Build a non- preemptive kernel that can switch between different tasks (task = process or kernel thread). Read the project spec for more details. Start early.

What is a non- preemptive kernel? Current running task will lose its CPU or running state: 1. yield 2. block: I/O operation; lock (thread) 3. exit

What is a non- preemptive kernel? COS 318: go_to_class(); go_to_precept(); yield(); thinking (); design_review() yield(); coding(); exit(); Life: have_fun(); yield(); play(); yield(); do_random_stuff() yield();

What is a non- preemptive kernel? COS 318: go_to_class(); go_to_precept(); yield(); thinking (); design_review() yield(); coding(); exit(); Life: have_fun(); yield(); play(); yield(); do_random_stuff() yield();

What you need to deal with 1. Process control blocks (PCB). 2. User and kernel stack. 3. Context switching procedure. 4. Basic system call mechanism. 5. Mutual exclusion.

Assumptions for this project Protected Mode - > don t worry about segment register Non- preemptive tasks: - run until they yield, exit or block. Fixed number of tasks: - allocate per- task state(pcb) statically in your program. - Each task s stack size is fixed.

1. Process Control Block Defined in kernel.h. and should be Initialized in kernel.c:_start(); What is its purpose? What should be in the PCB? - PID - Stack info? - All registers? - What else?

2. Allocating stacks Allocate separate stacks for tasks in kernel.c: _start() Processes have two stacks(theoratically): - user stack for the process to use; - kernel stack for the kernel to use when executing system calls on behalf of the process. - Option: only use one stack! Kernel threads need only one stack. Suggestion: put them in memory 0x40000-0x52000: - 4kb for the stack should be enough.

3. Context Switch Implement a queue structure first!!!! Ready queue: Contains all PCBs or addresses of all PCBs of ready tasks. Blocked queue: When do you need to push or pop your task?

3. Context Switch 1. Save state of task into the PCB. (Optional) 2. Push the current PCB into the ready queue or block queue. (Optional) 3. Pop the PCB of new task from ready queue. 4. Restore the state of new task. 5. Start new task.

3. Context Switch Save state of tasks When a task resumes control of CPU, it shouldn t have to care about what happened when it was not running. - save general purpose registers (%eax,, including %esp); - save flags. - instruction pointer? Where do you save these things? - PCB.

3. Finding the next task The kernel must keep track of which tasks have not exited yet. Run the task that has been inactive for the longest time. What s the natural data structure? - Please explain your design in the design review!

3. Calling yield() To call yield(), a task needs the addresses of the functions and be able to access these addresses. Kernel threads: no problem! - scheduler.c: do_yield(). User processes: should not have direct access. - Now, how to get access?

4. System calls yield() is an example of a system call. To make a system call, typically a process: - pushes a system call number and its arguments onto the stack; - uses an interrupt/trap mechanism to elevate privileges and jump into kernel. Two system calls: yield() and exit().

4. Jumping into the kernel: kernel_entry() kernel.c: _start() stores the address of kernel_entry at ENTRY_POINT (0xf00). Processes make system calls by: - Loading the address of kernel_entry from ENTRY_POINT; - Calling the function at this address with a system call number as an argument. kernel_entry (syscall_no) must save the registers and switch to the kernel stack, and reverse the process on the way out.

Memory layout 0x00000 0x00F00 0x01000 BIOS ENTRY_POINT Kernel 0x10000 Process 1 0x20000 Process 2 0x30000 Process 3 0x40000 Stacks 0x9FFFE 0xA0000 Kernel Stack (set by bootblock.s) Video RAM

5. Mutual exclusion through locks Lock- based synchronization is related to thread scheduling. The calls available to threads are: - lock_init(lock_t *); - lock_acquire(lock_t *); - lock_release(lock_t *). Precise semantics we want are described in the project specification. There is exactly one correct trace.

Timing a context switch util.c: get_timer() returns number of cycles since boot. There is only one process for your timing code, but it is given twice in tasks.c: - use a global variable to distinguish the first execution from the second.

Things to thing about What should you do to jump to a kernel thread for the first time? How to save CPU state into the PCB? In what order? Code up and test incrementally. - Most effort spent in debugging, so keep it simple. Start early. - Plenty of tricky bits in this assignment.