Chapter 1 Process and Thread. 1.2 process The address space of a program – Text – Code – Stack – Heap A set of registers – PC – SP Other resources – Files.

Slides:



Advertisements
Similar presentations
Process management Information maintained by OS for process management  process context  process control block OS virtualization of CPU for each process.
Advertisements

CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Processes CSCI 444/544 Operating Systems Fall 2008.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Nachos Instructional OS and Project 1 CS 170, Tao Yang.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Introduction to Processes CS Intoduction to Operating Systems.
CSC 501 Lecture 2: Processes. Process Process is a running program a program in execution an “instantiation” of a program Program is a bunch of instructions.
Exec Function calls Used to begin a processes execution. Accomplished by overwriting process imaged of caller with that of called. Several flavors, use.
Multiprogramming CSE451 Andrew Whitaker. Overview Multiprogramming: Running multiple programs “at the same time”  Requires multiplexing (sharing) the.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
The Structure of Processes (Chap 6 in the book “The Design of the UNIX Operating System”)
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Race Conditions Defined 1. Every data structure defines invariant conditions. defines the space of possible legal states of the structure defines what.
REVIEW OF COMMONLY USED DATA STRUCTURES IN OS. NEEDS FOR EFFICIENT DATA STRUCTURE Storage complexity & Computation complexity matter Consider the problem.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Project 2: Initial Implementation Notes Tao Yang.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Nachos Instructional OS CS 270, Tao Yang, Spring 2011.
Computer Studies (AL) Operating System Process Management - Process.
CS333 Intro to Operating Systems Jonathan Walpole.
CPS110: Implementing threads Landon Cox. Recap and looking ahead Hardware OS Applications Where we’ve been Where we’re going.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Chapter 4 Process Abstraction Chien-Chung Shen CIS, UD
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
1 Lecture 6 “Nachos” n nachos overview n directory structure n nachos emulated machine n nachos OS n nachos scheduler n nachos threads.
NachOS Threads System Road Map through the Code Lab 3.
Nachos Project 2 Lecturer: Hao-Hua Chu TA: Chun-Po Wang (Artoo) Date: 2008/10/14 Material Provided by Yuan-Hao Chang, Yung-Feng Lu.
CPS110: Implementing threads on a uni-processor Landon Cox January 29, 2008.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
A process is a program in execution A running system consists of multiple processes – OS processes Processes started by the OS to do “system things” –
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Processes and threads.
Process Tables; Threads
Process concept.
Chapter 3: Process Concept
CS 6560: Operating Systems Design
Protection of System Resources
CS399 New Beginnings Jonathan Walpole.
Chapter 3: Processes.
Intro to Processes CSSE 332 Operating Systems
Processes in Unix, Linux, and Windows
Nachos Threads and Concurrency
Processes in Unix, Linux, and Windows
Nachos Instructional OS
More examples How many processes does this piece of code create?
Processes in Unix, Linux, and Windows
Process Tables; Threads
Nachos Assignment#2 Priority Scheduling.
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Lecture Topics: 11/1 General Operating System Concepts Processes
Threads Chapter 5 2/17/2019 B.Ramamurthy.
Threads Chapter 5 2/23/2019 B.Ramamurthy.
Still Chapter 2 (Based on Silberchatz’s text and Nachos Roadmap.)
Threads and Concurrency
Lecture 6: Multiprogramming and Context Switching
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
CSE 451: Operating Systems Autumn 2004 Module 4 Processes
Presentation transcript:

Chapter 1 Process and Thread

1.2 process The address space of a program – Text – Code – Stack – Heap A set of registers – PC – SP Other resources – Files – Sockets A process is a virtual machine

Virtual machines PID PCB CPU switch

1.3 Thread A set of registers – PC – SP A stack Processes and threads share many concepts in common – States and State Transition – Control Block – Context Switch Differences A thread is a virtual CPU

1.4 Thread and Process Control Block A thread in Nachos is implemented as an object of class Thread in the kernel. The control block of a thread is implemented as part of data members of this class

Thread creation Thread creation (thread.cc) – sets up the thread name – sets status to JUST CREATED ) Thread status – JUST_CREATED – RUNNING – READY – BLOCKED

Thread creation A thread has two sets of CPU registers – system registers used for running the kernel userRegisters[] – user registers used for running user programs machineState[] Threads in a process share the same address space

Process Creation Each user process in Nachos starts with a kernel thread After having loaded the user program and formed the address space in the memory, the kernel thread becomes a user process.

1.5 Thread and Process Scheduling the job scheduler is implemented as an object of class Scheduler When Nachos is started, an object of class Scheduler is created and referenced by a global variable scheduler

Definition of Class Scheduler Ready queue ReadyToRun(Thread* thread) – puts the thread at the end of the queue FindNextToRun() – returns the pointer to the thread removed from the queue Run(Thread*) – calls the assembly function SWITCH(Thread*, Thread*) for the context switch from the current thread

1.6 Thread and Process State Transition Fork(VoidFunctionPtr func, _int arg) – JUST CREATED to READY Yield() – RUNNING to READY Sleep() – RUNNING to BLOCKED Finish() – terminate the thread

1.7 Thread Creation Thread::Thread(char* threadName) { name = threadName; stackTop = NULL; stack = NULL; status = JUST_CREATED; #ifdef USER_PROGRAM space = NULL; #endif } Thread object construction merely creates the data structure of the object and sets its state to JUST CREATED

Fork() This thread is not ready to run yet – Its control block has not been initialized – its stack has not been allocated – it does not have the initial value for PC StackAllocate (VoidFunctionPtr, int ) – allocate the memory space for the stack – initialize the array machineState[] interrupt->SetLevel(IntOff )

Thread::Fork(VoidFunctionPtr func, _int arg)

StackAllocate (VoidFunctionPtr, int ) AllocBoundedArray(int) – allocates a stack Set up registrstors – machineState[PCState] = (_int) ThreadRoot; – machineState[StartupPCState] = (_int) InterruptEnable – machineState[InitialPCState] = (_int) func – machineState[InitialArgState] = arg – machineState[WhenDonePCState] = (_int) ThreadFinish

ThreadRoot ra is called return address register and contains the address of the first instruction to execute after the assembly routine is complete machineState[PCState] refers to function ThreadRoot machineState[PCState] is loaded into register ra The first routine executed by the new thread is ThreadRoot

When a thread is scheduled to run for the first time, the value in machineState[PCState] which is the reference to function ThreadRoot, is loaded into register ra. ra is called return address register and contains the address of the first instruction to execute after the assembly routine is complete. Therefore, the first routine executed by the new thread is ThreadRoot

ThreadRoot

ThreadRoot’s function A wrapper which calls three subroutines – StartupPC : InterruptEnable simply to enable interrupt – InitialPC – ThreadFinish terminate the thread. Subroutine ThreadRoot defines the activities of the thread during its life time

InitialPC The reference of the function we want the thread to execute for the real job is in register InitialPC, and its argument in register InitialArg jal Reg is called “jump and link – It saves the return address in hardware – jumps to the subroutine pointed by register Reg

1.8 Context Switch a context switch is started by calling function Run (Thread *) of class Scheduler

Key global variables currentThread is the pointer to the current running thread scheduler is the pointer to the Scheduler object of the kernel – created when the Nachos kernel is started – Created by Initialize(int argc, char **argv)

Run (Thread *nextThread) sets variables – oldThread to the the current running thread (the thread which calls this function) – currentThread to the next thread 设置新进程状态 SWITCH – 参见 P23 Delete the carcasses of finished processes

SWITCH(..) saves all the important registers of the current thread Recall that the first private data member of Thread class is stackTop followed by achineState[MachineStateSize] register ra contains the the return address of the function call. In this case, ra contains the address of the instruction right after line 116 in scheduler.cc The instruction in line 113 makes the control jump to the address stored in ra

Note: Two return points the lines and lines in function Run(Thread*), are used to save and restore the user registers and the address space of user processes The entire function Run(Thread*) is run by the kernel, because it belongs to the Nachos kernel Two return points: – From the other thread to – From kernel to user

Note: The time of the return Note the time of the return of function call Run(Thread*) to the current thread. It does not return immediately. It won’t return until the calling thread is switched back and becomes the current thread again – Thread X gives up CPU by call Run()  SWITCH() – SWITCH() activates another thread Y – After Y, the CPU maybe not return to X

1.9 Thread Termination ThreadRoot calls function Finish() Finish() – sets threadToBeDestroyed to current thread – then calls Sleep() The termination of this thread is actually done by the next thread after the context switch A thread can’t delete itself

1.11 Operating Systems Kernel The smallest Nachos kernel – containing thread management only – call (void) Initialize(argc, argv) – call ThreadTest() – call currentThread->Finish() Explain P25,26