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]

Problems with Thread-start up delays


I've been doing some experimenting with an application on eCos 1.3.1
where I launch a worker thread repeatedly from my main thread. The work
done by the worker thread does not take very long - perhaps
milliseconds. It is important however, that time required to start up
the thread is negligible compared to the time spent doing the work in
the thread. I checked the real-time characterization numbers from the
"Getting Started with eCos" documentation for the Cirrus Logic EP7212
73MHz (although I'm using the EP7312 at the same frequency, I wouldn't
expect a difference). All of the numbers are on the order of
microseconds or tens of microseconds.
 
However, when I tried my code, it appeared that I wasn't getting the
performance that I had expected. I decided to perform a test to check
the delay associated with resuming a thread. In my main thread, I change
the state of an I/O pin and  launch a test thread which simply waits for
a specified time (the thread just spins in a for loop). When this delay
expires, the test thread sets a global variable flag and exits. The main
thread waits for this flag to be set before changing the state of the
I/O pin again. The main thread loops continuously. I've pasted the code
below:
 

#define STACKSIZE 10240
 
static char stack[STACKSIZE], stack2[STACKSIZE];
static cyg_handle_t hmainThread, htestThread;
static cyg_thread mainThread_obj, testThread_obj;
static void MainProc(CYG_ADDRESS data);
static void TestThread(CYG_ADDRESS data);
bool g_done;
 
extern "C" void cyg_user_start(void)
{
cyg_thread_create(4, MainProc, (cyg_addrword_t)0, "mainproc",
       (void*)&stack, STACKSIZE, &hmainThread, 
       &mainThread_obj);
 cyg_thread_resume(hmainThread);
}
static void MainProc(CYG_ADDRESS data)
{
 HAL_IO_REGISTER PortDOut = 0x80000003;         // output pin
 int x;
 cyg_thread_create(4, TestThread, (cyg_addrword_t)0, "testproc",
       (void*)&stack2, STACKSIZE, &htestThread, 
       &testThread_obj);
 while (1)
 {
  g_done=false;
  HAL_WRITE_UINT8(PortDOut, 0x06);     // set output pin Hi
  cyg_thread_resume(htestThread);                 // start test thread
  while (g_done == false);                              // wait for test
thread to finish
  g_done = false;
  HAL_WRITE_UINT8(PortDOut, 0x04);   // set output pin Lo
  cyg_thread_resume(htestThread);               // start test thread
  while (g_done == false);                            // wait for test
thread to finish
 }
}
  
static void TestThread(CYG_ADDRESS data)
{
 int x;
 g_done = false;
 for (x=0; x<2500; x++);      // spin for about 625 microseconds
 g_done = true;
 cyg_thread_exit();
}

When I checked the I/O pin on an oscilloscope, I didn't see the state of
the pin changing slightly more than every 625 microseconds. Instead, the
state would change about every 40-50 milliseconds. I changed the 625
microsecond delay a number of times and did not see a significant
difference on the 'scope. I would only see the period on the 'scope
matching the period set in the code when the delay in the test thread
was significantly greater than 50 milliseconds. I should mention that I
have verified the actual time required to spin in the for loop in an
independent test (eg. 500 spins takes about 125 microseconds, 2500 spins
takes about 625 microseconds on my board).
 
The results of this test suggest to me that there is delay of
approximately 40 or 50 milliseconds associated with resuming a thread.
However, this disagrees with what has been published in the eCos
documentaion. Have I missed something in the interpretation of my
results or the code itself? Can anyone offer an explanation for what I
have observed?
 
Thanks for any assistance,
 
CHRIS.
 

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