370_online_performance_tools.doxy 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), 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. /*! \page OnlinePerformanceTools Online Performance Tools
  17. \section On-linePerformanceFeedback On-line Performance Feedback
  18. \subsection EnablingOn-linePerformanceMonitoring Enabling On-line Performance Monitoring
  19. In order to enable online performance monitoring, the application can
  20. call starpu_profiling_status_set() with the parameter
  21. ::STARPU_PROFILING_ENABLE. It is possible to detect whether monitoring
  22. is already enabled or not by calling starpu_profiling_status_get().
  23. Enabling monitoring also reinitialize all previously collected
  24. feedback. The environment variable \ref STARPU_PROFILING can also be
  25. set to <c>1</c> to achieve the same effect. The function
  26. starpu_profiling_init() can also be called during the execution to
  27. reinitialize performance counters and to start the profiling if the
  28. environment variable \ref STARPU_PROFILING is set to <c>1</c>.
  29. Likewise, performance monitoring is stopped by calling
  30. starpu_profiling_status_set() with the parameter
  31. ::STARPU_PROFILING_DISABLE. Note that this does not reset the
  32. performance counters so that the application may consult them later
  33. on.
  34. More details about the performance monitoring API are available in \ref API_Profiling.
  35. \subsection Per-taskFeedback Per-task Feedback
  36. If profiling is enabled, a pointer to a structure
  37. starpu_profiling_task_info is put in the field
  38. starpu_task::profiling_info when a task terminates. This structure is
  39. automatically destroyed when the task structure is destroyed, either
  40. automatically or by calling starpu_task_destroy().
  41. The structure starpu_profiling_task_info indicates the date when the
  42. task was submitted (starpu_profiling_task_info::submit_time), started
  43. (starpu_profiling_task_info::start_time), and terminated
  44. (starpu_profiling_task_info::end_time), relative to the initialization
  45. of StarPU with starpu_init(). It also specifies the identifier of the worker
  46. that has executed the task (starpu_profiling_task_info::workerid).
  47. These date are stored as <c>timespec</c> structures which the user may convert
  48. into micro-seconds using the helper function
  49. starpu_timing_timespec_to_us().
  50. It it worth noting that the application may directly access this structure from
  51. the callback executed at the end of the task. The structure starpu_task
  52. associated to the callback currently being executed is indeed accessible with
  53. the function starpu_task_get_current().
  54. \subsection Per-codeletFeedback Per-codelet Feedback
  55. The field starpu_codelet::per_worker_stats is
  56. an array of counters. The <c>i</c>-th entry of the array is incremented every time a
  57. task implementing the codelet is executed on the <c>i</c>-th worker.
  58. This array is not reinitialized when profiling is enabled or disabled.
  59. \subsection Per-workerFeedback Per-worker Feedback
  60. The second argument returned by the function
  61. starpu_profiling_worker_get_info() is a structure
  62. starpu_profiling_worker_info that gives statistics about the specified
  63. worker. This structure specifies when StarPU started collecting
  64. profiling information for that worker
  65. (starpu_profiling_worker_info::start_time), the
  66. duration of the profiling measurement interval
  67. (starpu_profiling_worker_info::total_time), the time spent executing
  68. kernels (starpu_profiling_worker_info::executing_time), the time
  69. spent sleeping because there is no task to execute at all
  70. (starpu_profiling_worker_info::sleeping_time), and the number of tasks that were executed
  71. while profiling was enabled. These values give an estimation of the
  72. proportion of time spent do real work, and the time spent either
  73. sleeping because there are not enough executable tasks or simply
  74. wasted in pure StarPU overhead.
  75. Calling starpu_profiling_worker_get_info() resets the profiling
  76. information associated to a worker.
  77. To easily display all this information, the environment variable
  78. \ref STARPU_WORKER_STATS can be set to <c>1</c> (in addition to setting
  79. \ref STARPU_PROFILING to 1). A summary will then be displayed at
  80. program termination. To display the summary in a file instead of the
  81. standard error stream, use the environment variable \ref STARPU_WORKER_STATS_FILE.
  82. \verbatim
  83. Worker stats:
  84. CUDA 0.0 (4.7 GiB)
  85. 480 task(s)
  86. total: 1574.82 ms executing: 1510.72 ms sleeping: 0.00 ms overhead 64.10 ms
  87. 325.217970 GFlop/s
  88. CPU 0
  89. 22 task(s)
  90. total: 1574.82 ms executing: 1364.81 ms sleeping: 0.00 ms overhead 210.01 ms
  91. 7.512057 GFlop/s
  92. CPU 1
  93. 14 task(s)
  94. total: 1574.82 ms executing: 1500.13 ms sleeping: 0.00 ms overhead 74.69 ms
  95. 6.675853 GFlop/s
  96. CPU 2
  97. 14 task(s)
  98. total: 1574.82 ms executing: 1553.12 ms sleeping: 0.00 ms overhead 21.70 ms
  99. 7.152886 GFlop/s
  100. \endverbatim
  101. The number of GFlops is available because the starpu_task::flops field of the
  102. tasks were filled (or \ref STARPU_FLOPS used in starpu_task_insert()).
  103. When an FxT trace is generated (see \ref GeneratingTracesWithFxT), it is also
  104. possible to use the tool <c>starpu_workers_activity</c> (see
  105. \ref MonitoringActivity) to generate a graphic showing the evolution of
  106. these values during the time, for the different workers.
  107. \subsection Bus-relatedFeedback Bus-related Feedback
  108. // how to enable/disable performance monitoring
  109. // what kind of information do we get ?
  110. The bus speed measured by StarPU can be displayed by using the tool
  111. <c>starpu_machine_display</c>, for instance:
  112. \verbatim
  113. StarPU has found:
  114. 3 CUDA devices
  115. CUDA 0 (Tesla C2050 02:00.0)
  116. CUDA 1 (Tesla C2050 03:00.0)
  117. CUDA 2 (Tesla C2050 84:00.0)
  118. from to RAM to CUDA 0 to CUDA 1 to CUDA 2
  119. RAM 0.000000 5176.530428 5176.492994 5191.710722
  120. CUDA 0 4523.732446 0.000000 2414.074751 2417.379201
  121. CUDA 1 4523.718152 2414.078822 0.000000 2417.375119
  122. CUDA 2 4534.229519 2417.069025 2417.060863 0.000000
  123. \endverbatim
  124. Statistics about the data transfers which were performed and temporal average
  125. of bandwidth usage can be obtained by setting the environment variable
  126. \ref STARPU_BUS_STATS to <c>1</c>; a summary will then be displayed at
  127. program termination. To display the summary in a file instead of the
  128. standard error stream, use the environment variable \ref STARPU_BUS_STATS_FILE.
  129. \verbatim
  130. Data transfer stats:
  131. RAM 0 -> CUDA 0 319.92 MB 213.10 MB/s (transfers : 91 - avg 3.52 MB)
  132. CUDA 0 -> RAM 0 214.45 MB 142.85 MB/s (transfers : 61 - avg 3.52 MB)
  133. RAM 0 -> CUDA 1 302.34 MB 201.39 MB/s (transfers : 86 - avg 3.52 MB)
  134. CUDA 1 -> RAM 0 133.59 MB 88.99 MB/s (transfers : 38 - avg 3.52 MB)
  135. CUDA 0 -> CUDA 1 144.14 MB 96.01 MB/s (transfers : 41 - avg 3.52 MB)
  136. CUDA 1 -> CUDA 0 130.08 MB 86.64 MB/s (transfers : 37 - avg 3.52 MB)
  137. RAM 0 -> CUDA 2 312.89 MB 208.42 MB/s (transfers : 89 - avg 3.52 MB)
  138. CUDA 2 -> RAM 0 133.59 MB 88.99 MB/s (transfers : 38 - avg 3.52 MB)
  139. CUDA 0 -> CUDA 2 151.17 MB 100.69 MB/s (transfers : 43 - avg 3.52 MB)
  140. CUDA 2 -> CUDA 0 105.47 MB 70.25 MB/s (transfers : 30 - avg 3.52 MB)
  141. CUDA 1 -> CUDA 2 175.78 MB 117.09 MB/s (transfers : 50 - avg 3.52 MB)
  142. CUDA 2 -> CUDA 1 203.91 MB 135.82 MB/s (transfers : 58 - avg 3.52 MB)
  143. Total transfers: 2.27 GB
  144. \endverbatim
  145. \subsection MPI-relatedFeedback MPI-related Feedback
  146. Statistics about the data transfers which were performed over MPI can be
  147. obtained by setting the environment variable \ref STARPU_COMM_STATS to <c>1</c>;
  148. a summary will then be displayed at program termination:
  149. \verbatim
  150. [starpu_comm_stats][1] TOTAL: 456.000000 B 0.000435 MB 0.000188 B/s 0.000000 MB/s
  151. [starpu_comm_stats][1:0] 456.000000 B 0.000435 MB 0.000188 B/s 0.000000 MB/s
  152. [starpu_comm_stats][0] TOTAL: 456.000000 B 0.000435 MB 0.000188 B/s 0.000000 MB/s
  153. [starpu_comm_stats][0:1] 456.000000 B 0.000435 MB 0.000188 B/s 0.000000 MB/s
  154. \endverbatim
  155. These statistics can be plotted as heatmaps using StarPU tool <c>starpu_mpi_comm_matrix.py</c> (see \ref MPIDebug).
  156. \section TaskAndWorkerProfiling Task And Worker Profiling
  157. A full example showing how to use the profiling API is available in
  158. the StarPU sources in the directory <c>examples/profiling/</c>.
  159. \code{.c}
  160. struct starpu_task *task = starpu_task_create();
  161. task->cl = &cl;
  162. task->synchronous = 1;
  163. /* We will destroy the task structure by hand so that we can
  164. * query the profiling info before the task is destroyed. */
  165. task->destroy = 0;
  166. /* Submit and wait for completion (since synchronous was set to 1) */
  167. starpu_task_submit(task);
  168. /* The task is finished, get profiling information */
  169. struct starpu_profiling_task_info *info = task->profiling_info;
  170. /* How much time did it take before the task started ? */
  171. double delay += starpu_timing_timespec_delay_us(&info->submit_time, &info->start_time);
  172. /* How long was the task execution ? */
  173. double length += starpu_timing_timespec_delay_us(&info->start_time, &info->end_time);
  174. /* We no longer need the task structure */
  175. starpu_task_destroy(task);
  176. \endcode
  177. \code{.c}
  178. /* Display the occupancy of all workers during the test */
  179. int worker;
  180. for (worker = 0; worker < starpu_worker_get_count(); worker++)
  181. {
  182. struct starpu_profiling_worker_info worker_info;
  183. int ret = starpu_profiling_worker_get_info(worker, &worker_info);
  184. STARPU_ASSERT(!ret);
  185. double total_time = starpu_timing_timespec_to_us(&worker_info.total_time);
  186. double executing_time = starpu_timing_timespec_to_us(&worker_info.executing_time);
  187. double sleeping_time = starpu_timing_timespec_to_us(&worker_info.sleeping_time);
  188. double overhead_time = total_time - executing_time - sleeping_time;
  189. float executing_ratio = 100.0*executing_time/total_time;
  190. float sleeping_ratio = 100.0*sleeping_time/total_time;
  191. float overhead_ratio = 100.0 - executing_ratio - sleeping_ratio;
  192. char workername[128];
  193. starpu_worker_get_name(worker, workername, 128);
  194. fprintf(stderr, "Worker %s:\n", workername);
  195. fprintf(stderr, "\ttotal time: %.2lf ms\n", total_time*1e-3);
  196. fprintf(stderr, "\texec time: %.2lf ms (%.2f %%)\n", executing_time*1e-3, executing_ratio);
  197. fprintf(stderr, "\tblocked time: %.2lf ms (%.2f %%)\n", sleeping_time*1e-3, sleeping_ratio);
  198. fprintf(stderr, "\toverhead time: %.2lf ms (%.2f %%)\n", overhead_time*1e-3, overhead_ratio);
  199. }
  200. \endcode
  201. \section PerformanceModelExample Performance Model Example
  202. To achieve good scheduling, StarPU scheduling policies need to be able to
  203. estimate in advance the duration of a task. This is done by giving to codelets
  204. a performance model, by defining a structure starpu_perfmodel and
  205. providing its address in the field starpu_codelet::model. The fields
  206. starpu_perfmodel::symbol and starpu_perfmodel::type are mandatory, to
  207. give a name to the model, and the type of the model, since there are
  208. several kinds of performance models. For compatibility, make sure to
  209. initialize the whole structure to zero, either by using explicit
  210. memset(), or by letting the compiler implicitly do it as examplified
  211. below.
  212. <ul>
  213. <li>
  214. Measured at runtime (model type ::STARPU_HISTORY_BASED). This assumes that for a
  215. given set of data input/output sizes, the performance will always be about the
  216. same. This is very true for regular kernels on GPUs for instance (<0.1% error),
  217. and just a bit less true on CPUs (~=1% error). This also assumes that there are
  218. few different sets of data input/output sizes. StarPU will then keep record of
  219. the average time of previous executions on the various processing units, and use
  220. it as an estimation. History is done per task size, by using a hash of the input
  221. and ouput sizes as an index.
  222. It will also save it in <c>$STARPU_HOME/.starpu/sampling/codelets</c>
  223. for further executions, and can be observed by using the tool
  224. <c>starpu_perfmodel_display</c>, or drawn by using
  225. the tool <c>starpu_perfmodel_plot</c> (\ref PerformanceModelCalibration). The
  226. models are indexed by machine name. To
  227. share the models between machines (e.g. for a homogeneous cluster), use
  228. <c>export STARPU_HOSTNAME=some_global_name</c>. Measurements are only done
  229. when using a task scheduler which makes use of it, such as
  230. <c>dmda</c>. Measurements can also be provided explicitly by the application, by
  231. using the function starpu_perfmodel_update_history().
  232. The following is a small code example.
  233. If e.g. the code is recompiled with other compilation options, or several
  234. variants of the code are used, the <c>symbol</c> string should be changed to reflect
  235. that, in order to recalibrate a new model from zero. The <c>symbol</c> string can even
  236. be constructed dynamically at execution time, as long as this is done before
  237. submitting any task using it.
  238. \code{.c}
  239. static struct starpu_perfmodel mult_perf_model =
  240. {
  241. .type = STARPU_HISTORY_BASED,
  242. .symbol = "mult_perf_model"
  243. };
  244. struct starpu_codelet cl =
  245. {
  246. .cpu_funcs = { cpu_mult },
  247. .cpu_funcs_name = { "cpu_mult" },
  248. .nbuffers = 3,
  249. .modes = { STARPU_R, STARPU_R, STARPU_W },
  250. /* for the scheduling policy to be able to use performance models */
  251. .model = &mult_perf_model
  252. };
  253. \endcode
  254. </li>
  255. <li>
  256. Measured at runtime and refined by regression (model types
  257. ::STARPU_REGRESSION_BASED and ::STARPU_NL_REGRESSION_BASED). This
  258. still assumes performance regularity, but works
  259. with various data input sizes, by applying regression over observed
  260. execution times. ::STARPU_REGRESSION_BASED uses an <c>a*n^b</c> regression
  261. form, ::STARPU_NL_REGRESSION_BASED uses an <c>a*n^b+c</c> (more precise than
  262. ::STARPU_REGRESSION_BASED, but costs a lot more to compute).
  263. For instance,
  264. <c>tests/perfmodels/regression_based.c</c> uses a regression-based performance
  265. model for the function memset().
  266. Of course, the application has to issue
  267. tasks with varying size so that the regression can be computed. StarPU will not
  268. trust the regression unless there is at least 10% difference between the minimum
  269. and maximum observed input size. It can be useful to set the
  270. environment variable \ref STARPU_CALIBRATE to <c>1</c> and run the application
  271. on varying input sizes with \ref STARPU_SCHED set to <c>dmda</c> scheduler,
  272. so as to feed the performance model for a variety of
  273. inputs. The application can also provide the measurements explictly by
  274. using the function starpu_perfmodel_update_history(). The tools
  275. <c>starpu_perfmodel_display</c> and <c>starpu_perfmodel_plot</c> can
  276. be used to observe how much the performance model is calibrated
  277. (\ref PerformanceModelCalibration); when their output look good,
  278. \ref STARPU_CALIBRATE can be reset to <c>0</c> to let
  279. StarPU use the resulting performance model without recording new measures, and
  280. \ref STARPU_SCHED can be set to <c>dmda</c> to benefit from the performance models. If
  281. the data input sizes vary a lot, it is really important to set
  282. \ref STARPU_CALIBRATE to <c>0</c>, otherwise StarPU will continue adding the
  283. measures, and result with a very big performance model, which will take time a
  284. lot of time to load and save.
  285. For non-linear regression, since computing it
  286. is quite expensive, it is only done at termination of the application. This
  287. means that the first execution of the application will use only history-based
  288. performance model to perform scheduling, without using regression.
  289. </li>
  290. <li>
  291. Another type of model is ::STARPU_MULTIPLE_REGRESSION_BASED, which
  292. is based on multiple linear regression. In this model, the user
  293. defines both the relevant parameters and the equation for computing the
  294. task duration.
  295. \f[
  296. T_{kernel} = a + b(M^{\alpha_1} * N^{\beta_1} * K^{\gamma_1}) + c(M^{\alpha_2} * N^{\beta_2} * K^{\gamma_2}) + ...
  297. \f]
  298. \f$M, N, K\f$ are the parameters of the task, added at the task
  299. creation. These need to be extracted by the <c>cl_perf_func</c>
  300. function, which should be defined by the user. \f$\alpha, \beta,
  301. \gamma\f$ are the exponents defined by the user in
  302. <c>model->combinations</c> table. Finally, coefficients \f$a, b, c\f$
  303. are computed automatically by the StarPU at the end of the execution, using least
  304. squares method of the <c>dgels_</c> LAPACK function.
  305. <c>examples/mlr/mlr.c</c> example provides more details on
  306. the usage of ::STARPU_MULTIPLE_REGRESSION_BASED models. The \ref enable-mlr
  307. "--enable-mlr" configure option needs to be set to calibrate the model.
  308. Coefficients computation is done at the end of the execution, and the
  309. results are stored in standard codelet perfmodel files. Additional
  310. files containing the duration of task together with the value of each
  311. parameter are stored in <c>.starpu/sampling/codelets/tmp/</c>
  312. directory. These files are reused when \ref STARPU_CALIBRATE
  313. environment variable is set to <c>1</c>, to recompute coefficients
  314. based on the current, but also on the previous
  315. executions. By default StarPU uses a lightweight dgels implementation, but the
  316. \ref enable-mlr-system-blas "--enable-mlr-system-blas" configure option can be
  317. used to make StarPU use a system-provided dgels BLAS.
  318. Additionally, when multiple linear regression models are not enabled through
  319. \ref enable-mlr "--enable-mlr" or when the
  320. <c>model->combinations</c> are not defined, StarPU will still write
  321. output files into <c>.starpu/sampling/codelets/tmp/</c> to allow
  322. performing an analysis. This analysis typically aims at finding the
  323. most appropriate equation for the codelet and
  324. <c>tools/starpu_mlr_analysis</c> script provides an example of how to
  325. perform such study.
  326. </li>
  327. <li>
  328. Provided as an estimation from the application itself (model type
  329. ::STARPU_COMMON and field starpu_perfmodel::cost_function),
  330. see for instance
  331. <c>examples/common/blas_model.h</c> and <c>examples/common/blas_model.c</c>.
  332. </li>
  333. <li>
  334. Provided explicitly by the application (model type ::STARPU_PER_ARCH):
  335. either field starpu_perfmodel::arch_cost_function, or
  336. the fields <c>.per_arch[arch][nimpl].cost_function</c> have to be
  337. filled with pointers to functions which return the expected duration
  338. of the task in micro-seconds, one per architecture, see for instance
  339. <c>tests/datawizard/locality.c</c>
  340. </li>
  341. <li>
  342. Provided explicitly by the application (model type ::STARPU_PER_WORKER)
  343. similarly with the starpu_perfmodel::worker_cost_function field.
  344. </li>
  345. </ul>
  346. For ::STARPU_HISTORY_BASED, ::STARPU_REGRESSION_BASED, and
  347. ::STARPU_NL_REGRESSION_BASED, the dimensions of task data (both input
  348. and output) are used as an index by default. ::STARPU_HISTORY_BASED uses a CRC
  349. hash of the dimensions as an index to distinguish histories, and
  350. ::STARPU_REGRESSION_BASED and ::STARPU_NL_REGRESSION_BASED use the total
  351. size as an index for the regression.
  352. The starpu_perfmodel::size_base and starpu_perfmodel::footprint fields however
  353. permit the application to override that, when for instance some of the data
  354. do not matter for task cost (e.g. mere reference table), or when using sparse
  355. structures (in which case it is the number of non-zeros which matter), or when
  356. there is some hidden parameter such as the number of iterations, or when the
  357. application actually has a very good idea of the complexity of the algorithm,
  358. and just not the speed of the processor, etc. The example in the directory
  359. <c>examples/pi</c> uses this to include the number of iterations in the base
  360. size. starpu_perfmodel::size_base should be used when the variance of the actual
  361. performance is known (i.e. bigger return value is longer execution
  362. time), and thus particularly useful for ::STARPU_REGRESSION_BASED or
  363. ::STARPU_NL_REGRESSION_BASED. starpu_perfmodel::footprint can be used when the
  364. variance of the actual performance is unknown (irregular performance behavior,
  365. etc.), and thus only useful for ::STARPU_HISTORY_BASED.
  366. starpu_task_data_footprint() can be used as a base and combined with other
  367. parameters through starpu_hash_crc32c_be() for instance.
  368. StarPU will automatically determine when the performance model is calibrated,
  369. or rather, it will assume the performance model is calibrated until the
  370. application submits a task for which the performance can not be predicted. For
  371. ::STARPU_HISTORY_BASED, StarPU will require 10 (STARPU_CALIBRATE_MINIMUM)
  372. measurements for a given size before estimating that an average can be taken as
  373. estimation for further executions with the same size. For
  374. ::STARPU_REGRESSION_BASED and ::STARPU_NL_REGRESSION_BASED, StarPU will require
  375. 10 (STARPU_CALIBRATE_MINIMUM) measurements, and that the minimum measured
  376. data size is smaller than 90% of the maximum measured data size (i.e. the
  377. measurement interval is large enough for a regression to have a meaning).
  378. Calibration can also be forced by setting the \ref STARPU_CALIBRATE environment
  379. variable to <c>1</c>, or even reset by setting it to <c>2</c>.
  380. How to use schedulers which can benefit from such performance model is explained
  381. in \ref TaskSchedulingPolicy.
  382. The same can be done for task energy consumption estimation, by setting
  383. the field starpu_codelet::energy_model the same way as the field
  384. starpu_codelet::model. Note: for now, the application has to give to
  385. the energy consumption performance model a name which is different from
  386. the execution time performance model.
  387. The application can request time estimations from the StarPU performance
  388. models by filling a task structure as usual without actually submitting
  389. it. The data handles can be created by calling any of the functions
  390. <c>starpu_*_data_register</c> with a <c>NULL</c> pointer and <c>-1</c>
  391. node and the desired data sizes, and need to be unregistered as usual.
  392. The functions starpu_task_expected_length() and
  393. starpu_task_expected_energy() can then be called to get an estimation
  394. of the task cost on a given arch. starpu_task_footprint() can also be
  395. used to get the footprint used for indexing history-based performance
  396. models. starpu_task_destroy() needs to be called to destroy the dummy
  397. task afterwards. See <c>tests/perfmodels/regression_based.c</c> for an example.
  398. The application can also request an on-the-fly XML report of the performance
  399. model, by calling starpu_perfmodel_dump_xml() to print the report to a
  400. <c>FILE*</c>.
  401. \section PerformanceMonitoringCounters Performance Monitoring Counters
  402. This section presents the StarPU performance monitoring framework. It summarizes the objectives of the framework. It then introduces the entities involved in the framework. It presents the API of the framework, as well as some implementation details. It exposes the typical sequence of operations to plug an external tool to monitor a performance counter of StarPU.
  403. \subsection PerfMonCountObjectives Objectives
  404. The objectives of this framework are to let external tools interface with StarPU to collect various performance metrics at runtime, in a generic, safe, extensible way. For that, it enables such tools to discover the available performance metrics in a particular StarPU build as well as the type of each performance counter value. It lets these tools build sets of performance counters to monitor, and then register listener callbacks to collect the measurement samples of these sets of performance counters at runtime.
  405. \subsection PerfMonCountEntities Entities
  406. The performance monitoring framework is built on a series of concepts and items, organized in a consistent way. The corresponding C language objects should be considered opaque by external tools, and should only be manipulated through proper function calls and accessors.
  407. \subsubsection PerfMonCountCounter Performance Counter
  408. The performance counter entity is the fundamental object of the framework, representing one piece of performance metrics, such as for instance the total number of tasks submitted so far, that is exported by StarPU and can be collected through the framework at runtime. A performance counter has a type and belongs to a scope. A performance counter is designated by a unique name and unique ID integer.
  409. \subsubsection PerfMonCountCounterType Performance Counter Type
  410. A performance counter has a type. A type is designated by a unique name and unique ID number. Currently supported types include:
  411. \verbatim
  412. Type Name Type Definition
  413. "int32" 32-bit signed integers
  414. "int64" 64-bit signed integers
  415. "float" 32-bit single-precision floating point
  416. "double" 64-bit double-precision floating point
  417. \endverbatim
  418. \subsubsection PerfMonCountCounterScope Performance Counter Scope
  419. A performance counter belongs to a scope. The scope of a counter defines the context considered for computing the corresponding performance counter. A scope is designated with a unique name and unique ID number. Currently defined scopes include:
  420. \verbatim
  421. Scope Name Scope Definition
  422. "global" Counter is global to the StarPU instance
  423. "per_worker" Counter is within the scope of a thread worker
  424. "per_codelet" Counter is within the scope of a task codelet
  425. \endverbatim
  426. \subsubsection PerfMonCountCounterSet Performance Counter Set
  427. A performance counter set is a subset of the performance counters belonging to the same scope. Each counter of the scope can be in the enabled or disabled state in a performance counter set. A performance counter set enables a performance monitoring tool to indicate the set of counters to be collected for a particular listener callback.
  428. \subsubsection PerfMonCountCounterSample Performance Counter Sample
  429. A performance counter sample corresponds to one sample of collected measurement values of a performance counter set. Only the values corresponding to enabled counters in the sample's counter set should be observed by the listener callback. Whether the sample contains valid values for counters disabled in the set is unspecified.
  430. \subsubsection PerfMonCountCounterListener Performance Counter Listener
  431. A performance counter listener is a callback function registered by some external tool to monitor a set of performance counters in a particular scope. It is called each time a new performance counter sample is ready to be observed. The sample object should not be accessed outside of the callback.
  432. \subsubsection PerfMonCountCounterAPI Application Programming Interface
  433. The API of the performance monitoring framework is defined in the "starpu_perf_monitoring.h" public header file of StarPU. This header file is automatically included with "starpu.h". An example of use of the routines is given in Section 3.6.
  434. \subsubsection PerfMonCountCounterScopeRoutines Scope Related Routines
  435. \verbatim
  436. Function Name Function Definition
  437. starpu_perf_counter_scope_name_to_id Translate scope name constant string to scope id
  438. starpu_perf_counter_scope_id_to_name Translate scope id to scope name constant string
  439. \endverbatim
  440. \subsubsection PerfMonCountCounterTypeRoutines Type Related Routines
  441. \verbatim
  442. Function Name Function Definition
  443. starpu_perf_counter_type_name_to_id Translate type name constant string to type id
  444. starpu_perf_counter_type_id_to_name Translate type id to type name constant string
  445. \endverbatim
  446. \subsubsection PerfMonCountCounterCounterRoutines Counter Related Routines
  447. \verbatim
  448. Function Name Function Definition
  449. starpu_perf_counter_nb Return the number of performance counters for the given scope
  450. starpu_perf_counter_name_to_id Translate a performance counter name to its id
  451. starpu_perf_counter_nth_to_id Translate a performance counter rank in its scope to its counter id
  452. starpu_perf_counter_id_to_name Translate a counter id to its name constant string
  453. starpu_perf_counter_get_type_id Return the counter's type id
  454. starpu_perf_counter_get_help_string Return the counter's help string
  455. starpu_perf_counter_list_avail Display the list of counters defined in the given scope
  456. starpu_perf_counter_list_all_avail Display the list of counters defined in all scopes
  457. \endverbatim
  458. \subsubsection PerfMonCountCounterCounterSetRoutines Counter Set Related Routines
  459. \verbatim
  460. Function Name Function Definition
  461. starpu_perf_counter_set_alloc Allocate a new performance counter set
  462. starpu_perf_counter_set_free Free a performance counter set
  463. starpu_perf_counter_set_enable_id Enable a given counter in the set
  464. starpu_perf_counter_set_disable_id Disable a given counter in the set
  465. \endverbatim
  466. \subsubsection PerfMonCountCounterListenerRoutines Listener Related Routines
  467. \verbatim
  468. Function Name Function Definition
  469. starpu_perf_counter_listener_init Initialize a new performance counter listener
  470. starpu_perf_counter_listener_exit End a performance counter listener
  471. starpu_perf_counter_set_global_listener Set a listener for the global scope
  472. starpu_perf_counter_set_per_worker_listener Set a listener for the per_worker scope on a given worker
  473. starpu_perf_counter_set_all_per_worker_listeners Set a common listener for all workers
  474. starpu_perf_counter_set_per_codelet_listener Set a per_codelet listener for a codelet
  475. starpu_perf_counter_unset_global_listener Unset the global listener
  476. starpu_perf_counter_unset_per_worker_listener Unset the per_worker listener
  477. starpu_perf_counter_unset_all_per_worker_listeners Unset all per_worker listeners
  478. starpu_perf_counter_unset_per_codelet_listener Unset a per_codelet listener
  479. \endverbatim
  480. \subsubsection PerfMonCountCounterSampleRoutines Sample Related Routines
  481. \verbatim
  482. Function Name Function Definition
  483. starpu_perf_counter_sample_get_int32_value Read an int32 counter value from a sample
  484. starpu_perf_counter_sample_get_int64_value Read an int64 counter value from a sample
  485. starpu_perf_counter_sample_get_float_value Read a float counter value from a sample
  486. starpu_perf_counter_sample_get_double_value Read a double counter value from a sample
  487. \endverbatim
  488. \subsection PerfMonCountCounterImplementation Implementation Details
  489. \subsubsection PerfMonCountCounterImplRegistration Performance Counter Registration
  490. Each module of StarPU can export performance counters. In order to do so, modules that need to export some counters define a registration function that is called at StarPU initialization time. This function is responsible for calling the "_starpu_perf_counter_register()" function once for each counter it exports, to let the framework know about the list of counters managed by the module. It also registers performance sample updater callbacks for the module, one for each scope for which it exports counters.
  491. \subsubsection PerfMonCountCounterImplUpdaters Performance Sample Updaters
  492. The updater callback for a module and scope combination is internally called every time a sample for a set of performance counter must be updated. Thus, the updated callback is responsible for filling the sample's selected counters with the counter values found at the time of the call.
  493. Global updaters are currently called at task submission time, as well as any blocking tasks management function of the StarPU API, such as the "starpu_task_wait_for_all()", which waits for the completion of all tasks submitted up to this point.
  494. Per-worker updaters are currently called at the level of StarPU's drivers, that is, the modules in charge of task execution of hardware-specific worker threads. The actual calls occur in-between the execution of tasks.
  495. Per-codelet updaters are currently called both at task submission time, and at the level of StarPU's drivers together with the per-worker updaters.
  496. A performance sample object is locked during the sample collection. The locking prevents the following issues:
  497. <ul>
  498. <li>The listener of sample being changed during sample collection;
  499. <li>The set of counters enabled for a sample being changed;
  500. <li>Conflicting concurrent updates;
  501. <li>Updates while the sample is being read by the listener.
  502. </ul>
  503. The location of the updaters' calls is chosen to minimize the sequentialization effect of the locking, in order to limit the level of interference of the monitoring process. For Global updaters, the calls are performed only on the application thread(s) in charge of submitting tasks. Since, in most cases, only a single application thread submits tasks, the sequentialization effect is moderate. Per-worker updates are local to their worker, thus here again the sample lock is un-contented, unless the external monitoring tool frequently changes the set of enabled counters in the sample.
  504. \subsubsection PerfMonCountCounterImplOperations Counter operations
  505. In practice the sample updaters only take snapshots of the actual performance counters. The performance counters themselves are updated with ad-hoc procedures depending on each counter. Such procedures typically involve atomic operations. While operations such as atomic increments or decrements on integer values are readily available, this is not the case for more complex operations such as min/max for computing peak value counters (for instance in the global and per-codelet counters for peak number of submitted tasks and peak number of ready tasks waiting for execution), and this is also not the case for computations on floating point data (used for instance in computing cumulated execution time of tasks, either per worker or per codelet). The performance monitoring framework therefore supplies such missing routines, for the internal use of StarPU.
  506. \subsubsection PerfMonCountCounterImplRuntime Runtime checks
  507. The performance monitoring framework features a comprehensive set of runtime checks to verify that both StarPU and some external tool do not access a performance counter with the wrong typed routines, to quickly detect situations of mismatch that can result from the evolution of multiple pieces of software at distinct paces. Moreover, no StarPU data structure is accessed directly either by the external code making use of the performance monitoring framework. The use of the C enum constants is optional; referring to values through constant strings is available when more robustness is desired. These runtime checks enable the framework to be extensible. Moreover, while the framework's counters currently are permanently compiled in, they could be made optional at compile time, for instance to suppress any overhead once the analysis and optimization process has been completed by the programmer. Thanks to the runtime discovery of available counters, the applicative code, or an intermediate layer such as skeleton layer acting on its behalf, would then be able to adapt to performance analysis builds versus optimized builds.
  508. \subsection PerfMonCountCounterExported Exported Counters
  509. \subsubsection PerfMonCountCounterExportedGlobal Global Scope
  510. \verbatim
  511. Counter Name Counter Definition
  512. starpu.task.g_total_submitted Total number of tasks submitted
  513. starpu.task.g_peak_submitted Maximum number of tasks submitted, waiting for dependencies resolution at any time
  514. starpu.task.g_peak_ready Maximum number of tasks ready for execution, waiting for an execution slot at any time
  515. \endverbatim
  516. \subsubsection PerfMonCountCounterExportedPerWorker Per-worker Scope
  517. \verbatim
  518. Counter Name Counter Definition
  519. starpu.task.w_total_executed Total number of tasks executed on a given worker
  520. starpu.task.w_cumul_execution_time Cumulated execution time of tasks executed on a given worker
  521. \endverbatim
  522. \subsubsection PerfMonCountCounterExportedPerCodelet Per-Codelet Scope
  523. \verbatim
  524. Counter Name Counter Definition
  525. starpu.task.c_total_submitted Total number of submitted tasks for a given codelet
  526. starpu.task.c_peak_submitted Maximum number of submitted tasks for a given codelet waiting for dependencies resolution at any time
  527. starpu.task.c_peak_ready Maximum number of ready tasks for a given codelet waiting for an execution slot at any time
  528. starpu.task.c_total_executed Total number of executed tasks for a given codelet
  529. starpu.task.c_cumul_execution_time Cumulated execution time of tasks for a given codelet
  530. \endverbatim
  531. \subsection PerfMonCountCounterSequence Sequence of operations
  532. This section presents a typical sequence of operations to interface an external tool with some StarPU performance counters. In this example, the counters monitored are the per-worker total number of executed tasks ("starpu.task.w_total_executed") and the tasks' cumulated execution time ("starpu.task.w_cumul_execution_time").
  533. <b>Step 0: Initialize StarPU</b>
  534. StarPU must first be initialized, by a call to starpu_init(), for performance counters to become available, since each module of StarPU registers the performance counters it exports during that initialization phase.
  535. \verbatim
  536. int ret = starpu_init(NULL);
  537. \endverbatim
  538. <b>Step 1: Allocate a counter set</b>
  539. A counter set has to be allocated on the per-worker scope. The per-worker scope id can be obtained by name, or with the pre-defined enum value starpu_perf_counter_scope_per_worker.
  540. \verbatim
  541. enum starpu_perf_counter_scope w_scope = starpu_perf_counter_scope_per_worker;
  542. struct starpu_perf_counter_set *w_set = starpu_perf_counter_set_alloc(w_scope);
  543. \endverbatim
  544. <b>Step 2: Get the counter IDs</b>
  545. Each performance counter has a unique ID used to refer to it in subsequent calls to the performance monitoring framework.
  546. \verbatim
  547. int id_w_total_executed = starpu_perf_counter_name_to_id(w_scope,
  548. "starpu.task.w_total_executed");
  549. int id_w_cumul_execution_time = starpu_perf_counter_name_to_id(w_scope,
  550. "starpu.task.w_cumul_execution_time");
  551. \endverbatim
  552. <b>Step 3: Enable the counters in the counter set</b>
  553. This step indicates which counters will be collected into performance monitoring samples for the listeners referring to this counter set.
  554. \verbatim
  555. starpu_perf_counter_set_enable_id(w_set, id_w_total_executed);
  556. starpu_perf_counter_set_enable_id(w_set, id_w_cumul_execution_time);
  557. \endverbatim
  558. <b>Step 4: Write a listener callback</b>
  559. This callback will be triggered when a sample becomes available. Upon execution, it reads the values for the two counters from the sample and displays these values, for the sake of the example.
  560. \verbatim
  561. void w_listener_cb(struct starpu_perf_counter_listener *listener,
  562. struct starpu_perf_counter_sample *sample,
  563. void *context)
  564. {
  565. int32_t w_total_executed =
  566. starpu_perf_counter_sample_get_int32_value(sample, id_w_total_executed);
  567. double w_cumul_execution_time =
  568. starpu_perf_counter_sample_get_double_value(sample, id_w_cumul_execution_time);
  569. printf("worker[%d]: w_total_executed = %d, w_cumul_execution_time = %lf\n",
  570. starpu_worker_get_id(),
  571. w_total_executed,
  572. w_cumul_execution_time);
  573. }
  574. \endverbatim
  575. <b>Step 5: Initialize the listener</b>
  576. This step allocates the listener structure and prepares it to listen to the selected set of per-worker counters. However, it is not actually active until Step 6, once it is attached to one or more worker.
  577. \verbatim
  578. struct starpu_perf_counter_listener * w_listener =
  579. starpu_perf_counter_listener_init(w_set, w_listener_cb, NULL);
  580. \endverbatim
  581. <b>Step 6: Set the listener on all workers</b>
  582. This step actually makes the listener active, in this case on every StarPU worker thread.
  583. \verbatim
  584. starpu_perf_counter_set_all_per_worker_listeners(w_listener);
  585. \endverbatim
  586. After this step, any task assigned to a worker will be counted in that worker selected performance counters, and reported to the listener.
  587. \section PerfKnobs Performance Steering Knobs
  588. This section presents the StarPU performance steering framework. It summarizes the objectives of the framework. It introduces the entities involved in the framework, and then details the API, implementation and sequence of operations.
  589. \subsection PerfKnobsObjectives Objectives
  590. The objectives of this framework are to let external tools interface with StarPU, observe, and act at runtime on actionable performance steering knobs exported by StarPU, in a generic, safe, extensible way. It defines an API to let such external tools discover the available performance steering knobs in a particular StarPU revision of build, as well as the type of each knob.
  591. \subsection PerfKnobsEntities Entities
  592. \subsubsection PerfKnobsEntitiesKnob Performance Steering Knob
  593. The performance steering knob entity designates one runtime-actionable knob exported by StarPU. It may represent some setting, or some constant used within StarPU for a given purpose. The value of the knob is typed, it can be obtained or modified with the appropriate getter/setter routine. The knob belongs to a scope. A performance steering knob is designated with a unique name and unique ID number.
  594. \subsubsection PerfKnobsEntitiesKnobType Knob Type
  595. A performance steering knob has a type. A type is designated by a unique name and unique ID number. Currently supported types include:
  596. \verbatim
  597. Type Name Type Definition
  598. "int32" 32-bit signed integers
  599. "int64" 64-bit signed integers
  600. "float" 32-bit single precision floating point
  601. "double" 64-bit double precision floating point
  602. \endverbatim
  603. On/Off knobs are defined as "int32" type, with value 0 for Off and value !0 for On, unless otherwise specified.
  604. \subsubsection PerfKnobsEntitiesKnobScope Knob Scope
  605. A performance steering knob belongs to a scope. The scope of a knob defines the context considered for computing the corresponding knob. A scope is designated with a unique name and unique ID number. Currently defined scopes include:
  606. \verbatim
  607. Scope Name Scope Definition
  608. "global" Knob is global to the StarPU instance
  609. "per_worker" Knob is within the scope of a thread worker
  610. "per_scheduler" Knob is within the scope of a scheduling policy instance
  611. \endverbatim
  612. \subsubsection PerfKnobsEntitiesKnobGroup Knob Group
  613. The notion of Performance Steering Knob Group is currently internal to StarPU. It defines a series of knobs that are handled by the same couple of setter/getter functions internally. A knob group belongs to a knob scope.
  614. \subsection PerfKnobsAPI Application Programming Interface
  615. \subsubsection PerfKnobsAPIScope Scope Related Routines
  616. \verbatim
  617. Function Name Function Definition
  618. starpu_perf_knob_scope_name_to_id Translate scope name constant string to scope id
  619. starpu_perf_knob_scope_id_to_name Translate scope id to scope name constant string
  620. \endverbatim
  621. \subsubsection PerfKnobsAPIType Type Related Routines
  622. \verbatim
  623. Function Name Function Definition
  624. starpu_perf_knob_type_name_to_id Translate type name constant string to type id
  625. starpu_perf_knob_type_id_to_name Translate type id to type name constant string
  626. \endverbatim
  627. \subsubsection PerfKnobsAPISteer Performance Steering Knob Related Routines
  628. \verbatim
  629. Function Name Function Definition
  630. starpu_perf_knob_nb Return the number of performance steering knobs for the given scope
  631. starpu_perf_knob_name_to_id Translate a performance knob name to its id
  632. starpu_perf_knob_nth_to_id Translate a performance knob rank in its scope to its knob id
  633. starpu_perf_knob_id_to_name Translate a knob id to its name constant string
  634. starpu_perf_knob_get_type_id Return the knob's type id
  635. starpu_perf_knob_get_help_string Return the knob's help string
  636. starpu_perf_knob_list_avail Display the list of knobs defined in the given scope
  637. starpu_perf_knob_list_all_avail Display the list of knobs defined in all scopes
  638. starpu_perf_knob_get_<SCOPE>_<TYPE>_value Get knob value for given scope and type
  639. starpu_perf_knob_set_<SCOPE>_<TYPE>_value Set knob value for given scope and type
  640. \endverbatim
  641. \subsection PerfKnobsImpl Implementation Details
  642. While the APIs of the monitoring and the steering frameworks share a similar design philosophy, the internals are significantly different. Since the effect of the steering knobs varies widely, there is no global locking scheme in place shared for all knobs. Instead, each knob gets its own procedures to get the value of a setting, or change it. To prevent code duplication, some related knobs may share getter/setter routines as knob groups.
  643. The steering framework does not involve callback routines. Knob get operations proceed immediately, except for the possible delay in getting access to the knob value. Knob set operations also proceed immediately, not counting the exclusive access time, though their action result may be observed with some latency, depending on the knob and on the current workload. For instance, acting on a per-worker "starpu.worker.w_enable_worker_knob" to disable a worker thread may be observed only after the corresponding worker's assigned task queue becomes empty, since its actual effect is to prevent additional tasks to be queued to the worker, and not to migrate already queued tasks to another worker. Such design choices aim at providing a compromise between offering some steering capabilities and keeping the cost of supporting such steering capabilities to an acceptable level.
  644. The framework is designed to be easily extensible. At StarPU initialization time, the framework calls initialization functions if StarPU modules to initialize the set of knobs they export. Knob get/set accessors can be shared among multiple knobs in a knob group. Thus, exporting a new knob is basically a matter of declaring it at initialization time, by specifying its name and value type, and either add its handling to an existing getter/setter pair of accessors in a knob group, or create a new group. As the performance monitoring framework, the performance steering framework is currently permanently enabled, but could be made optional at compile-time to separate testing builds from production builds.
  645. \subsection PerfKnobsExported Exported Steering Knobs
  646. \subsubsection PerfKnobsExportedGlobal Global Scope
  647. \verbatim
  648. Knob Name Knob Definition
  649. starpu.global.g_calibrate_knob
  650. Enable/disable the calibration of performance models
  651. starpu.global.g_enable_catch_signal_knob Enable/disable the catching of UNIX signals
  652. \endverbatim
  653. \subsubsection PerfKnobsExportedPerWorker Per-worker Scope
  654. \verbatim
  655. Knob Name Knob Definition
  656. starpu.worker.w_bind_to_pu_knob Change the processing unit to which a worker thread is bound
  657. starpu.worker.w_enable_worker_knob Disable/re-enable a worker thread to be selected
  658. for task execution
  659. \endverbatim
  660. \subsubsection PerfKnobsExportedPerScheduler Per-Scheduler Scope
  661. \verbatim
  662. Knob Name Knob Definition
  663. starpu.task.s_max_priority_cap_knob Set a capping maximum priority value for subsequently submitted tasks
  664. starpu.task.s_min_priority_cap_knob Set a capping minimum priority value for subsequently submitted tasks
  665. starpu.dmda.s_alpha_knob Scaling factor for the Alpha constant for Deque Model schedulers to alter the weight of the estimated task execution time
  666. starpu.dmda.s_beta_knob Scaling factor for the Beta constant for Deque Model schedulers to alter the weight of the estimated data transfer time for the task's input(s)
  667. starpu.dmda.s_gamma_knob Scaling factor for the Gamma constant for Deque Model schedulers to alter the weight of the estimated power consumption of the task
  668. starpu.dmda.s_idle_power_knob Scaling factor for the baseline Idle power consumption estimation of the corresponding processing unit
  669. \endverbatim
  670. \subsection PerfKnobsSequence Sequence of operations
  671. This section presents an example of sequence of operations representing a typical use of the performance steering knobs exported by StarPU. In this example, a worker thread is temporarily barred from executing tasks. For that, the corresponding "starpu.worker.w_enable_worker_knob" of the worker, initially set to 1 (= enabled) is changed to 0 (= disabled).
  672. <b>Step 0: Initialize StarPU</b>
  673. StarPU must first be initialized, by a call to starpu_init(). Performance steering knobs only become available after this step, since each module of StarPU registers the knobs it exports during that initialization phase.
  674. \verbatim
  675. int ret = starpu_init(NULL);
  676. \endverbatim
  677. <b>Step 1: Get the knob ID</b>
  678. Each performance steering knob has a unique ID used to refer to it in subsequent calls to the performance steering framework. The knob belongs to the "per_worker" scope.
  679. \verbatim
  680. int w_scope = starpu_perf_knob_scope_name_to_id("per_worker");
  681. int w_enable_id = starpu_perf_knob_name_to_id(w_scope,
  682. "starpu.worker.w_enable_worker_knob");
  683. \endverbatim
  684. <b>Step 2: Get the knob current value</b>
  685. This knob is an On/Off knob. Its value type is therefore a 32-bit integer, with value 0 for Off and value !0 for On. The getter functions for per-worker knobs expect the knob ID as first argument, and the worker ID as second argument. Here the getter call obtains the value of worker 5.
  686. \verbatim
  687. int32_t val = starpu_perf_knob_get_per_worker_int32_value(w_enable_id, 5);
  688. \endverbatim
  689. <b>Step 3: Set the knob current value</b>
  690. The setter functions for per-worker knobs expect the knob ID as first argument, the worker ID as second argument, and the new value as third argument. Here, the value for worker 5 is set to 0 to temporarily bar the worker thread from accepting new tasks for execution.
  691. \verbatim
  692. starpu_perf_knob_set_per_worker_int32_value(w_enable_id, 5, 0);
  693. \endverbatim
  694. Subsequently setting the value of the knob back to 1 enables the corresponding to accept new tasks for execution again.
  695. \verbatim
  696. starpu_perf_knob_set_per_worker_int32_value(w_enable_id, 5, 1);
  697. \endverbatim
  698. */