mirror of
https://github.com/jwinterm/xmr-stak.git
synced 2026-12-01 12:23:57 +01:00
Merge branch 'dev' into master
This commit is contained in:
+75
@@ -0,0 +1,75 @@
|
||||
dist: trusty
|
||||
|
||||
osx_image: xcode8.3
|
||||
|
||||
sudo: false
|
||||
|
||||
language: cpp
|
||||
|
||||
addons:
|
||||
apt:
|
||||
packages: &default_packages
|
||||
- cmake
|
||||
- libmicrohttpd-dev
|
||||
- libssl-dev
|
||||
- libhwloc-dev
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- *default_packages
|
||||
- gcc-5
|
||||
- g++-5
|
||||
env:
|
||||
- CMAKE_CXX_COMPILER=g++-5
|
||||
- CMAKE_C_COMPILER=gcc-5
|
||||
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- *default_packages
|
||||
- gcc-6
|
||||
- g++-6
|
||||
env:
|
||||
- CMAKE_CXX_COMPILER=g++-6
|
||||
- CMAKE_C_COMPILER=gcc-6
|
||||
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- *default_packages
|
||||
- gcc-7
|
||||
- g++-7
|
||||
env:
|
||||
- CMAKE_CXX_COMPILER=g++-7
|
||||
- CMAKE_C_COMPILER=gcc-7
|
||||
|
||||
- os: osx
|
||||
compiler: gcc
|
||||
|
||||
before_install:
|
||||
- if [ $TRAVIS_OS_NAME = osx ]; then brew tap homebrew/science; fi
|
||||
|
||||
script:
|
||||
- if [ $TRAVIS_OS_NAME = osx ]; then
|
||||
brew install hwloc;
|
||||
cmake -DMICROHTTPD_ENABLE=OFF -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl .;
|
||||
else
|
||||
cmake -D CMAKE_C_COMPILER=${CMAKE_C_COMPILER} -D CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} .;
|
||||
fi;
|
||||
- make VERBOSE=1
|
||||
- ./bin/xmr-stak-cpu -c ./config.txt
|
||||
+39
-19
@@ -48,36 +48,56 @@ 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")
|
||||
if(MICROHTTPD_REQUIRED)
|
||||
message(FATAL_ERROR "microhttpd NOT found: use `-DMICROHTTPD_REQUIRED=OFF` to build without http deamon support")
|
||||
option(MICROHTTPD_ENABLE "Enable or disable the requirement of microhttp (http deamon)" ON)
|
||||
if(MICROHTTPD_ENABLE)
|
||||
find_library(MHTD NAMES microhttpd)
|
||||
if("${MHTD}" STREQUAL "MHTD-NOTFOUND")
|
||||
message(FATAL_ERROR "microhttpd NOT found: use `-DMICROHTTPD_ENABLE=OFF` to build without http deamon support")
|
||||
else()
|
||||
message(STATUS "microhttpd NOT found: disable http server")
|
||||
add_definitions("-DCONF_NO_HTTPD")
|
||||
set(LIBS ${LIBS} ${MHTD})
|
||||
endif()
|
||||
else()
|
||||
set(LIBS ${LIBS} ${MHTD})
|
||||
add_definitions("-DCONF_NO_HTTPD")
|
||||
endif()
|
||||
|
||||
###############################################################################
|
||||
# Find OpenSSL
|
||||
###############################################################################
|
||||
|
||||
option(OpenSSL_REQUIRED "Enable or disable the requirement of OpenSSL" ON)
|
||||
find_package(OpenSSL)
|
||||
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")
|
||||
option(OpenSSL_ENABLE "Enable or disable the requirement of OpenSSL" ON)
|
||||
if(OpenSSL_ENABLE)
|
||||
find_package(OpenSSL)
|
||||
if(OPENSSL_FOUND)
|
||||
include_directories(${OPENSSL_INCLUDE_DIR})
|
||||
set(LIBS ${LIBS} ${OPENSSL_LIBRARIES})
|
||||
else()
|
||||
if(NOT OPENSSL_FOUND)
|
||||
add_definitions("-DCONF_NO_TLS")
|
||||
endif()
|
||||
message(FATAL_ERROR "OpenSSL NOT found: use `-DOpenSSL_ENABLE=OFF` to build without SSL support")
|
||||
endif()
|
||||
else()
|
||||
add_definitions("-DCONF_NO_TLS")
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
# Find hwloc
|
||||
################################################################################
|
||||
|
||||
option(HWLOC_ENABLE "Enable or disable the requirement of hwloc" ON)
|
||||
if(HWLOC_ENABLE)
|
||||
find_path(HWLOC_INCLUDE_DIR hwloc.h
|
||||
$ENV{HWLOC_ROOT}/inlcude
|
||||
/opt/local/include
|
||||
/usr/local/include
|
||||
/usr/include
|
||||
)
|
||||
find_library(HWLOC NAMES hwloc)
|
||||
if("${HWLOC}" STREQUAL "MHTD-NOTFOUND" OR ${HWLOC_INCLUDE_DIR} STREQUAL "HWLOC_INCLUDE_DIR-NOTFOUND")
|
||||
message(FATAL_ERROR "hwloc NOT found: use `-DHWLOC_ENABLE=OFF` to build without hwloc support")
|
||||
else()
|
||||
set(LIBS ${LIBS} ${HWLOC})
|
||||
include_directories(AFTER ${HWLOC_INCLUDE_DIR})
|
||||
endif()
|
||||
else()
|
||||
add_definitions("-DCONF_NO_HWLOC")
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
|
||||
@@ -42,12 +42,24 @@ xXl2Nm/u3cPP/eQVrZz5H8eACwIv+LL1EV+9uLanWUa+IO5hHr3KElvKNKD6vN0=
|
||||
-----END PGP SIGNATURE-----
|
||||
```
|
||||
|
||||
## Compile on Linux (Debian-based distros)
|
||||
## Compile on Linux
|
||||
|
||||
### GNU Compiler
|
||||
```
|
||||
sudo apt-get install libmicrohttpd-dev libssl-dev cmake build-essential
|
||||
# Ubuntu / Debian
|
||||
sudo apt-get install libmicrohttpd-dev libssl-dev cmake build-essential libhwloc-dev
|
||||
cmake .
|
||||
|
||||
# Fedora
|
||||
sudo dnf install gcc gcc-c++ hwloc-devel libmicrohttpd-devel openssl-devel cmake
|
||||
cmake .
|
||||
|
||||
# CentOS
|
||||
sudo yum install centos-release-scl cmake3 hwloc-devel libmicrohttpd-devel openssl-devel
|
||||
sudo yum install devtoolset-4-gcc*
|
||||
sudo scl enable devtoolset-4 bash
|
||||
cmake3 .
|
||||
|
||||
make install
|
||||
```
|
||||
|
||||
@@ -58,7 +70,7 @@ xXl2Nm/u3cPP/eQVrZz5H8eACwIv+LL1EV+9uLanWUa+IO5hHr3KElvKNKD6vN0=
|
||||
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'
|
||||
Note - cmake caches variables, so if you want to do a dynamic build later you need to specify '-DCMAKE_LINK_STATIC=OFF'
|
||||
|
||||
|
||||
You can find a complete compile guide under [Advanced Compile Options](#advanced-compile-options).
|
||||
@@ -168,12 +180,15 @@ and install.
|
||||
-`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*
|
||||
- `MICROHTTPD_ENABLE` 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*
|
||||
- there is no *http* interface available if option is disabled: `cmake . -DMICROHTTPD_ENABLE=OFF`
|
||||
- `OpenSSL_ENABLE` 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`
|
||||
- it is not possible to connect to a *https* secured pool if option is disabled: `cmake . -DOpenSSL_ENABLE=OFF`
|
||||
- `HWLOC_ENABLE` allow to disable/enable the dependency *hwloc*
|
||||
- by default enabled
|
||||
- the config suggestion is not optimal if option is disabled: `cmake . -DHWLOC_ENABLE=OFF`
|
||||
|
||||
## PGP Key
|
||||
```
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
#pragma once
|
||||
|
||||
#include "console.h"
|
||||
#include <hwloc.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif // _WIN32
|
||||
|
||||
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");
|
||||
printer::inst()->print_str("\n**************** Copy&Paste ****************\n\n");
|
||||
printer::inst()->print_str("\"cpu_threads_conf\" :\n[\n");
|
||||
|
||||
int depth;
|
||||
hwloc_topology_t topology;
|
||||
hwloc_obj_t socket;
|
||||
|
||||
|
||||
hwloc_topology_init(&topology);
|
||||
hwloc_topology_load(topology);
|
||||
|
||||
depth = hwloc_get_type_depth(topology, HWLOC_OBJ_SOCKET);
|
||||
if (depth == HWLOC_TYPE_DEPTH_UNKNOWN)
|
||||
{
|
||||
printf("*** The number of sockets is unknown\n");
|
||||
}
|
||||
|
||||
for (int i = 0; i < hwloc_get_nbobjs_by_depth(topology, depth); i++)
|
||||
{
|
||||
socket = hwloc_get_obj_by_depth(topology, depth, i);
|
||||
|
||||
// search cacheprinter::inst()->print_str("\n**************** Copy&Paste ****************\n\n");
|
||||
for (int j = 0; j < socket->arity; j++)
|
||||
{
|
||||
hwloc_obj_t nextLvl = socket->children[j];
|
||||
findCache(topology, nextLvl);
|
||||
}
|
||||
}
|
||||
|
||||
/* Destroy topology object. */
|
||||
hwloc_topology_destroy(topology);
|
||||
|
||||
printer::inst()->print_str("],\n\n**************** Copy&Paste ****************\n");
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/** count bits with ones */
|
||||
template<typename T>
|
||||
int compat_popcnt(T x)
|
||||
{
|
||||
int count = 0;
|
||||
for( int i = 0; i < sizeof(T) - 1; ++i )
|
||||
if( ( ( x >> i ) & 1 ) == 1 )
|
||||
++count;
|
||||
return count;
|
||||
}
|
||||
|
||||
int rightZeros(size_t v)
|
||||
{
|
||||
int c;
|
||||
if (v)
|
||||
{
|
||||
v = (v ^ (v - 1)) >> 1;
|
||||
for (c = 0; v; c++)
|
||||
{
|
||||
v >>= 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
c = CHAR_BIT * sizeof (v);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
inline void getConfig(hwloc_topology_t topology, hwloc_obj_t obj, size_t& numHashes, int& numCachesLeft)
|
||||
{
|
||||
if (obj->type == HWLOC_OBJ_CORE)
|
||||
{
|
||||
if (obj)
|
||||
{
|
||||
hwloc_cpuset_t cpuset;
|
||||
/* Get a copy of its cpuset that we may modify. */
|
||||
cpuset = hwloc_bitmap_dup(obj->cpuset);
|
||||
size_t allcpu = hwloc_bitmap_to_ulong(cpuset);
|
||||
/* Get only one logical processor (in case the core is
|
||||
SMT/hyperthreaded). */
|
||||
hwloc_bitmap_singlify(cpuset);
|
||||
|
||||
|
||||
size_t cpu = hwloc_bitmap_to_ulong(cpuset);
|
||||
// move bit mask to right to allow to compare always the first bit
|
||||
cpu >>= rightZeros(allcpu);
|
||||
|
||||
|
||||
int nativeCores = compat_popcnt(cpu);
|
||||
int numPus = obj->arity;
|
||||
for (int i = 0; i < numPus && numHashes != 0; i++)
|
||||
{
|
||||
hwloc_obj_t pu = obj->children[i];
|
||||
// only use native pu's
|
||||
if (pu->type == HWLOC_OBJ_PU && cpu & 1)
|
||||
{
|
||||
// if no cache is available we give each native core a hash
|
||||
int numUnit = numCachesLeft != 0 ? numCachesLeft : nativeCores;
|
||||
|
||||
// two hashes per native pu if number of hashes if larger than compute units
|
||||
int power = numHashes > numUnit ? 2 : 1;
|
||||
char strbuf[256];
|
||||
//printf("------------------------------core %i -> %i mpu=%i %lu\n", pu->os_index, power, nativeCores, numHashes);
|
||||
snprintf(strbuf, sizeof(strbuf), " { \"low_power_mode\" : %s, \"no_prefetch\" : true, \"affine_to_cpu\" : %u },\n",
|
||||
power == 2 ? "true" : "false", pu->os_index);
|
||||
printer::inst()->print_str(strbuf);
|
||||
|
||||
// update number of free hashes
|
||||
numHashes -= power;
|
||||
cpu >>= 1;
|
||||
|
||||
// one cache is filled with hashes
|
||||
if (numCachesLeft != 0) numCachesLeft--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < obj->arity; i++)
|
||||
getConfig(topology, obj->children[i], numHashes, numCachesLeft);
|
||||
}
|
||||
}
|
||||
|
||||
inline void findCache(hwloc_topology_t topology, hwloc_obj_t obj)
|
||||
{
|
||||
if (obj->type == HWLOC_OBJ_CACHE)
|
||||
{
|
||||
size_t cacheSize = obj->attr->cache.size;
|
||||
size_t numHashL3 = ( cacheSize + m_scratchPadMemSize/ 2llu ) / m_scratchPadMemSize;
|
||||
|
||||
/* check cache is exclusive or inclusive */
|
||||
const char* value = hwloc_obj_get_info_by_name(obj, "Inclusive");
|
||||
|
||||
|
||||
bool doL3 = true;
|
||||
if (value == NULL || value[0] != 49 || cacheSize == 0)
|
||||
{
|
||||
size_t numHashes = 0;
|
||||
int numL2 = obj->arity;
|
||||
for (int k = 0; k < numL2; k++)
|
||||
{
|
||||
hwloc_obj_t l3Cache = obj->children[k];
|
||||
size_t l2Cache = 0;
|
||||
|
||||
if (obj->type == HWLOC_OBJ_CACHE)
|
||||
l2Cache = l3Cache->attr->cache.size;
|
||||
else
|
||||
break;
|
||||
|
||||
if (l2Cache < m_scratchPadMemSize)
|
||||
{
|
||||
// we need to start from L3
|
||||
break;
|
||||
}
|
||||
|
||||
// start from L2
|
||||
|
||||
/* if more hashes available than objects in the current depth of the topology
|
||||
* than divide with round down else round up
|
||||
*/
|
||||
int extraHash = numHashL3 > numL2 ? numHashL3 / numL2 : (numHashL3 + numL2 - 1) / numL2;
|
||||
numHashL3 -= extraHash;
|
||||
if (numHashL3 < 0)
|
||||
numHashL3 = 0;
|
||||
numHashes += extraHash;
|
||||
//add L2 hashes
|
||||
numHashes += ( l2Cache + m_scratchPadMemSize / 2llu ) / m_scratchPadMemSize;
|
||||
int numCachesLeft = numL2;
|
||||
getConfig(topology, l3Cache, numHashes, numCachesLeft);
|
||||
doL3 = false;
|
||||
}
|
||||
}
|
||||
if (doL3)
|
||||
{
|
||||
int numCachesLeft = obj->arity;
|
||||
getConfig(topology, obj, numHashL3, numCachesLeft);
|
||||
}
|
||||
}
|
||||
else
|
||||
for (int j = 0; j < obj->arity; j++)
|
||||
findCache(topology, obj->children[j]);
|
||||
}
|
||||
|
||||
static constexpr size_t m_scratchPadMemSize = ( 2llu * 1024llu * 1024llu );
|
||||
};
|
||||
+18
-3
@@ -26,7 +26,12 @@
|
||||
#include "jconf.h"
|
||||
#include "console.h"
|
||||
#include "donate-level.h"
|
||||
#include "autoAdjust.hpp"
|
||||
#ifndef CONF_NO_HWLOC
|
||||
# include "autoAdjustHwloc.hpp"
|
||||
#else
|
||||
# include "autoAdjust.hpp"
|
||||
#endif
|
||||
#include "version.h"
|
||||
|
||||
#ifndef CONF_NO_HTTPD
|
||||
# include "httpd.h"
|
||||
@@ -133,7 +138,7 @@ int main(int argc, char *argv[])
|
||||
#endif
|
||||
|
||||
printer::inst()->print_str("-------------------------------------------------------------------\n");
|
||||
printer::inst()->print_str("XMR-Stak-CPU mining software, CPU Version.\n");
|
||||
printer::inst()->print_str( XMR_STAK_NAME" " XMR_STAK_VERSION " mining software, CPU Version.\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];
|
||||
@@ -148,7 +153,10 @@ int main(int argc, char *argv[])
|
||||
if(strlen(jconf::inst()->GetOutputFile()) != 0)
|
||||
printer::inst()->open_logfile(jconf::inst()->GetOutputFile());
|
||||
|
||||
executor::inst()->ex_start();
|
||||
executor::inst()->ex_start(jconf::inst()->DaemonMode());
|
||||
|
||||
using namespace std::chrono;
|
||||
uint64_t lastTime = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
|
||||
|
||||
int key;
|
||||
while(true)
|
||||
@@ -169,6 +177,13 @@ int main(int argc, char *argv[])
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
uint64_t currentTime = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
|
||||
|
||||
/* Hard guard to make sure we never get called more than twice per second */
|
||||
if( currentTime - lastTime < 500)
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500 - (currentTime - lastTime)));
|
||||
lastTime = currentTime;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -139,6 +139,14 @@ null,
|
||||
*/
|
||||
"h_print_time" : 60,
|
||||
|
||||
/*
|
||||
* Daemon mode
|
||||
*
|
||||
* If you are running the process in the background and you don't need the keyboard reports, set this to true.
|
||||
* This should solve the hashrate problems on some emulated terminals.
|
||||
*/
|
||||
"daemon_mode" : false,
|
||||
|
||||
/*
|
||||
* Output file
|
||||
*
|
||||
|
||||
+29
-19
@@ -368,9 +368,11 @@ void cryptonight_double_hash(const void* input, size_t len, void* output, crypto
|
||||
uint8_t* l1 = ctx1->long_state;
|
||||
uint64_t* h1 = (uint64_t*)ctx1->hash_state;
|
||||
|
||||
__m128i ax0 = _mm_set_epi64x(h0[1] ^ h0[5], h0[0] ^ h0[4]);
|
||||
uint64_t axl0 = h0[0] ^ h0[4];
|
||||
uint64_t axh0 = h0[1] ^ h0[5];
|
||||
__m128i bx0 = _mm_set_epi64x(h0[3] ^ h0[7], h0[2] ^ h0[6]);
|
||||
__m128i ax1 = _mm_set_epi64x(h1[1] ^ h1[5], h1[0] ^ h1[4]);
|
||||
uint64_t axl1 = h1[0] ^ h1[4];
|
||||
uint64_t axh1 = h1[1] ^ h1[5];
|
||||
__m128i bx1 = _mm_set_epi64x(h1[3] ^ h1[7], h1[2] ^ h1[6]);
|
||||
|
||||
uint64_t idx0 = h0[0] ^ h0[4];
|
||||
@@ -383,9 +385,9 @@ void cryptonight_double_hash(const void* input, size_t len, void* output, crypto
|
||||
cx = _mm_load_si128((__m128i *)&l0[idx0 & 0x1FFFF0]);
|
||||
|
||||
if(SOFT_AES)
|
||||
cx = soft_aesenc(cx, ax0);
|
||||
cx = soft_aesenc(cx, _mm_set_epi64x(axh0, axl0));
|
||||
else
|
||||
cx = _mm_aesenc_si128(cx, ax0);
|
||||
cx = _mm_aesenc_si128(cx, _mm_set_epi64x(axh0, axl0));
|
||||
|
||||
_mm_store_si128((__m128i *)&l0[idx0 & 0x1FFFF0], _mm_xor_si128(bx0, cx));
|
||||
idx0 = _mm_cvtsi128_si64(cx);
|
||||
@@ -397,9 +399,9 @@ void cryptonight_double_hash(const void* input, size_t len, void* output, crypto
|
||||
cx = _mm_load_si128((__m128i *)&l1[idx1 & 0x1FFFF0]);
|
||||
|
||||
if(SOFT_AES)
|
||||
cx = soft_aesenc(cx, ax1);
|
||||
cx = soft_aesenc(cx, _mm_set_epi64x(axh1, axl1));
|
||||
else
|
||||
cx = _mm_aesenc_si128(cx, ax1);
|
||||
cx = _mm_aesenc_si128(cx, _mm_set_epi64x(axh1, axl1));
|
||||
|
||||
_mm_store_si128((__m128i *)&l1[idx1 & 0x1FFFF0], _mm_xor_si128(bx1, cx));
|
||||
idx1 = _mm_cvtsi128_si64(cx);
|
||||
@@ -408,27 +410,35 @@ void cryptonight_double_hash(const void* input, size_t len, void* output, crypto
|
||||
if(PREFETCH)
|
||||
_mm_prefetch((const char*)&l1[idx1 & 0x1FFFF0], _MM_HINT_T0);
|
||||
|
||||
uint64_t hi, lo;
|
||||
cx = _mm_load_si128((__m128i *)&l0[idx0 & 0x1FFFF0]);
|
||||
uint64_t hi, lo, cl, ch;
|
||||
cl = ((uint64_t*)&l0[idx0 & 0x1FFFF0])[0];
|
||||
ch = ((uint64_t*)&l0[idx0 & 0x1FFFF0])[1];
|
||||
|
||||
lo = _umul128(idx0, _mm_cvtsi128_si64(cx), &hi);
|
||||
lo = _umul128(idx0, cl, &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);
|
||||
axl0 += hi;
|
||||
axh0 += lo;
|
||||
((uint64_t*)&l0[idx0 & 0x1FFFF0])[0] = axl0;
|
||||
((uint64_t*)&l0[idx0 & 0x1FFFF0])[1] = axh0;
|
||||
axh0 ^= ch;
|
||||
axl0 ^= cl;
|
||||
idx0 = axl0;
|
||||
|
||||
if(PREFETCH)
|
||||
_mm_prefetch((const char*)&l0[idx0 & 0x1FFFF0], _MM_HINT_T0);
|
||||
|
||||
cx = _mm_load_si128((__m128i *)&l1[idx1 & 0x1FFFF0]);
|
||||
cl = ((uint64_t*)&l1[idx1 & 0x1FFFF0])[0];
|
||||
ch = ((uint64_t*)&l1[idx1 & 0x1FFFF0])[1];
|
||||
|
||||
lo = _umul128(idx1, _mm_cvtsi128_si64(cx), &hi);
|
||||
lo = _umul128(idx1, cl, &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);
|
||||
axl1 += hi;
|
||||
axh1 += lo;
|
||||
((uint64_t*)&l1[idx1 & 0x1FFFF0])[0] = axl1;
|
||||
((uint64_t*)&l1[idx1 & 0x1FFFF0])[1] = axh1;
|
||||
axh1 ^= ch;
|
||||
axl1 ^= cl;
|
||||
idx1 = axl1;
|
||||
|
||||
if(PREFETCH)
|
||||
_mm_prefetch((const char*)&l1[idx1 & 0x1FFFF0], _MM_HINT_T0);
|
||||
|
||||
@@ -146,6 +146,9 @@ cryptonight_ctx* cryptonight_alloc_ctx(size_t use_fast_mem, size_t use_mlock, al
|
||||
#if defined(__APPLE__)
|
||||
ptr->long_state = (uint8_t*)mmap(0, MEMORY, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON, VM_FLAGS_SUPERPAGE_SIZE_2MB, 0);
|
||||
#elif defined(__FreeBSD__)
|
||||
ptr->long_state = (uint8_t*)mmap(0, MEMORY, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER | MAP_PREFAULT_READ, -1, 0);
|
||||
#else
|
||||
ptr->long_state = (uint8_t*)mmap(0, MEMORY, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0);
|
||||
|
||||
@@ -43,7 +43,6 @@ executor* executor::oInst = NULL;
|
||||
|
||||
executor::executor()
|
||||
{
|
||||
my_thd = nullptr;
|
||||
}
|
||||
|
||||
void executor::push_timed_event(ex_event&& ev, size_t sec)
|
||||
|
||||
+3
-3
@@ -19,8 +19,7 @@ public:
|
||||
return oInst;
|
||||
};
|
||||
|
||||
void ex_start() { my_thd = new std::thread(&executor::ex_main, this); }
|
||||
void ex_main();
|
||||
void ex_start(bool daemon) { daemon ? ex_main() : std::thread(&executor::ex_main, this).detach(); }
|
||||
|
||||
void get_http_report(ex_event_name ev_id, std::string& data);
|
||||
|
||||
@@ -53,7 +52,6 @@ private:
|
||||
|
||||
telemetry* telem;
|
||||
std::vector<minethd*>* pvThreads;
|
||||
std::thread* my_thd;
|
||||
|
||||
size_t current_pool_id;
|
||||
|
||||
@@ -67,6 +65,8 @@ private:
|
||||
executor();
|
||||
static executor* oInst;
|
||||
|
||||
void ex_main();
|
||||
|
||||
void ex_clock_thd();
|
||||
void pool_connect(jpsock* pool);
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include "console.h"
|
||||
|
||||
#ifndef CONF_NO_HWLOC
|
||||
|
||||
#include <hwloc.h>
|
||||
|
||||
/** pin memory to NUMA node
|
||||
*
|
||||
* Set the default memory policy for the current thread to bind memory to the
|
||||
* NUMA node.
|
||||
*
|
||||
* @param puId core id
|
||||
*/
|
||||
void bindMemoryToNUMANode( int puId )
|
||||
{
|
||||
int depth;
|
||||
hwloc_topology_t topology;
|
||||
hwloc_obj_t obj;
|
||||
|
||||
hwloc_topology_init(&topology);
|
||||
hwloc_topology_load(topology);
|
||||
|
||||
depth = hwloc_get_type_depth(topology, HWLOC_OBJ_PU);
|
||||
|
||||
for( int i = 0;
|
||||
i < hwloc_get_nbobjs_by_depth(topology, depth);
|
||||
i++ )
|
||||
{
|
||||
hwloc_obj_t pu = hwloc_get_obj_by_depth(topology, depth, i);
|
||||
if( pu->os_index == puId )
|
||||
if( 0 > hwloc_set_membind_nodeset(
|
||||
topology,
|
||||
pu->nodeset,
|
||||
HWLOC_MEMBIND_BIND,
|
||||
HWLOC_MEMBIND_THREAD)
|
||||
)
|
||||
printer::inst()->print_msg(L0, "hwloc: can't bind memory");
|
||||
else
|
||||
{
|
||||
printer::inst()->print_msg(L0, "hwloc: memory pinned");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
void bindMemoryToNUMANode( int )
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -48,7 +48,7 @@ using namespace rapidjson;
|
||||
enum configEnum { aCpuThreadsConf, sUseSlowMem, bNiceHashMode,
|
||||
bTlsMode, bTlsSecureAlgo, sTlsFingerprint, sPoolAddr, sWalletAddr, sPoolPwd,
|
||||
iCallTimeout, iNetRetry, iGiveUpLimit, iVerboseLevel, iAutohashTime,
|
||||
sOutputFile, iHttpdPort, bPreferIpv4 };
|
||||
bDaemonMode, sOutputFile, iHttpdPort, bPreferIpv4 };
|
||||
|
||||
struct configVal {
|
||||
configEnum iName;
|
||||
@@ -73,6 +73,7 @@ configVal oConfigValues[] = {
|
||||
{ iGiveUpLimit, "giveup_limit", kNumberType },
|
||||
{ iVerboseLevel, "verbose_level", kNumberType },
|
||||
{ iAutohashTime, "h_print_time", kNumberType },
|
||||
{ bDaemonMode, "daemon_mode", kTrueType },
|
||||
{ sOutputFile, "output_file", kStringType },
|
||||
{ iHttpdPort, "httpd_port", kNumberType },
|
||||
{ bPreferIpv4, "prefer_ipv4", kTrueType }
|
||||
@@ -251,6 +252,11 @@ bool jconf::NiceHashMode()
|
||||
return prv->configValues[bNiceHashMode]->GetBool();
|
||||
}
|
||||
|
||||
bool jconf::DaemonMode()
|
||||
{
|
||||
return prv->configValues[bDaemonMode]->GetBool();
|
||||
}
|
||||
|
||||
const char* jconf::GetOutputFile()
|
||||
{
|
||||
return prv->configValues[sOutputFile]->GetString();
|
||||
|
||||
@@ -54,6 +54,8 @@ public:
|
||||
|
||||
bool NiceHashMode();
|
||||
|
||||
bool DaemonMode();
|
||||
|
||||
bool PreferIpv4();
|
||||
|
||||
inline bool HaveHardwareAes() { return bHaveAes; }
|
||||
|
||||
+2
-1
@@ -32,8 +32,9 @@
|
||||
#include "jext.h"
|
||||
#include "socks.h"
|
||||
#include "socket.h"
|
||||
#include "version.h"
|
||||
|
||||
#define AGENTID_STR "xmr-stak-cpu/1.3.1"
|
||||
#define AGENTID_STR XMR_STAK_NAME "/" XMR_STAK_VERSION
|
||||
|
||||
using namespace rapidjson;
|
||||
|
||||
|
||||
+19
-3
@@ -42,15 +42,23 @@ void thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id)
|
||||
#include <mach/thread_policy.h>
|
||||
#include <mach/thread_act.h>
|
||||
#define SYSCTL_CORE_COUNT "machdep.cpu.core_count"
|
||||
#elif defined(__FreeBSD__)
|
||||
#include <pthread_np.h>
|
||||
#endif
|
||||
|
||||
|
||||
void thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id)
|
||||
{
|
||||
#if defined(__APPLE__)
|
||||
thread_port_t mach_thread;
|
||||
thread_affinity_policy_data_t policy = { cpu_id };
|
||||
thread_affinity_policy_data_t policy = { static_cast<integer_t>(cpu_id) };
|
||||
mach_thread = pthread_mach_thread_np(h);
|
||||
thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY, (thread_policy_t)&policy, 1);
|
||||
#elif defined(__FreeBSD__)
|
||||
cpuset_t mn;
|
||||
CPU_ZERO(&mn);
|
||||
CPU_SET(cpu_id, &mn);
|
||||
pthread_setaffinity_np(h, sizeof(cpuset_t), &mn);
|
||||
#else
|
||||
cpu_set_t mn;
|
||||
CPU_ZERO(&mn);
|
||||
@@ -64,6 +72,7 @@ void thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id)
|
||||
#include "minethd.h"
|
||||
#include "jconf.h"
|
||||
#include "crypto/cryptonight_aesni.h"
|
||||
#include "hwlocMemory.hpp"
|
||||
|
||||
telemetry::telemetry(size_t iThd)
|
||||
{
|
||||
@@ -140,7 +149,7 @@ void telemetry::push_perf_value(size_t iThd, uint64_t iHashCount, uint64_t iTime
|
||||
iBucketTop[iThd] = (iTop + 1) & iBucketMask;
|
||||
}
|
||||
|
||||
minethd::minethd(miner_work& pWork, size_t iNo, bool double_work, bool no_prefetch)
|
||||
minethd::minethd(miner_work& pWork, size_t iNo, bool double_work, bool no_prefetch, int affinity)
|
||||
{
|
||||
oWork = pWork;
|
||||
bQuit = 0;
|
||||
@@ -149,6 +158,7 @@ minethd::minethd(miner_work& pWork, size_t iNo, bool double_work, bool no_prefet
|
||||
iHashCount = 0;
|
||||
iTimestamp = 0;
|
||||
bNoPrefetch = no_prefetch;
|
||||
this->affinity = affinity;
|
||||
|
||||
if(double_work)
|
||||
oWorkThd = std::thread(&minethd::double_work_main, this);
|
||||
@@ -295,7 +305,7 @@ std::vector<minethd*>* minethd::thread_starter(miner_work& pWork)
|
||||
{
|
||||
jconf::inst()->GetThreadConfig(i, cfg);
|
||||
|
||||
minethd* thd = new minethd(pWork, i, cfg.bDoubleMode, cfg.bNoPrefetch);
|
||||
minethd* thd = new minethd(pWork, i, cfg.bDoubleMode, cfg.bNoPrefetch, cfg.iCpuAff);
|
||||
|
||||
if(cfg.iCpuAff >= 0)
|
||||
{
|
||||
@@ -361,6 +371,9 @@ minethd::cn_hash_fun minethd::func_selector(bool bHaveAes, bool bNoPrefetch)
|
||||
|
||||
void minethd::work_main()
|
||||
{
|
||||
// pin memory to NUMA node
|
||||
bindMemoryToNUMANode(this->affinity);
|
||||
|
||||
cn_hash_fun hash_fun;
|
||||
cryptonight_ctx* ctx;
|
||||
uint64_t iCount = 0;
|
||||
@@ -448,6 +461,9 @@ minethd::cn_hash_fun_dbl minethd::func_dbl_selector(bool bHaveAes, bool bNoPrefe
|
||||
|
||||
void minethd::double_work_main()
|
||||
{
|
||||
// pin memory to NUMA node
|
||||
bindMemoryToNUMANode(this->affinity);
|
||||
|
||||
cn_hash_fun_dbl hash_fun;
|
||||
cryptonight_ctx* ctx0;
|
||||
cryptonight_ctx* ctx1;
|
||||
|
||||
@@ -97,11 +97,13 @@ public:
|
||||
std::atomic<uint64_t> iHashCount;
|
||||
std::atomic<uint64_t> iTimestamp;
|
||||
|
||||
int affinity;
|
||||
|
||||
private:
|
||||
typedef void (*cn_hash_fun)(const void*, size_t, void*, 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);
|
||||
minethd(miner_work& pWork, size_t iNo, bool double_work, bool no_prefetch, int affinity);
|
||||
|
||||
// We use the top 10 bits of the nonce for thread and resume
|
||||
// This allows us to resume up to 128 threads 4 times before
|
||||
|
||||
@@ -60,6 +60,9 @@ inline const char* sock_gai_strerror(int err, char* buf, size_t len)
|
||||
#include <unistd.h> /* Needed for close() */
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#if defined(__FreeBSD__)
|
||||
#include <netinet/in.h> /* Needed for IPPROTO_TCP */
|
||||
#endif
|
||||
|
||||
inline void sock_init() {}
|
||||
typedef int SOCKET;
|
||||
@@ -76,7 +79,9 @@ inline void sock_close(SOCKET s)
|
||||
inline const char* sock_strerror(char* buf, size_t len)
|
||||
{
|
||||
buf[0] = '\0';
|
||||
|
||||
#if defined(__APPLE__) || defined(__FreeBSD__) || !defined(_GNU_SOURCE) || !defined(__GLIBC__)
|
||||
|
||||
strerror_r(errno, buf, len);
|
||||
return buf;
|
||||
#else
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#define XMR_STAK_NAME "xmr-stak-cpu"
|
||||
#define XMR_STAK_VERSION "1.4.1-dev"
|
||||
@@ -67,6 +67,7 @@
|
||||
<Add library="libmicrohttpd" />
|
||||
<Add library="crypto" />
|
||||
<Add library="ssl" />
|
||||
<Add library="libhwloc" />
|
||||
</Linker>
|
||||
<Unit filename="autoAdjust.hpp" />
|
||||
<Unit filename="cli-miner.cpp" />
|
||||
|
||||
Reference in New Issue
Block a user