Re: sched_yield() makes OpenLDAP slow

From: Nikita Danilov
Date: Sat Aug 20 2005 - 17:09:20 EST


Howard Chu writes:
> Nikita Danilov wrote:
> > That returns us to the core of the problem: sched_yield() is used to
> > implement a synchronization primitive and non-portable assumptions are
> > made about its behavior: SUS defines that after sched_yield() thread
> > ceases to run on the CPU "until it again becomes the head of its thread
> > list", and "thread list" discipline is only defined for real-time
> > scheduling policies. E.g.,
> >
> > int sched_yield(void)
> > {
> > return 0;
> > }
> >
> > and
> >
> > int sched_yield(void)
> > {
> > sleep(100);
> > return 0;
> > }
> >
> > are both valid sched_yield() implementation for non-rt (SCHED_OTHER)
> > threads.
> I think you're mistaken:
> http://groups.google.com/group/comp.programming.threads/browse_frm/thread/0d4eaf3703131e86/da051ebe58976b00#da051ebe58976b00
>
> sched_yield() is required to be supported even if priority scheduling is
> not supported, and it is required to cause the calling thread (not
> process) to yield the processor.

Of course sched_yield() is required to be supported, the question is for
how long CPU is yielded. Here is the quote from the SUS (actually the
complete definition of sched_yield()):

The sched_yield() function shall force the running thread to
relinquish the processor until it again becomes the head of its
thread list.

As far as I can see, SUS doesn't specify how "thread list" is maintained
for non-RT scheduling policy, and implementation that immediately places
SCHED_OTHER thread that called sched_yield() back at the head of its
thread list is perfectly valid. Also valid is an implementation that
waits for 100 seconds and then places sched_yield() caller to the head
of the list, etc. Basically, while semantics of sched_yield() are well
defined for RT scheduling policy, for SCHED_OTHER policy standard leaves
it implementation defined.

>
> --
> -- Howard Chu

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