Debian Codegraph @

test/dapltest/mdep/linux/dapl_mdep_user.h

raw
1 /*
2 * Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved.
3 *
4 * This Software is licensed under one of the following licenses:
5 *
6 * 1) under the terms of the "Common Public License 1.0" a copy of which is
7 * in the file LICENSE.txt in the root directory. The license is also
8 * available from the Open Source Initiative, see
9 * http://www.opensource.org/licenses/cpl.php.
10 *
11 * 2) under the terms of the "The BSD License" a copy of which is in the file
12 * LICENSE2.txt in the root directory. The license is also available from
13 * the Open Source Initiative, see
14 * http://www.opensource.org/licenses/bsd-license.php.
15 *
16 * 3) under the terms of the "GNU General Public License (GPL) Version 2" a
17 * copy of which is in the file LICENSE3.txt in the root directory. The
18 * license is also available from the Open Source Initiative, see
19 * http://www.opensource.org/licenses/gpl-license.php.
20 *
21 * Licensee has the right to choose one of the above licenses.
22 *
23 * Redistributions of source code must retain the above copyright
24 * notice and one of the license notices.
25 *
26 * Redistributions in binary form must reproduce both the above copyright
27 * notice, one of the license notices in the documentation
28 * and/or other materials provided with the distribution.
29 */
30
31 #ifndef __DAPL_MDEP_USER_H__
32 #define __DAPL_MDEP_USER_H__
33
34 /* include files */
35
36 #include <ctype.h>
37 #include <stdlib.h>
38 #include <inttypes.h>
39 #include <netdb.h>
40 #include <unistd.h>
41 #include <pthread.h>
42 #include <stdio.h>
43 #include <string.h>
44 #include <sys/times.h>
45 #include <sys/time.h>
46
47 /* inet_ntoa */
48 #include <sys/socket.h>
49 #include <netinet/in.h>
50 #include <arpa/inet.h>
51
52 /* Default Device Name */
53 #define DT_MdepDeviceName "ofa-v2-ib0"
54
55 /* Boolean */
56 typedef int bool;
57
58 #define true (1)
59 #define false (0)
60
61 #ifndef __BASE_FILE__
62 #define __BASE_FILE__ __FILE__
63 #endif
64
65 #ifndef _INLINE_
66 #define _INLINE_ __inline__
67 #endif
68
69 /*
70 * Locks
71 */
72
73 typedef pthread_mutex_t DT_Mdep_LockType;
74
75 /* Wait object used for inter thread communication */
76
77 typedef struct
78 {
79 bool signaled;
80 pthread_cond_t cv;
81 pthread_mutex_t lock;
82 } DT_WAIT_OBJECT;
83
84 /*
85 * Thread types
86 */
87 typedef pthread_t DT_Mdep_ThreadHandleType;
88 typedef void (*DT_Mdep_ThreadFunction) (void *param);
89 typedef void * DT_Mdep_Thread_Start_Routine_Return_Type;
90 #define DT_MDEP_DEFAULT_STACK_SIZE 65536
91
92 typedef struct
93 {
94 void (*function) (void *);
95 void *param;
96 DT_Mdep_ThreadHandleType thread_handle;
97 unsigned int stacksize;
98 pthread_attr_t attr; /* Thread attributes */
99 } Thread;
100
101 /*
102 * System information
103 *
104 */
105
106 typedef struct
107 {
108 unsigned long int system;
109 unsigned long int user;
110 unsigned long int idle;
111 } DT_CpuStat;
112
113 /*
114 * Timing
115 */
116 #ifdef RDTSC_TIMERS
117 typedef unsigned long long int DT_Mdep_TimeStamp;
118
119 static _INLINE_ DT_Mdep_TimeStamp
120 DT_Mdep_GetTimeStamp ( void )
121 {
122 #if defined(__GNUC__) && defined(__i386__)
123 DT_Mdep_TimeStamp x;
124 __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
125 return x;
126 #else
127 #ifdef __ia64__
128 unsigned long ret;
129 __asm__ __volatile__ ("mov %0=ar.itc" : "=r"(ret));
130 return ret;
131 #else
132 #if defined(__PPC__) || defined(__PPC64__)
133 unsigned int tbl, tbu0, tbu1;
134 do {
135 __asm__ __volatile__ ("mftbu %0" : "=r"(tbu0));
136 __asm__ __volatile__ ("mftb %0" : "=r"(tbl));
137 __asm__ __volatile__ ("mftbu %0" : "=r"(tbu1));
138 } while (tbu0 != tbu1);
139 return (((unsigned long long)tbu0) << 32) | tbl;
140 #else
141 #if defined(__x86_64__)
142 unsigned int __a,__d;
143 asm volatile("rdtsc" : "=a" (__a), "=d" (__d));
144 return ((unsigned long)__a) | (((unsigned long)__d)<<32);
145 #else
146 #error "Linux CPU architecture - unimplemented"
147 #endif
148 #endif
149 #endif
150 #endif
151 }
152 #else /* !RDTSC_TIMERS */
153 /*
154 * Get timestamp, microseconds, (relative to some fixed point)
155 */
156 typedef double DT_Mdep_TimeStamp;
157
158 static _INLINE_ DT_Mdep_TimeStamp
159 DT_Mdep_GetTimeStamp ( void )
160 {
161 struct timeval tv;
162 gettimeofday(&tv, NULL);
163 return (tv.tv_sec * 1000000 + tv.tv_usec);
164 }
165 #endif
166
167
168 /*
169 * Define long format types to be used in *printf format strings. We
170 * use the C string constant concatenation ability to define 64 bit
171 * formats, which unfortunatly are non standard in the C compiler
172 * world. E.g. %llx for gcc, %I64x for Windows
173 */
174
175 #if defined(__x86_64__) || defined(__ia64__)
176 #define F64d "%ld"
177 #define F64u "%lu"
178 #define F64x "%lx"
179 #define F64X "%lX"
180 #else
181 #define F64d "%lld"
182 #define F64u "%llu"
183 #define F64x "%llx"
184 #define F64X "%llX"
185 #endif
186 /*
187 * Define notion of a LONG LONG 0
188 */
189 #define LZERO 0ULL
190
191 /* Mdep function defines */
192 #define DT_Mdep_Debug(N, _X_) \
193 do { \
194 if (DT_dapltest_debug >= (N)) \
195 { \
196 DT_Mdep_printf _X_; \
197 } \
198 } while (0)
199 #define DT_Mdep_printf printf
200
201 #define DT_Mdep_flush() fflush(NULL)
202
203 /*
204 * Release processor to reschedule
205 */
206 #define DT_Mdep_yield sched_yield
207
208 #endif