| 1 | // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/core/info/icpuinfo.h`/ |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include <filesystem> |
| 7 | #include <memory> |
| 8 | #include <string> |
| 9 | #include <string_view> |
| 10 | #include <utility> |
| 11 | #include <vector> |
| 12 | |
| 13 | /// Interface to retrieve info of a physical cpu package. |
| 14 | class ICPUInfocxx . . $ ICPUInfo# |
| 15 | { |
| 16 | public: |
| 17 | struct Keyscxx . . $ ICPUInfo#Keys# |
| 18 | { |
| 19 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# vendorIdcxx . . $ ICPUInfo#Keys#vendorId.{"vendorid"}; |
| 20 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# cpuFamilycxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).{"cpufamily"}; |
| 21 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# modelcxx . . $ ICPUInfo#Keys#model.{"model"}; |
| 22 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# modelNamecxx . . $ ICPUInfo#Keys#modelName.{"modname"}; |
| 23 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# steppingcxx . . $ ICPUInfo#Keys#stepping.{"stepping"}; |
| 24 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# ucodecxx . . $ ICPUInfo#Keys#ucode.{"ucodev"}; |
| 25 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# l3Cachecxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).{"l3cache"}; |
| 26 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# executionUnitscxx . . $ ICPUInfo#Keys#executionUnits.{"exeunits"}; |
| 27 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# corescxx . . $ ICPUInfo#Keys#cores.{"cores"}; |
| 28 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# flagscxx . . $ ICPUInfo#Keys#flags.{"flags"}; |
| 29 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# bugscxx . . $ ICPUInfo#Keys#bugs.{"bugs"}; |
| 30 | static constexpr stdcxx . . $ std/::string_viewcxx . . $ std/string_view# bogomipscxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).{"bogomips"}; |
| 31 | }; |
| 32 | |
| 33 | /// An execution unit is exposed by the system as a single cpu. |
| 34 | struct ExecutionUnitcxx . . $ ICPUInfo#ExecutionUnit# |
| 35 | { |
| 36 | ExecutionUnitcxx . . $ ICPUInfo#ExecutionUnit#ExecutionUnit(29dc65b71c02a3d9).(int cpuId, int coreId, stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# sysPath) |
| 37 | : cpuIdcxx . . $ ICPUInfo#ExecutionUnit#cpuId.(cpuId) |
| 38 | , coreIdcxx . . $ ICPUInfo#ExecutionUnit#coreId.(coreId) |
| 39 | , sysPathcxx . . $ std/filesystem/__cxx11/path#path(91601bf9ad65ca31).(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(sysPath)) |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | /// cpu id exposed by the system |
| 44 | int const cpuIdcxx . . $ ICPUInfo#ExecutionUnit#cpuId.; |
| 45 | |
| 46 | /// core id on the physical cpu package in which the cpu resides |
| 47 | int const coreIdcxx . . $ ICPUInfo#ExecutionUnit#coreId.; |
| 48 | |
| 49 | /// sysfs path |
| 50 | stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# const sysPathcxx . . $ ICPUInfo#ExecutionUnit#sysPath.; |
| 51 | }; |
| 52 | |
| 53 | class IProvidercxx . . $ ICPUInfo#IProvider# |
| 54 | { |
| 55 | public: |
| 56 | virtual stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::stringcxx . . $ std/string#>> |
| 57 | provideInfocxx . . $ ICPUInfo#IProvider#provideInfo(ba0be1eb8c175b81).(int physicalId, |
| 58 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<ICPUInfocxx . . $ ICPUInfo#::ExecutionUnitcxx . . $ ICPUInfo#ExecutionUnit#> const &executionUnits) = 0; |
| 59 | |
| 60 | virtual stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> provideCapabilitiescxx . . $ ICPUInfo#IProvider#provideCapabilities(61866227792b2a60).( |
| 61 | int physicalId, |
| 62 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<ICPUInfocxx . . $ ICPUInfo#::ExecutionUnitcxx . . $ ICPUInfo#ExecutionUnit#> const &executionUnits) = 0; |
| 63 | |
| 64 | virtual ~cxx . . $ ICPUInfo#IProvider#`~IProvider`(49f6e7a06ebc5aa8).IProvidercxx . . $ ICPUInfo#IProvider#() = default; |
| 65 | }; |
| 66 | |
| 67 | class IProviderRegistrycxx . . $ ICPUInfo#IProviderRegistry# |
| 68 | { |
| 69 | public: |
| 70 | virtual stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<ICPUInfocxx . . $ ICPUInfo#::IProvidercxx . . $ ICPUInfo#IProvider#>> const & |
| 71 | cpuInfoProviderscxx . . $ ICPUInfo#IProviderRegistry#cpuInfoProviders(b09f5b0ca2a1a4eb).() const = 0; |
| 72 | |
| 73 | virtual ~cxx . . $ ICPUInfo#IProviderRegistry#`~IProviderRegistry`(ced63f7c635d850d).IProviderRegistrycxx . . $ ICPUInfo#IProviderRegistry#() = default; |
| 74 | }; |
| 75 | |
| 76 | /// @return physical id |
| 77 | virtual int physicalIdcxx . . $ ICPUInfo#physicalId(455f465bc33b4cdf).() const = 0; |
| 78 | |
| 79 | /// @return available execution units |
| 80 | virtual stdcxx . . $ std/::vectorcxx . . $ std/vector#<ICPUInfocxx . . $ ICPUInfo#::ExecutionUnitcxx . . $ ICPUInfo#ExecutionUnit#> const &executionUnitscxx . . $ ICPUInfo#executionUnits(d06c1a4c98578052).() const = 0; |
| 81 | |
| 82 | /// @returns collection of keys for the stored gpu information |
| 83 | virtual stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> keyscxx . . $ ICPUInfo#keys(491c255a7e496038).() const = 0; |
| 84 | |
| 85 | /// @returns string with gpu info or empty string when no info |
| 86 | /// is mapped to the key |
| 87 | virtual stdcxx . . $ std/::stringcxx . . $ std/string# infocxx . . $ ICPUInfo#info(3654cd48a63d288).(stdcxx . . $ std/::string_viewcxx . . $ std/string_view# key) const = 0; |
| 88 | |
| 89 | /// @returns true when a capability is present |
| 90 | virtual bool hasCapabilitycxx . . $ ICPUInfo#hasCapability(aa6d140991badc75).(stdcxx . . $ std/::string_viewcxx . . $ std/string_view# name) const = 0; |
| 91 | |
| 92 | /// Initialize cpu info |
| 93 | /// @param infoProviders information providers |
| 94 | virtual void initializecxx . . $ ICPUInfo#initialize(9f043417cf7016f2).( |
| 95 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<ICPUInfocxx . . $ ICPUInfo#::IProvidercxx . . $ ICPUInfo#IProvider#>> const &infoProviders) = 0; |
| 96 | |
| 97 | virtual ~cxx . . $ ICPUInfo#`~ICPUInfo`(49f6e7a06ebc5aa8).ICPUInfocxx . . $ ICPUInfo#() = default; |
| 98 | }; |