# Chapter 1 Introduction :::info Professor skips the following section: - 1.7 Virtualization - 1.8 Distributed Systems - 1.9 Kernel Data Structures - 1.10 Computing Environments ::: ## Outline [TOC] ## Definition of Computer System Components - **CPU**: The hardware that executes instructions. - **Processor**: A physical chip that contains one or more CPUs. - **Core**: The basic computation unit of the CPU. - **Multicore**: Multiple processing cores within the same CPU chip or within a single system. - **Multicore Processor**: Multiple processing cores within the same CPU chip. - **Multiprocessor**: Multiple processors (CPU cores) within the same CPU chip or within a single system. ## 1.1 What Operating System Do? ##### What is operating system? :::spoiler Ans 1. A software that acts between users/applicatons and computer hardware. 2. Running at all times on the computer ::: ## 1.2 Computer System Organization ### Definition **Interrupt:** A signal driven by hardware. #### Device controller (hardware) ##### What is a computer system? :::spoiler Ans A computer system consists of CPUs and multiple device controllers, connect through a bus. ::: ## 1.3 Computer-System Architecture ### Definition _Multiprocessor System:_ ~ A system which processors are *single-core CPUs*. The processor *share the computer bus* and sometimes the clock, memory, and peripheral devices. _Non-uniform Memory Access, NUMA (for multiprocessor):_ ~ This approach provide *each CPU with its own local memory* that is accessed via a small, fast local bus. The CPUs are connected by a *shared system interconnect*. _Blade Servers:_ ~ A system which *multiple processor boards*, I/O boards and networking boards are *placed in the same chasis*. Each blade-processor board *boots independently* and runs its *own operating system*. _Clustered Systems:_ ~ A system is composed of *two or more individual systems* (or nodes). Such systems are considered *loosly coupled*. The clustered computers *share storage* and are *closely linked via a local-area network LAN*. - **high-availaility service:** A service that will continue if one or more systems in the cluster fail. - **gracefule degradation:** The ability to continue providing service proportional to the level of surviving hardware ## 1.4 Operating-System Operations Operating Systems are **event-driven**. ### Definition _System Daemons:_ ~ The system programs run the entire time the kernel is running. _Trap (or Exception):_ ~ Trap is Another form of interrupt, which is a *software-generated interrupt* caused either by an *error* or by a specific *requst from a user program* by a *system call* _System Call:_ ~ A special operation from a *request of user program* calling a operating-system service. #### 1.4.1 _Multiprogramming:_ ~ The ability to run multiple programs and keep either the CPU or the I/O devices *busy at all times*. _Multitasking:_ ~ Multitsking is a logical extension of multirogramming. The CPU executes multiple processes by switching among them, but the *switches occur frequently*, providing the user with a fast response time. - I/O may be interactive. #### 1.4.2 _Dual-Mode Operation:_ ~ To ensure that an *incorrect program cannot cause other programs or the operating system itself to execute incorrectly*, we can distinguish between the execution of *operating system* code and one *user-defined* code. ~ We need at least two separate modes of operation: ~ - **User mode (1)** ~ - **Kernel mode (supervisor mode, systme mode, or privileged mode)(0)** - **Priveleged instructions** _Multi-Mode Operation:_ ~ The concept of modes are extended beyond two modes. - **Protection rings** EX: Intel processors: ring 0 is kernel mode and ring 3 is user mode. #### 1.4.3 _Timer:_ ~ A timer which can be set to interrupt the computer after a spedified period. ## 1.5 Resource Management ### 1.5.1 Process Management - A program can do nothing unless its instructions are executed by a CPU. - "A **program in execution**"" is a **process**. - A **multithreaded process** has **multiple program counters**, each program counter pointing to the next instruction to execute for a given thread. - All processes can potentially execute **concurrently** by multiplexing on a single CPU core or **in parallel** across multiple CPU cores. ## Practice Exercises (Accodring to the textbook's question number) #### 1. What are the three main purposes of an operating system? :::spoiler Ans 1. To provide an **environment** for a computer user to **execute programs on computer hardware** in a convenient and efficient way. 2. To **allocate separate resources** of the computer as needed to perform the required tasks. 3. As a control program, it serves two major functions: (1) supervision of user programs to **prevent error and improper execution** (2) **management of operation** and control of I/O devices. My answer: 1. Communicate between software programs and hardware device. 2. Deal with the concurrence of threads. 3. Give users the secutity to retrieve data. ::: #### 3. What is the main difficulty that a programmer must overcome in writing an operating system for a real-time environment? :::spoiler Ans The main difficulty is keeping the operating system **within the fixed time constraints** of a real-time system. If the system does not complete the task in a certain time frame, it may cause a *breakdown* of the entire system. Therefore, when writing an operating system for a real-time system, the writer can't allow the **response time** to exceed the time constraint. My answer: The point which is difficult to do is to allocate time period to all user programs with stability and no error. ::: #### 5. How does the distinction between kernel mode and user mode function as a rudimentary form of protection (security)? :::spoiler Ans **Certain instructions** can be executed only when the *CPU* is in the kernel mode. **Hardware devices** can be *accessed* only when the *program* is in the kernel mode. **Interrupts** can be *enabled* or *disabled* only when the *CPU* is in the kernel mode. Consequently, the CPU has very limited capability when executing in the user mode, thereby enforcing the **protection of critical resources**. My Answer: Having a kernel mode can prevent the system from illegal interruption. This kind of system would give the interrupt authorization when it's in the specific situation. ::: #### 6. Which of the following instructions should be privileged? a. Set value of timer. b. Read the clock. c. Clear memory. d. Issue a trap instruction. e. Turn off interrupts. f. Modify entries in device-status. g. Switch from user to kernel mode. h. Access I/O device. :::spoiler Ans The following operations need to privileged: a. Set value of timer. <--- c. Clear memory. e. Turn off interrupts. f. Modify entries in device-status. h. Access I/O device. My answer: c, e, f, h ::: #### 9. Timers could be used to compute the current time. Provide a short description of how this could be accomplished. :::spoiler Ans A program can set a timer for some time in the future and go to sleep. When awakened by the interrupt, it could update its local state, which it keeps track of the number of interrupts it has received thus far. Given the start time point, We can compute the current time by repeating this process of continually setting the timer interrupts and updating its local state. My answer: Because the timer **interrupt the CPUs in a specified period**, we can use this given period to calculate the time period between the starting point of the timer we set and the finshing point we designate. ::: #### 10. Give two reasons why caches are useful. What problems do they solve? What problems do they cause? If a cache can be made as large as the device for which it is caching (for instance, a cache as large as a disk), why not make it that large and eliminate the device? :::spoiler Ans (1) Caches are useful when two or more components need to **exchange data**, and the components perform **transfer at differing speeds**. Caches solve the transfer problem by providing a **buffer of intermediate speed** between the components. If the fast device finds the data in the cache, it **need not wait for the slower device**. :::