[Reading notes] in-depth understanding of computer systems: Chapter 1 - computer system roaming

The computer system roaming

Information is context-bit +

All programs and data on a computer is constituted by one bit (i.e., bit, bit). While each bit is only two states 0 and 1, typically 8 bits are grouped into a group, called a byte (i.e. byte).
All the information system - comprises a disk file, a program memory, the user data stored in the memory and a data transmission on the network, are represented by a series of bits, and the only way to distinguish these data objects that we read context of these data objects.
For example, in different contexts, a similar sequence of bytes may be represented as an integer, float, string or machine instructions.
As a programmer, we should not be satisfied with the surface of the data, but should look under the hood, a real understanding of data representation on the machine. For example: integer and floating point numbers in fact the expression on the machine and in fact, our experience is different, they are limited approximation of the true value. Sometimes there will be unexpected behavior.

Acquaintance build system

A program that can be understood by people from high-level programming language (eg C language) into machine language, is due to the build system.
In an example gcc compiler system (compilation system) by the preprocessor (CPP), a compiler (CCL), the assembler (as) and linker (id) configuration.

Pre-processing stage

The command preprocessor beginning with the character #, modify the original C program, the instruction pre-processed text insertion procedure, another procedure C to give as a suffix .i.

Compile phase

The compiler will translate the text file C program become an assembly language program text file to .s as a suffix.
Assembly language is very useful because it provides a common language for different output different high-level language compilers. (Example: C compiler and Fortran compiler output file scraps assembly language are the same)

Compilation stage

Next, the assembler will .s translated into machine language instructions, the instructions packaged into a relocatable object program format is called, and the result is stored in the file .o object file format.
.o file format is a binary file.

Link stage

If the program uses the library functions such as printf, the linker will have been handled well printf.o merged into an existing file.
The final goal into an executable file.

For starters, I do not know the build system does not affect our program, but we understand the build system for the actual programming is of great help, as follows.

1. Understand the underlying representation of the program, it can help us choose a better programming in certain aspects.

2. To understand the error that occurs when the link instruction can not be resolved easily when writing large programs, understand the compiler system can learn more about global and local variables.

3. To avoid security breaches, learning safety program is the first step to understand the consequences of the way data and control information stored on the program stack will cause.

Hardware composition

bus

Throughout the electronic system is a set of pipes, referred to as a bus, carrying his bytes of information and for transmitting the respective member. Typically bus transfer byte fixed-length blocks.

I / O device

I / O device is an output device that is input to the channel system outside world. Common input device is a mouse, a keyboard, an output device with a display, a printer, a hard disk. Each I / O devices or / O bus is connected to a controller via I adapter.

Main memory (RAM)

Main memory is a temporary storage device, when the processor executes the program, and a program for storing the data processing program. Physically, by a set of dynamic random access memory DRAM chips.

processor

Referred to as CPU, it is stored in the engine that interprets and executes instructions stored in main memory. Core processor for the PC (instruction register), it always points to the address of one instruction. The ALU (arithmetic logic unit) to perform some arithmetic or logical operations.

(Note: Generally regarded book external memory (disk, hard disk) to separate out, the book is classified as directly to the output device I / O devices, there is a certain sense)

The importance of cache

The mechanical principle, a large storage device to a relatively small storage devices run slower, and the cost of the device quickly than low-speed device is higher, so the access speed than the main memory is much slower memory register.
To solve this problem, system designers put in main memory, cache memory, as a temporary staging area information, stored information may be required in the near future.
Three levels of cache, from L1 to L3, decreasing access speed, memory size increment.
Most operations can be done in fast memory cache, which greatly accelerated the speed of the system.
As a programmer, if aware of the role of the cache, the cache can be utilized to improve the performance of the program an order of magnitude.

Hierarchical Storage devices

The cache thought mentioned above, we realize that different memory vary in performance, generally in the same computer, a computer storage hierarchy shown below.

The main idea of ​​the memory hierarchy is the layer of the first layer memory of the memory cache. For example, L1 is L2 cache.

Operating Systems management hardware

In addition to some of the details of the program can improve performance, we in the preparation of the program and does not come into contact with the software between the hardware, applications and hardware we called the operating system.
Operating system has two basic functions:

1. Application hardware is prevented runaway abuse;

2. To provide a simple and consistent mechanism for the application to control complex and very different from the usual low-level hardware devices.

The simple consistent mechanism mentioned above is the operating system abstraction of hardware.

They are:
file - an abstract representation of the operating system I / O devices (should mainly refers to the external memory);
virtual memory - an abstract representation of the operating system main memory and disk I / O devices;
process - operating system abstract processor, main memory and I / O devices represented;

process:

Applications running on modern operating systems, the operating system will provide an illusion, as if this is the only program on the system running. The program appears to be exclusively used by a processor, main memory and I / O devices.
Process is the operating system running on a abstract play an abstraction. You can run multiple processes simultaneously on a single system, and each process seems to exclusively use the hardware. And running concurrently , it is said that a process of instruction and another process is staggered execution. Staggered implementation of multiple CPU in the process of what we call a context switch.
To achieve this abstraction process requires close cooperation between the low-level hardware and operating system software, computer science course is one of the most important and most successful concept.

Thread

In modern operating systems, in fact, a process may be referred to by a plurality of threads of execution units, each thread running in the context of the process, and share the same code and global data.

Virtual Memory

Virtual memory is an abstract concept, it provides an illusion for each process, each process in the exclusive use of main memory. Each process see the memory are the same, called virtual memory space . As shown below (FIG address is increased from the bottom)

The following is a brief description of each partition:

Program codes and data area

For all processes, the code is starting from the same fixed address, followed by a global variables and data corresponding to the location.

Heap

After the code and the data area is the runtime stack when calling malloc, free (C), new, when the delete (C ++), the stack can be dynamically expand and contract.

Share Reservoir

Approximately intermediate portion is an address space used to store the code and data regions like the C standard library and the math library of such a shared library.

Stack

Located at the top of the user virtual address space is the user stack, the compiler uses to achieve the function call. And heap, users can stack dynamically expand and contract during program execution

Kernel virtual memory

Area at the top of the address space is reserved for the kernel. Allowed applications to read and write this kernel code region or function defined for the immediate caller.

Virtual memory operations are very complex. The basic idea is it a process on the virtual disk and main memory as a disk cache memory content storage.

file

File is a sequence of bytes, and nothing more. Each I / O devices, including a disk, a keyboard, a display, and even the network, can be viewed as a file. All system functions are input output system by using a group called Unix I / O calls to read and write files to achieve.
File this simple and elegant concept is very powerful, because it wants the application to provide a unified view of all to look at a wide range of I / O devices in the system contains. For example, when dealing with the contents of a disk file, programmers need to understand the specific disk technology.

(Here referred to the book simple network, but only roughly say a little ways and network file transfers, nothing substantial dry, then skipped behind the particular time and then carefully studied)

Other knowledge

Amdahl's Law

When we accelerate to a certain part of the system, its impact on the overall performance of the system depends on the importance and the degree of acceleration of the part. If the system needs to execute an application time Told. Suppose a part of the execution time required by the system to change the time ratio α, and the performance ratio of the portion to be k. I.e., the time required for the initial part αTold, now is the time required (αTold) / k. Therefore, the total execution time is:

Tnew = (1-a) Told + (aTold) / k = Told [(1-a) + a / k]

Thereby, it is possible to calculate the speedup S = Told / Tnew is
S = 1 / [(1-a) + a / k]

Main points Amdahl's law - wants to significantly speed up the whole system, the whole system must be raised in a large part of the rate.
Amdahl's Law is an interesting special case when considering the effect of k tends to ∞. This means that we can take a part of the system to accelerate to almost take time, so this time:
S = 1 / (1-a)

Concurrent and Parallel

Read, temporarily slightly.

The importance of computer systems in the abstract

Abstraction is one of the most important computer science concepts. For example, a set of functions prescribed a simple application programming interface (API) is a good programming practice, call the API function programmers need to understand is how to achieve, just use this function to complete their procedures.
(On the abstract, I will have time to write a blog specifically to comb it again from computer hardware to software abstraction layer by layer).

to sum up

这一章主要把本书的主要内容概述了一遍,同时也是对整个计算机系统的概述,因为我在读这本书时只有C语言和数据结构的基础,所以初次读处处碰壁,读哪哪都不懂,感觉自己是不是读这本书读的太早了,后来在知乎上看到一位网友说这本书不是让人一遍读完的,这本书是需要你在碰壁时放下书去学习,回过头来发现能看懂时继续读,直到把计算机专业的所有课程学完,这本书也就读完了。才感觉恍然大悟。
这里要向和我一样的初学者推荐一个视频课程: [Crash Course:Computer Science]open.163.com/movie/2018/5/M/S/MDGEPAQ4K_MDGET74MS.html 这个系列视频并没有教我们编程,而是从计算机的历史入手,把计算机所有的基础专业课概述了一遍,甚至还有几乎所有计算机科学的研究方向的概述:人工智能,计算机图形学,计算机视觉等等。。十分详尽,配的动画也很有趣,是读这本书的一个好向导。
借知乎网友的话:“这是一份地图,不是一个世界”。希望能在这份地图的指引下,踏踏实实的把计算机科学的世界从过去到未来完整地走一遍。

Guess you like

Origin www.cnblogs.com/z-y-k/p/11267543.html