by ask » Fri, 07 Oct 2005 06:23:42
uname -a
Linux smurf7 2.4.21-32.0.1.ELsmp #1 SMP Tue May 17 17:52:23 EDT 2005
i686 i686
cat /usr/src/linux-2.4/kernel/sched.c | grep migration
task_t *migration_thread;
struct list_head migration_queue;
* (such as the load balancing or the thread migration code), lock
#define migration_thread(cpu) (cpu_int(cpu)->migration_thread)
#define migration_queue(cpu) (&cpu_int(cpu)->migration_queue)
* We wake up one of the migration threads (it
if (rq->cpu[0].migration_thread)
wake_up_process(rq->cpu[0].migration_thread);
* imbalance. Since we are the migration thread, try to
INIT_LIST_HEAD(&rq1->cpu[cpu2_idx].migration_queue);
* This is how migration works:
* 1) we queue a migration_req_t structure in the source CPU's
* runqueue and wake up that CPU's migration thread.
* 3) migration thread wakes up (implicitly it forces the migrated
* 4) it gets the migration request and checks whether the migrated
* 5) if it's in the wrong runqueue then the migration thread removes
* 6) migration thread up()s the semaphore.
* 7) we wake up and the migration is done.
} migration_req_t;
migration_req_t req;
list_add(&req.list, migration_queue(cpu));
wake_up_process(migration_thread(cpu));
} migration_startup_t;
* migration_task - this is a highprio system thread that performs
* thread migration by 'pulling' threads into the target runqueue.
static int migration_task(void * data)
migration_startup_t *startup = data;
sprintf(current->comm, "migration/%d", cpu);
migration_thread(cpu) = current;
migration_req_t *req;
head = migration_queue(cpu);
req = list_entry(head->next, migration_req_t, list);
* migration_call - callback that gets triggered when a CPU is added.
* Here we can start up the necessary migration thread for the new CPU.
void migration_call(void *hcpu)
migration_startup_t startup;
printk("Starting migration thread for cpu %li\n", (long)hcpu);
kernel_thread(migration_task, &startup, CLONE_KERNEL);
while (!migration_thread(cpu))
__init int migration_init(void)
migration_call((void *)(long)cpu);
INIT_LIST_HEAD(migration_queue(i));