driver_common.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2012 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012 Centre National de la Recherche Scientifique
  5. * Copyright (C) 2011 Télécom-SudParis
  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. #include <math.h>
  19. #include <starpu.h>
  20. #include <starpu_profiling.h>
  21. #include <profiling/profiling.h>
  22. #include <common/utils.h>
  23. #include <core/debug.h>
  24. #include <drivers/driver_common/driver_common.h>
  25. #include <starpu_top.h>
  26. #include <core/sched_policy.h>
  27. #include <top/starpu_top_core.h>
  28. void _starpu_driver_start_job(struct _starpu_worker *args, struct _starpu_job *j, struct timespec *codelet_start, int rank, int profiling)
  29. {
  30. struct starpu_task *task = j->task;
  31. struct starpu_codelet *cl = task->cl;
  32. struct starpu_task_profiling_info *profiling_info;
  33. int starpu_top=_starpu_top_status_get();
  34. int workerid = args->workerid;
  35. unsigned calibrate_model = 0;
  36. if (cl->model && cl->model->benchmarking)
  37. calibrate_model = 1;
  38. /* If the job is executed on a combined worker there is no need for the
  39. * scheduler to process it : it doesn't contain any valuable data
  40. * as it's not linked to an actual worker */
  41. if (j->task_size == 1)
  42. _starpu_sched_pre_exec_hook(task);
  43. args->status = STATUS_EXECUTING;
  44. task->status = STARPU_TASK_RUNNING;
  45. if (rank == 0)
  46. {
  47. cl->per_worker_stats[workerid]++;
  48. profiling_info = task->profiling_info;
  49. if ((profiling && profiling_info) || calibrate_model || starpu_top)
  50. {
  51. _starpu_clock_gettime(codelet_start);
  52. _starpu_worker_register_executing_start_date(workerid, codelet_start);
  53. }
  54. }
  55. if (starpu_top)
  56. _starpu_top_task_started(task,workerid,codelet_start);
  57. _STARPU_TRACE_START_CODELET_BODY(j);
  58. }
  59. void _starpu_driver_end_job(struct _starpu_worker *args, struct _starpu_job *j, enum starpu_perf_archtype perf_arch STARPU_ATTRIBUTE_UNUSED, struct timespec *codelet_end, int rank, int profiling)
  60. {
  61. struct starpu_task *task = j->task;
  62. struct starpu_codelet *cl = task->cl;
  63. struct starpu_task_profiling_info *profiling_info = task->profiling_info;
  64. int starpu_top=_starpu_top_status_get();
  65. int workerid = args->workerid;
  66. unsigned calibrate_model = 0;
  67. _STARPU_TRACE_END_CODELET_BODY(j, j->nimpl, perf_arch);
  68. if (cl->model && cl->model->benchmarking)
  69. calibrate_model = 1;
  70. if (rank == 0)
  71. {
  72. if ((profiling && profiling_info) || calibrate_model || starpu_top)
  73. _starpu_clock_gettime(codelet_end);
  74. }
  75. if (starpu_top)
  76. _starpu_top_task_ended(task,workerid,codelet_end);
  77. args->status = STATUS_UNKNOWN;
  78. }
  79. void _starpu_driver_update_job_feedback(struct _starpu_job *j, struct _starpu_worker *worker_args,
  80. enum starpu_perf_archtype perf_arch,
  81. struct timespec *codelet_start, struct timespec *codelet_end, int profiling)
  82. {
  83. struct starpu_task_profiling_info *profiling_info = j->task->profiling_info;
  84. struct timespec measured_ts;
  85. double measured;
  86. int workerid = worker_args->workerid;
  87. struct starpu_codelet *cl = j->task->cl;
  88. int calibrate_model = 0;
  89. int updated = 0;
  90. if (cl->model && cl->model->benchmarking)
  91. calibrate_model = 1;
  92. if ((profiling && profiling_info) || calibrate_model)
  93. {
  94. starpu_timespec_sub(codelet_end, codelet_start, &measured_ts);
  95. measured = starpu_timing_timespec_to_us(&measured_ts);
  96. if (profiling && profiling_info)
  97. {
  98. memcpy(&profiling_info->start_time, codelet_start, sizeof(struct timespec));
  99. memcpy(&profiling_info->end_time, codelet_end, sizeof(struct timespec));
  100. profiling_info->workerid = workerid;
  101. _starpu_worker_update_profiling_info_executing(workerid, &measured_ts, 1,
  102. profiling_info->used_cycles,
  103. profiling_info->stall_cycles,
  104. profiling_info->power_consumed);
  105. updated = 1;
  106. }
  107. if (calibrate_model)
  108. _starpu_update_perfmodel_history(j, j->task->cl->model, perf_arch, worker_args->devid, measured,j->nimpl);
  109. }
  110. if (!updated)
  111. _starpu_worker_update_profiling_info_executing(workerid, NULL, 1, 0, 0, 0);
  112. if (profiling_info && profiling_info->power_consumed && cl->power_model && cl->power_model->benchmarking)
  113. {
  114. _starpu_update_perfmodel_history(j, j->task->cl->power_model, perf_arch, worker_args->devid, profiling_info->power_consumed,j->nimpl);
  115. }
  116. }
  117. /* Workers may block when there is no work to do at all. We assume that the
  118. * mutex is hold when that function is called. */
  119. void _starpu_block_worker(int workerid, pthread_cond_t *cond, pthread_mutex_t *mutex)
  120. {
  121. struct timespec start_time, end_time;
  122. _STARPU_TRACE_WORKER_SLEEP_START
  123. _starpu_worker_set_status(workerid, STATUS_SLEEPING);
  124. _starpu_clock_gettime(&start_time);
  125. _starpu_worker_register_sleeping_start_date(workerid, &start_time);
  126. _STARPU_PTHREAD_COND_WAIT(cond, mutex);
  127. _starpu_worker_set_status(workerid, STATUS_UNKNOWN);
  128. _STARPU_TRACE_WORKER_SLEEP_END
  129. _starpu_clock_gettime(&end_time);
  130. int profiling = starpu_profiling_status_get();
  131. if (profiling)
  132. {
  133. struct timespec sleeping_time;
  134. starpu_timespec_sub(&end_time, &start_time, &sleeping_time);
  135. _starpu_worker_update_profiling_info_sleeping(workerid, &start_time, &end_time);
  136. }
  137. }