From ff6113bb00741efff872772dd2a3bd2856e42649 Mon Sep 17 00:00:00 2001 From: Markus Schmidl Date: Fri, 27 Sep 2024 16:21:48 +0200 Subject: [PATCH] second pass of clang-tidy for the header files. use unique_ptr for the payload instead of raw pointers --- .../firestarter/DumpRegisterWorkerData.hpp | 6 +- .../firestarter/Environment/CPUTopology.hpp | 60 +-- .../firestarter/Environment/Environment.hpp | 17 +- .../Environment/Payload/Payload.hpp | 3 +- .../Environment/Platform/PlatformConfig.hpp | 11 +- .../Environment/Platform/RuntimeConfig.hpp | 5 +- .../Environment/X86/Payload/AVX512Payload.hpp | 6 +- .../Environment/X86/Payload/AVXPayload.hpp | 6 +- .../Environment/X86/Payload/FMA4Payload.hpp | 6 +- .../Environment/X86/Payload/FMAPayload.hpp | 6 +- .../Environment/X86/Payload/SSE2Payload.hpp | 7 +- .../Environment/X86/Payload/X86Payload.hpp | 10 +- .../Environment/X86/Payload/ZENFMAPayload.hpp | 7 +- .../X86/Platform/BulldozerConfig.hpp | 12 +- .../X86/Platform/HaswellConfig.hpp | 10 +- .../X86/Platform/HaswellEPConfig.hpp | 12 +- .../X86/Platform/KnightsLandingConfig.hpp | 12 +- .../Environment/X86/Platform/NaplesConfig.hpp | 12 +- .../X86/Platform/NehalemConfig.hpp | 12 +- .../X86/Platform/NehalemEPConfig.hpp | 12 +- .../Environment/X86/Platform/RomeConfig.hpp | 12 +- .../X86/Platform/SandyBridgeConfig.hpp | 12 +- .../X86/Platform/SandyBridgeEPConfig.hpp | 12 +- .../X86/Platform/SkylakeConfig.hpp | 12 +- .../X86/Platform/SkylakeSPConfig.hpp | 12 +- .../X86/Platform/X86PlatformConfig.hpp | 45 +- .../Environment/X86/X86CPUTopology.hpp | 9 +- .../Environment/X86/X86Environment.hpp | 58 ++- include/firestarter/Firestarter.hpp | 20 +- include/firestarter/Json/Summary.hpp | 25 +- include/firestarter/LoadWorkerData.hpp | 8 +- .../Logging/FirstWorkerThreadFilter.hpp | 5 +- include/firestarter/Logging/Log.hpp | 42 +- .../Measurement/MeasurementWorker.hpp | 13 +- .../Measurement/Metric/IPCEstimate.h | 2 +- include/firestarter/Measurement/Metric/Perf.h | 2 +- include/firestarter/Measurement/Metric/RAPL.h | 2 +- include/firestarter/Measurement/Summary.hpp | 7 +- include/firestarter/Measurement/TimeValue.hpp | 2 +- include/firestarter/Optimizer/Algorithm.hpp | 2 +- .../firestarter/Optimizer/Algorithm/NSGA2.hpp | 2 +- include/firestarter/Optimizer/History.hpp | 158 +++---- .../firestarter/Optimizer/OptimizerWorker.hpp | 4 +- include/firestarter/Optimizer/Population.hpp | 5 +- include/firestarter/Optimizer/Problem.hpp | 4 +- .../Optimizer/Problem/CLIArgumentProblem.hpp | 6 +- .../Optimizer/Util/MultiObjective.hpp | 2 +- src/firestarter/Environment/CPUTopology.cpp | 401 +++++++++--------- .../Environment/X86/Payload/AVX512Payload.cpp | 9 +- .../Environment/X86/Payload/X86Payload.cpp | 1 + .../Environment/X86/X86CPUTopology.cpp | 228 +++++----- .../Environment/X86/X86Environment.cpp | 86 ++-- src/firestarter/LoadWorker.cpp | 4 +- src/firestarter/Main.cpp | 8 +- .../Measurement/MeasurementWorker.cpp | 2 + src/firestarter/Optimizer/Algorithm/NSGA2.cpp | 2 + src/firestarter/Optimizer/Population.cpp | 2 +- 57 files changed, 723 insertions(+), 735 deletions(-) diff --git a/include/firestarter/DumpRegisterWorkerData.hpp b/include/firestarter/DumpRegisterWorkerData.hpp index a05863d5..cf5e22ba 100644 --- a/include/firestarter/DumpRegisterWorkerData.hpp +++ b/include/firestarter/DumpRegisterWorkerData.hpp @@ -21,9 +21,9 @@ #pragma once +#include "LoadWorkerData.hpp" +#include "Logging/Log.hpp" #include -#include -#include #include #ifdef FIRESTARTER_DEBUG_FEATURES @@ -32,6 +32,8 @@ namespace firestarter { class DumpRegisterWorkerData { public: + DumpRegisterWorkerData() = delete; + DumpRegisterWorkerData(std::shared_ptr LoadWorkerDataPtr, std::chrono::seconds DumpTimeDelta, const std::string& DumpFilePath) : LoadWorkerDataPtr(std::move(LoadWorkerDataPtr)) diff --git a/include/firestarter/Environment/CPUTopology.hpp b/include/firestarter/Environment/CPUTopology.hpp index ba10df3c..c58933db 100644 --- a/include/firestarter/Environment/CPUTopology.hpp +++ b/include/firestarter/Environment/CPUTopology.hpp @@ -34,50 +34,52 @@ namespace firestarter::environment { class CPUTopology { public: - CPUTopology(std::string architecture); + explicit CPUTopology(std::string Architecture); virtual ~CPUTopology(); - unsigned numThreads() const { return _numThreadsPerCore * _numCoresTotal; } - unsigned maxNumThreads() const; - unsigned numThreadsPerCore() const { return _numThreadsPerCore; } - unsigned numCoresTotal() const { return _numCoresTotal; } - unsigned numPackages() const { return _numPackages; } + [[nodiscard]] auto numThreads() const -> unsigned { return NumThreadsPerCore * NumCoresTotal; } + [[nodiscard]] auto maxNumThreads() const -> unsigned; + [[nodiscard]] auto numThreadsPerCore() const -> unsigned { return NumThreadsPerCore; } + [[nodiscard]] auto numCoresTotal() const -> unsigned { return NumCoresTotal; } + [[nodiscard]] auto numPackages() const -> unsigned { return NumPackages; } - std::string const& architecture() const { return _architecture; } - virtual std::string const& vendor() const { return _vendor; } - virtual std::string const& processorName() const { return _processorName; } - virtual std::string const& model() const = 0; + [[nodiscard]] auto architecture() const -> std::string const& { return Architecture; } + [[nodiscard]] virtual auto vendor() const -> std::string const& { return Vendor; } + [[nodiscard]] virtual auto processorName() const -> std::string const& { return ProcessorName; } + [[nodiscard]] virtual auto model() const -> std::string const& { return Model; } // get the size of the L1i-cache in bytes - unsigned instructionCacheSize() const { return _instructionCacheSize; } + [[nodiscard]] auto instructionCacheSize() const -> unsigned { return InstructionCacheSize; } // return the cpu clockrate in Hz - virtual uint64_t clockrate() const { return _clockrate; } + [[nodiscard]] virtual auto clockrate() const -> uint64_t { return Clockrate; } // return the cpu features - virtual std::list const& features() const = 0; + [[nodiscard]] virtual auto features() const -> std::list const& = 0; // get a timestamp - virtual uint64_t timestamp() const = 0; + [[nodiscard]] virtual auto timestamp() const -> uint64_t = 0; - int getPkgIdFromPU(unsigned pu) const; - int getCoreIdFromPU(unsigned pu) const; + [[nodiscard]] auto getPkgIdFromPU(unsigned Pu) const -> int; + [[nodiscard]] auto getCoreIdFromPU(unsigned Pu) const -> int; protected: - std::string scalingGovernor() const; - std::ostream& print(std::ostream& stream) const; + [[nodiscard]] static auto scalingGovernor() -> std::string; + [[nodiscard]] auto print(std::ostream& Stream) const -> std::ostream&; + + std::string Vendor; + std::string Model; private: - static std::stringstream getFileAsStream(std::string const& filePath); - - unsigned _numThreadsPerCore; - unsigned _numCoresTotal; - unsigned _numPackages; - std::string _architecture; - std::string _vendor = ""; - std::string _processorName = ""; - unsigned _instructionCacheSize = 0; - uint64_t _clockrate = 0; - hwloc_topology_t topology; + [[nodiscard]] static auto getFileAsStream(std::string const& FilePath) -> std::stringstream; + + unsigned NumThreadsPerCore; + unsigned NumCoresTotal; + unsigned NumPackages; + std::string Architecture; + std::string ProcessorName; + unsigned InstructionCacheSize = 0; + uint64_t Clockrate = 0; + hwloc_topology_t Topology; }; } // namespace firestarter::environment diff --git a/include/firestarter/Environment/Environment.hpp b/include/firestarter/Environment/Environment.hpp index 5f204ccc..57e60094 100644 --- a/include/firestarter/Environment/Environment.hpp +++ b/include/firestarter/Environment/Environment.hpp @@ -21,11 +21,10 @@ #pragma once +#include "CPUTopology.hpp" +#include "Platform/RuntimeConfig.hpp" #include #include -#include -#include -#include #include namespace firestarter::environment { @@ -33,13 +32,9 @@ namespace firestarter::environment { class Environment { public: Environment() = delete; - explicit Environment(CPUTopology* Topology) - : Topology(Topology) {} - virtual ~Environment() { - delete this->Topology; - - delete SelectedConfig; - } + explicit Environment(std::unique_ptr&& Topology) + : Topology(std::move(Topology)) {} + virtual ~Environment() { delete SelectedConfig; } auto evaluateCpuAffinity(unsigned RequestedNumThreads, std::string CpuBind) -> int; auto setCpuAffinity(unsigned Thread) -> int; @@ -77,7 +72,7 @@ class Environment { protected: platform::RuntimeConfig* SelectedConfig = nullptr; - CPUTopology* Topology = nullptr; + std::unique_ptr Topology; private: uint64_t RequestedNumThreads = 0; diff --git a/include/firestarter/Environment/Payload/Payload.hpp b/include/firestarter/Environment/Payload/Payload.hpp index 3871400f..9c37bdfc 100644 --- a/include/firestarter/Environment/Payload/Payload.hpp +++ b/include/firestarter/Environment/Payload/Payload.hpp @@ -22,6 +22,7 @@ #pragma once #include +#include #include #include #include @@ -101,7 +102,7 @@ class Payload { [[nodiscard]] virtual auto highLoadFunction(uint64_t* AddrMem, volatile uint64_t* AddrHigh, uint64_t Iterations) -> uint64_t = 0; - [[nodiscard]] virtual auto clone() const -> Payload* = 0; + [[nodiscard]] virtual auto clone() const -> std::unique_ptr = 0; }; } // namespace firestarter::environment::payload diff --git a/include/firestarter/Environment/Platform/PlatformConfig.hpp b/include/firestarter/Environment/Platform/PlatformConfig.hpp index 5588cb8a..954b6682 100644 --- a/include/firestarter/Environment/Platform/PlatformConfig.hpp +++ b/include/firestarter/Environment/Platform/PlatformConfig.hpp @@ -21,8 +21,7 @@ #pragma once -#include -#include +#include "../Payload/Payload.hpp" #include #include #include @@ -35,7 +34,7 @@ class PlatformConfig { private: std::string Name; std::list Threads; - payload::Payload* Payload; + std::unique_ptr Payload; protected: unsigned InstructionCacheSize; @@ -48,15 +47,15 @@ class PlatformConfig { PlatformConfig(std::string Name, std::list Threads, unsigned InstructionCacheSize, std::initializer_list DataCacheBufferSize, unsigned RamBufferSize, unsigned Lines, - payload::Payload* Payload) + std::unique_ptr&& Payload) : Name(std::move(Name)) , Threads(std::move(Threads)) - , Payload(Payload) + , Payload(std::move(Payload)) , InstructionCacheSize(InstructionCacheSize) , DataCacheBufferSize(DataCacheBufferSize) , RamBufferSize(RamBufferSize) , Lines(Lines) {} - virtual ~PlatformConfig() { delete Payload; } + virtual ~PlatformConfig() = default; [[nodiscard]] auto name() const -> const std::string& { return Name; } [[nodiscard]] auto instructionCacheSize() const -> unsigned { return InstructionCacheSize; } diff --git a/include/firestarter/Environment/Platform/RuntimeConfig.hpp b/include/firestarter/Environment/Platform/RuntimeConfig.hpp index 3d1d1786..17770e97 100644 --- a/include/firestarter/Environment/Platform/RuntimeConfig.hpp +++ b/include/firestarter/Environment/Platform/RuntimeConfig.hpp @@ -21,8 +21,9 @@ #pragma once +#include "../../Logging/Log.hpp" +#include "../Platform/PlatformConfig.hpp" #include -#include namespace firestarter::environment::platform { @@ -62,7 +63,7 @@ class RuntimeConfig { , RamBufferSize(Other.ramBufferSize()) , Lines(Other.lines()) {} - ~RuntimeConfig() { Payload.reset(); } + ~RuntimeConfig() = default; [[nodiscard]] auto platformConfig() const -> PlatformConfig const& { return PlatformConfigValue; } [[nodiscard]] auto payload() const -> payload::Payload& { diff --git a/include/firestarter/Environment/X86/Payload/AVX512Payload.hpp b/include/firestarter/Environment/X86/Payload/AVX512Payload.hpp index 317b8196..9478353e 100644 --- a/include/firestarter/Environment/X86/Payload/AVX512Payload.hpp +++ b/include/firestarter/Environment/X86/Payload/AVX512Payload.hpp @@ -21,7 +21,7 @@ #pragma once -#include +#include "X86Payload.hpp" namespace firestarter::environment::x86::payload { class AVX512Payload final : public X86Payload { @@ -37,8 +37,8 @@ class AVX512Payload final : public X86Payload { [[nodiscard]] auto getAvailableInstructions() const -> std::list override; void init(uint64_t* MemoryAddr, uint64_t BufferSize) override; - [[nodiscard]] auto clone() const -> firestarter::environment::payload::Payload* override { - return new AVX512Payload(this->supportedFeatures()); + [[nodiscard]] auto clone() const -> std::unique_ptr override { + return std::make_unique(this->supportedFeatures()); }; private: diff --git a/include/firestarter/Environment/X86/Payload/AVXPayload.hpp b/include/firestarter/Environment/X86/Payload/AVXPayload.hpp index 6516c0de..ca6cac6d 100644 --- a/include/firestarter/Environment/X86/Payload/AVXPayload.hpp +++ b/include/firestarter/Environment/X86/Payload/AVXPayload.hpp @@ -21,7 +21,7 @@ #pragma once -#include +#include "X86Payload.hpp" namespace firestarter::environment::x86::payload { class AVXPayload final : public X86Payload { @@ -37,8 +37,8 @@ class AVXPayload final : public X86Payload { [[nodiscard]] auto getAvailableInstructions() const -> std::list override; void init(uint64_t* MemoryAddr, uint64_t BufferSize) override; - [[nodiscard]] auto clone() const -> firestarter::environment::payload::Payload* override { - return new AVXPayload(this->supportedFeatures()); + [[nodiscard]] auto clone() const -> std::unique_ptr override { + return std::make_unique(this->supportedFeatures()); }; private: diff --git a/include/firestarter/Environment/X86/Payload/FMA4Payload.hpp b/include/firestarter/Environment/X86/Payload/FMA4Payload.hpp index bb623e68..ccc43d00 100644 --- a/include/firestarter/Environment/X86/Payload/FMA4Payload.hpp +++ b/include/firestarter/Environment/X86/Payload/FMA4Payload.hpp @@ -21,7 +21,7 @@ #pragma once -#include +#include "X86Payload.hpp" namespace firestarter::environment::x86::payload { @@ -39,8 +39,8 @@ class FMA4Payload final : public X86Payload { [[nodiscard]] auto getAvailableInstructions() const -> std::list override; void init(uint64_t* MemoryAddr, uint64_t BufferSize) override; - [[nodiscard]] auto clone() const -> firestarter::environment::payload::Payload* override { - return new FMA4Payload(this->supportedFeatures()); + [[nodiscard]] auto clone() const -> std::unique_ptr override { + return std::make_unique(this->supportedFeatures()); }; private: diff --git a/include/firestarter/Environment/X86/Payload/FMAPayload.hpp b/include/firestarter/Environment/X86/Payload/FMAPayload.hpp index b610a838..a8443b97 100644 --- a/include/firestarter/Environment/X86/Payload/FMAPayload.hpp +++ b/include/firestarter/Environment/X86/Payload/FMAPayload.hpp @@ -21,7 +21,7 @@ #pragma once -#include +#include "X86Payload.hpp" namespace firestarter::environment::x86::payload { class FMAPayload final : public X86Payload { @@ -37,8 +37,8 @@ class FMAPayload final : public X86Payload { [[nodiscard]] auto getAvailableInstructions() const -> std::list override; void init(uint64_t* MemoryAddr, uint64_t BufferSize) override; - [[nodiscard]] auto clone() const -> firestarter::environment::payload::Payload* override { - return new FMAPayload(this->supportedFeatures()); + [[nodiscard]] auto clone() const -> std::unique_ptr override { + return std::make_unique(this->supportedFeatures()); }; private: diff --git a/include/firestarter/Environment/X86/Payload/SSE2Payload.hpp b/include/firestarter/Environment/X86/Payload/SSE2Payload.hpp index 538837b4..5e363432 100644 --- a/include/firestarter/Environment/X86/Payload/SSE2Payload.hpp +++ b/include/firestarter/Environment/X86/Payload/SSE2Payload.hpp @@ -21,8 +21,7 @@ #pragma once -#include -#include +#include "X86Payload.hpp" namespace firestarter::environment::x86::payload { class SSE2Payload final : public X86Payload { @@ -38,8 +37,8 @@ class SSE2Payload final : public X86Payload { [[nodiscard]] auto getAvailableInstructions() const -> std::list override; void init(uint64_t* MemoryAddr, uint64_t BufferSize) override; - [[nodiscard]] auto clone() const -> firestarter::environment::payload::Payload* override { - return new SSE2Payload(this->supportedFeatures()); + [[nodiscard]] auto clone() const -> std::unique_ptr override { + return std::make_unique(this->supportedFeatures()); }; private: diff --git a/include/firestarter/Environment/X86/Payload/X86Payload.hpp b/include/firestarter/Environment/X86/Payload/X86Payload.hpp index 9e947143..2e38b855 100644 --- a/include/firestarter/Environment/X86/Payload/X86Payload.hpp +++ b/include/firestarter/Environment/X86/Payload/X86Payload.hpp @@ -21,13 +21,13 @@ #pragma once +#include "../../../Constants.hpp" // IWYU pragma: keep +#include "../../../DumpRegisterStruct.hpp" // IWYU pragma: keep +#include "../../../Logging/Log.hpp" // IWYU pragma: keep +#include "../../Payload/Payload.hpp" #include - #include -#include -#include -#include -#include +#include // IWYU pragma: keep #include #define INIT_BLOCKSIZE 1024 diff --git a/include/firestarter/Environment/X86/Payload/ZENFMAPayload.hpp b/include/firestarter/Environment/X86/Payload/ZENFMAPayload.hpp index 425dd600..35746efc 100644 --- a/include/firestarter/Environment/X86/Payload/ZENFMAPayload.hpp +++ b/include/firestarter/Environment/X86/Payload/ZENFMAPayload.hpp @@ -21,8 +21,7 @@ #pragma once -#include -#include +#include "X86Payload.hpp" namespace firestarter::environment::x86::payload { class ZENFMAPayload final : public X86Payload { @@ -39,8 +38,8 @@ class ZENFMAPayload final : public X86Payload { [[nodiscard]] auto getAvailableInstructions() const -> std::list override; void init(uint64_t* MemoryAddr, uint64_t BufferSize) override; - [[nodiscard]] auto clone() const -> firestarter::environment::payload::Payload* override { - return new ZENFMAPayload(this->supportedFeatures()); + [[nodiscard]] auto clone() const -> std::unique_ptr override { + return std::make_unique(this->supportedFeatures()); }; private: diff --git a/include/firestarter/Environment/X86/Platform/BulldozerConfig.hpp b/include/firestarter/Environment/X86/Platform/BulldozerConfig.hpp index 4cc4b811..fc7e5337 100644 --- a/include/firestarter/Environment/X86/Platform/BulldozerConfig.hpp +++ b/include/firestarter/Environment/X86/Platform/BulldozerConfig.hpp @@ -21,17 +21,17 @@ #pragma once -#include -#include +#include "../Payload/FMA4Payload.hpp" +#include "X86PlatformConfig.hpp" namespace firestarter::environment::x86::platform { class BulldozerConfig final : public X86PlatformConfig { public: - BulldozerConfig(asmjit::CpuFeatures const& supportedFeatures, unsigned family, unsigned model, unsigned threads) - : X86PlatformConfig("BLD_OPTERON", 21, {1, 2, 3}, {1}, 0, {16384, 1048576, 786432}, 104857600, 1536, family, - model, threads, new payload::FMA4Payload(supportedFeatures)) {} + BulldozerConfig(asmjit::CpuFeatures const& SupportedFeatures, unsigned Family, unsigned Model, unsigned Threads) + : X86PlatformConfig("BLD_OPTERON", 21, {1, 2, 3}, {1}, 0, {16384, 1048576, 786432}, 104857600, 1536, Family, + Model, Threads, std::make_unique(SupportedFeatures)) {} - std::vector> getDefaultPayloadSettings() const override { + [[nodiscard]] auto getDefaultPayloadSettings() const -> std::vector> override { return std::vector>( {{"RAM_L", 1}, {"L3_L", 1}, {"L2_LS", 5}, {"L1_L", 90}, {"REG", 45}}); } diff --git a/include/firestarter/Environment/X86/Platform/HaswellConfig.hpp b/include/firestarter/Environment/X86/Platform/HaswellConfig.hpp index 5b30d6a0..00bf3199 100644 --- a/include/firestarter/Environment/X86/Platform/HaswellConfig.hpp +++ b/include/firestarter/Environment/X86/Platform/HaswellConfig.hpp @@ -21,17 +21,17 @@ #pragma once -#include -#include +#include "../Payload/FMAPayload.hpp" +#include "X86PlatformConfig.hpp" namespace firestarter::environment::x86::platform { class HaswellConfig final : public X86PlatformConfig { public: - HaswellConfig(asmjit::CpuFeatures const& supportedFeatures, unsigned family, unsigned model, unsigned threads) + HaswellConfig(asmjit::CpuFeatures const& SupportedFeatures, unsigned Family, unsigned Model, unsigned Threads) : X86PlatformConfig("HSW_COREI", 6, {60, 61, 69, 70, 71}, {1, 2}, 0, {32768, 262144, 1572864}, 104857600, 1536, - family, model, threads, new payload::FMAPayload(supportedFeatures)) {} + Family, Model, Threads, std::make_unique(SupportedFeatures)) {} - std::vector> getDefaultPayloadSettings() const override { + [[nodiscard]] auto getDefaultPayloadSettings() const -> std::vector> override { return std::vector>( {{"RAM_L", 2}, {"L3_LS", 3}, {"L2_LS", 9}, {"L1_LS", 90}, {"REG", 40}}); } diff --git a/include/firestarter/Environment/X86/Platform/HaswellEPConfig.hpp b/include/firestarter/Environment/X86/Platform/HaswellEPConfig.hpp index 106dd0e3..d5df3341 100644 --- a/include/firestarter/Environment/X86/Platform/HaswellEPConfig.hpp +++ b/include/firestarter/Environment/X86/Platform/HaswellEPConfig.hpp @@ -21,17 +21,17 @@ #pragma once -#include -#include +#include "../Payload/FMAPayload.hpp" +#include "X86PlatformConfig.hpp" namespace firestarter::environment::x86::platform { class HaswellEPConfig final : public X86PlatformConfig { public: - HaswellEPConfig(asmjit::CpuFeatures const& supportedFeatures, unsigned family, unsigned model, unsigned threads) - : X86PlatformConfig("HSW_XEONEP", 6, {63, 79}, {1, 2}, 0, {32768, 262144, 2621440}, 104857600, 1536, family, - model, threads, new payload::FMAPayload(supportedFeatures)) {} + HaswellEPConfig(asmjit::CpuFeatures const& SupportedFeatures, unsigned Family, unsigned Model, unsigned Threads) + : X86PlatformConfig("HSW_XEONEP", 6, {63, 79}, {1, 2}, 0, {32768, 262144, 2621440}, 104857600, 1536, Family, + Model, Threads, std::make_unique(SupportedFeatures)) {} - std::vector> getDefaultPayloadSettings() const override { + [[nodiscard]] auto getDefaultPayloadSettings() const -> std::vector> override { return std::vector>( {{"RAM_L", 8}, {"L3_LS", 1}, {"L2_LS", 29}, {"L1_LS", 100}, {"REG", 100}}); } diff --git a/include/firestarter/Environment/X86/Platform/KnightsLandingConfig.hpp b/include/firestarter/Environment/X86/Platform/KnightsLandingConfig.hpp index 709ef934..cbc7d976 100644 --- a/include/firestarter/Environment/X86/Platform/KnightsLandingConfig.hpp +++ b/include/firestarter/Environment/X86/Platform/KnightsLandingConfig.hpp @@ -21,17 +21,17 @@ #pragma once -#include -#include +#include "../Payload/AVX512Payload.hpp" +#include "X86PlatformConfig.hpp" namespace firestarter::environment::x86::platform { class KnightsLandingConfig final : public X86PlatformConfig { public: - KnightsLandingConfig(asmjit::CpuFeatures const& supportedFeatures, unsigned family, unsigned model, unsigned threads) - : X86PlatformConfig("KNL_XEONPHI", 6, {87}, {4}, 0, {32768, 524288, 236279125}, 26214400, 1536, family, model, - threads, new payload::AVX512Payload(supportedFeatures)) {} + KnightsLandingConfig(asmjit::CpuFeatures const& SupportedFeatures, unsigned Family, unsigned Model, unsigned Threads) + : X86PlatformConfig("KNL_XEONPHI", 6, {87}, {4}, 0, {32768, 524288, 236279125}, 26214400, 1536, Family, Model, + Threads, std::make_unique(SupportedFeatures)) {} - std::vector> getDefaultPayloadSettings() const override { + [[nodiscard]] auto getDefaultPayloadSettings() const -> std::vector> override { return std::vector>({{"RAM_P", 3}, {"L2_S", 8}, {"L1_L", 40}, {"REG", 10}}); } }; diff --git a/include/firestarter/Environment/X86/Platform/NaplesConfig.hpp b/include/firestarter/Environment/X86/Platform/NaplesConfig.hpp index 5ad0a065..56f5bdc6 100644 --- a/include/firestarter/Environment/X86/Platform/NaplesConfig.hpp +++ b/include/firestarter/Environment/X86/Platform/NaplesConfig.hpp @@ -21,17 +21,17 @@ #pragma once -#include -#include +#include "../Payload/ZENFMAPayload.hpp" +#include "X86PlatformConfig.hpp" namespace firestarter::environment::x86::platform { class NaplesConfig final : public X86PlatformConfig { public: - NaplesConfig(asmjit::CpuFeatures const& supportedFeatures, unsigned family, unsigned model, unsigned threads) - : X86PlatformConfig("ZEN_EPYC", 23, {1, 8, 17, 24}, {1, 2}, 0, {65536, 524288, 2097152}, 104857600, 1536, family, - model, threads, new payload::ZENFMAPayload(supportedFeatures)) {} + NaplesConfig(asmjit::CpuFeatures const& SupportedFeatures, unsigned Family, unsigned Model, unsigned Threads) + : X86PlatformConfig("ZEN_EPYC", 23, {1, 8, 17, 24}, {1, 2}, 0, {65536, 524288, 2097152}, 104857600, 1536, Family, + Model, Threads, std::make_unique(SupportedFeatures)) {} - std::vector> getDefaultPayloadSettings() const override { + [[nodiscard]] auto getDefaultPayloadSettings() const -> std::vector> override { return std::vector>( {{"RAM_L", 3}, {"L3_L", 14}, {"L2_L", 75}, {"L1_LS", 81}, {"REG", 100}}); } diff --git a/include/firestarter/Environment/X86/Platform/NehalemConfig.hpp b/include/firestarter/Environment/X86/Platform/NehalemConfig.hpp index 3f0748de..320d29f4 100644 --- a/include/firestarter/Environment/X86/Platform/NehalemConfig.hpp +++ b/include/firestarter/Environment/X86/Platform/NehalemConfig.hpp @@ -21,17 +21,17 @@ #pragma once -#include -#include +#include "../Payload/SSE2Payload.hpp" +#include "X86PlatformConfig.hpp" namespace firestarter::environment::x86::platform { class NehalemConfig final : public X86PlatformConfig { public: - NehalemConfig(asmjit::CpuFeatures const& supportedFeatures, unsigned family, unsigned model, unsigned threads) - : X86PlatformConfig("NHM_COREI", 6, {30, 37, 23}, {1, 2}, 0, {32768, 262144, 1572864}, 104857600, 1536, family, - model, threads, new payload::SSE2Payload(supportedFeatures)) {} + NehalemConfig(asmjit::CpuFeatures const& SupportedFeatures, unsigned Family, unsigned Model, unsigned Threads) + : X86PlatformConfig("NHM_COREI", 6, {30, 37, 23}, {1, 2}, 0, {32768, 262144, 1572864}, 104857600, 1536, Family, + Model, Threads, std::make_unique(SupportedFeatures)) {} - std::vector> getDefaultPayloadSettings() const override { + [[nodiscard]] auto getDefaultPayloadSettings() const -> std::vector> override { return std::vector>({{"RAM_P", 1}, {"L1_LS", 70}, {"REG", 2}}); } }; diff --git a/include/firestarter/Environment/X86/Platform/NehalemEPConfig.hpp b/include/firestarter/Environment/X86/Platform/NehalemEPConfig.hpp index a738fb7f..c9d032da 100644 --- a/include/firestarter/Environment/X86/Platform/NehalemEPConfig.hpp +++ b/include/firestarter/Environment/X86/Platform/NehalemEPConfig.hpp @@ -21,17 +21,17 @@ #pragma once -#include -#include +#include "../Payload/SSE2Payload.hpp" +#include "X86PlatformConfig.hpp" namespace firestarter::environment::x86::platform { class NehalemEPConfig final : public X86PlatformConfig { public: - NehalemEPConfig(asmjit::CpuFeatures const& supportedFeatures, unsigned family, unsigned model, unsigned threads) - : X86PlatformConfig("NHM_XEONEP", 6, {26, 44}, {1, 2}, 0, {32768, 262144, 2097152}, 104857600, 1536, family, - model, threads, new payload::SSE2Payload(supportedFeatures)) {} + NehalemEPConfig(asmjit::CpuFeatures const& SupportedFeatures, unsigned Family, unsigned Model, unsigned Threads) + : X86PlatformConfig("NHM_XEONEP", 6, {26, 44}, {1, 2}, 0, {32768, 262144, 2097152}, 104857600, 1536, Family, + Model, Threads, std::make_unique(SupportedFeatures)) {} - std::vector> getDefaultPayloadSettings() const override { + [[nodiscard]] auto getDefaultPayloadSettings() const -> std::vector> override { return std::vector>({{"RAM_P", 1}, {"L1_LS", 60}, {"REG", 2}}); } }; diff --git a/include/firestarter/Environment/X86/Platform/RomeConfig.hpp b/include/firestarter/Environment/X86/Platform/RomeConfig.hpp index 230d91ba..c8c1ea73 100644 --- a/include/firestarter/Environment/X86/Platform/RomeConfig.hpp +++ b/include/firestarter/Environment/X86/Platform/RomeConfig.hpp @@ -21,17 +21,17 @@ #pragma once -#include -#include +#include "../Payload/FMAPayload.hpp" +#include "X86PlatformConfig.hpp" namespace firestarter::environment::x86::platform { class RomeConfig final : public X86PlatformConfig { public: - RomeConfig(asmjit::CpuFeatures const& supportedFeatures, unsigned family, unsigned model, unsigned threads) - : X86PlatformConfig("ZEN_2_EPYC", 23, {49}, {1, 2}, 0, {32768, 524288, 2097152}, 104857600, 1536, family, model, - threads, new payload::FMAPayload(supportedFeatures)) {} + RomeConfig(asmjit::CpuFeatures const& SupportedFeatures, unsigned Family, unsigned Model, unsigned Threads) + : X86PlatformConfig("ZEN_2_EPYC", 23, {49}, {1, 2}, 0, {32768, 524288, 2097152}, 104857600, 1536, Family, Model, + Threads, std::make_unique(SupportedFeatures)) {} - std::vector> getDefaultPayloadSettings() const override { + [[nodiscard]] auto getDefaultPayloadSettings() const -> std::vector> override { return std::vector>( {{"RAM_L", 10}, {"L3_L", 25}, {"L2_L", 91}, {"L1_2LS_256", 72}, {"L1_LS_256", 82}, {"REG", 75}}); } diff --git a/include/firestarter/Environment/X86/Platform/SandyBridgeConfig.hpp b/include/firestarter/Environment/X86/Platform/SandyBridgeConfig.hpp index a58e193a..5ceef9ff 100644 --- a/include/firestarter/Environment/X86/Platform/SandyBridgeConfig.hpp +++ b/include/firestarter/Environment/X86/Platform/SandyBridgeConfig.hpp @@ -21,17 +21,17 @@ #pragma once -#include -#include +#include "../Payload/AVXPayload.hpp" +#include "X86PlatformConfig.hpp" namespace firestarter::environment::x86::platform { class SandyBridgeConfig final : public X86PlatformConfig { public: - SandyBridgeConfig(asmjit::CpuFeatures const& supportedFeatures, unsigned family, unsigned model, unsigned threads) - : X86PlatformConfig("SNB_COREI", 6, {42, 58}, {1, 2}, 0, {32768, 262144, 1572864}, 104857600, 1536, family, model, - threads, new payload::AVXPayload(supportedFeatures)) {} + SandyBridgeConfig(asmjit::CpuFeatures const& SupportedFeatures, unsigned Family, unsigned Model, unsigned Threads) + : X86PlatformConfig("SNB_COREI", 6, {42, 58}, {1, 2}, 0, {32768, 262144, 1572864}, 104857600, 1536, Family, Model, + Threads, std::make_unique(SupportedFeatures)) {} - std::vector> getDefaultPayloadSettings() const override { + [[nodiscard]] auto getDefaultPayloadSettings() const -> std::vector> override { return std::vector>( {{"RAM_L", 2}, {"L3_LS", 4}, {"L2_LS", 10}, {"L1_LS", 90}, {"REG", 45}}); } diff --git a/include/firestarter/Environment/X86/Platform/SandyBridgeEPConfig.hpp b/include/firestarter/Environment/X86/Platform/SandyBridgeEPConfig.hpp index 3f4f6303..8449bee1 100644 --- a/include/firestarter/Environment/X86/Platform/SandyBridgeEPConfig.hpp +++ b/include/firestarter/Environment/X86/Platform/SandyBridgeEPConfig.hpp @@ -22,17 +22,17 @@ #ifndef INCLUDE_FIRESTARTER_ENVIRONMENT_X86_PLATFORM_SANDYBRIDGEEPCONFIG_H #define INCLUDE_FIRESTARTER_ENVIRONMENT_X86_PLATFORM_SANDYBRIDGEEPCONFIG_H -#include -#include +#include "../Payload/AVXPayload.hpp" +#include "X86PlatformConfig.hpp" namespace firestarter::environment::x86::platform { class SandyBridgeEPConfig final : public X86PlatformConfig { public: - SandyBridgeEPConfig(asmjit::CpuFeatures const& supportedFeatures, unsigned family, unsigned model, unsigned threads) - : X86PlatformConfig("SNB_XEONEP", 6, {45, 62}, {1, 2}, 0, {32768, 262144, 2621440}, 104857600, 1536, family, - model, threads, new payload::AVXPayload(supportedFeatures)) {} + SandyBridgeEPConfig(asmjit::CpuFeatures const& SupportedFeatures, unsigned Family, unsigned Model, unsigned Threads) + : X86PlatformConfig("SNB_XEONEP", 6, {45, 62}, {1, 2}, 0, {32768, 262144, 2621440}, 104857600, 1536, Family, + Model, Threads, std::make_unique(SupportedFeatures)) {} - std::vector> getDefaultPayloadSettings() const override { + [[nodiscard]] auto getDefaultPayloadSettings() const -> std::vector> override { return std::vector>( {{"RAM_L", 3}, {"L3_LS", 2}, {"L2_LS", 10}, {"L1_LS", 90}, {"REG", 30}}); } diff --git a/include/firestarter/Environment/X86/Platform/SkylakeConfig.hpp b/include/firestarter/Environment/X86/Platform/SkylakeConfig.hpp index c533c3a5..1437ce98 100644 --- a/include/firestarter/Environment/X86/Platform/SkylakeConfig.hpp +++ b/include/firestarter/Environment/X86/Platform/SkylakeConfig.hpp @@ -22,17 +22,17 @@ #ifndef INCLUDE_FIRESTARTER_ENVIRONMENT_X86_PLATFORM_SKYLAKECONFIG_H #define INCLUDE_FIRESTARTER_ENVIRONMENT_X86_PLATFORM_SKYLAKECONFIG_H -#include -#include +#include "../Payload/FMAPayload.hpp" +#include "X86PlatformConfig.hpp" namespace firestarter::environment::x86::platform { class SkylakeConfig final : public X86PlatformConfig { public: - SkylakeConfig(asmjit::CpuFeatures const& supportedFeatures, unsigned family, unsigned model, unsigned threads) - : X86PlatformConfig("SKL_COREI", 6, {78, 94}, {1, 2}, 0, {32768, 262144, 1572864}, 104857600, 1536, family, model, - threads, new payload::FMAPayload(supportedFeatures)) {} + SkylakeConfig(asmjit::CpuFeatures const& SupportedFeatures, unsigned Family, unsigned Model, unsigned Threads) + : X86PlatformConfig("SKL_COREI", 6, {78, 94}, {1, 2}, 0, {32768, 262144, 1572864}, 104857600, 1536, Family, Model, + Threads, std::make_unique(SupportedFeatures)) {} - std::vector> getDefaultPayloadSettings() const override { + [[nodiscard]] auto getDefaultPayloadSettings() const -> std::vector> override { return std::vector>( {{"RAM_L", 3}, {"L3_LS_256", 5}, {"L2_LS_256", 18}, {"L1_2LS_256", 78}, {"REG", 40}}); } diff --git a/include/firestarter/Environment/X86/Platform/SkylakeSPConfig.hpp b/include/firestarter/Environment/X86/Platform/SkylakeSPConfig.hpp index 8243d9d6..8a91b6de 100644 --- a/include/firestarter/Environment/X86/Platform/SkylakeSPConfig.hpp +++ b/include/firestarter/Environment/X86/Platform/SkylakeSPConfig.hpp @@ -21,17 +21,17 @@ #pragma once -#include -#include +#include "../Payload/AVX512Payload.hpp" +#include "X86PlatformConfig.hpp" namespace firestarter::environment::x86::platform { class SkylakeSPConfig final : public X86PlatformConfig { public: - SkylakeSPConfig(asmjit::CpuFeatures const& supportedFeatures, unsigned family, unsigned model, unsigned threads) - : X86PlatformConfig("SKL_XEONEP", 6, {85}, {1, 2}, 0, {32768, 1048576, 1441792}, 1048576000, 1536, family, model, - threads, new payload::AVX512Payload(supportedFeatures)) {} + SkylakeSPConfig(asmjit::CpuFeatures const& SupportedFeatures, unsigned Family, unsigned Model, unsigned Threads) + : X86PlatformConfig("SKL_XEONEP", 6, {85}, {1, 2}, 0, {32768, 1048576, 1441792}, 1048576000, 1536, Family, Model, + Threads, std::make_unique(SupportedFeatures)) {} - std::vector> getDefaultPayloadSettings() const override { + [[nodiscard]] auto getDefaultPayloadSettings() const -> std::vector> override { return std::vector>({{"RAM_S", 3}, {"RAM_P", 1}, {"L3_S", 1}, diff --git a/include/firestarter/Environment/X86/Platform/X86PlatformConfig.hpp b/include/firestarter/Environment/X86/Platform/X86PlatformConfig.hpp index 648346d8..3d33756c 100644 --- a/include/firestarter/Environment/X86/Platform/X86PlatformConfig.hpp +++ b/include/firestarter/Environment/X86/Platform/X86PlatformConfig.hpp @@ -21,34 +21,39 @@ #pragma once -#include -#include +#include "../../Platform/PlatformConfig.hpp" +#include "../Payload/X86Payload.hpp" +#include +#include +#include +#include // IWYU pragma: keep namespace firestarter::environment::x86::platform { class X86PlatformConfig : public environment::platform::PlatformConfig { private: - unsigned _family; - std::list _models; - unsigned _currentFamily; - unsigned _currentModel; - unsigned _currentThreads; + unsigned Family; + std::list Models; + unsigned CurrentFamily; + unsigned CurrentModel; + unsigned CurrentThreads; public: - X86PlatformConfig(std::string name, unsigned family, std::initializer_list models, - std::initializer_list threads, unsigned instructionCacheSize, - std::initializer_list dataCacheBufferSize, unsigned ramBuffersize, unsigned lines, - unsigned currentFamily, unsigned currentModel, unsigned currentThreads, - payload::X86Payload* payload) - : PlatformConfig(name, threads, instructionCacheSize, dataCacheBufferSize, ramBuffersize, lines, payload) - , _family(family) - , _models(models) - , _currentFamily(currentFamily) - , _currentModel(currentModel) - , _currentThreads(currentThreads) {} + X86PlatformConfig(std::string Name, unsigned Family, std::initializer_list Models, + std::initializer_list Threads, unsigned InstructionCacheSize, + std::initializer_list DataCacheBufferSize, unsigned RamBuffersize, unsigned Lines, + unsigned CurrentFamily, unsigned CurrentModel, unsigned CurrentThreads, + std::unique_ptr&& Payload) + : PlatformConfig(std::move(Name), Threads, InstructionCacheSize, DataCacheBufferSize, RamBuffersize, Lines, + std::move(Payload)) + , Family(Family) + , Models(Models) + , CurrentFamily(CurrentFamily) + , CurrentModel(CurrentModel) + , CurrentThreads(CurrentThreads) {} - bool isDefault() const override { - return _family == _currentFamily && (std::find(_models.begin(), _models.end(), _currentModel) != _models.end()) && + [[nodiscard]] auto isDefault() const -> bool override { + return Family == CurrentFamily && (std::find(Models.begin(), Models.end(), CurrentModel) != Models.end()) && isAvailable(); } }; diff --git a/include/firestarter/Environment/X86/X86CPUTopology.hpp b/include/firestarter/Environment/X86/X86CPUTopology.hpp index d9ca6393..44875e03 100644 --- a/include/firestarter/Environment/X86/X86CPUTopology.hpp +++ b/include/firestarter/Environment/X86/X86CPUTopology.hpp @@ -23,7 +23,7 @@ #include -#include +#include "../CPUTopology.hpp" namespace firestarter::environment::x86 { @@ -36,9 +36,6 @@ class X86CPUTopology final : public CPUTopology { [[nodiscard]] auto features() const -> std::list const& override { return this->FeatureList; } [[nodiscard]] auto featuresAsmjit() const -> const asmjit::CpuFeatures& { return this->CpuInfo.features(); } - [[nodiscard]] auto vendor() const -> std::string const& override { return this->Vendor; } - [[nodiscard]] auto model() const -> std::string const& override { return this->Model; } - [[nodiscard]] auto clockrate() const -> uint64_t override; [[nodiscard]] auto timestamp() const -> uint64_t override; @@ -50,15 +47,13 @@ class X86CPUTopology final : public CPUTopology { private: [[nodiscard]] auto hasRdtsc() const -> bool { return this->HasRdtsc; } [[nodiscard]] auto hasInvariantRdtsc() const -> bool { return this->HasInvariantRdtsc; } - void cpuid(uint64_t* A, uint64_t* B, uint64_t* C, uint64_t* D) const; + static void cpuid(uint64_t* Rax, uint64_t* Rbx, uint64_t* Rcx, uint64_t* Rdx); asmjit::CpuInfo CpuInfo; std::list FeatureList; bool HasRdtsc; bool HasInvariantRdtsc; - std::string Vendor; - std::string Model; }; inline auto operator<<(std::ostream& Stream, X86CPUTopology const& CpuTopology) -> std::ostream& { diff --git a/include/firestarter/Environment/X86/X86Environment.hpp b/include/firestarter/Environment/X86/X86Environment.hpp index 7873c9c4..3e358d90 100644 --- a/include/firestarter/Environment/X86/X86Environment.hpp +++ b/include/firestarter/Environment/X86/X86Environment.hpp @@ -23,27 +23,26 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "../Environment.hpp" +#include "Platform/BulldozerConfig.hpp" +#include "Platform/HaswellConfig.hpp" +#include "Platform/HaswellEPConfig.hpp" +#include "Platform/KnightsLandingConfig.hpp" +#include "Platform/NaplesConfig.hpp" +#include "Platform/NehalemConfig.hpp" +#include "Platform/NehalemEPConfig.hpp" +#include "Platform/RomeConfig.hpp" +#include "Platform/SandyBridgeConfig.hpp" +#include "Platform/SandyBridgeEPConfig.hpp" +#include "Platform/SkylakeConfig.hpp" +#include "Platform/SkylakeSPConfig.hpp" +#include "Platform/X86PlatformConfig.hpp" +#include "X86CPUTopology.hpp" #define REGISTER(NAME) \ [](asmjit::CpuFeatures const& supportedFeatures, unsigned family, unsigned model, \ - unsigned threads) -> platform::X86PlatformConfig* { \ - return new platform::NAME(supportedFeatures, family, model, threads); \ + unsigned threads) -> std::unique_ptr { \ + return std::make_unique(supportedFeatures, family, model, threads); \ } namespace firestarter::environment::x86 { @@ -51,18 +50,9 @@ namespace firestarter::environment::x86 { class X86Environment final : public Environment { public: X86Environment() - : Environment(new X86CPUTopology()) {} + : Environment(std::make_unique()) {} - ~X86Environment() { - for (auto const& Config : PlatformConfigs) { - delete Config; - } - for (auto const& Config : FallbackPlatformConfigs) { - delete Config; - } - } - - auto topology() -> X86CPUTopology const& { return *reinterpret_cast(this->Topology); } + auto topology() -> X86CPUTopology const& { return *dynamic_cast(Topology.get()); } void evaluateFunctions() override; auto selectFunction(unsigned FunctionId, bool AllowUnavailablePayload) -> int override; @@ -76,16 +66,18 @@ class X86Environment final : public Environment { // The available function IDs are generated by iterating through this list // of PlatformConfig. Add new PlatformConfig at the bottom to maintain // stable IDs. - const std::list> + const std::list(asmjit::CpuFeatures const&, unsigned, + unsigned, unsigned)>> PlatformConfigsCtor = {REGISTER(KnightsLandingConfig), REGISTER(SkylakeConfig), REGISTER(SkylakeSPConfig), REGISTER(HaswellConfig), REGISTER(HaswellEPConfig), REGISTER(SandyBridgeConfig), REGISTER(SandyBridgeEPConfig), REGISTER(NehalemConfig), REGISTER(NehalemEPConfig), REGISTER(BulldozerConfig), REGISTER(NaplesConfig), REGISTER(RomeConfig)}; - std::list PlatformConfigs; + std::list> PlatformConfigs; // List of fallback PlatformConfig. Add one for each x86 extension. - const std::list> + const std::list(asmjit::CpuFeatures const&, unsigned, + unsigned, unsigned)>> FallbackPlatformConfigsCtor = { REGISTER(SkylakeSPConfig), // AVX512 REGISTER(BulldozerConfig), // FMA4 @@ -94,7 +86,7 @@ class X86Environment final : public Environment { REGISTER(NehalemConfig) // SSE2 }; - std::list FallbackPlatformConfigs; + std::list> FallbackPlatformConfigs; #undef REGISTER }; diff --git a/include/firestarter/Firestarter.hpp b/include/firestarter/Firestarter.hpp index 8009c1c9..0e4c7ef5 100644 --- a/include/firestarter/Firestarter.hpp +++ b/include/firestarter/Firestarter.hpp @@ -22,27 +22,27 @@ #pragma once #if defined(FIRESTARTER_BUILD_CUDA) || defined(FIRESTARTER_BUILD_HIP) -#include +#include "Cuda/Cuda.hpp" #endif #ifdef FIRESTARTER_BUILD_ONEAPI -#include +#include "OneAPI/OneAPI.hpp" #endif -#include +#include "Constants.hpp" #if defined(linux) || defined(__linux__) -#include -#include -#include -#include +#include "Measurement/MeasurementWorker.hpp" +#include "Optimizer/Algorithm.hpp" +#include "Optimizer/OptimizerWorker.hpp" +#include "Optimizer/Population.hpp" #endif -#include -#include +#include "DumpRegisterWorkerData.hpp" +#include "LoadWorkerData.hpp" #if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64) -#include +#include "Environment/X86/X86Environment.hpp" #endif #include diff --git a/include/firestarter/Json/Summary.hpp b/include/firestarter/Json/Summary.hpp index a2e8e03a..8fe781e9 100644 --- a/include/firestarter/Json/Summary.hpp +++ b/include/firestarter/Json/Summary.hpp @@ -21,23 +21,26 @@ #pragma once -#include +#include "../Measurement/Summary.hpp" namespace nlohmann { template <> struct adl_serializer { - static firestarter::measurement::Summary from_json(const json& j) { - return {j["num_timepoints"].get(), - std::chrono::milliseconds(j["duration"].get()), j["average"].get(), - j["stddev"].get()}; + // functions for nlohmann json do not follow LLVM code style + // NOLINTBEGIN(readability-identifier-naming) + static auto from_json(const json& J) -> firestarter::measurement::Summary { + return {J["num_timepoints"].get(), + std::chrono::milliseconds(J["duration"].get()), J["average"].get(), + J["stddev"].get()}; } - static void to_json(json& j, firestarter::measurement::Summary s) { - j = json::object(); + static void to_json(json& J, firestarter::measurement::Summary S) { + J = json::object(); - j["num_timepoints"] = s.NumTimepoints; - j["duration"] = s.Duration.count(); - j["average"] = s.Average; - j["stddev"] = s.Stddev; + J["num_timepoints"] = S.NumTimepoints; + J["duration"] = S.Duration.count(); + J["average"] = S.Average; + J["stddev"] = S.Stddev; } + // NOLINTEND(readability-identifier-naming) }; } // namespace nlohmann diff --git a/include/firestarter/LoadWorkerData.hpp b/include/firestarter/LoadWorkerData.hpp index eb7e0c3c..6aa5b40f 100644 --- a/include/firestarter/LoadWorkerData.hpp +++ b/include/firestarter/LoadWorkerData.hpp @@ -21,11 +21,11 @@ #pragma once +#include "Constants.hpp" +#include "DumpRegisterStruct.hpp" +#include "Environment/Environment.hpp" +#include "ErrorDetectionStruct.hpp" #include -#include -#include -#include -#include #include #include #include diff --git a/include/firestarter/Logging/FirstWorkerThreadFilter.hpp b/include/firestarter/Logging/FirstWorkerThreadFilter.hpp index 3a0e68fc..2a1a51f1 100644 --- a/include/firestarter/Logging/FirstWorkerThreadFilter.hpp +++ b/include/firestarter/Logging/FirstWorkerThreadFilter.hpp @@ -21,7 +21,6 @@ #pragma once -#include #include #include @@ -33,8 +32,8 @@ template class FirstWorkerThreadFilter { static void setFirstThread(std::thread::id NewFirstThread) { FirstThread = NewFirstThread; } - auto filter(Record& r) const -> bool { - return r.std_thread_id() == FirstThread || r.severity() >= nitro::log::severity_level::error; + auto filter(Record& R) const -> bool { + return R.std_thread_id() == FirstThread || R.severity() >= nitro::log::severity_level::error; } private: diff --git a/include/firestarter/Logging/Log.hpp b/include/firestarter/Logging/Log.hpp index 74cc3e1a..a2874ebb 100644 --- a/include/firestarter/Logging/Log.hpp +++ b/include/firestarter/Logging/Log.hpp @@ -21,9 +21,7 @@ #pragma once -#include -#include -#include +#include "FirstWorkerThreadFilter.hpp" #include #include #include @@ -42,61 +40,61 @@ namespace logging { class StdOut { public: - void sink(nitro::log::severity_level severity, const std::string& formatted_record) { - switch (severity) { + static void sink(nitro::log::severity_level Severity, const std::string& FormattedRecord) { + switch (Severity) { case nitro::log::severity_level::warn: case nitro::log::severity_level::error: case nitro::log::severity_level::fatal: - std::cerr << formatted_record << std::endl << std::flush; + std::cerr << FormattedRecord << '\n' << std::flush; break; default: - std::cout << formatted_record << std::endl << std::flush; + std::cout << FormattedRecord << '\n' << std::flush; break; } } }; -using record = nitro::log::record; -template class formater { +template class Formater { public: - std::string format(Record& r) { - std::stringstream s; + auto format(Record& R) -> std::string { + std::stringstream S; - switch (r.severity()) { + switch (R.severity()) { case nitro::log::severity_level::warn: - s << "Warning: "; + S << "Warning: "; break; case nitro::log::severity_level::error: - s << "Error: "; + S << "Error: "; break; case nitro::log::severity_level::fatal: - s << "Fatal: "; + S << "Fatal: "; break; case nitro::log::severity_level::trace: - s << "Debug: "; + S << "Debug: "; break; default: break; } - s << r.message(); + S << R.message(); - return s.str(); + return S.str(); } }; -template using filter = nitro::log::filter::severity_filter; +template using Filter = nitro::log::filter::severity_filter; template -using workerFilter = nitro::log::filter::and_filter, FirstWorkerThreadFilter>; +using WorkerFilter = nitro::log::filter::and_filter, FirstWorkerThreadFilter>; } // namespace logging -using log = nitro::log::logger; +using log = nitro::log::logger; using workerLog = - nitro::log::logger; + nitro::log::logger; } // namespace firestarter diff --git a/include/firestarter/Measurement/MeasurementWorker.hpp b/include/firestarter/Measurement/MeasurementWorker.hpp index 2045bd43..e9e18b76 100644 --- a/include/firestarter/Measurement/MeasurementWorker.hpp +++ b/include/firestarter/Measurement/MeasurementWorker.hpp @@ -21,14 +21,13 @@ #pragma once +#include "Metric/IPCEstimate.h" +#include "Metric/Perf.h" +#include "Metric/RAPL.h" +#include "MetricInterface.h" +#include "Summary.hpp" +#include "TimeValue.hpp" #include -#include -#include -#include -#include -#include -#include -#include #include #include diff --git a/include/firestarter/Measurement/Metric/IPCEstimate.h b/include/firestarter/Measurement/Metric/IPCEstimate.h index 360c1d91..63dcb26b 100644 --- a/include/firestarter/Measurement/Metric/IPCEstimate.h +++ b/include/firestarter/Measurement/Metric/IPCEstimate.h @@ -21,7 +21,7 @@ #pragma once -#include +#include "../MetricInterface.h" extern "C" { diff --git a/include/firestarter/Measurement/Metric/Perf.h b/include/firestarter/Measurement/Metric/Perf.h index 39a070f6..2702cd94 100644 --- a/include/firestarter/Measurement/Metric/Perf.h +++ b/include/firestarter/Measurement/Metric/Perf.h @@ -21,7 +21,7 @@ #pragma once -#include +#include "../MetricInterface.h" extern "C" { diff --git a/include/firestarter/Measurement/Metric/RAPL.h b/include/firestarter/Measurement/Metric/RAPL.h index 726ff61a..017373a1 100644 --- a/include/firestarter/Measurement/Metric/RAPL.h +++ b/include/firestarter/Measurement/Metric/RAPL.h @@ -21,7 +21,7 @@ #pragma once -#include +#include "../MetricInterface.h" extern "C" { diff --git a/include/firestarter/Measurement/Summary.hpp b/include/firestarter/Measurement/Summary.hpp index 09c91016..019a73eb 100644 --- a/include/firestarter/Measurement/Summary.hpp +++ b/include/firestarter/Measurement/Summary.hpp @@ -21,15 +21,12 @@ #pragma once +#include "MetricInterface.h" +#include "TimeValue.hpp" #include -#include #include #include -extern "C" { -#include -} - namespace firestarter::measurement { struct Summary { diff --git a/include/firestarter/Measurement/TimeValue.hpp b/include/firestarter/Measurement/TimeValue.hpp index cc168ad2..10b31e8b 100644 --- a/include/firestarter/Measurement/TimeValue.hpp +++ b/include/firestarter/Measurement/TimeValue.hpp @@ -33,7 +33,7 @@ struct TimeValue { , Value(Value){}; std::chrono::high_resolution_clock::time_point Time; - double Value; + double Value{}; }; } // namespace firestarter::measurement diff --git a/include/firestarter/Optimizer/Algorithm.hpp b/include/firestarter/Optimizer/Algorithm.hpp index 4cdae1ec..8bae8bd3 100644 --- a/include/firestarter/Optimizer/Algorithm.hpp +++ b/include/firestarter/Optimizer/Algorithm.hpp @@ -21,7 +21,7 @@ #pragma once -#include +#include "Population.hpp" namespace firestarter::optimizer { diff --git a/include/firestarter/Optimizer/Algorithm/NSGA2.hpp b/include/firestarter/Optimizer/Algorithm/NSGA2.hpp index e02e7e14..70c2aac0 100644 --- a/include/firestarter/Optimizer/Algorithm/NSGA2.hpp +++ b/include/firestarter/Optimizer/Algorithm/NSGA2.hpp @@ -21,7 +21,7 @@ #pragma once -#include +#include "../Algorithm.hpp" namespace firestarter::optimizer::algorithm { diff --git a/include/firestarter/Optimizer/History.hpp b/include/firestarter/Optimizer/History.hpp index 332b49c5..8c573d72 100644 --- a/include/firestarter/Optimizer/History.hpp +++ b/include/firestarter/Optimizer/History.hpp @@ -21,14 +21,14 @@ #pragma once +#include "../Json/Summary.hpp" // IWYU pragma: keep +#include "../Logging/Log.hpp" +#include "../Measurement/Summary.hpp" +#include "Individual.hpp" #include #include #include #include -#include -#include -#include -#include #include #include #include @@ -88,129 +88,129 @@ struct History { // print the best 20 individuals for each metric in a format // where the user can give it to --run-instruction-groups directly - std::map columnWidth; + std::map ColumnWidth; - for (auto const& metric : OptimizationMetrics) { - columnWidth[metric] = (std::max)(metric.size(), MinColumnWidth); - firestarter::log::trace() << metric << ": " << columnWidth[metric]; + for (auto const& Metric : OptimizationMetrics) { + ColumnWidth[Metric] = (std::max)(Metric.size(), MinColumnWidth); + firestarter::log::trace() << Metric << ": " << ColumnWidth[Metric]; } - for (auto const& metric : OptimizationMetrics) { + for (auto const& Metric : OptimizationMetrics) { using SummaryMap = std::map; - auto compareIndividual = [&metric](SummaryMap const& mapA, SummaryMap const& mapB) { - auto summaryA = mapA.find(metric); - auto summaryB = mapB.find(metric); - - if (summaryA == mapA.end() || summaryB == mapB.end()) { - summaryA = mapA.find(metric.substr(1)); - summaryB = mapB.find(metric.substr(1)); - assert(summaryA != mapA.end()); - assert(summaryB != mapB.end()); - return summaryA->second.Average < summaryB->second.Average; + auto CompareIndividual = [&Metric](SummaryMap const& MapA, SummaryMap const& MapB) { + auto SummaryA = MapA.find(Metric); + auto SummaryB = MapB.find(Metric); + + if (SummaryA == MapA.end() || SummaryB == MapB.end()) { + SummaryA = MapA.find(Metric.substr(1)); + SummaryB = MapB.find(Metric.substr(1)); + assert(SummaryA != MapA.end()); + assert(SummaryB != MapB.end()); + return SummaryA->second.Average < SummaryB->second.Average; } - assert(summaryA != mapA.end()); - assert(summaryB != mapB.end()); - return summaryA->second.Average > summaryB->second.Average; + assert(SummaryA != MapA.end()); + assert(SummaryB != MapB.end()); + return SummaryA->second.Average > SummaryB->second.Average; }; - auto perm = sortPermutation(F, compareIndividual); + auto Perm = sortPermutation(F, CompareIndividual); - auto formatIndividual = [&PayloadItems](std::vector const& individual) { - std::string result = ""; - assert(PayloadItems.size() == individual.size()); + auto FormatIndividual = [&PayloadItems](std::vector const& Individual) { + std::string Result; + assert(PayloadItems.size() == Individual.size()); - for (std::size_t i = 0; i < individual.size(); ++i) { + for (std::size_t I = 0; I < Individual.size(); ++I) { // skip zero values - if (individual[i] == 0) { + if (Individual[I] == 0) { continue; } - if (result.size() != 0) { - result += ","; + if (Result.size() != 0) { + Result += ","; } - result += PayloadItems[i] + ":" + std::to_string(individual[i]); + Result += PayloadItems[I] + ":" + std::to_string(Individual[I]); } - return result; + return Result; }; - auto begin = perm.begin(); - auto end = perm.end(); + auto Begin = Perm.begin(); + auto End = Perm.end(); // stop printing at a max of MaxElementPrintCount - if (std::distance(begin, end) > MaxElementPrintCount) { - end = perm.begin(); - std::advance(end, MaxElementPrintCount); + if (std::distance(Begin, End) > MaxElementPrintCount) { + End = Perm.begin(); + std::advance(End, MaxElementPrintCount); } // print each of the best elements - std::size_t max = 0; - for (auto it = begin; it != end; ++it) { - max = (std::max)(max, formatIndividual(X[*it]).size()); + std::size_t Max = 0; + for (auto It = Begin; It != End; ++It) { + Max = (std::max)(Max, FormatIndividual(X[*It]).size()); } - std::stringstream firstLine; - std::stringstream secondLine; - std::string ind = "INDIVIDUAL"; + std::stringstream FirstLine; + std::stringstream SecondLine; + std::string Ind = "INDIVIDUAL"; - firstLine << " " << ind; - padding(firstLine, max, ind.size(), ' '); + FirstLine << " " << Ind; + padding(FirstLine, Max, Ind.size(), ' '); - secondLine << " "; - padding(secondLine, (std::max)(max, ind.size()), 0, '-'); + SecondLine << " "; + padding(SecondLine, (std::max)(Max, Ind.size()), 0, '-'); - for (auto const& metric : OptimizationMetrics) { - auto width = columnWidth[metric]; + for (auto const& Metric : OptimizationMetrics) { + auto Width = ColumnWidth[Metric]; - firstLine << " | "; - secondLine << "---"; + FirstLine << " | "; + SecondLine << "---"; - firstLine << metric; - padding(firstLine, width, metric.size(), ' '); - padding(secondLine, width, 0, '-'); + FirstLine << Metric; + padding(FirstLine, Width, Metric.size(), ' '); + padding(SecondLine, Width, 0, '-'); } - std::stringstream ss; + std::stringstream Ss; - ss << "\n Best individuals sorted by metric " << metric << " " - << ((metric[0] == '-') ? "ascending" : "descending") << ":\n" - << firstLine.str() << "\n" - << secondLine.str() << "\n"; + Ss << "\n Best individuals sorted by metric " << Metric << " " + << ((Metric[0] == '-') ? "ascending" : "descending") << ":\n" + << FirstLine.str() << "\n" + << SecondLine.str() << "\n"; // print INDIVIDUAL | metric 1 | metric 2 | ... | metric N - for (auto it = begin; it != end; ++it) { - auto const fitness = F[*it]; - auto const ind = formatIndividual(X[*it]); + for (auto It = Begin; It != End; ++It) { + auto const& Fitness = F[*It]; + auto const Ind = FormatIndividual(X[*It]); - ss << " " << ind; - padding(ss, max, ind.size(), ' '); + Ss << " " << Ind; + padding(Ss, Max, Ind.size(), ' '); - for (auto const& metric : OptimizationMetrics) { - auto width = columnWidth[metric]; - std::string value; + for (auto const& Metric : OptimizationMetrics) { + auto Width = ColumnWidth[Metric]; + std::string Value; - auto fitnessOfMetric = fitness.find(metric); - auto invertedMetric = metric.substr(1); - auto fitnessOfInvertedMetric = fitness.find(invertedMetric); + auto FitnessOfMetric = Fitness.find(Metric); + auto InvertedMetric = Metric.substr(1); + auto FitnessOfInvertedMetric = Fitness.find(InvertedMetric); - if (fitnessOfMetric != fitness.end()) { - value = std::to_string(fitnessOfMetric->second.Average); - } else if (fitnessOfInvertedMetric != fitness.end()) { - value = std::to_string(fitnessOfInvertedMetric->second.Average); + if (FitnessOfMetric != Fitness.end()) { + Value = std::to_string(FitnessOfMetric->second.Average); + } else if (FitnessOfInvertedMetric != Fitness.end()) { + Value = std::to_string(FitnessOfInvertedMetric->second.Average); } else { assert(false); } - ss << " | " << value; - padding(ss, width, value.size(), ' '); + Ss << " | " << Value; + padding(Ss, Width, Value.size(), ' '); } - ss << "\n"; + Ss << "\n"; } - ss << "\n"; + Ss << "\n"; - firestarter::log::info() << ss.str(); + firestarter::log::info() << Ss.str(); } firestarter::log::info() << "To run FIRESTARTER with the best individual of a given metric " diff --git a/include/firestarter/Optimizer/OptimizerWorker.hpp b/include/firestarter/Optimizer/OptimizerWorker.hpp index e98c25b9..ba106595 100644 --- a/include/firestarter/Optimizer/OptimizerWorker.hpp +++ b/include/firestarter/Optimizer/OptimizerWorker.hpp @@ -19,9 +19,9 @@ * Contact: daniel.hackenberg@tu-dresden.de *****************************************************************************/ +#include "Algorithm.hpp" +#include "Population.hpp" #include -#include -#include #include extern "C" { diff --git a/include/firestarter/Optimizer/Population.hpp b/include/firestarter/Optimizer/Population.hpp index 757a2e46..2d904467 100644 --- a/include/firestarter/Optimizer/Population.hpp +++ b/include/firestarter/Optimizer/Population.hpp @@ -22,10 +22,9 @@ #ifndef FIRESTARTER_OPTIMIZER_POPULATION_HPP #define FIRESTARTER_OPTIMIZER_POPULATION_HPP +#include "Individual.hpp" +#include "Problem.hpp" #include -#include -#include -#include #include #include #include diff --git a/include/firestarter/Optimizer/Problem.hpp b/include/firestarter/Optimizer/Problem.hpp index df31ec98..ae0d285d 100644 --- a/include/firestarter/Optimizer/Problem.hpp +++ b/include/firestarter/Optimizer/Problem.hpp @@ -21,9 +21,9 @@ #pragma once +#include "../Measurement/Summary.hpp" +#include "Individual.hpp" #include -#include -#include #include #include #include diff --git a/include/firestarter/Optimizer/Problem/CLIArgumentProblem.hpp b/include/firestarter/Optimizer/Problem/CLIArgumentProblem.hpp index 74346a74..9d3c4ed7 100644 --- a/include/firestarter/Optimizer/Problem/CLIArgumentProblem.hpp +++ b/include/firestarter/Optimizer/Problem/CLIArgumentProblem.hpp @@ -21,11 +21,9 @@ #pragma once +#include "../../Measurement/MeasurementWorker.hpp" +#include "../Problem.hpp" #include -#include -#include -#include -#include #include #include #include diff --git a/include/firestarter/Optimizer/Util/MultiObjective.hpp b/include/firestarter/Optimizer/Util/MultiObjective.hpp index fab62be8..1b3a1873 100644 --- a/include/firestarter/Optimizer/Util/MultiObjective.hpp +++ b/include/firestarter/Optimizer/Util/MultiObjective.hpp @@ -21,7 +21,7 @@ #pragma once -#include +#include "../Individual.hpp" #include #include #include diff --git a/src/firestarter/Environment/CPUTopology.cpp b/src/firestarter/Environment/CPUTopology.cpp index b3e9a862..62c9224c 100644 --- a/src/firestarter/Environment/CPUTopology.cpp +++ b/src/firestarter/Environment/CPUTopology.cpp @@ -27,34 +27,30 @@ #include #include -extern "C" { -#include -} - namespace firestarter::environment { -auto CPUTopology::print(std::ostream& stream) const -> std::ostream& { - stream << " system summary:\n" - << " number of processors: " << this->numPackages() << "\n" - << " number of cores (total)): " << this->numCoresTotal() << "\n" +auto CPUTopology::print(std::ostream& Stream) const -> std::ostream& { + Stream << " system summary:\n" + << " number of processors: " << numPackages() << "\n" + << " number of cores (total)): " << numCoresTotal() << "\n" << " (this includes only cores in the cgroup)" << "\n" - << " number of threads per core: " << this->numThreadsPerCore() << "\n" - << " total number of threads: " << this->numThreads() << "\n\n"; + << " number of threads per core: " << numThreadsPerCore() << "\n" + << " total number of threads: " << numThreads() << "\n\n"; - std::stringstream ss; + std::stringstream Ss; - for (auto const& Entry : this->features()) { - ss << Entry << " "; + for (auto const& Entry : features()) { + Ss << Entry << " "; } - stream << " processor characteristics:\n" - << " architecture: " << this->architecture() << "\n" - << " vendor: " << this->vendor() << "\n" - << " processor-name: " << this->processorName() << "\n" - << " model: " << this->model() << "\n" - << " frequency: " << this->clockrate() / 1000000 << " MHz\n" - << " supported features: " << ss.str() << "\n" + Stream << " processor characteristics:\n" + << " architecture: " << architecture() << "\n" + << " vendor: " << vendor() << "\n" + << " processor-name: " << processorName() << "\n" + << " model: " << model() << "\n" + << " frequency: " << clockrate() / 1000000 << " MHz\n" + << " supported features: " << Ss.str() << "\n" << " Caches:"; std::vector Caches = { @@ -65,76 +61,76 @@ auto CPUTopology::print(std::ostream& stream) const -> std::ostream& { std::vector CacheStrings = {}; for (hwloc_obj_type_t const& Cache : Caches) { - std::stringstream ss; + std::stringstream Ss; - auto Width = hwloc_get_nbobjs_by_type(this->topology, Cache); + auto Width = hwloc_get_nbobjs_by_type(Topology, Cache); if (Width >= 1) { - ss << "\n - "; + Ss << "\n - "; - auto* CacheObj = hwloc_get_obj_by_type(this->topology, Cache, 0); + auto* CacheObj = hwloc_get_obj_by_type(Topology, Cache, 0); std::array String{}; hwloc_obj_type_snprintf(String.begin(), sizeof(String), CacheObj, 0); switch (CacheObj->attr->cache.type) { case HWLOC_OBJ_CACHE_DATA: - ss << "Level " << CacheObj->attr->cache.depth << " Data"; + Ss << "Level " << CacheObj->attr->cache.depth << " Data"; break; case HWLOC_OBJ_CACHE_INSTRUCTION: - ss << "Level " << CacheObj->attr->cache.depth << " Instruction"; + Ss << "Level " << CacheObj->attr->cache.depth << " Instruction"; break; case HWLOC_OBJ_CACHE_UNIFIED: default: - ss << "Unified Level " << CacheObj->attr->cache.depth; + Ss << "Unified Level " << CacheObj->attr->cache.depth; break; } - ss << " Cache, " << CacheObj->attr->cache.size / 1024 << " KiB, " << CacheObj->attr->cache.linesize + Ss << " Cache, " << CacheObj->attr->cache.size / 1024 << " KiB, " << CacheObj->attr->cache.linesize << " B Cacheline, "; switch (CacheObj->attr->cache.associativity) { case -1: - ss << "full"; + Ss << "full"; break; case 0: - ss << "unknown"; + Ss << "unknown"; break; default: - ss << CacheObj->attr->cache.associativity << "-way set"; + Ss << CacheObj->attr->cache.associativity << "-way set"; break; } - ss << " associative, "; + Ss << " associative, "; - auto Shared = this->numThreads() / Width; + auto Shared = numThreads() / Width; if (Shared > 1) { - ss << "shared among " << Shared << " threads."; + Ss << "shared among " << Shared << " threads."; } else { - ss << "per thread."; + Ss << "per thread."; } - stream << ss.str(); + Stream << Ss.str(); } } - return stream; + return Stream; } -CPUTopology::CPUTopology(std::string architecture) - : _architecture(std::move(architecture)) { +CPUTopology::CPUTopology(std::string Architecture) + : Architecture(std::move(Architecture)) { - hwloc_topology_init(&this->topology); + hwloc_topology_init(&Topology); // do not filter icaches - hwloc_topology_set_cache_types_filter(this->topology, HWLOC_TYPE_FILTER_KEEP_ALL); + hwloc_topology_set_cache_types_filter(Topology, HWLOC_TYPE_FILTER_KEEP_ALL); - hwloc_topology_load(this->topology); + hwloc_topology_load(Topology); // check for hybrid processor - int nr_cpukinds = hwloc_cpukinds_get_nr(this->topology, 0); + int NrCpukinds = hwloc_cpukinds_get_nr(Topology, 0); - switch (nr_cpukinds) { + switch (NrCpukinds) { case -1: log::warn() << "Hybrid core check failed"; break; @@ -142,203 +138,206 @@ CPUTopology::CPUTopology(std::string architecture) log::warn() << "Hybrid core check read no information"; break; default: - log::trace() << "Number of CPU kinds:" << nr_cpukinds; + log::trace() << "Number of CPU kinds:" << NrCpukinds; } - if (nr_cpukinds > 1) { + if (NrCpukinds > 1) { log::warn() << "FIRESTARTER detected a hybrid CPU set-up"; } // get number of packages - int depth = hwloc_get_type_depth(this->topology, HWLOC_OBJ_PACKAGE); + int Depth = hwloc_get_type_depth(Topology, HWLOC_OBJ_PACKAGE); - if (depth == HWLOC_TYPE_DEPTH_UNKNOWN) { - this->_numPackages = 1; + if (Depth == HWLOC_TYPE_DEPTH_UNKNOWN) { + NumPackages = 1; log::warn() << "Could not get number of packages"; } else { - this->_numPackages = hwloc_get_nbobjs_by_depth(this->topology, depth); + NumPackages = hwloc_get_nbobjs_by_depth(Topology, Depth); } - log::trace() << "Number of Packages:" << this->_numPackages; + log::trace() << "Number of Packages:" << NumPackages; // get number of cores per package - depth = hwloc_get_type_depth(this->topology, HWLOC_OBJ_CORE); + Depth = hwloc_get_type_depth(Topology, HWLOC_OBJ_CORE); - if (depth == HWLOC_TYPE_DEPTH_UNKNOWN) { - this->_numCoresTotal = 1; + if (Depth == HWLOC_TYPE_DEPTH_UNKNOWN) { + NumCoresTotal = 1; log::warn() << "Could not get number of cores"; } else { - this->_numCoresTotal = hwloc_get_nbobjs_by_depth(this->topology, depth); - if (this->_numCoresTotal == 0) { + NumCoresTotal = hwloc_get_nbobjs_by_depth(Topology, Depth); + if (NumCoresTotal == 0) { log::warn() << "Could not get number of cores"; - this->_numCoresTotal = 1; + NumCoresTotal = 1; } } - log::trace() << "Number of Cores:" << this->_numCoresTotal; + log::trace() << "Number of Cores:" << NumCoresTotal; // get number of threads per core - depth = hwloc_get_type_depth(this->topology, HWLOC_OBJ_PU); + Depth = hwloc_get_type_depth(Topology, HWLOC_OBJ_PU); - if (depth == HWLOC_TYPE_DEPTH_UNKNOWN) { - this->_numThreadsPerCore = 1; + if (Depth == HWLOC_TYPE_DEPTH_UNKNOWN) { + NumThreadsPerCore = 1; log::warn() << "Could not get number of threads"; } else { - this->_numThreadsPerCore = hwloc_get_nbobjs_by_depth(this->topology, depth) / this->_numCoresTotal; - if (this->_numThreadsPerCore == 0) { + NumThreadsPerCore = hwloc_get_nbobjs_by_depth(Topology, Depth) / NumCoresTotal; + if (NumThreadsPerCore == 0) { log::warn() << "Could not get number of threads per core"; - this->_numThreadsPerCore = 1; + NumThreadsPerCore = 1; } } // get vendor, processor name and clockrate for linux #if defined(linux) || defined(__linux__) - auto procCpuinfo = this->getFileAsStream("/proc/cpuinfo"); - std::string line; - std::string clockrate = "0"; - - while (std::getline(procCpuinfo, line, '\n')) { - const std::regex vendorIdRe("^vendor_id.*:\\s*(.*)\\s*$"); - const std::regex modelNameRe("^model name.*:\\s*(.*)\\s*$"); - const std::regex cpuMHzRe("^cpu MHz.*:\\s*(.*)\\s*$"); - std::smatch vendorIdM; - std::smatch modelNameM; - std::smatch cpuMHzM; - - if (std::regex_match(line, vendorIdM, vendorIdRe)) { - this->_vendor = vendorIdM[1].str(); - } + { + auto ProcCpuinfo = getFileAsStream("/proc/cpuinfo"); + std::string Line; + std::string ClockrateStr = "0"; + + while (std::getline(ProcCpuinfo, Line, '\n')) { + const std::regex VendorIdRe("^vendor_id.*:\\s*(.*)\\s*$"); + const std::regex ModelNameRe("^model name.*:\\s*(.*)\\s*$"); + const std::regex CpuMHzRe("^cpu MHz.*:\\s*(.*)\\s*$"); + std::smatch VendorIdMatch; + std::smatch ModelNameMatch; + std::smatch CpuMHzMatch; + + if (std::regex_match(Line, VendorIdMatch, VendorIdRe)) { + Vendor = VendorIdMatch[1].str(); + } - if (std::regex_match(line, modelNameM, modelNameRe)) { - this->_processorName = modelNameM[1].str(); - } + if (std::regex_match(Line, ModelNameMatch, ModelNameRe)) { + ProcessorName = ModelNameMatch[1].str(); + } - if (std::regex_match(line, cpuMHzM, cpuMHzRe)) { - clockrate = cpuMHzM[1].str(); + if (std::regex_match(Line, CpuMHzMatch, CpuMHzRe)) { + ClockrateStr = CpuMHzMatch[1].str(); + } } - } - if (this->_vendor == "") { - log::warn() << "Could determine vendor from /proc/cpuinfo"; - } + if (Vendor.empty()) { + log::warn() << "Could determine vendor from /proc/cpuinfo"; + } - if (this->_processorName == "") { - log::warn() << "Could determine processor-name from /proc/cpuinfo"; - } + if (ProcessorName.empty()) { + log::warn() << "Could determine processor-name from /proc/cpuinfo"; + } - if (clockrate == "0") { - firestarter::log::warn() << "Can't determine clockrate from /proc/cpuinfo"; - } else { - firestarter::log::trace() << "Clockrate from /proc/cpuinfo is " << clockrate; - this->_clockrate = 1e6 * std::stoi(clockrate); - } + if (ClockrateStr == "0") { + firestarter::log::warn() << "Can't determine clockrate from /proc/cpuinfo"; + } else { + firestarter::log::trace() << "Clockrate from /proc/cpuinfo is " << ClockrateStr; + Clockrate = 1e6 * std::stoi(ClockrateStr); + } - auto governor = this->scalingGovernor(); - if (!governor.empty()) { + auto Governor = scalingGovernor(); + if (!Governor.empty()) { - auto scalingCurFreq = this->getFileAsStream("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq").str(); - auto cpuinfoCurFreq = this->getFileAsStream("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq").str(); - auto scalingMaxFreq = this->getFileAsStream("/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq").str(); - auto cpuinfoMaxFreq = this->getFileAsStream("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq").str(); + auto ScalingCurFreq = getFileAsStream("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq").str(); + auto CpuinfoCurFreq = getFileAsStream("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq").str(); + auto ScalingMaxFreq = getFileAsStream("/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq").str(); + auto CpuinfoMaxFreq = getFileAsStream("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq").str(); - if (governor.compare("performance") || governor.compare("powersave")) { - if (scalingCurFreq.empty()) { - if (!cpuinfoCurFreq.empty()) { - clockrate = cpuinfoCurFreq; + if (Governor.compare("performance") || Governor.compare("powersave")) { + if (ScalingCurFreq.empty()) { + if (!CpuinfoCurFreq.empty()) { + ClockrateStr = CpuinfoCurFreq; + } + } else { + ClockrateStr = ScalingCurFreq; } } else { - clockrate = scalingCurFreq; - } - } else { - if (scalingMaxFreq.empty()) { - if (!cpuinfoMaxFreq.empty()) { - clockrate = cpuinfoMaxFreq; + if (ScalingMaxFreq.empty()) { + if (!CpuinfoMaxFreq.empty()) { + ClockrateStr = CpuinfoMaxFreq; + } + } else { + ClockrateStr = ScalingMaxFreq; } - } else { - clockrate = scalingMaxFreq; } - } - this->_clockrate = 1e3 * std::stoi(clockrate); + Clockrate = 1e3 * std::stoi(ClockrateStr); + } } #endif // try to detect processor name for macos #ifdef __APPLE__ - // use sysctl to detect the name - std::array buffer; - auto cmd = "sysctl -n machdep.cpu.brand_string"; - std::unique_ptr pipe(popen(cmd, "r"), pclose); - if (!pipe) { - log::warn() << "Could not determine processor-name"; - } - if (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { - auto str = std::string(buffer.data()); - str.erase(std::remove(str.begin(), str.end(), '\n'), str.end()); - this->_processorName = str; + { + // use sysctl to detect the name + std::array Buffer{}; + const auto* Cmd = "sysctl -n machdep.cpu.brand_string"; + std::unique_ptr Pipe(popen(Cmd, "r"), pclose); + if (!Pipe) { + log::warn() << "Could not determine processor-name"; + } + if (fgets(Buffer.data(), Buffer.size(), Pipe.get()) != nullptr) { + auto Str = std::string(Buffer.data()); + Str.erase(std::remove(Str.begin(), Str.end(), '\n'), Str.end()); + ProcessorName = Str; + } } #endif // try to detect processor name for windows #ifdef _WIN32 - // use wmic - std::array buffer; - auto cmd = "wmic cpu get name"; - std::unique_ptr pipe(_popen(cmd, "r"), _pclose); - if (!pipe) { - log::warn() << "Could not determine processor-name"; - } - auto line = 0; - while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { - if (line != 1) { - line++; - continue; + { + // use wmic + std::array Buffer{}; + const auto* Cmd = "wmic cpu get name"; + std::unique_ptr Pipe(_popen(Cmd, "r"), _pclose); + if (!Pipe) { + log::warn() << "Could not determine processor-name"; } + auto Line = 0; + while (fgets(Buffer.data(), Buffer.size(), Pipe.get()) != nullptr) { + if (Line != 1) { + Line++; + continue; + } - auto str = std::string(buffer.data()); - str.erase(std::remove(str.begin(), str.end(), '\n'), str.end()); - this->_processorName = str; + auto Str = std::string(Buffer.data()); + Str.erase(std::remove(Str.begin(), Str.end(), '\n'), Str.end()); + ProcessorName = Str; + } } #endif // get L1i-Cache size - int width = hwloc_get_nbobjs_by_type(this->topology, HWLOC_OBJ_L1ICACHE); + int Width = hwloc_get_nbobjs_by_type(Topology, HWLOC_OBJ_L1ICACHE); - if (width >= 1) { - hwloc_obj_t cacheObj = hwloc_get_obj_by_type(this->topology, HWLOC_OBJ_L1ICACHE, 0); - this->_instructionCacheSize = cacheObj->attr->cache.size; + if (Width >= 1) { + hwloc_obj_t CacheObj = hwloc_get_obj_by_type(Topology, HWLOC_OBJ_L1ICACHE, 0); + InstructionCacheSize = CacheObj->attr->cache.size; } } -CPUTopology::~CPUTopology() { hwloc_topology_destroy(this->topology); } +CPUTopology::~CPUTopology() { hwloc_topology_destroy(Topology); } -std::stringstream CPUTopology::getFileAsStream(std::string const& filePath) { - std::ifstream file(filePath); - std::stringstream ss; +auto CPUTopology::getFileAsStream(std::string const& FilePath) -> std::stringstream { + std::ifstream File(FilePath); + std::stringstream Ss; - if (!file.is_open()) { - log::trace() << "Could not open " << filePath; + if (!File.is_open()) { + log::trace() << "Could not open " << FilePath; } else { - ss << file.rdbuf(); - file.close(); + Ss << File.rdbuf(); + File.close(); } - return ss; + return Ss; } -std::string CPUTopology::scalingGovernor() const { - return this->getFileAsStream("/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor").str(); +auto CPUTopology::scalingGovernor() -> std::string { + return getFileAsStream("/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor").str(); } -int CPUTopology::getCoreIdFromPU(unsigned pu) const { - int width; - hwloc_obj_t obj; - - width = hwloc_get_nbobjs_by_type(this->topology, HWLOC_OBJ_PU); +auto CPUTopology::getCoreIdFromPU(unsigned Pu) const -> int { + auto Width = hwloc_get_nbobjs_by_type(Topology, HWLOC_OBJ_PU); - if (width >= 1) { - for (int i = 0; i < width; i++) { - obj = hwloc_get_obj_by_type(this->topology, HWLOC_OBJ_PU, i); - if (obj->os_index == pu) { - for (; obj; obj = obj->parent) { - if (obj->type == HWLOC_OBJ_CORE) { - return obj->logical_index; + if (Width >= 1) { + for (int I = 0; I < Width; I++) { + auto* Obj = hwloc_get_obj_by_type(Topology, HWLOC_OBJ_PU, I); + if (Obj->os_index == Pu) { + for (; Obj; Obj = Obj->parent) { + if (Obj->type == HWLOC_OBJ_CORE) { + return Obj->logical_index; } } } @@ -348,19 +347,16 @@ int CPUTopology::getCoreIdFromPU(unsigned pu) const { return -1; } -int CPUTopology::getPkgIdFromPU(unsigned pu) const { - int width; - hwloc_obj_t obj; +auto CPUTopology::getPkgIdFromPU(unsigned Pu) const -> int { + auto Width = hwloc_get_nbobjs_by_type(Topology, HWLOC_OBJ_PU); - width = hwloc_get_nbobjs_by_type(this->topology, HWLOC_OBJ_PU); - - if (width >= 1) { - for (int i = 0; i < width; i++) { - obj = hwloc_get_obj_by_type(this->topology, HWLOC_OBJ_PU, i); - if (obj->os_index == pu) { - for (; obj; obj = obj->parent) { - if (obj->type == HWLOC_OBJ_PACKAGE) { - return obj->logical_index; + if (Width >= 1) { + for (int I = 0; I < Width; I++) { + auto* Obj = hwloc_get_obj_by_type(Topology, HWLOC_OBJ_PU, I); + if (Obj->os_index == Pu) { + for (; Obj; Obj = Obj->parent) { + if (Obj->type == HWLOC_OBJ_PACKAGE) { + return Obj->logical_index; } } } @@ -370,46 +366,45 @@ int CPUTopology::getPkgIdFromPU(unsigned pu) const { return -1; } -unsigned CPUTopology::maxNumThreads() const { - unsigned max = 0; +auto CPUTopology::maxNumThreads() const -> unsigned { + unsigned Max = 0; // There might be more then one kind of cores - int nr_cpukinds = hwloc_cpukinds_get_nr(this->topology, 0); + int NrCpukinds = hwloc_cpukinds_get_nr(Topology, 0); // fallback in case this did not work ... can happen on some platforms // already printed a warning earlier - if (nr_cpukinds < 1) { - hwloc_obj_t obj; - int width = hwloc_get_nbobjs_by_type(this->topology, HWLOC_OBJ_PU); - unsigned max = 0; - - for (int i = 0; i < width; i++) { - obj = hwloc_get_obj_by_type(this->topology, HWLOC_OBJ_PU, i); - max = max < obj->os_index ? obj->os_index : max; + if (NrCpukinds < 1) { + auto Width = hwloc_get_nbobjs_by_type(Topology, HWLOC_OBJ_PU); + unsigned Max = 0; + + for (int I = 0; I < Width; I++) { + auto* Obj = hwloc_get_obj_by_type(Topology, HWLOC_OBJ_PU, I); + Max = std::max(Max, Obj->os_index); } - return max + 1; + return Max + 1; } // Allocate bitmap to get CPUs later - hwloc_bitmap_t bitmap = hwloc_bitmap_alloc(); - if (bitmap == NULL) { + hwloc_bitmap_t Bitmap = hwloc_bitmap_alloc(); + if (Bitmap == nullptr) { log::error() << "Could not allocate memory for CPU bitmap"; return 1; } // Find CPUs per kind - for (int kind_index = 0; kind_index < nr_cpukinds; kind_index++) { - int result = hwloc_cpukinds_get_info(this->topology, kind_index, bitmap, NULL, NULL, NULL, 0); - if (result) { - log::warn() << "Could not get information for CPU kind " << kind_index; + for (int KindIndex = 0; KindIndex < NrCpukinds; KindIndex++) { + int Result = hwloc_cpukinds_get_info(Topology, KindIndex, Bitmap, nullptr, nullptr, nullptr, 0); + if (Result) { + log::warn() << "Could not get information for CPU kind " << KindIndex; } - max += hwloc_bitmap_weight(bitmap); + Max += hwloc_bitmap_weight(Bitmap); } - hwloc_bitmap_free(bitmap); + hwloc_bitmap_free(Bitmap); - return max; + return Max; } }; // namespace firestarter::environment \ No newline at end of file diff --git a/src/firestarter/Environment/X86/Payload/AVX512Payload.cpp b/src/firestarter/Environment/X86/Payload/AVX512Payload.cpp index 8e29715f..2325ed04 100644 --- a/src/firestarter/Environment/X86/Payload/AVX512Payload.cpp +++ b/src/firestarter/Environment/X86/Payload/AVX512Payload.cpp @@ -103,7 +103,7 @@ auto AVX512Payload::compilePayload(std::vector> auto shift_reg32 = std::vector({edi, esi, edx}); auto nr_shift_regs = 3; auto mul_regs = 3; - auto add_regs = 24; + auto add_regs = 22; auto alt_dst_regs = 5; auto ram_reg = zmm30; @@ -123,7 +123,7 @@ auto AVX512Payload::compilePayload(std::vector> } // make all other used registers dirty except RAX frame.addDirtyRegs(l1_addr, l2_addr, l3_addr, ram_addr, l2_count_reg, l3_count_reg, ram_count_reg, temp_reg, - offset_reg, addrHigh_reg, iter_reg, ram_addr); + temp_reg2, offset_reg, addrHigh_reg, iter_reg, ram_addr); for (const auto& reg : shift_reg) { frame.addDirtyRegs(reg); } @@ -190,7 +190,6 @@ auto AVX512Payload::compilePayload(std::vector> bool left = false; auto add_dest = add_start + 1; auto mov_dst = trans_start; - auto mov_src = mov_dst + 1; unsigned l1_offset = 0; #define L1_INCREMENT() \ @@ -292,10 +291,6 @@ auto AVX512Payload::compilePayload(std::vector> if (mov_dst > trans_end) { mov_dst = trans_start; } - mov_src++; - if (mov_src > trans_end) { - mov_src = trans_start; - } shift_pos++; if (shift_pos == nr_shift_regs) { shift_pos = 0; diff --git a/src/firestarter/Environment/X86/Payload/X86Payload.cpp b/src/firestarter/Environment/X86/Payload/X86Payload.cpp index 73175bd5..93458d25 100644 --- a/src/firestarter/Environment/X86/Payload/X86Payload.cpp +++ b/src/firestarter/Environment/X86/Payload/X86Payload.cpp @@ -19,6 +19,7 @@ * Contact: daniel.hackenberg@tu-dresden.de *****************************************************************************/ +#include #include #include #include diff --git a/src/firestarter/Environment/X86/X86CPUTopology.cpp b/src/firestarter/Environment/X86/X86CPUTopology.cpp index dae61165..283e7f61 100644 --- a/src/firestarter/Environment/X86/X86CPUTopology.cpp +++ b/src/firestarter/Environment/X86/X86CPUTopology.cpp @@ -31,99 +31,101 @@ #pragma intrinsic(__rdtsc) #endif -using namespace firestarter::environment::x86; +namespace firestarter::environment::x86 { X86CPUTopology::X86CPUTopology() : CPUTopology("x86_64") - , CpuInfo(asmjit::CpuInfo::host()) - , Vendor(this->CpuInfo.vendor()) { + , CpuInfo(asmjit::CpuInfo::host()) { - std::stringstream ss; - ss << "Family " << this->familyId() << ", Model " << this->modelId() << ", Stepping " << this->stepping(); - this->Model = ss.str(); + Vendor = CpuInfo.vendor(); - for (int i = 0; i <= (int)asmjit::CpuFeatures::X86::Id::kMaxValue; i++) { - if (!this->CpuInfo.hasFeature(i)) { + { + std::stringstream Ss; + Ss << "Family " << familyId() << ", Model " << modelId() << ", Stepping " << stepping(); + Model = Ss.str(); + } + + for (auto FeatureId = 0; FeatureId <= asmjit::CpuFeatures::X86::Id::kMaxValue; FeatureId++) { + if (!CpuInfo.hasFeature(FeatureId)) { continue; } - asmjit::String sb; + asmjit::String Sb; - auto error = asmjit::Formatter::formatFeature(sb, this->CpuInfo.arch(), i); - if (error != asmjit::ErrorCode::kErrorOk) { - log::warn() << "Formatting cpu features got asmjit error: " << error; + auto Error = asmjit::Formatter::formatFeature(Sb, CpuInfo.arch(), FeatureId); + if (Error != asmjit::ErrorCode::kErrorOk) { + log::warn() << "Formatting cpu features got asmjit error: " << Error; } - this->FeatureList.push_back(std::string(sb.data())); + FeatureList.emplace_back(Sb.data()); } - uint64_t a = 0, b = 0, c = 0, d = 0; + uint64_t Rax = 0; + uint64_t Rbx = 0; + uint64_t Rcx = 0; + uint64_t Rdx = 0; // check if we have rdtsc - this->cpuid(&a, &b, &c, &d); - if (a >= 1) { - a = 1; - this->cpuid(&a, &b, &c, &d); - if ((int)d & (1 << 4)) { - this->HasRdtsc = true; - } else { - this->HasRdtsc = false; - } + cpuid(&Rax, &Rbx, &Rcx, &Rdx); + if (Rax >= 1) { + Rax = 1; + cpuid(&Rax, &Rbx, &Rcx, &Rdx); + HasRdtsc = (Rdx & (1 << 4)) != 0; } // check if we have invarant rdtsc - if (this->hasRdtsc()) { - a = 0, b = 0, c = 0, d = 0; + if (hasRdtsc()) { + Rax = 0, Rbx = 0, Rcx = 0, Rdx = 0; - this->HasInvariantRdtsc = true; + HasInvariantRdtsc = true; /* TSCs are usable if CPU supports only one frequency in C0 (no speedstep/Cool'n'Quite) or if multiple frequencies are available and the constant/invariant TSC feature flag is set */ - if (0 == this->vendor().compare("INTEL")) { + if ("INTEL" == vendor()) { /*check if Powermanagement and invariant TSC are supported*/ - a = 1; - this->cpuid(&a, &b, &c, &d); + Rax = 1; + cpuid(&Rax, &Rbx, &Rcx, &Rdx); /* no Frequency control */ - if ((!(d & (1 << 22))) && (!(c & (1 << 7)))) { - this->HasInvariantRdtsc = true; + if ((!(Rdx & (1 << 22))) && (!(Rcx & (1 << 7)))) { + HasInvariantRdtsc = true; } else { - a = 0x80000000; - this->cpuid(&a, &b, &c, &d); - if (a >= 0x80000007) { - a = 0x80000007; - this->cpuid(&a, &b, &c, &d); + Rax = 0x80000000; + cpuid(&Rax, &Rbx, &Rcx, &Rdx); + if (Rax >= 0x80000007) { + Rax = 0x80000007; + cpuid(&Rax, &Rbx, &Rcx, &Rdx); /* invariant TSC */ - if (d & (1 << 8)) { - this->HasInvariantRdtsc = true; + if (Rdx & (1 << 8)) { + HasInvariantRdtsc = true; } } } } - if (0 == this->vendor().compare("AMD")) { + if ("AMD" == vendor()) { /*check if Powermanagement and invariant TSC are supported*/ - a = 0x80000000; - this->cpuid(&a, &b, &c, &d); - if (a >= 0x80000007) { - a = 0x80000007; - this->cpuid(&a, &b, &c, &d); + Rax = 0x80000000; + cpuid(&Rax, &Rbx, &Rcx, &Rdx); + if (Rax >= 0x80000007) { + Rax = 0x80000007; + cpuid(&Rax, &Rbx, &Rcx, &Rdx); /* no Frequency control */ - if ((!(d & (1 << 7))) && (!(d & (1 << 1)))) { - this->HasInvariantRdtsc = true; + if ((!(Rdx & (1 << 7))) && (!(Rdx & (1 << 1)))) { + HasInvariantRdtsc = true; } /* invariant TSC */ - if (d & (1 << 8)) { - this->HasInvariantRdtsc = true; + if (Rdx & (1 << 8)) { + HasInvariantRdtsc = true; } } /* assuming no frequency control if cpuid does not provide the extended function to test for it */ else { - this->HasInvariantRdtsc = true; + HasInvariantRdtsc = true; } } } @@ -133,118 +135,122 @@ X86CPUTopology::X86CPUTopology() // only constant TSCs will be used (i.e. power management indepent TSCs) // save frequency in highest P-State or use generic fallback if no invarient TSC // is available -uint64_t X86CPUTopology::clockrate() const { - typedef std::chrono::high_resolution_clock Clock; - typedef std::chrono::microseconds ticks; +auto X86CPUTopology::clockrate() const -> uint64_t { + using ClockT = std::chrono::high_resolution_clock; + using TicksT = std::chrono::microseconds; - uint64_t start1_tsc, start2_tsc, end1_tsc, end2_tsc; - uint64_t time_diff; - uint64_t clock_lower_bound, clock_upper_bound, clock; - uint64_t clockrate = 0; - int i, num_measurements = 0, min_measurements; + uint64_t TimeDiff = 0; + uint64_t Clockrate = 0; + int NumMeasurements = 0; + int MinMeasurements = 0; - Clock::time_point start_time, end_time; + ClockT::time_point StartTime; + ClockT::time_point EndTime; #if not(defined(__APPLE__) || defined(_WIN32)) - auto governor = this->scalingGovernor(); + auto governor = scalingGovernor(); if (governor.empty()) { return CPUTopology::clockrate(); } /* non invariant TSCs can be used if CPUs run at fixed frequency */ - if (!this->hasInvariantRdtsc() && governor.compare("performance") && governor.compare("powersave")) { + if (!hasInvariantRdtsc() && governor.compare("performance") && governor.compare("powersave")) { return CPUTopology::clockrate(); } - min_measurements = 5; + MinMeasurements = 5; #else min_measurements = 20; #endif - i = 3; + int I = 3; do { + uint64_t End1Tsc = 0; + uint64_t End2Tsc = 0; + // start timestamp - start1_tsc = this->timestamp(); - start_time = Clock::now(); - start2_tsc = this->timestamp(); + uint64_t Start1Tsc = timestamp(); + StartTime = ClockT::now(); + uint64_t Start2Tsc = timestamp(); // waiting do { - end1_tsc = this->timestamp(); - } while (end1_tsc < start2_tsc + 1000000 * i); /* busy waiting */ + End1Tsc = timestamp(); + } while (End1Tsc < Start2Tsc + 1000000 * I); /* busy waiting */ // end timestamp do { - end1_tsc = this->timestamp(); - end_time = Clock::now(); - end2_tsc = this->timestamp(); + End1Tsc = timestamp(); + EndTime = ClockT::now(); + End2Tsc = timestamp(); - time_diff = std::chrono::duration_cast(end_time - start_time).count(); - } while (0 == time_diff); + TimeDiff = std::chrono::duration_cast(EndTime - StartTime).count(); + } while (0 == TimeDiff); - clock_lower_bound = (((end1_tsc - start2_tsc) * 1000000) / (time_diff)); - clock_upper_bound = (((end2_tsc - start1_tsc) * 1000000) / (time_diff)); + uint64_t ClockLowerBound = (((End1Tsc - Start2Tsc) * 1000000) / (TimeDiff)); + uint64_t ClockUpperBound = (((End2Tsc - Start1Tsc) * 1000000) / (TimeDiff)); // if both values differ significantly, the measurement could have been // interrupted between 2 rdtsc's - if (((double)clock_lower_bound > (((double)clock_upper_bound) * 0.999)) && ((time_diff) > 2000)) { - num_measurements++; - clock = (clock_lower_bound + clock_upper_bound) / 2; - if (clockrate == 0) - clockrate = clock; + if ((static_cast(ClockLowerBound) > ((static_cast(ClockUpperBound)) * 0.999)) && + ((TimeDiff) > 2000)) { + NumMeasurements++; + uint64_t Clock = (ClockLowerBound + ClockUpperBound) / 2; + bool ClockrateUpdateCondition = Clockrate == 0 || #ifndef _WIN32 - else if (clock < clockrate) - clockrate = clock; + Clock < Clockrate; #else - else if (clock > clockrate) - clockrate = clock; + Clock > Clockrate; #endif + if (ClockrateUpdateCondition) { + Clockrate = Clock; + } } - i += 2; - } while (((time_diff) < 10000) || (num_measurements < min_measurements)); + I += 2; + } while (((TimeDiff) < 10000) || (NumMeasurements < MinMeasurements)); - return clockrate; + return Clockrate; } -uint64_t X86CPUTopology::timestamp() const { -#ifndef _MSC_VER - uint64_t reg_a, reg_d; -#else - uint64_t i; -#endif - - if (!this->hasRdtsc()) { +auto X86CPUTopology::timestamp() const -> uint64_t { + if (!hasRdtsc()) { return 0; } #ifndef _MSC_VER - __asm__ __volatile__("rdtsc;" : "=a"(reg_a), "=d"(reg_d)); - return (reg_d << 32) | (reg_a & 0xffffffffULL); + uint64_t Rax = 0; + uint64_t Rdx = 0; + __asm__ __volatile__("rdtsc;" : "=a"(Rax), "=d"(Rdx)); + return (Rdx << 32) | (Rax & 0xffffffffULL); #else - i = __rdtsc(); - return i; + return __rdtsc(); #endif } -void X86CPUTopology::cpuid(uint64_t* a, uint64_t* b, uint64_t* c, uint64_t* d) const { +void X86CPUTopology::cpuid(uint64_t* Rax, uint64_t* Rbx, uint64_t* Rcx, uint64_t* Rdx) { #ifndef _MSC_VER - uint64_t reg_a, reg_b, reg_c, reg_d; + uint64_t RaxOut = 0; + uint64_t RbxOut = 0; + uint64_t RcxOut = 0; + uint64_t RdxOut = 0; __asm__ __volatile__("cpuid;" - : "=a"(reg_a), "=b"(reg_b), "=c"(reg_c), "=d"(reg_d) - : "a"(*a), "b"(*b), "c"(*c), "d"(*d)); - *a = reg_a; - *b = reg_b; - *c = reg_c; - *d = reg_d; + : "=a"(RaxOut), "=b"(RbxOut), "=c"(RcxOut), "=d"(RdxOut) + : "a"(*Rax), "b"(*Rbx), "c"(*Rcx), "d"(*Rdx)); + *Rax = RaxOut; + *Rbx = RbxOut; + *Rcx = RcxOut; + *Rdx = RdxOut; #else std::array cpuid; - __cpuidex(cpuid.data(), *a, *c); + __cpuidex(cpuid.data(), *Rax, *Rcx); - *a = cpuid[0]; - *b = cpuid[1]; - *c = cpuid[2]; - *d = cpuid[3]; + *Rax = cpuid[0]; + *Rbx = cpuid[1]; + *Rcx = cpuid[2]; + *Rdx = cpuid[3]; #endif } + +} // namespace firestarter::environment::x86 \ No newline at end of file diff --git a/src/firestarter/Environment/X86/X86Environment.cpp b/src/firestarter/Environment/X86/X86Environment.cpp index 508b01c6..2c2dabb0 100644 --- a/src/firestarter/Environment/X86/X86Environment.cpp +++ b/src/firestarter/Environment/X86/X86Environment.cpp @@ -26,50 +26,50 @@ #include #include -using namespace firestarter::environment::x86; +namespace firestarter::environment::x86 { void X86Environment::evaluateFunctions() { - for (auto ctor : this->PlatformConfigsCtor) { + for (const auto& Ctor : PlatformConfigsCtor) { // add asmjit for model and family detection - this->PlatformConfigs.push_back(ctor(this->topology().featuresAsmjit(), this->topology().familyId(), - this->topology().modelId(), this->topology().numThreadsPerCore())); + PlatformConfigs.emplace_back( + Ctor(topology().featuresAsmjit(), topology().familyId(), topology().modelId(), topology().numThreadsPerCore())); } - for (auto ctor : this->FallbackPlatformConfigsCtor) { - this->FallbackPlatformConfigs.push_back(ctor(this->topology().featuresAsmjit(), this->topology().familyId(), - this->topology().modelId(), this->topology().numThreadsPerCore())); + for (const auto& Ctor : FallbackPlatformConfigsCtor) { + FallbackPlatformConfigs.emplace_back( + Ctor(topology().featuresAsmjit(), topology().familyId(), topology().modelId(), topology().numThreadsPerCore())); } } -int X86Environment::selectFunction(unsigned functionId, bool allowUnavailablePayload) { +auto X86Environment::selectFunction(unsigned FunctionId, bool AllowUnavailablePayload) -> int { unsigned id = 1; std::string defaultPayloadName(""); // if functionId is 0 get the default or fallback - for (auto config : this->PlatformConfigs) { - for (auto const& [thread, functionName] : config->getThreadMap()) { + for (const auto& Config : PlatformConfigs) { + for (auto const& [thread, functionName] : Config->getThreadMap()) { // the selected function - if (id == functionId) { - if (!config->isAvailable()) { - log::error() << "Function " << functionId << " (\"" << functionName << "\") requires " - << config->payload().name() << ", which is not supported by the processor."; - if (!allowUnavailablePayload) { + if (id == FunctionId) { + if (!Config->isAvailable()) { + log::error() << "Function " << FunctionId << " (\"" << functionName << "\") requires " + << Config->payload().name() << ", which is not supported by the processor."; + if (!AllowUnavailablePayload) { return EXIT_FAILURE; } } // found function - this->SelectedConfig = new ::firestarter::environment::platform::RuntimeConfig( - *config, thread, this->topology().instructionCacheSize()); + SelectedConfig = + new ::firestarter::environment::platform::RuntimeConfig(*Config, thread, topology().instructionCacheSize()); return EXIT_SUCCESS; } // default function - if (0 == functionId && config->isDefault()) { - if (thread == this->topology().numThreadsPerCore()) { - this->SelectedConfig = new ::firestarter::environment::platform::RuntimeConfig( - *config, thread, this->topology().instructionCacheSize()); + if (0 == FunctionId && Config->isDefault()) { + if (thread == topology().numThreadsPerCore()) { + SelectedConfig = new ::firestarter::environment::platform::RuntimeConfig(*Config, thread, + topology().instructionCacheSize()); return EXIT_SUCCESS; } else { - defaultPayloadName = config->payload().name(); + defaultPayloadName = Config->payload().name(); } } id++; @@ -78,35 +78,35 @@ int X86Environment::selectFunction(unsigned functionId, bool allowUnavailablePay // no default found // use fallback - if (0 == functionId) { + if (0 == FunctionId) { if (!defaultPayloadName.empty()) { // default payload available, but number of threads per core is not // supported - log::warn() << "No " << defaultPayloadName << " code path for " << this->topology().numThreadsPerCore() + log::warn() << "No " << defaultPayloadName << " code path for " << topology().numThreadsPerCore() << " threads per core!"; } - log::warn() << this->topology().vendor() << " " << this->topology().model() + log::warn() << topology().vendor() << " " << topology().model() << " is not supported by this version of FIRESTARTER!\n" << "Check project website for updates."; // loop over available implementation and check if they are marked as // fallback - for (auto config : this->FallbackPlatformConfigs) { - if (config->isAvailable()) { + for (const auto& Config : FallbackPlatformConfigs) { + if (Config->isAvailable()) { auto selectedThread = 0; auto selectedFunctionName = std::string(""); - for (auto const& [thread, functionName] : config->getThreadMap()) { - if (thread == this->topology().numThreadsPerCore()) { + for (auto const& [thread, functionName] : Config->getThreadMap()) { + if (thread == topology().numThreadsPerCore()) { selectedThread = thread; selectedFunctionName = functionName; } } if (selectedThread == 0) { - selectedThread = config->getThreadMap().begin()->first; - selectedFunctionName = config->getThreadMap().begin()->second; + selectedThread = Config->getThreadMap().begin()->first; + selectedFunctionName = Config->getThreadMap().begin()->second; } - this->SelectedConfig = new ::firestarter::environment::platform::RuntimeConfig( - *config, selectedThread, this->topology().instructionCacheSize()); + SelectedConfig = new ::firestarter::environment::platform::RuntimeConfig(*Config, selectedThread, + topology().instructionCacheSize()); log::warn() << "Using function " << selectedFunctionName << " as fallback.\n" << "You can use the parameter --function to try other " "functions."; @@ -120,14 +120,14 @@ int X86Environment::selectFunction(unsigned functionId, bool allowUnavailablePay return EXIT_FAILURE; } - log::error() << "unknown function id: " << functionId << ", see --avail for available ids"; + log::error() << "unknown function id: " << FunctionId << ", see --avail for available ids"; return EXIT_FAILURE; } int X86Environment::selectInstructionGroups(std::string groups) { const std::string delimiter = ","; const std::regex re("^(\\w+):(\\d+)$"); - const auto availableInstructionGroups = this->selectedConfig().platformConfig().payload().getAvailableInstructions(); + const auto availableInstructionGroups = selectedConfig().platformConfig().payload().getAvailableInstructions(); std::stringstream ss(groups); std::vector> payloadSettings = {}; @@ -161,7 +161,7 @@ int X86Environment::selectInstructionGroups(std::string groups) { } } - this->selectedConfig().setPayloadSettings(payloadSettings); + selectedConfig().setPayloadSettings(payloadSettings); log::info() << " Running custom instruction group: " << groups; @@ -171,7 +171,7 @@ int X86Environment::selectInstructionGroups(std::string groups) { void X86Environment::printAvailableInstructionGroups() { std::stringstream ss; - for (auto const& item : this->selectedConfig().platformConfig().payload().getAvailableInstructions()) { + for (auto const& item : selectedConfig().platformConfig().payload().getAvailableInstructions()) { ss << item << ","; } @@ -180,14 +180,14 @@ void X86Environment::printAvailableInstructionGroups() { s.pop_back(); } - log::info() << " available instruction-groups for payload " - << this->selectedConfig().platformConfig().payload().name() << ":\n" + log::info() << " available instruction-groups for payload " << selectedConfig().platformConfig().payload().name() + << ":\n" << " " << s; } -void X86Environment::setLineCount(unsigned lineCount) { this->selectedConfig().setLineCount(lineCount); } +void X86Environment::setLineCount(unsigned lineCount) { selectedConfig().setLineCount(lineCount); } -void X86Environment::printSelectedCodePathSummary() { this->selectedConfig().printCodePathSummary(); } +void X86Environment::printSelectedCodePathSummary() { selectedConfig().printCodePathSummary(); } void X86Environment::printFunctionSummary() { log::info() << " available load-functions:\n" @@ -200,7 +200,7 @@ void X86Environment::printFunctionSummary() { unsigned id = 1; - for (auto const& config : this->PlatformConfigs) { + for (auto const& config : PlatformConfigs) { for (auto const& [thread, functionName] : config->getThreadMap()) { const char* available = config->isAvailable() ? "yes" : "no"; const char* fmt = " %4u | %-30s | %-24s | %s"; @@ -214,3 +214,5 @@ void X86Environment::printFunctionSummary() { } } } + +} // namespace firestarter::environment::x86 \ No newline at end of file diff --git a/src/firestarter/LoadWorker.cpp b/src/firestarter/LoadWorker.cpp index ed925cf1..c5a998c5 100644 --- a/src/firestarter/LoadWorker.cpp +++ b/src/firestarter/LoadWorker.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #if defined(linux) || defined(__linux__) extern "C" { @@ -95,7 +96,7 @@ int Firestarter::initLoadWorkers(bool lowLoad, uint64_t period) { if (i == 0) { // only show error for all worker threads except first. - firestarter::logging::FirstWorkerThreadFilter::setFirstThread(t.get_id()); + firestarter::logging::FirstWorkerThreadFilter::setFirstThread(t.get_id()); } this->LoadThreads.push_back(std::make_pair(std::move(t), td)); @@ -383,6 +384,7 @@ void Firestarter::loadThreadWorker(std::shared_ptr td) { break; case THREAD_STOP: default: + firestarter::log::debug() << "ERR" << '\n'; return; } } diff --git a/src/firestarter/Main.cpp b/src/firestarter/Main.cpp index 62bcc426..51b53177 100644 --- a/src/firestarter/Main.cpp +++ b/src/firestarter/Main.cpp @@ -263,13 +263,13 @@ Config::Config(int argc, const char** argv) { auto options = parser.parse(argc, argv); if (options.count("quiet")) { - firestarter::logging::filter::set_severity(nitro::log::severity_level::warn); + firestarter::logging::Filter::set_severity(nitro::log::severity_level::warn); } else if (options.count("report")) { - firestarter::logging::filter::set_severity(nitro::log::severity_level::debug); + firestarter::logging::Filter::set_severity(nitro::log::severity_level::debug); } else if (options.count("debug")) { - firestarter::logging::filter::set_severity(nitro::log::severity_level::trace); + firestarter::logging::Filter::set_severity(nitro::log::severity_level::trace); } else { - firestarter::logging::filter::set_severity(nitro::log::severity_level::info); + firestarter::logging::Filter::set_severity(nitro::log::severity_level::info); } if (options.count("version")) { diff --git a/src/firestarter/Measurement/MeasurementWorker.cpp b/src/firestarter/Measurement/MeasurementWorker.cpp index 36405051..0c880bbb 100644 --- a/src/firestarter/Measurement/MeasurementWorker.cpp +++ b/src/firestarter/Measurement/MeasurementWorker.cpp @@ -19,8 +19,10 @@ * Contact: daniel.hackenberg@tu-dresden.de *****************************************************************************/ +#include #include +#include #include #include diff --git a/src/firestarter/Optimizer/Algorithm/NSGA2.cpp b/src/firestarter/Optimizer/Algorithm/NSGA2.cpp index 8b9a7b02..e6a703bb 100644 --- a/src/firestarter/Optimizer/Algorithm/NSGA2.cpp +++ b/src/firestarter/Optimizer/Algorithm/NSGA2.cpp @@ -21,11 +21,13 @@ // This file borrows a lot of code from https://github.com/esa/pagmo2 +#include #include #include #include #include +#include #include using namespace firestarter::optimizer::algorithm; diff --git a/src/firestarter/Optimizer/Population.cpp b/src/firestarter/Optimizer/Population.cpp index 35c5ef04..e136fda6 100644 --- a/src/firestarter/Optimizer/Population.cpp +++ b/src/firestarter/Optimizer/Population.cpp @@ -20,11 +20,11 @@ *****************************************************************************/ #include +#include #include #include #include -#include using namespace firestarter::optimizer;