sched: add kernel thread creation and SMP-aware thread scheduling
This commit is contained in:
44
sched/core.c
44
sched/core.c
@@ -130,6 +130,50 @@ void schedule(enum sched_mode mode)
|
||||
} while (need_resched());
|
||||
}
|
||||
|
||||
struct runqueue *select_rq_for_thread(struct thread *thr)
|
||||
{
|
||||
struct runqueue *best_rq = NULL;
|
||||
unsigned int best_nthreads = 0;
|
||||
unsigned long flags;
|
||||
|
||||
unsigned int nr_cpu = cpu_get_highest_available() + 1;
|
||||
for (unsigned int i = 0; i < nr_cpu; i++) {
|
||||
if (!cpu_is_available(i) || !cpu_is_online(i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
struct runqueue *rq = cpu_rq(i);
|
||||
if (!rq) {
|
||||
continue;
|
||||
}
|
||||
|
||||
rq_lock(rq, &flags);
|
||||
unsigned int nthreads = rq->rq_nthreads;
|
||||
if (rq->rq_cur && rq->rq_cur != rq->rq_idle) {
|
||||
nthreads++;
|
||||
}
|
||||
rq_unlock(rq, flags);
|
||||
|
||||
if (!best_rq || nthreads < best_nthreads) {
|
||||
best_rq = rq;
|
||||
best_nthreads = nthreads;
|
||||
}
|
||||
}
|
||||
|
||||
return best_rq;
|
||||
}
|
||||
|
||||
void schedule_thread_on_cpu(struct thread *thr)
|
||||
{
|
||||
struct runqueue *rq = select_rq_for_thread(thr);
|
||||
if (rq) {
|
||||
unsigned long flags;
|
||||
rq_lock(rq, &flags);
|
||||
rq_enqueue(rq, thr);
|
||||
rq_unlock(rq, flags);
|
||||
}
|
||||
}
|
||||
|
||||
void start_charge_period(void)
|
||||
{
|
||||
struct thread *self = current_thread();
|
||||
|
||||
Reference in New Issue
Block a user