driver_common.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2011 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. #include <math.h>
  18. #include <starpu.h>
  19. #include <starpu_profiling.h>
  20. #include <profiling/profiling.h>
  21. #include <common/utils.h>
  22. #include <core/debug.h>
  23. #include <drivers/driver_common/driver_common.h>
  24. void _starpu_driver_update_job_feedback(starpu_job_t j, struct starpu_worker_s *worker_args,
  25. struct starpu_task_profiling_info *profiling_info,
  26. enum starpu_perf_archtype perf_arch,
  27. struct timespec *codelet_start, struct timespec *codelet_end)
  28. {
  29. struct timespec measured_ts;
  30. double measured;
  31. int workerid = worker_args->workerid;
  32. struct starpu_codelet_t *cl = j->task->cl;
  33. int calibrate_model = 0;
  34. int profiling = starpu_profiling_status_get();
  35. int updated = 0;
  36. if (cl->model && cl->model->benchmarking)
  37. calibrate_model = 1;
  38. if (profiling_info || calibrate_model)
  39. {
  40. starpu_timespec_sub(codelet_end, codelet_start, &measured_ts);
  41. measured = starpu_timing_timespec_to_us(&measured_ts);
  42. if (profiling && profiling_info)
  43. {
  44. memcpy(&profiling_info->start_time, codelet_start, sizeof(struct timespec));
  45. memcpy(&profiling_info->end_time, codelet_end, sizeof(struct timespec));
  46. profiling_info->workerid = workerid;
  47. _starpu_worker_update_profiling_info_executing(workerid, &measured_ts, 1,
  48. profiling_info->used_cycles,
  49. profiling_info->stall_cycles,
  50. profiling_info->power_consumed);
  51. updated = 1;
  52. }
  53. if (calibrate_model)
  54. _starpu_update_perfmodel_history(j, j->task->cl->model, perf_arch, worker_args->devid, measured);
  55. }
  56. if (!updated)
  57. _starpu_worker_update_profiling_info_executing(workerid, NULL, 1, 0, 0, 0);
  58. if (profiling_info && profiling_info->power_consumed && cl->power_model && cl->power_model->benchmarking) {
  59. _starpu_update_perfmodel_history(j, j->task->cl->power_model, perf_arch, worker_args->devid, profiling_info->power_consumed);
  60. }
  61. }
  62. /* Workers may block when there is no work to do at all. We assume that the
  63. * mutex is hold when that function is called. */
  64. void _starpu_block_worker(int workerid, pthread_cond_t *cond, pthread_mutex_t *mutex)
  65. {
  66. struct timespec start_time, end_time;
  67. STARPU_TRACE_WORKER_SLEEP_START
  68. _starpu_worker_set_status(workerid, STATUS_SLEEPING);
  69. starpu_clock_gettime(&start_time);
  70. _starpu_worker_register_sleeping_start_date(workerid, &start_time);
  71. PTHREAD_COND_WAIT(cond, mutex);
  72. _starpu_worker_set_status(workerid, STATUS_UNKNOWN);
  73. STARPU_TRACE_WORKER_SLEEP_END
  74. starpu_clock_gettime(&end_time);
  75. int profiling = starpu_profiling_status_get();
  76. if (profiling)
  77. {
  78. struct timespec sleeping_time;
  79. starpu_timespec_sub(&end_time, &start_time, &sleeping_time);
  80. _starpu_worker_update_profiling_info_sleeping(workerid, &start_time, &end_time);
  81. }
  82. }