Skip to content

Commit

Permalink
fix errors in MSC compile
Browse files Browse the repository at this point in the history
  • Loading branch information
marenz2569 committed Oct 7, 2024
1 parent 230103d commit bfc2167
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 16 deletions.
7 changes: 4 additions & 3 deletions include/firestarter/LoadWorkerData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "DumpRegisterStruct.hpp"
#include "Environment/Environment.hpp"
#include "ErrorDetectionStruct.hpp"
#include <array>
#include <atomic>
#include <cmath>
#include <cstddef>
Expand Down Expand Up @@ -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)
Expand All @@ -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; }

Expand Down Expand Up @@ -173,7 +174,7 @@ class LoadWorkerData {
std::shared_ptr<uint64_t> CommunicationRight;

private:
int Id;
uint64_t Id;
environment::Environment& Environment;
environment::platform::RuntimeConfig* Config;
};
Expand Down
5 changes: 1 addition & 4 deletions include/firestarter/Optimizer/History.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "../Logging/Log.hpp"
#include "../Measurement/Summary.hpp"
#include "Individual.hpp"
#include "firestarter/WindowsCompat.hpp" // IWYU pragma: keep
#include <algorithm>
#include <cassert>
#include <cstring>
Expand All @@ -35,10 +36,6 @@
#include <optional>
#include <vector>

extern "C" {
#include <unistd.h>
}

namespace firestarter::optimizer {

struct History {
Expand Down
20 changes: 20 additions & 0 deletions include/firestarter/WindowsCompat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,34 @@ namespace {
#include <direct.h>
inline auto get_current_dir_name() -> char* { return _getcwd(nullptr, 0); }
} // namespace
#else
#include <unistd.h>
#endif

// correct include for gethostname
#ifdef _MSC_VER
#include <winsock.h>
#else
// NOLINTBEGIN(readability-duplicate-include)
#include <unistd.h>
// 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;
#else
extern "C" {
#include <pthread.h>
}
#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
3 changes: 2 additions & 1 deletion src/firestarter/DumpRegisterWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ void Firestarter::initDumpRegisterWorker(std::chrono::seconds DumpTimeDelta, con
void Firestarter::joinDumpRegisterWorker() { this->DumpRegisterWorkerThread.join(); }

void Firestarter::dumpRegisterWorker(std::unique_ptr<DumpRegisterWorkerData> 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();
Expand Down
5 changes: 3 additions & 2 deletions src/firestarter/Environment/CPUTopology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char, 128> 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:
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/firestarter/Environment/Environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion src/firestarter/Firestarter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Contact: [email protected]
*****************************************************************************/

#include "firestarter/WindowsCompat.hpp"
#include <algorithm>
#include <csignal>
#include <firestarter/Environment/X86/X86Environment.hpp>
Expand Down Expand Up @@ -179,7 +180,7 @@ Firestarter::Firestarter(const int Argc, const char** Argv, std::chrono::seconds

signalWork();

uint64_t StartTimestamp = std::numeric_limits<uint64_t>::max();
uint64_t StartTimestamp = (std::numeric_limits<uint64_t>::max)();
uint64_t StopTimestamp = 0;

for (auto const& Thread : LoadThreads) {
Expand Down
8 changes: 4 additions & 4 deletions src/firestarter/LoadWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<firestarter::logging::Record>::setFirstThread(T.get_id());
firestarter::logging::FirstWorkerThreadFilter<firestarter::logging::record>::setFirstThread(T.get_id());
}

LoadThreads.emplace_back(std::move(T), Td);
Expand Down Expand Up @@ -175,7 +175,7 @@ void Firestarter::printThreadErrorReport() {

void Firestarter::printPerformanceReport() {
// performance report
uint64_t StartTimestamp = std::numeric_limits<uint64_t>::max();
uint64_t StartTimestamp = (std::numeric_limits<uint64_t>::max)();
uint64_t StopTimestamp = 0;

uint64_t Iterations = 0;
Expand All @@ -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();
}
Expand Down

0 comments on commit bfc2167

Please sign in to comment.