sc_hypervisor_intern.h 3.4 KB

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