CS 450 Module R3. Today's Agenda R1 and R2 review Module R3 Introduction Schedule R1 Grading Next Week Module R4 Introduction.

Slides:



Advertisements
Similar presentations
R4 Dynamically loading processes. Overview R4 is closely related to R3, much of what you have written for R3 applies to R4 In R3, we executed procedures.
Advertisements

CS 450 Module R4. R4 Overview Due on March 11 th along with R3. R4 is a small yet critical part of the MPX system. In this module, you will add the functionality.
CS 450 Module R3. Next Week R2 is due next Friday ▫Make sure to correct all errors with R1 ▫Correct errors in the documentation as well, it will be checked.
There are two types of addressing schemes:
Module R2 Overview. Process queues As processes enter the system and transition from state to state, they are stored queues. There may be many different.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
CS 450 MPX P ROJECT Introduction to MPX. I NTRODUCTION TO MPX The MPX module is divided into six modules Module R1: User Interface Module R2: Process.
Procedures and Stacks. Outline Stack organization PUSH and POP instructions Defining and Calling procedures.
Tips for R3: Process Initialization When we create processes to represent our 5 test procedures we must correctly initialize its context by placing values.
Set 20 Interrupts. INTERRUPTS The Pentium has a mechanism whereby external devices can interrupt it. Devices such as the keyboard, the monitor, hard disks.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Process Description and Control
Processes CSCI 444/544 Operating Systems Fall 2008.
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
Page 1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
CSSE Operating Systems
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
Threads CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
Process Description and Control A process is sometimes called a task, it is a program in execution.
Introduction to Embedded Systems
System Calls 1.
Micro-Computer Applications: Procedures & Interrupts Dr. Eng. Amr T. Abdel-Hamid ELECT 707 Fall 2011.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
CS 450 Module R6. Next Week R5 is due next Friday (April 3) No documentation, no source code due R5 is stand-alone, so I will not be checking errors from.
Chapter 10 The Stack Stack: An Abstract Data Type An important abstraction that you will encounter in many applications. We will describe two uses:
CS 450 Module R6. Next Week R5 is due Friday after Break ( April 1st ) ▫No documentation, no source code due ▫R5 is stand-alone, so I will not be checking.
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
Introduction to Processes CS Intoduction to Operating Systems.
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
Chapter 41 Processes Chapter 4. 2 Processes  Multiprogramming operating systems are built around the concept of process (also called task).  A process.
Compiler Construction
Chapter 4 Processes. Process: what is it? A program in execution A program in execution usually usually Can also have suspended or waiting processes Can.
CS 450 Module R5. Next Week Reminder: R3 & R4 is due next Friday. No documentation due. You do not need to turn in a copy of your source code. Remember.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Processes: program + execution state
Device Drivers CPU I/O Interface Device Driver DEVICECONTROL OPERATIONSDATA TRANSFER OPERATIONS Disk Seek to Sector, Track, Cyl. Seek Home Position.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
Module R3 Process Scheduling. Module R3 involves the creation of a simple “Round Robin” dispatcher. The successful completion of this module will require.
Linux Processes Travis Willey Jeff Mihalik. What is a process? A process is a program in execution A process includes: –program counter –stack –data section.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
Operating Systems CMPSC 473 Signals, Introduction to mutual exclusion September 28, Lecture 9 Instructor: Bhuvan Urgaonkar.
Interrupts And tips for R3. What is an interrupt? An interrupt is an electronic signal that indicates an event (possibly caused by hardware or the program.
Preocedures A closer look at procedures. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Process Control Management Prepared by: Dhason Operating Systems.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Overview: Using Hardware.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Processes and threads.
Process concept.
Format of Assembly language
Process Management Process Concept Why only the global variables?
Intro to Processes CSSE 332 Operating Systems
The slides must be understood in Lecture 5
Symbolic Instruction and Addressing
Process Description and Control
Chapter 3: Processes.
Chapter 6 –Symbolic Instruction and Addressing
Process.
Chapter 3: Process Concept
Presentation transcript:

CS 450 Module R3

Today's Agenda R1 and R2 review Module R3 Introduction Schedule R1 Grading Next Week Module R4 Introduction

Module R1 Due next Friday before your evaluation ▫We'll schedule evaluation times today ▫Only those present will receive a grade You will turn in: ▫A zip archive of your Module R1 code ( this) ▫A paper copy of your Module R1 code ▫Your programmer's manual ▫Your user's manual (See Intro to MPX slides)

Module R2 Due two weeks from now ▫You'll use the same evaluation time as Module R1 You will turn in the same materials as R1: ▫Zipped code ( ed to ▫Printed code ▫Updated programmer's manual ▫Updated user's manual

Module R3 Introduction Previously: ▫R1 adds user interaction and command handling ▫R2 adds structures (PCBs) to store processes Module R3 loads actual code into your PCBs These processes then dispatched to execute on the CPU, one at a time, until they give up control

How MPX Processes Work The CPU can only run one process at a time To give the illusion of simultaneous execution, processes need to run in short bursts The OS must handle changing from one process to another, without affecting process execution In other words, MPX performs a context switch

Context Switching With MPX, a process voluntarily gives up CPU access in the middle of execution. MPX needs a way to save the current "context" of the running process so it can resume later However, how can MPX "know" when a process is ready to give up the CPU? We can accomplish this using interrupts

Interrupts & Handlers An interrupt signals a hardware or software event When an interrupt is generated, the CPU calls an interrupt handler to figure out what happened Interrupt handlers: ▫Push context info onto a stack –Turbo C automatically does this for you  Interrupts can occur at any time, they are not predictable, therefore the complete system state has to be preserved ▫Execute something  Interrupt handlers should do only what is absolutely necessary and contain as little code as possible ▫Pop context information from the stack and restores it – Turbo C automatically does this for you  Restoring the system state so whatever what running before the interrupt can continue

Interrupt Keyword Interrupt keyword (Turbo C Only) ▫Used to designate interrupt handlers; automatically injects assembly code that saves CPU register values void interrupt name() ▫Note there cannot be parameters, and there cannot be a return value With R3, process that wish to give up the CPU will generate an interrupt, which MPX will handle. Thus, MPX can remove the process and insert a new one.

Generating Interrupts in MPX MPX processes will use the “sys_req” function to generate an interrupt. When a process generates an interrupt, it will have a status associated with it. For R3/R4- the statuses are ▫IDLE- means the program is not done terminating, so put it back in the ready, not suspended state and reinsert it into the ready queue ▫EXIT- program wants to terminate- so delete its PCB from memory ▫Other statuses, such as READ and WRITE, will need to be handled in Module R6.

Dos.h functions You will need to include dos.h ▫#include Construct a far pointer ▫unsinged char * MK_FP(unsigned int SEGMENT, unsigned int OFFSET) Get the segment of a far pointer ▫unsigned char FP_SEG(void*) Get the offset of a far pointer ▫unsigned char FP_OFF(void*)

R3: Breakdown R3 is due along with R4 on Friday March 11 th You will be writing two interrupt handlers The dispatcher will give the first process on the ready queue control of the CPU, thus allowing it to execute The sys_call handler will handle interrupts generated by MPX programs and call the dispatcher to run the next ready process

R3 Overview Two interrupt handlers ▫Dispatcher  will be called by the MPX OS ▫Sys_call  will be triggered by an interrupt Temporary Function ▫Load Processes Temporary Commands ▫To call dispatcher ▫To load test processes

Context When a process is interrupted, the values in all of the CPU registers must be saved. This information will be placed on the stack by Turbo C, but to access it, you will need to define a C structure- the PCB’s context. Sample is below- note that you can call the structure whatever you want, but you MUST use the same datatypes and have the registers in the same order! typedef struct context { unsigned int BP, DI, SI, DS, ES; unsigned int DX, CX, BX, AX; unsigned int IP, CS, FLAGS; } context;

Context Switching An important part of this Module is context switching. Context switching allows the system to replace a process that is currently running with a different process. In a context switch, you must: ▫Save the context of the running process ▫Replace it with the context of the process you want to run Turbo C automatically saves 12 registers for you when you use the interrupt keyword. However, the SS and the SP must also be saved, and Turbo C does not do this automatically. In Turbo C, you can directly access the SS and SP using _SS and _SP. You should save them into variables of type unsigned short. You can assign new values to the SS and SP using the dos functions mentioned earlier: ▫_SS = FP_SEG(sys_stack) ▫_SP = FP_OFF(sys_stack) + SYS_STACK_SIZE When assigning new values to _SS and _SP, you should use intermediate variables. When accessing (saving or changing) the SS and SP, you must do so in consecutive, uninterrupted steps.

Parameters Parameters cannot be passed to an interrupt handler in the normal way. When an MPX process generates an interrupt, sys_req will place certain parameters on the process’s stack. We need a structure to represent the parameters so that we can access them: typedef struct params{ int op_code; --operation code, IDLE, EXIT, READ, WRITE, etc int device_id; --TERMINAL, COM_PORT byte *buf_addr; --buffer address int *count_addr; --size of the buffer } params; op_code is the main concern of ours for now… it will be either IDLE or EXIT, as described before Byte = unsigned char We will discuss later how to access these parameters

R3: Variables Needed (Example) Variables to save and manipulate the stack segment (SS) and stack pointer (SP). ▫unsigned short ss_save; ▫unsigned short sp_save; ▫unsigned short new_ss; ▫unsigned short new_sp; The process that is currently running will not be in any queue, but we still need to keep track of it, so we need a variable to hold a pointer to that process’s PCB. We designate this “cop” (current operating process) ▫PCB *cop; Temporary system stack ▫char sys_stack[SYS_STACK_SIZE]; ▫Use a symbolic constant for the sys_stack_size- make it at least 1024

Stack Manipulation using Dos.h Save stack pointers ▫ss_save = _SS ▫sp_save = _SP Restore stack pointers ▫_SS = ss_save ▫_SP = sp_save Switch to temporary stack using intermediate variables ▫new_ss = FP_SEG(&sys_stack); ▫new_sp = FP_OFF(&sys_stack) + SYS_STACK_SIZE; ▫_SS = new_ss; ▫_SP = new_sp; Make a far pointer to stack top ▫stack_top = MK_FP(ss_save, sp_save);

Example: Illustration of R3

Procedure: sys_call Parameters: none Returns: null Sample Prototype ▫void interrupt sys_call(); Sys_call is not directly called. It is invoked (indirectly) by MPX processes requesting to go IDLE or EXIT Sys_call interprets system call parameters, puts the currently running process back in a queue or deletes it, depending on the nature of the interrupt. Then calls the dispatcher to allow the next process on the ready queue to run.

Sys_call: outline When an MPX process generates an interrupt, the sys_req function places the parameters on the stack. In sys_call, you need to access those parameters to uncover the reason the interrupt was generated. Access the stack and get the parameters ▫params *param_ptr = (params*)(MK_FP(_SS, _SP) + sizeof(context)) Switch to temporary stack Check the parameters (might be useful to do in a SWITCH statement as we will be adding to this later) ▫If param_ptr->op_code = IDLE  Process wants to continue executing  Set cop state to ready  Insert cop into the ready queue (in priority order) ▫If param_ptr->op_code = EXIT  Process wants to terminate  Delete cop (free its memory)  Set cop = null Call the dispatcher

Procedure: Dispatcher Parameters: none Returns: void Sample prototype ▫void interrupt dispatch() The dispatcher will be responsible for running processes from the ready queue. When the dispatcher is called, this means that the process that is “currently” running doesn’t need to run anymore, and another process should be given control of the CPU. The dispatcher is called directly from the sys_call handler.

Dispatcher The first time the dispatcher is run, it needs to see if the stack pointers (SS and SP) have been saved yet – if not you must save them so dispatcher has a way of returning to the function which originally called it. ▫Check to see if ss_save is NULL  If yes, save the stack pointers (_SS, _SP) to the save variables Now, we need to find the next process that will run ▫Find the first process in the ready queue that is not suspended If no PCB is ready, we need to restore the MPX state ▫Set the cop variable to NULL ▫Restore the stack pointers (SS, SP) using the save variables ▫Return If a PCB is found that is ready, we need to perform a context switch to allow that process to run ▫Set the cop variable equal to the process that is next in line to run ▫Remove the process from the ready queue and set its state to “RUNNING” ▫Context switch  Set _SS and _SP equal to the PCB’s stack pointer using dos.h functions ▫Return

Dispatcher: Outline If sp_save is null Save current SS and SP Look for the first PCB that is ready, not suspended If one is found Set COP = that PCB Remove from ready queue, set state to RUNNING Set _SS and _SP to the cop’s stack (context switch) Else Set COP to NULL Restore SS and SP Set sp_save & ss_save = null; end

R3 Initialization We need to set the interrupt vector to point to your system call handler (sys_call). This is so the interrupt instruction generated by MPX processes causes sys_call to be called. If you call your system handler sys_call, you would need to use the command: ▫sys_set_vec(sys_call)  Returns 0 if no problem  Returns ERR_SUP_INVHAN if invalid handler name You should also set all of your stack save variables to null in the initialization. You also need to modify your allocate_pcb function (R2), specifically when you set the stack_top pointer, you should set it to ▫Stack_top = Stack_base + Stack_size – sizeof(context)

Test Processes On Dr. Mooney’s website is a file named “procs- r3.c” This contains 5 test processes we will use to test R3. In order to use these, however, you will need to create a procedure (load_procs) to load these processes into your MPX system.

Load Processes: outline Need to do the following sequence 5 times (once for each process). Assumed that you have created a PCB* np, and a context* npc ▫np = Call your setuppcb function, give PCB name (ex “testproc1” or “test1”), priority = 0, class = APPLICATION ▫npc = (context*) np->stack_top; ▫npc->IP = FP_OFF(&test1_R3); //test1_R3 is a func name in procs-r3.c ▫npc->CS = FP_SEG(&test1_R3); ▫npc->FLAGS = 0x200; ▫npc->DS = _DS; ▫npc->ES = _ES; ▫Insert np into the ready queue in priority order ▫Repeat for each test process You should also include uniqueness checks on the process names.

Temporary Commands Load processes ▫Will call your load_procs() function to load the test processes from procs-r3.c ▫No parameters ▫Suggested commands: load, load_test, loadr3, etc. Dispatch ▫Will call dispatcher ▫No parameters ▫Suggest commands: go, dispatch Do not combine these commands- you should have one command to load the processes and a separate command to call dispatcher

How to use procs-r3.c Put prototypes for the test processes in your R3.C or R3.H file (ex. void test1_R3(void);) Link procs-r3.c with your project when you compile, DO NOT INCLUDE IT! Use your load command to load the processes. Use your dispatch command to run them You should see all 5 test processes run with lines like ▫Test n dispatched; loop count = 1 You should be able to load and dispatch these processes infinitely many times. If your system crashes after doing this a couple of times, you more than likely have a memory leak.

Tips and Hints Change your “sys_init” call to have the parameter “MODULE_R3” Sys call and dispatcher should be short functions. Neither should require more than lines of code. Do not use printf statements inside your dispatcher and sys_call functions. They will cause problems and make your code harder to debug. Remember to always manipulate _SS and _SP in consecutive, simple statements. Suspended processes and blocked processes should never be run. To test your program, try loading the processes and then blocking/suspending a few before calling dispatch. Only those in the ready, not suspended state should run, and all others should remain in their appropriate queues until they have been run. Do not declare variables inside of interrupt handlers- make any variables you need to use in an interrupt handler global. Most R3 errors can be traced back to R2 functions Read the project manual for R3- there is more pseudocode available in the manual.

Documentation Programmer’s Manual ▫Add on to what you did already Temporary Commands Manual ▫Add your load and dispatch commands User’s Manual ▫Nothing new to add- no need to turn it in. Program comments No manuals due with this module, but it is expected that all of these functions are in the final version of the manuals.