lp_policy.c 3.7 KB

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