|
From: <jmk...@us...> - 2003-08-03 02:41:47
|
Update of /cvsroot/emc/rtapi/src/rtapi
In directory sc8-pr-cvs1:/tmp/cvs-serv28730/src/rtapi
Modified Files:
rtai_rtapi.c rtapi.h
Log Message:
more tweaking of rtai_rtapi, added debugging printfs
Index: rtai_rtapi.c
===================================================================
RCS file: /cvsroot/emc/rtapi/src/rtapi/rtai_rtapi.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** rtai_rtapi.c 2 Aug 2003 23:30:43 -0000 1.10
--- rtai_rtapi.c 3 Aug 2003 02:41:44 -0000 1.11
***************
*** 8,15 ****
#include <linux/module.h>
#include <linux/kernel.h>
! /* FIXME - on my system malloc.h is deprecated, use slab.h instead */
! /* #include <linux/malloc.h> *//* kmalloc(), kfree(), GFP_USER */
! #include <linux/slab.h>
!
#include <rtai.h>
#include <rtai_sched.h>
--- 8,12 ----
#include <linux/module.h>
#include <linux/kernel.h>
! #include <linux/slab.h> /* replaces malloc.h in recent kernels */
#include <rtai.h>
#include <rtai_sched.h>
***************
*** 28,33 ****
--- 25,36 ----
#endif
+ /* declare vsprintf() explicitly instead of including all of <stdio.h>,
+ since we don't need all of it and it may cause problems */
+ extern int vsprintf(char *s, const char *format, va_list arg);
+
#include "rtapi.h" /* these decls */
+ /* set to 1/0 to enable/disable logging of task creation etc. */
+ #define VERBOSE 1
/* These structs hold data associated with objects like tasks, etc. */
***************
*** 63,72 ****
#define FIFO_MAGIC 10293
! /* Usage counter so that we don't kill the periodic timer too soon */
! static int usage_count = 0;
! /* declare vsprintf() explicitly instead of including all of <stdio.h>,
! since we don't need all of it and it may cause problems */
! extern int vsprintf(char *s, const char *format, va_list arg);
/* Priority functions. RTAI uses 0 as the highest priority, as the
--- 66,78 ----
#define FIFO_MAGIC 10293
! /* Usage counters to keep track of new/delete calls */
! static int task_usage_count = 0;
! static int shmem_usage_count = 0;
! static int sem_usage_count = 0;
! static int fifo_usage_count = 0;
! static int int_usage_count = 0;
! /* Flag used to keep track of timer state */
! static int timer_running = 0;
/* Priority functions. RTAI uses 0 as the highest priority, as the
***************
*** 117,121 ****
static int rtapi_init(void)
{
! rtapi_print("Initing RTAPI\n");
rt_linux_use_fpu(1);
return RTAPI_SUCCESS;
--- 123,133 ----
static int rtapi_init(void)
{
! rtapi_print("RTAPI: Initing\n");
! task_usage_count = 0;
! shmem_usage_count = 0;
! sem_usage_count = 0;
! fifo_usage_count = 0;
! int_usage_count = 0;
! timer_running = 0;
rt_linux_use_fpu(1);
return RTAPI_SUCCESS;
***************
*** 125,132 ****
static int rtapi_exit(void)
{
! if (usage_count != 0 ) {
! rtapi_print(" Warning, you have %d task handlers active", usage_count);
}
! rtapi_print("Removing RTAPI\n");
return RTAPI_SUCCESS;
}
--- 137,159 ----
static int rtapi_exit(void)
{
! if (task_usage_count != 0 ) {
! rtapi_print("RTAPI: ERROR: %d task(s) allocated but not deleted", task_usage_count);
}
! if (shmem_usage_count != 0 ) {
! rtapi_print("RTAPI: ERROR: %d shared memory block(s) allocated but not deleted", shmem_usage_count);
! }
! if (sem_usage_count != 0 ) {
! rtapi_print("RTAPI: ERROR: %d semaphores(s) allocated but not deleted", sem_usage_count);
! }
! if (fifo_usage_count != 0 ) {
! rtapi_print("RTAPI: ERROR: %d fifo(s) allocated but not deleted", fifo_usage_count);
! }
! if (int_usage_count != 0 ) {
! rtapi_print("RTAPI: ERROR: %d interrupt handler(s) installed but not removed", int_usage_count);
! }
! if (timer_running != 0 ) {
! rt_free_timer();
! }
! rtapi_print("RTAPI: Shutting down\n");
return RTAPI_SUCCESS;
}
***************
*** 146,149 ****
--- 173,180 ----
int rtapi_clock_set_period(unsigned long int nsecs)
{
+ if ( VERBOSE ) {
+ rtapi_print ( "RTAPI: clock_set_period ( %ld )\n", nsecs );
+ }
+ timer_running = 1;
rt_set_periodic_mode();
return count2nano(start_rt_timer(nano2count((RTIME) nsecs)));
***************
*** 176,180 ****
/* increment the usage counter */
! usage_count++;
return RTAPI_SUCCESS;
--- 207,215 ----
/* increment the usage counter */
! task_usage_count++;
!
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: new_task %p, count = %d\n", task, task_usage_count );
! }
return RTAPI_SUCCESS;
***************
*** 196,200 ****
/* decrement the usage counter */
! usage_count--;
return RTAPI_SUCCESS;
--- 231,239 ----
/* decrement the usage counter */
! task_usage_count--;
!
! if ( VERBOSE ) {
! rtapi_print ( "RTAPI: delete_task %p, count = %d\n", task, task_usage_count );
! }
return RTAPI_SUCCESS;
***************
*** 268,280 ****
}
- /* P.C.
- Added these lines to release the 8254 IRQ and stop the timer
- as it was causing a kernel panic after removing rtai_sched.
- */
-
- if (usage_count == 0) {
- rt_free_timer();
- }
-
retval = rt_task_delete(&(task->ostask));
if (retval != 0) {
--- 307,310 ----
***************
*** 413,416 ****
--- 443,454 ----
/* return handle to the caller */
*shmemptr = shmem;
+
+ /* increment the usage counter */
+ shmem_usage_count++;
+
+ if ( VERBOSE ) {
+ rtapi_print ( "RTAPI: new_shmem %p, key = %d, count = %d\n", shmem, key, shmem_usage_count );
+ }
+
return RTAPI_SUCCESS;
}
***************
*** 448,451 ****
--- 486,497 ----
shmem->magic = 0;
kfree(shmem);
+
+ /* decrement the usage counter */
+ shmem_usage_count--;
+
+ if ( VERBOSE ) {
+ rtapi_print ( "RTAPI: delete_shmem %p, count = %d\n", shmem, shmem_usage_count );
+ }
+
return RTAPI_SUCCESS;
}
***************
*** 492,495 ****
--- 538,549 ----
}
}
+
+ /* increment the usage counter */
+ int_usage_count++;
+
+ if ( VERBOSE ) {
+ rtapi_print ( "RTAPI: assign_interrupt_handler for int %d, count = %d\n", irq, int_usage_count );
+ }
+
return RTAPI_SUCCESS;
}
***************
*** 505,508 ****
--- 559,570 ----
return RTAPI_FAIL;
}
+
+ /* decrement the usage counter */
+ int_usage_count--;
+
+ if ( VERBOSE ) {
+ rtapi_print ( "RTAPI: free_interrupt_handler for int %d, count = %d\n", irq, int_usage_count );
+ }
+
return RTAPI_SUCCESS;
}
***************
*** 558,561 ****
--- 620,631 ----
/* return handle to the caller */
*semptr = sem;
+
+ /* increment the usage counter */
+ sem_usage_count++;
+
+ if ( VERBOSE ) {
+ rtapi_print ( "RTAPI: new_sem %p, count = %d\n", sem, sem_usage_count );
+ }
+
return RTAPI_SUCCESS;
}
***************
*** 577,580 ****
--- 647,658 ----
sem->magic = 0;
kfree(sem);
+
+ /* decrement the usage counter */
+ sem_usage_count--;
+
+ if ( VERBOSE ) {
+ rtapi_print ( "RTAPI: delete_sem %p, count = %d\n", sem, sem_usage_count );
+ }
+
return RTAPI_SUCCESS;
}
***************
*** 652,657 ****
/* create failed */
kfree(fifo);
- rtapi_print("rtapi_fifo_new: rtf_create ( %d, %d ) returned %d\n", key,
- size, retval);
if (retval == ENOMEM) {
/* couldn't allocate memory */
--- 730,733 ----
***************
*** 669,672 ****
--- 745,756 ----
/* return handle to the caller */
*fifoptr = fifo;
+
+ /* increment the usage counter */
+ fifo_usage_count++;
+
+ if ( VERBOSE ) {
+ rtapi_print ( "RTAPI: new_fifo %p, count = %d\n", fifo, fifo_usage_count );
+ }
+
return RTAPI_SUCCESS;
}
***************
*** 688,691 ****
--- 772,783 ----
fifo->magic = 0;
kfree(fifo);
+
+ /* decrement the usage counter */
+ fifo_usage_count--;
+
+ if ( VERBOSE ) {
+ rtapi_print ( "RTAPI: delete_fifo %p, count = %d\n", fifo, fifo_usage_count );
+ }
+
return RTAPI_SUCCESS;
}
Index: rtapi.h
===================================================================
RCS file: /cvsroot/emc/rtapi/src/rtapi/rtapi.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** rtapi.h 2 Aug 2003 19:37:18 -0000 1.9
--- rtapi.h 3 Aug 2003 02:41:44 -0000 1.10
***************
*** 70,74 ****
* multiple realtime tasks in multiple kernel modules. Calling this *
* function after realtime tasks have been started may disrupt the *
! * tasks. Returns a status code. */
extern int rtapi_clock_set_period(unsigned long int nsecs);
--- 70,85 ----
* multiple realtime tasks in multiple kernel modules. Calling this *
* function after realtime tasks have been started may disrupt the *
! * tasks. Returns a negative error code on failure. On success, *
! * returns either 0, or if the RTOS supports it, the actual timer *
! * period in nanoseconds, (which may not be exactly what was requested *
! * due to hardware limitations). */
!
! /* FIXME - the request is an unsigned long int, but the return value is
! an ordinary signed int. A request of 3,000,000,000 ( 3 secs) is a
! a legal unsigned number, but when returned as a signed int it will
! be negative, and look like an error to the caller. Possible solutions:
! 1) limit the argument to 1,000,000,000 (1 second), return INVAL if higher
! 2) don't return actual value, just return success or errorcode (as before)
! */
extern int rtapi_clock_set_period(unsigned long int nsecs);
|