fxt.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2011 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #ifndef __FXT_H__
  18. #define __FXT_H__
  19. #ifndef _GNU_SOURCE
  20. #define _GNU_SOURCE /* ou _BSD_SOURCE ou _SVID_SOURCE */
  21. #endif
  22. #include <unistd.h>
  23. #include <string.h>
  24. #include <sys/types.h>
  25. #include <stdlib.h>
  26. #include <common/config.h>
  27. #include <starpu.h>
  28. /* some key to identify the worker kind */
  29. #define STARPU_FUT_APPS_KEY 0x100
  30. #define STARPU_FUT_CPU_KEY 0x101
  31. #define STARPU_FUT_CUDA_KEY 0x102
  32. #define STARPU_FUT_OPENCL_KEY 0x103
  33. #define STARPU_FUT_WORKER_INIT_START 0x5100
  34. #define STARPU_FUT_WORKER_INIT_END 0x5101
  35. #define STARPU_FUT_START_CODELET_BODY 0x5102
  36. #define STARPU_FUT_END_CODELET_BODY 0x5103
  37. #define STARPU_FUT_JOB_PUSH 0x5104
  38. #define STARPU_FUT_JOB_POP 0x5105
  39. #define STARPU_FUT_UPDATE_TASK_CNT 0x5106
  40. #define STARPU_FUT_START_FETCH_INPUT 0x5107
  41. #define STARPU_FUT_END_FETCH_INPUT 0x5108
  42. #define STARPU_FUT_START_PUSH_OUTPUT 0x5109
  43. #define STARPU_FUT_END_PUSH_OUTPUT 0x5110
  44. #define STARPU_FUT_TAG 0x5111
  45. #define STARPU_FUT_TAG_DEPS 0x5112
  46. #define STARPU_FUT_TASK_DEPS 0x5113
  47. #define STARPU_FUT_DATA_COPY 0x5114
  48. #define STARPU_FUT_WORK_STEALING 0x5115
  49. #define STARPU_FUT_WORKER_DEINIT_START 0x5116
  50. #define STARPU_FUT_WORKER_DEINIT_END 0x5117
  51. #define STARPU_FUT_WORKER_SLEEP_START 0x5118
  52. #define STARPU_FUT_WORKER_SLEEP_END 0x5119
  53. #define STARPU_FUT_USER_DEFINED_START 0x5120
  54. #define STARPU_FUT_USER_DEFINED_END 0x5121
  55. #define STARPU_FUT_NEW_MEM_NODE 0x5122
  56. #define STARPU_FUT_START_CALLBACK 0x5123
  57. #define STARPU_FUT_END_CALLBACK 0x5124
  58. #define STARPU_FUT_TASK_DONE 0x5125
  59. #define STARPU_FUT_TAG_DONE 0x5126
  60. #define STARPU_FUT_START_ALLOC 0x5127
  61. #define STARPU_FUT_END_ALLOC 0x5128
  62. #define STARPU_FUT_START_ALLOC_REUSE 0x5129
  63. #define STARPU_FUT_END_ALLOC_REUSE 0x5130
  64. #define STARPU_FUT_START_MEMRECLAIM 0x5131
  65. #define STARPU_FUT_END_MEMRECLAIM 0x5132
  66. #define STARPU_FUT_START_DRIVER_COPY 0x5133
  67. #define STARPU_FUT_END_DRIVER_COPY 0x5134
  68. #define STARPU_FUT_START_DRIVER_COPY_ASYNC 0x5135
  69. #define STARPU_FUT_END_DRIVER_COPY_ASYNC 0x5136
  70. #define STARPU_FUT_START_PROGRESS 0x5137
  71. #define STARPU_FUT_END_PROGRESS 0x5138
  72. #define STARPU_FUT_USER_EVENT 0x5139
  73. #define STARPU_FUT_SET_PROFILING 0x513a
  74. #define STARPU_FUT_TASK_WAIT_FOR_ALL 0x513b
  75. #ifdef STARPU_USE_FXT
  76. #include <sys/syscall.h> /* pour les définitions de SYS_xxx */
  77. #include <fxt/fxt.h>
  78. #include <fxt/fut.h>
  79. /* Initialize the FxT library. */
  80. void _starpu_start_fxt_profiling(void);
  81. /* Stop the FxT library, and generate the trace file. */
  82. void _starpu_stop_fxt_profiling(void);
  83. /* Associate the current processing unit to the identifier of the LWP that runs
  84. * the worker. */
  85. void _starpu_fxt_register_thread(unsigned);
  86. /* Sometimes we need something a little more specific than the wrappers from
  87. * FxT: these macro permit to put add an event with 3 (or 4) numbers followed
  88. * by a string. */
  89. #define STARPU_FUT_DO_PROBE3STR(CODE, P1, P2, P3, str) \
  90. do { \
  91. /* No more than FXT_MAX_PARAMS args are allowed */ \
  92. /* we add a \0 just in case ... */ \
  93. size_t len = STARPU_MIN(strlen(str)+1, (FXT_MAX_PARAMS - 3)*sizeof(unsigned long));\
  94. unsigned nbargs_str = (len + sizeof(unsigned long) - 1)/(sizeof(unsigned long));\
  95. unsigned nbargs = 3 + nbargs_str; \
  96. size_t total_len = FUT_SIZE(nbargs); \
  97. unsigned long *futargs = \
  98. fut_getstampedbuffer(FUT_CODE(CODE, nbargs), total_len);\
  99. *(futargs++) = (unsigned long)(P1); \
  100. *(futargs++) = (unsigned long)(P2); \
  101. *(futargs++) = (unsigned long)(P3); \
  102. snprintf((char *)futargs, len, "%s", str); \
  103. ((char *)futargs)[len - 1] = '\0'; \
  104. } while (0);
  105. #define STARPU_FUT_DO_PROBE4STR(CODE, P1, P2, P3, P4, str) \
  106. do { \
  107. /* No more than FXT_MAX_PARAMS args are allowed */ \
  108. /* we add a \0 just in case ... */ \
  109. size_t len = STARPU_MIN(strlen(str)+1, (FXT_MAX_PARAMS - 4)*sizeof(unsigned long));\
  110. unsigned nbargs_str = (len + sizeof(unsigned long) - 1)/(sizeof(unsigned long));\
  111. unsigned nbargs = 4 + nbargs_str; \
  112. size_t total_len = FUT_SIZE(nbargs); \
  113. unsigned long *futargs = \
  114. fut_getstampedbuffer(FUT_CODE(CODE, nbargs), total_len);\
  115. *(futargs++) = (unsigned long)(P1); \
  116. *(futargs++) = (unsigned long)(P2); \
  117. *(futargs++) = (unsigned long)(P3); \
  118. *(futargs++) = (unsigned long)(P4); \
  119. snprintf((char *)futargs, len, "%s", str); \
  120. ((char *)futargs)[len - 1] = '\0'; \
  121. } while (0);
  122. #define STARPU_FUT_DO_PROBE5STR(CODE, P1, P2, P3, P4, P5, str) \
  123. do { \
  124. /* No more than FXT_MAX_PARAMS args are allowed */ \
  125. /* we add a \0 just in case ... */ \
  126. size_t len = STARPU_MIN(strlen(str)+1, (FXT_MAX_PARAMS - 5)*sizeof(unsigned long));\
  127. unsigned nbargs_str = (len + sizeof(unsigned long) - 1)/(sizeof(unsigned long));\
  128. unsigned nbargs = 5 + nbargs_str; \
  129. size_t total_len = FUT_SIZE(nbargs); \
  130. unsigned long *futargs = \
  131. fut_getstampedbuffer(FUT_CODE(CODE, nbargs), total_len);\
  132. *(futargs++) = (unsigned long)(P1); \
  133. *(futargs++) = (unsigned long)(P2); \
  134. *(futargs++) = (unsigned long)(P3); \
  135. *(futargs++) = (unsigned long)(P4); \
  136. *(futargs++) = (unsigned long)(P5); \
  137. snprintf((char *)futargs, len, "%s", str); \
  138. ((char *)futargs)[len - 1] = '\0'; \
  139. } while (0);
  140. /* workerkind = STARPU_FUT_CPU_KEY for instance */
  141. #define STARPU_TRACE_NEW_MEM_NODE(nodeid) \
  142. FUT_DO_PROBE2(STARPU_FUT_NEW_MEM_NODE, nodeid, syscall(SYS_gettid));
  143. #define STARPU_TRACE_WORKER_INIT_START(workerkind, devid, memnode) \
  144. FUT_DO_PROBE4(STARPU_FUT_WORKER_INIT_START, workerkind, devid, memnode, syscall(SYS_gettid));
  145. #define STARPU_TRACE_WORKER_INIT_END \
  146. FUT_DO_PROBE1(STARPU_FUT_WORKER_INIT_END, syscall(SYS_gettid));
  147. #define STARPU_TRACE_START_CODELET_BODY(job) \
  148. do { \
  149. const char *model_name = _starpu_get_model_name((job)); \
  150. if (model_name) \
  151. { \
  152. /* we include the symbol name */ \
  153. STARPU_FUT_DO_PROBE3STR(STARPU_FUT_START_CODELET_BODY, (job), syscall(SYS_gettid), 1, model_name); \
  154. } \
  155. else { \
  156. FUT_DO_PROBE3(STARPU_FUT_START_CODELET_BODY, (job), syscall(SYS_gettid), 0); \
  157. } \
  158. } while(0);
  159. #define STARPU_TRACE_END_CODELET_BODY(job, archtype) \
  160. do { \
  161. const size_t job_size = _starpu_job_get_data_size((job)); \
  162. const uint32_t job_hash = _starpu_compute_buffers_footprint(job);\
  163. FUT_DO_PROBE5(STARPU_FUT_END_CODELET_BODY, job, (job_size), (job_hash), (archtype), syscall(SYS_gettid)); \
  164. } while(0);
  165. #define STARPU_TRACE_START_CALLBACK(job) \
  166. FUT_DO_PROBE2(STARPU_FUT_START_CALLBACK, job, syscall(SYS_gettid));
  167. #define STARPU_TRACE_END_CALLBACK(job) \
  168. FUT_DO_PROBE2(STARPU_FUT_END_CALLBACK, job, syscall(SYS_gettid));
  169. #define STARPU_TRACE_JOB_PUSH(task, prio) \
  170. FUT_DO_PROBE3(STARPU_FUT_JOB_PUSH, task, prio, syscall(SYS_gettid));
  171. #define STARPU_TRACE_JOB_POP(task, prio) \
  172. FUT_DO_PROBE3(STARPU_FUT_JOB_POP, task, prio, syscall(SYS_gettid));
  173. #define STARPU_TRACE_UPDATE_TASK_CNT(counter) \
  174. FUT_DO_PROBE2(STARPU_FUT_UPDATE_TASK_CNT, counter, syscall(SYS_gettid))
  175. #define STARPU_TRACE_START_FETCH_INPUT(job) \
  176. FUT_DO_PROBE2(STARPU_FUT_START_FETCH_INPUT, job, syscall(SYS_gettid));
  177. #define STARPU_TRACE_END_FETCH_INPUT(job) \
  178. FUT_DO_PROBE2(STARPU_FUT_END_FETCH_INPUT, job, syscall(SYS_gettid));
  179. #define STARPU_TRACE_START_PUSH_OUTPUT(job) \
  180. FUT_DO_PROBE2(STARPU_FUT_START_PUSH_OUTPUT, job, syscall(SYS_gettid));
  181. #define STARPU_TRACE_END_PUSH_OUTPUT(job) \
  182. FUT_DO_PROBE2(STARPU_FUT_END_PUSH_OUTPUT, job, syscall(SYS_gettid));
  183. #define STARPU_TRACE_TAG(tag, job) \
  184. FUT_DO_PROBE2(STARPU_FUT_TAG, tag, (job)->job_id)
  185. #define STARPU_TRACE_TAG_DEPS(tag_child, tag_father) \
  186. FUT_DO_PROBE2(STARPU_FUT_TAG_DEPS, tag_child, tag_father)
  187. #define STARPU_TRACE_TASK_DEPS(job_prev, job_succ) \
  188. FUT_DO_PROBE2(STARPU_FUT_TASK_DEPS, (job_prev)->job_id, (job_succ)->job_id)
  189. #define STARPU_TRACE_GHOST_TASK_DEPS(ghost_prev_id, job_succ_id) \
  190. FUT_DO_PROBE2(STARPU_FUT_TASK_DEPS, (ghost_prev_id), (job_succ_id))
  191. #define STARPU_TRACE_TASK_DONE(job) \
  192. do { \
  193. unsigned exclude_from_dag = (job)->exclude_from_dag; \
  194. const char *model_name = _starpu_get_model_name((job)); \
  195. if (model_name) \
  196. { \
  197. STARPU_FUT_DO_PROBE4STR(STARPU_FUT_TASK_DONE, (job)->job_id, syscall(SYS_gettid), (long unsigned)exclude_from_dag, 1, model_name);\
  198. } \
  199. else { \
  200. FUT_DO_PROBE4(STARPU_FUT_TASK_DONE, (job)->job_id, syscall(SYS_gettid), (long unsigned)exclude_from_dag, 0);\
  201. } \
  202. } while(0);
  203. #define STARPU_TRACE_TAG_DONE(tag) \
  204. do { \
  205. struct starpu_job_s *job = (tag)->job; \
  206. const char *model_name = _starpu_get_model_name((job)); \
  207. if (model_name) \
  208. { \
  209. STARPU_FUT_DO_PROBE3STR(STARPU_FUT_TAG_DONE, (tag)->id, syscall(SYS_gettid), 1, model_name); \
  210. } \
  211. else { \
  212. FUT_DO_PROBE3(STARPU_FUT_TAG_DONE, (tag)->id, syscall(SYS_gettid), 0);\
  213. } \
  214. } while(0);
  215. #define STARPU_TRACE_DATA_COPY(src_node, dst_node, size) \
  216. FUT_DO_PROBE3(STARPU_FUT_DATA_COPY, src_node, dst_node, size)
  217. #define STARPU_TRACE_START_DRIVER_COPY(src_node, dst_node, size, com_id) \
  218. FUT_DO_PROBE4(STARPU_FUT_START_DRIVER_COPY, src_node, dst_node, size, com_id)
  219. #define STARPU_TRACE_END_DRIVER_COPY(src_node, dst_node, size, com_id) \
  220. FUT_DO_PROBE4(STARPU_FUT_END_DRIVER_COPY, src_node, dst_node, size, com_id)
  221. #define STARPU_TRACE_START_DRIVER_COPY_ASYNC(src_node, dst_node) \
  222. FUT_DO_PROBE2(STARPU_FUT_START_DRIVER_COPY_ASYNC, src_node, dst_node)
  223. #define STARPU_TRACE_END_DRIVER_COPY_ASYNC(src_node, dst_node) \
  224. FUT_DO_PROBE2(STARPU_FUT_END_DRIVER_COPY, src_node, dst_node)
  225. #define STARPU_TRACE_WORK_STEALING(empty_q, victim_q) \
  226. FUT_DO_PROBE2(STARPU_FUT_WORK_STEALING, empty_q, victim_q)
  227. #define STARPU_TRACE_WORKER_DEINIT_START \
  228. FUT_DO_PROBE1(STARPU_FUT_WORKER_DEINIT_START, syscall(SYS_gettid));
  229. #define STARPU_TRACE_WORKER_DEINIT_END(workerkind) \
  230. FUT_DO_PROBE2(STARPU_FUT_WORKER_DEINIT_END, workerkind, syscall(SYS_gettid));
  231. #define STARPU_TRACE_WORKER_SLEEP_START \
  232. FUT_DO_PROBE1(STARPU_FUT_WORKER_SLEEP_START, syscall(SYS_gettid));
  233. #define STARPU_TRACE_WORKER_SLEEP_END \
  234. FUT_DO_PROBE1(STARPU_FUT_WORKER_SLEEP_END, syscall(SYS_gettid));
  235. #define STARPU_TRACE_USER_DEFINED_START \
  236. FUT_DO_PROBE1(STARPU_FUT_USER_DEFINED_START, syscall(SYS_gettid));
  237. #define STARPU_TRACE_USER_DEFINED_END \
  238. FUT_DO_PROBE1(STARPU_FUT_USER_DEFINED_END, syscall(SYS_gettid));
  239. #define STARPU_TRACE_START_ALLOC(memnode) \
  240. FUT_DO_PROBE2(STARPU_FUT_START_ALLOC, memnode, syscall(SYS_gettid));
  241. #define STARPU_TRACE_END_ALLOC(memnode) \
  242. FUT_DO_PROBE2(STARPU_FUT_END_ALLOC, memnode, syscall(SYS_gettid));
  243. #define STARPU_TRACE_START_ALLOC_REUSE(memnode) \
  244. FUT_DO_PROBE2(STARPU_FUT_START_ALLOC_REUSE, memnode, syscall(SYS_gettid));
  245. #define STARPU_TRACE_END_ALLOC_REUSE(memnode) \
  246. FUT_DO_PROBE2(STARPU_FUT_END_ALLOC_REUSE, memnode, syscall(SYS_gettid));
  247. #define STARPU_TRACE_START_MEMRECLAIM(memnode) \
  248. FUT_DO_PROBE2(STARPU_FUT_START_MEMRECLAIM, memnode, syscall(SYS_gettid));
  249. #define STARPU_TRACE_END_MEMRECLAIM(memnode) \
  250. FUT_DO_PROBE2(STARPU_FUT_END_MEMRECLAIM, memnode, syscall(SYS_gettid));
  251. /* We skip these events becasue they are called so often that they cause FxT to
  252. * fail and make the overall trace unreadable anyway. */
  253. #define STARPU_TRACE_START_PROGRESS(memnode) \
  254. do {} while (0);
  255. // FUT_DO_PROBE2(STARPU_FUT_START_PROGRESS, memnode, syscall(SYS_gettid));
  256. #define STARPU_TRACE_END_PROGRESS(memnode) \
  257. do {} while (0);
  258. //FUT_DO_PROBE2(STARPU_FUT_END_PROGRESS, memnode, syscall(SYS_gettid));
  259. #define STARPU_TRACE_USER_EVENT(code) \
  260. FUT_DO_PROBE2(STARPU_FUT_USER_EVENT, code, syscall(SYS_gettid));
  261. #define STARPU_TRACE_SET_PROFILING(status) \
  262. FUT_DO_PROBE2(STARPU_FUT_SET_PROFILING, status, syscall(SYS_gettid));
  263. #define STARPU_TRACE_TASK_WAIT_FOR_ALL \
  264. FUT_DO_PROBE0(STARPU_FUT_TASK_WAIT_FOR_ALL)
  265. #else // !STARPU_USE_FXT
  266. /* Dummy macros in case FxT is disabled */
  267. #define STARPU_TRACE_NEW_MEM_NODE(nodeid) do {} while(0);
  268. #define TRACE_NEW_WORKER(a,b) do {} while(0);
  269. #define STARPU_TRACE_WORKER_INIT_START(a,b,c) do {} while(0);
  270. #define STARPU_TRACE_WORKER_INIT_END do {} while(0);
  271. #define STARPU_TRACE_START_CODELET_BODY(job) do {} while(0);
  272. #define STARPU_TRACE_END_CODELET_BODY(job, a) do {} while(0);
  273. #define STARPU_TRACE_START_CALLBACK(job) do {} while(0);
  274. #define STARPU_TRACE_END_CALLBACK(job) do {} while(0);
  275. #define STARPU_TRACE_JOB_PUSH(task, prio) do {} while(0);
  276. #define STARPU_TRACE_JOB_POP(task, prio) do {} while(0);
  277. #define STARPU_TRACE_UPDATE_TASK_CNT(counter) do {} while(0);
  278. #define STARPU_TRACE_START_FETCH_INPUT(job) do {} while(0);
  279. #define STARPU_TRACE_END_FETCH_INPUT(job) do {} while(0);
  280. #define STARPU_TRACE_START_PUSH_OUTPUT(job) do {} while(0);
  281. #define STARPU_TRACE_END_PUSH_OUTPUT(job) do {} while(0);
  282. #define STARPU_TRACE_TAG(tag, job) do {} while(0);
  283. #define STARPU_TRACE_TAG_DEPS(a, b) do {} while(0);
  284. #define STARPU_TRACE_TASK_DEPS(a, b) do {} while(0);
  285. #define STARPU_TRACE_GHOST_TASK_DEPS(a, b) do {} while(0);
  286. #define STARPU_TRACE_TASK_DONE(a) do {} while(0);
  287. #define STARPU_TRACE_TAG_DONE(a) do {} while(0);
  288. #define STARPU_TRACE_DATA_COPY(a, b, c) do {} while(0);
  289. #define STARPU_TRACE_START_DRIVER_COPY(a,b,c,d) do {} while(0);
  290. #define STARPU_TRACE_END_DRIVER_COPY(a,b,c,d) do {} while(0);
  291. #define STARPU_TRACE_START_DRIVER_COPY_ASYNC(a,b) do {} while(0);
  292. #define STARPU_TRACE_END_DRIVER_COPY_ASYNC(a,b) do {} while(0);
  293. #define STARPU_TRACE_WORK_STEALING(a, b) do {} while(0);
  294. #define STARPU_TRACE_WORKER_DEINIT_START do {} while(0);
  295. #define STARPU_TRACE_WORKER_DEINIT_END(a) do {} while(0);
  296. #define STARPU_TRACE_WORKER_SLEEP_START do {} while(0);
  297. #define STARPU_TRACE_WORKER_SLEEP_END do {} while(0);
  298. #define STARPU_TRACE_USER_DEFINED_START do {} while(0);
  299. #define STARPU_TRACE_USER_DEFINED_END do {} while(0);
  300. #define STARPU_TRACE_START_ALLOC(memnode) do {} while(0);
  301. #define STARPU_TRACE_END_ALLOC(memnode) do {} while(0);
  302. #define STARPU_TRACE_START_ALLOC_REUSE(a) do {} while(0);
  303. #define STARPU_TRACE_END_ALLOC_REUSE(a) do {} while(0);
  304. #define STARPU_TRACE_START_MEMRECLAIM(memnode) do {} while(0);
  305. #define STARPU_TRACE_END_MEMRECLAIM(memnode) do {} while(0);
  306. #define STARPU_TRACE_START_PROGRESS(memnode) do {} while(0);
  307. #define STARPU_TRACE_END_PROGRESS(memnode) do {} while(0);
  308. #define STARPU_TRACE_USER_EVENT(code) do {} while(0);
  309. #define STARPU_TRACE_SET_PROFILING(status) do {} while(0);
  310. #define STARPU_TRACE_TASK_WAIT_FOR_ALL do {} while(0);
  311. #endif // STARPU_USE_FXT
  312. #endif // __FXT_H__