This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Thread scheduling


Giovanni Perbellini wrote:
Hi all,
I don't understand the behavoir of the scheduler.

I hope this isn't your homework ;-).


I have a simple application running two threads with euqal priority
(priority = 12).
When the execution starts the ISR function is executed and then the DSR
function is called.The DSR function executes the tick method to calculate the tick SW and
finally the timeslice function is executed to assign a time slot to a
thread (let's suppose to have a single cpu with the threads timeslice
disabled...unique timeslice associates to 1 cpu).
The timeslice calls timeslice_cpu function that checks if the current
thread is running, then tries to rotate the run queue and finally the
need_reschule flag is set.
        if( thread->get_state() == Cyg_Thread::RUNNING )
        {
            Cyg_Scheduler *sched = &Cyg_Scheduler::scheduler;
            CYG_INSTRUMENT_MLQ( TIMESLICE, thread, 0);
            CYG_ASSERTCLASS( thread, "Bad current thread");
            CYG_ASSERTCLASS( sched, "Bad scheduler");
            cyg_priority pri    = thread->priority;
            Cyg_RunQueue *queue = &sched->run_queue[pri];
      #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
            if( queue->get_head() != thread )
                sched->set_need_reschedule();
            timeslice_count[cpu_this] = CYGNUM_KERNEL_SCHED_TIMESLICE_TICKS;
        }

What happens when this function is finished?

Execution returns from the DSR.


Is the schedule method called?
I guess that the scheduler executes the same prevoius thread even if it
should the context switch. Why?

No. After the DSR returns, the HAL's interrupt processing in vectors.S will then call interrupt_end in src/intr/intr.cxx. This calls Cyg_Scheduler::unlock, which, if the scheduler count is 0 will call unlock_inner in src/sched/sched.cxx. That function actually does the context switch - have a look.


Jifl
--
eCosCentric    http://www.eCosCentric.com/    The eCos and RedBoot experts
>>>>> Visit us in booth 2527 at the Embedded Systems Conference 2004 <<<<<
March 30 - April 1, San Francisco http://www.esconline.com/electronicaUSA/
--["No sense being pessimistic, it wouldn't work anyway"]-- Opinions==mine


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]