Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:01:15

0001 /*
0002  * Copyright © 2020-2021 Inria.  All rights reserved.
0003  * See COPYING in top-level directory.
0004  */
0005 
0006 /** \file
0007  * \brief Kinds of CPU cores.
0008  */
0009 
0010 #ifndef HWLOC_CPUKINDS_H
0011 #define HWLOC_CPUKINDS_H
0012 
0013 #include "hwloc.h"
0014 
0015 #ifdef __cplusplus
0016 extern "C" {
0017 #elif 0
0018 }
0019 #endif
0020 
0021 /** \defgroup hwlocality_cpukinds Kinds of CPU cores
0022  *
0023  * Platforms with heterogeneous CPUs may have some cores with
0024  * different features or frequencies.
0025  * This API exposes identical PUs in sets called CPU kinds.
0026  * Each PU of the topology may only be in a single kind.
0027  *
0028  * The number of kinds may be obtained with hwloc_cpukinds_get_nr().
0029  * If the platform is homogeneous, there may be a single kind
0030  * with all PUs.
0031  * If the platform or operating system does not expose any
0032  * information about CPU cores, there may be no kind at all.
0033  *
0034  * The index of the kind that describes a given CPU set
0035  * (if any, and not partially)
0036  * may be obtained with hwloc_cpukinds_get_by_cpuset().
0037  *
0038  * From the index of a kind, it is possible to retrieve information
0039  * with hwloc_cpukinds_get_info():
0040  * an abstracted efficiency value,
0041  * and an array of info attributes
0042  * (for instance the "CoreType" and "FrequencyMaxMHz",
0043  *  see \ref topoattrs_cpukinds).
0044  *
0045  * A higher efficiency value means greater intrinsic performance
0046  * (and possibly less performance/power efficiency).
0047  * Kinds with lower efficiency values are ranked first:
0048  * Passing 0 as \p kind_index to hwloc_cpukinds_get_info() will
0049  * return information about the CPU kind with lower performance
0050  * but higher energy-efficiency.
0051  * Higher \p kind_index values would rather return information
0052  * about power-hungry high-performance cores.
0053  *
0054  * When available, efficiency values are gathered from the operating system.
0055  * If so, \p cpukind_efficiency is set in the struct hwloc_topology_discovery_support array.
0056  * This is currently available on Windows 10, Mac OS X (Darwin),
0057  * and on some Linux platforms where core "capacity" is exposed in sysfs.
0058  *
0059  * If the operating system does not expose core efficiencies natively,
0060  * hwloc tries to compute efficiencies by comparing CPU kinds using
0061  * frequencies (on ARM), or core types and frequencies (on other architectures).
0062  * The environment variable HWLOC_CPUKINDS_RANKING may be used
0063  * to change this heuristics, see \ref envvar.
0064  *
0065  * If hwloc fails to rank any kind, for instance because the operating
0066  * system does not expose efficiencies and core frequencies,
0067  * all kinds will have an unknown efficiency (\c -1),
0068  * and they are not indexed/ordered in any specific way.
0069  *
0070  * @{
0071  */
0072 
0073 /** \brief Get the number of different kinds of CPU cores in the topology.
0074  *
0075  * \p flags must be \c 0 for now.
0076  *
0077  * \return The number of CPU kinds (positive integer) on success.
0078  * \return \c 0 if no information about kinds was found.
0079  * \return \c -1 with \p errno set to \c EINVAL if \p flags is invalid.
0080  */
0081 HWLOC_DECLSPEC int
0082 hwloc_cpukinds_get_nr(hwloc_topology_t topology,
0083                       unsigned long flags);
0084 
0085 /** \brief Get the index of the CPU kind that contains CPUs listed in \p cpuset.
0086  *
0087  * \p flags must be \c 0 for now.
0088  *
0089  * \return The index of the CPU kind (positive integer or 0) on success.
0090  * \return \c -1 with \p errno set to \c EXDEV if \p cpuset is
0091  * only partially included in the some kind.
0092  * \return \c -1 with \p errno set to \c ENOENT if \p cpuset is
0093  * not included in any kind, even partially.
0094  * \return \c -1 with \p errno set to \c EINVAL if parameters are invalid.
0095  */
0096 HWLOC_DECLSPEC int
0097 hwloc_cpukinds_get_by_cpuset(hwloc_topology_t topology,
0098                              hwloc_const_bitmap_t cpuset,
0099                              unsigned long flags);
0100 
0101 /** \brief Get the CPU set and infos about a CPU kind in the topology.
0102  *
0103  * \p kind_index identifies one kind of CPU between 0 and the number
0104  * of kinds returned by hwloc_cpukinds_get_nr() minus 1.
0105  *
0106  * If not \c NULL, the bitmap \p cpuset will be filled with
0107  * the set of PUs of this kind.
0108  *
0109  * The integer pointed by \p efficiency, if not \c NULL will, be filled
0110  * with the ranking of this kind of CPU in term of efficiency (see above).
0111  * It ranges from \c 0 to the number of kinds
0112  * (as reported by hwloc_cpukinds_get_nr()) minus 1.
0113  *
0114  * Kinds with lower efficiency are reported first.
0115  *
0116  * If there is a single kind in the topology, its efficiency \c 0.
0117  * If the efficiency of some kinds of cores is unknown,
0118  * the efficiency of all kinds is set to \c -1,
0119  * and kinds are reported in no specific order.
0120  *
0121  * The array of info attributes (for instance the "CoreType",
0122  * "FrequencyMaxMHz" or "FrequencyBaseMHz", see \ref topoattrs_cpukinds)
0123  * and its length are returned in \p infos or \p nr_infos.
0124  * The array belongs to the topology, it should not be freed or modified.
0125  *
0126  * If \p nr_infos or \p infos is \c NULL, no info is returned.
0127  *
0128  * \p flags must be \c 0 for now.
0129  *
0130  * \return \c 0 on success.
0131  * \return \c -1 with \p errno set to \c ENOENT if \p kind_index does not match any CPU kind.
0132  * \return \c -1 with \p errno set to \c EINVAL if parameters are invalid.
0133  */
0134 HWLOC_DECLSPEC int
0135 hwloc_cpukinds_get_info(hwloc_topology_t topology,
0136                         unsigned kind_index,
0137                         hwloc_bitmap_t cpuset,
0138                         int *efficiency,
0139                         unsigned *nr_infos, struct hwloc_info_s **infos,
0140                         unsigned long flags);
0141 
0142 /** \brief Register a kind of CPU in the topology.
0143  *
0144  * Mark the PUs listed in \p cpuset as being of the same kind
0145  * with respect to the given attributes.
0146  *
0147  * \p forced_efficiency should be \c -1 if unknown.
0148  * Otherwise it is an abstracted efficiency value to enforce
0149  * the ranking of all kinds if all of them have valid (and
0150  * different) efficiencies.
0151  *
0152  * The array \p infos of size \p nr_infos may be used to provide
0153  * info names and values describing this kind of PUs.
0154  *
0155  * \p flags must be \c 0 for now.
0156  *
0157  * Parameters \p cpuset and \p infos will be duplicated internally,
0158  * the caller is responsible for freeing them.
0159  *
0160  * If \p cpuset overlaps with some existing kinds, those might get
0161  * modified or split. For instance if existing kind A contains
0162  * PUs 0 and 1, and one registers another kind for PU 1 and 2,
0163  * there will be 3 resulting kinds:
0164  * existing kind A is restricted to only PU 0;
0165  * new kind B contains only PU 1 and combines information from A
0166  * and from the newly-registered kind;
0167  * new kind C contains only PU 2 and only gets information from
0168  * the newly-registered kind.
0169  *
0170  * \note The efficiency \p forced_efficiency provided to this function
0171  * may be different from the one reported later by hwloc_cpukinds_get_info()
0172  * because hwloc will scale efficiency values down to
0173  * between 0 and the number of kinds minus 1.
0174  *
0175  * \return \c 0 on success.
0176  * \return \c -1 with \p errno set to \c EINVAL if some parameters are invalid,
0177  * for instance if \p cpuset is \c NULL or empty.
0178  */
0179 HWLOC_DECLSPEC int
0180 hwloc_cpukinds_register(hwloc_topology_t topology,
0181                         hwloc_bitmap_t cpuset,
0182                         int forced_efficiency,
0183                         unsigned nr_infos, struct hwloc_info_s *infos,
0184                         unsigned long flags);
0185 
0186 /** @} */
0187 
0188 #ifdef __cplusplus
0189 } /* extern "C" */
0190 #endif
0191 
0192 
0193 #endif /* HWLOC_CPUKINDS_H */