I posted this same problem a couple days ago, and would like to thank
those of you who helped out, but my glitch still exists. Every now and
again, my system hangs for ~1ms. Running a periodic thread of any period,
the glitch is always the same duration: 1.1 to 1.3 ms on one machine or
.5 to .6 ms on another. I think it's safe to say that the glitch is
prohibiting me from doing hard realtime processing.

The code below is very short and simple. It compiles with the standard
options available as variables in rtl.mk, and the module depends on
rtl_sched and rtl_time. All you have to do is compile, insert, wait(for me
30 seconds is enough), and dmesg.

Typical dmesg output

> Delay of     192ns near       0ms
> Delay of     288ns near      95ms
> Delay of     352ns near    1609ms
> Delay of     384ns near    1648ms
> Delay of     448ns near   23322ms
> Delay of 1141792ns near  937517ms
> Delay of 1224000ns near 1530446ms

You see the two vastly different scales. The first 5 maximum delays are
fractions of a microsecond, no problem. The later 2 delays are >100
periods of the periodic task!

Any advice would be greatly appreciated.
Thanks in advance - Chuck


// Stipped down DAQ code - Chuck
 
// ***** System headers ***** //
#include <rtl.h>
#include <rtl_sync.h>
#include <time.h>
#include <pthread.h>
 
// ***** System Definitions ***** //
#define FREQUENCY 100000                    // Thread frequency [=] Hz
 
// ***** Function Declarations ***** //
void *daq_code(void*);                      // DAQ Periodic function
 
// ***** Global Variables ***** //
pthread_t daq_thread;                       // main rtlinux thread
 
 
// Simple thread measures clock 
void *daq_code(void *param)
{
   rtl_irqstate_t irqstate;
 
   hrtime_t zero_time,  tick_time, tock_time;
   long     delay_time, delay,     max_delay=0;
 
   zero_time = clock_gethrtime(CLOCK_REALTIME);  // module insert time
 
   while (1)      // periodic task, must loop
     {
 
       // Begin DANGER
       rtl_no_interrupts(irqstate);             // disable all interrupts
 
       tick_time = clock_gethrtime(CLOCK_REALTIME);     //check time
       tock_time = clock_gethrtime(CLOCK_REALTIME);     //check time
       delay     = (long)(tock_time - tick_time);       //find difference
 
       rtl_restore_interrupts(irqstate);        // reenable interrupts
       // End DANGER
 
 
       if (delay > max_delay)           //is this the biggest delay yet?
        {
          // reset delay max
          max_delay  = delay;           //record new maximum delay
 
          // reset time of max, >>20 is ~equal to /1e6
          delay_time = (long)((tock_time - zero_time)>>20);
 
          printk( "Delay of %7ldns near %7ldms\n", max_delay, delay_time);
        }
 
       pthread_wait_np( );              //wait for next period
     }    
}
 
 
// ***** Module Standard Functions ***** ///
 
int init_module(void)
{
   pthread_attr_t attr;
   struct sched_param sched_param;
   hrtime_t period, soon;
 
   // initialize pthread attributes
   if( pthread_attr_init(&attr) ) 
     printk( "Cannot initialize pthread attributes\n" );
 
   // modify pthread priority
   sched_param.sched_priority = 1;
   if ( pthread_attr_setschedparam (&attr, &sched_param) )
     printk( "Cannot set pthread priority: 0\n" );
   
   // initialize the main thread
   if( pthread_create (&daq_thread, &attr, daq_code,(void *)1) )
     printk( "Cannot create pthread\n" );
 
   // make the thread run off the CPU clock
   period = HRTICKS_PER_SEC / FREQUENCY;
   soon   = clock_gethrtime(CLOCK_REALTIME) + (100 * period);
   if( pthread_make_periodic_np (daq_thread, soon, period) )
     printk( "Cannot make pthread periodic\n" );
 
   return 0;
}
 
void cleanup_module(void)
{
   // destroy periodic thread
   if( pthread_delete_np(daq_thread) )
     printk( "Cannot destroy phread\n" );
}


-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/

Reply via email to