Re: Question about sched_yield()

Richard B. Johnson (root@chaos.analogic.com)
Tue, 18 Jun 2002 13:12:44 -0400 (EDT)


On Tue, 18 Jun 2002, Chris Friesen wrote:

> David Schwartz wrote:
> >
> > >And you seem to have a misconception about sched_yield, too. If a
> > >machine has n tasks, half of which are doing CPU-intense work and the
> > >other half of which are just yielding... why on Earth would the yielding
> > >tasks get any noticeable amount of CPU use?
> >
> > Because they are not blocking. They are in an endless CPU burning loop. They
> > should get CPU use for the same reason they should get CPU use if they're the
> > only threads running. They are always ready-to-run.
> >
> > >Quite frankly, even if the supposed standard says nothing of this... I
> > >do not care: calling sched_yield in a loop should not show up as a CPU
> > >hog.
> >
> > It has to. What if the only task running is:
> >
> > while(1) sched_yield();
> >
> > What would you expect?
>
> If there is only the one task, then sure it's going to be 100% cpu on that task.
>
> However, if there is anything else other than the idle task that wants to run,
> then it should run until it exhausts its timeslice.
>
> One process looping on sched_yield() and another one doing calculations should
> result in almost the entire system being devoted to calculations.
>
> Chris
>

It's all in the accounting. Use usleep(0) if you want it to "look good".

Cheers,
Dick Johnson

Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).

Windows-2000/Professional isn't.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/