Below is a pared down version of my rt_process.c. I've cut out all COMEDI
data acquisition and FIFO stuff. I'm running rtlinux-2.3 on a single
processor computer without SMP support. I use mbuff-0.7.0 for shared
memory.

If I compile it with:
gcc -D INT_G -I/usr/src/rtl/linux/include -I/usr/src/rtlinux-2.3 
-I/usr/src/rtlinux-2.3/include -I/usr/src/rtlinux-2.3/include/posix -Wall 
-Wstrict-prototypes -O2 -D__RTL__ -D__KERNEL__ -DMODULE -pipe -fno-strength-reduce 
-m486 -malign-loops=2 -malign-jumps=2 -malign-functions=2 -DCPU=686 -g -c -o 
rt_process_tmp.o rt_process.c; ld -r -static rt_process_tmp.o -o rt_process.o 
-L/usr/lib -lm; rm -f rt_process_tmp.o   
my shared memory variable g is int, and the process runs fine.

If I compile it with:
gcc -D FLOAT_G -I/usr/src/rtl/linux/include -I/usr/src/rtlinux-2.3 
-I/usr/src/rtlinux-2.3/include -I/usr/src/rtlinux-2.3/include/posix -Wall 
-Wstrict-prototypes -O2 -D__RTL__ -D__KERNEL__ -DMODULE -pipe -fno-strength-reduce 
-m486 -malign-loops=2 -malign-jumps=2 -malign-functions=2 -DCPU=686 -g -c -o 
rt_process_tmp.o rt_process.c; ld -r -static rt_process_tmp.o -o rt_process.o 
-L/usr/lib -lm; rm -f rt_process_tmp.o   
my shared memory variable g is float, and my computer occasionally, but
not always, crashes at the first occurence of:  sh_mem->g/=2;

Note that I think (although it's difficult to know for sure with this sort
of "random" phenomenon) that if it runs fine once, it seems that it will
always run fine unless I reboot the computer. After rebooting, it may run
fine again. After rebooting again, it may run fine again, etc. But, sooner
or later, I'll reboot, insmod rt_process, and my system crashes.

The code is at the end of this message, preceded by some possibly useful
module and dmesg stuff.

Any ideas?

Thanks,
Dave

-----------
This is what modules I have running when it works - cat /proc/modules:
rt_process              1068   0 (unused)
mbuff                   6084   1 [rt_process]
rtl_fifo                7892   0 (unused)
rtl_posixio             6716   0 [rtl_fifo]
rtl_sched               5776   0 [rt_process]
kcomedilib              3136   0 (unused)
ni_atmio               14408   0
comedi                 14028   0 [kcomedilib ni_atmio]
rtl_time               11036   0 [rt_process rtl_posixio rtl_sched 
kcomedilib ni_atmio comedi]   
------------
This is dmesg after a brief successful run (terminated by rmmod):

dmesg
mbuff: kernel shared memory driver v0.7.0 for Linux 2.2.14-rtl2.3
mbuff: (C) Tomasz Motylewski et al., GPL
mbuff: registered as MISC device minor 254
allocated 1048576 bytes at cc849000 for cb2a3a20(default)
djc_float_crasher: requesting allocation of 8 bytes for sh_mem from mbuff:
allocated 4096 bytes at cc94c000 for cb2a3c60(djc_float_crasher)
djc_float_crasher: acquisition started at 1000 Hz (status 0)
djc_float_crasher g=50000000
djc_float_crasher g=25000000
djc_float_crasher g=12500000
djc_float_crasher g=6250000
deallocating kernel buffer at cc94c000(djc_float_crasher), count=0.
djc_float_crasher: deleted RT task (status 0) after 5461 cycles (~5
seconds).
unloading mbuff
deallocating kernel buffer at cc849000(default), count=0.
mbuff device deregistered                                   
---------

/************ rt_process.c **************/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/errno.h>
#include <rtl.h>
#include <rtl_fifo.h>
#include <rtl_sched.h>
#include <rtl_sync.h>
#include <rtl_debug.h>
#include <float.h>            //necessary for floating point ops?
#include <asm/types.h>        //necessary for floating point ops?
#include "/usr/src/rtl/drivers/mbuff/mbuff.h" //mbuff: shared memory dyn. alloc

#define RT_HZ 1000                        //rt_process loop frequency
#define RT_PROCESS_ID "djc_float_crasher" //text ID for this process

int init_module(void);        //set up RT stuff
void cleanup_module(void);    //clean up RT stuff
void init_shared_mem(void);   //set up RT shared memory

pthread_t daq_task;           //main RT task

typedef struct {
    int scan_index;         //index holding current analog input scan number
#ifdef FLOAT_G
    float g;                //g feedback proportionality control parameter
#endif
#ifdef INT_G
    int g;                  //g feedback proportionality control parameter
#endif
} SharedMemStruct;
volatile SharedMemStruct *sh_mem; //define mbuff shared memory

void *daq(void *arg) { /* this task reads and writes data to a DAQ board */

  while (1) /* must loop, b/c it is a periodic task */
    {
      sh_mem->scan_index++; //increment scan_index counter

      /* normally my COMEDI analog input and output goes here;
         instead here's a dumb computation*/
      if ((sh_mem->scan_index>2000)&&(!(sh_mem->scan_index%200))){
        sh_mem->g/=2;
        rtl_printf(RT_PROCESS_ID " g=%d\n",(int)sh_mem->g);
      }

      pthread_wait_np();             //wait until beginning of next period
    }
}

int init_module(void) {
  int ret;             //return value from function calls
  pthread_attr_t attr;
  struct sched_param sched_param;

  init_shared_mem();                        //initialize shared memory

  /* create the realtime task */
  pthread_attr_init(&attr);
  sched_param.sched_priority = 1;
  pthread_attr_setschedparam(&attr, &sched_param);
  if ((ret = pthread_create(&daq_task, &attr, daq, (void *)1))) {
    goto init_error;
  }

  /* make task periodic: run at a rate of RT_HZ */
  ret = pthread_make_periodic_np(daq_task, gethrtime(),NSECS_PER_SEC/RT_HZ);
  if (ret) goto init_error;

  rtl_printf(RT_PROCESS_ID ": acquisition started at %d Hz (status %d)\n", 
         RT_HZ, ret);
  return 0;

  //allow floating point operations ... see RTLinux FAQ
  pthread_setfp_np (daq_task, 1);

 init_error:
  rtl_printf(RT_PROCESS_ID ": can't initalize RT task (error %d)\n", ret);
  return 1;
}

void init_shared_mem(void) { // Initialize the rtlinux shared memory

  //allocate mbuff Shared Memory structure
  rtl_printf(RT_PROCESS_ID ": requesting allocation of %d bytes for sh_mem from 
mbuff:\n",
             sizeof(SharedMemStruct));
  sh_mem=(volatile SharedMemStruct*)mbuff_alloc(RT_PROCESS_ID,
                                                sizeof(SharedMemStruct));

  //initialize shared memory variables ... see rt_process.h for definitions
  sh_mem->scan_index=0;
  sh_mem->g=100000000;         //TRUE;
}

void cleanup_module(void) {
  int ret;

  //delete daq_task
  ret= pthread_delete_np(daq_task);
  rtl_printf(RT_PROCESS_ID ": deleted RT task (status %d) after %d cycles (~%d 
seconds).\n",
         ret, sh_mem->scan_index, sh_mem->scan_index/RT_HZ);

  //free up mbuff shared memory
  mbuff_free(RT_PROCESS_ID,sh_mem);

}


-- [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