CSAPP_1_计算机系统漫游

Posted on Jun 3, 2022

The goal got this book is to help you underestand what happens and why when you run programmer on a system.

 

compilation system (contains 4 parts as follows)

  • Preprocessing phase: modifies the original C program, list exchange include code.
  • Compilation phase: translate text file to assembly-language program. Assembly-language is useful because it provides a common output language for different compilers for different high-level languages.
  • Assembly phase: translate assemly-language to machine-language instruction, packages them in a from known as a relocatable object program, and store in the object file hello.o
  • Linking phase: hello program use standard C library(printf.o). The linker merge hello.o and printf.o and create the hello file, which is an executable object file.

some reasons why programmers need to understand how compliation systems word

  • Optimizing program performance: in order to make good coding decisions in programs, we do need a basic understanding of machine-level code and how the compiler translates different C statements into machine code. [chapter 3, 6]
  • Understanding link-time errors: For example: what does it mean when the linker reports hat it cannot resolve a reference? What id the difference between a static library and a dynamic library? [chapter 7]
  • Avoiding security holes: Too few programmers understand the need to carefully restrict the quantity and forms of data they accept from untrustes sources. [chapter 3]

 

Hardware orgnization of a system

  • Buses: Running throughout the system is a collection of electrical conduits called buses that carry bytes of information back and forth between the components.
  • I/O devices: I/O devices are the system`s connection to the external world. For example keyboard, mouse and disk drive.
  • Main memory: The main memory is a temporary storage device that holds both a program and the data it manipulates while processor is excuting the program.
  • Processor: The central processing uint(CPU), or simply processor, is the engine that interprets (or executes) instructions stored in main memory.

  ⭐️application programmers who are aware of cache memories can exploit them to improve the performance of their programs by an order of magnitude.

The operating system has two primary purposes:

  • to protect the hardware from misuse by runaway applications.
  • to provide applications with simple and uniform mechanisms for manipulating complicated and often wildly different low-level hardware devices.

The operating system achieves both goals via the fundamental abstractions shown in Figure 1.11: processes, virtual memory, and files.

  • Processes: A process is the operating system’s abstraction for a running program.
  • Threads: Although we normally think of a process as having a single control flow, 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.
  • Files: A file is a sequence of bytes, nothing more and nothing less. Every I/O device, including disks, keyboards, displays, and even networks, is modeled as a file. All input and output in the system is performed by reading and writing files, using a small set of system calls known as Unix I/O.
  • Virtual Memory: Virtual memory is an abstraction that provides each process with the illusion that it has exclusive use of the main memory.

Concurrency and Parallelism

  • Processes Concurrency: All programs can be processed simultaneously by switching between threads or processes on one CPU core.
  • Processes Parallelism: Multiple CPU cores executing different processes or threads at the same time
  • Instruction-Level Parallelism: At a much lower level of abstraction, modern processors can execute multiple instructions at one time.
  • 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.