Whamcloud - gitweb
tcpnal:
authorericm <ericm>
Thu, 4 Dec 2003 05:25:51 +0000 (05:25 +0000)
committerericm <ericm>
Thu, 4 Dec 2003 05:25:51 +0000 (05:25 +0000)
  originally tcpnal came with PtEQWait_timeout(), which implemented with
  longjmp. It shows some problems with pthreads, and even totally can't
  work on Opteron machines.
  Now use the pthread's internal timer to do timeout, but also brings some
  unclean things between portals - tcpnal. but it's ok at this moment.

lnet/lnet/api-eq.c
lnet/ulnds/procapi.c
lnet/ulnds/socklnd/procapi.c
lustre/portals/portals/api-eq.c
lustre/portals/unals/procapi.c

index 9bc9c36..e73d525 100644 (file)
@@ -119,6 +119,7 @@ int PtlEQWait(ptl_handle_eq_t eventq_in, ptl_event_t *event_out)
 }
 
 #ifndef __KERNEL__
+#if 0
 static jmp_buf eq_jumpbuf;
 
 static void eq_timeout(int signal)
@@ -162,6 +163,46 @@ int PtlEQWait_timeout(ptl_handle_eq_t eventq_in, ptl_event_t * event_out,
 
         return rc;
 }
+#else
+#include <errno.h>
 
-#endif
+/* FIXME
+ * Here timeout need a trick with tcpnal, definitely unclean but OK for
+ * this moment.
+ */
+
+/* global variables defined by tcpnal */
+extern int __tcpnal_eqwait_timeout_value;
+extern int __tcpnal_eqwait_timedout;
+
+int PtlEQWait_timeout(ptl_handle_eq_t eventq_in, ptl_event_t * event_out,
+                      int timeout)
+{
+        int rc;
+
+        if (!timeout)
+                return PtlEQWait(eventq_in, event_out);
+
+        __tcpnal_eqwait_timeout_value = timeout;
+
+        while ((rc = PtlEQGet(eventq_in, event_out)) == PTL_EQ_EMPTY) {
+                nal_t *nal = ptl_hndl2nal(&eventq_in);
+                
+                if (nal->yield)
+                        nal->yield(nal);
 
+                if (__tcpnal_eqwait_timedout) {
+                        if (__tcpnal_eqwait_timedout != ETIMEDOUT)
+                                printf("Warning: yield return error %d\n",
+                                        __tcpnal_eqwait_timedout);
+                        rc = PTL_EQ_EMPTY;
+                        break;
+                }
+        }
+
+        __tcpnal_eqwait_timeout_value = 0;
+
+        return rc;
+}
+#endif
+#endif /* __KERNEL__ */
index 2a3fbd8..d1a445f 100644 (file)
@@ -104,6 +104,12 @@ static int procbridge_validate(nal_t *nal, void *base, size_t extent)
 }
 
 
+/* FIXME cfs temporary workaround! FIXME
+ * global time out value
+ */
+int __tcpnal_eqwait_timeout_value = 0;
+int __tcpnal_eqwait_timedout = 0;
+
 /* Function: yield
  * Arguments:  pid:
  *
@@ -118,7 +124,19 @@ static void procbridge_yield(nal_t *n)
     procbridge p=(procbridge)b->local;
 
     pthread_mutex_lock(&p->mutex);
-    pthread_cond_wait(&p->cond,&p->mutex);
+    if (!__tcpnal_eqwait_timeout_value) {
+        pthread_cond_wait(&p->cond,&p->mutex);
+    } else {
+        struct timeval now;
+        struct timespec timeout;
+
+        gettimeofday(&now, NULL);
+        timeout.tv_sec = now.tv_sec + __tcpnal_eqwait_timeout_value;
+        timeout.tv_nsec = now.tv_usec * 1000;
+
+        __tcpnal_eqwait_timedout =
+                pthread_cond_timedwait(&p->cond, &p->mutex, &timeout);
+    }
     pthread_mutex_unlock(&p->mutex);
 }
 
index 2a3fbd8..d1a445f 100644 (file)
@@ -104,6 +104,12 @@ static int procbridge_validate(nal_t *nal, void *base, size_t extent)
 }
 
 
+/* FIXME cfs temporary workaround! FIXME
+ * global time out value
+ */
+int __tcpnal_eqwait_timeout_value = 0;
+int __tcpnal_eqwait_timedout = 0;
+
 /* Function: yield
  * Arguments:  pid:
  *
@@ -118,7 +124,19 @@ static void procbridge_yield(nal_t *n)
     procbridge p=(procbridge)b->local;
 
     pthread_mutex_lock(&p->mutex);
-    pthread_cond_wait(&p->cond,&p->mutex);
+    if (!__tcpnal_eqwait_timeout_value) {
+        pthread_cond_wait(&p->cond,&p->mutex);
+    } else {
+        struct timeval now;
+        struct timespec timeout;
+
+        gettimeofday(&now, NULL);
+        timeout.tv_sec = now.tv_sec + __tcpnal_eqwait_timeout_value;
+        timeout.tv_nsec = now.tv_usec * 1000;
+
+        __tcpnal_eqwait_timedout =
+                pthread_cond_timedwait(&p->cond, &p->mutex, &timeout);
+    }
     pthread_mutex_unlock(&p->mutex);
 }
 
index 9bc9c36..e73d525 100644 (file)
@@ -119,6 +119,7 @@ int PtlEQWait(ptl_handle_eq_t eventq_in, ptl_event_t *event_out)
 }
 
 #ifndef __KERNEL__
+#if 0
 static jmp_buf eq_jumpbuf;
 
 static void eq_timeout(int signal)
@@ -162,6 +163,46 @@ int PtlEQWait_timeout(ptl_handle_eq_t eventq_in, ptl_event_t * event_out,
 
         return rc;
 }
+#else
+#include <errno.h>
 
-#endif
+/* FIXME
+ * Here timeout need a trick with tcpnal, definitely unclean but OK for
+ * this moment.
+ */
+
+/* global variables defined by tcpnal */
+extern int __tcpnal_eqwait_timeout_value;
+extern int __tcpnal_eqwait_timedout;
+
+int PtlEQWait_timeout(ptl_handle_eq_t eventq_in, ptl_event_t * event_out,
+                      int timeout)
+{
+        int rc;
+
+        if (!timeout)
+                return PtlEQWait(eventq_in, event_out);
+
+        __tcpnal_eqwait_timeout_value = timeout;
+
+        while ((rc = PtlEQGet(eventq_in, event_out)) == PTL_EQ_EMPTY) {
+                nal_t *nal = ptl_hndl2nal(&eventq_in);
+                
+                if (nal->yield)
+                        nal->yield(nal);
 
+                if (__tcpnal_eqwait_timedout) {
+                        if (__tcpnal_eqwait_timedout != ETIMEDOUT)
+                                printf("Warning: yield return error %d\n",
+                                        __tcpnal_eqwait_timedout);
+                        rc = PTL_EQ_EMPTY;
+                        break;
+                }
+        }
+
+        __tcpnal_eqwait_timeout_value = 0;
+
+        return rc;
+}
+#endif
+#endif /* __KERNEL__ */
index 2a3fbd8..d1a445f 100644 (file)
@@ -104,6 +104,12 @@ static int procbridge_validate(nal_t *nal, void *base, size_t extent)
 }
 
 
+/* FIXME cfs temporary workaround! FIXME
+ * global time out value
+ */
+int __tcpnal_eqwait_timeout_value = 0;
+int __tcpnal_eqwait_timedout = 0;
+
 /* Function: yield
  * Arguments:  pid:
  *
@@ -118,7 +124,19 @@ static void procbridge_yield(nal_t *n)
     procbridge p=(procbridge)b->local;
 
     pthread_mutex_lock(&p->mutex);
-    pthread_cond_wait(&p->cond,&p->mutex);
+    if (!__tcpnal_eqwait_timeout_value) {
+        pthread_cond_wait(&p->cond,&p->mutex);
+    } else {
+        struct timeval now;
+        struct timespec timeout;
+
+        gettimeofday(&now, NULL);
+        timeout.tv_sec = now.tv_sec + __tcpnal_eqwait_timeout_value;
+        timeout.tv_nsec = now.tv_usec * 1000;
+
+        __tcpnal_eqwait_timedout =
+                pthread_cond_timedwait(&p->cond, &p->mutex, &timeout);
+    }
     pthread_mutex_unlock(&p->mutex);
 }