Skip to content

Commit

Permalink
sched_yield(): avoid schedule for single thread
Browse files Browse the repository at this point in the history
  • Loading branch information
bgerofi committed Dec 5, 2016
1 parent 0ab7d02 commit ddc3382
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion kernel/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -6449,7 +6449,23 @@ SYSCALL_DECLARE(nanosleep)

SYSCALL_DECLARE(sched_yield)
{
schedule();
struct cpu_local_var *v;
int do_schedule = 0;
long runq_irqstate;

runq_irqstate =
ihk_mc_spinlock_lock(&(get_this_cpu_local_var()->runq_lock));
v = get_this_cpu_local_var();

if (v->flags & CPU_FLAG_NEED_RESCHED || v->runq_len > 1) {
do_schedule = 1;
}

ihk_mc_spinlock_unlock(&v->runq_lock, runq_irqstate);

if (do_schedule) {
schedule();
}

return 0;
}
Expand Down

0 comments on commit ddc3382

Please sign in to comment.