Pick a Free OS

User login

Navigation

For Kernel_Newbies By a Kernel_Newbie

  • Start computing the next task by trying to select a task with maximum

    goodness value by looping through the runqueue_head.(Look out for the runqueue

    manipulation routines).

  • If the goodness ends up being 0, then its an indication that all the tasks

    have had their share of time_slices. Try readjusting the time_slice

    (task->counter) by jumping to recalculate,and try again to get a task with

    maximum goodness value.

  • The next task gets in,and the per-cpu schedule_data structure is adjusted

    to update the entries to the next_task,and recompute the last clock cycles

    value.

  • If the new task selected is the same as the old one,then jump to

    same_process,check for task->need_resched,to see if the schedule operation

    has to be repeated,and if not,return,thereby skipping any switch_mm calls.

  • If the new task selected doesnt have a mm_struct (task->mm == NULL),

    then its a Kernel_Thread. Try setting the active_mm of the Kernel_Thread to

    that of the scheduled_out task,thereby avoiding a switch_mm. If the new task

    has a mm_struct,then do a switch_mm(include/asm-i386/mmu_context.h) which

    updates the page_directory pointer in cr3,to that of the new_task.

  • Update the context switches field in the kstat structure and do a

    switch_to to the new task. You should rewind your memory,to try recollecting

    the acts of switch_to which were discussed while describing the ret_from_fork

    path.

  • switch_to returns when the scheduled_out task starts running,which then has

    to go through the schedule_tail routine. The schedule_tail routine (also called

    from ret_from_fork path,as mentioned before) zeroes out the task->has_cpu,and

    calls reschedule_idle only if its not an idle_task and the scheduler policy for

    the task is not SCHED_YIELD,else the SCHED_YIELD is masked out. reschedule_idle

    is an important routine in SMP zone,whereas in a UNP context,it just amounts to

    a positive ( > 1) pre-emption_goodness.(The chance of pre-empting a running

    task) In SMP context,reschedule_idle tries to find an idle_cpu for the previous

    task that is now scheduled in. It first checks whether the process __can_be__

    scheduled in this_cpu (task->processor). In order to get the concept of

    can_schedule,check out the macro can_schedule,which checks that the Process is

    not running in another CPU,and has not masked off task->processor from the