Intro to Computer Systems Summer 2014 COMP 2130 Introduction to Computer Systems Computing Science Thompson Rivers University.

Slides:



Advertisements
Similar presentations
Fabián E. Bustamante, Spring 2007 Introduction to Computer Systems Today : Welcome to EECS 213 Lecture topics and assignments Lab rationale Next time:
Advertisements

Computer Organization. This module surveys the physical resources of a computer system. –Basic components CPUMemoryBus I/O devices –CPU structure Registers.
COSC 120 Computer Programming
General information Course web page: html Office hours:- Prof. Eyal.
Introduction to Computer Systems Topics: Staff, text, and policies Lecture topics and assignments Lab rationale CS 213 F ’06 CS-213 Yan Chen.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
CS 104 Introduction to Computer Science and Graphics Problems
Memory Management CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
OS Spring’03 Introduction Operating Systems Spring 2003.
Computer System Overview
Introduction to Computer Systems Topics: Staff, text, and policies Lecture topics and assignments Class overview CS 213 S ’06 CS-213 Aleksandar Kuzmanovic.
Chapter 2: Impact of Machine Architectures What is the Relationship Between Programs, Programming Languages, and Computers.
Introduction to Computer Systems Topics: Staff, text, and policies Lecture topics and assignments Class overview CS 213 S ’08 CS-213 Aleksandar Kuzmanovic.
Virtual Memory Topics Virtual Memory Access Page Table, TLB Programming for locality Memory Mountain Revisited.
Chapter 6: An Introduction to System Software and Virtual Machines
CPU Registers PC Arith Logic Unit Bus Interface I/O Bridge System bus Memory bus Main Memory USB Controller Graphics Adapter Disk Controller I/O Bus Mouse.
Systems I Locality and Caching
Computer Organization
System Calls 1.
Computer Architecture ECE 4801 Berk Sunar Erkay Savas.
Winter 2015 COMP 2130 Introduction to Computer Systems Computing Science Thompson Rivers University Introduction and Overview.
Computer Processing of Data
Memory Hierarchy 1 Computer Organization II © CS:APP & McQuain Cache Memory and Performance Many of the following slides are taken with.
CMSC 313, F ‘09 1 Introduction to Assembly TopicsTopics –Assembly Overview –Instructions –Hardware.
University of Amsterdam Computer Systems – a guided tour Arnoud Visser 1 Computer Systems A guided Tour.
CPU Computer Hardware Organization (How does the computer look from inside?) Register file ALU PC System bus Memory bus Main memory Bus interface I/O bridge.
Introduction to Computer Systems Topics: Theme Four great realities of computer systems Chap 1 in “Computer Systems” book “The Class That Gives.
1 Operating System Overview. 2 Today’s Objectives Explain the main purpose of operating systems and describe milestones of OS evolution Explain fundamental.
Virtual & Dynamic Memory Management Summer 2014 COMP 2130 Intro Computer Systems Computing Science Thompson Rivers University.
Computer Systems Organization CS 1428 Foundations of Computer Science.
Computers organization & Assembly Language Chapter 0 INTRODUCTION TO COMPUTING Basic Concepts.
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.
Introduction and Overview Summer 2014 COMP 2130 Introduction to Computer Systems Computing Science Thompson Rivers University.
Advanced Computer Architecture 0 Lecture # 1 Introduction by Husnain Sherazi.
INVITATION TO COMPUTER SCIENCE, JAVA VERSION, THIRD EDITION Chapter 6: An Introduction to System Software and Virtual Machines.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Operating-System Structures System Components Operating System Services.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Computer Architecture And Organization UNIT-II General System Architecture.
Introduction to Computer Systems Topics: Theme Five great realities of computer systems (continued) “The class that bytes”
Computer Organization & Assembly Language © by DR. M. Amer.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
CPSC 171 Introduction to Computer Science System Software and Virtual Machines.
Introduction: Memory Management 2 Ideally programmers want memory that is large fast non volatile Memory hierarchy small amount of fast, expensive memory.
Lecture on Central Process Unit (CPU)
Chapter 1 Introduction. Components of a Computer CPU (central processing unit) Executing instructions –Carrying out arithmetic and logical operations.
Computer operation is of how the different parts of a computer system work together to perform a task.
Simple ALU How to perform this C language integer operation in the computer C=A+B; ? The arithmetic/logic unit (ALU) of a processor performs integer arithmetic.
CBP 2002ITY 270 Computer Architecture1 Module Structure Whirlwind Review – Fetch-Execute Simulation Instruction Set Architectures RISC vs x86 How to build.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
1 Basic Processor Architecture. 2 Building Blocks of Processor Systems CPU.
Hello world !!! ASCII representation of hello.c.
Operating Systems A Biswas, Dept. of Information Technology.
Introduction and Overview Winter 2013 COMP 2130 Introduction to Computer Systems Computing Science Thompson Rivers University.
1 The user’s view  A user is a person employing the computer to do useful work  Examples of useful work include spreadsheets word processing developing.
Introduction to Operating Systems Concepts
Computer Systems MTSU CSCI 3240 Spring 2016 Dr. Hyrum D. Carroll
Chapter 1: A Tour of Computer Systems
Edexcel GCSE Computer Science Topic 15 - The Processor (CPU)
CS703 - Advanced Operating Systems
Local secondary storage (local disks)
Introduction to Computer Systems
Introduction to Computer Systems
Lecture Topics: 11/1 General Operating System Concepts Processes
Introduction to Computer Systems
Hardware Organization
Cache Memory and Performance
Presentation transcript:

Intro to Computer Systems Summer 2014 COMP 2130 Introduction to Computer Systems Computing Science Thompson Rivers University

TRU-COMP2130 Intro to Computer Systems2 Course Objectives The better knowledge of computer systems, the better programing. Computer SystemC Programming Language Computer architecture CPU (Central Processing Unit) IA32 assembly language Introduction to C language Compiling, linking, loading, executing Physical main memory MMU (Memory Management Unit) Virtual memory space Memory hierarchy Cache Dynamic memory management Better coding – locality Reliable and efficient programming for power programmers (to avoid strange errors, to optimize codes, to avoid security holes, …)

TRU-COMP2130 Intro to Computer Systems3 Course Contents Introduction to computer systems: B&O 1, 9.1 – 9.2 Introduction to C programming: K&R 1 – 4 Data representations: B&O 2.1 – 2.4 C: advanced topics: K&R 5.1 – 5.9, 5.11, 6 – 8 Introduction to IA32 (Intel Architecture 32): B&O 3.1 – 3.8, 3.13 Compiling, linking, loading, and executing: B&O 7 (except 7.12) Dynamic memory management – Heap: B&O – 9.9.2, – 9.9.5, 9.11 Code optimization: B&O 5.1 – 5.6, 5.13 Memory hierarchy, locality, caching: B&O 5.12, 6.1 – 6.3, – 6.4.2, 6.5, – 6.6.3, 6.7 Virtual memory (if time permits): B&O 9.4 – 9.5

TRU-COMP2130 Intro to Computer Systems4 Unit Learning Objectives List the four phases in the compilation system. List the four major hardware components. List the three major components in CPU. Explain the logical concepts of main memory. List the two steps in an instruction cycle. Explain briefly for what and how PC is used. Explain briefly what locality means. Give an example code that can be executed fast by using cache memory. Define what a process is. Explain how process and thread are different. Define what multi-processing is. Distinguish virtual memory and physical memory.

TRU-COMP2130 Intro to Computer Systems5 Explain what heap in the virtual memory space is. Explain what stack in the virtual memory space is. Name the hardware component that translates virtual addresses to physical addresses. …

TRU-COMP2130 Intro to Computer Systems6 Unit Contents What is information? Programs and compilation systems CPU Cache Memory hierarchy Operating systems Communications

TRU-COMP2130 Intro to Computer Systems7 Introduction A computer system consists of 1. H… 2. S… that work together to run … Hardware affects the CORRECTNESS and PERFORMANCE of programs.

TRU-COMP2130 Intro to Computer Systems8 1. What is Information? A source program (or source file) – a sequence of bits? #include int main() { printf(“Hello, world\n”); } Bits ??? Bytes ??? ASCII code ??? For each character, a unique byte-sized integer is assigned. Text file ??? Binary file ??? But files are files for operating systems.

TRU-COMP2130 Intro to Computer Systems9 Where are files (or data) stored in a computer system? How is information different from data? The only thing that distinguishes different data objects is the context in which we view. A data object can be interpreted in different ways. E.g., the same sequence of bytes might represent integer, floating-point number (???), character string, machine instruction, … As programmers, we need to understand machine representations of numbers. Details in B&O 2.

TRU-COMP2130 Intro to Computer Systems10 2. Programs and Compilation Systems Can a computer system understand a high-level C program? A high-level C program  translated to  low-level machine-language instructions packaged in a form called executable object program and stored as a binary file. Object programs are also referred as object files. How to translate? Compilers gcc (or cc )

TRU-COMP2130 Intro to Computer Systems11 The compilation system Preprocessing phase #include #define PI Compilation phase Assembly phase Linking phase hello is ready to be loaded into main memory and executed. Being loaded into main memory Being executed Pre- processor ( cpp ) hello.i Compiler ( cc1 ) hello.s Assembler ( as ) hello.o Linker ( ld ) hellohello.c Source program (text) Modified source program (text) Assembly program (text) Relocatable object programs (binary) Executable object program (binary) printf.o

TRU-COMP2130 Intro to Computer Systems12 Compilation systems try to produce correct and efficient machine codes, but lists the errors which it could not understand Reasons to understand how the compilation systems work Optimizing program performance Not easy for them to optimize source codes Understanding link-time errors Especially in the development of a large software system Avoiding security holes Run-time errors

TRU-COMP2130 Intro to Computer Systems13 3. CPU CPU stands for Central Processing Unit Let’s discuss how CPU is used to run programs. Shell, a special application program called a command-line interpreter, accepts commands from the user and execute them. What happens to hello program when we run?

Hardware Organization of a System What happens to hello program when we run? Need to understand the hardware organization that consists of 4 major components: CPU, main memory, buses, i/o devices Main memory I/O bridge Bus interface ALU Registers CPU System busMemory bus Disk controller Graphics adapter USB controller MouseKeyboardDisplay Disk I/O bus Expansion slots for other devices such as network adapters hello executable stored on disk PC

Buses Carry fixed-size bytes known as words 4 bytes (32bits) or 8 bytes (64bits) I/O devices Main memory DRAM Logically a linear array of addressable bytes, each with its own unique address starting at zero CPU (…), or simply processor Register files, or simply registers A register is a word-sized storage device. PC (Program Counter) A special register pointing at (contains the address of) some machine-language instruction stored in main memory; increased after the fetch cycle ALU (???) Compute new data and address values

Only one instruction in main memory, which is pointed by PC, is read (called fetched) by CPU and executed, not multiple instructions. This is called instruction cycle. PC is increased after the instruction fetch so that the next instruction is pointed by PC and read by CPU. Hence programs have to be loaded into main memory to be executed. How to start after the program is loaded into memory? PC must be updated to the address of the first instruction in the program. PC is updated.

TRU-COMP2130 Intro to Computer Systems17 Running the hello Program What happens to hello program when we run?

TRU-COMP2130 Intro to Computer Systems18 Main memory I/O bridge Bus interface ALU Registers CPU System busMemory bus Disk controller Graphics adapter USB controller MouseKeyboardDisplay Disk I/O bus Expansion slots for other devices such as network adapters PC “./hello" User types “./hello" Shell is reading “.\hello” using the services provided by OS.

TRU-COMP2130 Intro to Computer Systems19 Main memory I/O bridge Bus interface ALU Registers CPU System busMemory bus Disk controller Graphics adapter USB controller MouseKeyboardDisplay Disk I/O bus Expansion slots for other devices such as network adapters hello executable stored on disk PC hello code "hello,world\n" Shell is loading “.\hello” using the services provided by OS.

TRU-COMP2130 Intro to Computer Systems20 Main memory I/O bridge Bus interface ALU Registers CPU System busMemory bus Disk controller Graphics adapter USB controller MouseKeyboardDisplay Disk I/O bus Expansion slots for other devices such as network adapters hello executable stored on disk PC hello code "hello,world\n" “.\hello” is now running. Shell then?

TRU-COMP2130 Intro to Computer Systems21 4. Cache From the previous example, we can see that a system spends a lot of time moving information from one place to another. It might take CPU 10 M times longer to read a word from disk than from main memory. This is why hello is loaded into memory before the file is executed by CPU. How is hello executed? hello consists of machine instructions. Only one instruction pointed by PC is read (called fetched) by CPU and executed, not multiple instructions. This is called instruction cycle. Fetch time is much longer than execution time. PC is updated.

TRU-COMP2130 Intro to Computer Systems22 Fetch time is much longer than execution time. Any good idea to solve this processor-memory gap? Hint: The processor can read data from registers almost 100 times faster than from memory.

TRU-COMP2130 Intro to Computer Systems23 Smaller faster and closely located storage device called cache memory, or simply cache Multiple levels could be possible: E.g., L1, L2, L3 How is cache helpful? Programs will be loaded into cache, not memory? Initially programs will be loaded into main memory. Locality – the tendency for programs to access frequently data and code in localized regions; any example code? Important for code optimization Main memory I/O bridge Bus interface ALU Registers CPU chip System busMemory bus Cache memories for (i=0; i<100; i++) sum += i;

TRU-COMP2130 Intro to Computer Systems24 5. Memory Hierarchy Regs L1 cache Main memory (DRAM) Local secondary storage (local disks) Larger, slower, and cheaper (per byte) storage devices Remote secondary storage (distributed file systems, Web servers) Local disks hold files retrieved from disks on remote network servers. Main memory holds disk blocks retrieved from local disks. L2 cache (SRAM) L1 cache holds cache lines retrieved from the L2 cache. CPU registers hold words retrieved from cache memory. L2 cache holds cache lines retrieved from L3 cache L0: L1: L2: L3: L4: L5: Smaller, faster, and costlier (per byte) storage devices L3 cache (SRAM) L3 cache holds cache lines retrieved from memory. L6:

25 6. Operating Systems When the shell loaded and ran the hello program, and when the hello program printed its message, neither program actually accessed the keyboard, display, disk, or main memory directly. Then how? Services including I/O are provided by the operating system. Application programs ProcessorMain memoryI/O devices Operating system Software Hardware ProcessorMain memoryI/O devices Processes Files Virtual memory

TRU-COMP2130 Intro to Computer Systems26 Processes A process is the operating system’s abstract for a running program. Multiple processes can run on the system? (We assume one CPU core.) Logically yes. In the previous example, shell and hello programs. But this is not real parallel processing. This is called multi-processing. The instructions of one process are interleaved with the instructions of another process, using context switching. (all the register values + …) Process AProcess B User code Kernel code User code Kernel code User code Time Context switch Context switch read Disk interrupt Return from read

TRU-COMP2130 Intro to Computer Systems27 Threads A process can consists of multiple execution units, called threads or light-weight processes, each running in the context of the process and sharing the same code and global variables, but different local variables. Very important programming model. Any good example application?

TRU-COMP2130 Intro to Computer Systems28 Virtual Memory A program includes instructions and data, and they will be loaded into memory. The addresses of instruction and data are used in the program. E.g., x = y + 10; Multiple processes should share the fixed-size memory. When a program is loaded next time, the location of the program in memory will be probably different. How to assign memory space to each process? How to let a process (i.e., machine codes) know its location in memory? If processes have to know their location in memory to access variables, programming would become a very difficult job. Do you think in which area in memory you would put variables? How to solve this problem? Virtual (oac logical) address space and physical address space

TRU-COMP Virtual memory is an abstraction that provides each process with the illusion that it has exclusive use of main memory. Each process has the same uniform view of memory, which is known as its virtual address space. Now compilers can compile programs to machine-level instructions. (All instructions in programs use virtual addresses.) Kernel virtual memory Memory mapped region for shared libraries Run-time heap (created by malloc ) User stack (created at runtime) 0 Memory invisible to user code Read/write data Read-only code and data Loaded from the hello executable file printf function 0x (32) 0x (64) Intro to Computer Systems

TRU-COMP2130 Intro to Computer Systems30 Program code and data Machine instructions Global variables Heap Dynamic memory allocation – malloc(), free(), … Shared libraries Shared by multiple process – e.g., C standard library, the math library, … Stack To allocate memory for parameters and local variables as functions are called Kernel virtual memory The part of the operating system Always resident in memory

TRU-COMP2130 Intro to Computer Systems31 Multiple processes have program code and data within the same virtual address space. But they are loaded in different locations in the physical memory.

TRU-COMP2130 Intro to Computer Systems32 Multiple processes have program code and data within the same virtual address space. But they are loaded in different locations in the physical memory. Here is a very critical problem. The program code, i.e., machine instructions, uses virtual addresses in the virtual address space, and the actual code and data are loaded in different physical addresses. When an instruction is fetched and executed by CPU, virtual addresses are used. E.g., pointing to a variable uses the virtual address of the variable, which is different from the physical address of the variable in memory. CPU would access wrong location in the physical memory. How to solve? MMU (Memory Management Unit) – hardware component to translate virtual addresses to physical addresses

TRU-COMP2130 Intro to Computer Systems33 Example

TRU-COMP2130 Intro to Computer Systems34 7. Communications Main memory I/O bridge Bus interface ALU Registers CPU chip System busMemory bus Disk controller Graphics adapter USB controller MouseKeyboardMonitor Disk I/O bus Expansion slots Network adapter Network PC

TRU-COMP2130 Intro to Computer Systems35 Local telnet client Remote telnet server 2. Client sends " hello " string to telnet server 3. Server sends " hello " string to the shell, which runs the hello program, and passes the output to the telnet server 4. Telnet server sends " hello, world\n " string to client 5. Client prints " hello, world\n " string on display 1. User types " hello " at the keyboard