driver_common.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (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. #include <math.h>
  17. #include <starpu.h>
  18. #include <starpu_profiling.h>
  19. #include <profiling/profiling.h>
  20. #include <common/utils.h>
  21. #include <core/debug.h>
  22. #include <drivers/driver_common/driver_common.h>
  23. void _starpu_driver_update_job_feedback(starpu_job_t j, struct starpu_worker_s *worker_args,
  24. struct starpu_task_profiling_info *profiling_info,
  25. unsigned calibrate_model, enum starpu_perf_archtype perf_arch,
  26. struct timespec *codelet_start, struct timespec *codelet_end)
  27. {
  28. struct timespec measured_ts;
  29. double measured;
  30. if (profiling_info || calibrate_model)
  31. {
  32. starpu_timespec_sub(codelet_end, codelet_start, &measured_ts);
  33. measured = starpu_timing_timespec_to_us(&measured_ts);
  34. if (profiling_info)
  35. {
  36. memcpy(&profiling_info->start_time, codelet_start, sizeof(struct timespec));
  37. memcpy(&profiling_info->end_time, codelet_end, sizeof(struct timespec));
  38. int workerid = worker_args->workerid;
  39. profiling_info->workerid = workerid;
  40. _starpu_worker_update_profiling_info_executing(workerid, &measured_ts, 1);
  41. }
  42. if (calibrate_model)
  43. _starpu_update_perfmodel_history(j, perf_arch, worker_args->devid, measured);
  44. }
  45. }
  46. /* Workers may block when there is no work to do at all. We assume that the
  47. * mutex is hold when that function is called. */
  48. void _starpu_block_worker(int workerid, pthread_cond_t *cond, pthread_mutex_t *mutex)
  49. {
  50. struct timespec start_time, end_time;
  51. STARPU_TRACE_WORKER_SLEEP_START
  52. _starpu_worker_set_status(workerid, STATUS_SLEEPING);
  53. starpu_clock_gettime(&start_time);
  54. _starpu_worker_register_sleeping_start_date(workerid, &start_time);
  55. PTHREAD_COND_WAIT(cond, mutex);
  56. _starpu_worker_set_status(workerid, STATUS_UNKNOWN);
  57. STARPU_TRACE_WORKER_SLEEP_END
  58. starpu_clock_gettime(&end_time);
  59. int profiling = starpu_profiling_status_get();
  60. if (profiling)
  61. {
  62. struct timespec sleeping_time;
  63. starpu_timespec_sub(&end_time, &start_time, &sleeping_time);
  64. _starpu_worker_update_profiling_info_sleeping(workerid, &start_time, &end_time);
  65. }
  66. }