sched_ctx_hypervisor.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. #ifndef STARPU_SCHED_CTX_HYPERVISOR_H
  17. #define STARPU_SCHED_CTX_HYPERVISOR_H
  18. #define STARPU_ARCHTYPE_DEFAULT_VALUE -1
  19. #include <starpu.h>
  20. #include <pthread.h>
  21. /* ioctl properties*/
  22. #define HYPERVISOR_MAX_IDLE -1
  23. #define HYPERVISOR_MIN_WORKING -2
  24. #define HYPERVISOR_PRIORITY -3
  25. #define HYPERVISOR_MIN_WORKERS -4
  26. #define HYPERVISOR_MAX_WORKERS -5
  27. #define HYPERVISOR_GRANULARITY -6
  28. #define HYPERVISOR_FIXED_WORKERS -7
  29. #define HYPERVISOR_MIN_TASKS -8
  30. #define HYPERVISOR_NEW_WORKERS_MAX_IDLE -9
  31. #define HYPERVISOR_TIME_TO_APPLY -10
  32. #define HYPERVISOR_EMPTY_CTX_MAX_IDLE -11
  33. #define HYPERVISOR_NULL -12
  34. pthread_mutex_t act_hypervisor_mutex;
  35. #define MAX_IDLE_TIME 5000000000
  36. #define MIN_WORKING_TIME 500
  37. struct policy_config {
  38. /* underneath this limit we cannot resize */
  39. int min_nworkers;
  40. /* above this limit we cannot resize */
  41. int max_nworkers;
  42. /*resize granularity */
  43. int granularity;
  44. /* priority for a worker to stay in this context */
  45. /* the smaller the priority the faster it will be moved */
  46. /* to another context */
  47. int priority[STARPU_NMAXWORKERS];
  48. /* above this limit the priority of the worker is reduced */
  49. double max_idle[STARPU_NMAXWORKERS];
  50. /* underneath this limit the priority of the worker is reduced */
  51. double min_working[STARPU_NMAXWORKERS];
  52. /* workers that will not move */
  53. int fixed_workers[STARPU_NMAXWORKERS];
  54. /* max idle for the workers that will be added during the resizing process*/
  55. double new_workers_max_idle;
  56. /* above this context we allow removing all workers */
  57. double empty_ctx_max_idle[STARPU_NMAXWORKERS];
  58. };
  59. struct resize_ack{
  60. int receiver_sched_ctx;
  61. int *moved_workers;
  62. int nmoved_workers;
  63. int *acked_workers;
  64. };
  65. struct sched_ctx_wrapper {
  66. unsigned sched_ctx;
  67. struct policy_config *config;
  68. double current_idle_time[STARPU_NMAXWORKERS];
  69. int worker_to_be_removed[STARPU_NMAXWORKERS];
  70. int pushed_tasks[STARPU_NMAXWORKERS];
  71. int poped_tasks[STARPU_NMAXWORKERS];
  72. double total_flops;
  73. double total_elapsed_flops[STARPU_NMAXWORKERS];
  74. double elapsed_flops[STARPU_NMAXWORKERS];
  75. double submitted_flops;
  76. double remaining_flops;
  77. double start_time;
  78. struct resize_ack resize_ack;
  79. pthread_mutex_t mutex;
  80. };
  81. /* Forward declaration of an internal data structure
  82. * FIXME: Remove when no longer exposed. */
  83. struct resize_request_entry;
  84. struct hypervisor_policy {
  85. const char* name;
  86. unsigned custom;
  87. void (*size_ctxs)(int *sched_ctxs, int nsched_ctxs , int *workers, int nworkers);
  88. void (*handle_idle_cycle)(unsigned sched_ctx, int worker);
  89. void (*handle_pushed_task)(unsigned sched_ctx, int worker);
  90. void (*handle_poped_task)(unsigned sched_ctx, int worker);
  91. void (*handle_idle_end)(unsigned sched_ctx, int worker);
  92. void (*handle_post_exec_hook)(unsigned sched_ctx, int task_tag);
  93. void (*handle_submitted_job)(struct starpu_task *task, unsigned footprint);
  94. };
  95. struct starpu_performance_counters* sched_ctx_hypervisor_init(struct hypervisor_policy* policy);
  96. void sched_ctx_hypervisor_shutdown(void);
  97. void sched_ctx_hypervisor_register_ctx(unsigned sched_ctx, double total_flops);
  98. void sched_ctx_hypervisor_unregister_ctx(unsigned sched_ctx);
  99. void sched_ctx_hypervisor_resize(unsigned sched_ctx, int task_tag);
  100. void sched_ctx_hypervisor_move_workers(unsigned sender_sched_ctx, unsigned receier_sched_ctx, int *workers_to_move, unsigned nworkers_to_move, unsigned now);
  101. void sched_ctx_hypervisor_stop_resize(unsigned sched_ctx);
  102. void sched_ctx_hypervisor_start_resize(unsigned sched_ctx);
  103. void sched_ctx_hypervisor_ioctl(unsigned sched_ctx, ...);
  104. void sched_ctx_hypervisor_set_config(unsigned sched_ctx, void *config);
  105. struct policy_config* sched_ctx_hypervisor_get_config(unsigned sched_ctx);
  106. int* sched_ctx_hypervisor_get_sched_ctxs();
  107. int sched_ctx_hypervisor_get_nsched_ctxs();
  108. int get_nworkers_ctx(unsigned sched_ctx, enum starpu_archtype arch);
  109. struct sched_ctx_wrapper* sched_ctx_hypervisor_get_wrapper(unsigned sched_ctx);
  110. double sched_ctx_hypervisor_get_elapsed_flops_per_sched_ctx(struct sched_ctx_wrapper* sc_w);
  111. double sched_ctx_hypervisor_get_total_elapsed_flops_per_sched_ctx(struct sched_ctx_wrapper* sc_w);
  112. const char* sched_ctx_hypervisor_get_policy();
  113. void sched_ctx_hypervisor_add_workers_to_sched_ctx(int* workers_to_add, unsigned nworkers_to_add, unsigned sched_ctx);
  114. void sched_ctx_hypervisor_remove_workers_from_sched_ctx(int* workers_to_remove, unsigned nworkers_to_remove, unsigned sched_ctx, unsigned now);
  115. void sched_ctx_hypervisor_size_ctxs(int *sched_ctxs, int nsched_ctxs, int *workers, int nworkers);
  116. unsigned sched_ctx_hypervisor_get_size_req(int **sched_ctxs, int* nsched_ctxs, int **workers, int *nworkers);
  117. void sched_ctx_hypervisor_save_size_req(int *sched_ctxs, int nsched_ctxs, int *workers, int nworkers);
  118. void sched_ctx_hypervisor_free_size_req(void);
  119. unsigned sched_ctx_hypervisor_can_resize(unsigned sched_ctx);
  120. #endif