"Linux Kernel Design and Implementation" Reading Notes-Portability

Kernel portability strategy

Middle route:

Almost all interfaces and core codes are C language codes independent of the hardware architecture;

In the part with very strict performance requirements, the characteristics of the kernel will be adjusted according to different hardware systems;

The code related to the architecture is placed in the arch/xx/ directory, where xx is the name of the architecture, such as x86.

 

Word length

The word length in Linux refers to the number of bits of the machine. For example, x86 has 32 bits and 64 bits, so the word length is 32 bits and 64 bits respectively (the word length here is not the length of a word).

BITS_PER_LONG in asm/types.h represents the word length, for example, in include\asm-generic\bitsperlong.h:

#ifdef CONFIG_64BIT
#define BITS_PER_LONG 64
#else
#define BITS_PER_LONG 32
#endif /* CONFIG_64BIT */

The length of the long type in the C language is determined to be the word length of the machine, and the int type is sometimes smaller than the word length.

Although there is no clear stipulation, in the architecture supported by Linux, int is 32-bit and short is 16-bit.

The operating system often uses a simple mnemonic to describe the size of the data type in the system:

LLP64: The length of long long and pointer is 64 bits, and long is 32 bits;

LP64 : long, long long and pointers are all 64-bit; Linux uses this.

ILP64: The length of int, long, long long and pointer is 64;

Types declared with typedef are called opaque types, such as pid_t, atomic_t, etc. We should not assume their length or do type conversion.

The kernel defines types with a clear length:

 

Page length

Defined in asm/page.h, x86 is 4KB.

 

Guess you like

Origin blog.csdn.net/jiangwei0512/article/details/106153213