Extensions to the Data Structures

The scheduling methods that each scheduler class must provide are augmented by two additional functions on SMP systems:

struct sched_class {

#ifdef CONFIG_SMP

unsigned long (*load_balance) (struct rq *this_rq, int this_cpu, struct rq *busiest, unsigned long max_load_move, struct sched_domain *sd, enum cpu_idle_type idle int *all_pinned, int *this_best_prio);

int (*move_one_task) (struct rq *this_rq, int this_cpu, struct rq *busiest, struct sched_domain *sd, enum cpu_idle_type idle);

#endif

Despite their names, the functions are, however, not directly responsible to handle load balancing. They are called by the core scheduler code whenever the kernel deems rebalancing necessary. The scheduler class-specific functions then set up an iterator that allows the generic code to walk through all processes that are potential candidates to be moved to another queue, but the internal structures of the individual scheduler classes must not be exposed to the generic code because of the iterator. load_balance employs the generic function load_balance, while move_one_task uses iter_move_one_task. The functions serve different purposes:

□ iter_move_one_task picks one task off the busy run queue busiest and moves it to the run queue of the current CPU.

□ load_balance is allowed to distribute multiple tasks from the busiest run queue to the current CPU, but must not move more load than specified by max_load_move.

How is load balancing initiated? On SMP systems, the scheduler_tick periodic scheduler function invokes the trigger_load_balance function on completion of the tasks required for all systems as described above. This raises the schedule_softirq softlRQ (the software analog to hardware interrupts; see Chapter 14 for more details), which, in turn, guarantees that run_rebalance_domains will be run in due time. This function finally invokes load balancing for the current CPU by calling rebalance_domains. The time flow is illustrated in Figure 2-25.

To perform rebalancing, the kernel needs some more information. Run queues are therefore augmented with additional fields on SMP systems:

kernel/sched.c struct rq {

#ifdef CONFIG_SMP

struct sched_domain *sd; /* For active balancing */ int active_balance; int push_cpu;

struct task_struct *migration_thread; struct list_head migration_queue;

Timer tick scheduler_tick trigger_load_balance iULE_SOFTIRQ

Raise

Raise trigger_load_balance iULE_SOFTIRQ

run_rebalance_domains

rebalance_domains 1

Continue reading here: Figure 225 Time flow for initiation of load balancing on SMP systems

Was this article helpful?

0 0