sched_ctx.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 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 __SCHED_CONTEXT_H__
  17. #define __SCHED_CONTEXT_H__
  18. #include <starpu.h>
  19. #include <starpu_scheduler.h>
  20. #include <common/config.h>
  21. #include <common/barrier_counter.h>
  22. #include <profiling/profiling.h>
  23. struct starpu_sched_ctx {
  24. /* id of the context used in user mode*/
  25. unsigned sched_ctx_id;
  26. /* name of context */
  27. const char *sched_name;
  28. /* policy of the context */
  29. struct starpu_sched_policy_s *sched_policy;
  30. /* data necessary for the policy */
  31. void *policy_data;
  32. /* list of indices of workers */
  33. int workerid[STARPU_NMAXWORKERS];
  34. /* number of threads in contex */
  35. int nworkers_in_ctx;
  36. /* temporary variable for number of threads in contex */
  37. int temp_nworkers_in_ctx;
  38. /* mutext for temp_nworkers_in_ctx*/
  39. pthread_mutex_t changing_ctx_mutex;
  40. /* we keep an initial sched which we never delete */
  41. unsigned is_initial_sched;
  42. /* wait for the tasks submitted to the context to be executed */
  43. struct _starpu_barrier_counter_t tasks_barrier;
  44. /* table of sched cond corresponding to each worker in this ctx */
  45. pthread_cond_t **sched_cond;
  46. /* table of sched mutex corresponding to each worker in this ctx */
  47. pthread_mutex_t **sched_mutex;
  48. };
  49. struct starpu_machine_config_s;
  50. struct callback_list callback_lists[STARPU_NMAXWORKERS];
  51. /* init sched_ctx_id of all contextes*/
  52. void _starpu_init_all_sched_ctx(struct starpu_machine_config_s *config);
  53. /* init the list of contextes of the worker */
  54. void _starpu_init_sched_ctx_for_worker(unsigned workerid);
  55. /* allocate all structures belonging to a context */
  56. struct starpu_sched_ctx* _starpu_create_sched_ctx(const char *policy_name, int *workerid, int nworkerids, unsigned is_init_sched, const char *sched_name);
  57. /* delete all sched_ctx */
  58. void _starpu_delete_all_sched_ctxs();
  59. /* Keeps track of the number of tasks currently submitted to a worker */
  60. void _starpu_decrement_nsubmitted_tasks_of_worker(int workerid);
  61. void _starpu_increment_nsubmitted_tasks_of_worker(int workerid);
  62. /* In order to implement starpu_wait_for_all_tasks_of_ctx, we keep track of the number of
  63. * task currently submitted to the context */
  64. void _starpu_decrement_nsubmitted_tasks_of_sched_ctx(unsigned sched_ctx_id);
  65. void _starpu_increment_nsubmitted_tasks_of_sched_ctx(unsigned sched_ctx_id);
  66. /* Return the corresponding index of the workerid in the ctx table */
  67. int _starpu_get_index_in_ctx_of_workerid(unsigned sched_ctx, unsigned workerid);
  68. /* Get the mutex corresponding to the global workerid */
  69. pthread_mutex_t *_starpu_get_sched_mutex(struct starpu_sched_ctx *sched_ctx, int worker);
  70. /* Get the cond corresponding to the global workerid */
  71. pthread_cond_t *_starpu_get_sched_cond(struct starpu_sched_ctx *sched_ctx, int worker);
  72. /* Get the total number of sched_ctxs created till now */
  73. unsigned _starpu_get_nsched_ctxs();
  74. #endif // __SCHED_CONTEXT_H__