Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Intro to Computer Systems Summer 2014 COMP 2130 Introduction to Computer Systems Computing Science Thompson Rivers University."— Presentation transcript:

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

2 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, …)

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

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

5 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. …

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

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

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

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

10 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 )

11 TRU-COMP2130 Intro to Computer Systems11 The compilation system Preprocessing phase #include #define PI 3.141593 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

12 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

13 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?

14 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

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 TRU-COMP2130 Intro to Computer Systems17 Running the hello Program What happens to hello program when we run?

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

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

20 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?

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

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

23 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;

24 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 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

26 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

27 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?

28 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

29 TRU-COMP2130 29 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 0x08048000 (32) 0x00400000 (64) Intro to Computer Systems

30 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

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

32 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

33 TRU-COMP2130 Intro to Computer Systems33 Example

34 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

35 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


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

Similar presentations


Ads by Google