[Beignet] [PATCH 1/2] [opencl 1.2]fix event related bugs.

Luo, Xionghu xionghu.luo at intel.com
Mon Apr 28 18:33:51 PDT 2014


Hi Rong,
Please review the two patches updated today. Both utest for events and confirmance test passed.
Thanks.

For PATCH1, added the wait_user_events update after the loop to fix regression.


Luo Xionghu
Best Regards

-----Original Message-----
From: Luo, Xionghu 
Sent: Tuesday, April 29, 2014 4:27 AM
To: beignet at lists.freedesktop.org
Cc: Luo, Xionghu
Subject: [PATCH 1/2] [opencl 1.2]fix event related bugs.

From: Luo <xionghu.luo at intel.com>

---
 src/cl_alloc.c |  1 +
 src/cl_event.c | 80 +++++++++++++++++++++++++++++++++-------------------------
 2 files changed, 47 insertions(+), 34 deletions(-)

diff --git a/src/cl_alloc.c b/src/cl_alloc.c index 20d5578..93d2e6a 100644
--- a/src/cl_alloc.c
+++ b/src/cl_alloc.c
@@ -71,6 +71,7 @@ cl_free(void *ptr)
     return;
   atomic_dec(&cl_alloc_n);
   free(ptr);
+  ptr = NULL;
 }
 
 LOCAL size_t
diff --git a/src/cl_event.c b/src/cl_event.c index 727ee1f..85e4041 100644
--- a/src/cl_event.c
+++ b/src/cl_event.c
@@ -260,12 +260,12 @@ void cl_event_new_enqueue_callback(cl_event event,
   cl_int i;
   GET_QUEUE_THREAD_GPGPU(data->queue);
 
-  /* Allocate and inialize the structure itself */
+  /* Allocate and initialize the structure itself */
   TRY_ALLOC_NO_ERR (cb, CALLOC(enqueue_callback));
   cb->num_events = num_events_in_wait_list;
   TRY_ALLOC_NO_ERR (cb->wait_list, CALLOC_ARRAY(cl_event, num_events_in_wait_list));
   for(i=0; i<num_events_in_wait_list; i++)
-    cb->wait_list[i] = event_wait_list[i];
+      cb->wait_list[i] = event_wait_list[i];
   cb->event = event;
   cb->next = NULL;
   cb->wait_user_events = NULL;
@@ -276,12 +276,13 @@ void cl_event_new_enqueue_callback(cl_event event,
       node = queue->wait_events[i]->waits_head;
       if(node == NULL)
         queue->wait_events[i]->waits_head = cb;
-      else
-        while((node != cb) && node->next)
-          node = node->next;
-        if(node == cb)   //wait on dup user event
-          continue;
-        node->next = cb;
+      else{
+          while((node != cb) && node->next)
+              node = node->next;
+          if(node == cb)   //wait on dup user event
+              continue;
+          node->next = cb;
+      }
 
       /* Insert the user event to enqueue_callback's wait_user_events */
       TRY_ALLOC_NO_ERR (u_ev, CALLOC(user_event)); @@ -291,7 +292,7 @@ void cl_event_new_enqueue_callback(cl_event event,
     }
   }
 
-  /* Find out all user events that events in event_wait_list wait */
+  /* Find out all user events that in event_wait_list wait */
   for(i=0; i<num_events_in_wait_list; i++) {
     if(event_wait_list[i]->status <= CL_COMPLETE)
       continue;
@@ -319,21 +320,25 @@ void cl_event_new_enqueue_callback(cl_event event,
       while(user_events != NULL) {
         /* Insert the enqueue_callback to user event's  waits_tail */
         node = user_events->event->waits_head;
-        while((node != cb) && node->next)
-          node = node->next;
-        if(node == cb) {  //wait on dup user event
-          user_events = user_events->next;
-          continue;
+        if(node == NULL)
+            event_wait_list[i]->waits_head = cb;
+        else{
+            while((node != cb) && node->next)
+                node = node->next;
+            if(node == cb) {  //wait on dup user event
+                user_events = user_events->next;
+                continue;
+            }
+            node->next = cb;
         }
-        node->next = cb;
 
         /* Insert the user event to enqueue_callback's wait_user_events */
         TRY_ALLOC_NO_ERR (u_ev, CALLOC(user_event));
         u_ev->event = user_events->event;
         u_ev->next = cb->wait_user_events;
         cb->wait_user_events = u_ev;
+        cl_command_queue_insert_event(event->queue, 
+ user_events->event);
         user_events = user_events->next;
-        cl_command_queue_insert_event(event->queue, event_wait_list[i]);
       }
     }
   }
@@ -354,7 +359,7 @@ error:
       cl_free(u_ev);
     }
     if(cb->wait_list)
-      cl_free(cb->wait_list);
+        cl_free(cb->wait_list);
     cl_free(cb);
   }
   goto exit;
@@ -363,7 +368,7 @@ error:
 void cl_event_set_status(cl_event event, cl_int status)  {
   user_callback *user_cb;
-  user_event    *u_ev, *u_ev_next;
+  user_event    *u_ev;
   cl_int ret, i;
   cl_event evt;
 
@@ -387,11 +392,11 @@ void cl_event_set_status(cl_event event, cl_int status)
 
       pthread_mutex_unlock(&event->ctx->event_lock);
       for(i=0; i<event->enqueue_cb->num_events; i++)
-        cl_event_delete(event->enqueue_cb->wait_list[i]);
+          cl_event_delete(event->enqueue_cb->wait_list[i]);
       pthread_mutex_lock(&event->ctx->event_lock);
 
       if(event->enqueue_cb->wait_list)
-        cl_free(event->enqueue_cb->wait_list);
+          cl_free(event->enqueue_cb->wait_list);
       cl_free(event->enqueue_cb);
       event->enqueue_cb = NULL;
     }
@@ -419,22 +424,29 @@ void cl_event_set_status(cl_event event, cl_int status)
   /* Check all defer enqueue */
   enqueue_callback *cb, *enqueue_cb = event->waits_head;
   while(enqueue_cb) {
-    /* Remove this user event in enqueue_cb */
-    while(enqueue_cb->wait_user_events &&
-          enqueue_cb->wait_user_events->event == event) {
-      u_ev = enqueue_cb->wait_user_events;
-      enqueue_cb->wait_user_events = enqueue_cb->wait_user_events->next;
-      cl_free(u_ev);
-    }
-
+    /* Remove this user event in enqueue_cb, update the header if 
+ needed. */
     u_ev = enqueue_cb->wait_user_events;
+    user_event * u_prev = NULL;
+    user_event *tmp =NULL;
     while(u_ev) {
-      u_ev_next = u_ev->next;
-      if(u_ev_next && u_ev_next->event == event) {
-        u_ev->next = u_ev_next->next;
-        cl_free(u_ev_next);
-      } else
-        u_ev->next = u_ev_next;
+        if(u_ev && u_ev->event == event) {
+            if(u_prev){
+                u_prev->next = u_ev->next;
+            }
+            tmp = u_ev;
+            u_ev = u_ev->next;
+            cl_free(tmp);
+        }else{
+            if(!u_prev){ 
+                enqueue_cb->wait_user_events = u_ev;
+            }
+            u_prev=u_ev;
+            u_ev = u_ev->next;
+        }
+    }
+
+    if(!u_prev){ 
+        enqueue_cb->wait_user_events = NULL;
     }
 
     /* Still wait on other user events */
--
1.8.1.2



More information about the Beignet mailing list