1 / 35

Intro to Computer Systems

Intro to Computer Systems. Winter 2013 COMP 2130 Introduction to Computer Systems Computing Science Thompson Rivers University. Course Objectives. The better knowledge of computer systems, the better programing. Course Contents. Introduction to computer systems: B&O 1, 9.1 – 9.2

scunningham
Download Presentation

Intro to Computer Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Intro to Computer Systems Winter 2013 COMP 2130 Introduction to Computer Systems Computing Science Thompson Rivers University

  2. Course Objectives • The better knowledge of computer systems, the better programing. Intro to Computer Systems

  3. 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.1 – 9.9.2, 9.9.4 – 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.1 – 6.4.2, 6.5, 6.6.2 – 6.6.3, 6.7 • Virtual memory (if time permits): B&O 9.4 – 9.5 Intro to Computer Systems

  4. 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. Intro to Computer Systems

  5. 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. • … Intro to Computer Systems

  6. Unit Contents • What is information? • Programs and compilation systems • CPU • Cache • Memory hierarchy • Operating systems • Communications Intro to Computer Systems

  7. Introduction • A computer system consists of • H… • S… that work together to run … • Hardware affects the … and … of programs. Intro to Computer Systems

  8. 1. What is Information? • A source program (or source file) – a sequence of bits? #include <stdio.h> 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. Intro to Computer Systems

  9. 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. Intro to Computer Systems

  10. 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) Intro to Computer Systems

  11. printf.o Pre- processor (cpp) Compiler (cc1) Assembler (as) Linker (ld) hello.c hello.i hello.s hello.o hello Source program (text) Assembly program (text) Modified source program (text) Relocatable object programs (binary) Executable object program (binary) • The compilation system • Preprocessing phase • #include <stdio.h> • #define PI 3.141593 • Compilation phase • Assembly phase • Linking phase • hello is ready to be loadedinto main memory and executed. • Being loaded into main memory??? • Being executed??? Intro to Computer Systems

  12. Compilation systems try to produce correct and efficient machine codes, but … • 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? Intro to Computer Systems

  13. 3. CPU • CPU stands for … • 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? Intro to Computer Systems

  14. Hardware Organization of a System CPU Registers ALU PC System bus Memory bus • 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 Bus interface I/O bridge I/O bus Expansion slots for other devices such as network adapters USB controller Graphics adapter Disk controller Mouse Keyboard Display Disk hello executable stored on disk

  15. 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

  16. 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.

  17. Running the hello Program • What happens to hello program when we run? Intro to Computer Systems

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

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

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

  21. 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. Intro to Computer Systems

  22. 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. Intro to Computer Systems

  23. CPU chip Registers ALU Cache memories System bus Memory bus • 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 Bus interface I/O bridge for (i=0; i<100; i++) sum += i; Intro to Computer Systems

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

  25. Application programs 6. Operating Systems Software Processes Operating system Hardware Processor Main memory I/O devices Virtual memory • 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. Files Processor Main memory I/O devices

  26. Process A Process B Processes Time User code Context switch read Kernel code User code • A processis 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 + …) Disk interrupt Context switch Kernel code Return from read User code Intro to Computer Systems

  27. 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? Intro to Computer Systems

  28. 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 Intro to Computer Systems

  29. Memory invisible to user code Kernel virtual memory User stack (created at runtime) • 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.) Memory mapped region for shared libraries printf function Run-time heap (created by malloc) Read/write data Loaded from the hello executable file Read-only code and data 0x08048000 (32) 0x00400000 (64) 0 Intro to Computer Systems

  30. 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 Intro to Computer Systems

  31. Multiple processes have program code and data within the same virtual address space. • But they are loaded in different locations in the physical memory. Intro to Computer Systems

  32. 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 Intro to Computer Systems

  33. Example Intro to Computer Systems

  34. CPU chip 7. Communications Registers ALU PC System bus Memory bus Main memory Bus interface I/O bridge Expansion slots I/O bus USB controller Network adapter Graphics adapter Disk controller Mouse Keyboard Monitor Disk Network Intro to Computer Systems

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

More Related