[Spread-cvs] commit: r416 - in branches/events_testing: daemon include

jschultz at spread.org jschultz at spread.org
Sun May 17 18:34:06 EDT 2009


Author: jschultz
Date: 2009-05-17 18:34:06 -0400 (Sun, 17 May 2009)
New Revision: 416

Modified:
   branches/events_testing/daemon/events.c
   branches/events_testing/daemon/events.old.c
   branches/events_testing/daemon/microbench_events_pipes.c
   branches/events_testing/include/sp_events.h
Log:
Added some code to test program to test timers and added cleanup code to look for memory leaks.  Fixed a memory leak 
in epoll backend.  Slightly changed how we decide on a timeout for a query.


Modified: branches/events_testing/daemon/events.c
===================================================================
--- branches/events_testing/daemon/events.c	2009-05-17 18:45:47 UTC (rev 415)
+++ branches/events_testing/daemon/events.c	2009-05-17 22:34:06 UTC (rev 416)
@@ -1,6 +1,6 @@
 #include "arch.h"
 
-/*#define HAVE_LINUX*/
+#define HAVE_LINUX
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -356,7 +356,7 @@
     goto FAIL;
   }
 
-  if (stdskl_construct(&events->fd_watches, sizeof(int), sizeof(E_fd_watch*), NULL) != 0) {
+  if (stdskl_construct(&events->fd_watches, sizeof(int), sizeof(E_fd_watch*), E_int_cmp) != 0) {
     ret = E_ALLOC_FAILURE;
     goto FAIL_TIME_WATCHES;
   }
@@ -489,7 +489,7 @@
   }
 
   stdskl_destruct(&events->time_watches);
-  memset(&events, 0, sizeof(*events));
+  memset(events, 0, sizeof(*events));
 }
 
 /***************************************************************************************************************************
@@ -608,8 +608,8 @@
       for (starve_lvl = events->max_priority; starve_lvl >= events->active_threshold; --starve_lvl) {
 
         if (starve_lvl != dispatch_lvl && 
-	    events->priorities[starve_lvl].starve_thresh != 0 &&
-	    events->priorities[starve_lvl].num_active_fd_watches != 0) {
+            events->priorities[starve_lvl].starve_thresh != 0 &&
+            events->priorities[starve_lvl].num_active_fd_watches != 0) {
           ++events->priorities[starve_lvl].starve_cnter;
         }
       }
@@ -720,29 +720,44 @@
       timeout->sec  = 0;
       timeout->usec = 0;
 
-    } else if (!stdskl_empty(&events->timeouts)) {  /* else calculate an appropriate timeout */
+    } else {  /* else calculate an appropriate timeout */
 
-      abs_timeout = (const sp_time*) stdskl_it_key(stdskl_begin(&events->timeouts, &sit));
+      abs_timeout = NULL;
 
-      E_events_update_loop_time(events);
+      for (stdskl_begin(&events->timeouts, &sit); !stdskl_is_end(&events->timeouts, &sit); stdskl_it_next(&sit)) {
 
-      timeout->sec  = abs_timeout->sec  - events->last_loop_time.sec;
-      timeout->usec = abs_timeout->usec - events->last_loop_time.usec;
-      
-      if (timeout->usec < 0) {
-        timeout->usec += 1000000;
-        --timeout->sec;
+        watch = *(E_watch**) stdskl_it_val(&sit);
+
+        if (watch->priority < events->active_threshold) {
+          continue;  /* NOTE: don't allow watches that we will ignore anyway to wake us early */
+        }
+
+        abs_timeout = (const sp_time*) stdskl_it_key(&sit);
+        break;
       }
 
-      assert(timeout->usec >= 0 && timeout->usec < 1000000);
+      if (abs_timeout != NULL) {
+        E_events_update_loop_time(events);
+
+        timeout->sec  = abs_timeout->sec  - events->last_loop_time.sec;
+        timeout->usec = abs_timeout->usec - events->last_loop_time.usec;
       
-      if (timeout->sec < 0) {  /* earliest timeout has already expired */
-        timeout->sec  = 0;
-        timeout->usec = 0;
+        if (timeout->usec < 0) {
+          timeout->usec += 1000000;
+          --timeout->sec;
+        }
+
+        assert(timeout->usec >= 0 && timeout->usec < 1000000);
+      
+        if (timeout->sec < 0) {  /* earliest timeout has already expired */
+          timeout->sec  = 0;
+          timeout->usec = 0;
+        }
+
+      } else {
+        /* NOTE: backend query mechanism must return an error if not watching any fds to avoid sleeping forever */
+        timeout = NULL;
       }
-
-    } else {  /* NOTE: backend query mechanism must return an error if not watching any fds and timeout == NULL to avoid sleeping forever */
-      timeout = NULL;
     }
 
     switch (events->backend_type) {
@@ -1952,6 +1967,7 @@
   assert(fd_watch->w.watch_type >= 0 && fd_watch->w.watch_type <= NUM_FDTYPES);
   assert(!fd_watch->active);
 
+  memset(&epoll_evnt, 0, sizeof(epoll_evnt));
   epoll_evnt.data.fd = fd_watch->fd;
   stdskl_lowerb(&events->fd_watches, &fd_it, &fd_watch->fd);  /* find the beginning of all the watches on the fd */
 
@@ -2274,7 +2290,8 @@
       ret = E_ALLOC_FAILURE;
       goto FAIL;
     }
-    
+
+    free(info->events);
     info->events     = evnt;
     info->num_events = 2 * lvl_info->num_poll_fds;
     assert(info->num_events >= lvl_info->num_poll_fds);
@@ -2347,11 +2364,11 @@
       /* push a new notice onto the associated priority's notice queue and record where it is */
 
       if (generate_notice &&
-	  stddll_insert(&events->priorities[fd_watch->w.priority].notices, 
-			stddll_end(&events->priorities[fd_watch->w.priority].notices, &fd_watch->w.notice_it), 
-			&fd_watch) != 0) {
-	ret = E_ALLOC_FAILURE;
-	goto FAIL;
+          stddll_insert(&events->priorities[fd_watch->w.priority].notices, 
+                        stddll_end(&events->priorities[fd_watch->w.priority].notices, &fd_watch->w.notice_it), 
+                        &fd_watch) != 0) {
+        ret = E_ALLOC_FAILURE;
+        goto FAIL;
       }
 
       fd_watch->w.noticed = STDTRUE;      

Modified: branches/events_testing/daemon/events.old.c
===================================================================
--- branches/events_testing/daemon/events.old.c	2009-05-17 18:45:47 UTC (rev 415)
+++ branches/events_testing/daemon/events.old.c	2009-05-17 22:34:06 UTC (rev 416)
@@ -100,6 +100,10 @@
 int     E_set_elevate_count( int priority, unsigned count ) { return 0; }
 int     E_get_elevate_count( int priority, unsigned *count ) { return 0; }
 
+int     E_queue_periodic( void (* func)( int code, void *data ), int code, void *data, sp_time period ) { return 0; }
+
+void    E_fini(void) {}
+
 int 	E_init(void)
 {
 	int	i,ret;

Modified: branches/events_testing/daemon/microbench_events_pipes.c
===================================================================
--- branches/events_testing/daemon/microbench_events_pipes.c	2009-05-17 18:45:47 UTC (rev 415)
+++ branches/events_testing/daemon/microbench_events_pipes.c	2009-05-17 22:34:06 UTC (rev 416)
@@ -15,6 +15,7 @@
 int     Num_Pipes     = 1000;
 int     Num_Ops       = 100000;
 int     Num_Pending   = 1;
+sp_time Timeout       = { 1, 0 };
 int     Seed          = 0;
 
 int     Num_Ops_Done  = 0;
@@ -131,6 +132,24 @@
 /***************************************************************************************************************************
  ***************************************************************************************************************************/
 
+void delta_timeout(int code, void * data)
+{
+  fprintf(stdout, "delta_timeout: code is %d, data is %p\r\n", code, data);
+
+  E_queue(delta_timeout, code + 1, (char*) data + 1, Timeout);
+}
+
+/***************************************************************************************************************************
+ ***************************************************************************************************************************/
+
+void periodic_timeout(int code, void * data)
+{
+  fprintf(stdout, "periodic_timeout: code is %d, data is %p\r\n", code, data);
+}
+
+/***************************************************************************************************************************
+ ***************************************************************************************************************************/
+
 void usage(int argc, char ** argv)
 {
   switch (argc) {
@@ -172,6 +191,24 @@
 /***************************************************************************************************************************
  ***************************************************************************************************************************/
 
+void fini(void)
+{
+  int i;
+
+  E_fini();
+
+  for (i = 0; i != Num_Pipes; ++i) {
+    close(Pipes[i][0]);
+    close(Pipes[i][1]);
+  }
+
+  free(Pipes);
+  stdskl_destruct(&Active_Fds);
+}
+
+/***************************************************************************************************************************
+ ***************************************************************************************************************************/
+
 int main(int argc, char ** argv) 
 {
   int ret;
@@ -238,8 +275,11 @@
   /* loop handling events */
 
   E_set_elevate_count(HIGH_PRIORITY, 1);
-  E_set_elevate_count(LOW_PRIORITY, 5);
+  E_set_elevate_count(LOW_PRIORITY, 1);
 
+  E_queue(delta_timeout, 0, NULL, Timeout);
+  E_queue_periodic(periodic_timeout, -1, NULL, Timeout);
+
   T1 = E_get_time();
 
   ret = E_handle_events();
@@ -251,6 +291,9 @@
   fprintf(stdout, "Took %ld.%06ld seconds for an average rate of %f ops/s!\r\n", 
 	  T3.sec, T3.usec, Num_Ops / (T3.sec + T3.usec / 1000000.0));
 
+  fini();
+  fprintf(stdout, "Bye!\r\n");
+
   return 0;
 }
 

Modified: branches/events_testing/include/sp_events.h
===================================================================
--- branches/events_testing/include/sp_events.h	2009-05-17 18:45:47 UTC (rev 415)
+++ branches/events_testing/include/sp_events.h	2009-05-17 22:34:06 UTC (rev 416)
@@ -74,6 +74,7 @@
 /* Event routines */
 
 int     E_init( void );
+void    E_fini( void );
 
 int     E_queue( void (* func)( int code, void *data ), int code, void *data, sp_time delta );
 int     E_queue_absolute( void (* func)( int code, void *data ), int code, void *data, sp_time absolute );




More information about the Spread-cvs mailing list