sc_hypervisor_intern.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2013 Inria
  4. * Copyright (C) 2012-2013,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.h>
  18. #include "uthash.h"
  19. #define SC_SPEED_MAX_GAP_DEFAULT 50
  20. #define SC_HYPERVISOR_DEFAULT_CPU_SPEED 5.0
  21. #define SC_HYPERVISOR_DEFAULT_CUDA_SPEED 100.0
  22. struct size_request
  23. {
  24. int *workers;
  25. int nworkers;
  26. unsigned *sched_ctxs;
  27. int nsched_ctxs;
  28. };
  29. /* Entry in the resize request hash table. */
  30. struct resize_request_entry
  31. {
  32. /* Key: the tag of tasks concerned by this resize request. */
  33. uint32_t task_tag;
  34. /* Value: identifier of the scheduling context needing to be resized.
  35. * The value doesn't matter since the hash table is used only to test
  36. * membership of a task tag. */
  37. unsigned sched_ctx;
  38. /* Bookkeeping. */
  39. UT_hash_handle hh;
  40. };
  41. /* structure to indicate when the moving of workers was actually done
  42. (moved workers can be seen in the new ctx ) */
  43. struct resize_ack
  44. {
  45. /* receiver context */
  46. int receiver_sched_ctx;
  47. /* list of workers required to be moved */
  48. int *moved_workers;
  49. /* number of workers required to be moved */
  50. int nmoved_workers;
  51. /* list of workers that actually got in the receiver ctx */
  52. int *acked_workers;
  53. };
  54. struct configuration_entry
  55. {
  56. /* Key: the tag of tasks concerned by this configuration. */
  57. uint32_t task_tag;
  58. /* Value: configuration of the scheduling context. */
  59. struct sc_hypervisor_policy_config *configuration;
  60. /* Bookkeeping. */
  61. UT_hash_handle hh;
  62. };
  63. struct sc_hypervisor
  64. {
  65. struct sc_hypervisor_wrapper sched_ctx_w[STARPU_NMAX_SCHED_CTXS];
  66. unsigned sched_ctxs[STARPU_NMAX_SCHED_CTXS];
  67. unsigned nsched_ctxs;
  68. unsigned resize[STARPU_NMAX_SCHED_CTXS];
  69. unsigned allow_remove[STARPU_NMAX_SCHED_CTXS];
  70. int min_tasks;
  71. struct sc_hypervisor_policy policy;
  72. struct configuration_entry *configurations[STARPU_NMAX_SCHED_CTXS];
  73. /* Set of pending resize requests for any context/tag pair. */
  74. struct resize_request_entry *resize_requests[STARPU_NMAX_SCHED_CTXS];
  75. starpu_pthread_mutex_t conf_mut[STARPU_NMAX_SCHED_CTXS];
  76. starpu_pthread_mutex_t resize_mut[STARPU_NMAX_SCHED_CTXS];
  77. struct size_request *sr;
  78. int check_min_tasks[STARPU_NMAX_SCHED_CTXS];
  79. /* time when the hypervisor started */
  80. double start_executing_time;
  81. /* max speed diff btw ctx before triggering resizing */
  82. double max_speed_gap;
  83. /* criteria to trigger resizing */
  84. unsigned resize_criteria;
  85. /* value of the speed to compare the speed of the context to */
  86. double optimal_v[STARPU_NMAX_SCHED_CTXS];
  87. };
  88. struct sc_hypervisor_adjustment
  89. {
  90. int workerids[STARPU_NMAXWORKERS];
  91. int nworkers;
  92. };
  93. struct sc_hypervisor hypervisor;
  94. void _add_config(unsigned sched_ctx);
  95. void _remove_config(unsigned sched_ctx);
  96. double _get_max_speed_gap();
  97. double _get_optimal_v(unsigned sched_ctx);
  98. void _set_optimal_v(unsigned sched_ctx, double optimal_v);
  99. int _sc_hypervisor_use_lazy_resize(void);
  100. void _sc_hypervisor_allow_compute_idle(unsigned sched_ctx, int worker, unsigned allow);