fxt.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #ifndef __FXT_H__
  17. #define __FXT_H__
  18. #ifndef _GNU_SOURCE
  19. #define _GNU_SOURCE /* ou _BSD_SOURCE ou _SVID_SOURCE */
  20. #endif
  21. #include <unistd.h>
  22. #include <string.h>
  23. #include <sys/types.h>
  24. #include <stdlib.h>
  25. #include <common/config.h>
  26. #include <starpu.h>
  27. /* some key to identify the worker kind */
  28. #define STARPU_FUT_APPS_KEY 0x100
  29. #define STARPU_FUT_CPU_KEY 0x101
  30. #define STARPU_FUT_CUDA_KEY 0x102
  31. #define STARPU_FUT_OPENCL_KEY 0x103
  32. #define STARPU_FUT_WORKER_INIT_START 0x5100
  33. #define STARPU_FUT_WORKER_INIT_END 0x5101
  34. #define STARPU_FUT_START_CODELET_BODY 0x5102
  35. #define STARPU_FUT_END_CODELET_BODY 0x5103
  36. #define STARPU_FUT_JOB_PUSH 0x5104
  37. #define STARPU_FUT_JOB_POP 0x5105
  38. #define STARPU_FUT_UPDATE_TASK_CNT 0x5106
  39. #define STARPU_FUT_START_FETCH_INPUT 0x5107
  40. #define STARPU_FUT_END_FETCH_INPUT 0x5108
  41. #define STARPU_FUT_START_PUSH_OUTPUT 0x5109
  42. #define STARPU_FUT_END_PUSH_OUTPUT 0x5110
  43. #define STARPU_FUT_CODELET_TAG 0x5111
  44. #define STARPU_FUT_CODELET_TAG_DEPS 0x5112
  45. #define STARPU_FUT_TASK_DEPS 0x5113
  46. #define STARPU_FUT_DATA_COPY 0x5114
  47. #define STARPU_FUT_WORK_STEALING 0x5115
  48. #define STARPU_FUT_WORKER_DEINIT_START 0x5116
  49. #define STARPU_FUT_WORKER_DEINIT_END 0x5117
  50. #define STARPU_FUT_WORKER_SLEEP_START 0x5118
  51. #define STARPU_FUT_WORKER_SLEEP_END 0x5119
  52. #define STARPU_FUT_USER_DEFINED_START 0x5120
  53. #define STARPU_FUT_USER_DEFINED_END 0x5121
  54. #define STARPU_FUT_NEW_MEM_NODE 0x5122
  55. #define STARPU_FUT_START_CALLBACK 0x5123
  56. #define STARPU_FUT_END_CALLBACK 0x5124
  57. #define STARPU_FUT_TASK_DONE 0x5125
  58. #define STARPU_FUT_TAG_DONE 0x5126
  59. #define STARPU_FUT_START_ALLOC 0x5127
  60. #define STARPU_FUT_END_ALLOC 0x5128
  61. #define STARPU_FUT_START_ALLOC_REUSE 0x5129
  62. #define STARPU_FUT_END_ALLOC_REUSE 0x5130
  63. #define STARPU_FUT_START_MEMRECLAIM 0x5131
  64. #define STARPU_FUT_END_MEMRECLAIM 0x5132
  65. #define STARPU_FUT_START_DRIVER_COPY 0x5133
  66. #define STARPU_FUT_END_DRIVER_COPY 0x5134
  67. #define STARPU_FUT_START_PROGRESS 0x5135
  68. #define STARPU_FUT_END_PROGRESS 0x5136
  69. #define STARPU_FUT_USER_EVENT 0x5137
  70. #define STARPU_FUT_SET_PROFILING 0x5138
  71. #ifdef STARPU_USE_FXT
  72. #include <sys/syscall.h> /* pour les définitions de SYS_xxx */
  73. #include <fxt/fxt.h>
  74. #include <fxt/fut.h>
  75. void _starpu_start_fxt_profiling(void);
  76. void _starpu_stop_fxt_profiling(void);
  77. void _starpu_fxt_register_thread(unsigned);
  78. /* sometimes we need something a little more specific than the wrappers from
  79. * FxT */
  80. #define STARPU_FUT_DO_PROBE3STR(CODE, P1, P2, P3, str) \
  81. do { \
  82. /* we add a \0 just in case ... */ \
  83. size_t len = strlen((str)) + 1; \
  84. unsigned nbargs = 3 + (len + sizeof(unsigned long) - 1)/(sizeof(unsigned long));\
  85. size_t total_len = FUT_SIZE(nbargs); \
  86. unsigned long *args = \
  87. fut_getstampedbuffer(FUT_CODE(CODE, nbargs), total_len);\
  88. *(args++) = (unsigned long)(P1); \
  89. *(args++) = (unsigned long)(P2); \
  90. *(args++) = (unsigned long)(P3); \
  91. sprintf((char *)args, "%s", str); \
  92. } while (0);
  93. #define STARPU_FUT_DO_PROBE4STR(CODE, P1, P2, P3, P4, str) \
  94. do { \
  95. /* we add a \0 just in case ... */ \
  96. size_t len = strlen((str)) + 1; \
  97. unsigned nbargs = 4 + (len + sizeof(unsigned long) - 1)/(sizeof(unsigned long));\
  98. size_t total_len = FUT_SIZE(nbargs); \
  99. unsigned long *args = \
  100. fut_getstampedbuffer(FUT_CODE(CODE, nbargs), total_len);\
  101. *(args++) = (unsigned long)(P1); \
  102. *(args++) = (unsigned long)(P2); \
  103. *(args++) = (unsigned long)(P3); \
  104. *(args++) = (unsigned long)(P4); \
  105. sprintf((char *)args, "%s", str); \
  106. } while (0);
  107. /* workerkind = STARPU_FUT_CPU_KEY for instance */
  108. #define STARPU_TRACE_NEW_MEM_NODE(nodeid) \
  109. FUT_DO_PROBE2(STARPU_FUT_NEW_MEM_NODE, nodeid, syscall(SYS_gettid));
  110. #define STARPU_TRACE_WORKER_INIT_START(workerkind, devid, memnode) \
  111. FUT_DO_PROBE4(STARPU_FUT_WORKER_INIT_START, workerkind, devid, memnode, syscall(SYS_gettid));
  112. #define STARPU_TRACE_WORKER_INIT_END \
  113. FUT_DO_PROBE1(STARPU_FUT_WORKER_INIT_END, syscall(SYS_gettid));
  114. #define STARPU_TRACE_START_CODELET_BODY(job) \
  115. do { \
  116. struct starpu_perfmodel_t *model = (job)->task->cl->model; \
  117. if (model && model->symbol) \
  118. { \
  119. /* we include the symbol name */ \
  120. STARPU_FUT_DO_PROBE3STR(STARPU_FUT_START_CODELET_BODY, job, syscall(SYS_gettid), 1, model->symbol);\
  121. } \
  122. else { \
  123. FUT_DO_PROBE3(STARPU_FUT_START_CODELET_BODY, job, syscall(SYS_gettid), 0);\
  124. } \
  125. } while(0);
  126. #define STARPU_TRACE_END_CODELET_BODY(job) \
  127. FUT_DO_PROBE2(STARPU_FUT_END_CODELET_BODY, job, syscall(SYS_gettid));
  128. #define STARPU_TRACE_START_CALLBACK(job) \
  129. FUT_DO_PROBE2(STARPU_FUT_START_CALLBACK, job, syscall(SYS_gettid));
  130. #define STARPU_TRACE_END_CALLBACK(job) \
  131. FUT_DO_PROBE2(STARPU_FUT_END_CALLBACK, job, syscall(SYS_gettid));
  132. #define STARPU_TRACE_JOB_PUSH(task, prio) \
  133. FUT_DO_PROBE3(STARPU_FUT_JOB_PUSH, task, prio, syscall(SYS_gettid));
  134. #define STARPU_TRACE_JOB_POP(task, prio) \
  135. FUT_DO_PROBE3(STARPU_FUT_JOB_POP, task, prio, syscall(SYS_gettid));
  136. #define STARPU_TRACE_UPDATE_TASK_CNT(counter) \
  137. FUT_DO_PROBE2(STARPU_FUT_UPDATE_TASK_CNT, counter, syscall(SYS_gettid))
  138. #define STARPU_TRACE_START_FETCH_INPUT(job) \
  139. FUT_DO_PROBE2(STARPU_FUT_START_FETCH_INPUT, job, syscall(SYS_gettid));
  140. #define STARPU_TRACE_END_FETCH_INPUT(job) \
  141. FUT_DO_PROBE2(STARPU_FUT_END_FETCH_INPUT, job, syscall(SYS_gettid));
  142. #define STARPU_TRACE_START_PUSH_OUTPUT(job) \
  143. FUT_DO_PROBE2(STARPU_FUT_START_PUSH_OUTPUT, job, syscall(SYS_gettid));
  144. #define STARPU_TRACE_END_PUSH_OUTPUT(job) \
  145. FUT_DO_PROBE2(STARPU_FUT_END_PUSH_OUTPUT, job, syscall(SYS_gettid));
  146. #define STARPU_TRACE_CODELET_TAG(tag, job) \
  147. FUT_DO_PROBE2(STARPU_FUT_CODELET_TAG, tag, (job)->job_id)
  148. #define STARPU_TRACE_CODELET_TAG_DEPS(tag_child, tag_father) \
  149. FUT_DO_PROBE2(STARPU_FUT_CODELET_TAG_DEPS, tag_child, tag_father)
  150. #define STARPU_TRACE_TASK_DEPS(job_prev, job_succ) \
  151. FUT_DO_PROBE2(STARPU_FUT_TASK_DEPS, (job_prev)->job_id, (job_succ)->job_id)
  152. #define STARPU_TRACE_TASK_DONE(job) \
  153. do { \
  154. struct starpu_task *task = (job)->task; \
  155. unsigned exclude_from_dag = (job)->exclude_from_dag; \
  156. if (task && task->cl \
  157. && task->cl->model \
  158. && task->cl->model->symbol) \
  159. { \
  160. char *symbol = task->cl->model->symbol; \
  161. STARPU_FUT_DO_PROBE4STR(STARPU_FUT_TASK_DONE, (job)->job_id, syscall(SYS_gettid), (long unsigned)exclude_from_dag, 1, symbol);\
  162. } \
  163. else { \
  164. FUT_DO_PROBE4(STARPU_FUT_TASK_DONE, (job)->job_id, syscall(SYS_gettid), (long unsigned)exclude_from_dag, 0);\
  165. } \
  166. } while(0);
  167. #define STARPU_TRACE_TAG_DONE(tag) \
  168. do { \
  169. struct starpu_job_s *job = (tag)->job; \
  170. if (job && job->task \
  171. && job->task->cl \
  172. && job->task->cl->model \
  173. && job->task->cl->model->symbol) \
  174. { \
  175. char *symbol = job->task->cl->model->symbol; \
  176. STARPU_FUT_DO_PROBE3STR(STARPU_FUT_TAG_DONE, (tag)->id, syscall(SYS_gettid), 1, symbol);\
  177. } \
  178. else { \
  179. FUT_DO_PROBE3(STARPU_FUT_TAG_DONE, (tag)->id, syscall(SYS_gettid), 0);\
  180. } \
  181. } while(0);
  182. #define STARPU_TRACE_DATA_COPY(src_node, dst_node, size) \
  183. FUT_DO_PROBE3(STARPU_FUT_DATA_COPY, src_node, dst_node, size)
  184. #define STARPU_TRACE_START_DRIVER_COPY(src_node, dst_node, size, com_id) \
  185. FUT_DO_PROBE4(STARPU_FUT_START_DRIVER_COPY, src_node, dst_node, size, com_id)
  186. #define STARPU_TRACE_END_DRIVER_COPY(src_node, dst_node, size, com_id) \
  187. FUT_DO_PROBE4(STARPU_FUT_END_DRIVER_COPY, src_node, dst_node, size, com_id)
  188. #define STARPU_TRACE_WORK_STEALING(empty_q, victim_q) \
  189. FUT_DO_PROBE2(STARPU_FUT_WORK_STEALING, empty_q, victim_q)
  190. #define STARPU_TRACE_WORKER_DEINIT_START \
  191. FUT_DO_PROBE1(STARPU_FUT_WORKER_DEINIT_START, syscall(SYS_gettid));
  192. #define STARPU_TRACE_WORKER_DEINIT_END(workerkind) \
  193. FUT_DO_PROBE2(STARPU_FUT_WORKER_DEINIT_END, workerkind, syscall(SYS_gettid));
  194. #define STARPU_TRACE_WORKER_SLEEP_START \
  195. FUT_DO_PROBE1(STARPU_FUT_WORKER_SLEEP_START, syscall(SYS_gettid));
  196. #define STARPU_TRACE_WORKER_SLEEP_END \
  197. FUT_DO_PROBE1(STARPU_FUT_WORKER_SLEEP_END, syscall(SYS_gettid));
  198. #define STARPU_TRACE_USER_DEFINED_START \
  199. FUT_DO_PROBE1(STARPU_FUT_USER_DEFINED_START, syscall(SYS_gettid));
  200. #define STARPU_TRACE_USER_DEFINED_END \
  201. FUT_DO_PROBE1(STARPU_FUT_USER_DEFINED_END, syscall(SYS_gettid));
  202. #define STARPU_TRACE_START_ALLOC(memnode) \
  203. FUT_DO_PROBE2(STARPU_FUT_START_ALLOC, memnode, syscall(SYS_gettid));
  204. #define STARPU_TRACE_END_ALLOC(memnode) \
  205. FUT_DO_PROBE2(STARPU_FUT_END_ALLOC, memnode, syscall(SYS_gettid));
  206. #define STARPU_TRACE_START_ALLOC_REUSE(memnode) \
  207. FUT_DO_PROBE2(STARPU_FUT_START_ALLOC_REUSE, memnode, syscall(SYS_gettid));
  208. #define STARPU_TRACE_END_ALLOC_REUSE(memnode) \
  209. FUT_DO_PROBE2(STARPU_FUT_END_ALLOC_REUSE, memnode, syscall(SYS_gettid));
  210. #define STARPU_TRACE_START_MEMRECLAIM(memnode) \
  211. FUT_DO_PROBE2(STARPU_FUT_START_MEMRECLAIM, memnode, syscall(SYS_gettid));
  212. #define STARPU_TRACE_END_MEMRECLAIM(memnode) \
  213. FUT_DO_PROBE2(STARPU_FUT_END_MEMRECLAIM, memnode, syscall(SYS_gettid));
  214. #define STARPU_TRACE_START_PROGRESS(memnode) \
  215. FUT_DO_PROBE2(STARPU_FUT_START_PROGRESS, memnode, syscall(SYS_gettid));
  216. #define STARPU_TRACE_END_PROGRESS(memnode) \
  217. FUT_DO_PROBE2(STARPU_FUT_END_PROGRESS, memnode, syscall(SYS_gettid));
  218. #define STARPU_TRACE_USER_EVENT(code) \
  219. FUT_DO_PROBE2(STARPU_FUT_USER_EVENT, code, syscall(SYS_gettid));
  220. #define STARPU_TRACE_SET_PROFILING(status) \
  221. FUT_DO_PROBE2(STARPU_FUT_SET_PROFILING, status, syscall(SYS_gettid));
  222. #else // !STARPU_USE_FXT
  223. #define STARPU_TRACE_NEW_MEM_NODE(nodeid) do {} while(0);
  224. #define TRACE_NEW_WORKER(a,b) do {} while(0);
  225. #define STARPU_TRACE_WORKER_INIT_START(a,b,c) do {} while(0);
  226. #define STARPU_TRACE_WORKER_INIT_END do {} while(0);
  227. #define STARPU_TRACE_START_CODELET_BODY(job) do {} while(0);
  228. #define STARPU_TRACE_END_CODELET_BODY(job) do {} while(0);
  229. #define STARPU_TRACE_START_CALLBACK(job) do {} while(0);
  230. #define STARPU_TRACE_END_CALLBACK(job) do {} while(0);
  231. #define STARPU_TRACE_JOB_PUSH(task, prio) do {} while(0);
  232. #define STARPU_TRACE_JOB_POP(task, prio) do {} while(0);
  233. #define STARPU_TRACE_UPDATE_TASK_CNT(counter) do {} while(0);
  234. #define STARPU_TRACE_START_FETCH_INPUT(job) do {} while(0);
  235. #define STARPU_TRACE_END_FETCH_INPUT(job) do {} while(0);
  236. #define STARPU_TRACE_START_PUSH_OUTPUT(job) do {} while(0);
  237. #define STARPU_TRACE_END_PUSH_OUTPUT(job) do {} while(0);
  238. #define STARPU_TRACE_CODELET_TAG(tag, job) do {} while(0);
  239. #define STARPU_TRACE_CODELET_TAG_DEPS(a, b) do {} while(0);
  240. #define STARPU_TRACE_TASK_DEPS(a, b) do {} while(0);
  241. #define STARPU_TRACE_TASK_DONE(a) do {} while(0);
  242. #define STARPU_TRACE_TAG_DONE(a) do {} while(0);
  243. #define STARPU_TRACE_DATA_COPY(a, b, c) do {} while(0);
  244. #define STARPU_TRACE_START_DRIVER_COPY(a,b,c,d) do {} while(0);
  245. #define STARPU_TRACE_END_DRIVER_COPY(a,b,c,d) do {} while(0);
  246. #define STARPU_TRACE_WORK_STEALING(a, b) do {} while(0);
  247. #define STARPU_TRACE_WORKER_DEINIT_START do {} while(0);
  248. #define STARPU_TRACE_WORKER_DEINIT_END(a) do {} while(0);
  249. #define STARPU_TRACE_WORKER_SLEEP_START do {} while(0);
  250. #define STARPU_TRACE_WORKER_SLEEP_END do {} while(0);
  251. #define STARPU_TRACE_USER_DEFINED_START do {} while(0);
  252. #define STARPU_TRACE_USER_DEFINED_END do {} while(0);
  253. #define STARPU_TRACE_START_ALLOC(memnode) do {} while(0);
  254. #define STARPU_TRACE_END_ALLOC(memnode) do {} while(0);
  255. #define STARPU_TRACE_START_ALLOC_REUSE(a) do {} while(0);
  256. #define STARPU_TRACE_END_ALLOC_REUSE(a) do {} while(0);
  257. #define STARPU_TRACE_START_MEMRECLAIM(memnode) do {} while(0);
  258. #define STARPU_TRACE_END_MEMRECLAIM(memnode) do {} while(0);
  259. #define STARPU_TRACE_START_PROGRESS(memnode) do {} while(0);
  260. #define STARPU_TRACE_END_PROGRESS(memnode) do {} while(0);
  261. #define STARPU_TRACE_USER_EVENT(code) do {} while(0);
  262. #define STARPU_TRACE_SET_PROFILING(status) do {} while(0);
  263. #endif // STARPU_USE_FXT
  264. #endif // __FXT_H__