Today’s agenda Hardware architecture and runtime system

Slides:



Advertisements
Similar presentations
CPU Structure and Function
Advertisements

Computer Organization and Architecture
Computer Organization and Architecture
OPERATING SYSTEM LESSON 2. INTRODUCTION TO OPERATING SYSTEM Computer Hardware’s complexity Operating Systems (OS) hide this complexity from users OS manages.
©Brooks/Cole, 2003 Chapter 5 Computer Organization.
Computer System Overview
Introduction Operating Systems’ Concepts and Structure Lecture 1 ~ Spring, 2008 ~ Spring, 2008TUCN. Operating Systems. Lecture 1.
Chapter 4  Converts data into information  Control center  Set of electronic circuitry that executes stored program instructions  Two parts ◦ Control.
CH12 CPU Structure and Function
Chapter 8 Input/Output. Busses l Group of electrical conductors suitable for carrying computer signals from one location to another l Each conductor in.
Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Overview: Using Hardware.
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
CS Fall 2011 CS 423 – Operating Systems Design Lecture 2 – Concepts Review Klara Nahrstedt Fall 2011.
1 CS503: Operating Systems Spring 2014 Dongyan Xu Department of Computer Science Purdue University.
Computer Architecture Lecture10: Input/output devices Piotr Bilski.
Operating Systems and Networks AE4B33OSS Introduction.
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Input/Output CS 342 – Operating Systems Ibrahim Korpeoglu Bilkent University.
Chapter 2 Parallel Architecture. Moore’s Law The number of transistors on a chip doubles every years. – Has been valid for over 40 years – Can’t.
1.4 Hardware Review. CPU  Fetch-decode-execute cycle 1. Fetch 2. Bump PC 3. Decode 4. Determine operand addr (if necessary) 5. Fetch operand from memory.
Experiment 0 COE 205 Computer Organization & Assembly Language Programming Term 052.
Processor Structure and Function Chapter8:. CPU Structure  CPU must:  Fetch instructions –Read instruction from memory  Interpret instructions –Instruction.
Lecture on Central Process Unit (CPU)
Operating Systems: History, Hardware & Concepts Ch 1.4 & 1.5 Thursday, January 18, 2007.
1 Computer System Overview Chapter 1. 2 Operating System Exploits the hardware resources of one or more processors Provides a set of services to system.
Introduction to Operating Systems Concepts
Chapter Overview General Concepts IA-32 Processor Architecture
Operating System Overview
Chapter 13: I/O Systems Modified by Dr. Neerja Mhaskar for CS 3SH3.
Computer System Overview
Chapter 2.
Computer Hardware – System Unit
William Stallings Computer Organization and Architecture 8th Edition
Jonathan Walpole Computer Science Portland State University
Operating Systems (CS 340 D)
Discovering Computers 2011: Living in a Digital World Chapter 4
Chapter 7.2 Computer Architecture
Transforming Data Into Information
Introduction to Computer Architecture
Introduction of microprocessor
introduction to computer
Chapter 3 Top Level View of Computer Function and Interconnection
Basic Computer Organization
Microcomputer Architecture
الجزء السابع الجزء السادس الجزء الخامس الجزء الرابع الجزء الثالث الجزء
Computer Organization
McGraw-Hill Technology Education
Computer System Overview
ECEG-3202 Computer Architecture and Organization
Introduction to Computer Architecture
Today’s agenda Hardware architecture and runtime system
Today’s agenda Lab 1 Module 4: Process Management
Computer Organization
Created by Vivi Sahfitri
Overview 1. Inside a PC 2. The Motherboard 3. RAM the 'brains' 4. ROM
A451: Computer Systems and Programming
Introduction to Computer Systems
Chapter 1 Computer System Overview
Chapter 5 Computer Organization
Computer System Overview
McGraw-Hill Technology Education
McGraw-Hill Technology Education
CPU Structure and Function
Chapter 11 Processor Structure and function
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment. Phone:
Chapter 13: I/O Systems.
Presentation transcript:

Today’s agenda Hardware architecture and runtime system Additional slides Module-3 Lab1 will be released soon System calls: create(),resume(),kill(), sleep(), sleepms(), Semaphores: wait(), signal(), semcreate(),semdelete() Read Chapter 2 (2.8, 2.9) Producer-consumer sample in chapter 2 CS354-Fall2018

CS250 in 15 minutes CS354-Fall2018

Processors Each CPU has a specific set of instructions All CPUs contain General registers inside to hold key variables and temporary results Special registers visible to the programmer Program counter contains the memory address of the next instruction to be fetched Stack pointer points to the top of the current stack in memory Control registers (e.g., CR0-CR4 in x86) PSW (Program Status Word) contains the condition code bits which are set by comparison instructions, the CPU priority, the mode (user or kernel) and various other control bits. CS354-Fall2018

How Processors Work Execute instructions CPU cycles Two modes of CPU Fetch (from mem)  decode  execute Program counter (PC) When is PC changed? Pipeline: fetch n+2 while decode n+1 while execute n Two modes of CPU User mode (a subset of instructions) Privileged mode (all instruction) Trap (special instruction) CS354-Fall2018

Memory Access Memory read: How many mem access for one instruction? Assert address on address lines Wait till data appear on data line Much slower than CPU! How many mem access for one instruction? Fetch instruction Fetch operand (0, 1 or 2) Write results (0 or 1) How to speed up instruction execution? CS354-Fall2018

Memory-Storage Hierarchy - 4MB < -1GB -TB -TB CS354-Fall2018

Memory Registers internal to CPU (as fast as CPU) Storage 32x32 bits on a 32-bit CPU, 64x64 on 64 bit CPU (less than 1KB in both cases) Cache memory controlled by hardware Cache hit and miss RAM (Random Access Memory) Disk (magnetic disk), CD-ROM, DVD,… Cylinder, track, … Non-volatile Memory ROM (Read Only Memory) Programmed at the factory and can’t be changed EEPROM (Electrically Erasable ROM) Flash RAM Can be erased and re-written Volatile Memory CMOS holds current time and date

CPU Cache Cache hit: Cache miss: no need to access memory data obtained from mem, possibly update cache CS354-Fall2018

Memory Management How to protect programs from each other? How to handle relocation ? Base register Limit register Check and Mapping of Addresses Virtual Address - Physical Address Memory Management Unit (MMU – located on CPU chip or close to it Performance effects on memory system Cache Context switch

I/O Devices Controller Device Example: Disk Controller Controllers are complex converting OS request into device parameters Controllers often contain small embedded computers Device Fairly simple interfaces and standardized IDE (Integrated Drive Electronics) – standard disk type on Pentiums and other computers

I/O Devices Device Driver Needed since each type of controller may be different. Software that talks to a controller, giving it comments and accepting responses Each controller manufacturer supplies a driver for each OS it supports (e.g., drivers for Windows XP, Longhorn, UNIX)

Methods for I/O How device driver talks to controller Busy wait Interrupt DMA

Bus Pentium systems have eight buses Cache, local, memory, PCI, SCSI, USB, IDE, ISA PCI (Peripheral Component Interconnect) bus is successor to IBM PC ISA bus Intel bus, 528MB/sec ISA (Industry Standard Architecture) bus 16.67 MB/sec Specialized buses: SCSI (Small Computer System Interface) 160MB/sec – for disks, scanners (popular on Macintosh, UNIX) USB (Universal Serial Bus) 1.5 MB/sec IEEE 1394 – FireWire (Apple) bus 50MB/sec, connectivity for cameras to computer IDE (Integrated Drive Electronics) bus Disk, CD-ROM

Structure of an Intel Pentium System

Switch to Module-3 CS354-Fall2018

Lab 1: Producer-Consumer Read Chapter 2.8, 2.9 ex4.c, ex5.c and ex6.c two concurrent processes that each increments a shared integer n Race condition (how to handle it?) CS354-Fall2018

Start with Lab 0-Task 3 prch(c) char c; { int i; while(1) { for (i=0; i< 20000; i++); kprintf("%c", c); } /* while */ } /* prch */ main () { kprintf("\n\nHello world, Xinu lives!\n\n; resume(create(prch,2000,20,"proc A",1,'A')); resume(create(prch,2000,20,"proc B",1,'B')); resume(create(prch,2000,20,"proc C",1,'C')); } /* main */ CS354-Fall2018

What if producer-consumer? write integer n read consumer CS354-Fall2018

ex4.c /* ex4.c - main, prod2, cons2 */ # include <xinu.h>   # include <xinu.h> void produce(void),consume(void); int32 n = 0; /* global variable n shared by all processes */ /* --------------- * main - Example of unsychronized producer and consumer processes * --------------- */ void main(void) { resume (create (consume, 1024, 20, "cons", 0)); resume (create (produce, 1024, 20, "prod", 0)); } CS354-Fall2018

What are outputs? Surprisingly, we do not see all values in [0,2000] /* --------------- * produce - Increment n 2000 times * --------------- */   void produce (void) { int32 i; for (i=1; i<=2000; i++){ n++; } * consume - print n 2000 times and exit void consume(void) printf("n is %d \n", n); What are outputs? Surprisingly, we do not see all values in [0,2000] But, a few 0s at start and most are 2000s. Why not? CS354-Fall2018

How to synchronize independent processes? Semaphore abstraction wait() signal() semcreate() semdelete() Two semaphores: One on which the consumer waits One on which the producer waits CS354-Fall2018

Ex5.c /* ex5.c - main, prod2, cons2 */ # include <xinu.h> void prod2(sid32,sid32), cons2(sid32,sid32);   int32 n = 0; /* variable n has initial value zero */ /* --------------- * main - producer and consumer processes sychronizaed with semaphores * --------------- */ void main(void) { sid32 produced, consumed; consumed = semcreate(0); produced = semcreate(1); resume (create (cons2, 1024, 20, "cons", 2, consumed, produced)); resume (create (prod2, 1024, 20, "prod", 2, consumed, produced)); } CS354-Fall2018

* prod2 - Increment n 2000 times, waiting for it to be consumed. /* --------------- * prod2 - Increment n 2000 times, waiting for it to be consumed. * --------------- */   void prod2( sid32 consumed, sid32 produced) { int32 i; for (i=1; i<=2000; i++){ wait(consumed); n++; signal(produced); } /* --------------- * cons2 - print n 2000 times, waiting for it to be produced * --------------- */ void cons2( sid32 consumed, sid32 produced) { int32 i; for (i=1; i<=2000; i++){ wait(produced); printf("n is %d \n", n); signal(consumed); } CS354-Fall2018

Semaphores: Mutual Exclusion Only one of two executing processes obtains access to a shared resource what if not n? but a shared list? Accessed by many processes shared[n++] = item; /* n is updated over time */ CS354-Fall2018

# include <xinu.h> /* ex6.c - additem */   # include <xinu.h> sid32 mutex; /* assume initialized with semcreate */ int32 shared[100]; /* An array shared by many processes */ int32 n = 0; /* Count of items in the array */ int32 n = 0; /* variable n has initial value zero */ /* --------------- * addiotem - obtain exclusive use of array shared and add an item to it. * --------------- */ void additem (int32 item) { wait(mutex); shared[n++] = item; signal(mutex); } CS354-Fall2018