starpu_util.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2008-2018 Université de Bordeaux
  4. * Copyright (C) 2011,2012,2017 Inria
  5. * Copyright (C) 2010-2017, 2019 CNRS
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #ifndef __STARPU_UTIL_H__
  19. #define __STARPU_UTIL_H__
  20. /** @defgroup
  21. *
  22. * @{
  23. */
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <stdint.h>
  27. #include <string.h>
  28. #include <assert.h>
  29. #include <starpu_config.h>
  30. #ifdef __GLIBC__
  31. #include <execinfo.h>
  32. #endif
  33. #ifdef STARPU_SIMGRID_MC
  34. #include <simgrid/modelchecker.h>
  35. #endif
  36. #ifdef __cplusplus
  37. extern "C"
  38. {
  39. #endif
  40. #if defined __GNUC__ && defined __GNUC_MINOR__
  41. # define STARPU_GNUC_PREREQ(maj, min) \
  42. ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
  43. #else
  44. # define STARPU_GNUC_PREREQ(maj, min) 0
  45. #endif
  46. #ifdef __GNUC__
  47. # define STARPU_UNLIKELY(expr) (__builtin_expect(!!(expr),0))
  48. # define STARPU_LIKELY(expr) (__builtin_expect(!!(expr),1))
  49. # define STARPU_ATTRIBUTE_UNUSED __attribute__((unused))
  50. # define STARPU_ATTRIBUTE_NORETURN __attribute__((noreturn))
  51. # define STARPU_ATTRIBUTE_INTERNAL __attribute__ ((visibility ("internal")))
  52. # define STARPU_ATTRIBUTE_MALLOC __attribute__((malloc))
  53. # define STARPU_ATTRIBUTE_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  54. # define STARPU_ATTRIBUTE_PURE __attribute__((pure))
  55. # define STARPU_ATTRIBUTE_ALIGNED(size) __attribute__((aligned(size)))
  56. # define STARPU_ATTRIBUTE_FORMAT(type, string, first) __attribute__((format(type, string, first)))
  57. #else
  58. # define STARPU_UNLIKELY(expr) (expr)
  59. # define STARPU_LIKELY(expr) (expr)
  60. # define STARPU_ATTRIBUTE_UNUSED
  61. # define STARPU_ATTRIBUTE_NORETURN
  62. # define STARPU_ATTRIBUTE_INTERNAL
  63. # define STARPU_ATTRIBUTE_MALLOC
  64. # define STARPU_ATTRIBUTE_WARN_UNUSED_RESULT
  65. # define STARPU_ATTRIBUTE_PURE
  66. # define STARPU_ATTRIBUTE_ALIGNED(size)
  67. # define STARPU_ATTRIBUTE_FORMAT(type, string, first)
  68. #endif
  69. /* Note that if we're compiling C++, then just use the "inline"
  70. keyword, since it's part of C++ */
  71. #if defined(c_plusplus) || defined(__cplusplus)
  72. # define STARPU_INLINE inline
  73. #elif defined(_MSC_VER) || defined(__HP_cc)
  74. # define STARPU_INLINE __inline
  75. #else
  76. # define STARPU_INLINE __inline__
  77. #endif
  78. #if STARPU_GNUC_PREREQ(4, 3)
  79. # define STARPU_ATTRIBUTE_CALLOC_SIZE(num,size) __attribute__((alloc_size(num,size)))
  80. # define STARPU_ATTRIBUTE_ALLOC_SIZE(size) __attribute__((alloc_size(size)))
  81. #else
  82. # define STARPU_ATTRIBUTE_CALLOC_SIZE(num,size)
  83. # define STARPU_ATTRIBUTE_ALLOC_SIZE(size)
  84. #endif
  85. #if STARPU_GNUC_PREREQ(3, 1) && !defined(BUILDING_STARPU) && !defined(STARPU_USE_DEPRECATED_API) && !defined(STARPU_USE_DEPRECATED_ONE_ZERO_API)
  86. #define STARPU_DEPRECATED __attribute__((__deprecated__))
  87. #else
  88. #define STARPU_DEPRECATED
  89. #endif /* __GNUC__ */
  90. #if STARPU_GNUC_PREREQ(3,3)
  91. #define STARPU_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
  92. #else
  93. #define STARPU_WARN_UNUSED_RESULT
  94. #endif /* __GNUC__ */
  95. #define STARPU_POISON_PTR ((void *)0xdeadbeef)
  96. #define STARPU_MIN(a,b) ((a)<(b)?(a):(b))
  97. #define STARPU_MAX(a,b) ((a)<(b)?(b):(a))
  98. #define STARPU_BACKTRACE_LENGTH 32
  99. #ifdef __GLIBC__
  100. # define STARPU_DUMP_BACKTRACE() do { \
  101. void *__ptrs[STARPU_BACKTRACE_LENGTH]; \
  102. int __n = backtrace(__ptrs, STARPU_BACKTRACE_LENGTH); \
  103. backtrace_symbols_fd(__ptrs, __n, 2); \
  104. } while (0)
  105. #else
  106. # define STARPU_DUMP_BACKTRACE() do { } while (0)
  107. #endif
  108. #ifdef STARPU_SIMGRID_MC
  109. #define STARPU_SIMGRID_ASSERT(x) MC_assert(!!(x))
  110. #else
  111. #define STARPU_SIMGRID_ASSERT(x)
  112. #endif
  113. #ifdef STARPU_NO_ASSERT
  114. #define STARPU_ASSERT(x) do { if (0) { (void) (x); } } while(0)
  115. #define STARPU_ASSERT_ACCESSIBLE(x) do { if (0) { (void) (x); } } while(0)
  116. #define STARPU_ASSERT_MSG(x, msg, ...) do { if (0) { (void) (x); (void) msg; } } while(0)
  117. #else
  118. # if defined(__CUDACC__) || defined(STARPU_HAVE_WINDOWS)
  119. # define STARPU_ASSERT(x) do { if (STARPU_UNLIKELY(!(x))) { STARPU_DUMP_BACKTRACE(); STARPU_SIMGRID_ASSERT(x); *(int*)NULL = 0; } } while(0)
  120. # define STARPU_ASSERT_MSG(x, msg, ...) do { if (STARPU_UNLIKELY(!(x))) { STARPU_DUMP_BACKTRACE(); fprintf(stderr, "\n[starpu][%s][assert failure] " msg "\n\n", __starpu_func__, ## __VA_ARGS__); STARPU_SIMGRID_ASSERT(x); *(int*)NULL = 0; }} while(0)
  121. # else
  122. # define STARPU_ASSERT(x) do { if (STARPU_UNLIKELY(!(x))) { STARPU_DUMP_BACKTRACE(); STARPU_SIMGRID_ASSERT(x); assert(x); } } while (0)
  123. # define STARPU_ASSERT_MSG(x, msg, ...) do { if (STARPU_UNLIKELY(!(x))) { STARPU_DUMP_BACKTRACE(); fprintf(stderr, "\n[starpu][%s][assert failure] " msg "\n\n", __starpu_func__, ## __VA_ARGS__); STARPU_SIMGRID_ASSERT(x); assert(x); } } while(0)
  124. # endif
  125. # define STARPU_ASSERT_ACCESSIBLE(ptr) do { \
  126. volatile char __c STARPU_ATTRIBUTE_UNUSED = *(char*) (ptr); \
  127. } while(0)
  128. #endif
  129. #ifdef __APPLE_CC__
  130. # ifdef __clang_analyzer__
  131. # define _starpu_abort() exit(42)
  132. # else
  133. # define _starpu_abort() *(volatile int*)NULL = 0
  134. # endif
  135. #else
  136. # define _starpu_abort() abort()
  137. #endif
  138. #define STARPU_ABORT() do { \
  139. STARPU_DUMP_BACKTRACE(); \
  140. fprintf(stderr, "[starpu][abort][%s()@%s:%d]\n", __starpu_func__, __FILE__, __LINE__); \
  141. _starpu_abort(); \
  142. } while(0)
  143. #define STARPU_ABORT_MSG(msg, ...) do { \
  144. STARPU_DUMP_BACKTRACE(); \
  145. fprintf(stderr, "[starpu][abort][%s()@%s:%d] " msg "\n", __starpu_func__, __FILE__, __LINE__, ## __VA_ARGS__); \
  146. _starpu_abort(); \
  147. } while(0)
  148. #if defined(STARPU_HAVE_STRERROR_R)
  149. #if (! defined(__GLIBC__) || !__GLIBC__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && (! defined(_GNU_SOURCE)))
  150. /* XSI-compliant version of strerror_r returns an int */
  151. #define starpu_strerror_r(errnum, buf, buflen) \
  152. do \
  153. { \
  154. int _ret = strerror_r((errnum), (buf), (buflen)); \
  155. STARPU_ASSERT(_ret == 0); \
  156. } \
  157. while (0)
  158. #else
  159. /* GNU-specific version of strerror_r returns a char * */
  160. #define starpu_strerror_r(errnum, buf, buflen) \
  161. do \
  162. { \
  163. char * const _user_buf = (buf); \
  164. const size_t _user_buflen = (buflen); \
  165. /* the GNU-specific behaviour when 'buf' == NULL cannot be emulated with the XSI-compliant version */ \
  166. STARPU_ASSERT((buf) != NULL); \
  167. char * _tmp_buf = strerror_r((errnum), _user_buf, _user_buflen); \
  168. if (_tmp_buf != _user_buf) \
  169. { \
  170. if (_user_buflen > 0) \
  171. { \
  172. strncpy(_user_buf, _tmp_buf, _user_buflen); \
  173. _user_buf[_user_buflen-1] = '\0'; \
  174. } \
  175. } \
  176. } \
  177. while (0)
  178. #endif /* strerror_r ABI version */
  179. # define STARPU_CHECK_RETURN_VALUE(err, message, ...) {if (STARPU_UNLIKELY(err != 0)) { \
  180. char xmessage[256]; starpu_strerror_r(-err, xmessage, 256); \
  181. fprintf(stderr, "[starpu] Unexpected value: <%d:%s> returned for " message "\n", err, xmessage, ## __VA_ARGS__); \
  182. STARPU_ABORT(); }}
  183. # define STARPU_CHECK_RETURN_VALUE_IS(err, value, message, ...) {if (STARPU_UNLIKELY(err != value)) { \
  184. char xmessage[256]; starpu_strerror_r(-err, xmessage, 256); \
  185. fprintf(stderr, "[starpu] Unexpected value: <%d!=%d:%s> returned for " message "\n", err, value, xmessage, ## __VA_ARGS__); \
  186. STARPU_ABORT(); }}
  187. #else
  188. # define STARPU_CHECK_RETURN_VALUE(err, message, ...) {if (STARPU_UNLIKELY(err != 0)) { \
  189. fprintf(stderr, "[starpu] Unexpected value: <%d> returned for " message "\n", err, ## __VA_ARGS__); \
  190. STARPU_ABORT(); }}
  191. # define STARPU_CHECK_RETURN_VALUE_IS(err, value, message, ...) {if (STARPU_UNLIKELY(err != value)) { \
  192. fprintf(stderr, "[starpu] Unexpected value: <%d != %d> returned for " message "\n", err, value, ## __VA_ARGS__); \
  193. STARPU_ABORT(); }}
  194. #endif /* STARPU_HAVE_STRERROR_R */
  195. #if defined(__i386__) || defined(__x86_64__)
  196. static __starpu_inline unsigned starpu_cmpxchg(unsigned *ptr, unsigned old, unsigned next)
  197. {
  198. __asm__ __volatile__("lock cmpxchgl %2,%1": "+a" (old), "+m" (*ptr) : "q" (next) : "memory");
  199. return old;
  200. }
  201. static __starpu_inline unsigned starpu_xchg(unsigned *ptr, unsigned next)
  202. {
  203. /* Note: xchg is always locked already */
  204. __asm__ __volatile__("xchgl %1,%0": "+m" (*ptr), "+q" (next) : : "memory");
  205. return next;
  206. }
  207. #define STARPU_HAVE_XCHG
  208. #if defined(__i386__)
  209. static __starpu_inline unsigned long starpu_cmpxchgl(unsigned long *ptr, unsigned long old, unsigned long next)
  210. {
  211. __asm__ __volatile__("lock cmpxchgl %2,%1": "+a" (old), "+m" (*ptr) : "q" (next) : "memory");
  212. return old;
  213. }
  214. static __starpu_inline unsigned long starpu_xchgl(unsigned long *ptr, unsigned long next)
  215. {
  216. /* Note: xchg is always locked already */
  217. __asm__ __volatile__("xchgl %1,%0": "+m" (*ptr), "+q" (next) : : "memory");
  218. return next;
  219. }
  220. #define STARPU_HAVE_XCHGL
  221. #endif
  222. #if defined(__x86_64__)
  223. static __starpu_inline unsigned long starpu_cmpxchgl(unsigned long *ptr, unsigned long old, unsigned long next)
  224. {
  225. __asm__ __volatile__("lock cmpxchgq %2,%1": "+a" (old), "+m" (*ptr) : "q" (next) : "memory");
  226. return old;
  227. }
  228. static __starpu_inline unsigned long starpu_xchgl(unsigned long *ptr, unsigned long next)
  229. {
  230. /* Note: xchg is always locked already */
  231. __asm__ __volatile__("xchgq %1,%0": "+m" (*ptr), "+q" (next) : : "memory");
  232. return next;
  233. }
  234. #define STARPU_HAVE_XCHGL
  235. #endif
  236. #endif
  237. #define STARPU_ATOMIC_SOMETHING(name,expr) \
  238. static __starpu_inline unsigned starpu_atomic_##name(unsigned *ptr, unsigned value) \
  239. { \
  240. unsigned old, next; \
  241. while (1) \
  242. { \
  243. old = *ptr; \
  244. next = expr; \
  245. if (starpu_cmpxchg(ptr, old, next) == old) \
  246. break; \
  247. }; \
  248. return expr; \
  249. }
  250. #define STARPU_ATOMIC_SOMETHINGL(name,expr) \
  251. static __starpu_inline unsigned long starpu_atomic_##name##l(unsigned long *ptr, unsigned long value) \
  252. { \
  253. unsigned long old, next; \
  254. while (1) \
  255. { \
  256. old = *ptr; \
  257. next = expr; \
  258. if (starpu_cmpxchgl(ptr, old, next) == old) \
  259. break; \
  260. }; \
  261. return expr; \
  262. }
  263. /* Returns the new value */
  264. #ifdef STARPU_HAVE_SYNC_FETCH_AND_ADD
  265. #define STARPU_ATOMIC_ADD(ptr, value) (__sync_fetch_and_add ((ptr), (value)) + (value))
  266. #define STARPU_ATOMIC_ADDL(ptr, value) (__sync_fetch_and_add ((ptr), (value)) + (value))
  267. #else
  268. #if defined(STARPU_HAVE_XCHG)
  269. STARPU_ATOMIC_SOMETHING(add, old + value)
  270. #define STARPU_ATOMIC_ADD(ptr, value) starpu_atomic_add(ptr, value)
  271. #endif
  272. #if defined(STARPU_HAVE_XCHGL)
  273. STARPU_ATOMIC_SOMETHINGL(add, old + value)
  274. #define STARPU_ATOMIC_ADDL(ptr, value) starpu_atomic_addl(ptr, value)
  275. #endif
  276. #endif
  277. #ifdef STARPU_HAVE_SYNC_FETCH_AND_OR
  278. #define STARPU_ATOMIC_OR(ptr, value) (__sync_fetch_and_or ((ptr), (value)))
  279. #define STARPU_ATOMIC_ORL(ptr, value) (__sync_fetch_and_or ((ptr), (value)))
  280. #else
  281. #if defined(STARPU_HAVE_XCHG)
  282. STARPU_ATOMIC_SOMETHING(or, old | value)
  283. #define STARPU_ATOMIC_OR(ptr, value) starpu_atomic_or(ptr, value)
  284. #endif
  285. #if defined(STARPU_HAVE_XCHGL)
  286. STARPU_ATOMIC_SOMETHINGL(or, old | value)
  287. #define STARPU_ATOMIC_ORL(ptr, value) starpu_atomic_orl(ptr, value)
  288. #endif
  289. #endif
  290. #ifdef STARPU_HAVE_SYNC_BOOL_COMPARE_AND_SWAP
  291. #define STARPU_BOOL_COMPARE_AND_SWAP(ptr, old, value) (__sync_bool_compare_and_swap ((ptr), (old), (value)))
  292. #elif defined(STARPU_HAVE_XCHG)
  293. #define STARPU_BOOL_COMPARE_AND_SWAP(ptr, old, value) (starpu_cmpxchg((ptr), (old), (value)) == (old))
  294. #endif
  295. #ifdef STARPU_HAVE_SYNC_VAL_COMPARE_AND_SWAP
  296. #define STARPU_VAL_COMPARE_AND_SWAP(ptr, old, value) (__sync_val_compare_and_swap ((ptr), (old), (value)))
  297. #elif defined(STARPU_HAVE_XCHG)
  298. #define STARPU_VAL_COMPARE_AND_SWAP(ptr, old, value) (starpu_cmpxchg((ptr), (old), (value)))
  299. #endif
  300. /* Returns the previous value */
  301. #ifdef STARPU_HAVE_SYNC_LOCK_TEST_AND_SET
  302. #define STARPU_TEST_AND_SET(ptr, value) (__sync_lock_test_and_set ((ptr), (value)))
  303. #define STARPU_RELEASE(ptr) (__sync_lock_release ((ptr)))
  304. #elif defined(STARPU_HAVE_XCHG)
  305. #define STARPU_TEST_AND_SET(ptr, value) (starpu_xchg((ptr), (value)))
  306. #define STARPU_RELEASE(ptr) (starpu_xchg((ptr), 0))
  307. #endif
  308. #ifdef STARPU_HAVE_SYNC_SYNCHRONIZE
  309. #define STARPU_SYNCHRONIZE() __sync_synchronize()
  310. #elif defined(__i386__)
  311. #define STARPU_SYNCHRONIZE() __asm__ __volatile__("lock; addl $0,0(%%esp)" ::: "memory")
  312. #elif defined(__KNC__) || defined(__KNF__)
  313. #define STARPU_SYNCHRONIZE() __asm__ __volatile__("lock; addl $0,0(%%rsp)" ::: "memory")
  314. #elif defined(__x86_64__)
  315. #define STARPU_SYNCHRONIZE() __asm__ __volatile__("mfence" ::: "memory")
  316. #elif defined(__ppc__) || defined(__ppc64__)
  317. #define STARPU_SYNCHRONIZE() __asm__ __volatile__("sync" ::: "memory")
  318. #endif
  319. #if defined(__i386__)
  320. #define STARPU_RMB() __asm__ __volatile__("lock; addl $0,0(%%esp)" ::: "memory")
  321. #define STARPU_WMB() __asm__ __volatile__("lock; addl $0,0(%%esp)" ::: "memory")
  322. #elif defined(__KNC__) || defined(__KNF__)
  323. #define STARPU_RMB() __asm__ __volatile__("lock; addl $0,0(%%rsp)" ::: "memory")
  324. #define STARPU_WMB() __asm__ __volatile__("lock; addl $0,0(%%rsp)" ::: "memory")
  325. #elif defined(__x86_64__)
  326. #define STARPU_RMB() __asm__ __volatile__("lfence" ::: "memory")
  327. #define STARPU_WMB() __asm__ __volatile__("sfence" ::: "memory")
  328. #elif defined(__ppc__) || defined(__ppc64__)
  329. #define STARPU_RMB() __asm__ __volatile__("sync" ::: "memory")
  330. #define STARPU_WMB() __asm__ __volatile__("sync" ::: "memory")
  331. #else
  332. #define STARPU_RMB() STARPU_SYNCHRONIZE()
  333. #define STARPU_WMB() STARPU_SYNCHRONIZE()
  334. #endif
  335. #ifdef __cplusplus
  336. }
  337. #endif
  338. #ifdef __cplusplus
  339. extern "C"
  340. {
  341. #endif
  342. extern int _starpu_silent;
  343. char *starpu_getenv(const char *str);
  344. static __starpu_inline int starpu_get_env_number(const char *str)
  345. {
  346. char *strval;
  347. strval = starpu_getenv(str);
  348. if (strval)
  349. {
  350. /* the env variable was actually set */
  351. long int val;
  352. char *pcheck;
  353. val = strtol(strval, &pcheck, 10);
  354. if (*pcheck) {
  355. fprintf(stderr,"The %s environment variable must contain an integer\n", str);
  356. STARPU_ABORT();
  357. }
  358. /* fprintf(stderr, "ENV %s WAS %d\n", str, val); */
  359. STARPU_ASSERT_MSG(val >= 0, "The value for the environment variable '%s' cannot be negative", str);
  360. return (int)val;
  361. }
  362. else
  363. {
  364. /* there is no such env variable */
  365. /* fprintf("There was no %s ENV\n", str); */
  366. return -1;
  367. }
  368. }
  369. static __starpu_inline int starpu_get_env_number_default(const char *str, int defval)
  370. {
  371. int ret = starpu_get_env_number(str);
  372. if (ret == -1)
  373. ret = defval;
  374. return ret;
  375. }
  376. static __starpu_inline float starpu_get_env_float_default(const char *str, float defval)
  377. {
  378. char *strval;
  379. strval = starpu_getenv(str);
  380. if (strval)
  381. {
  382. /* the env variable was actually set */
  383. float val;
  384. char *pcheck;
  385. val = strtof(strval, &pcheck);
  386. if (*pcheck) {
  387. fprintf(stderr,"The %s environment variable must contain a float\n", str);
  388. STARPU_ABORT();
  389. }
  390. /* fprintf(stderr, "ENV %s WAS %f\n", str, val); */
  391. return val;
  392. }
  393. else
  394. {
  395. /* there is no such env variable */
  396. /* fprintf("There was no %s ENV\n", str); */
  397. return defval;
  398. }
  399. }
  400. void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t where);
  401. void starpu_execute_on_each_worker_ex(void (*func)(void *), void *arg, uint32_t where, const char *name);
  402. void starpu_execute_on_specific_workers(void (*func)(void*), void *arg, unsigned num_workers, unsigned *workers, const char *name);
  403. double starpu_timing_now(void);
  404. #ifdef _WIN32
  405. /* Try to fetch the system definition of timespec */
  406. #include <sys/types.h>
  407. #include <sys/stat.h>
  408. #ifdef HAVE_UNISTD_H
  409. #include <unistd.h>
  410. #endif
  411. #include <time.h>
  412. #if !defined(_MSC_VER) || defined(BUILDING_STARPU)
  413. #include <pthread.h>
  414. #endif
  415. #if !defined(STARPU_HAVE_STRUCT_TIMESPEC) || (defined(_MSC_VER) && _MSC_VER < 1900)
  416. /* If it didn't get defined in the standard places, then define it ourself */
  417. #ifndef STARPU_TIMESPEC_DEFINED
  418. #define STARPU_TIMESPEC_DEFINED 1
  419. struct timespec
  420. {
  421. time_t tv_sec; /* Seconds */
  422. long tv_nsec; /* Nanoseconds */
  423. };
  424. #endif /* STARPU_TIMESPEC_DEFINED */
  425. #endif /* STARPU_HAVE_STRUCT_TIMESPEC */
  426. /* Fetch gettimeofday on mingw/cygwin */
  427. #if defined(__MINGW32__) || defined(__CYGWIN__)
  428. #include <sys/time.h>
  429. #endif
  430. #else
  431. #include <sys/time.h>
  432. #endif /* _WIN32 */
  433. #ifdef __cplusplus
  434. }
  435. #endif
  436. /** @} */
  437. #endif /* __STARPU_UTIL_H__ */