lp_policy.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2012 INRIA
  4. *
  5. * StarPU 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. * StarPU 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 "lp_tools.h"
  17. #include <starpu_config.h>
  18. static void lp_handle_poped_task(unsigned sched_ctx, int worker)
  19. {
  20. if(_velocity_gap_btw_ctxs())
  21. {
  22. int nsched_ctxs = sched_ctx_hypervisor_get_nsched_ctxs();
  23. double nworkers[nsched_ctxs][2];
  24. int ret = pthread_mutex_trylock(&act_hypervisor_mutex);
  25. if(ret != EBUSY)
  26. {
  27. int total_nw[2];
  28. _get_total_nw(NULL, -1, 2, total_nw);
  29. struct timeval start_time;
  30. struct timeval end_time;
  31. gettimeofday(&start_time, NULL);
  32. double vmax = _lp_get_nworkers_per_ctx(nsched_ctxs, 2, nworkers, total_nw);
  33. gettimeofday(&end_time, NULL);
  34. long diff_s = end_time.tv_sec - start_time.tv_sec;
  35. long diff_us = end_time.tv_usec - start_time.tv_usec;
  36. float timing = (float)(diff_s*1000000 + diff_us)/1000;
  37. if(vmax != 0.0)
  38. {
  39. int nworkers_rounded[nsched_ctxs][2];
  40. _lp_round_double_to_int(nsched_ctxs, 2, nworkers, nworkers_rounded);
  41. _lp_redistribute_resources_in_ctxs(nsched_ctxs, 2, nworkers_rounded, nworkers);
  42. }
  43. pthread_mutex_unlock(&act_hypervisor_mutex);
  44. }
  45. }
  46. }
  47. static void lp_size_ctxs(int *sched_ctxs, int ns, int *workers, int nworkers)
  48. {
  49. int nsched_ctxs = sched_ctxs == NULL ? sched_ctx_hypervisor_get_nsched_ctxs() : ns;
  50. double nworkers_per_type[nsched_ctxs][2];
  51. int total_nw[2];
  52. _get_total_nw(workers, nworkers, 2, total_nw);
  53. pthread_mutex_lock(&act_hypervisor_mutex);
  54. double vmax = _lp_get_nworkers_per_ctx(nsched_ctxs, 2, nworkers_per_type, total_nw);
  55. if(vmax != 0.0)
  56. {
  57. printf("********size\n");
  58. /* for( i = 0; i < nsched_ctxs; i++) */
  59. /* { */
  60. /* printf("ctx %d/worker type %d: n = %lf \n", i, 0, res[i][0]); */
  61. /* printf("ctx %d/worker type %d: n = %lf \n", i, 1, res[i][1]); */
  62. /* } */
  63. int nworkers_per_type_rounded[nsched_ctxs][2];
  64. _lp_round_double_to_int(nsched_ctxs, 2, nworkers_per_type, nworkers_per_type_rounded);
  65. /* for( i = 0; i < nsched_ctxs; i++) */
  66. /* { */
  67. /* printf("ctx %d/worker type %d: n = %d \n", i, 0, res_rounded[i][0]); */
  68. /* printf("ctx %d/worker type %d: n = %d \n", i, 1, res_rounded[i][1]); */
  69. /* } */
  70. _lp_distribute_resources_in_ctxs(sched_ctxs, nsched_ctxs, 2, nworkers_per_type_rounded, nworkers_per_type, workers, nworkers);
  71. }
  72. pthread_mutex_unlock(&act_hypervisor_mutex);
  73. }
  74. #ifdef STARPU_HAVE_GLPK_H
  75. struct hypervisor_policy lp_policy = {
  76. .size_ctxs = lp_size_ctxs,
  77. .handle_poped_task = lp_handle_poped_task,
  78. .handle_pushed_task = NULL,
  79. .handle_idle_cycle = NULL,
  80. .handle_idle_end = NULL,
  81. .handle_post_exec_hook = NULL,
  82. .handle_submitted_job = NULL,
  83. .custom = 0,
  84. .name = "lp"
  85. };
  86. #endif /* STARPU_HAVE_GLPK_H */