/** * @file include/ActivMiddleware/ActivBase/ProcessorAffinity.h * * @brief Header file for the processor affinity class. */ #if (!defined ACTIV_BASE_PROCESSOR_AFFINITY_H) #define ACTIV_BASE_PROCESSOR_AFFINITY_H #include "ActivMiddleware/ActivBase/External.h" #include "ActivMiddleware/ActivBase/CpuDetail.h" #include "ActivMiddleware/ActivBase/IniFileParser.h" //! Activ namespace. namespace Activ { /** * @brief Processor Affinity * * Handles the details of specifying a processor affinity for processes and threads. */ class ProcessorAffinity { public: typedef std::vector List; ///< A list that will store 0-based core ids. //! Default constructor. ACTIV_BASE_API ProcessorAffinity(); /** * @brief Read settings from an ini file section. * * @param sectionIterator iterator to an ini file section. * @param keyName optional key name override. * * @throw std::exception */ ACTIV_BASE_API void Read(const IniFileParser::ConstSectionIterator §ionIterator, const String &keyName = "ProcessorAffinity"); /** * @brief Parse an affinity string. * * @param processorAffinity a string defining a processor definition. * * @throw std::exception */ ACTIV_BASE_API void Parse(const String &processorAffinity); /** * @brief Initialize the processor affinities from a list of OS core ids. * * @param osCoreIdList the list of OS core ids. * * @retval STATUS_CODE_SUCCESS */ ACTIV_BASE_API StatusCode Initialize(const List &osCoreIdList); /** * @brief Initialize a single processor affinity from a string address definition. * * @param processorAddressString the string to initialize the affinity from. * The string should be in the following format: ":[:]" * e.g. "1:2:1" or "0:5" * The thread id is optional and will default to 0 if not specified. * Thread id is the id of the logical core within the physical core. It should always be 0 unless hyper-threading is * enabled in which case it may also be 1. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_INVALID_FORMAT @a processAddressString is incorrectly formatted. * @retval STATUS_CODE_NOT_FOUND processor address could not be found. */ ACTIV_BASE_API StatusCode Initialize(const String &processorAddressString); /** * @brief Initialize a single processor affinity from an OS core id. * * @param osCoreId the OS core id of the processor. * * @retval STATUS_CODE_SUCCESS */ ACTIV_BASE_API StatusCode Initialize(const CpuDetail::CoreId osCoreId); /** * @brief Initialize a single ProcessorAffinity from a CpuDetail object. * * @param cpuDetail the cpuDetail for the processor. * * @retval STATUS_CODE_SUCCESS */ ACTIV_BASE_API StatusCode Initialize(const CpuDetail &cpuDetail); //! Reset the object. ACTIV_BASE_API void Reset(); //! Indicates whether the Processor Affinity has been initialized. ACTIV_BASE_API bool IsInitialized() const; //! Indicates whether the Processor Affinity is to a single processor. ACTIV_BASE_API bool IsSingleProcessor() const; /** * @brief Get the list of OS core ids. * * @return The list of OS core ids. */ ACTIV_BASE_API const List &GetList() const; /** * @brief Get the cpu detail for the first processor affinity in the list. * * @return The CpuDetail for the first processor affinity. * * @throw Exception * @throw std::exception */ ACTIV_BASE_API const CpuDetail &GetFirstCpuDetail() const; //! Should use reordered core ids. ACTIV_BASE_API static bool ShouldUseReorderedCoreIds(); /** * @brief Convert processor affinity to a string. * * @return The string form of the processor affinity. */ ACTIV_BASE_API String ToString() const; /** * @brief Get affinity address string. * * @return For affinities to a single core the address of the core else "-". */ ACTIV_BASE_API String GetAddressString() const; private: /** * @brief Parse an affinity string list. * * @param processorAffinityList a string defining a processor definition. * * @throw Exception */ void Parse(const std::vector &processorAffinityList); List m_processorList; ///< The list of OS core ids. }; } // namespace Activ #endif // (!defined ACTIV_BASE_PROCESSOR_AFFINITY_H)