[ECOS] some doubts in mlqueue.cxx code

Sergei Organov osv@topconrd.ru
Tue Nov 30 17:58:00 GMT 2004


Nick Garnett <nickg@ecoscentric.com> writes:
> sandeep <shimple0@yahoo.com> writes:
> 
> > There is this code fragment in timeslice_cpu and yield functions in
> > mlqueue.cxx
> > 
> > -----------------------------------------------------------------
> > ifdef CYGPKG_KERNEL_SMP_SUPPORT
> >     // In SMP systems we set the head of the queue to point to
> >     // the thread immediately after the current
> >     // thread. schedule() will then pick that thread, or one
> >     // after it to run next.
> > 
> >     queue->to_head( thread->get_next() );
> > #else
> >     queue->rotate();
> > #endif
> > -----------------------------------------------------------------
> > 
> > I am missing something in understanding the things here.
> > 
> > how the actions of rotating and to_head(get_next) are different?
> > except for the case when head is NULL.
> > but will NULL head situation ever arise in these functions?
> 
> rotate() just sets the head of the queue to the second thread in the
> queue. 
> 
> In the SMP case, the current thread may not be the head thread of the
> run queue. If there are several threads at the same priority then the
> first N such threads will be running on different CPUs. By setting the
> queue head to the thread after the current one, we reduce the amount
> of searching that the scheduler has to do to find a runnable thread.

So for non-SMP case the current thread is always the head of the run
queue, thus both variants are effectively the same? If so, why don't you
just use the SMP variant for non-SMP case as well? Not only it allows to
get rid of the ifdef, but also SMP variant seems to be faster than
non-SMP one as it neither needs to fetch 'queue->head' nor check it for
NULL, right?

-- 
Sergei.


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss



More information about the Ecos-discuss mailing list