From bfc21677ade733efe5049e2ca835ee934ccae8c8 Mon Sep 17 00:00:00 2001 From: Markus Schmidl Date: Mon, 7 Oct 2024 18:51:15 +0200 Subject: [PATCH] fix errors in MSC compile --- include/firestarter/LoadWorkerData.hpp | 7 ++++--- include/firestarter/Optimizer/History.hpp | 5 +---- include/firestarter/WindowsCompat.hpp | 20 ++++++++++++++++++++ src/firestarter/DumpRegisterWorker.cpp | 3 ++- src/firestarter/Environment/CPUTopology.cpp | 5 +++-- src/firestarter/Environment/Environment.cpp | 2 +- src/firestarter/Firestarter.cpp | 3 ++- src/firestarter/LoadWorker.cpp | 8 ++++---- 8 files changed, 37 insertions(+), 16 deletions(-) diff --git a/include/firestarter/LoadWorkerData.hpp b/include/firestarter/LoadWorkerData.hpp index ef45404c..65c3286d 100644 --- a/include/firestarter/LoadWorkerData.hpp +++ b/include/firestarter/LoadWorkerData.hpp @@ -26,6 +26,7 @@ #include "DumpRegisterStruct.hpp" #include "Environment/Environment.hpp" #include "ErrorDetectionStruct.hpp" +#include #include #include #include @@ -106,7 +107,7 @@ class LoadWorkerData { } }; - LoadWorkerData(int Id, environment::Environment& Environment, volatile LoadThreadWorkType& LoadVar, + LoadWorkerData(uint64_t Id, environment::Environment& Environment, volatile LoadThreadWorkType& LoadVar, std::chrono::microseconds Period, bool DumpRegisters, bool ErrorDetection) : LoadVar(LoadVar) , Period(Period) @@ -124,7 +125,7 @@ class LoadWorkerData { this->CommunicationRight = std::move(CommunicationRight); } - [[nodiscard]] auto id() const -> int { return Id; } + [[nodiscard]] auto id() const -> uint64_t { return Id; } [[nodiscard]] auto environment() const -> environment::Environment& { return Environment; } [[nodiscard]] auto config() const -> environment::platform::RuntimeConfig& { return *Config; } @@ -173,7 +174,7 @@ class LoadWorkerData { std::shared_ptr CommunicationRight; private: - int Id; + uint64_t Id; environment::Environment& Environment; environment::platform::RuntimeConfig* Config; }; diff --git a/include/firestarter/Optimizer/History.hpp b/include/firestarter/Optimizer/History.hpp index 21d969f5..b6acc566 100644 --- a/include/firestarter/Optimizer/History.hpp +++ b/include/firestarter/Optimizer/History.hpp @@ -25,6 +25,7 @@ #include "../Logging/Log.hpp" #include "../Measurement/Summary.hpp" #include "Individual.hpp" +#include "firestarter/WindowsCompat.hpp" // IWYU pragma: keep #include #include #include @@ -35,10 +36,6 @@ #include #include -extern "C" { -#include -} - namespace firestarter::optimizer { struct History { diff --git a/include/firestarter/WindowsCompat.hpp b/include/firestarter/WindowsCompat.hpp index cfff3a41..8eb46144 100644 --- a/include/firestarter/WindowsCompat.hpp +++ b/include/firestarter/WindowsCompat.hpp @@ -58,9 +58,21 @@ namespace { #include inline auto get_current_dir_name() -> char* { return _getcwd(nullptr, 0); } } // namespace +#else +#include +#endif + +// correct include for gethostname +#ifdef _MSC_VER +#include +#else +// NOLINTBEGIN(readability-duplicate-include) +#include +// NOLINTEND(readability-duplicate-include) #endif // Make references in header files to pthread_t compatible to MSC. This will not make them functionally work. +// We will be able to remove this hack once we transition from using pthread to std::thread #ifdef _MSC_VER struct Placeholder {}; using pthread_t = Placeholder; @@ -68,4 +80,12 @@ using pthread_t = Placeholder; extern "C" { #include } +#endif + +// Disable __asm__ __volatile__ in MSC +// Static assert wont work, since if constexpr doesn't seem to work correctly +#ifdef _MSC_VER +#define __volatile__(X, ...) \ + assert(false && "Attempted to use code path that uses the incorrect inline assembly macros for MSC.") +#define __asm__ #endif \ No newline at end of file diff --git a/src/firestarter/DumpRegisterWorker.cpp b/src/firestarter/DumpRegisterWorker.cpp index 97d5e135..37b7bb67 100644 --- a/src/firestarter/DumpRegisterWorker.cpp +++ b/src/firestarter/DumpRegisterWorker.cpp @@ -65,8 +65,9 @@ void Firestarter::initDumpRegisterWorker(std::chrono::seconds DumpTimeDelta, con void Firestarter::joinDumpRegisterWorker() { this->DumpRegisterWorkerThread.join(); } void Firestarter::dumpRegisterWorker(std::unique_ptr Data) { - +#if defined(linux) || defined(__linux__) pthread_setname_np(pthread_self(), "DumpRegWorker"); +#endif const auto RegisterCount = Data->LoadWorkerDataPtr->config().payload().registerCount(); const auto RegisterSize = Data->LoadWorkerDataPtr->config().payload().registerSize(); diff --git a/src/firestarter/Environment/CPUTopology.cpp b/src/firestarter/Environment/CPUTopology.cpp index fa4d97ca..4283c34b 100644 --- a/src/firestarter/Environment/CPUTopology.cpp +++ b/src/firestarter/Environment/CPUTopology.cpp @@ -68,7 +68,8 @@ auto CPUTopology::print(std::ostream& Stream) const -> std::ostream& { auto* CacheObj = hwloc_get_obj_by_type(Topology, Cache, 0); std::array String{}; - hwloc_obj_type_snprintf(String.begin(), sizeof(String), CacheObj, 0); + auto* StringPtr = String.data(); + hwloc_obj_type_snprintf(StringPtr, sizeof(String), CacheObj, 0); switch (CacheObj->attr->cache.type) { case HWLOC_OBJ_CACHE_DATA: @@ -378,7 +379,7 @@ auto CPUTopology::maxNumThreads() const -> unsigned { 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); + Max = (std::max)(Max, Obj->os_index); } return Max + 1; diff --git a/src/firestarter/Environment/Environment.cpp b/src/firestarter/Environment/Environment.cpp index a8c55cbc..88664044 100644 --- a/src/firestarter/Environment/Environment.cpp +++ b/src/firestarter/Environment/Environment.cpp @@ -178,7 +178,7 @@ void Environment::evaluateCpuAffinity(unsigned RequestedNumThreads, const std::s } #endif - this->RequestedNumThreads = std::min(RequestedNumThreads, topology().maxNumThreads()); + this->RequestedNumThreads = (std::min)(RequestedNumThreads, topology().maxNumThreads()); } void Environment::printThreadSummary() { diff --git a/src/firestarter/Firestarter.cpp b/src/firestarter/Firestarter.cpp index abc02acb..534dec53 100644 --- a/src/firestarter/Firestarter.cpp +++ b/src/firestarter/Firestarter.cpp @@ -19,6 +19,7 @@ * Contact: daniel.hackenberg@tu-dresden.de *****************************************************************************/ +#include "firestarter/WindowsCompat.hpp" #include #include #include @@ -179,7 +180,7 @@ Firestarter::Firestarter(const int Argc, const char** Argv, std::chrono::seconds signalWork(); - uint64_t StartTimestamp = std::numeric_limits::max(); + uint64_t StartTimestamp = (std::numeric_limits::max)(); uint64_t StopTimestamp = 0; for (auto const& Thread : LoadThreads) { diff --git a/src/firestarter/LoadWorker.cpp b/src/firestarter/LoadWorker.cpp index 2ecf5d43..5a136a40 100644 --- a/src/firestarter/LoadWorker.cpp +++ b/src/firestarter/LoadWorker.cpp @@ -92,7 +92,7 @@ void Firestarter::initLoadWorkers(bool LowLoad, std::chrono::microseconds 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()); } LoadThreads.emplace_back(std::move(T), Td); @@ -175,7 +175,7 @@ void Firestarter::printThreadErrorReport() { void Firestarter::printPerformanceReport() { // performance report - uint64_t StartTimestamp = std::numeric_limits::max(); + uint64_t StartTimestamp = (std::numeric_limits::max)(); uint64_t StopTimestamp = 0; uint64_t Iterations = 0; @@ -188,8 +188,8 @@ void Firestarter::printPerformanceReport() { log::debug() << "Thread " << Td->id() << ": " << Td->LastRun.Iterations << " iterations, tsc_delta: " << Td->LastRun.StopTsc - Td->LastRun.StartTsc; - StartTimestamp = std::min(StartTimestamp, Td->LastRun.StartTsc.load()); - StopTimestamp = std::max(StopTimestamp, Td->LastRun.StopTsc.load()); + StartTimestamp = (std::min)(StartTimestamp, Td->LastRun.StartTsc.load()); + StopTimestamp = (std::max)(StopTimestamp, Td->LastRun.StopTsc.load()); Iterations += Td->LastRun.Iterations.load(); }