task_pool.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2013 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. void sc_hypervisor_policy_add_task_to_pool(struct starpu_codelet *cl, unsigned sched_ctx, uint32_t footprint, struct sc_hypervisor_policy_task_pool **task_pools, size_t data_size)
  18. {
  19. struct sc_hypervisor_policy_task_pool *tp = NULL;
  20. for (tp = *task_pools; tp; tp = tp->next)
  21. {
  22. if (tp && tp->cl == cl && tp->footprint == footprint && tp->sched_ctx_id == sched_ctx)
  23. break;
  24. }
  25. if (!tp)
  26. {
  27. tp = (struct sc_hypervisor_policy_task_pool *) malloc(sizeof(struct sc_hypervisor_policy_task_pool));
  28. tp->cl = cl;
  29. tp->footprint = footprint;
  30. tp->sched_ctx_id = sched_ctx;
  31. tp->n = 0;
  32. tp->next = *task_pools;
  33. tp->data_size = data_size;
  34. *task_pools = tp;
  35. }
  36. /* One more task of this kind */
  37. tp->n++;
  38. }
  39. void sc_hypervisor_policy_remove_task_from_pool(struct starpu_task *task, uint32_t footprint, struct sc_hypervisor_policy_task_pool **task_pools)
  40. {
  41. /* count the tasks of the same type */
  42. struct sc_hypervisor_policy_task_pool *tp = NULL;
  43. for (tp = *task_pools; tp; tp = tp->next)
  44. {
  45. if (tp && tp->cl == task->cl && tp->footprint == footprint && tp->sched_ctx_id == task->sched_ctx)
  46. break;
  47. }
  48. if (tp)
  49. {
  50. if(tp->n > 1)
  51. tp->n--;
  52. else
  53. {
  54. if(tp == *task_pools)
  55. {
  56. struct sc_hypervisor_policy_task_pool *next_tp = NULL;
  57. if((*task_pools)->next)
  58. next_tp = (*task_pools)->next;
  59. free(tp);
  60. tp = NULL;
  61. if(next_tp)
  62. *task_pools = next_tp;
  63. }
  64. else
  65. {
  66. struct sc_hypervisor_policy_task_pool *prev_tp = NULL;
  67. for (prev_tp = *task_pools; prev_tp; prev_tp = prev_tp->next)
  68. {
  69. if (prev_tp->next == tp)
  70. prev_tp->next = tp->next;
  71. }
  72. free(tp);
  73. tp = NULL;
  74. }
  75. }
  76. }
  77. }
  78. struct sc_hypervisor_policy_task_pool* sc_hypervisor_policy_clone_task_pool(struct sc_hypervisor_policy_task_pool *tp)
  79. {
  80. if(tp == NULL) return NULL;
  81. struct sc_hypervisor_policy_task_pool *tmp_tp = (struct sc_hypervisor_policy_task_pool*)malloc(sizeof(struct sc_hypervisor_policy_task_pool));
  82. memcpy(tmp_tp, tp, sizeof(struct sc_hypervisor_policy_task_pool));
  83. tmp_tp->next = sc_hypervisor_policy_clone_task_pool(tp->next);
  84. return tmp_tp;
  85. }