perf_knobs_03.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2019 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 <starpu.h>
  17. #include <assert.h>
  18. #include <string.h>
  19. #define NTASKS 100
  20. volatile int task_count[2];
  21. void cpu_func(void *buffer[], void *cl_arg)
  22. {
  23. (void)buffer;
  24. (void)cl_arg;
  25. int workerid = starpu_worker_get_id();
  26. STARPU_ASSERT(workerid == 0 || workerid == 1);
  27. task_count[workerid]++;
  28. }
  29. int main(int argc, char **argv)
  30. {
  31. int ret;
  32. struct starpu_conf conf;
  33. starpu_conf_init(&conf);
  34. conf.ncpus = 2;
  35. conf.sched_policy_name = "prio";
  36. ret = starpu_initialize(&conf, &argc, &argv);
  37. if (ret == -ENODEV)
  38. return 77;
  39. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  40. unsigned int ncpu = starpu_cpu_worker_get_count();
  41. if (ncpu < 2)
  42. {
  43. fprintf(stderr, "example needs two cpu cores.\n");
  44. return 77;
  45. }
  46. STARPU_ASSERT(ncpu == 2);
  47. {
  48. const char * const max_prio_knob_name = "starpu.task.s_max_priority_cap_knob";
  49. const char * const min_prio_knob_name = "starpu.task.s_min_priority_cap_knob";
  50. const char * const knob_scope_name = "per_scheduler";
  51. const char * const knob_type_name = "int32";
  52. int32_t max_prio_val;
  53. int32_t min_prio_val;
  54. const int scope_id = starpu_perf_knob_scope_name_to_id(knob_scope_name);
  55. const int max_prio_id = starpu_perf_knob_name_to_id(scope_id, max_prio_knob_name);
  56. STARPU_ASSERT(starpu_perf_knob_get_type_id(max_prio_id) == starpu_perf_knob_type_name_to_id(knob_type_name));
  57. const int min_prio_id = starpu_perf_knob_name_to_id(scope_id, min_prio_knob_name);
  58. STARPU_ASSERT(starpu_perf_knob_get_type_id(min_prio_id) == starpu_perf_knob_type_name_to_id(knob_type_name));
  59. printf("%s:\n", max_prio_knob_name);
  60. max_prio_val = starpu_perf_knob_get_per_scheduler_int32_value(max_prio_id, "prio");
  61. printf("- %d\n", max_prio_val);
  62. printf("%s:\n", min_prio_knob_name);
  63. min_prio_val = starpu_perf_knob_get_per_scheduler_int32_value(min_prio_id, "prio");
  64. printf("- %d\n", min_prio_val);
  65. STARPU_ASSERT (max_prio_val >= min_prio_val);
  66. if (min_prio_val > 0)
  67. {
  68. starpu_perf_knob_set_per_scheduler_int32_value(min_prio_id, "prio", 0);
  69. starpu_perf_knob_set_per_scheduler_int32_value(max_prio_id, "prio", 0);
  70. }
  71. else
  72. {
  73. starpu_perf_knob_set_per_scheduler_int32_value(max_prio_id, "prio", 0);
  74. starpu_perf_knob_set_per_scheduler_int32_value(min_prio_id, "prio", 0);
  75. }
  76. printf("%s:\n", max_prio_knob_name);
  77. max_prio_val = starpu_perf_knob_get_per_scheduler_int32_value(max_prio_id, "prio");
  78. printf("- %d\n", max_prio_val);
  79. printf("%s:\n", min_prio_knob_name);
  80. min_prio_val = starpu_perf_knob_get_per_scheduler_int32_value(min_prio_id, "prio");
  81. printf("- %d\n", min_prio_val);
  82. STARPU_ASSERT (max_prio_val == 0);
  83. STARPU_ASSERT (min_prio_val == 0);
  84. }
  85. {
  86. const char * const knob_name = "starpu.worker.w_enable_worker_knob";
  87. const char * const knob_scope_name = "per_worker";
  88. const char * const knob_type_name = "int32";
  89. int32_t val;
  90. const int scope_id = starpu_perf_knob_scope_name_to_id(knob_scope_name);
  91. const int id = starpu_perf_knob_name_to_id(scope_id, knob_name);
  92. STARPU_ASSERT(starpu_perf_knob_get_type_id(id) == starpu_perf_knob_type_name_to_id(knob_type_name));
  93. struct starpu_codelet cl = {
  94. .cpu_func = cpu_func
  95. };
  96. task_count[0] = 0;
  97. task_count[1] = 0;
  98. val = starpu_perf_knob_get_per_worker_int32_value(id, 0);
  99. STARPU_ASSERT(val == 1);
  100. val = starpu_perf_knob_get_per_worker_int32_value(id, 1);
  101. STARPU_ASSERT(val == 1);
  102. starpu_perf_knob_set_per_worker_int32_value(id, 1, 0);
  103. val = starpu_perf_knob_get_per_worker_int32_value(id, 1);
  104. STARPU_ASSERT(val == 0);
  105. int i;
  106. for (i=0; i<NTASKS; i++)
  107. {
  108. starpu_task_insert(&cl, 0);
  109. }
  110. starpu_task_wait_for_all();
  111. STARPU_ASSERT(task_count[0] == NTASKS);
  112. STARPU_ASSERT(task_count[1] == 0);
  113. task_count[0] = 0;
  114. starpu_perf_knob_set_per_worker_int32_value(id, 1, 1);
  115. val = starpu_perf_knob_get_per_worker_int32_value(id, 1);
  116. STARPU_ASSERT(val == 1);
  117. starpu_perf_knob_set_per_worker_int32_value(id, 0, 0);
  118. val = starpu_perf_knob_get_per_worker_int32_value(id, 0);
  119. STARPU_ASSERT(val == 0);
  120. for (i=0; i<NTASKS; i++)
  121. {
  122. starpu_task_insert(&cl, 0);
  123. }
  124. starpu_task_wait_for_all();
  125. STARPU_ASSERT(task_count[0] == 0);
  126. STARPU_ASSERT(task_count[1] == NTASKS);
  127. starpu_perf_knob_set_per_worker_int32_value(id, 0, 1);
  128. val = starpu_perf_knob_get_per_worker_int32_value(id, 0);
  129. STARPU_ASSERT(val == 1);
  130. }
  131. starpu_shutdown();
  132. return 0;
  133. }