CSCI 2122 Lecture 2 Introduction - PDF

Summary

This document presents an introduction to computer architecture concepts. It explores program translation, execution, and the role of the operating system. The lecture slides delve into data representation, memory hierarchies, and fundamental abstractions like processes and files, providing a foundation for understanding how computer systems work.

Full Transcript

CSCI 2122: LECTURE 2 Introduction LECTURE PLAN Information: Bits + Context Data vs Information Program Translation Program Execution Caching and Storage Role of the Operating System TO PROGRAM A SYSTEM ONE NEEDS TO UNDERSTAND THE SYSTEM Key Idea 1: All computers hav...

CSCI 2122: LECTURE 2 Introduction LECTURE PLAN Information: Bits + Context Data vs Information Program Translation Program Execution Caching and Storage Role of the Operating System TO PROGRAM A SYSTEM ONE NEEDS TO UNDERSTAND THE SYSTEM Key Idea 1: All computers have the same basic components: Hardware CPU / Processor RAM / Memory Disks / Storage Software Operating system Programs System utilities Applications Key Idea 2: These components are all interdependent. A computer will be useless if one of these components is missing or if these components do not work together As computer scientists, we are focused on the software. Key Idea 3: To understand and develop software, we need to understand everything else! WHAT DO WE NEED TO UNDERSTAND? 1. How to manipulate information: Purpose of programs is to produce and manipulate information. Information = Bits + Context 2. How Programs are translated Translation must reconcile between program & hardware requirements Program may use very large numbers, but hardware supports 32-bit operations Single program instruction may become many machine instructions Much of the program code is taken from libraries 3 How programs are executed Depends on the Architecture/Organization of the hardware 4 How programs are affected by their environment The Operating System The Memory Architecture and Caching INFORMATION = BITS + CONTEXT What does that mean? Data by itself has no meaning. Data derives its meaning from interpretation or its context Data can have the same meaning but have different representations For example, a program could be in ASCII Hex Binary etc. Consider hello.c What is the data behind it? #include int main() { printf(“Hello, World!\n”); return 0; } 1/9/2025 5 DATA V/S INFORMATION 1/9/2025 6 SAME DATA DIFFERENT MEANINGS 1/9/2025 7 SAME DATA DIFFERENT REPRESENTATIONS 1/9/2025 8 SAME INTEGERS DIFFERENT REPRESENTATIONS 1/9/2025 9 CONTEXT MATTERS In ordert to make data meaningful, we need context to interpret the data. Does hello.c contain: Text 8-bit integers 32-bit integers etc This applies to all information in a system! Files Memory CPU Everything is up to interpretation. To manipulate a system, we need to know how data is represented and interpreted in the system. 1/9/2025 10 PROGRAM TRANSLATION Program translation is a fundamental part of systems. Programs are typically translated multiple times to allow them to run on a system: For example: Java program (.java) ➔ byte code (.class) ➔ machine code (running on JVM) C program (.c) ➔ assembly (.s) ➔ object code (.o) ➔ executable At each stage of translation the program is transformed Each stage depends on the previous stage and the translator Each affects the final version! 1/9/2025 11 THE C COMPILATION CHAIN 1/9/2025 12 THE ASSEMBLY FILE 1/9/2025 13 WHY DO WE CARE? Optimizing Program Performance We want to write efficient code Some code choices will result in better performance Switch statements vs if statements For loops vs while loops vs do while loops References vs indexing operations Avoiding Security Holes Understanding how programs are compiled avoids security bugs Stack overflow errors Buffer overflow errors Uninitialized memory Understanding Linking Errors Multiple definitions of global variables and functions Variable and function definitions in header files Linking order issues 1/9/2025 14 PROGRAM EXECUTION Programs are Executed on the Computer Program execution intrinsically depends on the hardware CPU (Processor) Instruction Set Word size (16-bit, 32-bit, 64-bit) Implementation of the CPU RAM (Memory) Amount of memory available Speed of the memory Caching Bus (interconnect between devices) Word-size Speed Coherency protocols 1/9/2025 15 THE HARDWARE 1/9/2025 16 FETCH-DECODE-EXECUTE CPU performs an infinite loop Fetch next instruction from memory (location is in PC) Decode instruction Execute instruction Execution of an instruction may involve Reading from or writing to memory Modifying registers and other CPU state Jumping to other locations in the program (modifying the PC) 1/9/2025 17 SOME INSTRUCTIONS ARE FASTER THAN OTHERS Instructions that access memory are slower Memory accesses require data transfers across the bus Two words of data to be transferred per read or write Memory is slower than the CPU, causing the CPU to wait for memory accesses We can make programs faster by Reducing the number of memory accesses Making memory accesses cache-friendly Key Idea: We can speed up computation by speeding up memory access 1/9/2025 18 CACHES CAN SPEED UP EXECUTION A cache is a smaller, faster staging memory that sits between the Storage being accessed (main memory) and The component accessing the storage (CPU) A cache speeds up computation by storing commonly accessed data, reducing the number of times main memory has to be accessed Caches are usually much smaller than main memory because they are Closer to the components (on the CPU) Are much more expensive 1/9/2025 19 THE MEMORY HIERARCHY Inserting faster storage between the processor and a larger, slower storage is a general idea. Each level of storage acts as a cache for the level below it. To write efficient programs, we need to understand: Where the data is stored When the data is used Where the data is cached Focus of the second half of the term Who manages the caches? 1/9/2025 20 THE ROLE OF THE OPERATING SYSTEM Manage the computer hardware CPU, I/O devices, RAM, Etc. Provide an execution environment for programs Act as an intermediary between computer, user, and programs Protect the hardware, programs, and users from each other Provide abstractions through which computer resources are accessed 1/9/2025 21 RESOURCES AND ABSTRACTIONS CPU Process RAM Memory Address Space Secondary Storage (eg HD) File Network File Peripheral Devices File 1/9/2025 22 THREE KEY ABSTRACTIONS 1/9/2025 23 THE FUNDAMENTAL ABSTRACTIONS: PROCESSES 1/9/2025 24 FUNDAMENTAL ABSTRACTIONS: VIRTUAL MEMORY 1/9/2025 25 FUNDAMENTAL ABSTRACTIONS: FILES Files: A file is a sequence of bytes Every I/O device, including displays, keyboards Even the network – are modelled as files. Files provide applications with a uniform view across many typers of I/O devices. 1/9/2025 26 PROCESS COMPOSITION A process is composed of CPU context Memory space Thread of execution (1 or more) CPU context General registers Program counter Special purpose registers Memory space Stack : local variables and return addresses Heap : dynamically allocated memory Data : global and static variables Code : program code 1/9/2025 27 THREAD OF EXECUTION A thread is an active execution of program code Location is stored in PC, which points to the current instruction The thread of execution depends only on the CPU context and memory 1/9/2025 28 KEY TAKE-AWAY POINTS Information is data + context Data can be represented in different ways Data can be interpreted in different ways Programs must be translated before they can be executed. Translation affects execution. Execution depends on the hardware components and architecture of the system as well as the operating system. Memory and storage access is a dominant cost in execution. Systems are architected to mitigate the cost of access. The operating system is responsible for managing the computer system and provides the mechanisms, abstractions, and environment for execution to take place. 1/9/2025 29

Use Quizgecko on...
Browser
Browser