Skip to content

Commit

Permalink
wrapp x86 model information in X86Model class. test X86Model class. t…
Browse files Browse the repository at this point in the history
…est X86PlafromConfig::isDefault.
  • Loading branch information
marenz2569 committed Dec 14, 2024
1 parent 09797a6 commit 6ecbf51
Show file tree
Hide file tree
Showing 27 changed files with 342 additions and 60 deletions.
42 changes: 42 additions & 0 deletions include/firestarter/CpuModel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/******************************************************************************
* FIRESTARTER - A Processor Stress Test Utility
* Copyright (C) 2024 TU Dresden, Center for Information Services and High
* Performance Computing
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/\>.
*
* Contact: [email protected]
*****************************************************************************/

#pragma once

namespace firestarter {

/// Abstract class that defines the methods required to check if one cpu model is equal to another
class CpuModel {
public:
CpuModel() = default;
virtual ~CpuModel() = default;

/// \arg Other The model to which operator < should be checked.
/// \return true if this is less than other
[[nodiscard]] virtual auto operator<(const CpuModel& Other) const -> bool = 0;

/// Check if two models match.
/// \arg Other The model to which equality should be checked.
/// \return true if this and the other model match
[[nodiscard]] virtual auto operator==(const CpuModel& Other) const -> bool = 0;
};

} // namespace firestarter
13 changes: 5 additions & 8 deletions include/firestarter/Platform/PlatformConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#pragma once

#include "firestarter/Config/InstructionGroups.hpp"
#include "firestarter/CpuModel.hpp"
#include "firestarter/Logging/Log.hpp"
#include "firestarter/Payload/Payload.hpp"
#include "firestarter/ProcessorInformation.hpp"
Expand Down Expand Up @@ -59,19 +60,15 @@ class PlatformConfig {
[[nodiscard]] auto payload() const -> const auto& { return Payload; }

/// Check if this platform is available and the default on the current system.
/// \arg Topology The reference to the CPUTopology that is used to check agains if this payload is supported.
/// \returns true if the platform is the default one for a given CPUTopology.
[[nodiscard]] auto isDefault(const ProcessorInformation& Topology) const -> bool { return isDefault(&Topology); }
/// \arg Model The reference to the cpu model that is used to check if this config is the default.
/// \arg CpuFeatures Features that this payload requires to check agains if this payload is supported.
/// \returns true if the platform is the default one.
[[nodiscard]] virtual auto isDefault(const CpuModel& Model, const CpuFeatures& Features) const -> bool = 0;

protected:
/// Non const Getter for the settings of the platform.
[[nodiscard]] auto settings() -> payload::PayloadSettings& { return Settings; }

/// Check if this platform is available and the default on the current system.
/// \arg Topology The pointer to the CPUTopology that is used to check agains if this payload is supported.
/// \returns true if the platform is the default one for a given CPUTopology.
[[nodiscard]] virtual auto isDefault(const ProcessorInformation*) const -> bool = 0;

public:
PlatformConfig() = delete;

Expand Down
9 changes: 8 additions & 1 deletion include/firestarter/ProcessorInformation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#pragma once

#include "firestarter/CpuFeatures.hpp"
#include "firestarter/CpuModel.hpp"

#include <cstdint>
#include <list>
Expand All @@ -38,7 +39,8 @@ namespace firestarter {
/// This class models the properties of a processor.
class ProcessorInformation {
public:
explicit ProcessorInformation(std::string Architecture, std::unique_ptr<CpuFeatures>&& Features);
explicit ProcessorInformation(std::string Architecture, std::unique_ptr<CpuFeatures>&& Features,
std::unique_ptr<CpuModel>&& Model);
virtual ~ProcessorInformation() = default;

/// Getter for the clockrate in Hz
Expand All @@ -56,6 +58,9 @@ class ProcessorInformation {
/// Getter for the cpu features abstraction
[[nodiscard]] auto cpuFeatures() const -> const CpuFeatures& { return *Features; }

/// Getter for the cpu model abstraction
[[nodiscard]] auto cpuModel() const -> const CpuModel& { return *Model; }

/// Print the information about this process to a stream.
void print() const;

Expand All @@ -75,6 +80,8 @@ class ProcessorInformation {
std::string Vendor;
/// The cpu features of this processor.
std::unique_ptr<CpuFeatures> Features;
/// The cpu model of this processor.
std::unique_ptr<CpuModel> Model;

/// Helper function to open a filepath and return a stringstream with its contents.
/// \arg FilePath The file to open
Expand Down
5 changes: 4 additions & 1 deletion include/firestarter/X86/Platform/BulldozerConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ class BulldozerConfig final : public X86PlatformConfig {
public:
BulldozerConfig() noexcept
: X86PlatformConfig(
/*Name=*/"BLD_OPTERON", /*Family=*/21, /*Models=*/{1, 2, 3},
/*Name=*/"BLD_OPTERON",
/*RequestedModels=*/
{X86CpuModel(/*FamilyId=*/21, /*ModelId=*/1), X86CpuModel(/*FamilyId=*/21, /*ModelId=*/2),
X86CpuModel(/*FamilyId=*/21, /*ModelId=*/3)},
/*Settings=*/
firestarter::payload::PayloadSettings(
/*Threads=*/{1}, /*DataCacheBufferSize=*/{16384, 1048576, 786432}, /*RamBufferSize=*/104857600,
Expand Down
5 changes: 4 additions & 1 deletion include/firestarter/X86/Platform/HaswellConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ class HaswellConfig final : public X86PlatformConfig {
public:
HaswellConfig() noexcept
: X86PlatformConfig(
/*Name=*/"HSW_COREI", /*Family=*/6, /*Models=*/{60, 61, 69, 70, 71},
/*Name=*/"HSW_COREI", /*RequestedModels=*/
{X86CpuModel(/*FamilyId=*/6, /*ModelId=*/60), X86CpuModel(/*FamilyId=*/6, /*ModelId=*/61),
X86CpuModel(/*FamilyId=*/6, /*ModelId=*/69), X86CpuModel(/*FamilyId=*/6, /*ModelId=*/70),
X86CpuModel(/*FamilyId=*/6, /*ModelId=*/71)},
/*Settings=*/
firestarter::payload::PayloadSettings(
/*Threads=*/{1, 2}, /*DataCacheBufferSize=*/{32768, 262144, 1572864}, /*RamBufferSize=*/104857600,
Expand Down
3 changes: 2 additions & 1 deletion include/firestarter/X86/Platform/HaswellEPConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class HaswellEPConfig final : public X86PlatformConfig {
public:
HaswellEPConfig() noexcept
: X86PlatformConfig(
/*Name=*/"HSW_XEONEP", /*Family=*/6, /*Models=*/{63, 79},
/*Name=*/"HSW_XEONEP", /*RequestedModels=*/
{X86CpuModel(/*FamilyId=*/6, /*ModelId=*/63), X86CpuModel(/*FamilyId=*/6, /*ModelId=*/79)},
/*Settings=*/
firestarter::payload::PayloadSettings(
/*Threads=*/{1, 2}, /*DataCacheBufferSize=*/{32768, 262144, 2621440},
Expand Down
3 changes: 2 additions & 1 deletion include/firestarter/X86/Platform/KnightsLandingConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ namespace firestarter::x86::platform {
class KnightsLandingConfig final : public X86PlatformConfig {
public:
KnightsLandingConfig() noexcept
: X86PlatformConfig(/*Name=*/"KNL_XEONPHI", /*Family=*/6, /*Models=*/{87},
: X86PlatformConfig(/*Name=*/"KNL_XEONPHI", /*RequestedModels=*/
{X86CpuModel(/*FamilyId=*/6, /*ModelId=*/87)},
/*Settings=*/
firestarter::payload::PayloadSettings(
/*Threads=*/{4}, /*DataCacheBufferSize=*/{32768, 524288, 236279125},
Expand Down
4 changes: 3 additions & 1 deletion include/firestarter/X86/Platform/NaplesConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class NaplesConfig final : public X86PlatformConfig {
public:
NaplesConfig() noexcept
: X86PlatformConfig(
/*Name=*/"ZEN_EPYC", /*Family=*/23, /*Models=*/{1, 8, 17, 24},
/*Name=*/"ZEN_EPYC", /*RequestedModels=*/
{X86CpuModel(/*FamilyId=*/23, /*ModelId=*/1), X86CpuModel(/*FamilyId=*/23, /*ModelId=*/8),
X86CpuModel(/*FamilyId=*/23, /*ModelId=*/17), X86CpuModel(/*FamilyId=*/23, /*ModelId=*/24)},
/*Settings=*/
firestarter::payload::PayloadSettings(
/*Threads=*/{1, 2}, /*DataCacheBufferSize=*/{65536, 524288, 2097152}, /*RamBufferSize=*/104857600,
Expand Down
4 changes: 3 additions & 1 deletion include/firestarter/X86/Platform/NehalemConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class NehalemConfig final : public X86PlatformConfig {
public:
NehalemConfig() noexcept
: X86PlatformConfig(
/*Name=*/"NHM_COREI", /*Family=*/6, /*Models=*/{30, 37, 23},
/*Name=*/"NHM_COREI", /*RequestedModels=*/
{X86CpuModel(/*FamilyId=*/6, /*ModelId=*/30), X86CpuModel(/*FamilyId=*/6, /*ModelId=*/37),
X86CpuModel(/*FamilyId=*/6, /*ModelId=*/23)},
/*Settings=*/
firestarter::payload::PayloadSettings(/*Threads=*/{1, 2}, /*DataCacheBufferSize=*/{32768, 262144, 1572864},
/*RamBufferSize=*/104857600, /*Lines=*/1536,
Expand Down
3 changes: 2 additions & 1 deletion include/firestarter/X86/Platform/NehalemEPConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ namespace firestarter::x86::platform {
class NehalemEPConfig final : public X86PlatformConfig {
public:
NehalemEPConfig() noexcept
: X86PlatformConfig(/*Name=*/"NHM_XEONEP", /*Family=*/6, /*Models=*/{26, 44},
: X86PlatformConfig(/*Name=*/"NHM_XEONEP", /*RequestedModels=*/
{X86CpuModel(/*FamilyId=*/6, /*ModelId=*/26), X86CpuModel(/*FamilyId=*/6, /*ModelId=*/44)},
/*Settings=*/
firestarter::payload::PayloadSettings(
/*Threads=*/{1, 2}, /*DataCacheBufferSize=*/{32768, 262144, 2097152},
Expand Down
3 changes: 2 additions & 1 deletion include/firestarter/X86/Platform/RomeConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class RomeConfig final : public X86PlatformConfig {
public:
RomeConfig() noexcept
: X86PlatformConfig(
/*Name=*/"ZEN_2_EPYC", /*Family=*/23, /*Models=*/{49},
/*Name=*/"ZEN_2_EPYC", /*RequestedModels=*/
{X86CpuModel(/*FamilyId=*/23, /*ModelId=*/49)},
/*Settings=*/
firestarter::payload::PayloadSettings(
/*Threads=*/{1, 2}, /*DataCacheBufferSize=*/{32768, 524288, 2097152}, /*RamBufferSize=*/104857600,
Expand Down
3 changes: 2 additions & 1 deletion include/firestarter/X86/Platform/SandyBridgeConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class SandyBridgeConfig final : public X86PlatformConfig {
public:
SandyBridgeConfig() noexcept
: X86PlatformConfig(
/*Name=*/"SNB_COREI", /*Family=*/6, /*Models=*/{42, 58},
/*Name=*/"SNB_COREI", /*RequestedModels=*/
{X86CpuModel(/*FamilyId=*/6, /*ModelId=*/42), X86CpuModel(/*FamilyId=*/6, /*ModelId=*/58)},
/*Settings=*/
firestarter::payload::PayloadSettings(
/*Threads=*/{1, 2}, /*DataCacheBufferSize=*/{32768, 262144, 1572864}, /*RamBufferSize=*/104857600,
Expand Down
3 changes: 2 additions & 1 deletion include/firestarter/X86/Platform/SandyBridgeEPConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class SandyBridgeEPConfig final : public X86PlatformConfig {
public:
SandyBridgeEPConfig() noexcept
: X86PlatformConfig(
/*Name=*/"SNB_XEONEP", /*Family=*/6, /*Models=*/{45, 62},
/*Name=*/"SNB_XEONEP", /*RequestedModels=*/
{X86CpuModel(/*FamilyId=*/6, /*ModelId=*/45), X86CpuModel(/*FamilyId=*/6, /*ModelId=*/62)},
/*Settings=*/
firestarter::payload::PayloadSettings(
/*Threads=*/{1, 2}, /*DataCacheBufferSize=*/{32768, 262144, 2621440}, /*RamBufferSize=*/104857600,
Expand Down
3 changes: 2 additions & 1 deletion include/firestarter/X86/Platform/SkylakeConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class SkylakeConfig final : public X86PlatformConfig {
public:
SkylakeConfig() noexcept
: X86PlatformConfig(
/*Name=*/"SKL_COREI", /*Family=*/6, /*Models=*/{78, 94},
/*Name=*/"SKL_COREI", /*RequestedModels=*/
{X86CpuModel(/*FamilyId=*/6, /*ModelId=*/78), X86CpuModel(/*FamilyId=*/6, /*ModelId=*/94)},
/*Settings=*/
firestarter::payload::PayloadSettings(
/*Threads=*/{1, 2}, /*DataCacheBufferSize=*/{32768, 262144, 1572864},
Expand Down
3 changes: 2 additions & 1 deletion include/firestarter/X86/Platform/SkylakeSPConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ namespace firestarter::x86::platform {
class SkylakeSPConfig final : public X86PlatformConfig {
public:
SkylakeSPConfig() noexcept
: X86PlatformConfig(/*Name=*/"SKL_XEONEP", /*Family=*/6, /*Models=*/{85},
: X86PlatformConfig(/*Name=*/"SKL_XEONEP", /*RequestedModels=*/
{X86CpuModel(/*FamilyId=*/6, /*ModelId=*/85)},
/*Settings=*/
firestarter::payload::PayloadSettings(/*Threads=*/{1, 2},
/*DataCacheBufferSize=*/{32768, 1048576, 1441792},
Expand Down
40 changes: 15 additions & 25 deletions include/firestarter/X86/Platform/X86PlatformConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,27 @@
#pragma once

#include "firestarter/Platform/PlatformConfig.hpp"
#include "firestarter/ProcessorInformation.hpp"
#include "firestarter/X86/X86ProcessorInformation.hpp"
#include "firestarter/X86/X86CpuModel.hpp"
#include <set>

namespace firestarter::x86::platform {

/// Models a platform config that is the default based on x86 CPU family and model ids.
class X86PlatformConfig : public firestarter::platform::PlatformConfig {
private:
/// The famility id of the processor for which this is the default platform config.
unsigned Family;
/// The list of model ids in combination with the family for which this is the default platform config.
std::list<unsigned> Models;
/// The set of requested cpu models
std::set<X86CpuModel> RequestedModels;

public:
X86PlatformConfig(std::string Name, unsigned Family, std::list<unsigned>&& Models,
X86PlatformConfig(std::string Name, std::set<X86CpuModel>&& RequestedModels,
firestarter::payload::PayloadSettings&& Settings,
std::shared_ptr<const firestarter::payload::Payload>&& Payload) noexcept
: PlatformConfig(std::move(Name), std::move(Settings), std::move(Payload))
, Family(Family)
, Models(std::move(Models)) {}
, RequestedModels(std::move(RequestedModels)) {}

/// Clone a the platform config.
[[nodiscard]] auto clone() const -> std::unique_ptr<PlatformConfig> final {
auto Ptr = std::make_unique<X86PlatformConfig>(name(), Family, std::list<unsigned>(Models),
auto Ptr = std::make_unique<X86PlatformConfig>(name(), std::set<X86CpuModel>(RequestedModels),
firestarter::payload::PayloadSettings(settings()),
std::shared_ptr(payload()));
return Ptr;
Expand All @@ -62,21 +59,14 @@ class X86PlatformConfig : public firestarter::platform::PlatformConfig {
return Ptr;
}

private:
/// Check if this platform is available and the default on the current system. This is done by checking if the family
/// id in the CPUTopology matches the one saved in Family and if the model id in the CPUTopology is contained in
/// Models.
/// \arg Topology The pointer to the CPUTopology that is used to check agains if this payload is supported.
/// \returns true if the platform is the default one for a given CPUTopology.
[[nodiscard]] auto isDefault(const ProcessorInformation* Topology) const -> bool final {
const auto* FinalTopology = dynamic_cast<const X86ProcessorInformation*>(Topology);
assert(FinalTopology && "isDefault not called with const X86CPUTopology*");

// Check if the family of the topology matches the family of the config, if the model of the topology is contained
// in the models list of the config and if the config is available on the current platform.
return Family == FinalTopology->familyId() &&
(std::find(Models.begin(), Models.end(), FinalTopology->modelId()) != Models.end()) &&
payload()->isAvailable(Topology->cpuFeatures());
/// Check if this platform is available and the default on the current system. This is done by checking if the cpu
/// model matches one of the requested ones and that the payload is available with the supplied cpu features.
/// \arg Model The reference to the cpu model that is used to check if this config is the default.
/// \arg CpuFeatures Features that this payload requires to check agains if this payload is supported.
/// \returns true if the platform is the default one.
[[nodiscard]] auto isDefault(const CpuModel& Model, const CpuFeatures& Features) const -> bool override {
const auto ModelIt = std::find(RequestedModels.cbegin(), RequestedModels.cend(), Model);
return ModelIt != RequestedModels.cend() && payload()->isAvailable(Features);
}
};

Expand Down
70 changes: 70 additions & 0 deletions include/firestarter/X86/X86CpuModel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/******************************************************************************
* FIRESTARTER - A Processor Stress Test Utility
* Copyright (C) 2024 TU Dresden, Center for Information Services and High
* Performance Computing
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/\>.
*
* Contact: [email protected]
*****************************************************************************/

#pragma once

#include "firestarter/CpuModel.hpp"

#include <cassert>
#include <stdexcept>
#include <tuple>

namespace firestarter::x86 {

/// This class models the cpu features on the x86_64 platform.
class X86CpuModel : public CpuModel {
private:
/// The x86 family id
unsigned FamilyId;
/// The x86 model id
unsigned ModelId;

public:
X86CpuModel() = delete;
explicit X86CpuModel(unsigned FamilyId, unsigned ModelId) noexcept
: FamilyId(FamilyId)
, ModelId(ModelId) {}

/// \arg Other The model to which operator < should be checked.
/// \return true if this is less than other
[[nodiscard]] auto operator<(const CpuModel& Other) const -> bool override {
const auto* DerivedModel = dynamic_cast<const X86CpuModel*>(&Other);
if (!DerivedModel) {
throw std::runtime_error("Other is not of the correct type X86CpuModel");
}

return std::tie(FamilyId, ModelId) < std::tie(DerivedModel->FamilyId, DerivedModel->ModelId);
}

/// Check if two models match.
/// \arg Other The model to which equality should be checked.
/// \return true if this and the other model match
[[nodiscard]] auto operator==(const CpuModel& Other) const -> bool override {
const auto* DerivedModel = dynamic_cast<const X86CpuModel*>(&Other);
if (!DerivedModel) {
throw std::runtime_error("Other is not of the correct type X86CpuModel");
}

return std::tie(FamilyId, ModelId) == std::tie(DerivedModel->FamilyId, DerivedModel->ModelId);
}
};

} // namespace firestarter::x86
8 changes: 0 additions & 8 deletions include/firestarter/X86/X86ProcessorInformation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,13 @@ class X86ProcessorInformation final : public ProcessorInformation {

/// Getter for the list of CPU features
[[nodiscard]] auto features() const -> std::list<std::string> const& override { return this->FeatureList; }
/// Getter for the CPU features class from asmjit
[[nodiscard]] auto featuresAsmjit() const -> const asmjit::CpuFeatures& { return this->CpuInfo.features(); }

/// Getter for the clockrate in Hz
[[nodiscard]] auto clockrate() const -> uint64_t override;

/// Get the current hardware timestamp
[[nodiscard]] auto timestamp() const -> uint64_t override;

/// The family id of the x86 processor
[[nodiscard]] auto familyId() const -> unsigned { return this->CpuInfo.familyId(); }
/// The model id of the x86 processor
[[nodiscard]] auto modelId() const -> unsigned { return this->CpuInfo.modelId(); }
/// The stepping id of the x86 processor
[[nodiscard]] auto stepping() const -> unsigned { return this->CpuInfo.stepping(); }
/// The CPU vendor i.e., Intel or AMD.
[[nodiscard]] auto vendor() const -> std::string const& final { return Vendor; }
/// Get the string containing family, model and stepping ids.
Expand Down
Loading

0 comments on commit 6ecbf51

Please sign in to comment.