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: Time slice is not happening quiet alright


Think about this case...

Thread 0 calls 
	printf("%d:%d\n",(int)data,(int)cyg_current_time());

Its in the middle of the printf when the time slice happens. For
printf to be thread safe, it has to use some sort of protection, eg a
mutex. So this mutex is locked.

Thread 1 gets to run and call printf. It finds the mutex is locked and
imeadiately blocks. This allows thread 0 to run and it will run until
it is time sliced. So it looks like thread 0 has run for two slices,
but in fact thread 1 did get to run, but could not do anything.

Your test program can alone time slice as you want it, when it does
not have the mutex locked. Since its going to have the mutex most of
the time, you get the results you see.

    Andrew


On Thu, Aug 29, 2002 at 05:28:43PM +0000, Mike A wrote:
> Hi,
> 
> I wrote a small test program to study about the accuracy of time slicing 
> (Round robin scheduling) with ecos. The results show that the time-slice or 
> scheduling was happening at irregular time intervals.
> 
> I created two threads of the same priority & started them. Ideally each of 
> them should run alternately for exactly 5 ticks (5 ticks is the configured 
> time-slice). I guess the scheduler was getting called at every 5 ticks, but 
> some times the thread switching was not happening, so the running thread 
> ran continuously for 2 slots & some time 3, 4, 5, & so on…
> 
> Why is this happening? Am I missing some thing here?
> 
> Cheers,
> -Mike.
> 
> Ecos version: synced to the latest from CVS
> HAL: cirrus logic EDB7xxx development board
> CPU: EP7312 (ARM720T) running at ~74MHz
> 
> My test code:
> ------------
> 
> #include <cyg/kernel/kapi.h>
> 
> cyg_thread thread_s[2];		/* space for two thread objects */
> 
> char stack[2][4096];		/* space for two 4K stacks */
> 
> cyg_handle_t simple_threadA, simple_threadB;
> 
> cyg_thread_entry_t simple_program;
> 
> void cyg_user_start(void)
> {
> 	printf("Entering twothreads' cyg_user_start() function\n");
> 
> 	cyg_thread_create(4, simple_program, (cyg_addrword_t) 0,
> 		    "Thread A", (void *) stack[0], 4096,
> 		    &simple_threadA, &thread_s[0]);
> 	cyg_thread_create(4, simple_program, (cyg_addrword_t) 1,
> 		    "Thread B", (void *) stack[1], 4096,
> 		    &simple_threadB, &thread_s[1]);
> 
> 	cyg_thread_resume(simple_threadA);
> 	cyg_thread_resume(simple_threadB);
> }
> 
> void simple_program(cyg_addrword_t data)
> {
> 	while(1)
> 	{
> 		printf("%d:%d\n",(int)data,(int)cyg_current_time());
> 	}
> }
> 
> 
> Output:
> -------
> 
> Entering twothreads' cyg_user_start() function
> 0:0
> 0:1
> 0:1

[Snip]

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


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