Linux Debugging 1 - Kernel Introduction

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.

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值