Linux Debugging 1 - Kernel Introduction

来源:互联网 发布:sai mac下下来打不开 编辑:程序博客网 时间:2024/06/01 10:37

1. linux kernel version

Major.Minor.Release[extra]

 

Minor: Even minor numbers denote stable "production" kernel, whereas odd ones are reserved for development kernels.

 

API changes in the 2.6 kernel series refer to http://lwn.net/Articles/2.6-kernel-api/

 

解压kernel代码:

 

打补丁命令:

 

2. Linux Kernel的Feature

1) Implement generic UNIX kernel structure

2) Monolithic, thread kernel

3) user threads are LWP

4) kernel is preemptive (in 2.6)

5) small footprint

6) Modular and Extensible

 

3. 2.6的内核实现了抢占调度,抢占点在于:

- On return from Interrupt handlers

- On blocking Kernel calls

- when the Kernel preemption is reenabled (call preempt_enable)

- when a kernel thread voluntarily yields by calling schedule.

 

4. Schedulers

refer to : http://lwn.net/Articles/230574/

 

1) in 2.4 version, scheduler is O(n), while in 2.6 it is O(1), which is more efficient and provide natural CPU affinity.  It has one runqueue per processor(每个CPU都有自己的runqueue), and each runqueue contains 2 priority arrays. And it use bitmap to find the highest priority task(进程或者线程) to run.

We can check the codes from LXR.

 

RT task priority is from 0 to 100, and normal task priority is from 101 to 139 (from sched.h)

 

调度算法(from sched.c)

 

看一下sched_find_first_bit的实现,常数时间即可选择出最小的不为0的bit,所以为O(1)调度算法。

 

问题:高优先级的任务总是先被调度,低优先级的任务无法被调度,starvation.

 

2) In 2.6.23 release, a CFS (Completely Fair Scheduler) is added, see this from wiki (http://en.wikipedia.org/wiki/Completely_Fair_Scheduler), and we can get more info from http://kerneltrap.org/node/8059

 

 

High priority tasks still get larger slices, but tasks are ordered by "vruntime", which means schedule cpu-starved threads first, low priority threads get their smaller slice but at least execute.

 

3) IO scheduler

2.6 kernel has 4 I/O schedulers, No-op I/O scheduler, Anticipatory I/O scheduler(default), Deadline I/O scheduler与CFQ I/O scheduler. In 2.4, use the "Linus Elevator" (No-op I/O scheduler).问题主要是“请求饥饿”。

 

5. Kernel Architecture

 

old system call is using "int $0x80", and 2.6 use "sysenter" and the syscall number is in EAX. see syscall_table.S

 

6. Devices

分类:字符设备(例如:内存,终端,IO ports,键盘,鼠标等), 块设备 (buffered) device(硬盘,闪存等).

 

例如: mknod /dev/testdev c 254 0创建一个字符设备,major号(the number of the device registered in the kernel)是254,minor号(the number of device registered in the driver)是0.

 

 

 

原创粉丝点击