For Kernel_Newbies By a Kernel_Newbie
allowed_cpus. If an idle task is running in task->processor (best_cpu) and if
need_resched is not set to -1,and if this_cpu (current->processor) is not
equal to best_cpu,it sends a reschedule event to that cpu.(smp_send_reschedule).
If an idle_task is not running,then it loops through the list of processors,and
tries to find an idle_task which has not run for the maximum time,or tries to
locate a task with a positive maximum pre-emption goodness if it fails in
getting an idle task on all cpus,before sending a reschedule event on that cpu.
The goodness routine which tries to find the goodness value is pretty simple.It
masks out SCHED_YIELD with a negative return,real_time tasks with SCHED_FIFO and
SCHED_RR policies are given the maximum increment of +1000 on a
task->rt_priority.The SCHED_OTHER guys,get their time_slices added with their
NICE value. (-20 highest to +19 lowest.) There are also many helper functions
defined in sched.c which might be of interest. wake_ups aside,schedule_timeout
is one such function which uses Kernel Timers (check it out for timer_list
usage., to schedule out a task,and bring it back into action. (see
include/linux/timer.h.) Kernel Timers can be used when one wants to run a
tasklet at a defined time in future. You can set the expiry interval of the
timer in jiffies (number of clock_ticks since System Boot, and is incremented HZ
(include/linux/param.h) times/SEC.
{
struct timer_list your_timer;
init_timer(&your_timer);
your_timer.expires = jiffies + HZ * 5;
your_timer.function = your_function;
your_timer.data = (unsigned long)current;
add_timer(&your_timer); /*It gets called after 5 secs,which is set as the
expiry of the timer. */
}
Signal Handling :
In order to get inside signal_handling,one should focus on
kernel/signal.c,and arch/i386/kernel/signal.c. Also look up the headers in
include/{asm,linux}/{sigcontext.h,siginfo.h,signal.h} for the data_structures.
Each signal has a stack frame. Thats setup in set_sigcontext
(arch/i386/kernel/signal.c), by storing the stack of the user at the time of
ret_from_sys_call(a.k.a struct pt_regs,include/asm/ptrace.h), in the sigcontext
structure. This way,it performs a magic to switch to signal handler,by setting
up the stack context to the sigframe. Try analysing the sigframe structure which
- « first
- ‹ previous
- of 24
- next ›
- last »