#Linux Kernel Development 读书笔记
(8/10/14)
==========================day01===================
1.Introduction to linux:
1.kernel,device drivers,boot loader,command shell,filetype system utilities
2.linux can dynammic loading of kernel modules or unloaded;symmetrical multiprocessor(SMP?);all process are the same
3.Andrew Morton LKML
4.practical
2.Getting started:
1./usr/src/linux !!!不能动
2.using patches
3.Configuring the kernel
4.GNU c:inlines;Assembly:empty if();No memory Protection==>oops;No Floating Point
3.Process Management
1.The living result of running program code
2.Thread within the process,内核调度包括thread,not process.Modern operating systems provide two virtuazation:a virtualized processor and virtual memory
3.fork() begins process’s life,exit() end it’s life,exec() begins a new address space and loads a new program into it
4.task list consist of circular doubly linked list,
Each element in the task list is a process descriptor of the type struct task_struct
5.Allocating the Process Description:thread_info structure is defined on x86 in <asm/thread_info.h>,I want to know what he is taking about,
Process identification value or PID
6. maximum value is recorded in /proc/sys/kernel/pid_max.via the “current” macro
7.Process State(5个)==>set_task_state(task,state)/set task task
to state state
/
8.Process Context
9.The Process Family tree,the big father is PID is one(init in last step of the boot process),总的来说,就是在引导boot程序的最后一步时由init呼叫其他系统程序,完成了启动后即开始转换为big father,“struct task_struct *my_parent = current->parent”
10.Process Creation,fork()将父进程的所有资源复制给他的子进程,在这里,这两者之间用了一种锲约Copy-on-write(这是一种延迟(delay)),等时机差不多了再复制资源,所以,像连环套似的,下一个宝藏就是–copy-on-write,BTW,学习计算机,我自己最大的感受是当你看到一种新理论或者新名词时,最好不要去想这东东我能用着吗,我要掌握那得花多少时间啊,想都不要想,当然,如果你是按主题搜索资料时,还是要注意大方向的。
11.Forking:The fork() via the clone() system call,do_fork()
12.The Linux Implementation of Threads:They can also share open files and other resources,Thread enable concurrent programming and on the multiple processor systems ,true paralleism.But Linux kernel ,there is no concept of a thread,Linux implements all threads as standard processes.just happen to share resources ,such as an address space,with other process.linux没有线程的概念,这一点与windows与Solaris显然不同,也是存放在task_struct中在<linux/sched.h>有着clone flags的定义。
13.Kernel threads-standard processes,do not have an address space (mm pointer ,which points at their address space ,is NULL) ,内核线程有很多,如 top,ps -ef啦,第一次读到源代码,宏的使用比较多,还有各种各样的强制转换
============================chapter04==========
Process Scheduling
1. Multitasking,四个问题, suspending a running process is called preemption(?),timeslice ,yielding
2.linux’s Proces Scheduler is simple,But 2.5 kernel later call O(1) scheduler,get to constant-time,and 2.6.23,the completely fair scheduler or CFS.
3.主要讲了两类Bound,I/O,process
4.process priority,linux kernel have two separate priority ranges(-20 to +19 with a default of 0),shell ps -el
5.Real-time
6.关于linux的时间调度,有几个值得关注的地方:
1. Time Accounting
2. The scheduler entity struct,这个结构体定义在<linux/sched.h>中,并且这个结构实体嵌入在进程描述表中。
3.The virtual Runtime 记录了进程的实际运行时间,是上面结构体的一个成员。nanoseconds(十亿分之一,毫微秒)。
4.进程选择(process selection),这里涉及红黑二叉树,自己还是一无所知,补上啊.红黑树的定义在/linux/sched.h中,这个数据结构在内核中异常重要,在不同场景中都有它的应用,请你自己一定要掌握下来。
5.Picking the Next Task: 在红黑树的基础上,选择下一个任务就简单多了,选择rb_node的leftmost node就是了,而这个函数就是__pick_next_entity(),在 kernel/sched_fair.c中。
6. Adding process to the Tree : first created via fork(),then enqueue_entity(),将进程加入红黑树。
7. Removing Process from tree
8. The Scheduler Entry Point
9. Sleeping and Walking Up
———————-chapter 5 system call———–
- System Call Numbers 在Linux中,每一次系统调用会指派一个系统调用序列(syscall numbers). details for /arch/i386/kernel/syscall_64.c system_call() is important also. 怎么也看不懂啊
———————-chapter 7 interrupt ————
- These interrupt values are often called interrupt request(IRQ),on the classic PC,IRQ zero is the timer and IRQ one is the keyboard interrupt. 2 The function the kernel runs in response to a specific is called an interrupt handler or interrupt service route(ISR),
- In linux,interrupt handler are normal C functions. interrupt context;快速及时处理中断 Device uses interrupts ,driver must register one interrupt handler. with function request_irq(),which is declared in <linux/interrupt.h> On success,request_irq() return zero,A nonzero value indicates an error, a common error is -EBUSY.
- 还要释放中断处理:request_irq() free_irq(); ————————-9/4——————————–
- Linux把硬件中断的进程分成两部分。The top half is quick and simple and runs with some or all interrupts disabled.The bottom half runs later with all interrupts enabled.
- BH is called Bottom Half also.
- Task Queues : each queue contained a linked list of functions to call.
- Softirqs and Tasklets The softirq code lives in the kernel/softirq.c Softirqs are represented by the softirq_action structure,which is defined in <linux/interrupt.h>
- Networking and block devices –directly use softirqs. Softirq Types的图片放在了<picture/c>
- Registering your handler<net/core/dev.c> open_softirq(NET_TX_SOFTIRQ, net_tx_action); open_softirq(NET_RX_SOFTIRQ, net_rx_action);
- Tasklets are represented by two softirqs:HI_SOFTIRQ and TASKLET_SOFTIRQ.
- The tasklet structure struct tasklet_struct { struct tasklet_struct next; unsigned long state; atomic_t count; void (func)(unsigned long); unsigned long data; };
- Tasklet are scheduled via the tasklet_schedule() and tasklet_hi_scheduled() functions.
- old BH is no longer present in 2.6,the hostory is important. In 2.5,The kernel developers summarily removed the BH interface.Good riddance,BH!
–Work Queues–
- Work queues defer work into a kernel thread–this bottom half always runs in process context.
- struct workqueue_struct的数据结构定义在/kernel/workqueue.c中
struct workqueue_struct { struct list_head pwqs; /* WR: all pwqs of this wq / struct list_head list; / PL: list of all workqueues */
After i cast much time,i am on the way to the Linux Kernel. But how i start to code?
P234 11-14 ##two handware devices to help with time keeping ###the real-time clock The real-time clock(RTC) continuous to keep track of time even the system is off,on PC architecture the RTC and CMOS are integrated. On boot,the Kernel reads the RTC and uses it to initialize the wall time,which is stored in the xtime__variable. ###The timer interrupt is broken into two pieces,an architecture-dependent and architecture-independent,but both at least perform the following working. 1.obtain the __xtime_lock__lock,which protects access to __jiffies_64__and wall time value–xtime. 2.reset the system timers as required 3.Periodically save the updated wall time to the RTC 4.Call the architecture-independent the timer routin__tick_periodic(),后面这个函数是个重点。
====================================================== overhaul:检修;改造:rectified:矫正 to a fault:fellowship(团契)::latency::at-odds:: http://v.163.com/movie/2014/9/5/8/MA44SCUPU_MA47GQ658.html scenario::coexist::protocols::dabbled::coupons::bot:: ============================================ debian 分区工具 apt-get install parted