hard_coded_policy.c 4.0 KB

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