hard_coded_policy.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 "sc_hypervisor_policy.h"
  17. #include "sc_hypervisor_lp.h"
  18. #include "sc_hypervisor_policy.h"
  19. unsigned hard_coded_worker_belong_to_other_sched_ctx(unsigned sched_ctx, int worker)
  20. {
  21. unsigned *sched_ctxs = sc_hypervisor_get_sched_ctxs();
  22. int nsched_ctxs = sc_hypervisor_get_nsched_ctxs();
  23. int i;
  24. for(i = 0; i < nsched_ctxs; i++)
  25. if(sched_ctxs[i] != sched_ctx && starpu_sched_ctx_contains_worker(worker, sched_ctxs[i]))
  26. return 1;
  27. return 0;
  28. }
  29. void hard_coded_handle_idle_cycle(unsigned sched_ctx, int worker)
  30. {
  31. unsigned criteria = sc_hypervisor_get_resize_criteria();
  32. if(criteria != SC_NOTHING)// && criteria == SC_SPEED)
  33. {
  34. int ret = starpu_pthread_mutex_trylock(&act_hypervisor_mutex);
  35. if(ret != EBUSY)
  36. {
  37. // if(sc_hypervisor_criteria_fulfilled(sched_ctx, worker))
  38. // if(sc_hypervisor_check_speed_gap_btw_ctxs(NULL, -1, NULL, -1))
  39. if(sc_hypervisor_check_idle(sched_ctx, worker))
  40. {
  41. if(hard_coded_worker_belong_to_other_sched_ctx(sched_ctx, worker))
  42. sc_hypervisor_remove_workers_from_sched_ctx(&worker, 1, sched_ctx, 1);
  43. else
  44. {
  45. // sc_hypervisor_policy_resize_to_unknown_receiver(sched_ctx, 0);
  46. unsigned *sched_ctxs = sc_hypervisor_get_sched_ctxs();
  47. int ns = sc_hypervisor_get_nsched_ctxs();
  48. int nworkers = (int)starpu_worker_get_count();
  49. struct types_of_workers *tw = sc_hypervisor_get_types_of_workers(NULL, nworkers);
  50. int nw = tw->nw;
  51. double w_in_s[ns][nw];
  52. w_in_s[0][0] = 1;
  53. w_in_s[0][1] = 3;
  54. w_in_s[1][0] = 8;
  55. w_in_s[1][1] = 0;
  56. // sc_hypervisor_lp_place_resources_in_ctx(ns, nw, w_in_s, sched_ctxs, NULL, 1, tw);
  57. sc_hypervisor_lp_distribute_floating_no_resources_in_ctxs(sched_ctxs, ns, tw->nw, w_in_s, NULL, nworkers, tw);
  58. free(tw);
  59. }
  60. }
  61. STARPU_PTHREAD_MUTEX_UNLOCK(&act_hypervisor_mutex);
  62. }
  63. }
  64. }
  65. static void hard_coded_handle_poped_task(unsigned sched_ctx, __attribute__((unused))int worker, struct starpu_task *task, uint32_t footprint)
  66. {
  67. unsigned criteria = sc_hypervisor_get_resize_criteria();
  68. if(criteria != SC_NOTHING && criteria == SC_SPEED)
  69. {
  70. int ret = starpu_pthread_mutex_trylock(&act_hypervisor_mutex);
  71. if(ret != EBUSY)
  72. {
  73. if(sc_hypervisor_criteria_fulfilled(sched_ctx, worker))
  74. {
  75. // sc_hypervisor_policy_resize_to_unknown_receiver(sched_ctx, 0);
  76. unsigned *sched_ctxs = sc_hypervisor_get_sched_ctxs();
  77. int ns = sc_hypervisor_get_nsched_ctxs();
  78. int nworkers = (int)starpu_worker_get_count();
  79. struct types_of_workers *tw = sc_hypervisor_get_types_of_workers(NULL, nworkers);
  80. int nw = tw->nw;
  81. double w_in_s[ns][nw];
  82. w_in_s[0][0] = 1;
  83. w_in_s[0][1] = 3;
  84. w_in_s[1][0] = 8;
  85. w_in_s[1][1] = 0;
  86. // sc_hypervisor_lp_place_resources_in_ctx(ns, nw, w_in_s, sched_ctxs, NULL, 1, tw);
  87. sc_hypervisor_lp_distribute_floating_no_resources_in_ctxs(sched_ctxs, ns, tw->nw, w_in_s, NULL, nworkers, tw);
  88. free(tw);
  89. }
  90. STARPU_PTHREAD_MUTEX_UNLOCK(&act_hypervisor_mutex);
  91. }
  92. }
  93. }
  94. struct sc_hypervisor_policy hard_coded_policy =
  95. {
  96. .size_ctxs = NULL,
  97. .handle_poped_task = hard_coded_handle_poped_task,
  98. .handle_pushed_task = NULL,
  99. .handle_idle_cycle = hard_coded_handle_idle_cycle,
  100. .handle_idle_end = NULL,
  101. .handle_post_exec_hook = NULL,
  102. .handle_submitted_job = NULL,
  103. .end_ctx = NULL,
  104. .init_worker = NULL,
  105. .custom = 0,
  106. .name = "hard_coded"
  107. };