Skip to content

Commit

Permalink
second pass of clang-tidy for the header files. use unique_ptr for th…
Browse files Browse the repository at this point in the history
…e payload instead of raw pointers
  • Loading branch information
marenz2569 committed Sep 27, 2024
1 parent 90beb59 commit ff6113b
Show file tree
Hide file tree
Showing 57 changed files with 723 additions and 735 deletions.
6 changes: 4 additions & 2 deletions include/firestarter/DumpRegisterWorkerData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

#pragma once

#include "LoadWorkerData.hpp"
#include "Logging/Log.hpp"
#include <chrono>
#include <firestarter/DumpRegisterStruct.hpp>
#include <firestarter/LoadWorkerData.hpp>
#include <utility>

#ifdef FIRESTARTER_DEBUG_FEATURES
Expand All @@ -32,6 +32,8 @@ namespace firestarter {

class DumpRegisterWorkerData {
public:
DumpRegisterWorkerData() = delete;

DumpRegisterWorkerData(std::shared_ptr<LoadWorkerData> LoadWorkerDataPtr, std::chrono::seconds DumpTimeDelta,
const std::string& DumpFilePath)
: LoadWorkerDataPtr(std::move(LoadWorkerDataPtr))
Expand Down
60 changes: 31 additions & 29 deletions include/firestarter/Environment/CPUTopology.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> const& features() const = 0;
[[nodiscard]] virtual auto features() const -> std::list<std::string> 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
17 changes: 6 additions & 11 deletions include/firestarter/Environment/Environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,20 @@

#pragma once

#include "CPUTopology.hpp"
#include "Platform/RuntimeConfig.hpp"
#include <cassert>
#include <cstdint>
#include <firestarter/Environment/CPUTopology.hpp>
#include <firestarter/Environment/Platform/PlatformConfig.hpp>
#include <firestarter/Environment/Platform/RuntimeConfig.hpp>
#include <vector>

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<CPUTopology>&& Topology)
: Topology(std::move(Topology)) {}
virtual ~Environment() { delete SelectedConfig; }

auto evaluateCpuAffinity(unsigned RequestedNumThreads, std::string CpuBind) -> int;
auto setCpuAffinity(unsigned Thread) -> int;
Expand Down Expand Up @@ -77,7 +72,7 @@ class Environment {

protected:
platform::RuntimeConfig* SelectedConfig = nullptr;
CPUTopology* Topology = nullptr;
std::unique_ptr<CPUTopology> Topology;

private:
uint64_t RequestedNumThreads = 0;
Expand Down
3 changes: 2 additions & 1 deletion include/firestarter/Environment/Payload/Payload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#pragma once

#include <list>
#include <memory>
#include <string>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -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<Payload> = 0;
};

} // namespace firestarter::environment::payload
11 changes: 5 additions & 6 deletions include/firestarter/Environment/Platform/PlatformConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

#pragma once

#include <firestarter/Environment/Payload/Payload.hpp>
#include <firestarter/Logging/Log.hpp>
#include "../Payload/Payload.hpp"
#include <initializer_list>
#include <map>
#include <sstream>
Expand All @@ -35,7 +34,7 @@ class PlatformConfig {
private:
std::string Name;
std::list<unsigned> Threads;
payload::Payload* Payload;
std::unique_ptr<payload::Payload> Payload;

protected:
unsigned InstructionCacheSize;
Expand All @@ -48,15 +47,15 @@ class PlatformConfig {

PlatformConfig(std::string Name, std::list<unsigned> Threads, unsigned InstructionCacheSize,
std::initializer_list<unsigned> DataCacheBufferSize, unsigned RamBufferSize, unsigned Lines,
payload::Payload* Payload)
std::unique_ptr<payload::Payload>&& 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; }
Expand Down
5 changes: 3 additions & 2 deletions include/firestarter/Environment/Platform/RuntimeConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

#pragma once

#include "../../Logging/Log.hpp"
#include "../Platform/PlatformConfig.hpp"
#include <cassert>
#include <firestarter/Environment/Platform/PlatformConfig.hpp>

namespace firestarter::environment::platform {

Expand Down Expand Up @@ -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& {
Expand Down
6 changes: 3 additions & 3 deletions include/firestarter/Environment/X86/Payload/AVX512Payload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#pragma once

#include <firestarter/Environment/X86/Payload/X86Payload.hpp>
#include "X86Payload.hpp"

namespace firestarter::environment::x86::payload {
class AVX512Payload final : public X86Payload {
Expand All @@ -37,8 +37,8 @@ class AVX512Payload final : public X86Payload {
[[nodiscard]] auto getAvailableInstructions() const -> std::list<std::string> 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<firestarter::environment::payload::Payload> override {
return std::make_unique<AVX512Payload>(this->supportedFeatures());
};

private:
Expand Down
6 changes: 3 additions & 3 deletions include/firestarter/Environment/X86/Payload/AVXPayload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#pragma once

#include <firestarter/Environment/X86/Payload/X86Payload.hpp>
#include "X86Payload.hpp"

namespace firestarter::environment::x86::payload {
class AVXPayload final : public X86Payload {
Expand All @@ -37,8 +37,8 @@ class AVXPayload final : public X86Payload {
[[nodiscard]] auto getAvailableInstructions() const -> std::list<std::string> 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<firestarter::environment::payload::Payload> override {
return std::make_unique<AVXPayload>(this->supportedFeatures());
};

private:
Expand Down
6 changes: 3 additions & 3 deletions include/firestarter/Environment/X86/Payload/FMA4Payload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#pragma once

#include <firestarter/Environment/X86/Payload/X86Payload.hpp>
#include "X86Payload.hpp"

namespace firestarter::environment::x86::payload {

Expand All @@ -39,8 +39,8 @@ class FMA4Payload final : public X86Payload {
[[nodiscard]] auto getAvailableInstructions() const -> std::list<std::string> 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<firestarter::environment::payload::Payload> override {
return std::make_unique<FMA4Payload>(this->supportedFeatures());
};

private:
Expand Down
6 changes: 3 additions & 3 deletions include/firestarter/Environment/X86/Payload/FMAPayload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#pragma once

#include <firestarter/Environment/X86/Payload/X86Payload.hpp>
#include "X86Payload.hpp"

namespace firestarter::environment::x86::payload {
class FMAPayload final : public X86Payload {
Expand All @@ -37,8 +37,8 @@ class FMAPayload final : public X86Payload {
[[nodiscard]] auto getAvailableInstructions() const -> std::list<std::string> 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<firestarter::environment::payload::Payload> override {
return std::make_unique<FMAPayload>(this->supportedFeatures());
};

private:
Expand Down
7 changes: 3 additions & 4 deletions include/firestarter/Environment/X86/Payload/SSE2Payload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

#pragma once

#include <cstdint>
#include <firestarter/Environment/X86/Payload/X86Payload.hpp>
#include "X86Payload.hpp"

namespace firestarter::environment::x86::payload {
class SSE2Payload final : public X86Payload {
Expand All @@ -38,8 +37,8 @@ class SSE2Payload final : public X86Payload {
[[nodiscard]] auto getAvailableInstructions() const -> std::list<std::string> 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<firestarter::environment::payload::Payload> override {
return std::make_unique<SSE2Payload>(this->supportedFeatures());
};

private:
Expand Down
10 changes: 5 additions & 5 deletions include/firestarter/Environment/X86/Payload/X86Payload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <asmjit/x86.h>

#include <cstdint>
#include <firestarter/DumpRegisterWorkerData.hpp>
#include <firestarter/Environment/Payload/Payload.hpp>
#include <firestarter/LoadWorkerData.hpp>
#include <firestarter/Logging/Log.hpp>
#include <map> // IWYU pragma: keep
#include <utility>

#define INIT_BLOCKSIZE 1024
Expand Down
7 changes: 3 additions & 4 deletions include/firestarter/Environment/X86/Payload/ZENFMAPayload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@

#pragma once

#include <cstdint>
#include <firestarter/Environment/X86/Payload/X86Payload.hpp>
#include "X86Payload.hpp"

namespace firestarter::environment::x86::payload {
class ZENFMAPayload final : public X86Payload {
Expand All @@ -39,8 +38,8 @@ class ZENFMAPayload final : public X86Payload {
[[nodiscard]] auto getAvailableInstructions() const -> std::list<std::string> 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<firestarter::environment::payload::Payload> override {
return std::make_unique<ZENFMAPayload>(this->supportedFeatures());
};

private:
Expand Down
12 changes: 6 additions & 6 deletions include/firestarter/Environment/X86/Platform/BulldozerConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@

#pragma once

#include <firestarter/Environment/X86/Payload/FMA4Payload.hpp>
#include <firestarter/Environment/X86/Platform/X86PlatformConfig.hpp>
#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<payload::FMA4Payload>(SupportedFeatures)) {}

std::vector<std::pair<std::string, unsigned>> getDefaultPayloadSettings() const override {
[[nodiscard]] auto getDefaultPayloadSettings() const -> std::vector<std::pair<std::string, unsigned>> override {
return std::vector<std::pair<std::string, unsigned>>(
{{"RAM_L", 1}, {"L3_L", 1}, {"L2_LS", 5}, {"L1_L", 90}, {"REG", 45}});
}
Expand Down
Loading

0 comments on commit ff6113b

Please sign in to comment.