idle_policy.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. unsigned worker_belong_to_other_sched_ctx(unsigned sched_ctx, int worker)
  18. {
  19. int *sched_ctxs = sc_hypervisor_get_sched_ctxs();
  20. int nsched_ctxs = sc_hypervisor_get_nsched_ctxs();
  21. int i;
  22. for(i = 0; i < nsched_ctxs; i++)
  23. if(sched_ctxs[i] != sched_ctx && starpu_sched_ctx_contains_worker(worker, sched_ctxs[i]))
  24. return 1;
  25. return 0;
  26. }
  27. void idle_handle_idle_cycle(unsigned sched_ctx, int worker)
  28. {
  29. struct sc_hypervisor_wrapper* sc_w = sc_hypervisor_get_wrapper(sched_ctx);
  30. struct sc_hypervisor_policy_config *config = sc_w->config;
  31. if(config != NULL && sc_w->current_idle_time[worker] > config->max_idle[worker])
  32. {
  33. if(worker_belong_to_other_sched_ctx(sched_ctx, worker))
  34. sc_hypervisor_remove_workers_from_sched_ctx(&worker, 1, sched_ctx, 1);
  35. else
  36. sc_hypervisor_policy_resize_to_unknown_receiver(sched_ctx, 0);
  37. }
  38. }
  39. struct sc_hypervisor_policy idle_policy =
  40. {
  41. .size_ctxs = NULL,
  42. .handle_poped_task = NULL,
  43. .handle_pushed_task = NULL,
  44. .handle_idle_cycle = idle_handle_idle_cycle,
  45. .handle_idle_end = NULL,
  46. .handle_post_exec_hook = NULL,
  47. .handle_submitted_job = NULL,
  48. .end_ctx = NULL,
  49. .custom = 0,
  50. .name = "idle"
  51. };