您的位置:首页 > 移动开发

《CS:APP》 chapter 1 A Tour of Computer Systems 笔记

2014-04-23 18:31 645 查看

A Tour of Computer Systems

          If you dedicate yourself to learning the concepts in this book, then you will be on your way to becoming a rare “power pro-grammer”

 就冲这句话,就已经很“霸气”了。

一切从这里开始:
#include <stdio.h>

int main()
{
printf("hello world!\n");

return 0;
}


1.1 Information Is Bits + Context

Everthing is file。 多么漂亮的极简主义啊!

liuzjian@ubuntu:/CSAPP/chapter_1$ od -t oCc ./pro_1_1.c 
0000000 043 151 156 143 154 165 144 145 040 074 163 164 144 151 157 056
#   i   n   c   l   u   d   e       <   s   t   d   i   o   .
0000020 150 076 012 012 151 156 164 040 155 141 151 156 050 051 012 173
h   >  \n  \n   i   n   t       m   a   i   n   (   )  \n   {
0000040 012 011 160 162 151 156 164 146 050 042 150 145 154 154 157 040
\n  \t   p   r   i   n   t   f   (   "   h   e   l   l   o
0000060 167 157 162 154 144 041 134 156 042 051 073 012 012 011 162 145
w   o   r   l   d   !   \   n   "   )   ;  \n  \n  \t   r   e
0000100 164 165 162 156 040 060 073 012 175 012
t   u   r   n       0   ;  \n   }  \n
0000112


      咳咳、、、C是系统级别的编程语言,同样也可以做应用,但是不是很方便。像C++和java之类的就做了很多抽象,面向对象相对容易。所以我特别不喜欢那种黑我大C的人,动不动就把C踢出窗外,你可知道C经历了几十年的风雨,依然在TIOBE上面的排名第一。

      C is the language of choice for system-level programming, and there is a huge installed base of application-level programs as well. However, it is not perfect for all programmers and all situations.C pointers are a common
source of confusion and programming errors. C also lacks explicit support for useful abstractions such as classes, objects, and exceptions. Newer languages such as C++ and Java address these issues for application-level programs。

1.2 Programs Are Translated by Other Programs into Different Forms

         In order to run hello.c on the system, the individual C statements must be translated by other programs into a sequence of low-level machine-language
instructions. These instructions are then packaged in a form called an executable object programand stored as a binary disk file. Object programs are also referred to as executable object
files.



1.3 It Pays to Understand How Compilation Systems Work

         For simple programs such as hello.c , we can rely on the compilation system produce correct and efficient machine code. However, there are some important reasons why programmers need to understand how compilation systems
work:

       Optimizing program performance.  

       Understanding link-time errors.In our experience, some of the most perplexing programming errors are related to the operation of the linker, especially when you are trying to build large software systems.

       Avoiding security holes.For many years, buffer overflow vulnerabilities have accounted for the majority of security holes in network and Internet servers.

1.4 Processors Read and Interpret Instructions Stored in Memory

           If the first word of the command line does not correspond to a built-in shell command, then the shell assumes that it is the name of an executable file that it should load and run. 

1.4.1 Hardware Organization of a System

o(︶︿︶)o  虽然系统的硬件大体构架我在不同的书上面看了N次了,但是。。但是还是记不全。。。

再来一次



Buses

          Most machines today have word sizes of either 4 bytes (32 bits) or 8 bytes (64 bits). For the sake of our discussion here, we will assume a word size of 4 bytes, and we will assume that buses transfer only one word at
a time.

I/O Devices

           Input/output (I/O) devices are the system’s connection to the external world. Our example system has four I/O devices: a keyboard and mouse for user input, a display for user output, and a disk drive (or simply disk)
for long-term storage of data and programs. 

Main Memory

          The main memoryis a temporary storage device that holds both a program and the data it manipulates while the processor is executing the program. Physically, main memory consists of a collection ofdynamic random access
memory (DRAM)。

Processor

        The central processing unit (CPU), or simply processor, is the engine that inter-prets (or executes ) instructions stored in main memory. 

       Load: Copy a byte or a word from main memory into a register, overwritingthe previous contents of the register.

       Store: Copy a byte or a word from a register to a location in main memory,overwriting the previous contents of that location.

       Operate: Copy the contents of two registers to the ALU, perform an arithmetic operation on the two words, and store the result in a register, overwriting the previous contents of that register.

       Jump: Extract a word from the instruction itself and copy that word into the program counter (PC), overwriting the previous value of the PC。

1.4.2 Running the hello Program


 



1.5 Caches Matter

        Because of physical laws, larger storage devices are slower than smaller storage devices.

        Even more troublesome, as semiconductor technology progresses over the years, this processor-memory gap continues to increase.



        The L1 and L2 caches are implemented with a hardware technology known as static random access memory (SRAM).

1.6 Storage Devices Form a Hierarchy



1.7 The Operating System Manages the Hardware





1.7.1 Processes

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

         Traditional systems could only execute one program at a time, while newer multi-core processors can execute several programs simultaneously. In either case, a single CPU can appear to execute multiple processes concurrently by having the processor
switch among them



1.7.2 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.

1.7.3 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.4 Files

       A file is a sequence of bytes, nothing more and nothing less.

简洁啊!!

1.8 Systems Communicate with Other Systems Using Networks





1.9 Important Themes

重头戏了。。。

1.9.1 Concurrency and Parallelism

        we want them to run faster. Both of these factors improve when the processor does more things at once. We use the term concurrency to refer to the general concept of a system with multiple, simultaneous
activities, and the term parallelism to refer to the use of concurrency to make a system run faster。

Thread-Level Concurrency



Instruction-Level Parallelism

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

Single-Instruction, Multiple-Data (SIMD) Parallelism

1.9.2 The Importance of Abstractions in Computer Systems



         On the operating system side, we have introduced three abstractions: files as an abstraction of I/O, virtual memory as an abstraction of program memory, and processes as an abstraction of a running program. 


第一章积累词汇:待更新
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: