From a8d40d15fd9c52fd69a330fb0a5b1b55eeb45102 Mon Sep 17 00:00:00 2001 From: psychocrypt Date: Wed, 12 Apr 2017 21:15:36 +0200 Subject: [PATCH 01/25] refactor CMake - allow compiling without microhttpd - allow compiling without OpenSSL - install `config.txt` with command `make install` --- CMakeLists.txt | 104 +++++++++++++++++++++++++++++++++++++++++-------- cli-miner.cpp | 7 +++- httpd.cpp | 4 ++ 3 files changed, 97 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85249c4..49b7065 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,38 +1,108 @@ project(xmr-stak-cpu) -cmake_minimum_required(VERSION 2.8.10) +cmake_minimum_required(VERSION 3.0.1) +# enforce C++11 +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_CXX_STANDARD 11) + +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "install prefix" FORCE) +endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + +# allow user to extent CMAKE_PREFIX_PATH via environment variable +list(APPEND CMAKE_PREFIX_PATH "$ENV{CMAKE_PREFIX_PATH}") + +################################################################################ +# CMake user options +################################################################################ + +# gcc 5.1 is the first GNU version without CoW strings +# https://github.com/fireice-uk/xmr-stak-nvidia/pull/10#issuecomment-290821792 +# If you remove this guard to compile with older gcc versions the miner will produce +# a high rate of wrong shares. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1) + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1) message(FATAL_ERROR "GCC version must be at least 5.1!") endif() endif() +set(BUILD_TYPE "Release;Debug") +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build" FORCE) +endif() +set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${BUILD_TYPE}") + +################################################################################ +# Find PThreads +################################################################################ + +find_package(Threads REQUIRED) +set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT}) + +################################################################################ +# Find microhttpd +################################################################################ + find_library(MHTD NAMES microhttpd) if("${MHTD}" STREQUAL "MHTD-NOTFOUND") - message(FATAL_ERROR "libmicrohttpd is required") + message(STATUS "microhttpd NOT found: disable http server") + add_definitions("-DCONF_NO_HTTPD") +else() + set(LIBS ${LIBS} ${MHTD}) endif() -find_package(OpenSSL REQUIRED) +############################################################################### +# Find OpenSSL +############################################################################### + +find_package(OpenSSL) include_directories(${OPENSSL_INCLUDE_DIR}) - -#set(CMAKE_VERBOSE_MAKEFILE ON) -set(CMAKE_CONFIGURATION_TYPES "RELEASE;STATIC") -if("${CMAKE_BUILD_TYPE}" STREQUAL "") - set(CMAKE_BUILD_TYPE RELEASE) +set(LIBS ${LIBS} ${OPENSSL_LIBRARIES}) +if(NOT OPENSSL_FOUND) + add_definitions("-DCONF_NO_TLS") endif() -set(CMAKE_C_FLAGS "-DNDEBUG -march=westmere -O3 -m64 -s") -set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11") +################################################################################ +# Compile & Link +################################################################################ -set(CMAKE_EXE_LINKER_FLAGS_RELSEASE "") -set(CMAKE_EXE_LINKER_FLAGS_STATIC "-static-libgcc -static-libstdc++") +# activate sse2 and aes-ni +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -maes") + +file(GLOB SRCFILES_CPP "*.cpp" "crypto/*.cpp") +file(GLOB SRCFILES_C "crypto/*.c") + +add_library(xmr-stak-c + STATIC + ${SRCFILES_C} +) +set_property(TARGET xmr-stak-c PROPERTY C_STANDARD 99) + +add_executable(xmr-stak-cpu + ${SRCFILES_CPP} +) set(EXECUTABLE_OUTPUT_PATH "bin") +target_link_libraries(xmr-stak-cpu xmr-stak-c ${LIBS}) -file(GLOB SOURCES "crypto/*.c" "crypto/*.cpp" "*.cpp") +################################################################################ +# Install +################################################################################ -add_executable(xmr-stak-cpu ${SOURCES}) -target_link_libraries(xmr-stak-cpu pthread microhttpd crypto ssl) - +# do not install the binary if the project and install are equal +if( NOT "${CMAKE_INSTALL_PREFIX}" STREQUAL "${PROJECT_BINARY_DIR}" ) + install(TARGETS xmr-stak-amd + RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/bin") +endif() + +# avoid overwrite of user defined settings +# install `config.txt`if file not exists in `${CMAKE_INSTALL_PREFIX}/bin` +install(CODE " \ + if(NOT EXISTS ${CMAKE_INSTALL_PREFIX}/bin/config.txt)\n \ + file(INSTALL ${CMAKE_CURRENT_SOURCE_DIR}/config.txt \ + DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)\n \ + endif()" +) diff --git a/cli-miner.cpp b/cli-miner.cpp index 9eec369..8d5f83e 100644 --- a/cli-miner.cpp +++ b/cli-miner.cpp @@ -26,7 +26,10 @@ #include "jconf.h" #include "console.h" #include "donate-level.h" -#include "httpd.h" + +#ifndef CONF_NO_HTTPD +# include "httpd.h" +#endif #include #include @@ -109,6 +112,7 @@ int main(int argc, char *argv[]) return 0; } +#ifndef CONF_NO_HTTPD if(jconf::inst()->GetHttpdPort() != 0) { if (!httpd::inst()->start_daemon()) @@ -117,6 +121,7 @@ int main(int argc, char *argv[]) return 0; } } +#endif printer::inst()->print_str("-------------------------------------------------------------------\n"); printer::inst()->print_str("XMR-Stak-CPU mining software, CPU Version.\n"); diff --git a/httpd.cpp b/httpd.cpp index 7e82aa3..7c94f76 100644 --- a/httpd.cpp +++ b/httpd.cpp @@ -21,6 +21,8 @@ * */ +#ifndef CONF_NO_HTTPD + #include #include #include @@ -142,3 +144,5 @@ bool httpd::start_daemon() return true; } +#endif + From c3650df13dea6ea27ee2c8016597e229fbdaf122 Mon Sep 17 00:00:00 2001 From: psychocrypt Date: Wed, 19 Apr 2017 21:40:16 +0200 Subject: [PATCH 02/25] extend `.gitignore` --- .gitignore | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.gitignore b/.gitignore index 8356f53..60a43db 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,12 @@ obj/ xmr-stak-cpu.layout xmr-stak-cpu.depend config-debug.txt + +# netbeans project files +/nbproject/ + +# tmp files +*~ + +# merge original backup files +*.orig From 91fd7e20b18895818719419276c155a440cf51db Mon Sep 17 00:00:00 2001 From: psychocrypt Date: Wed, 19 Apr 2017 21:42:29 +0200 Subject: [PATCH 03/25] always build feature complete - throw an error if a compile dependancy is not fullfilled - add options to disable hard compile dependancies --- CMakeLists.txt | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 49b7065..5aa8b16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,10 +45,15 @@ set(LIBS ${LIBS} ${CMAKE_THREAD_LIBS_INIT}) # Find microhttpd ################################################################################ +option(MICROHTTPD_REQUIRED "Enable or disable the requirement of microhttp (http deamon)" ON) find_library(MHTD NAMES microhttpd) if("${MHTD}" STREQUAL "MHTD-NOTFOUND") - message(STATUS "microhttpd NOT found: disable http server") - add_definitions("-DCONF_NO_HTTPD") + if(MICROHTTPD_REQUIRED) + message(FATAL_ERROR "microhttpd NOT found: use `-DMICROHTTPD_REQUIRED=OFF` to build without http deamon support") + else() + message(STATUS "microhttpd NOT found: disable http server") + add_definitions("-DCONF_NO_HTTPD") + endif() else() set(LIBS ${LIBS} ${MHTD}) endif() @@ -57,11 +62,19 @@ endif() # Find OpenSSL ############################################################################### +option(OpenSSL_REQUIRED "Enable or disable the requirement of OpenSSL" ON) find_package(OpenSSL) -include_directories(${OPENSSL_INCLUDE_DIR}) -set(LIBS ${LIBS} ${OPENSSL_LIBRARIES}) -if(NOT OPENSSL_FOUND) - add_definitions("-DCONF_NO_TLS") +if(OPENSSL_FOUND) + include_directories(${OPENSSL_INCLUDE_DIR}) + set(LIBS ${LIBS} ${OPENSSL_LIBRARIES}) +else() + if(OpenSSL_REQUIRED) + message(FATAL_ERROR "OpenSSL NOT found: use `-DOpenSSL_REQUIRED=OFF` to build without SSL support") + else() + if(NOT OPENSSL_FOUND) + add_definitions("-DCONF_NO_TLS") + endif() + endif() endif() ################################################################################ From 63b22a4d32ecc5dd640450b9572705b4792ae2c6 Mon Sep 17 00:00:00 2001 From: psychocrypt Date: Wed, 19 Apr 2017 22:07:48 +0200 Subject: [PATCH 04/25] extend `README.txt` add overview about advanced compile options --- README.md | 63 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 43de2e6..c1cf297 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -### XMR-Stak-CPU - Monero mining software +# XMR-Stak-CPU - Monero mining software XMR-Stak is a universal Stratum pool miner. This is the CPU-mining version; there is also an [AMD GPU version](https://github.com/fireice-uk/xmr-stak-amd) and an [NVIDA GPU version](https://github.com/fireice-uk/xmr-stak-nvidia) -#### HTML reports +## HTML reports -#### Usage on Windows +## Usage on Windows 1) Edit the config.txt file to enter your pool login and password. 2) Double click the exe file. @@ -42,22 +42,27 @@ lBoYbHZRpcWUfDO8o2y+ZQIs+yzMoJHHBBXB9fsHlwq62PTtzjsEVwB2aq9ABzk= ``` -#### Usage on Linux (Debian-based distros) +## Compile on Linux (Debian-based distros) + +### GNU Compiler ``` sudo apt-get install libmicrohttpd-dev libssl-dev cmake build-essential cmake . - make + make install ``` -GCC version 5.1 or higher is required for full C++11 support. CMake release compile scripts, as well as CodeBlocks build environment for debug builds is included. +- GCC version 5.1 or higher is required for full C++11 support. CMake release compile scripts, as well as CodeBlocks build environment for debug builds is included. -To do a static build for a system without gcc 5.1+ +### To do a static build for a system without gcc 5.1+ ``` - cmake -DCMAKE_BUILD_TYPE=STATIC - make + cmake -DCMAKE_BUILD_TYPE=STATIC . + make install ``` Note - cmake caches variables, so if you want to do a dynamic build later you need to specify '-DCMAKE_BUILD_TYPE=RELEASE' + +You can find a complete compile guide under [Advanced Compile Options](#advanced-compile-options). + #### CPU mining performance Performance is nearly identical to the closed source paid miners. Here are some numbers: @@ -67,7 +72,7 @@ Performance is nearly identical to the closed source paid miners. Here are some * **Dual X5650** - 466 H/s (depends on NUMA) * **Dual E5640** - 365 H/s (same as above) -#### Default dev donation +## Default dev donation By default the miner will donate 1% of the hashpower (1 minute in 100 minutes) to my pool. If you want to change that, edit **donate-level.h** before you build the binaries. If you want to donate directly to support further development, here is my wallet @@ -76,7 +81,7 @@ If you want to donate directly to support further development, here is my wallet 4581HhZkQHgZrZjKeCfCJxZff9E3xCgHGF25zABZz7oR71TnbbgiS7sK9jveE6Dx6uMs2LwszDuvQJgRZQotdpHt1fTdDhk ``` -#### PGP Key +## PGP Key ``` -----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v2 @@ -110,7 +115,7 @@ c4hC0Yg9Dha1OoE5CJCqVL+ic4vAyB1urAwBlsd/wH8= -----END PGP PUBLIC KEY BLOCK----- ``` -### Common Issues +## Common Issues **SeLockMemoryPrivilege failed** @@ -160,4 +165,38 @@ You can also do it Windows-style and simply run-as-root, but this is NOT recomme This typically means you are trying to run it on a CPU that does not have [AES](https://en.wikipedia.org/wiki/AES_instruction_set). This only happens on older version of miner, new version gives better error message (but still wont' work since your CPU doesn't support the required instructions). +## Advanced Compile Options +The build system is CMake, if you are not familiar with CMake you can learn more [here](https://cmake.org/runningcmake/). + +### Short Description + +There are two easy ways to set variables for `cmake` to configure *xmr-stak-cpu* +- use the ncurses GUI + - `ccmake .` + - edit your options + - end the GUI by pressing the key `c`(create) and than `g`(generate) +- set Options on the command line + - enable a option: `cmake . -DNAME_OF_THE_OPTION=ON` + - disable a option `cmake . -DNAME_OF_THE_OPTION=OFF` + - set a value `cmake . -DNAME_OF_THE_OPTION=value` + +After the configuration you need to call +`make install` for slow sequential build +or +`make -j install` for faster parallel build +and install. + +### xmr-stak-cpu Compile Options +- `CMAKE_INSTALL_PREFIX` install miner to the home folder + - `cmake . -DCMAKE_INSTALL_PREFIX=$HOME/xmr-stak-cpu` + - you can find the binary and the `config.txt` file after `make install` in `$HOME/xmr-stak-cpu/bin` +-`CMAKE_BUILD_TYPE` set the build type + - valid options: `Release` or `Debug` + - you should always keep `Release` for your productive miners +- `MICROHTTPD_REQUIRED` allow to disable/enable the dependency *microhttpd* + - by default enabled + - there is no *http* interface available if option is disabled: `cmake . -DMICROHTTPD_REQUIRED=OFF` +- `OpenSSL_REQUIRED`allow to disable/enable the dependency *OpenSSL* + - by default enabled + - it is not possible to connect to a *https* secured pool if optin is disabled: `cmake . -DOpenSSL_REQUIRED=OFF` From fcadda3035bac526124d9f93de608fb4b9a84992 Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Thu, 20 Apr 2017 10:27:28 +0100 Subject: [PATCH 05/25] Added psychocrypt's wallet --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index c1cf297..4f662a4 100644 --- a/README.md +++ b/README.md @@ -77,10 +77,16 @@ By default the miner will donate 1% of the hashpower (1 minute in 100 minutes) t If you want to donate directly to support further development, here is my wallet +fireice-uk: ``` 4581HhZkQHgZrZjKeCfCJxZff9E3xCgHGF25zABZz7oR71TnbbgiS7sK9jveE6Dx6uMs2LwszDuvQJgRZQotdpHt1fTdDhk ``` +psychocrypt: +``` +43NoJVEXo21hGZ6tDG6Z3g4qimiGdJPE6GRxAmiWwm26gwr62Lqo7zRiCJFSBmbkwTGNuuES9ES5TgaVHceuYc4Y75txCTU +``` + ## PGP Key ``` -----BEGIN PGP PUBLIC KEY BLOCK----- From 015111fae68c5941362d9287be1dbfc38197a344 Mon Sep 17 00:00:00 2001 From: psychocrypt Date: Thu, 20 Apr 2017 21:21:10 +0200 Subject: [PATCH 06/25] allow optional static linking - add cmake option `CMAKE_LINK_STATIC` - add missing `CMAKE_C_FLAGS` - change documentation --- CMakeLists.txt | 14 +++++++++++++- README.md | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5aa8b16..e87d69d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,9 @@ if(NOT CMAKE_BUILD_TYPE) endif() set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${BUILD_TYPE}") +# option to add static libgcc and libstdc++ +option(CMAKE_LINK_STATIC "link as much as possible libraries static" OFF) + ################################################################################ # Find PThreads ################################################################################ @@ -83,6 +86,15 @@ endif() # activate sse2 and aes-ni set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -maes") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2 -maes") + +# activate static libgcc and libstdc++ linking +if(CMAKE_LINK_STATIC) + set(BUILD_SHARED_LIBRARIES OFF) + set(DL_LIB ${CMAKE_DL_LIBS}) + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") + set(LIBS "-static-libgcc -static-libstdc++ ${LIBS}") +endif() file(GLOB SRCFILES_CPP "*.cpp" "crypto/*.cpp") file(GLOB SRCFILES_C "crypto/*.c") @@ -98,7 +110,7 @@ add_executable(xmr-stak-cpu ) set(EXECUTABLE_OUTPUT_PATH "bin") -target_link_libraries(xmr-stak-cpu xmr-stak-c ${LIBS}) +target_link_libraries(xmr-stak-cpu ${LIBS} xmr-stak-c) ################################################################################ # Install diff --git a/README.md b/README.md index 4f662a4..c0938e2 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ lBoYbHZRpcWUfDO8o2y+ZQIs+yzMoJHHBBXB9fsHlwq62PTtzjsEVwB2aq9ABzk= ### To do a static build for a system without gcc 5.1+ ``` - cmake -DCMAKE_BUILD_TYPE=STATIC . + cmake -DCMAKE_LINK_STATIC=ON . make install ``` Note - cmake caches variables, so if you want to do a dynamic build later you need to specify '-DCMAKE_BUILD_TYPE=RELEASE' @@ -197,6 +197,8 @@ and install. - `CMAKE_INSTALL_PREFIX` install miner to the home folder - `cmake . -DCMAKE_INSTALL_PREFIX=$HOME/xmr-stak-cpu` - you can find the binary and the `config.txt` file after `make install` in `$HOME/xmr-stak-cpu/bin` +- `CMAKE_LINK_STATIC` link libgcc and libstdc++ libraries static (default OFF) + - disable with `cmake . -DCMAKE_LINK_STATIC=ON` -`CMAKE_BUILD_TYPE` set the build type - valid options: `Release` or `Debug` - you should always keep `Release` for your productive miners From fdcf349cbb4bb52f85f736b69d6d40324d364fc9 Mon Sep 17 00:00:00 2001 From: psychocrypt Date: Thu, 20 Apr 2017 21:30:59 +0200 Subject: [PATCH 07/25] speed improvement Increase the performance for systems without huge memory pages to the performance with huge pages. Use 2 MiB alignment for memory allocations. --- crypto/cryptonight_common.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crypto/cryptonight_common.cpp b/crypto/cryptonight_common.cpp index 6955dc1..bbcff34 100644 --- a/crypto/cryptonight_common.cpp +++ b/crypto/cryptonight_common.cpp @@ -114,7 +114,8 @@ cryptonight_ctx* cryptonight_alloc_ctx(size_t use_fast_mem, size_t use_mlock, al if(use_fast_mem == 0) { - ptr->long_state = (uint8_t*)_mm_malloc(MEMORY, 4096); + // use 2MiB aligned memory + ptr->long_state = (uint8_t*)_mm_malloc(MEMORY, 2*1024*1024); ptr->ctx_info[0] = 0; ptr->ctx_info[1] = 0; return ptr; From 259b0b3a23dfac55d7440e206738694cb5fd5e2c Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Fri, 21 Apr 2017 09:28:25 +0100 Subject: [PATCH 08/25] Faster multiplication --- crypto/cryptonight.h | 5 -- crypto/cryptonight_aesni.h | 37 +++++++++-- crypto/cryptonight_common.cpp | 20 ------ jconf.cpp | 17 ++++- jconf.h | 2 + minethd.cpp | 122 ++++++++++++++++++++++------------ minethd.h | 7 ++ xmr-stak-cpu.cbp | 2 +- 8 files changed, 137 insertions(+), 75 deletions(-) diff --git a/crypto/cryptonight.h b/crypto/cryptonight.h index f4ec843..978c798 100644 --- a/crypto/cryptonight.h +++ b/crypto/cryptonight.h @@ -24,11 +24,6 @@ size_t cryptonight_init(size_t use_fast_mem, size_t use_mlock, alloc_msg* msg); cryptonight_ctx* cryptonight_alloc_ctx(size_t use_fast_mem, size_t use_mlock, alloc_msg* msg); void cryptonight_free_ctx(cryptonight_ctx* ctx); -void cryptonight_hash_ctx(const void* input, size_t len, void* output, cryptonight_ctx* ctx); -void cryptonight_hash_ctx_soft(const void* input, size_t len, void* output, cryptonight_ctx* ctx); -void cryptonight_hash_ctx_np(const void* input, size_t len, void* output, cryptonight_ctx* ctx); -void cryptonight_double_hash_ctx(const void* input, size_t len, void* output, cryptonight_ctx* __restrict ctx0, cryptonight_ctx* __restrict ctx1); - #ifdef __cplusplus } #endif diff --git a/crypto/cryptonight_aesni.h b/crypto/cryptonight_aesni.h index 37672c6..de0f186 100644 --- a/crypto/cryptonight_aesni.h +++ b/crypto/cryptonight_aesni.h @@ -279,7 +279,7 @@ void cn_implode_scratchpad(const __m128i* input, __m128i* output) _mm_store_si128(output + 11, xout7); } -template +template void cryptonight_hash(const void* input, size_t len, void* output, cryptonight_ctx* ctx0) { keccak((const uint8_t *)input, len, ctx0->hash_state, 200); @@ -301,20 +301,28 @@ void cryptonight_hash(const void* input, size_t len, void* output, cryptonight_c { __m128i cx; cx = _mm_load_si128((__m128i *)&l0[idx0 & 0x1FFFF0]); + if(SOFT_AES) cx = soft_aesenc(cx, _mm_set_epi64x(ah0, al0)); else cx = _mm_aesenc_si128(cx, _mm_set_epi64x(ah0, al0)); + _mm_store_si128((__m128i *)&l0[idx0 & 0x1FFFF0], _mm_xor_si128(bx0, cx)); idx0 = _mm_cvtsi128_si64(cx); bx0 = cx; + if(PREFETCH) _mm_prefetch((const char*)&l0[idx0 & 0x1FFFF0], _MM_HINT_T0); uint64_t hi, lo, cl, ch; cl = ((uint64_t*)&l0[idx0 & 0x1FFFF0])[0]; ch = ((uint64_t*)&l0[idx0 & 0x1FFFF0])[1]; - lo = _umul128(idx0, cl, &hi); + + if(MULX) + lo = _mulx_u64(idx0, cl, (long long unsigned int*)&hi); + else + lo = _umul128(idx0, cl, &hi); + al0 += hi; ah0 += lo; ((uint64_t*)&l0[idx0 & 0x1FFFF0])[0] = al0; @@ -322,6 +330,7 @@ void cryptonight_hash(const void* input, size_t len, void* output, cryptonight_c ah0 ^= ch; al0 ^= cl; idx0 = al0; + if(PREFETCH) _mm_prefetch((const char*)&l0[idx0 & 0x1FFFF0], _MM_HINT_T0); } @@ -338,7 +347,7 @@ void cryptonight_hash(const void* input, size_t len, void* output, cryptonight_c // This lovely creation will do 2 cn hashes at a time. We have plenty of space on silicon // to fit temporary vars for two contexts. Function will read len*2 from input and write 64 bytes to output // We are still limited by L3 cache, so doubling will only work with CPUs where we have more than 2MB to core (Xeons) -template +template void cryptonight_double_hash(const void* input, size_t len, void* output, cryptonight_ctx* __restrict ctx0, cryptonight_ctx* __restrict ctx1) { keccak((const uint8_t *)input, len, ctx0->hash_state, 200); @@ -366,43 +375,61 @@ void cryptonight_double_hash(const void* input, size_t len, void* output, crypto { __m128i cx; cx = _mm_load_si128((__m128i *)&l0[idx0 & 0x1FFFF0]); + if(SOFT_AES) cx = soft_aesenc(cx, ax0); else cx = _mm_aesenc_si128(cx, ax0); + _mm_store_si128((__m128i *)&l0[idx0 & 0x1FFFF0], _mm_xor_si128(bx0, cx)); idx0 = _mm_cvtsi128_si64(cx); bx0 = cx; + if(PREFETCH) _mm_prefetch((const char*)&l0[idx0 & 0x1FFFF0], _MM_HINT_T0); cx = _mm_load_si128((__m128i *)&l1[idx1 & 0x1FFFF0]); + if(SOFT_AES) cx = soft_aesenc(cx, ax1); else cx = _mm_aesenc_si128(cx, ax1); + _mm_store_si128((__m128i *)&l1[idx1 & 0x1FFFF0], _mm_xor_si128(bx1, cx)); idx1 = _mm_cvtsi128_si64(cx); bx1 = cx; + if(PREFETCH) _mm_prefetch((const char*)&l1[idx1 & 0x1FFFF0], _MM_HINT_T0); uint64_t hi, lo; cx = _mm_load_si128((__m128i *)&l0[idx0 & 0x1FFFF0]); - lo = _umul128(idx0, _mm_cvtsi128_si64(cx), &hi); + + if(MULX) + lo = _mulx_u64(idx0, _mm_cvtsi128_si64(cx), (long long unsigned int*)&hi); + else + lo = _umul128(idx0, _mm_cvtsi128_si64(cx), &hi); + ax0 = _mm_add_epi64(ax0, _mm_set_epi64x(lo, hi)); _mm_store_si128((__m128i*)&l0[idx0 & 0x1FFFF0], ax0); ax0 = _mm_xor_si128(ax0, cx); idx0 = _mm_cvtsi128_si64(ax0); + if(PREFETCH) _mm_prefetch((const char*)&l0[idx0 & 0x1FFFF0], _MM_HINT_T0); cx = _mm_load_si128((__m128i *)&l1[idx1 & 0x1FFFF0]); - lo = _umul128(idx1, _mm_cvtsi128_si64(cx), &hi); + + if(MULX) + lo = _mulx_u64(idx1, _mm_cvtsi128_si64(cx), (long long unsigned int*)&hi); + else + lo = _umul128(idx1, _mm_cvtsi128_si64(cx), &hi); + ax1 = _mm_add_epi64(ax1, _mm_set_epi64x(lo, hi)); _mm_store_si128((__m128i*)&l1[idx1 & 0x1FFFF0], ax1); ax1 = _mm_xor_si128(ax1, cx); idx1 = _mm_cvtsi128_si64(ax1); + if(PREFETCH) _mm_prefetch((const char*)&l1[idx1 & 0x1FFFF0], _MM_HINT_T0); } diff --git a/crypto/cryptonight_common.cpp b/crypto/cryptonight_common.cpp index bbcff34..63ce3a4 100644 --- a/crypto/cryptonight_common.cpp +++ b/crypto/cryptonight_common.cpp @@ -190,23 +190,3 @@ void cryptonight_free_ctx(cryptonight_ctx* ctx) _mm_free(ctx); } - -void cryptonight_hash_ctx(const void* input, size_t len, void* output, cryptonight_ctx* ctx) -{ - cryptonight_hash<0x80000, MEMORY, true, false>(input, len, output, ctx); -} - -void cryptonight_hash_ctx_soft(const void* input, size_t len, void* output, cryptonight_ctx* ctx) -{ - cryptonight_hash<0x80000, MEMORY, true, true>(input, len, output, ctx); -} - -void cryptonight_hash_ctx_np(const void* input, size_t len, void* output, cryptonight_ctx* ctx) -{ - cryptonight_hash<0x80000, MEMORY, false, false>(input, len, output, ctx); -} - -void cryptonight_double_hash_ctx(const void* input, size_t len, void* output, cryptonight_ctx* __restrict ctx0, cryptonight_ctx* __restrict ctx1) -{ - cryptonight_double_hash<0x80000, MEMORY, false, false>(input, len, output, ctx0, ctx1); -} diff --git a/jconf.cpp b/jconf.cpp index 612065e..ce82525 100644 --- a/jconf.cpp +++ b/jconf.cpp @@ -253,8 +253,11 @@ bool jconf::check_cpu_features() { constexpr int AESNI_BIT = 1 << 25; constexpr int SSE2_BIT = 1 << 26; + constexpr int BMI2_BIT = 1 << 8; int cpu_info[4]; + bool bHaveSse2; + #ifdef _WIN32 __cpuid(cpu_info, 1); #else @@ -262,11 +265,23 @@ bool jconf::check_cpu_features() #endif bHaveAes = (cpu_info[2] & AESNI_BIT) != 0; + bHaveSse2 = (cpu_info[3] & SSE2_BIT) != 0; + +#ifdef _WIN32 + __cpuidex(cpu_info, 7, 0); +#else + __cpuid_count(7, 0, cpu_info[0], cpu_info[1], cpu_info[2], cpu_info[3]); +#endif + + bHaveBmi2 = (cpu_info[1] & BMI2_BIT) != 0; if(!bHaveAes) printer::inst()->print_msg(L0, "Your CPU doesn't support hardware AES. Don't expect high hashrates."); - return (cpu_info[3] & SSE2_BIT) != 0; + if(bHaveBmi2) + printer::inst()->print_msg(L0, "CPU supports BMI2 instructions. Faster multiplication enabled."); + + return bHaveSse2; } bool jconf::parse_config(const char* sFilename) diff --git a/jconf.h b/jconf.h index 6c3954b..7444a01 100644 --- a/jconf.h +++ b/jconf.h @@ -56,6 +56,7 @@ public: bool PreferIpv4(); inline bool HaveHardwareAes() { return bHaveAes; } + inline bool HaveMulx() { return bHaveBmi2; } private: jconf(); @@ -66,4 +67,5 @@ private: opaque_private* prv; bool bHaveAes; + bool bHaveBmi2; }; diff --git a/minethd.cpp b/minethd.cpp index 90a6f31..cf26037 100644 --- a/minethd.cpp +++ b/minethd.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "console.h" #ifdef _WIN32 @@ -62,7 +63,7 @@ void thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id) #include "executor.h" #include "minethd.h" #include "jconf.h" -#include "crypto/cryptonight.h" +#include "crypto/cryptonight_aesni.h" telemetry::telemetry(size_t iThd) { @@ -244,42 +245,29 @@ bool minethd::self_test() return false; } - bool bHasLp = ctx0->ctx_info[0] == 1 && ctx1->ctx_info[0] == 1; - size_t n = jconf::inst()->GetThreadCount(); - jconf::thd_cfg cfg; - for (size_t i = 0; i < n; i++) - { - jconf::inst()->GetThreadConfig(i, cfg); - - if(!bHasLp && cfg.bNoPrefetch) - { - printer::inst()->print_msg(L0, "Wrong config. You are running in slow memory mode with no_prefetch."); - cryptonight_free_ctx(ctx0); - cryptonight_free_ctx(ctx1); - return false; - } - } - unsigned char out[64]; bool bResult; - if(jconf::inst()->HaveHardwareAes()) - { - cryptonight_hash_ctx("This is a test", 14, out, ctx0); - bResult = memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0; + cn_hash_fun hashf; + cn_hash_fun_dbl hashdf; - cryptonight_hash_ctx_np("This is a test", 14, out, ctx0); - bResult &= memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0; + hashf = func_selector(jconf::inst()->HaveHardwareAes(), false, jconf::inst()->HaveMulx()); + hashf("This is a test", 14, out, ctx0); + bResult = memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0; - cryptonight_double_hash_ctx("The quick brown fox jumps over the lazy dogThe quick brown fox jumps over the lazy log", 43, out, ctx0, ctx1); - bResult &= memcmp(out, "\x3e\xbb\x7f\x9f\x7d\x27\x3d\x7c\x31\x8d\x86\x94\x77\x55\x0c\xc8\x00\xcf\xb1\x1b\x0c\xad\xb7\xff\xbd\xf6\xf8\x9f\x3a\x47\x1c\x59" - "\xb4\x77\xd5\x02\xe4\xd8\x48\x7f\x42\xdf\xe3\x8e\xed\x73\x81\x7a\xda\x91\xb7\xe2\x63\xd2\x91\x71\xb6\x5c\x44\x3a\x01\x2a\x41\x22", 64) == 0; - } - else - { - cryptonight_hash_ctx_soft("This is a test", 14, out, ctx0); - bResult = memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0; - } + hashf = func_selector(jconf::inst()->HaveHardwareAes(), true, jconf::inst()->HaveMulx()); + hashf("This is a test", 14, out, ctx0); + bResult &= memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0; + + hashdf = func_dbl_selector(jconf::inst()->HaveHardwareAes(), false, jconf::inst()->HaveMulx()); + hashdf("The quick brown fox jumps over the lazy dogThe quick brown fox jumps over the lazy log", 43, out, ctx0, ctx1); + bResult &= memcmp(out, "\x3e\xbb\x7f\x9f\x7d\x27\x3d\x7c\x31\x8d\x86\x94\x77\x55\x0c\xc8\x00\xcf\xb1\x1b\x0c\xad\xb7\xff\xbd\xf6\xf8\x9f\x3a\x47\x1c\x59" + "\xb4\x77\xd5\x02\xe4\xd8\x48\x7f\x42\xdf\xe3\x8e\xed\x73\x81\x7a\xda\x91\xb7\xe2\x63\xd2\x91\x71\xb6\x5c\x44\x3a\x01\x2a\x41\x22", 64) == 0; + + hashdf = func_dbl_selector(jconf::inst()->HaveHardwareAes(), true, jconf::inst()->HaveMulx()); + hashdf("The quick brown fox jumps over the lazy dogThe quick brown fox jumps over the lazy log", 43, out, ctx0, ctx1); + bResult &= memcmp(out, "\x3e\xbb\x7f\x9f\x7d\x27\x3d\x7c\x31\x8d\x86\x94\x77\x55\x0c\xc8\x00\xcf\xb1\x1b\x0c\xad\xb7\xff\xbd\xf6\xf8\x9f\x3a\x47\x1c\x59" + "\xb4\x77\xd5\x02\xe4\xd8\x48\x7f\x42\xdf\xe3\x8e\xed\x73\x81\x7a\xda\x91\xb7\xe2\x63\xd2\x91\x71\xb6\x5c\x44\x3a\x01\x2a\x41\x22", 64) == 0; cryptonight_free_ctx(ctx0); cryptonight_free_ctx(ctx1); @@ -350,21 +338,48 @@ void minethd::consume_work() iConsumeCnt++; } +minethd::cn_hash_fun minethd::func_selector(bool bHaveAes, bool bNoPrefetch, bool bMulx) +{ + // We have three independent flag bits in the functions + // therefore we will build a binary digit and select the + // function as a three digit binary + // Digit order SOFT_AES, NO_PREFETCH, MULX + + static const cn_hash_fun func_table[8] = { + cryptonight_hash<0x80000, MEMORY, false, false, false>, + cryptonight_hash<0x80000, MEMORY, false, false, true>, + cryptonight_hash<0x80000, MEMORY, false, true, false>, + cryptonight_hash<0x80000, MEMORY, false, true, true>, + cryptonight_hash<0x80000, MEMORY, true, false, false>, + cryptonight_hash<0x80000, MEMORY, true, false, true>, + cryptonight_hash<0x80000, MEMORY, true, true, false>, + cryptonight_hash<0x80000, MEMORY, true, true, true> + }; + + std::bitset<3> digit; + digit.set(0, bMulx); + digit.set(1, bNoPrefetch); + digit.set(2, !bHaveAes); + + return func_table[digit.to_ulong()]; +} + void minethd::work_main() { + cn_hash_fun hash_fun; cryptonight_ctx* ctx; uint64_t iCount = 0; uint64_t* piHashVal; uint32_t* piNonce; job_result result; + hash_fun = func_selector(jconf::inst()->HaveHardwareAes(), bNoPrefetch, jconf::inst()->HaveMulx()); ctx = minethd_alloc_ctx(); piHashVal = (uint64_t*)(result.bResult + 24); piNonce = (uint32_t*)(oWork.bWorkBlob + 39); iConsumeCnt++; - bool bHaveAes = jconf::inst()->HaveHardwareAes(); while (bQuit == 0) { if (oWork.bStall) @@ -401,15 +416,7 @@ void minethd::work_main() *piNonce = ++result.iNonce; - if(bHaveAes) - { - if(bNoPrefetch) - cryptonight_hash_ctx_np(oWork.bWorkBlob, oWork.iWorkSize, result.bResult, ctx); - else - cryptonight_hash_ctx(oWork.bWorkBlob, oWork.iWorkSize, result.bResult, ctx); - } - else - cryptonight_hash_ctx_soft(oWork.bWorkBlob, oWork.iWorkSize, result.bResult, ctx); + hash_fun(oWork.bWorkBlob, oWork.iWorkSize, result.bResult, ctx); if (*piHashVal < oWork.iTarget) executor::inst()->push_event(ex_event(result, oWork.iPoolId)); @@ -423,8 +430,35 @@ void minethd::work_main() cryptonight_free_ctx(ctx); } +minethd::cn_hash_fun_dbl minethd::func_dbl_selector(bool bHaveAes, bool bNoPrefetch, bool bMulx) +{ + // We have three independent flag bits in the functions + // therefore we will build a binary digit and select the + // function as a three digit binary + // Digit order SOFT_AES, NO_PREFETCH, MULX + + static const cn_hash_fun_dbl func_table[8] = { + cryptonight_double_hash<0x80000, MEMORY, false, false, false>, + cryptonight_double_hash<0x80000, MEMORY, false, false, true>, + cryptonight_double_hash<0x80000, MEMORY, false, true, false>, + cryptonight_double_hash<0x80000, MEMORY, false, true, true>, + cryptonight_double_hash<0x80000, MEMORY, true, false, false>, + cryptonight_double_hash<0x80000, MEMORY, true, false, true>, + cryptonight_double_hash<0x80000, MEMORY, true, true, false>, + cryptonight_double_hash<0x80000, MEMORY, true, true, true> + }; + + std::bitset<3> digit; + digit.set(0, bMulx); + digit.set(1, bNoPrefetch); + digit.set(2, !bHaveAes); + + return func_table[digit.to_ulong()]; +} + void minethd::double_work_main() { + cn_hash_fun_dbl hash_fun; cryptonight_ctx* ctx0; cryptonight_ctx* ctx1; uint64_t iCount = 0; @@ -435,6 +469,7 @@ void minethd::double_work_main() uint32_t iNonce; job_result res; + hash_fun = func_dbl_selector(jconf::inst()->HaveHardwareAes(), bNoPrefetch, jconf::inst()->HaveMulx()); ctx0 = minethd_alloc_ctx(); ctx1 = minethd_alloc_ctx(); @@ -484,7 +519,8 @@ void minethd::double_work_main() *piNonce0 = ++iNonce; *piNonce1 = ++iNonce; - cryptonight_double_hash_ctx(bDoubleWorkBlob, oWork.iWorkSize, bDoubleHashOut, ctx0, ctx1); + + hash_fun(bDoubleWorkBlob, oWork.iWorkSize, bDoubleHashOut, ctx0, ctx1); if (*piHashVal0 < oWork.iTarget) executor::inst()->push_event(ex_event(job_result(oWork.sJobID, iNonce-1, bDoubleHashOut), oWork.iPoolId)); diff --git a/minethd.h b/minethd.h index d4470b1..aa40344 100644 --- a/minethd.h +++ b/minethd.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include "crypto/cryptonight.h" class telemetry { @@ -97,6 +98,9 @@ public: std::atomic iTimestamp; private: + typedef void (*cn_hash_fun)(const void*, size_t, void*, cryptonight_ctx*); + typedef void (*cn_hash_fun_dbl)(const void*, size_t, void*, __restrict cryptonight_ctx*, __restrict cryptonight_ctx*); + minethd(miner_work& pWork, size_t iNo, bool double_work, bool no_prefetch); // We use the top 10 bits of the nonce for thread and resume @@ -110,6 +114,9 @@ private: inline uint32_t calc_nicehash_nonce(uint32_t start, uint32_t resume) { return start | (resume * iThreadCount + iThreadNo) << 18; } + static cn_hash_fun func_selector(bool bHaveAes, bool bNoPrefetch, bool bMulx); + static cn_hash_fun_dbl func_dbl_selector(bool bHaveAes, bool bNoPrefetch, bool bMulx); + void work_main(); void double_work_main(); void consume_work(); diff --git a/xmr-stak-cpu.cbp b/xmr-stak-cpu.cbp index cc606fd..8df8044 100644 --- a/xmr-stak-cpu.cbp +++ b/xmr-stak-cpu.cbp @@ -59,7 +59,7 @@ - + From 05610ba80aca1a97a550c13b23fe7378142d7e73 Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Fri, 21 Apr 2017 10:14:45 +0100 Subject: [PATCH 09/25] Logic correction --- minethd.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/minethd.cpp b/minethd.cpp index cf26037..27f7271 100644 --- a/minethd.cpp +++ b/minethd.cpp @@ -358,7 +358,7 @@ minethd::cn_hash_fun minethd::func_selector(bool bHaveAes, bool bNoPrefetch, boo std::bitset<3> digit; digit.set(0, bMulx); - digit.set(1, bNoPrefetch); + digit.set(1, !bNoPrefetch); digit.set(2, !bHaveAes); return func_table[digit.to_ulong()]; @@ -450,7 +450,7 @@ minethd::cn_hash_fun_dbl minethd::func_dbl_selector(bool bHaveAes, bool bNoPrefe std::bitset<3> digit; digit.set(0, bMulx); - digit.set(1, bNoPrefetch); + digit.set(1, !bNoPrefetch); digit.set(2, !bHaveAes); return func_table[digit.to_ulong()]; From 2ade51acfae4eb24b12af5a66fc9d397d8ae2c2c Mon Sep 17 00:00:00 2001 From: Esfomeado Date: Sun, 9 Apr 2017 18:47:00 +0100 Subject: [PATCH 10/25] Fix leake and use pre-increment --- executor.cpp | 2 +- jconf.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/executor.cpp b/executor.cpp index af10811..8f5a2a9 100644 --- a/executor.cpp +++ b/executor.cpp @@ -83,7 +83,7 @@ void executor::ex_clock_thd() ev = lTimedEvents.erase(ev); } else - ev++; + ++ev; } lck.unlock(); diff --git a/jconf.cpp b/jconf.cpp index ce82525..4656365 100644 --- a/jconf.cpp +++ b/jconf.cpp @@ -316,6 +316,7 @@ bool jconf::parse_config(const char* sFilename) if(flen <= 16) { + fclose(pFile); printer::inst()->print_msg(L0, "File is empty or too short - %s.", sFilename); return false; } From 8b6048d21f208d772ace6f9a31099096d0125e2a Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Mon, 10 Apr 2017 17:25:20 +0100 Subject: [PATCH 11/25] rv pre-inc to common style --- executor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor.cpp b/executor.cpp index 8f5a2a9..af10811 100644 --- a/executor.cpp +++ b/executor.cpp @@ -83,7 +83,7 @@ void executor::ex_clock_thd() ev = lTimedEvents.erase(ev); } else - ++ev; + ev++; } lck.unlock(); From a93d71cd10b2c2a0bee2bd106cae0288145e42b0 Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Mon, 10 Apr 2017 17:47:33 +0100 Subject: [PATCH 12/25] Fix priority for 32+ CPUs --- minethd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minethd.cpp b/minethd.cpp index 27f7271..55bf9e7 100644 --- a/minethd.cpp +++ b/minethd.cpp @@ -33,7 +33,7 @@ void thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id) { - SetThreadAffinityMask(h, 1 << cpu_id); + SetThreadAffinityMask(h, 1ULL << cpu_id); } #else #include From 741bee2e2f99602946abc9a77da2b5262ee02669 Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Fri, 21 Apr 2017 17:43:47 +0100 Subject: [PATCH 13/25] Windows build fix + gcc cmake opts --- CMakeLists.txt | 6 +++--- minethd.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e87d69d..2667f42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,9 +84,9 @@ endif() # Compile & Link ################################################################################ -# activate sse2 and aes-ni -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -maes") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2 -maes") +# activate sse2, aes-ni and bmi2 +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -maes -mbmi2") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2 -maes -mbmi2") # activate static libgcc and libstdc++ linking if(CMAKE_LINK_STATIC) diff --git a/minethd.h b/minethd.h index aa40344..fbee325 100644 --- a/minethd.h +++ b/minethd.h @@ -99,7 +99,7 @@ public: private: typedef void (*cn_hash_fun)(const void*, size_t, void*, cryptonight_ctx*); - typedef void (*cn_hash_fun_dbl)(const void*, size_t, void*, __restrict cryptonight_ctx*, __restrict cryptonight_ctx*); + typedef void (*cn_hash_fun_dbl)(const void*, size_t, void*, cryptonight_ctx* __restrict, cryptonight_ctx* __restrict); minethd(miner_work& pWork, size_t iNo, bool double_work, bool no_prefetch); From 7617fed8b1d3c420cce7a8ae0b482e84cd73d021 Mon Sep 17 00:00:00 2001 From: psychocrypt Date: Sat, 22 Apr 2017 22:47:45 +0200 Subject: [PATCH 14/25] add psychocrypt to cmd output --- cli-miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli-miner.cpp b/cli-miner.cpp index 8d5f83e..deb462e 100644 --- a/cli-miner.cpp +++ b/cli-miner.cpp @@ -125,8 +125,8 @@ int main(int argc, char *argv[]) printer::inst()->print_str("-------------------------------------------------------------------\n"); printer::inst()->print_str("XMR-Stak-CPU mining software, CPU Version.\n"); - printer::inst()->print_str("Based on CPU mining code by wolf9466 (heavily optimized by myself).\n"); - printer::inst()->print_str("Brought to you by fireice_uk under GPLv3.\n\n"); + printer::inst()->print_str("Based on CPU mining code by wolf9466 (heavily optimized by fireice_uk).\n"); + printer::inst()->print_str("Brought to you by fireice_uk and psychocrypt under GPLv3.\n\n"); char buffer[64]; snprintf(buffer, sizeof(buffer), "Configurable dev donation level is set to %.1f %%\n\n", fDevDonationLevel * 100.0); printer::inst()->print_str(buffer); From 865ee48f9afaecb9da2c01544a111ee222a575a1 Mon Sep 17 00:00:00 2001 From: psychocrypt Date: Sat, 22 Apr 2017 23:03:05 +0200 Subject: [PATCH 15/25] disable prefetch by default - allow to disable prefetch on systems without hardware aes - set default disable memory prefetch --- config.txt | 7 +++---- jconf.cpp | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/config.txt b/config.txt index 98d1c3e..1530809 100644 --- a/config.txt +++ b/config.txt @@ -11,8 +11,7 @@ * consume much less power (as less cores are working), but will max out at around 80-85% of * the maximum performance. * - * no_prefetch - This mode meant for large pages only. It will generate an error if running on slow memory - * Some sytems can gain up to extra 5% here, but sometimes it will have no difference or make + * no_prefetch - Some sytems can gain up to extra 5% here, but sometimes it will have no difference or make * things slower. * * affine_to_cpu - This can be either false (no affinity), or the CPU core number. Note that on hyperthreading @@ -22,8 +21,8 @@ * */ "cpu_threads_conf" : [ - { "low_power_mode" : false, "no_prefetch" : false, "affine_to_cpu" : 0 }, - { "low_power_mode" : false, "no_prefetch" : false, "affine_to_cpu" : 1 }, + { "low_power_mode" : false, "no_prefetch" : true, "affine_to_cpu" : 0 }, + { "low_power_mode" : false, "no_prefetch" : true, "affine_to_cpu" : 1 }, ], /* diff --git a/jconf.cpp b/jconf.cpp index 4656365..3e3a1d5 100644 --- a/jconf.cpp +++ b/jconf.cpp @@ -139,9 +139,9 @@ bool jconf::GetThreadConfig(size_t id, thd_cfg &cfg) cfg.bDoubleMode = mode->GetBool(); cfg.bNoPrefetch = no_prefetch->GetBool(); - if(!bHaveAes && (cfg.bDoubleMode || cfg.bNoPrefetch)) + if(!bHaveAes && cfg.bDoubleMode) { - printer::inst()->print_msg(L0, "Invalid thread confg - low_power_mode and no_prefetch are unsupported on CPUs without AES-NI."); + printer::inst()->print_msg(L0, "Invalid thread confg - low_power_mode are unsupported on CPUs without AES-NI."); return false; } From 37065f425d73d7ad05acba835bb7501fa575dd5c Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Mon, 24 Apr 2017 20:53:17 +0100 Subject: [PATCH 16/25] Apply psychocrypt's build solution to the template --- CMakeLists.txt | 6 +++--- crypto/cryptonight_aesni.h | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2667f42..e87d69d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,9 +84,9 @@ endif() # Compile & Link ################################################################################ -# activate sse2, aes-ni and bmi2 -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -maes -mbmi2") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2 -maes -mbmi2") +# activate sse2 and aes-ni +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -maes") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2 -maes") # activate static libgcc and libstdc++ linking if(CMAKE_LINK_STATIC) diff --git a/crypto/cryptonight_aesni.h b/crypto/cryptonight_aesni.h index de0f186..daf4037 100644 --- a/crypto/cryptonight_aesni.h +++ b/crypto/cryptonight_aesni.h @@ -28,6 +28,11 @@ static inline uint64_t _umul128(uint64_t a, uint64_t b, uint64_t* hi) return (uint64_t)r; } +__attribute__((target ("bmi2"))) static inline uint64_t _mulx_u64(uint64_t a, uint64_t b, uint64_t* hi) +{ + return _mulx_u64((unsigned long long)a, (unsigned long long)b, (unsigned long long*)hi); +} + #define _mm256_set_m128i(v0, v1) _mm256_insertf128_si256(_mm256_castsi128_si256(v1), (v0), 1) #else #include @@ -319,7 +324,7 @@ void cryptonight_hash(const void* input, size_t len, void* output, cryptonight_c ch = ((uint64_t*)&l0[idx0 & 0x1FFFF0])[1]; if(MULX) - lo = _mulx_u64(idx0, cl, (long long unsigned int*)&hi); + lo = _mulx_u64(idx0, cl, &hi); else lo = _umul128(idx0, cl, &hi); @@ -406,7 +411,7 @@ void cryptonight_double_hash(const void* input, size_t len, void* output, crypto cx = _mm_load_si128((__m128i *)&l0[idx0 & 0x1FFFF0]); if(MULX) - lo = _mulx_u64(idx0, _mm_cvtsi128_si64(cx), (long long unsigned int*)&hi); + lo = _mulx_u64(idx0, _mm_cvtsi128_si64(cx), &hi); else lo = _umul128(idx0, _mm_cvtsi128_si64(cx), &hi); @@ -421,7 +426,7 @@ void cryptonight_double_hash(const void* input, size_t len, void* output, crypto cx = _mm_load_si128((__m128i *)&l1[idx1 & 0x1FFFF0]); if(MULX) - lo = _mulx_u64(idx1, _mm_cvtsi128_si64(cx), (long long unsigned int*)&hi); + lo = _mulx_u64(idx1, _mm_cvtsi128_si64(cx), &hi); else lo = _umul128(idx1, _mm_cvtsi128_si64(cx), &hi); From d5b02fa0c351f5613358fdad3c4f7590860f937f Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Tue, 25 Apr 2017 19:50:10 +0100 Subject: [PATCH 17/25] CPU autoconfig --- autoAdjust.hpp | 138 +++++++++++++++++++++++++++++++++++++++++++++++++ cli-miner.cpp | 9 ++++ config.txt | 22 ++++---- jconf.cpp | 88 +++++++++++++++++-------------- jconf.h | 3 ++ 5 files changed, 210 insertions(+), 50 deletions(-) create mode 100644 autoAdjust.hpp diff --git a/autoAdjust.hpp b/autoAdjust.hpp new file mode 100644 index 0000000..8414b3e --- /dev/null +++ b/autoAdjust.hpp @@ -0,0 +1,138 @@ +#pragma once +#include "jconf.h" +#include "console.h" + +#ifdef _WIN32 +#include +#else +#include +#endif // _WIN32 + +int32_t get_masked(int32_t val, int32_t h, int32_t l) +{ + val &= (0x7FFFFFFF >> (31-(h-l))) << l; + return val >> l; +} + +class autoAdjust +{ +public: + + autoAdjust() + { + } + + void printConfig() + { + printer::inst()->print_str("The configuration for 'cpu_threads_conf' in your config file is 'null'.\n"); + printer::inst()->print_str("The miner evaluates your system and prints a suggestion for the section `cpu_threads_conf` to the terminal.\n"); + printer::inst()->print_str("The values are not optimal, please try to tweak the values based on notes in config.txt.\n"); + printer::inst()->print_str("Please copy & paste the block within the asterisks to your config.\n\n"); + + int32_t L3KB_size = 0; + + if(!detectL3Size(L3KB_size)) + return; + + if(L3KB_size < 1024 || L3KB_size > 102400) + { + printer::inst()->print_msg(L0, "Autoconf failed: L3 size sanity check failed %u.", L3KB_size); + return; + } + + printer::inst()->print_msg(L0, "Autoconf L3 size detected at %u.", L3KB_size); + + uint32_t corecnt; + bool linux_layout; + + detectCPUConf(corecnt, linux_layout); + + printer::inst()->print_msg(L0, "Autoconf cores detected at %u on %s.", corecnt, + linux_layout ? "Linux" : "Windows"); + + printer::inst()->print_str("\n**************** Copy&Paste ****************\n\n"); + printer::inst()->print_str("\"cpu_threads_conf\" :\n[\n"); + + uint32_t aff_id = 0; + char strbuf[256]; + for(uint32_t i=0; i < corecnt; i++) + { + bool double_mode; + + if(L3KB_size < 0) + break; + + double_mode = L3KB_size / 2048 > (int32_t)(corecnt-i); + + snprintf(strbuf, sizeof(strbuf), " { \"low_power_mode\" : %s, \"no_prefetch\" : true, \"affine_to_cpu\" : %u },\n", + double_mode ? "true" : "false", aff_id); + printer::inst()->print_str(strbuf); + + if(linux_layout) + aff_id++; + else + aff_id += 2; + + if(double_mode) + L3KB_size -= 4096; + else + L3KB_size -= 2048; + } + + printer::inst()->print_str("]\n\n**************** Copy&Paste ****************\n"); + } + +private: + bool detectL3Size(int32_t &l3kb) + { + int32_t cpu_info[4]; + char cpustr[13] = {0}; + + jconf::cpuid(0, 0, cpu_info); + memcpy(cpustr, &cpu_info[1], 4); + memcpy(cpustr+4, &cpu_info[3], 4); + memcpy(cpustr+8, &cpu_info[2], 4); + + if(strcmp(cpustr, "GenuineIntel") == 0) + { + jconf::cpuid(4, 3, cpu_info); + + if(get_masked(cpu_info[0], 7, 5) != 3) + { + printer::inst()->print_msg(L0, "Autoconf failed: Couln't find L3 cache page."); + return false; + } + + l3kb = ((get_masked(cpu_info[1], 31, 22) + 1) * (get_masked(cpu_info[1], 21, 12) + 1) * + (get_masked(cpu_info[1], 11, 0) + 1) * (cpu_info[2] + 1)) / 1024; + + return true; + } + else if(strcmp(cpustr, "AuthenticAMD") == 0) + { + jconf::cpuid(0x80000006, 0, cpu_info); + + l3kb = get_masked(cpu_info[3], 31, 18) * 512; + + return true; + } + else + { + printer::inst()->print_msg(L0, "Autoconf failed: Unknown CPU type: %s.", cpustr); + return false; + } + } + + void detectCPUConf(uint32_t &corecnt, bool &linux_layout) + { +#ifdef _WIN32 + SYSTEM_INFO info; + GetSystemInfo(&info); + corecnt = info.dwNumberOfProcessors; + linux_layout = false; +#else + corecnt = sysconf(_SC_NPROCESSORS_ONLN); + linux_layout = true; +#endif // _WIN32 + } +}; diff --git a/cli-miner.cpp b/cli-miner.cpp index deb462e..38fb720 100644 --- a/cli-miner.cpp +++ b/cli-miner.cpp @@ -26,6 +26,7 @@ #include "jconf.h" #include "console.h" #include "donate-level.h" +#include "autoAdjust.hpp" #ifndef CONF_NO_HTTPD # include "httpd.h" @@ -99,6 +100,14 @@ int main(int argc, char *argv[]) return 0; } + if(jconf::inst()->NeedsAutoconf()) + { + autoAdjust adjust; + adjust.printConfig(); + win_exit(); + return 0; + } + if (!minethd::self_test()) { win_exit(); diff --git a/config.txt b/config.txt index 1530809..0dcb9e9 100644 --- a/config.txt +++ b/config.txt @@ -1,10 +1,3 @@ -/* - * Number of threads. You can configure them below. Cryptonight uses 2MB of memory, so the optimal setting - * here is the size of your L3 cache divided by 2. Intel mid-to-high end desktop processors have 2MB of L3 - * cache per physical core. Low end cpus can have 1.5 or 1 MB while Xeons can have 2, 2.5 or 3MB per core. - */ -"cpu_thread_num" : 2, - /* * Thread configuration for each thread. Make sure it matches the number above. * low_power_mode - This mode will double the cache usage, and double the single thread performance. It will @@ -19,11 +12,18 @@ * even or odd numbered cpu numbers. For Linux it will be usually the lower CPU numbers, so for a 4 * physical core CPU you should select cpu numbers 0-3. * + * On the first run the miner will look at your system and suggest a basic configuration that will work, + * you can try to tweak it from there to get the best performance. + * + * A filled out configuration should look like this: + * "cpu_threads_conf" : + * [ + * { "low_power_mode" : false, "no_prefetch" : true, "affine_to_cpu" : 0 }, + * { "low_power_mode" : false, "no_prefetch" : true, "affine_to_cpu" : 1 }, + * ], */ -"cpu_threads_conf" : [ - { "low_power_mode" : false, "no_prefetch" : true, "affine_to_cpu" : 0 }, - { "low_power_mode" : false, "no_prefetch" : true, "affine_to_cpu" : 1 }, -], +"cpu_threads_conf" : +null, /* * LARGE PAGE SUPPORT diff --git a/jconf.cpp b/jconf.cpp index 3e3a1d5..82750cc 100644 --- a/jconf.cpp +++ b/jconf.cpp @@ -45,7 +45,7 @@ using namespace rapidjson; /* * This enum needs to match index in oConfigValues, otherwise we will get a runtime error */ -enum configEnum { iCpuThreadNum, aCpuThreadsConf, sUseSlowMem, bNiceHashMode, +enum configEnum { aCpuThreadsConf, sUseSlowMem, bNiceHashMode, bTlsMode, bTlsSecureAlgo, sTlsFingerprint, sPoolAddr, sWalletAddr, sPoolPwd, iCallTimeout, iNetRetry, iGiveUpLimit, iVerboseLevel, iAutohashTime, sOutputFile, iHttpdPort, bPreferIpv4 }; @@ -56,10 +56,10 @@ struct configVal { Type iType; }; -//Same order as in configEnum, as per comment above +// Same order as in configEnum, as per comment above +// kNullType means any type configVal oConfigValues[] = { - { iCpuThreadNum, "cpu_thread_num", kNumberType }, - { aCpuThreadsConf, "cpu_threads_conf", kArrayType }, + { aCpuThreadsConf, "cpu_threads_conf", kNullType }, { sUseSlowMem, "use_slow_memory", kStringType }, { bNiceHashMode, "nicehash_nonce", kTrueType }, { bTlsMode, "use_tls", kTrueType }, @@ -84,6 +84,8 @@ inline bool checkType(Type have, Type want) { if(want == have) return true; + else if(want == kNullType) + return true; else if(want == kTrueType && have == kFalseType) return true; else if(want == kFalseType && have == kTrueType) @@ -111,6 +113,9 @@ jconf::jconf() bool jconf::GetThreadConfig(size_t id, thd_cfg &cfg) { + if(!prv->configValues[aCpuThreadsConf]->IsArray()) + return false; + if(id >= prv->configValues[aCpuThreadsConf]->Size()) return false; @@ -206,7 +211,15 @@ bool jconf::PreferIpv4() size_t jconf::GetThreadCount() { - return prv->configValues[aCpuThreadsConf]->Size(); + if(prv->configValues[aCpuThreadsConf]->IsArray()) + return prv->configValues[aCpuThreadsConf]->Size(); + else + return 0; +} + +bool jconf::NeedsAutoconf() +{ + return !prv->configValues[aCpuThreadsConf]->IsArray(); } uint64_t jconf::GetCallTimeout() @@ -249,38 +262,34 @@ const char* jconf::GetOutputFile() return prv->configValues[sOutputFile]->GetString(); } +void jconf::cpuid(uint32_t eax, int32_t ecx, int32_t val[4]) +{ + memset(val, 0, sizeof(int32_t)*4); + +#ifdef _WIN32 + __cpuidex(val, eax, ecx); +#else + __cpuid_count(eax, ecx, val[0], val[1], val[2], val[3]); +#endif +} + bool jconf::check_cpu_features() { constexpr int AESNI_BIT = 1 << 25; constexpr int SSE2_BIT = 1 << 26; constexpr int BMI2_BIT = 1 << 8; - - int cpu_info[4]; + int32_t cpu_info[4]; bool bHaveSse2; -#ifdef _WIN32 - __cpuid(cpu_info, 1); -#else - __cpuid(1, cpu_info[0], cpu_info[1], cpu_info[2], cpu_info[3]); -#endif + cpuid(1, 0, cpu_info); bHaveAes = (cpu_info[2] & AESNI_BIT) != 0; bHaveSse2 = (cpu_info[3] & SSE2_BIT) != 0; -#ifdef _WIN32 - __cpuidex(cpu_info, 7, 0); -#else - __cpuid_count(7, 0, cpu_info[0], cpu_info[1], cpu_info[2], cpu_info[3]); -#endif + cpuid(7, 0, cpu_info); bHaveBmi2 = (cpu_info[1] & BMI2_BIT) != 0; - if(!bHaveAes) - printer::inst()->print_msg(L0, "Your CPU doesn't support hardware AES. Don't expect high hashrates."); - - if(bHaveBmi2) - printer::inst()->print_msg(L0, "CPU supports BMI2 instructions. Faster multiplication enabled."); - return bHaveSse2; } @@ -384,23 +393,8 @@ bool jconf::parse_config(const char* sFilename) } } - size_t n_thd = prv->configValues[aCpuThreadsConf]->Size(); - if(prv->configValues[iCpuThreadNum]->GetUint64() != n_thd) - { - printer::inst()->print_msg(L0, - "Invalid config file. Your CPU config array has %llu members, while you want to use %llu threads.", - int_port(n_thd), int_port(prv->configValues[iCpuThreadNum]->GetUint64())); - return false; - } - - if(NiceHashMode() && n_thd >= 32) - { - printer::inst()->print_msg(L0, "You need to use less than 32 threads in NiceHash mode."); - return false; - } - thd_cfg c; - for(size_t i=0; i < n_thd; i++) + for(size_t i=0; i < GetThreadCount(); i++) { if(!GetThreadConfig(i, c)) { @@ -409,6 +403,12 @@ bool jconf::parse_config(const char* sFilename) } } + if(NiceHashMode() && GetThreadCount() >= 32) + { + printer::inst()->print_msg(L0, "You need to use less than 32 threads in NiceHash mode."); + return false; + } + if(GetSlowMemSetting() == unknown_value) { printer::inst()->print_msg(L0, @@ -457,5 +457,15 @@ bool jconf::parse_config(const char* sFilename) #endif // _WIN32 printer::inst()->set_verbose_level(prv->configValues[iVerboseLevel]->GetUint64()); + + if(!NeedsAutoconf()) + { + if(!bHaveAes) + printer::inst()->print_msg(L0, "Your CPU doesn't support hardware AES. Don't expect high hashrates."); + + if(bHaveBmi2) + printer::inst()->print_msg(L0, "CPU supports BMI2 instructions. Faster multiplication enabled."); + } + return true; } diff --git a/jconf.h b/jconf.h index 7444a01..08e2124 100644 --- a/jconf.h +++ b/jconf.h @@ -29,6 +29,7 @@ public: size_t GetThreadCount(); bool GetThreadConfig(size_t id, thd_cfg &cfg); + bool NeedsAutoconf(); slow_mem_cfg GetSlowMemSetting(); @@ -58,6 +59,8 @@ public: inline bool HaveHardwareAes() { return bHaveAes; } inline bool HaveMulx() { return bHaveBmi2; } + static void cpuid(uint32_t eax, int32_t ecx, int32_t val[4]); + private: jconf(); static jconf* oInst; From 68afa3b58dcdbbfe701d4afdacbb0385b4e9adca Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Tue, 25 Apr 2017 20:06:36 +0100 Subject: [PATCH 18/25] Update CBP build env --- xmr-stak-cpu.cbp | 1 + 1 file changed, 1 insertion(+) diff --git a/xmr-stak-cpu.cbp b/xmr-stak-cpu.cbp index 8df8044..6d8553c 100644 --- a/xmr-stak-cpu.cbp +++ b/xmr-stak-cpu.cbp @@ -68,6 +68,7 @@ + From 95ba2f9dbf20785ce98dd3e850a044fb56ede3cc Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Tue, 25 Apr 2017 20:58:37 +0100 Subject: [PATCH 19/25] Fix off-by-one --- autoAdjust.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoAdjust.hpp b/autoAdjust.hpp index 8414b3e..fd24ea9 100644 --- a/autoAdjust.hpp +++ b/autoAdjust.hpp @@ -59,7 +59,7 @@ public: { bool double_mode; - if(L3KB_size < 0) + if(L3KB_size <= 0) break; double_mode = L3KB_size / 2048 > (int32_t)(corecnt-i); From ebaafe91adc4997f0615e997e4addc6c9e6fbf24 Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Tue, 25 Apr 2017 21:28:54 +0100 Subject: [PATCH 20/25] Older AMD stagger + switch to odd numbers when we run out --- autoAdjust.hpp | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/autoAdjust.hpp b/autoAdjust.hpp index fd24ea9..da3ccf0 100644 --- a/autoAdjust.hpp +++ b/autoAdjust.hpp @@ -29,9 +29,7 @@ public: printer::inst()->print_str("The values are not optimal, please try to tweak the values based on notes in config.txt.\n"); printer::inst()->print_str("Please copy & paste the block within the asterisks to your config.\n\n"); - int32_t L3KB_size = 0; - - if(!detectL3Size(L3KB_size)) + if(!detectL3Size()) return; if(L3KB_size < 1024 || L3KB_size > 102400) @@ -68,11 +66,16 @@ public: double_mode ? "true" : "false", aff_id); printer::inst()->print_str(strbuf); - if(linux_layout) - aff_id++; - else + if(!linux_layout || old_amd) + { aff_id += 2; + if(aff_id >= corecnt) + aff_id = 1; + } + else + aff_id++; + if(double_mode) L3KB_size -= 4096; else @@ -83,7 +86,7 @@ public: } private: - bool detectL3Size(int32_t &l3kb) + bool detectL3Size() { int32_t cpu_info[4]; char cpustr[13] = {0}; @@ -103,7 +106,7 @@ private: return false; } - l3kb = ((get_masked(cpu_info[1], 31, 22) + 1) * (get_masked(cpu_info[1], 21, 12) + 1) * + L3KB_size = ((get_masked(cpu_info[1], 31, 22) + 1) * (get_masked(cpu_info[1], 21, 12) + 1) * (get_masked(cpu_info[1], 11, 0) + 1) * (cpu_info[2] + 1)) / 1024; return true; @@ -112,7 +115,11 @@ private: { jconf::cpuid(0x80000006, 0, cpu_info); - l3kb = get_masked(cpu_info[3], 31, 18) * 512; + L3KB_size = get_masked(cpu_info[3], 31, 18) * 512; + + jconf::cpuid(1, 0, cpu_info); + if(get_masked(cpu_info[0], 11, 8) < 0x17) //0x17h is Zen + old_amd = true; return true; } @@ -123,7 +130,7 @@ private: } } - void detectCPUConf(uint32_t &corecnt, bool &linux_layout) + void detectCPUConf() { #ifdef _WIN32 SYSTEM_INFO info; @@ -135,4 +142,9 @@ private: linux_layout = true; #endif // _WIN32 } + + int32_t L3KB_size = 0; + uint32_t corecnt; + bool old_amd = false; + bool linux_layout; }; From 5d24424dd7dcff10e479aa52555b17e75d045b46 Mon Sep 17 00:00:00 2001 From: psychocrypt Date: Tue, 25 Apr 2017 22:39:27 +0200 Subject: [PATCH 21/25] fix amd stagger detection --- autoAdjust.hpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/autoAdjust.hpp b/autoAdjust.hpp index da3ccf0..aed69a8 100644 --- a/autoAdjust.hpp +++ b/autoAdjust.hpp @@ -40,10 +40,7 @@ public: printer::inst()->print_msg(L0, "Autoconf L3 size detected at %u.", L3KB_size); - uint32_t corecnt; - bool linux_layout; - - detectCPUConf(corecnt, linux_layout); + detectCPUConf(); printer::inst()->print_msg(L0, "Autoconf cores detected at %u on %s.", corecnt, linux_layout ? "Linux" : "Windows"); From 5b4f5c1607162adc7a746c7288c21a658cdd2e2d Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Wed, 26 Apr 2017 11:47:03 +0100 Subject: [PATCH 22/25] Cosmetic changes - clearer comments and error messages --- autoAdjust.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/autoAdjust.hpp b/autoAdjust.hpp index aed69a8..ee1bbf5 100644 --- a/autoAdjust.hpp +++ b/autoAdjust.hpp @@ -8,7 +8,10 @@ #include #endif // _WIN32 -int32_t get_masked(int32_t val, int32_t h, int32_t l) +// Mask bits between h and l and return the value +// This enables us to put in values exactly like in the manual +// For example EBX[31:22] is get_masked(cpu_info[1], 31, 22) +inline int32_t get_masked(int32_t val, int32_t h, int32_t l) { val &= (0x7FFFFFFF >> (31-(h-l))) << l; return val >> l; @@ -34,15 +37,15 @@ public: if(L3KB_size < 1024 || L3KB_size > 102400) { - printer::inst()->print_msg(L0, "Autoconf failed: L3 size sanity check failed %u.", L3KB_size); + printer::inst()->print_msg(L0, "Autoconf failed: L3 size sanity check failed - %u KB.", L3KB_size); return; } - printer::inst()->print_msg(L0, "Autoconf L3 size detected at %u.", L3KB_size); + printer::inst()->print_msg(L0, "Autoconf L3 size detected at %u KB.", L3KB_size); detectCPUConf(); - printer::inst()->print_msg(L0, "Autoconf cores detected at %u on %s.", corecnt, + printer::inst()->print_msg(L0, "Autoconf core count detected as %u on %s.", corecnt, linux_layout ? "Linux" : "Windows"); printer::inst()->print_str("\n**************** Copy&Paste ****************\n\n"); From ec1e41cd8c78492ac5c657d0434d84bd9c491fb5 Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Wed, 26 Apr 2017 12:29:43 +0100 Subject: [PATCH 23/25] Remove mulx --- crypto/cryptonight_aesni.h | 25 +++----------- jconf.cpp | 8 ----- jconf.h | 2 -- minethd.cpp | 70 ++++++++++++++++---------------------- minethd.h | 4 +-- 5 files changed, 37 insertions(+), 72 deletions(-) diff --git a/crypto/cryptonight_aesni.h b/crypto/cryptonight_aesni.h index daf4037..6d990d3 100644 --- a/crypto/cryptonight_aesni.h +++ b/crypto/cryptonight_aesni.h @@ -27,12 +27,6 @@ static inline uint64_t _umul128(uint64_t a, uint64_t b, uint64_t* hi) *hi = r >> 64; return (uint64_t)r; } - -__attribute__((target ("bmi2"))) static inline uint64_t _mulx_u64(uint64_t a, uint64_t b, uint64_t* hi) -{ - return _mulx_u64((unsigned long long)a, (unsigned long long)b, (unsigned long long*)hi); -} - #define _mm256_set_m128i(v0, v1) _mm256_insertf128_si256(_mm256_castsi128_si256(v1), (v0), 1) #else #include @@ -284,7 +278,7 @@ void cn_implode_scratchpad(const __m128i* input, __m128i* output) _mm_store_si128(output + 11, xout7); } -template +template void cryptonight_hash(const void* input, size_t len, void* output, cryptonight_ctx* ctx0) { keccak((const uint8_t *)input, len, ctx0->hash_state, 200); @@ -323,10 +317,7 @@ void cryptonight_hash(const void* input, size_t len, void* output, cryptonight_c cl = ((uint64_t*)&l0[idx0 & 0x1FFFF0])[0]; ch = ((uint64_t*)&l0[idx0 & 0x1FFFF0])[1]; - if(MULX) - lo = _mulx_u64(idx0, cl, &hi); - else - lo = _umul128(idx0, cl, &hi); + lo = _umul128(idx0, cl, &hi); al0 += hi; ah0 += lo; @@ -352,7 +343,7 @@ void cryptonight_hash(const void* input, size_t len, void* output, cryptonight_c // This lovely creation will do 2 cn hashes at a time. We have plenty of space on silicon // to fit temporary vars for two contexts. Function will read len*2 from input and write 64 bytes to output // We are still limited by L3 cache, so doubling will only work with CPUs where we have more than 2MB to core (Xeons) -template +template void cryptonight_double_hash(const void* input, size_t len, void* output, cryptonight_ctx* __restrict ctx0, cryptonight_ctx* __restrict ctx1) { keccak((const uint8_t *)input, len, ctx0->hash_state, 200); @@ -410,10 +401,7 @@ void cryptonight_double_hash(const void* input, size_t len, void* output, crypto uint64_t hi, lo; cx = _mm_load_si128((__m128i *)&l0[idx0 & 0x1FFFF0]); - if(MULX) - lo = _mulx_u64(idx0, _mm_cvtsi128_si64(cx), &hi); - else - lo = _umul128(idx0, _mm_cvtsi128_si64(cx), &hi); + lo = _umul128(idx0, _mm_cvtsi128_si64(cx), &hi); ax0 = _mm_add_epi64(ax0, _mm_set_epi64x(lo, hi)); _mm_store_si128((__m128i*)&l0[idx0 & 0x1FFFF0], ax0); @@ -425,10 +413,7 @@ void cryptonight_double_hash(const void* input, size_t len, void* output, crypto cx = _mm_load_si128((__m128i *)&l1[idx1 & 0x1FFFF0]); - if(MULX) - lo = _mulx_u64(idx1, _mm_cvtsi128_si64(cx), &hi); - else - lo = _umul128(idx1, _mm_cvtsi128_si64(cx), &hi); + lo = _umul128(idx1, _mm_cvtsi128_si64(cx), &hi); ax1 = _mm_add_epi64(ax1, _mm_set_epi64x(lo, hi)); _mm_store_si128((__m128i*)&l1[idx1 & 0x1FFFF0], ax1); diff --git a/jconf.cpp b/jconf.cpp index 82750cc..8ed1947 100644 --- a/jconf.cpp +++ b/jconf.cpp @@ -277,7 +277,6 @@ bool jconf::check_cpu_features() { constexpr int AESNI_BIT = 1 << 25; constexpr int SSE2_BIT = 1 << 26; - constexpr int BMI2_BIT = 1 << 8; int32_t cpu_info[4]; bool bHaveSse2; @@ -286,10 +285,6 @@ bool jconf::check_cpu_features() bHaveAes = (cpu_info[2] & AESNI_BIT) != 0; bHaveSse2 = (cpu_info[3] & SSE2_BIT) != 0; - cpuid(7, 0, cpu_info); - - bHaveBmi2 = (cpu_info[1] & BMI2_BIT) != 0; - return bHaveSse2; } @@ -462,9 +457,6 @@ bool jconf::parse_config(const char* sFilename) { if(!bHaveAes) printer::inst()->print_msg(L0, "Your CPU doesn't support hardware AES. Don't expect high hashrates."); - - if(bHaveBmi2) - printer::inst()->print_msg(L0, "CPU supports BMI2 instructions. Faster multiplication enabled."); } return true; diff --git a/jconf.h b/jconf.h index 08e2124..f932728 100644 --- a/jconf.h +++ b/jconf.h @@ -57,7 +57,6 @@ public: bool PreferIpv4(); inline bool HaveHardwareAes() { return bHaveAes; } - inline bool HaveMulx() { return bHaveBmi2; } static void cpuid(uint32_t eax, int32_t ecx, int32_t val[4]); @@ -70,5 +69,4 @@ private: opaque_private* prv; bool bHaveAes; - bool bHaveBmi2; }; diff --git a/minethd.cpp b/minethd.cpp index 55bf9e7..199779e 100644 --- a/minethd.cpp +++ b/minethd.cpp @@ -251,20 +251,20 @@ bool minethd::self_test() cn_hash_fun hashf; cn_hash_fun_dbl hashdf; - hashf = func_selector(jconf::inst()->HaveHardwareAes(), false, jconf::inst()->HaveMulx()); + hashf = func_selector(jconf::inst()->HaveHardwareAes(), false); hashf("This is a test", 14, out, ctx0); bResult = memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0; - hashf = func_selector(jconf::inst()->HaveHardwareAes(), true, jconf::inst()->HaveMulx()); + hashf = func_selector(jconf::inst()->HaveHardwareAes(), true); hashf("This is a test", 14, out, ctx0); bResult &= memcmp(out, "\xa0\x84\xf0\x1d\x14\x37\xa0\x9c\x69\x85\x40\x1b\x60\xd4\x35\x54\xae\x10\x58\x02\xc5\xf5\xd8\xa9\xb3\x25\x36\x49\xc0\xbe\x66\x05", 32) == 0; - hashdf = func_dbl_selector(jconf::inst()->HaveHardwareAes(), false, jconf::inst()->HaveMulx()); + hashdf = func_dbl_selector(jconf::inst()->HaveHardwareAes(), false); hashdf("The quick brown fox jumps over the lazy dogThe quick brown fox jumps over the lazy log", 43, out, ctx0, ctx1); bResult &= memcmp(out, "\x3e\xbb\x7f\x9f\x7d\x27\x3d\x7c\x31\x8d\x86\x94\x77\x55\x0c\xc8\x00\xcf\xb1\x1b\x0c\xad\xb7\xff\xbd\xf6\xf8\x9f\x3a\x47\x1c\x59" "\xb4\x77\xd5\x02\xe4\xd8\x48\x7f\x42\xdf\xe3\x8e\xed\x73\x81\x7a\xda\x91\xb7\xe2\x63\xd2\x91\x71\xb6\x5c\x44\x3a\x01\x2a\x41\x22", 64) == 0; - hashdf = func_dbl_selector(jconf::inst()->HaveHardwareAes(), true, jconf::inst()->HaveMulx()); + hashdf = func_dbl_selector(jconf::inst()->HaveHardwareAes(), true); hashdf("The quick brown fox jumps over the lazy dogThe quick brown fox jumps over the lazy log", 43, out, ctx0, ctx1); bResult &= memcmp(out, "\x3e\xbb\x7f\x9f\x7d\x27\x3d\x7c\x31\x8d\x86\x94\x77\x55\x0c\xc8\x00\xcf\xb1\x1b\x0c\xad\xb7\xff\xbd\xf6\xf8\x9f\x3a\x47\x1c\x59" "\xb4\x77\xd5\x02\xe4\xd8\x48\x7f\x42\xdf\xe3\x8e\xed\x73\x81\x7a\xda\x91\xb7\xe2\x63\xd2\x91\x71\xb6\x5c\x44\x3a\x01\x2a\x41\x22", 64) == 0; @@ -338,28 +338,23 @@ void minethd::consume_work() iConsumeCnt++; } -minethd::cn_hash_fun minethd::func_selector(bool bHaveAes, bool bNoPrefetch, bool bMulx) +minethd::cn_hash_fun minethd::func_selector(bool bHaveAes, bool bNoPrefetch) { - // We have three independent flag bits in the functions + // We have two independent flag bits in the functions // therefore we will build a binary digit and select the - // function as a three digit binary - // Digit order SOFT_AES, NO_PREFETCH, MULX + // function as a two digit binary + // Digit order SOFT_AES, NO_PREFETCH - static const cn_hash_fun func_table[8] = { - cryptonight_hash<0x80000, MEMORY, false, false, false>, - cryptonight_hash<0x80000, MEMORY, false, false, true>, - cryptonight_hash<0x80000, MEMORY, false, true, false>, - cryptonight_hash<0x80000, MEMORY, false, true, true>, - cryptonight_hash<0x80000, MEMORY, true, false, false>, - cryptonight_hash<0x80000, MEMORY, true, false, true>, - cryptonight_hash<0x80000, MEMORY, true, true, false>, - cryptonight_hash<0x80000, MEMORY, true, true, true> + static const cn_hash_fun func_table[4] = { + cryptonight_hash<0x80000, MEMORY, false, false>, + cryptonight_hash<0x80000, MEMORY, false, true>, + cryptonight_hash<0x80000, MEMORY, true, false>, + cryptonight_hash<0x80000, MEMORY, true, true> }; - std::bitset<3> digit; - digit.set(0, bMulx); - digit.set(1, !bNoPrefetch); - digit.set(2, !bHaveAes); + std::bitset<2> digit; + digit.set(0, !bNoPrefetch); + digit.set(1, !bHaveAes); return func_table[digit.to_ulong()]; } @@ -373,7 +368,7 @@ void minethd::work_main() uint32_t* piNonce; job_result result; - hash_fun = func_selector(jconf::inst()->HaveHardwareAes(), bNoPrefetch, jconf::inst()->HaveMulx()); + hash_fun = func_selector(jconf::inst()->HaveHardwareAes(), bNoPrefetch); ctx = minethd_alloc_ctx(); piHashVal = (uint64_t*)(result.bResult + 24); @@ -430,28 +425,23 @@ void minethd::work_main() cryptonight_free_ctx(ctx); } -minethd::cn_hash_fun_dbl minethd::func_dbl_selector(bool bHaveAes, bool bNoPrefetch, bool bMulx) +minethd::cn_hash_fun_dbl minethd::func_dbl_selector(bool bHaveAes, bool bNoPrefetch) { - // We have three independent flag bits in the functions + // We have two independent flag bits in the functions // therefore we will build a binary digit and select the - // function as a three digit binary - // Digit order SOFT_AES, NO_PREFETCH, MULX + // function as a two digit binary + // Digit order SOFT_AES, NO_PREFETCH - static const cn_hash_fun_dbl func_table[8] = { - cryptonight_double_hash<0x80000, MEMORY, false, false, false>, - cryptonight_double_hash<0x80000, MEMORY, false, false, true>, - cryptonight_double_hash<0x80000, MEMORY, false, true, false>, - cryptonight_double_hash<0x80000, MEMORY, false, true, true>, - cryptonight_double_hash<0x80000, MEMORY, true, false, false>, - cryptonight_double_hash<0x80000, MEMORY, true, false, true>, - cryptonight_double_hash<0x80000, MEMORY, true, true, false>, - cryptonight_double_hash<0x80000, MEMORY, true, true, true> + static const cn_hash_fun_dbl func_table[4] = { + cryptonight_double_hash<0x80000, MEMORY, false, false>, + cryptonight_double_hash<0x80000, MEMORY, false, true>, + cryptonight_double_hash<0x80000, MEMORY, true, false>, + cryptonight_double_hash<0x80000, MEMORY, true, true> }; - std::bitset<3> digit; - digit.set(0, bMulx); - digit.set(1, !bNoPrefetch); - digit.set(2, !bHaveAes); + std::bitset<2> digit; + digit.set(0, !bNoPrefetch); + digit.set(1, !bHaveAes); return func_table[digit.to_ulong()]; } @@ -469,7 +459,7 @@ void minethd::double_work_main() uint32_t iNonce; job_result res; - hash_fun = func_dbl_selector(jconf::inst()->HaveHardwareAes(), bNoPrefetch, jconf::inst()->HaveMulx()); + hash_fun = func_dbl_selector(jconf::inst()->HaveHardwareAes(), bNoPrefetch); ctx0 = minethd_alloc_ctx(); ctx1 = minethd_alloc_ctx(); diff --git a/minethd.h b/minethd.h index fbee325..6ba269e 100644 --- a/minethd.h +++ b/minethd.h @@ -114,8 +114,8 @@ private: inline uint32_t calc_nicehash_nonce(uint32_t start, uint32_t resume) { return start | (resume * iThreadCount + iThreadNo) << 18; } - static cn_hash_fun func_selector(bool bHaveAes, bool bNoPrefetch, bool bMulx); - static cn_hash_fun_dbl func_dbl_selector(bool bHaveAes, bool bNoPrefetch, bool bMulx); + static cn_hash_fun func_selector(bool bHaveAes, bool bNoPrefetch); + static cn_hash_fun_dbl func_dbl_selector(bool bHaveAes, bool bNoPrefetch); void work_main(); void double_work_main(); From 4ab9f0907f764fb98874037faa5b5468aed8d6ed Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Wed, 26 Apr 2017 18:02:58 +0100 Subject: [PATCH 24/25] Extend prefetch option. --- crypto/cryptonight_aesni.h | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/crypto/cryptonight_aesni.h b/crypto/cryptonight_aesni.h index 6d990d3..6d8479c 100644 --- a/crypto/cryptonight_aesni.h +++ b/crypto/cryptonight_aesni.h @@ -149,7 +149,7 @@ static inline void soft_aes_round(__m128i key, __m128i* x0, __m128i* x1, __m128i *x7 = soft_aesenc(*x7, key); } -template +template void cn_explode_scratchpad(const __m128i* input, __m128i* output) { // This is more than we have registers, compiler will assign 2 keys on the stack @@ -200,16 +200,21 @@ void cn_explode_scratchpad(const __m128i* input, __m128i* output) _mm_store_si128(output + i + 1, xin1); _mm_store_si128(output + i + 2, xin2); _mm_store_si128(output + i + 3, xin3); - _mm_prefetch((const char*)output + i + 0, _MM_HINT_T2); + + if(PREFETCH) + _mm_prefetch((const char*)output + i + 0, _MM_HINT_T2); + _mm_store_si128(output + i + 4, xin4); _mm_store_si128(output + i + 5, xin5); _mm_store_si128(output + i + 6, xin6); _mm_store_si128(output + i + 7, xin7); - _mm_prefetch((const char*)output + i + 4, _MM_HINT_T2); + + if(PREFETCH) + _mm_prefetch((const char*)output + i + 4, _MM_HINT_T2); } } -template +template void cn_implode_scratchpad(const __m128i* input, __m128i* output) { // This is more than we have registers, compiler will assign 2 keys on the stack @@ -229,12 +234,17 @@ void cn_implode_scratchpad(const __m128i* input, __m128i* output) for (size_t i = 0; i < MEM / sizeof(__m128i); i += 8) { - _mm_prefetch((const char*)input + i + 0, _MM_HINT_NTA); + if(PREFETCH) + _mm_prefetch((const char*)input + i + 0, _MM_HINT_NTA); + xout0 = _mm_xor_si128(_mm_load_si128(input + i + 0), xout0); xout1 = _mm_xor_si128(_mm_load_si128(input + i + 1), xout1); xout2 = _mm_xor_si128(_mm_load_si128(input + i + 2), xout2); xout3 = _mm_xor_si128(_mm_load_si128(input + i + 3), xout3); - _mm_prefetch((const char*)input + i + 4, _MM_HINT_NTA); + + if(PREFETCH) + _mm_prefetch((const char*)input + i + 4, _MM_HINT_NTA); + xout4 = _mm_xor_si128(_mm_load_si128(input + i + 4), xout4); xout5 = _mm_xor_si128(_mm_load_si128(input + i + 5), xout5); xout6 = _mm_xor_si128(_mm_load_si128(input + i + 6), xout6); @@ -284,7 +294,7 @@ void cryptonight_hash(const void* input, size_t len, void* output, cryptonight_c keccak((const uint8_t *)input, len, ctx0->hash_state, 200); // Optim - 99% time boundary - cn_explode_scratchpad((__m128i*)ctx0->hash_state, (__m128i*)ctx0->long_state); + cn_explode_scratchpad((__m128i*)ctx0->hash_state, (__m128i*)ctx0->long_state); uint8_t* l0 = ctx0->long_state; uint64_t* h0 = (uint64_t*)ctx0->hash_state; @@ -332,7 +342,7 @@ void cryptonight_hash(const void* input, size_t len, void* output, cryptonight_c } // Optim - 90% time boundary - cn_implode_scratchpad((__m128i*)ctx0->long_state, (__m128i*)ctx0->hash_state); + cn_implode_scratchpad((__m128i*)ctx0->long_state, (__m128i*)ctx0->hash_state); // Optim - 99% time boundary @@ -350,8 +360,8 @@ void cryptonight_double_hash(const void* input, size_t len, void* output, crypto keccak((const uint8_t *)input+len, len, ctx1->hash_state, 200); // Optim - 99% time boundary - cn_explode_scratchpad((__m128i*)ctx0->hash_state, (__m128i*)ctx0->long_state); - cn_explode_scratchpad((__m128i*)ctx1->hash_state, (__m128i*)ctx1->long_state); + cn_explode_scratchpad((__m128i*)ctx0->hash_state, (__m128i*)ctx0->long_state); + cn_explode_scratchpad((__m128i*)ctx1->hash_state, (__m128i*)ctx1->long_state); uint8_t* l0 = ctx0->long_state; uint64_t* h0 = (uint64_t*)ctx0->hash_state; @@ -425,8 +435,8 @@ void cryptonight_double_hash(const void* input, size_t len, void* output, crypto } // Optim - 90% time boundary - cn_implode_scratchpad((__m128i*)ctx0->long_state, (__m128i*)ctx0->hash_state); - cn_implode_scratchpad((__m128i*)ctx1->long_state, (__m128i*)ctx1->hash_state); + cn_implode_scratchpad((__m128i*)ctx0->long_state, (__m128i*)ctx0->hash_state); + cn_implode_scratchpad((__m128i*)ctx1->long_state, (__m128i*)ctx1->hash_state); // Optim - 99% time boundary From 620cd678faa27800c6f67b869d314d350b72f1f9 Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Wed, 26 Apr 2017 20:40:36 +0100 Subject: [PATCH 25/25] Print a single-threaded autoconf on error --- autoAdjust.hpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/autoAdjust.hpp b/autoAdjust.hpp index ee1bbf5..c9ee9e6 100644 --- a/autoAdjust.hpp +++ b/autoAdjust.hpp @@ -32,12 +32,16 @@ public: printer::inst()->print_str("The values are not optimal, please try to tweak the values based on notes in config.txt.\n"); printer::inst()->print_str("Please copy & paste the block within the asterisks to your config.\n\n"); - if(!detectL3Size()) - return; - - if(L3KB_size < 1024 || L3KB_size > 102400) + if(!detectL3Size() || L3KB_size < 1024 || L3KB_size > 102400) { - printer::inst()->print_msg(L0, "Autoconf failed: L3 size sanity check failed - %u KB.", L3KB_size); + if(L3KB_size < 1024 || L3KB_size > 102400) + printer::inst()->print_msg(L0, "Autoconf failed: L3 size sanity check failed - %u KB.", L3KB_size); + + printer::inst()->print_msg(L0, "Autoconf failed: Printing config for a single thread. Please try to add new ones until the hashrate slows down."); + printer::inst()->print_str("\n**************** Copy&Paste ****************\n\n"); + printer::inst()->print_str("\"cpu_threads_conf\" :\n[\n"); + printer::inst()->print_str(" { \"low_power_mode\" : false, \"no_prefetch\" : true, \"affine_to_cpu\" : false },\n"); + printer::inst()->print_str("],\n\n**************** Copy&Paste ****************\n"); return; } @@ -82,7 +86,7 @@ public: L3KB_size -= 2048; } - printer::inst()->print_str("]\n\n**************** Copy&Paste ****************\n"); + printer::inst()->print_str("],\n\n**************** Copy&Paste ****************\n"); } private: