From 130cf6de85e6a9eb58e38bfa5968bdc72fe6c9f3 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Mon, 19 Apr 2021 11:49:10 +0200 Subject: [PATCH] Fix: don't use floating point when calculating huge pages percentage I somehow got 101% displayed sometimes. --- src/backend/cpu/CpuBackend.cpp | 2 +- src/crypto/common/HugePagesInfo.h | 2 +- src/crypto/rx/RxBasicStorage.cpp | 2 +- src/crypto/rx/RxNUMAStorage.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/backend/cpu/CpuBackend.cpp b/src/backend/cpu/CpuBackend.cpp index 6fb74b20..08f6173e 100644 --- a/src/backend/cpu/CpuBackend.cpp +++ b/src/backend/cpu/CpuBackend.cpp @@ -116,7 +116,7 @@ public: return; } - LOG_INFO("%s" GREEN_BOLD(" READY") " threads %s%zu/%zu (%zu)" CLEAR " huge pages %s%1.0f%% %zu/%zu" CLEAR " memory " CYAN_BOLD("%zu KB") BLACK_BOLD(" (%" PRIu64 " ms)"), + LOG_INFO("%s" GREEN_BOLD(" READY") " threads %s%zu/%zu (%zu)" CLEAR " huge pages %s%d%% %zu/%zu" CLEAR " memory " CYAN_BOLD("%zu KB") BLACK_BOLD(" (%" PRIu64 " ms)"), Tags::cpu(), m_errors == 0 ? CYAN_BOLD_S : YELLOW_BOLD_S, m_started, m_threads, m_ways, diff --git a/src/crypto/common/HugePagesInfo.h b/src/crypto/common/HugePagesInfo.h index 295817e3..398ce7a6 100644 --- a/src/crypto/common/HugePagesInfo.h +++ b/src/crypto/common/HugePagesInfo.h @@ -41,7 +41,7 @@ public: size_t size = 0; inline bool isFullyAllocated() const { return allocated == total; } - inline double percent() const { return allocated == 0 ? 0.0 : static_cast(allocated) / total * 100.0; } + inline int percent() const { return allocated ? static_cast((allocated * 100 + total / 2) / total) : 0; } inline void reset() { allocated = 0; total = 0; size = 0; } inline HugePagesInfo &operator+=(const HugePagesInfo &other) diff --git a/src/crypto/rx/RxBasicStorage.cpp b/src/crypto/rx/RxBasicStorage.cpp index eacb6295..7c789926 100644 --- a/src/crypto/rx/RxBasicStorage.cpp +++ b/src/crypto/rx/RxBasicStorage.cpp @@ -97,7 +97,7 @@ private: if (m_dataset->get() != nullptr) { const auto pages = m_dataset->hugePages(); - LOG_INFO("%s" GREEN_BOLD("allocated") CYAN_BOLD(" %zu MB") BLACK_BOLD(" (%zu+%zu)") " huge pages %s%1.0f%% %u/%u" CLEAR " %sJIT" BLACK_BOLD(" (%" PRIu64 " ms)"), + LOG_INFO("%s" GREEN_BOLD("allocated") CYAN_BOLD(" %zu MB") BLACK_BOLD(" (%zu+%zu)") " huge pages %s%d%% %u/%u" CLEAR " %sJIT" BLACK_BOLD(" (%" PRIu64 " ms)"), Tags::randomx(), pages.size / oneMiB, RxDataset::maxSize() / oneMiB, diff --git a/src/crypto/rx/RxNUMAStorage.cpp b/src/crypto/rx/RxNUMAStorage.cpp index 6bd5627f..3c0d2bda 100644 --- a/src/crypto/rx/RxNUMAStorage.cpp +++ b/src/crypto/rx/RxNUMAStorage.cpp @@ -269,7 +269,7 @@ private: { const auto pages = dataset->hugePages(); - LOG_INFO("%s" CYAN_BOLD("#%u ") GREEN_BOLD("allocated") CYAN_BOLD(" %zu MB") " huge pages %s%3.0f%%" CLEAR BLACK_BOLD(" (%" PRIu64 " ms)"), + LOG_INFO("%s" CYAN_BOLD("#%u ") GREEN_BOLD("allocated") CYAN_BOLD(" %zu MB") " huge pages %s%d%%" CLEAR BLACK_BOLD(" (%" PRIu64 " ms)"), Tags::randomx(), nodeId, pages.size / oneMiB,