datastats.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010 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. #include <starpu.h>
  18. #include <datawizard/datastats.h>
  19. #include <datawizard/coherency.h>
  20. #include <common/config.h>
  21. #ifdef STARPU_DATA_STATS
  22. /* measure the cache hit ratio for each node */
  23. static unsigned hit_cnt[STARPU_MAXNODES];
  24. static unsigned miss_cnt[STARPU_MAXNODES];
  25. #endif
  26. void _starpu_msi_cache_hit(unsigned node __attribute__ ((unused)))
  27. {
  28. #ifdef STARPU_DATA_STATS
  29. hit_cnt[node]++;
  30. #endif
  31. }
  32. void _starpu_msi_cache_miss(unsigned node __attribute__ ((unused)))
  33. {
  34. #ifdef STARPU_DATA_STATS
  35. miss_cnt[node]++;
  36. #endif
  37. }
  38. void _starpu_display_msi_stats(void)
  39. {
  40. #ifdef STARPU_DATA_STATS
  41. unsigned node;
  42. unsigned total_hit_cnt = 0;
  43. unsigned total_miss_cnt = 0;
  44. fprintf(stderr, "MSI cache stats :\n");
  45. for (node = 0; node < STARPU_MAXNODES; node++)
  46. {
  47. total_hit_cnt += hit_cnt[node];
  48. total_miss_cnt += miss_cnt[node];
  49. }
  50. fprintf(stderr, "TOTAL MSI stats\thit %u (%2.2f \%%)\tmiss %u (%2.2f \%%)\n", total_hit_cnt, (100.0f*total_hit_cnt)/(total_hit_cnt+total_miss_cnt), total_miss_cnt, (100.0f*total_miss_cnt)/(total_hit_cnt+total_miss_cnt));
  51. for (node = 0; node < STARPU_MAXNODES; node++)
  52. {
  53. if (hit_cnt[node]+miss_cnt[node])
  54. {
  55. fprintf(stderr, "memory node %d\n", node);
  56. fprintf(stderr, "\thit : %u (%2.2f \%%)\n", hit_cnt[node], (100.0f*hit_cnt[node])/(hit_cnt[node]+miss_cnt[node]));
  57. fprintf(stderr, "\tmiss : %u (%2.2f \%%)\n", miss_cnt[node], (100.0f*miss_cnt[node])/(hit_cnt[node]+miss_cnt[node]));
  58. }
  59. }
  60. #endif
  61. }
  62. /* measure the efficiency of our allocation cache */
  63. #ifdef STARPU_DATA_STATS
  64. static unsigned alloc_cnt[STARPU_MAXNODES];
  65. static unsigned alloc_cache_hit_cnt[STARPU_MAXNODES];
  66. #endif
  67. void _starpu_allocation_cache_hit(unsigned node __attribute__ ((unused)))
  68. {
  69. #ifdef STARPU_DATA_STATS
  70. alloc_cache_hit_cnt[node]++;
  71. #endif
  72. }
  73. void _starpu_data_allocation_inc_stats(unsigned node __attribute__ ((unused)))
  74. {
  75. #ifdef STARPU_DATA_STATS
  76. alloc_cnt[node]++;
  77. #endif
  78. }
  79. void _starpu_display_alloc_cache_stats(void)
  80. {
  81. #ifdef STARPU_DATA_STATS
  82. fprintf(stderr, "Allocation cache stats:\n");
  83. unsigned node;
  84. for (node = 0; node < STARPU_MAXNODES; node++)
  85. {
  86. if (alloc_cnt[node])
  87. {
  88. fprintf(stderr, "memory node %d\n", node);
  89. fprintf(stderr, "\ttotal alloc : %u\n", alloc_cnt[node]);
  90. fprintf(stderr, "\tcached alloc: %u (%2.2f \%%)\n",
  91. alloc_cache_hit_cnt[node], (100.0f*alloc_cache_hit_cnt[node])/(alloc_cnt[node]));
  92. }
  93. }
  94. #endif
  95. }
  96. /* measure the amount of data transfers between each pair of nodes */
  97. #ifdef STARPU_DATA_STATS
  98. static size_t comm_amount[STARPU_MAXNODES][STARPU_MAXNODES];
  99. #endif /* STARPU_DATA_STATS */
  100. void _starpu_comm_amounts_inc(unsigned src __attribute__ ((unused)), unsigned dst __attribute__ ((unused)), size_t size __attribute__ ((unused)))
  101. {
  102. #ifdef STARPU_DATA_STATS
  103. comm_amount[src][dst] += size;
  104. #endif /* STARPU_DATA_STATS */
  105. }
  106. void _starpu_display_comm_amounts(void)
  107. {
  108. #ifdef STARPU_DATA_STATS
  109. unsigned src, dst;
  110. size_t sum = 0;
  111. for (dst = 0; dst < STARPU_MAXNODES; dst++)
  112. for (src = 0; src < STARPU_MAXNODES; src++)
  113. {
  114. sum += comm_amount[src][dst];
  115. sum += comm_amount[dst][src];
  116. }
  117. fprintf(stderr, "\nData transfers stats:\nTOTAL transfers %f MB\n", (float)sum/1024/1024);
  118. for (dst = 0; dst < STARPU_MAXNODES; dst++)
  119. for (src = dst + 1; src < STARPU_MAXNODES; src++)
  120. {
  121. if (comm_amount[src][dst])
  122. fprintf(stderr, "\t%d <-> %d\t%f MB\n\t\t%d -> %d\t%f MB\n\t\t%d -> %d\t%f MB\n",
  123. src, dst, ((float)comm_amount[src][dst] + (float)comm_amount[dst][src])/(1024*1024),
  124. src, dst, ((float)comm_amount[src][dst])/(1024*1024),
  125. dst, src, ((float)comm_amount[dst][src])/(1024*1024));
  126. }
  127. #endif
  128. }
  129. #ifdef STARPU_MEMORY_STATUS
  130. void _starpu_display_data_stats(void)
  131. {
  132. unsigned node;
  133. for (node = 0; node < STARPU_MAXNODES; node++)
  134. {
  135. _starpu_display_data_stats_by_node(node);
  136. }
  137. }
  138. void _starpu_display_data_handle_stats(starpu_data_handle_t handle)
  139. {
  140. unsigned node;
  141. fprintf(stderr, "#-----\n");
  142. fprintf(stderr, "Data : %p\n", handle);
  143. fprintf(stderr, "Size : %d\n", (int)handle->data_size);
  144. fprintf(stderr, "\n");
  145. fprintf(stderr, "#--\n");
  146. fprintf(stderr, "Data access stats\n");
  147. fprintf(stderr, "/!\\ Work Underway\n");
  148. for (node = 0; node < STARPU_MAXNODES; node++)
  149. {
  150. if (handle->stats_direct_access[node]+handle->stats_loaded_shared[node]
  151. +handle->stats_invalidated[node]+handle->stats_loaded_owner[node])
  152. {
  153. fprintf(stderr, "Node #%d\n", node);
  154. fprintf(stderr, "\tDirect access : %d\n", handle->stats_direct_access[node]);
  155. /* XXX Not Working yet. */
  156. if (handle->stats_shared_to_owner[node])
  157. fprintf(stderr, "\t\tShared to Owner : %d\n", handle->stats_shared_to_owner[node]);
  158. fprintf(stderr, "\tLoaded (Owner) : %d\n", handle->stats_loaded_owner[node]);
  159. fprintf(stderr, "\tLoaded (Shared) : %d\n", handle->stats_loaded_shared[node]);
  160. fprintf(stderr, "\tInvalidated (was Owner) : %d\n\n", handle->stats_invalidated[node]);
  161. }
  162. }
  163. }
  164. void _starpu_handle_stats_cache_hit(starpu_data_handle_t handle, unsigned node)
  165. {
  166. handle->stats_direct_access[node]++;
  167. }
  168. void _starpu_handle_stats_loaded_shared(starpu_data_handle_t handle, unsigned node)
  169. {
  170. handle->stats_loaded_shared[node]++;
  171. }
  172. void _starpu_handle_stats_loaded_owner(starpu_data_handle_t handle, unsigned node)
  173. {
  174. handle->stats_loaded_owner[node]++;
  175. }
  176. void _starpu_handle_stats_shared_to_owner(starpu_data_handle_t handle, unsigned node)
  177. {
  178. handle->stats_shared_to_owner[node]++;
  179. }
  180. void _starpu_handle_stats_invalidated(starpu_data_handle_t handle, unsigned node)
  181. {
  182. handle->stats_invalidated[node]++;
  183. }
  184. #endif