Reading Code

Nick Krause xerofoify at gmail.com
Fri Aug 8 15:16:14 EDT 2014


For the last few days , I have been reading the code for do_fork and
other parts of the scheduler code.
As most of the developers feel this is in my best interest. I do
however have a few questions about the
code for the function, schedule.
1. In task struct we have this one defined if needed
1481 #ifdef CONFIG_BLOCK
1482 /* stack plugging */
1483 struct blk_plug *plug;
1484 #endif
I am curious is this used for block IO or something else as we are
checking for it in schedule() with this line,
sched_submit_work(tsk); which in turn points to sched_submit_work and
in turn checks for blk_plug
2814 static inline void sched_submit_work(struct task_struct *tsk)
2815 {
2816 if (!tsk->state || tsk_is_pi_blocked(tsk))
2817 return;
2818 /*
2819 * If we are going to sleep and we have plugged IO queued,
2820 * make sure to submit it to avoid deadlocks.
2821 */
2822 if (blk_needs_flush_plug(tsk))
2823 blk_schedule_flush_plug(tsk);
2824 }
Since schedule returns this and after searching using lxr, can't find
much on this, what is this type actually defined as when compiled?
368 #define __sched __attribute__((__section__(".sched.text")))
3. context_switch(rq, prev, next); /* unlocks the rq */
I am getting confused by this function after tracing it, if  someone
wants to explain it to me that would be great.

In addition I am not not trying to turn this into a self help just for
me, but my questions about git I goggled for 2 hours and didn't

find any answers, sorry about that guys. In addition I hope theses
questions are valid.
Cheers Nick



More information about the Kernelnewbies mailing list