CS:ASP-Chapter 1

CS:ASP

Chapter 1

1.1 Information Is Bits + Context

All information in a system—including disk files, programs stored in memory, user data stored in memory, and data transferred across a network—is represented as a bunch of bits.
The only thing that distinguishes different data objects is the context in which we view them.

in different contexts, the same sequence of bytes might represent an integer, floating-point number, character string, or machine instruction.

1.2 Programs Are Translated by Other Programs into Different Forms

#include <stdio.h>

int main()
{
	printf("hello, world\n");
	return 0;
}

high-level C program for human beings to read and understand

hello.c needs to be translated into a sequence of low-level machine-language instructions for machine to execute
在这里插入图片描述

linux> gcc -o hello hello.c
  1. Preprocessing phase

    The preprocessor (cpp) modifies the original C program according to directives that begin with the ‘#’ character.The result is another C program, typically with the .i suffix.

  2. Compilation phase

    The compiler (cc1) translates the text file hello.i into the text file hello.s, which contains an assembly-language program.

  3. Assembly phase

    The assembler (as) translates hello.s into machinelanguage instructions, packages them in a form known as a relocatable object program, and stores the result in the object file hello.o.

  4. Linking phase

    The printf function is part of the standard C library provided by every C compiler. The printf
    function resides in a separate precompiled object file called printf.o, which must somehow be merged with our hello.o program. The linker (ld) handles this merging.

1.3 Processors Read and Interpret Instructions Stored in Memory

At this point, our hello.c source program has been translated by the compilation system into an executable object file called hello that is stored on disk. To run the executable file on a Unix system, we type its name to an application program known as a shell:

linux> ./hello
hello, world
linux>

Buses

Running throughout the system is a collection of electrical conduits called buses that carry bytes of information(4 bytes or 8 bytes ) back and forth between the components.

I/O Devices

Input/output (I/O) devices are the system’s connection to the external world.Each I/O device is connected to the I/O bus by either a controller or an adapter.The purpose of them is to transfer information back and forth between the I/O bus and an I/O device.

在这里插入图片描述

Main Memory

The main memory is a temporary storage device that holds both a program and the data it manipulates while the processor is executing the program.

Physically → a collection of dynamic random access memory (DRAM) chips.

Logically → a linear array of bytes, each with its own unique address (array index) starting at zero.

Processor

The central processing unit (CPU), or simply processor, is the engine that interprets (or executes) instructions stored in main memory.At its core is a word-size storage device (or register) called the program counter (PC).At any point in time,the PC points at (contains the address of) some machine-language instruction in main memory.

when the system is powered on,a processor repeatedly executes the instruction pointed at by the
program counter and updates the program counter to point to the next instruction.

instruction set architecture is a instruction execution model,In this model, instructions execute in strict sequence, and executing a single instruction involves performing a series of steps.

The processor reads the instruction from memory pointed at by the program counter (PC), interprets the bits in the instruction, performs some simple operation dictated by the instruction, and then updates the PC to point to the next instruction, which may or may not be contiguous in memory to the instruction that was just executed.

Running the hello Program

在这里插入图片描述

  1. type the characters ./hello at the keyboard

    the shell program reads each one into a register and then stores it in memory

  2. hit the enter key on the keyboard

    The Shell loads the executable hello file by executing a sequence of instructions that copies the code and data in the hello object file from disk to main memory.

    the string of characters hello, world\n that will eventually be printed out.

  3. use direct memory access(DMA)

    the data travel directly from disk to main memory, without passing through the processor

    在这里插入图片描述

    1. Writing the output string from memory to the display

      These instructions copy the bytes in the hello, world\n string from memory to the register file, and from there to the display device, where they are displayed on the screen.

      在这里插入图片描述

    1.4 cache matters

    The machine instructions of the hello program are initially stored on the hard disk, and when the program is loaded, they are copied to main memory; when the processor runs the program, the instructions are copied from main memory to the processor…

    Such a copy operation is a consumption to the system, and because the processor reads data from the register file much faster than from main memory, the system designer uses cache memories serve as temporary staging on the CPU chip. areas for information that the processor is likely to need in the near future.

    It might take 5 times longer for the processor to access the L2 cache than the L1 cache, but this is still 5 to 10 times faster than accessing the main memory

    The idea behind caching is that a system can get the effect of both a very large memory and a very fast one by exploiting locality, the tendency for programs to access data and code in localized regions. By setting up caches to hold data that are likely to be accessed often, we can perform most memory operations using the fast caches.

    在这里插入图片描述

    1.5 Storage Devices Form a Hierarchy

在这里插入图片描述

As we move from the top of the hierarchy to the bottom, the devices become slower, larger, and less costly per byte.

The register file → level 0

three levels of caching L1 to L3 → L1-L3

Main memory → level 4

storage at one level serves as a cache for storage at the next lower level.

On some networked systems with distributed file systems, the local disk serves as a cache for data stored on the disks of other systems.

1.6 The Operating System Manages the Hardware

We can think of the operating system as a layer of software interposed between the application program and the hardware.

在这里插入图片描述

operating system‘s purposes:

  1. to protect the hardware from misuse by runaway applications
  2. to provide applications with simple and uniform mechanisms for manipulating complicated and often wildly different low-level hardware devices.
    files are abstractions for I/O devices
    virtual memory is an abstraction for both the main memory and disk I/O devices
    processes are abstractions for the processor, main memory, and I/O devices

在这里插入图片描述

  • Process

A process is the operating system’s abstraction for a running program

The operating system keeps track of all the state information that the process needs in order to run. This state, which is known as the context, includes information such as the current values of the PC, the register file, and the contents of main memory.

When the operating system decides to transfer control from the current process to some new process, it performs a context switch by saving the context of the current process, restoring the context of the new process, and then passing control to the new process. The new process picks up exactly where it left off.

在这里插入图片描述

  • kernel

    it is a collection of code and data structures that the system uses to manage all the processes

There are two concurrent processes in our example scenario:
the shell process and the hello process.

Initially, the shell process is running alone, waiting for input on the command line. When we ask it to run the hello program, the shell carries out our request by invoking a special function known as a system call that passes control to the operating system. The operating system saves the shell’s context, creates a new hello process and its context, and then passes control to the new hello process. After hello terminates, the operating system restores the context of the shell process and passes control back to it, where it waits for the next command-line input.

  • Threads

In modern systems a process can actually consist of multiple execution units, called threads, each running in the context of the process and sharing the same code and global data. Threads are an increasingly important programming model because

  • the requirement for concurrency in network servers
  • it is easier to share data between multiple threads than between multiple processes
  • threads are typically more efficient than processes. Multi-threading is also one way to make programs run faster when multiple processors are available
  • Virtual Memory

Virtual memory is an abstraction that provides each process with the illusion that it has exclusive use of the main memory. Each process has the same uniform view of memory, which is known as its virtual address space.
在这里插入图片描述

1.7 Systems Communicate with Other Systems Using Networks

When the system copies a sequence of bytes from main memory to the network adapter, the data flow across the network to another machine, instead of, say, to a local disk drive. Similarly, the system can read data sent from other machines and copy these data to its main memory.

在这里插入图片描述

Using telnet to run hello remotely over a network

在这里插入图片描述

we type in the hello string to the telnet client and hit the enter key, the client sends the string to the telnet server. After the telnet server receives the string from the network, it passes it along to the remote shell program. Next, the remote shell runs the hello program and passes the output line back to the telnet server. Finally, the telnet server forwards the output string across the network to the telnet client, which prints the output string on our local terminal.

1.8 Important Themes

Concurrency and Parallelism

  1. Thread-Level Concurrency

    1. uniprocessor system.

      this concurrent execution was only simulated, by having a single computer rapidly switch among its executing processes.

    在这里插入图片描述

    1. multi-core processors

      Multi-core processors have several CPUs (referred to as “cores”) integrated onto a single integrated-circuit chip.

    在这里插入图片描述

    1. Hyperthreading

      It allows a single CPU to execute multiple flows of control. It involves having multiple copies of some of the CPU hardware, such as program counters and register files, while having only single copies of other parts of the hardware, such as the units that perform floating-point arithmetic.

  2. Instruction-Level Parallelism

    processors can execute multiple instructions at one time, a property known as instruction-level parallelism

    Processors that can sustain execution rates faster than 1 instruction per clock cycle are known as superscalar processors.

  3. Single-Instruction, Multiple-Data (SIMD) Parallelism

    At the lowest level, many modern processors have special hardware that allows a single instruction to cause multiple operations to be performed in parallel, a mode known as single-instruction, multiple-data (SIMD) parallelism.

    For example,recent generations of Intel and AMD processors have instructions that can add 8
    pairs of single-precision floating-point numbers (C data type float) in parallel.

    These SIMD instructions are provided mostly to speed up applications that process image, sound, and video data.

The Importance of Abstractions in Computer Systems
在这里插入图片描述

Some abstractions provided by a computer system.

A major theme in computer systems is to provide abstract representations at different levels to hide the complexity of the actual implementations.

  1. files as an abstraction of I/O devices.
  2. virtual memory as an abstraction of program memory.
  3. and processes as an abstraction of a running program.
  4. the virtual machine, providing an abstraction of the entire computer, including the operating system, the processor, and the programs.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值