Linux Kernel Architecture

(Jacob Rumans) #1
Mauerer runapp02.tex V2 - 09/04/2008 6:09pm Page 1163

Appendix B: Working with the Source Code


❑ The kernel source text can be scanned for any string usingfreetext search.
❑ File searchenables users to search for files by name if they don’t know where those files are
located in the sources.

B.4.2 Patch and Diff


Kernel patches were the only way of tracking ongoing kernel development in the early days of Linux.
Patches still have an important role to play because git builds implicitly on diffs and patches, and patches
are the required form when changes are communicated to a mailing list.

patchanddiffare complementary tools. Whereasdiffanalyzes the differences between two files or a
set of files,patchapplies the differences held in a file generated bydiffto an existing source text.

Unified Context Diffs


The following example illustrates the format used bydiffto record the differences between two versions
of a file. It reflects a change made to the scheduler during the development of kernel 2.6.24.

diff -up a/include/linux/sched.h b/include/linux/sched.h
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -908,6 +908,7 @@ struct sched_entity {
u64 sum_exec_runtime;
u64 vruntime;
u64 prev_sum_exec_runtime;



  • u64 last_min_vruntime;


#ifdef CONFIG_SCHEDSTATS
u64 wait_start;
diff -up a/kernel/sched.c b/kernel/sched.c
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -1615,6 +1615,7 @@ static void __sched_fork(struct task_struct *p)
p->se.exec_start = 0;
p->se.sum_exec_runtime = 0;
p->se.prev_sum_exec_runtime = 0;



  • p->se.last_min_vruntime = 0;


#ifdef CONFIG_SCHEDSTATS
p->se.wait_start = 0;
@@ -6495,6 +6496,7 @@ static inline void init_cfs_rq(struct cfs_rq cfs_rq, struct rq rq)
#ifdef CONFIG_FAIR_GROUP_SCHED
cfs_rq->rq = rq;
#endif



  • cfs_rq->min_vruntime = (u64)(-(1LL << 20));
    }


void __init sched_init(void)
diff -up a/kernel/sched_fair.c b/kernel/sched_fair.c
--- a/kernel/sched_fair.c
+++ b/kernel/sched_fair.c
@@ -243,6 +243,15 @@ static u64 sched_slice(struct cfs_rq cfs_rq, struct sched_entity se)
return period;

Free download pdf