Linux kernel

Spin locks are useless in a uniprocessor environment. When a kernel control path tries to access a locked data structure, it starts an endless loop. Therefore, the kernel control path that is updating the protected data structure would not have a chance to continue the execution and release the spin lock. The final result would be that the system hangs.


Memory Addressing

The data structures that map linear to physical addresses are called page tables; they are stored in main memory and must be properly initialized by the kernel before enabling the paging unit.

Starting with the 80386, all x86 processors support paging; it is enabled by setting the PG flag of a control register named CR0. When PG=0, liner addresses are interpreted as physical addresses.

Each active process must have a Page Directory assigned to it.

The entries of Page Directories and Page Tables have the same structure.

While x86 processors allow foure possible privilege levels to a segment, only two privilege levels are associated with pages and Page Tables, because privileges are controlled by the Usr/Supervisor flag.

Instead of the three types of access rights(Read,Write and Execute) associated with segments, only two types of access rights(Read and Write) are associated with pages.

The content of the first entries of the Page Global Directory that map linear addresses lower than 0xc0000000(that is 0xc0000000/0x400000=0x300 of 768decimal if PAD disabled) depends on the specific process. Conversely, the remaining entries should be the same for all processes and equal to the corresponding entries of the master kernel Page Global Directory.



PAGE_SHIFT: Specifies the length in bits of the Offset field of a linear address.                                       12

PAGE_SIZE:   The size of the page                                                                                                                       4096

PAGE_MASK: Used to mask all the bits of the Offset field                                                                               0xFFFFF000

PMD_SHIFT:   The total length in bits of the Offset field and Table field of a linear address.


Process

A process is an instance of a program in execution.

From the kernel's point of view, the purpose of a process is to act an entity to which system resources are allocated.

The POSIX 1003.1c standard states that all threads of a multithreaded application must have the same PID.

The kernel must be able to handle many processes at the same time, and process descriptors are stored in dynamic memory rather than in the memory area permanently assigned to the kernel.

The esp register is the CPU stack pointer, which is used to address the stack's top location. On 80x86 systems, the stack starts at the end and grows toward the beginning of the memory area. Rgith after switching from User Mode to Kernel Mode, the kernel stack of a process is always empty, and therefore the esp register points to the byte immediately following the stack.

The set of data that must be loaded into the registers before the process resumes its execution on the CPU is called the hardware context. The hardware context is a sub-set of the process execution context. In linux, a part of the hardware context of a process is stored in the process descriptor, while the remaning part is saved in the Kernel Mode stack. Process switching occurs only in Kernel Mode, the contents of all registers used by a process in User Mode have already been saved on the Kernel Mode stack before performing process switching.


Lists in process management:

The process list: a list that links together all existing process descriptors. Each task_struct structure includes a tasks field of type list_head whose prev and next fields point to the previous and to the next task_structure element respectively. The head of the process list is the init_task task_struct descriptor, it is the process descriptor of the so-called process 0 or swapper.

The lists of TASK_RUNNING processes: a list that links together all processes in the TASK_RUNNING state. Each task_struct descriptor includes a run_list filed of type list_head. If the process priority is equal to k(a value ranging between 0 and 139), the run_list field links the process descriptor into the list of runnable processes having priority k.

Wait queue: a wait queue represents a set of sleeping processes, which are woken up by the kernel when some condition becomes true. Each wait queue is identified by a wait queue head, a data structure of type wait_queue_head_t. Elements of a wait queue list are of type wait_queue_t. There are two kinds of sleeping processes: exclusive processes are selectively woken up by the kernel, while nonexclusive processes are always woken up by the kernel when the event occurs.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值