fxt.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010 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_PROGRESS 0x5135
  69. #define STARPU_FUT_END_PROGRESS 0x5136
  70. #define STARPU_FUT_USER_EVENT 0x5137
  71. #define STARPU_FUT_SET_PROFILING 0x5138
  72. #define STARPU_FUT_TASK_WAIT_FOR_ALL 0x5139
  73. #ifdef STARPU_USE_FXT
  74. #include <sys/syscall.h> /* pour les définitions de SYS_xxx */
  75. #include <fxt/fxt.h>
  76. #include <fxt/fut.h>
  77. /* Initialize the FxT library. */
  78. void _starpu_start_fxt_profiling(void);
  79. /* Stop the FxT library, and generate the trace file. */
  80. void _starpu_stop_fxt_profiling(void);
  81. /* Associate the current processing unit to the identifier of the LWP that runs
  82. * the worker. */
  83. void _starpu_fxt_register_thread(unsigned);
  84. /* Sometimes we need something a little more specific than the wrappers from
  85. * FxT: these macro permit to put add an event with 3 (or 4) numbers followed
  86. * by a string. */
  87. #define STARPU_FUT_DO_PROBE3STR(CODE, P1, P2, P3, str) \
  88. do { \
  89. /* we add a \0 just in case ... */ \
  90. size_t len = strlen((str)) + 1; \
  91. unsigned nbargs = 3 + (len + sizeof(unsigned long) - 1)/(sizeof(unsigned long));\
  92. size_t total_len = FUT_SIZE(nbargs); \
  93. unsigned long *args = \
  94. fut_getstampedbuffer(FUT_CODE(CODE, nbargs), total_len);\
  95. *(args++) = (unsigned long)(P1); \
  96. *(args++) = (unsigned long)(P2); \
  97. *(args++) = (unsigned long)(P3); \
  98. sprintf((char *)args, "%s", str); \
  99. } while (0);
  100. #define STARPU_FUT_DO_PROBE4STR(CODE, P1, P2, P3, P4, str) \
  101. do { \
  102. /* we add a \0 just in case ... */ \
  103. size_t len = strlen((str)) + 1; \
  104. unsigned nbargs = 4 + (len + sizeof(unsigned long) - 1)/(sizeof(unsigned long));\
  105. size_t total_len = FUT_SIZE(nbargs); \
  106. unsigned long *args = \
  107. fut_getstampedbuffer(FUT_CODE(CODE, nbargs), total_len);\
  108. *(args++) = (unsigned long)(P1); \
  109. *(args++) = (unsigned long)(P2); \
  110. *(args++) = (unsigned long)(P3); \
  111. *(args++) = (unsigned long)(P4); \
  112. sprintf((char *)args, "%s", str); \
  113. } while (0);
  114. /* workerkind = STARPU_FUT_CPU_KEY for instance */
  115. #define STARPU_TRACE_NEW_MEM_NODE(nodeid) \
  116. FUT_DO_PROBE2(STARPU_FUT_NEW_MEM_NODE, nodeid, syscall(SYS_gettid));
  117. #define STARPU_TRACE_WORKER_INIT_START(workerkind, devid, memnode) \
  118. FUT_DO_PROBE4(STARPU_FUT_WORKER_INIT_START, workerkind, devid, memnode, syscall(SYS_gettid));
  119. #define STARPU_TRACE_WORKER_INIT_END \
  120. FUT_DO_PROBE1(STARPU_FUT_WORKER_INIT_END, syscall(SYS_gettid));
  121. #define STARPU_TRACE_START_CODELET_BODY(job) \
  122. do { \
  123. const char *model_name = _starpu_get_model_name((job)); \
  124. if (model_name) \
  125. { \
  126. /* we include the symbol name */ \
  127. STARPU_FUT_DO_PROBE3STR(STARPU_FUT_START_CODELET_BODY, (job), syscall(SYS_gettid), 1, model_name); \
  128. } \
  129. else { \
  130. FUT_DO_PROBE3(STARPU_FUT_START_CODELET_BODY, (job), syscall(SYS_gettid), 0); \
  131. } \
  132. } while(0);
  133. #define STARPU_TRACE_END_CODELET_BODY(job) \
  134. FUT_DO_PROBE2(STARPU_FUT_END_CODELET_BODY, job, syscall(SYS_gettid));
  135. #define STARPU_TRACE_START_CALLBACK(job) \
  136. FUT_DO_PROBE2(STARPU_FUT_START_CALLBACK, job, syscall(SYS_gettid));
  137. #define STARPU_TRACE_END_CALLBACK(job) \
  138. FUT_DO_PROBE2(STARPU_FUT_END_CALLBACK, job, syscall(SYS_gettid));
  139. #define STARPU_TRACE_JOB_PUSH(task, prio) \
  140. FUT_DO_PROBE3(STARPU_FUT_JOB_PUSH, task, prio, syscall(SYS_gettid));
  141. #define STARPU_TRACE_JOB_POP(task, prio) \
  142. FUT_DO_PROBE3(STARPU_FUT_JOB_POP, task, prio, syscall(SYS_gettid));
  143. #define STARPU_TRACE_UPDATE_TASK_CNT(counter) \
  144. FUT_DO_PROBE2(STARPU_FUT_UPDATE_TASK_CNT, counter, syscall(SYS_gettid))
  145. #define STARPU_TRACE_START_FETCH_INPUT(job) \
  146. FUT_DO_PROBE2(STARPU_FUT_START_FETCH_INPUT, job, syscall(SYS_gettid));
  147. #define STARPU_TRACE_END_FETCH_INPUT(job) \
  148. FUT_DO_PROBE2(STARPU_FUT_END_FETCH_INPUT, job, syscall(SYS_gettid));
  149. #define STARPU_TRACE_START_PUSH_OUTPUT(job) \
  150. FUT_DO_PROBE2(STARPU_FUT_START_PUSH_OUTPUT, job, syscall(SYS_gettid));
  151. #define STARPU_TRACE_END_PUSH_OUTPUT(job) \
  152. FUT_DO_PROBE2(STARPU_FUT_END_PUSH_OUTPUT, job, syscall(SYS_gettid));
  153. #define STARPU_TRACE_TAG(tag, job) \
  154. FUT_DO_PROBE2(STARPU_FUT_TAG, tag, (job)->job_id)
  155. #define STARPU_TRACE_TAG_DEPS(tag_child, tag_father) \
  156. FUT_DO_PROBE2(STARPU_FUT_TAG_DEPS, tag_child, tag_father)
  157. #define STARPU_TRACE_TASK_DEPS(job_prev, job_succ) \
  158. FUT_DO_PROBE2(STARPU_FUT_TASK_DEPS, (job_prev)->job_id, (job_succ)->job_id)
  159. #define STARPU_TRACE_GHOST_TASK_DEPS(ghost_prev_id, job_succ_id) \
  160. FUT_DO_PROBE2(STARPU_FUT_TASK_DEPS, (ghost_prev_id), (job_succ_id))
  161. #define STARPU_TRACE_TASK_DONE(job) \
  162. do { \
  163. unsigned exclude_from_dag = (job)->exclude_from_dag; \
  164. const char *model_name = _starpu_get_model_name((job)); \
  165. if (model_name) \
  166. { \
  167. STARPU_FUT_DO_PROBE4STR(STARPU_FUT_TASK_DONE, (job)->job_id, syscall(SYS_gettid), (long unsigned)exclude_from_dag, 1, model_name);\
  168. } \
  169. else { \
  170. FUT_DO_PROBE4(STARPU_FUT_TASK_DONE, (job)->job_id, syscall(SYS_gettid), (long unsigned)exclude_from_dag, 0);\
  171. } \
  172. } while(0);
  173. #define STARPU_TRACE_TAG_DONE(tag) \
  174. do { \
  175. struct starpu_job_s *job = (tag)->job; \
  176. const char *model_name = _starpu_get_model_name((job)); \
  177. if (model_name) \
  178. { \
  179. STARPU_FUT_DO_PROBE3STR(STARPU_FUT_TAG_DONE, (tag)->id, syscall(SYS_gettid), 1, model_name); \
  180. } \
  181. else { \
  182. FUT_DO_PROBE3(STARPU_FUT_TAG_DONE, (tag)->id, syscall(SYS_gettid), 0);\
  183. } \
  184. } while(0);
  185. #define STARPU_TRACE_DATA_COPY(src_node, dst_node, size) \
  186. FUT_DO_PROBE3(STARPU_FUT_DATA_COPY, src_node, dst_node, size)
  187. #define STARPU_TRACE_START_DRIVER_COPY(src_node, dst_node, size, com_id) \
  188. FUT_DO_PROBE4(STARPU_FUT_START_DRIVER_COPY, src_node, dst_node, size, com_id)
  189. #define STARPU_TRACE_END_DRIVER_COPY(src_node, dst_node, size, com_id) \
  190. FUT_DO_PROBE4(STARPU_FUT_END_DRIVER_COPY, src_node, dst_node, size, com_id)
  191. #define STARPU_TRACE_WORK_STEALING(empty_q, victim_q) \
  192. FUT_DO_PROBE2(STARPU_FUT_WORK_STEALING, empty_q, victim_q)
  193. #define STARPU_TRACE_WORKER_DEINIT_START \
  194. FUT_DO_PROBE1(STARPU_FUT_WORKER_DEINIT_START, syscall(SYS_gettid));
  195. #define STARPU_TRACE_WORKER_DEINIT_END(workerkind) \
  196. FUT_DO_PROBE2(STARPU_FUT_WORKER_DEINIT_END, workerkind, syscall(SYS_gettid));
  197. #define STARPU_TRACE_WORKER_SLEEP_START \
  198. FUT_DO_PROBE1(STARPU_FUT_WORKER_SLEEP_START, syscall(SYS_gettid));
  199. #define STARPU_TRACE_WORKER_SLEEP_END \
  200. FUT_DO_PROBE1(STARPU_FUT_WORKER_SLEEP_END, syscall(SYS_gettid));
  201. #define STARPU_TRACE_USER_DEFINED_START \
  202. FUT_DO_PROBE1(STARPU_FUT_USER_DEFINED_START, syscall(SYS_gettid));
  203. #define STARPU_TRACE_USER_DEFINED_END \
  204. FUT_DO_PROBE1(STARPU_FUT_USER_DEFINED_END, syscall(SYS_gettid));
  205. #define STARPU_TRACE_START_ALLOC(memnode) \
  206. FUT_DO_PROBE2(STARPU_FUT_START_ALLOC, memnode, syscall(SYS_gettid));
  207. #define STARPU_TRACE_END_ALLOC(memnode) \
  208. FUT_DO_PROBE2(STARPU_FUT_END_ALLOC, memnode, syscall(SYS_gettid));
  209. #define STARPU_TRACE_START_ALLOC_REUSE(memnode) \
  210. FUT_DO_PROBE2(STARPU_FUT_START_ALLOC_REUSE, memnode, syscall(SYS_gettid));
  211. #define STARPU_TRACE_END_ALLOC_REUSE(memnode) \
  212. FUT_DO_PROBE2(STARPU_FUT_END_ALLOC_REUSE, memnode, syscall(SYS_gettid));
  213. #define STARPU_TRACE_START_MEMRECLAIM(memnode) \
  214. FUT_DO_PROBE2(STARPU_FUT_START_MEMRECLAIM, memnode, syscall(SYS_gettid));
  215. #define STARPU_TRACE_END_MEMRECLAIM(memnode) \
  216. FUT_DO_PROBE2(STARPU_FUT_END_MEMRECLAIM, memnode, syscall(SYS_gettid));
  217. /* We skip these events becasue they are called so often that they cause FxT to
  218. * fail and make the overall trace unreadable anyway. */
  219. #define STARPU_TRACE_START_PROGRESS(memnode) \
  220. do {} while (0);
  221. // FUT_DO_PROBE2(STARPU_FUT_START_PROGRESS, memnode, syscall(SYS_gettid));
  222. #define STARPU_TRACE_END_PROGRESS(memnode) \
  223. do {} while (0);
  224. //FUT_DO_PROBE2(STARPU_FUT_END_PROGRESS, memnode, syscall(SYS_gettid));
  225. #define STARPU_TRACE_USER_EVENT(code) \
  226. FUT_DO_PROBE2(STARPU_FUT_USER_EVENT, code, syscall(SYS_gettid));
  227. #define STARPU_TRACE_SET_PROFILING(status) \
  228. FUT_DO_PROBE2(STARPU_FUT_SET_PROFILING, status, syscall(SYS_gettid));
  229. #define STARPU_TRACE_TASK_WAIT_FOR_ALL \
  230. FUT_DO_PROBE0(STARPU_FUT_TASK_WAIT_FOR_ALL)
  231. #else // !STARPU_USE_FXT
  232. /* Dummy macros in case FxT is disabled */
  233. #define STARPU_TRACE_NEW_MEM_NODE(nodeid) do {} while(0);
  234. #define TRACE_NEW_WORKER(a,b) do {} while(0);
  235. #define STARPU_TRACE_WORKER_INIT_START(a,b,c) do {} while(0);
  236. #define STARPU_TRACE_WORKER_INIT_END do {} while(0);
  237. #define STARPU_TRACE_START_CODELET_BODY(job) do {} while(0);
  238. #define STARPU_TRACE_END_CODELET_BODY(job) do {} while(0);
  239. #define STARPU_TRACE_START_CALLBACK(job) do {} while(0);
  240. #define STARPU_TRACE_END_CALLBACK(job) do {} while(0);
  241. #define STARPU_TRACE_JOB_PUSH(task, prio) do {} while(0);
  242. #define STARPU_TRACE_JOB_POP(task, prio) do {} while(0);
  243. #define STARPU_TRACE_UPDATE_TASK_CNT(counter) do {} while(0);
  244. #define STARPU_TRACE_START_FETCH_INPUT(job) do {} while(0);
  245. #define STARPU_TRACE_END_FETCH_INPUT(job) do {} while(0);
  246. #define STARPU_TRACE_START_PUSH_OUTPUT(job) do {} while(0);
  247. #define STARPU_TRACE_END_PUSH_OUTPUT(job) do {} while(0);
  248. #define STARPU_TRACE_TAG(tag, job) do {} while(0);
  249. #define STARPU_TRACE_TAG_DEPS(a, b) do {} while(0);
  250. #define STARPU_TRACE_TASK_DEPS(a, b) do {} while(0);
  251. #define STARPU_TRACE_GHOST_TASK_DEPS(a, b) do {} while(0);
  252. #define STARPU_TRACE_TASK_DONE(a) do {} while(0);
  253. #define STARPU_TRACE_TAG_DONE(a) do {} while(0);
  254. #define STARPU_TRACE_DATA_COPY(a, b, c) do {} while(0);
  255. #define STARPU_TRACE_START_DRIVER_COPY(a,b,c,d) do {} while(0);
  256. #define STARPU_TRACE_END_DRIVER_COPY(a,b,c,d) do {} while(0);
  257. #define STARPU_TRACE_WORK_STEALING(a, b) do {} while(0);
  258. #define STARPU_TRACE_WORKER_DEINIT_START do {} while(0);
  259. #define STARPU_TRACE_WORKER_DEINIT_END(a) do {} while(0);
  260. #define STARPU_TRACE_WORKER_SLEEP_START do {} while(0);
  261. #define STARPU_TRACE_WORKER_SLEEP_END do {} while(0);
  262. #define STARPU_TRACE_USER_DEFINED_START do {} while(0);
  263. #define STARPU_TRACE_USER_DEFINED_END do {} while(0);
  264. #define STARPU_TRACE_START_ALLOC(memnode) do {} while(0);
  265. #define STARPU_TRACE_END_ALLOC(memnode) do {} while(0);
  266. #define STARPU_TRACE_START_ALLOC_REUSE(a) do {} while(0);
  267. #define STARPU_TRACE_END_ALLOC_REUSE(a) do {} while(0);
  268. #define STARPU_TRACE_START_MEMRECLAIM(memnode) do {} while(0);
  269. #define STARPU_TRACE_END_MEMRECLAIM(memnode) do {} while(0);
  270. #define STARPU_TRACE_START_PROGRESS(memnode) do {} while(0);
  271. #define STARPU_TRACE_END_PROGRESS(memnode) do {} while(0);
  272. #define STARPU_TRACE_USER_EVENT(code) do {} while(0);
  273. #define STARPU_TRACE_SET_PROFILING(status) do {} while(0);
  274. #define STARPU_TRACE_TASK_WAIT_FOR_ALL do {} while(0);
  275. #endif // STARPU_USE_FXT
  276. #endif // __FXT_H__