cpukinds.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * Copyright © 2020-2021 Inria. All rights reserved.
  3. * See COPYING in top-level directory.
  4. */
  5. /** \file
  6. * \brief Kinds of CPU cores.
  7. */
  8. #ifndef HWLOC_CPUKINDS_H
  9. #define HWLOC_CPUKINDS_H
  10. #include "hwloc.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #elif 0
  14. }
  15. #endif
  16. /** \defgroup hwlocality_cpukinds Kinds of CPU cores
  17. *
  18. * Platforms with heterogeneous CPUs may have some cores with
  19. * different features or frequencies.
  20. * This API exposes identical PUs in sets called CPU kinds.
  21. * Each PU of the topology may only be in a single kind.
  22. *
  23. * The number of kinds may be obtained with hwloc_cpukinds_get_nr().
  24. * If the platform is homogeneous, there may be a single kind
  25. * with all PUs.
  26. * If the platform or operating system does not expose any
  27. * information about CPU cores, there may be no kind at all.
  28. *
  29. * The index of the kind that describes a given CPU set
  30. * (if any, and not partially)
  31. * may be obtained with hwloc_cpukinds_get_by_cpuset().
  32. *
  33. * From the index of a kind, it is possible to retrieve information
  34. * with hwloc_cpukinds_get_info():
  35. * an abstracted efficiency value,
  36. * and an array of info attributes
  37. * (for instance the "CoreType" and "FrequencyMaxMHz",
  38. * see \ref topoattrs_cpukinds).
  39. *
  40. * A higher efficiency value means greater intrinsic performance
  41. * (and possibly less performance/power efficiency).
  42. * Kinds with lower efficiency values are ranked first:
  43. * Passing 0 as \p kind_index to hwloc_cpukinds_get_info() will
  44. * return information about the CPU kind with lower performance
  45. * but higher energy-efficiency.
  46. * Higher \p kind_index values would rather return information
  47. * about power-hungry high-performance cores.
  48. *
  49. * When available, efficiency values are gathered from the operating system.
  50. * If so, \p cpukind_efficiency is set in the struct hwloc_topology_discovery_support array.
  51. * This is currently available on Windows 10, Mac OS X (Darwin),
  52. * and on some Linux platforms where core "capacity" is exposed in sysfs.
  53. *
  54. * If the operating system does not expose core efficiencies natively,
  55. * hwloc tries to compute efficiencies by comparing CPU kinds using
  56. * frequencies (on ARM), or core types and frequencies (on other architectures).
  57. * The environment variable HWLOC_CPUKINDS_RANKING may be used
  58. * to change this heuristics, see \ref envvar.
  59. *
  60. * If hwloc fails to rank any kind, for instance because the operating
  61. * system does not expose efficiencies and core frequencies,
  62. * all kinds will have an unknown efficiency (\c -1),
  63. * and they are not indexed/ordered in any specific way.
  64. *
  65. * @{
  66. */
  67. /** \brief Get the number of different kinds of CPU cores in the topology.
  68. *
  69. * \p flags must be \c 0 for now.
  70. *
  71. * \return The number of CPU kinds (positive integer) on success.
  72. * \return \c 0 if no information about kinds was found.
  73. * \return \c -1 with \p errno set to \c EINVAL if \p flags is invalid.
  74. */
  75. HWLOC_DECLSPEC int
  76. hwloc_cpukinds_get_nr(hwloc_topology_t topology,
  77. unsigned long flags);
  78. /** \brief Get the index of the CPU kind that contains CPUs listed in \p cpuset.
  79. *
  80. * \p flags must be \c 0 for now.
  81. *
  82. * \return The index of the CPU kind (positive integer or 0) on success.
  83. * \return \c -1 with \p errno set to \c EXDEV if \p cpuset is
  84. * only partially included in the some kind.
  85. * \return \c -1 with \p errno set to \c ENOENT if \p cpuset is
  86. * not included in any kind, even partially.
  87. * \return \c -1 with \p errno set to \c EINVAL if parameters are invalid.
  88. */
  89. HWLOC_DECLSPEC int
  90. hwloc_cpukinds_get_by_cpuset(hwloc_topology_t topology,
  91. hwloc_const_bitmap_t cpuset,
  92. unsigned long flags);
  93. /** \brief Get the CPU set and infos about a CPU kind in the topology.
  94. *
  95. * \p kind_index identifies one kind of CPU between 0 and the number
  96. * of kinds returned by hwloc_cpukinds_get_nr() minus 1.
  97. *
  98. * If not \c NULL, the bitmap \p cpuset will be filled with
  99. * the set of PUs of this kind.
  100. *
  101. * The integer pointed by \p efficiency, if not \c NULL will, be filled
  102. * with the ranking of this kind of CPU in term of efficiency (see above).
  103. * It ranges from \c 0 to the number of kinds
  104. * (as reported by hwloc_cpukinds_get_nr()) minus 1.
  105. *
  106. * Kinds with lower efficiency are reported first.
  107. *
  108. * If there is a single kind in the topology, its efficiency \c 0.
  109. * If the efficiency of some kinds of cores is unknown,
  110. * the efficiency of all kinds is set to \c -1,
  111. * and kinds are reported in no specific order.
  112. *
  113. * The array of info attributes (for instance the "CoreType",
  114. * "FrequencyMaxMHz" or "FrequencyBaseMHz", see \ref topoattrs_cpukinds)
  115. * and its length are returned in \p infos or \p nr_infos.
  116. * The array belongs to the topology, it should not be freed or modified.
  117. *
  118. * If \p nr_infos or \p infos is \c NULL, no info is returned.
  119. *
  120. * \p flags must be \c 0 for now.
  121. *
  122. * \return \c 0 on success.
  123. * \return \c -1 with \p errno set to \c ENOENT if \p kind_index does not match any CPU kind.
  124. * \return \c -1 with \p errno set to \c EINVAL if parameters are invalid.
  125. */
  126. HWLOC_DECLSPEC int
  127. hwloc_cpukinds_get_info(hwloc_topology_t topology,
  128. unsigned kind_index,
  129. hwloc_bitmap_t cpuset,
  130. int *efficiency,
  131. unsigned *nr_infos, struct hwloc_info_s **infos,
  132. unsigned long flags);
  133. /** \brief Register a kind of CPU in the topology.
  134. *
  135. * Mark the PUs listed in \p cpuset as being of the same kind
  136. * with respect to the given attributes.
  137. *
  138. * \p forced_efficiency should be \c -1 if unknown.
  139. * Otherwise it is an abstracted efficiency value to enforce
  140. * the ranking of all kinds if all of them have valid (and
  141. * different) efficiencies.
  142. *
  143. * The array \p infos of size \p nr_infos may be used to provide
  144. * info names and values describing this kind of PUs.
  145. *
  146. * \p flags must be \c 0 for now.
  147. *
  148. * Parameters \p cpuset and \p infos will be duplicated internally,
  149. * the caller is responsible for freeing them.
  150. *
  151. * If \p cpuset overlaps with some existing kinds, those might get
  152. * modified or split. For instance if existing kind A contains
  153. * PUs 0 and 1, and one registers another kind for PU 1 and 2,
  154. * there will be 3 resulting kinds:
  155. * existing kind A is restricted to only PU 0;
  156. * new kind B contains only PU 1 and combines information from A
  157. * and from the newly-registered kind;
  158. * new kind C contains only PU 2 and only gets information from
  159. * the newly-registered kind.
  160. *
  161. * \note The efficiency \p forced_efficiency provided to this function
  162. * may be different from the one reported later by hwloc_cpukinds_get_info()
  163. * because hwloc will scale efficiency values down to
  164. * between 0 and the number of kinds minus 1.
  165. *
  166. * \return \c 0 on success.
  167. * \return \c -1 with \p errno set to \c EINVAL if some parameters are invalid,
  168. * for instance if \p cpuset is \c NULL or empty.
  169. */
  170. HWLOC_DECLSPEC int
  171. hwloc_cpukinds_register(hwloc_topology_t topology,
  172. hwloc_bitmap_t cpuset,
  173. int forced_efficiency,
  174. unsigned nr_infos, struct hwloc_info_s *infos,
  175. unsigned long flags);
  176. /** @} */
  177. #ifdef __cplusplus
  178. } /* extern "C" */
  179. #endif
  180. #endif /* HWLOC_CPUKINDS_H */