Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

vipl_macros.h

Go to the documentation of this file.
00001 /********************************************************
00002  * Myricom VI-GM  networking software and documentation *
00003  * Copyright (c) 2001 by Myricom, Inc.                  *
00004  * All rights reserved.                                 *
00005  * See the file `COPYING' for copyright notice.         *
00006  ********************************************************/
00007 
00008 #ifndef __VIPL_MACROS
00009 #define __VIPL_MACROS
00010 
00017 /***********/
00018 /* threads */
00019 /***********/
00020 
00021 #ifndef WIN32
00022 
00024 #define VIP_THREAD_T pthread_t
00025 
00026 #define VIP_THREAD_CREATE(thread,fctn,arg) \
00027 pthread_create (thread, NULL, fctn, arg)
00028 
00029 #define VIP_THREAD_JOIN(thread) pthread_join (thread, NULL)
00030 
00031 #define VIP_THREAD_EXIT(retval) pthread_exit (retval)
00032 
00033 #define VIP_THREAD_SELF() pthread_self()
00034 
00035 #else
00036 
00038 #define VIP_THREAD_T vipl_win_thread_t
00039 #define VIP_THREAD_CREATE(thread,fctn,arg) \
00040 vipl_win_thread_create (thread, fctn, arg)
00041 #define VIP_THREAD_JOIN(thread) vipl_win_thread_join (thread, NULL)
00042 #define VIP_THREAD_EXIT(retval) vipl_win_thread_exit (retval)
00043 #define VIP_THREAD_SELF() vipl_win_thread_self()
00044 
00045 #endif
00046 
00047 /***********/
00048 /* mutexes */
00049 /***********/
00050 
00051 #ifndef WIN32
00052 
00054 #define VIP_MUTEX_T pthread_mutex_t
00055 
00056 #ifdef VI_GM_DEBUG_MUTEX /* VI_GM_DEBUG_MUTEX */
00057 #include <asm/errno.h>
00059 #define VIP_MUTEX_ATTR pthread_mutexattr_t vip_mutex_attr
00060 extern pthread_mutexattr_t vip_mutex_attr;
00061 int pthread_mutexattr_setkind_np (pthread_mutexattr_t *, int);
00063 #define VIP_MUTEX_INIT(lock)                                                \
00064 pthread_mutexattr_init (&vip_mutex_attr);                                   \
00065 pthread_mutexattr_setkind_np (&vip_mutex_attr,PTHREAD_MUTEX_ERRORCHECK_NP); \
00066 pthread_mutex_init (lock,&vip_mutex_attr)
00067 
00068 #define VIP_ASSERT_MUTEX_LOCKED(lock) \
00069 assert (pthread_mutex_lock (lock) == EDEADLK)
00070 #else /* VI_GM_DEBUG_MUTEX */
00071 
00072 #define VIP_MUTEX_ATTR
00073 
00074 #define VIP_MUTEX_INIT(lock) pthread_mutex_init (lock,NULL)
00075 
00076 #define VIP_ASSERT_MUTEX_LOCKED(lock)
00077 #endif /* VI_GM_DEBUG_MUTEX */
00078 
00080 #define VIP_MUTEX_TRYLOCK(lock) \
00081 ((pthread_mutex_trylock (lock) == EBUSY) ? VIP_FALSE : VIP_TRUE)
00082 
00083 #ifdef VI_GM_DEBUG_ASSERT /* VI_GM_DEBUG_ASSERT */
00084 
00085 #define VIP_MUTEX_DESTROY(lock) assert (pthread_mutex_destroy (lock) == 0)
00086 
00087 #define VIP_MUTEX_LOCK(lock) assert (pthread_mutex_lock (lock) == 0)
00088 
00089 #define VIP_MUTEX_UNLOCK(lock) assert (pthread_mutex_unlock (lock) == 0)
00090 #else /* VI_GM_DEBUG_ASSERT */
00091 
00092 #define VIP_MUTEX_DESTROY(lock) pthread_mutex_destroy (lock)
00093 
00094 #define VIP_MUTEX_LOCK(lock) pthread_mutex_lock (lock)
00095 
00096 #define VIP_MUTEX_UNLOCK(lock) pthread_mutex_unlock (lock)
00097 #endif /* VI_GM_DEBUG_ASSERT */
00098 
00099 #else
00100 
00101 #define VIP_MUTEX_T CRITICAL_SECTION
00102 #define VIP_MUTEX_INIT(lock) InitializeCriticalSection (lock)
00103 #define VIP_ASSERT_MUTEX_LOCKED(lock)
00104 #define VIP_MUTEX_DESTROY(lock) DeleteCriticalSection (lock)
00105 #define VIP_MUTEX_LOCK(lock) EnterCriticalSection (lock)
00106 #define VIP_MUTEX_UNLOCK(lock) LeaveCriticalSection (lock)
00107 #define VIP_MUTEX_TRYLOCK(lock) TryEnterCriticalSection (lock)
00108 
00109 #endif
00110 
00111 /*******************/
00112 /* event signaling */
00113 /*******************/
00114 
00115 #ifndef WIN32
00116 
00118 #define VIP_EVENT_T pthread_cond_t
00119 
00120 #define VIP_EVENT_INIT(event) pthread_cond_init (event, NULL)
00121 
00122 #define VIP_EVENT_SIGNAL(event) pthread_cond_signal (event)
00123 
00124 #define VIP_EVENT_WAIT(event,lock) pthread_cond_wait (event,lock)
00125 
00126 #define VIP_EVENT_WAIT_TIMEOUT(event,lock,timeout) \
00127 pthread_cond_timedwait (event,lock,timeout)
00128 #ifdef VI_GM_DEBUG_ASSERT /* VI_GM_DEBUG_ASSERT */
00129 
00130 #define VIP_EVENT_DESTROY(event) assert (pthread_cond_destroy (event) == 0)
00131 #else /* VI_GM_DEBUG_ASSERT */
00132 
00133 #define VIP_EVENT_DESTROY(event) pthread_cond_destroy (event)
00134 #endif /* VI_GM_DEBUG_ASSERT */
00135 
00136 #else
00137 
00138 #define VIP_EVENT_T HANDLE
00139 #define VIP_EVENT_INIT(event) *event=CreateEvent(NULL,FALSE,FALSE,NULL)
00140 #define VIP_EVENT_SIGNAL(event) SetEvent(*event)
00141 #define VIP_EVENT_WAIT(event,lock)        \
00142 do {                                      \
00143   VIP_MUTEX_UNLOCK (lock);                \
00144   WaitForSingleObject (*event, INFINITE); \
00145   VIP_MUTEX_LOCK (lock);                  \
00146 } while (0)
00147 #define VIP_EVENT_WAIT_TIMEOUT(event,lock,abstime)               \
00148 do {                                                             \
00149   double timestart, timestop, timegap;                           \
00150   struct timeval tv;                                             \
00151   DWORD milli;                                                   \
00152   vip_gettimeofday (&tv, NULL);                                  \
00153   timestart = tv.tv_sec + tv.tv_usec/1000000.;                   \
00154   timestop = (abstime)->tv_sec + (abstime)->tv_nsec/1000000000.; \
00155   timegap = (timestop - timestart) * 1000.;                      \
00156   milli = (timegap < 0.0) ? 0 : (DWORD) timegap;                 \
00157   VIP_MUTEX_UNLOCK (lock);                                       \
00158   WaitForSingleObject (*event, milli);                           \
00159   VIP_MUTEX_LOCK (lock);                                         \
00160 } while (0)
00161 #define VIP_EVENT_DESTROY(event) CloseHandle(*event)
00162 
00163 #endif
00164 
00165 
00166 /**************/
00167 /* semaphores */
00168 /**************/
00169 
00170 #ifndef WIN32
00171 
00173 #define VIP_SEMAPHORE_T sem_t
00174 
00175 #define VIP_SEMAPHORE_WAIT(sema) sem_wait (sema)
00176 #ifdef VI_GM_DEBUG_ASSERT /* VI_GM_DEBUG_ASSERT */
00177 
00178 #define VIP_SEMAPHORE_INIT(sema,value) assert (sem_init(sema,0,value) == 0)
00179 
00180 #define VIP_SEMAPHORE_DESTROY(sema) assert (sem_destroy (sema) == 0)
00181 
00182 #define VIP_SEMAPHORE_POST(sema) assert (sem_post (sema) == 0)
00183 #else /* VI_GM_DEBUG_ASSERT */
00184 
00185 #define VIP_SEMAPHORE_INIT(sema,value) sem_init(sema,0,value)
00186 
00187 #define VIP_SEMAPHORE_DESTROY(sema) sem_destroy (sema)
00188 
00189 #define VIP_SEMAPHORE_POST(sema) sem_post (sema)
00190 #endif /* VI_GM_DEBUG_ASSERT */
00191 
00192 #else
00193 
00194 #define VIP_SEMAPHORE_T HANDLE
00195 #define VIP_SEMAPHORE_WAIT(sema) WaitForSingleObject (*sema, INFINITE)
00196 #define VIP_SEMAPHORE_INIT(sema,value) \
00197 *sema = CreateSemaphore (NULL, value, 0x7FFFFFFFL, NULL)
00198 #define VIP_SEMAPHORE_DESTROY(sema) CloseHandle (*sema)
00199 #define VIP_SEMAPHORE_POST(sema) ReleaseSemaphore (*sema, 1, NULL)
00200 
00201 #endif
00202 
00203 
00204 /*************/
00205 /* AVL trees */
00206 /*************/
00207 
00209 #define VIP_AVL_TREE_T avl_tree *
00210 
00211 #define VIP_AVL_TREE_INIT(tree) \
00212 tree = avl_create (vip_avl_compare_function, NULL)
00213 
00214 #define VIP_AVL_TREE_DESTROY(tree) avl_destroy (tree, vip_avl_free_function)
00215 
00216 #define VIP_AVL_TREE_FIND(tree,data) avl_find (tree, data)
00217 #ifdef VI_GM_DEBUG_ASSERT /* VI_GM_DEBUG_ASSERT */
00218 
00219 #define VIP_AVL_TREE_INSERT(tree,data) assert (avl_insert (tree, data) == 0)
00220 
00221 #define VIP_AVL_TREE_DELETE(tree,data) assert (avl_delete (tree, data) != 0)
00222 #else /* VI_GM_DEBUG_ASSERT */
00223 
00224 #define VIP_AVL_TREE_INSERT(tree,data) avl_insert (tree, data)
00225 
00226 #define VIP_AVL_TREE_DELETE(tree,data) avl_delete (tree, data)
00227 #endif /* VI_GM_DEBUG_ASSERT */
00228 
00229 
00231 #define VIP_NOTICE(args) vip_notice args
00232 
00233 #ifdef VI_GM_DEBUG_ASSERT /* VI_GM_DEBUG_ASSERT */
00234 
00235 #define VIP_ASSERT(exp) assert (exp)
00236 #else /* VI_GM_DEBUG_ASSERT */
00237 
00238 #define VIP_ASSERT(exp)
00239 #endif /* VI_GM_DEBUG_ASSERT */
00240 
00242 #define VIP_INVALID_NIC_HANDLE(vip_nic_ptr)                                \
00243 ((vip_nic_ptr == NULL)                                                     \
00244  || (((VIP_UINTPTR) vip_nic_ptr) <= VI_GM_MAX_NIC_HANDLES)                 \
00245  || (vip_nic_ptr->magic != VIP_NIC_MAGIC))
00246 
00248 #define VIP_INVALID_PTAG_HANDLE(vip_ptag_ptr)                              \
00249 ((vip_ptag_ptr == NULL) || (vip_ptag_ptr->handle.magic != VIP_PTAG_MAGIC)  \
00250  || (vip_ptag_ptr->handle.vip_nic_ptr->magic != VIP_NIC_MAGIC))
00251 
00253 #define VIP_INVALID_CQ_HANDLE(vip_cq_ptr)                                  \
00254 ((vip_cq_ptr == NULL) || (vip_cq_ptr->handle.magic != VIP_CQ_MAGIC)        \
00255  || (vip_cq_ptr->handle.vip_nic_ptr->magic != VIP_NIC_MAGIC))
00256 
00258 #define VIP_INVALID_VI_HANDLE(vip_vi_ptr)                                  \
00259 ((vip_vi_ptr == NULL)                                                      \
00260  || (((VIP_UINTPTR) vip_vi_ptr) <= VI_GM_MAX_VI)                           \
00261  || (vip_vi_ptr->handle.magic != VIP_VI_MAGIC)                             \
00262  || (vip_vi_ptr->handle.vip_nic_ptr->magic != VIP_NIC_MAGIC))
00263 
00265 #define VIP_INVALID_MEM_HANDLE(vip_mem_ptr)                                \
00266 ((vip_mem_ptr == NULL)                                                     \
00267  || (((VIP_UINTPTR) vip_mem_ptr) <= VI_GM_MAX_REGISTER_REGIONS)            \
00268  || (vip_mem_ptr->handle.magic != VIP_MEM_MAGIC)                           \
00269  || (vip_mem_ptr->handle.vip_nic_ptr->magic != VIP_NIC_MAGIC))
00270 
00272 #define VIP_INVALID_CONN_HANDLE(vip_conn_ptr)                              \
00273 ((vip_conn_ptr == NULL) || (vip_conn_ptr->handle.magic != VIP_CONN_MAGIC)  \
00274  || (vip_conn_ptr->handle.vip_nic_ptr->magic != VIP_NIC_MAGIC))
00275 
00277 #define VIP_FILL_GENERIC_HEAD(ptr,len,vi,type_code)                        \
00278 ptr->vip_pkt_eager_ur.type = VIP_HTON_UCHAR (type_code);                   \
00279 ptr->vip_pkt_eager_ur.length_24 = VIP_HTON_UCHAR ((len & 0xFF0000) >> 16); \
00280 ptr->vip_pkt_eager_ur.length_16 = VIP_HTON_UCHAR ((len & 0xFF00) >> 8);    \
00281 ptr->vip_pkt_eager_ur.length_8 = VIP_HTON_UCHAR (len & 0xFF);              \
00282 ptr->vip_pkt_eager_ur.net_remote_nic_index = vi->net_remote_nic_index;     \
00283 ptr->vip_pkt_eager_ur.net_remote_vi_index = vi->net_remote_vi_index
00284 
00286 #define VIP_ENTER_IOCTL(gm_ptr)
00287 
00288 #define VIP_EXIT_IOCTL(gm_ptr)
00289 
00291 #define VIP_PROGRESSION(gm_ptr)                                            \
00292 do                                                                         \
00293   {                                                                        \
00294     if (VIP_MUTEX_TRYLOCK (&(gm_ptr->recv_lock)) == VIP_TRUE)              \
00295       {                                                                    \
00296         vip_receive_event (gm_ptr, VIP_FALSE);                             \
00297         VIP_MUTEX_UNLOCK (&(gm_ptr->recv_lock));                           \
00298       }                                                                    \
00299   }                                                                        \
00300 while (0)
00301 
00303 #define STRINGIZE(arg) #arg
00304 
00305 #define XSTRINGIZE(arg) STRINGIZE(arg)
00306 
00307 #define LINE_STR XSTRINGIZE(__LINE__)
00308 
00309 #ifdef VI_GM_DEBUG_PRINT /* VI_GM_DEBUG_PRINT */
00310 
00311 #define VIP_DEBUG(args)                                                   \
00312 do                                                                        \
00313   {                                                                       \
00314     char hostname[64];                                                    \
00315     char fmt[4096];                                                       \
00316     char *output;                                                         \
00317                                                                           \
00318     VIP_ASSERT (vip_gethostname (hostname, 64) == 0);                     \
00319     output = vip_vsprintf args;                                           \
00320     if (output != NULL)                                                   \
00321       {                                                                   \
00322         sprintf (fmt, "VI-GM [%s/%lu] <%s>: %s (%s:%s)\n", hostname,      \
00323                  (unsigned long) VIP_THREAD_SELF (), function_name,       \
00324                  output, __FILE__, LINE_STR);                             \
00325         fprintf (stderr, fmt);                                            \
00326         free (output);                                                    \
00327       }                                                                   \
00328   }                                                                       \
00329 while (0)
00330 
00332 #define VIP_DEBUG_GM(args)                                                \
00333 do                                                                        \
00334   {                                                                       \
00335     char fmt[4096];                                                       \
00336     char *output;                                                         \
00337                                                                           \
00338     output = vip_vsprintf args;                                           \
00339     if (output != NULL)                                                   \
00340       {                                                                   \
00341         sprintf (fmt, "VI-GM <%s>: %s (%s:%s)\n", function_name,          \
00342                  output, __FILE__, LINE_STR);                             \
00343         gm_perror (fmt, gm_status);                                       \
00344       }                                                                   \
00345     free (output);                                                        \
00346   }                                                                       \
00347 while (0)
00348 
00350 #define VIP_DEBUG_LABEL(name)                                   \
00351 const char function_name[64] = name;                            \
00352 VIP_DEBUG ((""))
00353 
00355 #define VIP_DEBUG_PROTECTED(args)                               \
00356 VIP_MUTEX_LOCK (&vip_gm_host_name_lock);                        \
00357 VIP_ENTER_IOCTL (vip_gm_ptr);                                   \
00358 VIP_DEBUG (args)                                                \
00359 VIP_EXIT_IOCTL (vip_gm_ptr);                                    \
00360 VIP_MUTEX_UNLOCK (&vip_gm_host_name_lock)
00361 
00363 #define VIP_DEBUG_GM_PROTECTED(args)                            \
00364 VIP_MUTEX_LOCK (&vip_gm_host_name_lock);                        \
00365 VIP_DEBUG_GM (args);                                            \
00366 VIP_MUTEX_UNLOCK (&vip_gm_host_name_lock)
00367 
00368 #define VIP_ABORT(args) VIP_DEBUG (args); abort ()
00369 
00370 #else /* VI_GM_DEBUG_PRINT */
00371 
00372 #define VIP_DEBUG_LABEL(name)
00373 
00374 #define VIP_DEBUG(args)
00375 
00376 #define VIP_DEBUG_GM(args)
00377 
00379 #define VIP_DEBUG_PROTECTED(args)
00380 
00382 #define VIP_DEBUG_GM_PROTECTED(args)
00383 
00384 #define VIP_ABORT(args) VIP_DEBUG (("Print Debug not enabled")); abort ()
00385 #endif /* VI_GM_DEBUG_PRINT */
00386 
00387 
00388 
00389 #ifdef VI_GM_DEBUG_CHECKSUM     /* VI_GM_DEBUG_CHECKSUM */
00390 
00391 #define VI_GM_DEBUG_CHECKSUM_SMALL VIP_PKT_CKSUM cksum_small;
00392 
00393 #define VI_GM_DEBUG_CHECKSUM_LARGE VIP_PKT_CKSUM cksum_large;
00394 
00395 #define VI_GM_DEBUG_CHECKSUM_COMPUTE(cksum_ptr,buf,len) \
00396 vi_gm_debug_checksum_compute(cksum_ptr, buf, len)
00397 
00398 #define VI_GM_DEBUG_CHECKSUM_CHECK(msg,buf,from,cksum_ptr) \
00399 vi_gm_debug_checksum_check(msg, buf, from, cksum_ptr)
00400 
00401 #define VI_GM_DEBUG_CHECKSUM_COPY(cksum_target,cksum_source) \
00402 vi_gm_debug_checksum_copy(cksum_target, cksum_source)
00403 #else /* VI_GM_DEBUG_CHECKSUM */
00404 
00405 #define VI_GM_DEBUG_CHECKSUM_SMALL
00406 
00407 #define VI_GM_DEBUG_CHECKSUM_LARGE
00408 
00409 #define VI_GM_DEBUG_CHECKSUM_COMPUTE(cksum_ptr,buf,len)
00410 
00411 #define VI_GM_DEBUG_CHECKSUM_CHECK(msg,buf,from,cksum_ptr)
00412 
00413 #define VI_GM_DEBUG_CHECKSUM_COPY(cksum_target,cksum_source)
00414 #endif /* VI_GM_DEBUG_CHECKSUM */
00415 
00416 
00417 
00418 /*****************/
00419 /* Magic numbers */
00420 /*****************/
00421 
00423 #define VIP_NIC_MAGIC  0xCAFE
00424 
00425 #define VIP_VI_MAGIC   0xABCD
00426 
00427 #define VIP_CQ_MAGIC   0xBABA
00428 
00429 #define VIP_PTAG_MAGIC 0xDEDE
00430 
00431 #define VIP_MEM_MAGIC  0xFADE
00432 
00433 #define VIP_CONN_MAGIC 0xFFAA
00434 
00435 
00436 
00437 /****************/
00438 /* Send buffers */
00439 /****************/
00440 
00442 #define VIP_SEND_REQ_NONE          1
00443 
00444 #define VIP_SEND_REQ_DMA           2
00445 
00446 #define VIP_SEND_REQ_MALLOC        4
00447 
00448 #define VIP_SEND_REQ_RELIABLE      8
00449 
00450 #define VIP_SEND_REQ_UNRELIABLE   16
00451 
00452 #define VIP_SEND_REQ_RDMA_WRITE   32
00453 
00455 #define VIP_SEND_REQ_OPMASK \
00456 (VIP_SEND_REQ_RELIABLE + VIP_SEND_REQ_UNRELIABLE + VIP_SEND_REQ_RDMA_WRITE)
00457 
00458 #define VIP_SEND_REQ_TYPEMASK \
00459 (VIP_SEND_REQ_NONE + VIP_SEND_REQ_DMA + VIP_SEND_REQ_MALLOC)
00460 
00461 
00462 
00463 /****************/
00464 /* Report types */
00465 /****************/
00466 
00468 #define VIP_REPORT_COMPLETION_RR    1
00469 
00470 #define VIP_REPORT_REM_DESC_ERROR   2
00471 
00472 #define VIP_REPORT_INVALID_SENDER   4
00473 
00474 #define VIP_REPORT_RECV_QUEUE_EMPTY 8
00475 
00476 #define VIP_REPORT_RDMA_PROT_ERROR  16
00477 
00478 #define VIP_REPORT_CONN_LOST        32
00479 
00481 #define VIP_CONN_TYPE_CLIENT 1
00482 
00483 #define VIP_CONN_TYPE_SERVER 2
00484 
00485 #define VIP_CONN_TYPE_PEER   4
00486 
00487 
00488 
00489 /***********************/
00490 /* network order stuff */
00491 /***********************/
00492 
00494 #define VIP_NET_UCHAR gm_u8_n_t
00495 
00496 #define VIP_NET_UINT16 gm_u16_n_t
00497 
00498 #define VIP_NET_UINT32 gm_u32_n_t
00499 
00500 #define VIP_NET_UINT64 gm_u64_n_t
00501 
00503 #define VIP_HTON_UCHAR(x)  gm_hton_u8 (x)
00504 
00505 #define VIP_HTON_UINT16(x) gm_hton_u16 (x)
00506 
00507 #define VIP_HTON_UINT32(x) gm_hton_u32 (x)
00508 
00509 #define VIP_HTON_UINT64(x) gm_hton_u64 (x)
00510 
00512 #define VIP_NTOH_UCHAR(x)  gm_ntoh_u8 (x)
00513 
00514 #define VIP_NTOH_UINT16(x) gm_ntoh_u16 (x)
00515 
00516 #define VIP_NTOH_UINT32(x) gm_ntoh_u32 (x)
00517 
00518 #define VIP_NTOH_UINT64(x) gm_ntoh_u64 (x)
00519 
00520 
00521 #endif
VI-GM-1.3 by Myricom © 1997-2006. Documentation generated on 20 May 2006 by doxygen 1.4.4.