Basic knowledge of computer components and operating systems

Source: Internet
Author: User
Tags posix switches
Introduction of Computer Components

Modern computer equipment mainly consists of five parts: Calculator, controller, memory, input equipment, output equipment. CPU is the central processing unit, is the control and the operator, is a computer's operation core and the control core. The main function of memory is to store programs and various. Input we generally collectively referred to as I/O, used to connect the computer inside and outside. The connection of these components requires the bus and the motherboard to complete.
1, CPU

The CPU (cpu,central processing unit) is a large scale integrated circuit, is a computer's computing core and control core. Its function is mainly to interpret computer instructions and to deal with data in computer software. The CPU takes out instructions from memory or CPU cache, puts them in the instruction register, and decodes the instructions. It breaks down the instructions into a series of micro-operations, and then emits various control commands and executes the micro-operation series, which completes the execution of a single instruction.

1) Frequency

Frequency is also called the clock, used to indicate the CPU operation, processing data speed. Usually, the higher the frequency, the faster the CPU processes the data.

Q: The higher the frequency, the faster it must be.

A : Suppose that a CPU in a clock cycle to carry out an operation instruction, then when the CPU running in 2GHz, will be running in the 1GHz when the speed of one times faster. Because the 2GHz clock cycle is less than half the time taken by the 1GHz clock cycle, that is, working in the 2GHz CPU to carry out an operation command of the time than the work in the 1GHz clock time shortened by half, natural operation speed is faster, so at present many people are happy with overclocking. But using the frequency of the high and low to measure the performance of the processor, need to compare to each other under the same conditions, such as core and thread number, core process (instruction set), core caching and other factors for the processor is also very important, we can not take a past high frequency of the backward processor and now advanced low frequency processor compared to The performance aspect is obviously better than the current processor performance.

2) CPU Cache

The CPU cache is a temporary storage between the CPU and memory, which has a smaller capacity than memory but is faster to exchange.

CPU cache is mainly to solve the CPU operation speed and memory read and write speed mismatch contradiction, because the CPU operation speed than memory read and write faster, so that the CPU spent a long time waiting for data to come or write data to memory. The data in the cache is a small part of memory, but this small part of the CPU is about to be accessed in a short time, when the CPU calls a large number of data, you can avoid the memory directly from the cache call, thus speeding up reading speed. Thus, adding cache to the CPU is an efficient solution, so that the entire internal memory (cache+ memory) becomes a cache of high speed, and memory of the large capacity of the storage system.

According to the order of data reading and the degree of tightness with which the CPU is combined, CPU cache can be divided into a first-level cache, level two cache, some high-end CPU also has a level three cache, each level of the cache stored in all the data is a part of the next cache, the technical difficulties of these three caches and manufacturing costs are relatively decreasing, So its capacity is also relatively increasing. When the CPU is going to read a data, it first looks for it from the primary cache, if it is not found and then looks for it from the level two cache, or if it does not, it is looking from level three cache or memory. Generally, the hit rate for each level of cache is about 80%, that means that 80% of all data can be found in the first-level cache, and only 20% of the total amount of data needs to be read from level two cache, level three cache, or memory, which shows that a cache is the most important part of the entire CPU cache architecture. 2, Memory

Memory of the memory and external memory, the main storage disk, hard disk, and so on, in general, we will talk about external storage classified as I/O equipment. So here's the memory we're just talking about.

Memory is one of the important parts in the computer, it is the bridge that communicates with the CPU, it is the storage space that the CPU can address directly. The programs that we normally use, such as Windows operating system, typing software, game software, etc., are generally installed in the hard disk, such as external memory, but only this is not the use of its functions, they must be transferred into the RAM to run in order to really use its function, we usually enter a paragraph of text, or play a game, In fact, it's all in memory. It's like in a study, the shelves and bookcases that store books are the equivalent of a computer's memory, and our working desk is RAM. Typically, we store a large amount of data that is permanently stored on the external memory, and put some temporary or small amounts of data and programs on the RAM.

Memory is generally used in semiconductor storage units, including random memory (RAM), read-only memory (ROM), and caching (cache).

Rom means read only memory (read only Memory), when the ROM is manufactured, information (data or program) is deposited and permanently saved. This information can only be read out, generally not written, even if the machine power outage, the data will not be lost. ROM is typically used to store basic computer programs and data, such as BIOS ROM.

RAM indicates that random memory (Random Access Memory) indicates that data can be read from or written to. When the machine is powered off, the data stored in it is lost. The memory that we usually buy or upgrade is used as the memory of the computer, and the Memory Bar (Simms) is a small circuit board that centralizes the RAM integration block, which plugs into the memory slots in the computer to reduce the space occupied by the RAM integration block.

Cache is the CPU cache, the previous article has been introduced. 3. I/O

I/O (input/output), that is, the input/output port. Each device will have a dedicated I/O address to handle its input and output information. Common I/O devices include keyboards, hard disks, printers, mice, keyboards, and so on. The hard disk is through the I/O interface to send data to memory for CPU processing. 4. Bus

Bus is a transmission harness composed of conductors. It is the CPU, memory, input, output equipment to pass the information of the public channel, the host parts through the bus connection, the external equipment through the corresponding interface circuit and then connected with the bus, thus forming a computer hardware system.

1) According to functional classification

Data bus: used to transfer information. The data bus is a two-way three-state bus, that is, he can transfer the data of the CPU to other parts such as memory or I/O interface, and transmit the data of other parts to the CPU. It should be pointed out that the meaning of the data is broad, it can be real data, or can be instruction code or state information, sometimes even a control information, therefore, in the actual work, the data bus on the transmission is not necessarily just the real meaning. The common data bus is Isa, EISA, VESA, PCI and so on.

address bus Select、read: is specifically used to send addresses, because the address can only be transferred from the CPU to the external memory or I/O port, so the address bus select、read is always one-way three-state, which is different from the data bus. The number of digits of the address bus determines the amount of memory space that can be directly addressed by the CPU, for example, the address bus of 8-bit microcomputer is 16 bits, the address bus of the 2^16=64kb,16 bit is 20 bits and the addressable space is 2^20=1MB. Generally speaking, if address bus select、read is n bit, the addressable space is 2^n byte.

Control bus: used to transmit control signals and timing signals. Control signal, some of the microprocessor sent to the memory and I/O interface circuit, such as read/write signal, chip selection signal, interrupt response signal, and other components are feedback to the CPU, such as: interrupt the application signal, reset signal, bus request signal, equipment ready signal. Therefore, the transmission direction of the control bus is determined by the specific control signal, which is generally bidirectional, and the number of the control bus is determined according to the actual control needs of the system.

Q: Why 32-bit operating systems can support up to 4G of memory maximum.

A :the 32-digit representative address bus select、read is wide, the bit width of the bus refers to the number of bits of binary data that the bus can transmit at the same time, while the bit width of the address bus select、read determines the amount of memory space that the CPU can address directly, because the binary address is only 0 or 12, so the address space of the 32-bit operating system is 2 ^32=4GB.

2) According to the level of classification

internal bus: in the CPU, between registers and arithmetic logic parts alu and control parts of the transmission of data between the bus is called in-chip bus (that is, the chip inside the bus), such as I2C bus, SPI Bus, SCI bus and so on.

system bus: also known as the internal bus or board-level bus, is the computer in each plug-in board and the system board between the bus, for the plug-in board level of interconnection. Because the bus is used to connect the various functional components of a microcomputer and constitute a complete microcomputer system, so called the system bus. People usually say that the microcomputer bus refers to the system bus, such as the ISA bus, PCI bus and so on.

External bus: is the bus between the computer and the external device, such as IDE bus, USB bus, SCSI bus, etc.

3) According to the transmission mode classification

Serial bus: All signal multiplexing a pair of signal lines, the serial bus communication rate is relatively low, but in the data communication is not very large microprocessor circuit, it appears more convenient and flexible. such as USB bus, SPI Bus, I2C bus and so on.

Parallel bus: each signal has its own signal line, parallel bus communication speed, real-time good, but due to occupy the mouth line, the cost will be increased. such as ISA bus, PCI bus, and so on. 5, Motherboard

The motherboard provides a series of junction points for the processor, video card, sound-effect card, hard disk, memory, I/O devices and other devices to engage. They are usually inserted directly into the relevant slot or connected by a line. The most important component on the motherboard is the chipset. The chipset is usually made up of North and South Bridges, which provide a common platform for the motherboard to connect to different devices and control the communication of different devices.

The chipset (chipset) is the core component of the motherboard, which almost determines the function of the motherboard, which in turn affects the performance of the entire computer system. According to the arrangement on the motherboard of the different positions, usually divided into North Bridge and the bridge chip. North Bridge chip provides the type and frequency of the CPU, memory type and maximum capacity, ISA/PCI/AGP slot, ECC error correction and other support. The bridge chip provides support for KBC (keyboard controller), RTC (real Time clock Controller), USB (Universal serial Bus), Ultra dma/33 Eide data transfer mode, and ACPI (Advanced Energy Management). The North Bridge chip plays a leading role, also known as the main span (Host bridges).



second, the computer system level general statement

1, the first level is the micro-program level. This level of machine language is a micro-instruction set, programmers with micro-instructions to write a micro-program, usually directly by the hardware directly executed.

2, the second level is the traditional machine-level, this level of machine language is the machine's instruction set, programmers use machine instructions to write programs can be explained by the micro-program

3, the third level is the operating system level, from the basic functions of the operating system, on the one hand it to directly manage the traditional machine hardware and software resources, on the other hand it is the extension of traditional machines.

4, the fourth level is the assembly language level, this level of machine language is assembly language, complete assembly language translation program called Assembler program.

5, the fifth level is the high-level language level, this set of machine language is a variety of high-level languages, usually with the compiler program to complete the work of high-level language translation.

Summary: Different levels of programming are done by different languages, the lower the language closer to the machine, the more advanced language closer to the human, so most of our application staff are working at the advanced language level. and the operating system can be regarded as a middle layer, play the role of machine language and human natural language link, so the operating system is very important, but also the focus of our learning behind. Third, operating system 1, operating system function:

1 Shielding hardware physical characteristics and operating details, the output of a unified interface, for users to use the computer to provide convenience .

The operating system abstracts the various computing capabilities provided by the underlying computer into a unified interface software, whether the underlying AMD CPU or inter CPU, are unified into a provision of computing power, regardless of the memory is 1G, 2G, 4G, 8G are unified into 32-bit system 4G memory, 64-bit system 4G *4G of memory. So programmers write programs greatly simplified, regardless of the bottom end of the hardware, I intuitively face Linux or Windows this operating system, or 32-bit, 64-bit operating system to write programs. That's why we bought the computer. The first thing is to install the operating system, and then to install a variety of software, because generally speaking programmers are written in the face of the operating system, rather than face machine written, no operating system software can not run.

Q: The software must be on the operating system to run.

A : not so absolutely, if the programmer is willing to follow the underlying machine language to write programs, is not required operating system, but the underlying machine language is too complex, difficult to meet the needs of the current application software.

2 effectively manage the system resources and improve the efficiency of system resources utilization. how to effectively manage and rationally allocate system resources and improve the utilization efficiency of system resources is the main function that the operating system must play. For example: Hardware driver, CPU time slice cut allocation (process management), memory management, network management and so on. 2, operating system composition:

1) Kernel (Kernel)

Kernel, is the core of an operating system. From a different point of view, the kernel holds different roles. From a purely technical point of view, the kernel is just a middle tier of software and hardware , sending requests from software to the hardware, addressing and so on, and acting as a low-level driver. From an application perspective, the kernel is a high-level abstraction of the hardware, the application is not connected to the hardware, only the kernel, and the kernel is the lowest level that the application knows. From the point of view of multiple concurrent processes, the kernel is a resource manager that completes the process of switching, scheduling, and sharing computer resources (CPU, memory, disk, network, etc.). The kernel can also be viewed as a library that sends various requests to the kernel through system calls.

2 system call (Systems Calls)

In all of the CPU's instructions, some of the instructions are very dangerous, if all programs can use these instructions, once the wrong instructions will cause the entire system crashes, such as: clear memory, set the clock and so on. As a result, theCPU divides the instructions into privileged and unprivileged directives, which allow only the kernel of the operating system to be used for those dangerous privileged directives, and ordinary applications can only use unprivileged directives that do not cause disaster.

But an application must be used by both privileged and unprivileged directives, and then what to do.

The operating system divides the running space of the program into kernel space and user space (that is, the kernel State and user state), they run at different levels respectively, and are logically isolated from each other. User processes are typically not allowed to access kernel data, and they cannot use kernel functions, which can only manipulate user data in user space and invoke user-space functions. Intel's CPUs divide the privilege level into 4 levels: Ring0,ring1,ring2,ring3. Linux uses the RING3 level to run the user state, RING0 as a kernel state, without using Ring1 and Ring2. The RING3 state does not have access to the RING0 address space, including code and data. The system call is the operating system to provide support to the user program interface, system calls to the application of the request to the kernel, call the corresponding kernel function to complete the required processing, the processing results returned to the application. Note that system calls do not occur every moment, and only those privileged instructions need to request the kernel through the system call interface. Some non privileged directives do not need to invoke the kernel and can run directly on the CPU.

Q: How the application switches between the user state and the kernel state.

A : when the process executes the user's own code, we call it user state. That is, the processor is running in the lowest-privileged user code. Whenever a user process uses system calls, the run mode is automatically converted from the user level to the kernel level, at which time the process runs in the kernel's address space. When a process executes a system call and falls into the kernel code to execute, we say the process is in the kernel state. The processor is executing in the highest-privileged kernel code at this time. When the process is in the kernel state, the kernel code that executes uses the kernel stack of the current process, each with its own kernel stack.

Q: Why the application cannot call the kernel directly.

A : modern operating systems usually have multitasking functions that are usually implemented by processes. Because the operating system quickly switches between each process, everything looks as if it is simultaneous. This also poses a number of security issues, such as a process that can easily modify data in the memory space of a process to make another process unusual or achieve some purpose, so the operating system must ensure that each process is executed securely. The solution to this problem is to include the base address register and the boundary register in the processor. The contents of these registers are limited by hardware to the address of the memory accessed by the accessor instruction of the storage. This allows the contents of these registers to be written to the address range of the process being assigned to the system when the process is switched, thereby avoiding malicious software. To prevent user programs from modifying the contents of the base address register and the bounds register to access other memory spaces, these registers must be accessed through special instructions. Typically, the processor has two modes: "User mode" and "kernel mode", using a tab bit to identify what mode is currently in place. Some instructions, such as modifying the contents of the base address register, can only be performed in kernel mode, while in user mode the hardware will skip the instruction and proceed to the next. Similarly, for security reasons, some I/O operations directives are limited to kernel-mode execution, so it is necessary for the operating system to provide an interface to provide an interface to the application that reads data from a location on the disk, which is called a system call. When the operating system receives the system call request, it takes the processor into kernel mode, performs such instructions as I/O operations, modifies the base address register contents, and when the system call is processed, the operating system lets the processor return to user mode to execute the user code.

3 Library function call (libraries Calls)

While system calls are a bridge between the kernel and user applications, is a user application's access point to the kernel, but typically the system call does not directly deal with the programmer, it is simply an interface that submits a request to the kernel through a soft interrupt mechanism (int 0x80 in X86) to obtain the kernel service. applications are programmed through the application programming interfaces (APIs) provided by the operating system rather than directly through system tuning . The main function of the operating system API is to fully display the function of the operating system and provide it to the application, based on the operating system, the ability to interoperate with files, memory, clocks, networks, graphics, various peripherals, etc. In addition, the operating system APIs often provide functionality for many tool classes, such as manipulating strings, various data types, time dates, and so on.

In Linux, the API follows the most popular application programming interface standard in Unix-thePOSIX standard , which describes the system call programming interface (API) of the operating system based on existing UNIX practices and experiences at the time. Used to ensure that applications can be ported to a variety of operating systems at the source level, these system call programming interfaces are implemented primarily through the C Library (libc). Library functions are developed by users or organizations themselves, have a function set of functions, generally have a better platform portability, through the library file (static library or dynamic library) to provide functional calls to programmers. Programmers do not need to care about platform differences, by the library to screen platform differences.

The C library (LIBC) provides most of the POSIX APIs, and each system call provided by the kernel has the appropriate encapsulation function in the C library. System calls are often the same as the names of their C library encapsulation functions, for example, the Read function is the encapsulated function in the C library that is called by the read system. In fact, from the user's point of view, the difference between the system call and C library is not important, they only need to complete the function through the C library function. Instead, from the kernel's point of view, what you need to consider is the system calls that are provided for a certain purpose and do not need to be concerned about how they are used.

4 The connection and difference between system call and function library call

connection between system calls and function library calls:

1, the library function is in the system call on a layer of packaging, run in user mode, for example, the library function is equivalent to the contractor, system call is a worker, we can find their own workers, but generally the task to the contractor, the contractor to the workers to separate tasks.

2. Some functions in function library call the system call interface, the programmer can call the system call interface through function library, of course, advanced programming can also use INT 0x80 to enter system call directly, but need not pass function library as intermediary;

3, many function libraries in the function name and the name of the system call, because the function itself is actually called the system call, put to the function library is to use the user state, which can reduce the user state to the kernel switching overhead. However, there is not a one by one correspondence between the system call and the library function, and several different functions may be called to the same system call, and it is possible for a function to call multiple system calls. Some functions do not depend on any system calls, because they do not require any service from the kernel.

differences between system calls and function library calls:

Q: A program that needs to execute kernel code is ultimately called a system call , but why our usual practice is to call a library function instead of a direct system call.

A : 1, the library function call does not depend on the operating system, the platform portability is good;

2, library functions to provide us with more user-friendly interface, so call up more convenient;

3, call the library function more secure, memory management do not worry about their own;

4, call library functions more efficient, although the library function is ultimately called system functions, but the library function than we in a better way to call the system functions (for example, using a buffer pool).

Q: The system call is different in each operating system, and the library function call will eventually make the system call, then how to implement the Library function portability.

A : between the operating systems, an intermediate layer is abstracted based on most of the requirements. In the middle tier, the middle tier uses masking low-level detail, which, in the programmer's view, is the middle-tier role of the C language library. In each platform, our default C standard library functions are the same, so the basic can be portable.  But for the C library itself, in the various operating system platform its internal implementation is completely different, that is, C library encapsulates the system call interface in its internal implementation details (the compiler is responsible for library functions to the transformation between system calls). Therefore, the C language provides our portability at the code level, that is, the portable is done through the middle tier of C language.

Q: If programmers write programs that are API-oriented and not OS-portable, why are programs on windows that are typically not running on Linux?

A : This can be transplanted, is the source code can be transplanted, not the program can be transplanted , executable program is compiled from the source code, compiled after the source has become the machine language binaries, and different operating systems compiled binary code is different, The binary code is interpreted differently by different operating systems, and the compiled executable is not the same in each operating system. Popular saying if the source code analogy into a Chinese article, then the German translation of the article only the Germans can understand, the French translation of the article only the French can understand. (the compiler is to compile the source code into the target code, the implementation of the compiler is not required, directly in the support of the target code platform to run, so that execution efficiency than interpretation performed much faster.) For example, the C language code is compiled into a binary code EXE program, executed on the Windows platform. )

for more information on system calls and library function calls refer to the relationship between system calls and C libraries IV, assembly language

Assembly Language (assembly language) is a low-level language for computers, microprocessors, microcontrollers, or other programmable devices, also known as symbolic languages . In different devices, the assembly language corresponds to a different set of machine language instructions, which are converted to machine instructions by assembly process.
assembly Language Advantages:

1, because the assembly language design program is eventually converted into machine instructions, it can maintain the consistency of machine language, direct, simple, and can be like machine instructions to access, control the computer's various hardware devices, such as disk, memory, CPU, I/O ports. Using assembly language, you can access all the software and hardware resources that can be accessed;

2, the target code short, occupy less memory, fast implementation, is a highly efficient programming language, often with high-level language, to improve the execution speed and efficiency of the program to make up for high-level language in the hardware control deficiencies, application is very wide. assembly Language Disadvantage:

1, assembly language instruction is a symbol of machine instructions, and different types of CPUs have different machine instruction system, there are different assembly language, so, assembly language programs and machines have a close relationship. So, in addition to the same series, different models of the assembly language between the CPU program has a certain degree of portability, other different types (such as: minicomputer and computer, etc.) between the CPU assembly language program is unable to transplant, that is, the assembly language program of universality and portability than high-level language programs;

2, it is difficult to understand the program design from the assembly language code, the maintenance of poor, even the completion of simple work also requires a large number of assembly language code, it is easy to produce bugs, difficult to debug;

3, the use of assembly language must be very understanding of a processor, but only for the specific architecture and processor optimization, development efficiency is very low, long and monotonous cycle. the use of assembly language scene:

Historically, assembly language was once one of the most popular programming languages. However, as modern software systems become more and more complex, a large number of high-level languages, such as C/c++,pascal/object Pascal, have also emerged. These new languages enable programmers to be simpler and more efficient in the development process, enabling software developers to cope with rapid software development requirements. But the assembly language because of its complexity makes its application field gradually reduce.

But that does not mean that the compendium is useless. Because the assembly is closer to the machine language and can operate directly on the hardware, the resulting program has a higher running speed and less memory than other languages, and is therefore heavily used in a number of time-sensitive programs, core modules for many large programs, and industrial controls.

1, most of the statements of assembly language directly correspond to machine instructions, fast execution, high efficiency, small code, in those memory capacity is limited, but need fast and real-time response of the occasion is more useful, such as instrumentation and industrial control equipment.

2, in the System program's core part, as well as with the system hardware frequently deals with the part, may use the assembly language. For example, the operating system's core program segment, the I/O interface circuit initialization program, the external device's low-level driver, as well as the frequently invoked subroutine, the dynamic Connection library, some advanced drawing program, the video game program and so on. With the Linux kernel, although most of the code is written in C, it is still inevitable to use the assembly code in some key places. Because this part of the code and hardware relationship is very close, even if the C language will appear powerless, and assembly language can be very good to avoid weaknesses, maximize the performance of the hardware.

3, assembly language can be used for software encryption and decryption, computer virus analysis and prevention, as well as debugging and error analysis of the program and other aspects.

4, through the study of assembly language, can deepen the computer principles and operating systems and other courses of understanding. Through the study and use of assembly language, can perceive, realize and understand the logic function of the machine, up to understand the principles of various software systems, lay the technical theoretical foundation; down to master the principle of the hardware system, lay the practical application Foundation.
v. High-level languages

Because the assembly language relies on the hardware system and the mnemonic volume, people have invented the so-called advanced language which is more easy to use. Advanced languages (High-level programming language) are highly encapsulated programming languages, relative to low-level languages. It is a programming language based on the everyday language of mankind, the use of generally acceptable text to express (such as Chinese characters, irregular English or other foreign languages), so that the program writers to write easier and more readable, so as to facilitate the understanding of computer users can probably understand the content. Since the early development of the computer industry is mainly in the United States, the general high-level language is modelled on English. Because the high-level language is a encapsulated programming language, it cannot be recognized directly by the computer, and it needs to be transformed to be executed, and they can be divided into two classes by the way they are converted:

1. Compile-type language

Compiled languages include C, C + +, and so on. This refers to the compilation of the application of the source code before the implementation of the program to "translate" into assembly language, and then further according to the hardware environment to be changed to meet the needs of the operation of the machine language target files.

2. Explanatory language

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.