Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ if(MICROHTTPD_ENABLE)
/usr/local
/usr
ENV "PROGRAMFILES(X86)"
ENV "HWLOC_ROOT"
ENV "MICROHTTPD_ROOT"
PATH_SUFFIXES
include)

Expand Down
8 changes: 5 additions & 3 deletions LINUXCOMPILE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
make install

# Fedora
sudo dnf install gcc gcc-c++ hwloc-devel libmicrohttpd-devel openssl-devel cmake
sudo dnf install gcc gcc-c++ hwloc-devel libmicrohttpd-devel libstdc++-static make openssl-devel cmake
cmake .
make install

# CentOS
sudo yum install centos-release-scl cmake3 hwloc-devel libmicrohttpd-devel openssl-devel
sudo yum install devtoolset-4-gcc*
sudo yum install centos-release-scl epel-release
sudo yum install cmake3 devtoolset-4-gcc* hwloc-devel libmicrohttpd-devel openssl-devel make
sudo scl enable devtoolset-4 bash
cmake3 .
make install
Expand All @@ -39,6 +39,8 @@

- g++ 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.

If you want to compile the binary without installing libraries / compiler or just compile binary for some other distribution, please check the [build_xmr-stak_docker.sh script](scripts/build_xmr-stak_docker/build_xmr-stak_docker.sh).

### To do a static build for a system without gcc 5.1+
```
cmake -DCMAKE_LINK_STATIC=ON .
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Download and install this [runtime package](https://go.microsoft.com/fwlink/?Lin
From [config.txt](config.txt):

On Linux you will need to configure large page support `sudo sysctl -w vm.nr_hugepages=128` and increase your
ulimit -l. To do do this you need to add following lines to /etc/security/limits.conf:
ulimit -l. To do this you need to add following lines to /etc/security/limits.conf:

* soft memlock 262144
* hard memlock 262144
Expand Down
10 changes: 5 additions & 5 deletions config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ null,

/*
* LARGE PAGE SUPPORT
* Lare pages need a properly set up OS. It can be difficult if you are not used to systems administation,
* but the performace results are worth the trouble - you will get around 20% boost. Slow memory mode is
* Large pages need a properly set up OS. It can be difficult if you are not used to systems administration,
* but the performance results are worth the trouble - you will get around 20% boost. Slow memory mode is
* meant as a backup, you won't get stellar results there. If you are running into trouble, especially
* on Windows, please read the common issues in the README.
*
Expand All @@ -53,13 +53,13 @@ null,
* and "* hard memlock 262144". You can also do it Windows-style and simply run-as-root, but this is NOT
* recommended for security reasons.
*
* Memory locking means that the kernel can't swap out the page to disk - something that is unlikey to happen on a
* Memory locking means that the kernel can't swap out the page to disk - something that is unlikely to happen on a
* command line system that isn't starved of memory. I haven't observed any difference on a CLI Linux system between
* locked and unlocked memory. If that is your setup see option "no_mlck".
*/

/*
* use_slow_memory defines our behaviour with regards to large pages. There are three possible options here:
* use_slow_memory defines our behavior with regards to large pages. There are three possible options here:
* always - Don't even try to use large pages. Always use slow memory.
* warn - We will try to use large pages, but fall back to slow memory if that fails.
* no_mlck - This option is only relevant on Linux, where we can use large pages without locking memory.
Expand All @@ -70,7 +70,7 @@ null,

/*
* NiceHash mode
* nicehash_nonce - Limit the noce to 3 bytes as required by nicehash. This cuts all the safety margins, and
* nicehash_nonce - Limit the nonce to 3 bytes as required by nicehash. This cuts all the safety margins, and
* if a block isn't found within 30 minutes then you might run into nonce collisions. Number
* of threads in this mode is hard-limited to 32.
*/
Expand Down
27 changes: 19 additions & 8 deletions minethd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ minethd::minethd(miner_work& pWork, size_t iNo, bool double_work, bool no_prefet
bNoPrefetch = no_prefetch;
this->affinity = affinity;

std::lock_guard<std::mutex> lock(work_thd_mtx);
if(double_work)
oWorkThd = std::thread(&minethd::double_work_main, this);
else
Expand Down Expand Up @@ -363,6 +364,9 @@ minethd::cn_hash_fun minethd::func_selector(bool bHaveAes, bool bNoPrefetch)

void minethd::pin_thd_affinity()
{
//Lock is needed because we need to use oWorkThd
std::lock_guard<std::mutex> lock(work_thd_mtx);

// pin memory to NUMA node
bindMemoryToNUMANode(affinity);

Expand Down Expand Up @@ -462,6 +466,13 @@ minethd::cn_hash_fun_dbl minethd::func_dbl_selector(bool bHaveAes, bool bNoPrefe
return func_table[digit.to_ulong()];
}

uint32_t* minethd::prep_double_work(uint8_t bDoubleWorkBlob[sizeof(miner_work::bWorkBlob) * 2])
{
memcpy(bDoubleWorkBlob, oWork.bWorkBlob, oWork.iWorkSize);
memcpy(bDoubleWorkBlob + oWork.iWorkSize, oWork.bWorkBlob, oWork.iWorkSize);
return (uint32_t*)(bDoubleWorkBlob + oWork.iWorkSize + 39);
}

void minethd::double_work_main()
{
if(affinity >= 0) //-1 means no affinity
Expand All @@ -474,7 +485,7 @@ void minethd::double_work_main()
uint64_t *piHashVal0, *piHashVal1;
uint32_t *piNonce0, *piNonce1;
uint8_t bDoubleHashOut[64];
uint8_t bDoubleWorkBlob[sizeof(miner_work::bWorkBlob) * 2];
uint8_t bDoubleWorkBlob[sizeof(miner_work::bWorkBlob) * 2];
uint32_t iNonce;
job_result res;

Expand All @@ -485,7 +496,11 @@ void minethd::double_work_main()
piHashVal0 = (uint64_t*)(bDoubleHashOut + 24);
piHashVal1 = (uint64_t*)(bDoubleHashOut + 32 + 24);
piNonce0 = (uint32_t*)(bDoubleWorkBlob + 39);
piNonce1 = nullptr;

if(!oWork.bStall)
piNonce1 = prep_double_work(bDoubleWorkBlob);
else
piNonce1 = nullptr;

iConsumeCnt++;

Expand All @@ -501,9 +516,7 @@ void minethd::double_work_main()
std::this_thread::sleep_for(std::chrono::milliseconds(100));

consume_work();
memcpy(bDoubleWorkBlob, oWork.bWorkBlob, oWork.iWorkSize);
memcpy(bDoubleWorkBlob + oWork.iWorkSize, oWork.bWorkBlob, oWork.iWorkSize);
piNonce1 = (uint32_t*)(bDoubleWorkBlob + oWork.iWorkSize + 39);
piNonce1 = prep_double_work(bDoubleWorkBlob);
continue;
}

Expand Down Expand Up @@ -541,9 +554,7 @@ void minethd::double_work_main()
}

consume_work();
memcpy(bDoubleWorkBlob, oWork.bWorkBlob, oWork.iWorkSize);
memcpy(bDoubleWorkBlob + oWork.iWorkSize, oWork.bWorkBlob, oWork.iWorkSize);
piNonce1 = (uint32_t*)(bDoubleWorkBlob + oWork.iWorkSize + 39);
piNonce1 = prep_double_work(bDoubleWorkBlob);
}

cryptonight_free_ctx(ctx0);
Expand Down
4 changes: 4 additions & 0 deletions minethd.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include <thread>
#include <atomic>
#include <mutex>
#include "crypto/cryptonight.h"

class telemetry
Expand Down Expand Up @@ -120,6 +121,7 @@ class minethd
void work_main();
void double_work_main();
void consume_work();
uint32_t* prep_double_work(uint8_t bDoubleWorkBlob[sizeof(miner_work::bWorkBlob) * 2]);

static std::atomic<uint64_t> iGlobalJobNo;
static std::atomic<uint64_t> iConsumeCnt;
Expand All @@ -130,6 +132,8 @@ class minethd
miner_work oWork;

void pin_thd_affinity();
// Held by the creating context to prevent a race cond with oWorkThd = std::thread(...)
std::mutex work_thd_mtx;

std::thread oWorkThd;
uint8_t iThreadNo;
Expand Down
114 changes: 114 additions & 0 deletions scripts/build_xmr-stak_docker/build_xmr-stak_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/bin/bash -uex

if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi

if [ -d xmr-stak-cpu ]; then
git -C xmr-stak-cpu clean -fd
else
git clone https://github.com/fireice-uk/xmr-stak-cpu.git
fi


########################
# Fedora 26
########################
docker run --rm -it -v $PWD/xmr-stak-cpu:/xmr-stak-cpu fedora:26 /bin/bash -c "
set -ex ;
dnf install -y -q gcc gcc-c++ hwloc-devel libmicrohttpd-devel libstdc++-static make openssl-devel cmake ;
cd /xmr-stak-cpu ;
cmake -DCMAKE_LINK_STATIC=ON . ;
make install ;
"
mv xmr-stak-cpu/bin/xmr-stak-cpu xmr-stak-cpu_fedora_26
git -C xmr-stak-cpu clean -fd


########################
# Ubuntu (17.04)
########################
docker run --rm -it -v $PWD/xmr-stak-cpu:/xmr-stak-cpu ubuntu:17.04 /bin/bash -c "
set -ex ;
apt update -qq ;
apt install -y -qq libmicrohttpd-dev libssl-dev cmake build-essential libhwloc-dev ;
cd /xmr-stak-cpu ;
cmake -DCMAKE_LINK_STATIC=ON . ;
make install ;
"
mv xmr-stak-cpu/bin/xmr-stak-cpu xmr-stak-cpu_ubuntu_17.04
git -C xmr-stak-cpu clean -fd


########################
# Ubuntu 16.04
########################
docker run --rm -it -v $PWD/xmr-stak-cpu:/xmr-stak-cpu ubuntu:16.04 /bin/bash -c "
set -ex ;
apt update -qq ;
apt install -y -qq libmicrohttpd-dev libssl-dev cmake build-essential libhwloc-dev ;
cd /xmr-stak-cpu ;
cmake -DCMAKE_LINK_STATIC=ON . ;
make install ;
"
mv xmr-stak-cpu/bin/xmr-stak-cpu xmr-stak-cpu_ubuntu_16.04
git -C xmr-stak-cpu clean -fd


########################
# Ubuntu 14.04
########################
docker run --rm -it -v $PWD/xmr-stak-cpu:/xmr-stak-cpu ubuntu:14.04 /bin/bash -c "
set -ex ;
apt update -qq ;
apt install -y -qq curl libmicrohttpd-dev libssl-dev libhwloc-dev software-properties-common ;
add-apt-repository -y ppa:ubuntu-toolchain-r/test ;
apt update -qq ;
apt install -y -qq gcc-7 g++-7 make ;
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 1 --slave /usr/bin/g++ g++ /usr/bin/g++-7 ;
curl -L https://cmake.org/files/v3.9/cmake-3.9.0.tar.gz | tar -xzf - -C /tmp/ ;
( cd /tmp/cmake-3.9.0/ && ./configure && make && sudo make install && cd - ) > /dev/null
update-alternatives --install /usr/bin/cmake cmake /usr/local/bin/cmake 1 --force ;
cd /xmr-stak-cpu ;
cmake -DCMAKE_LINK_STATIC=ON . ;
make install ;
"
mv xmr-stak-cpu/bin/xmr-stak-cpu xmr-stak-cpu_ubuntu_14.04
git -C xmr-stak-cpu clean -fd


########################
# CentOS 7
########################
docker run --rm -it -v $PWD/xmr-stak-cpu:/xmr-stak-cpu centos:7 /bin/bash -c "
set -ex ;
yum install -y -q centos-release-scl epel-release ;
yum install -y -q cmake3 devtoolset-4-gcc* hwloc-devel libmicrohttpd-devel openssl-devel make ;
scl enable devtoolset-4 - << EOF
cd /xmr-stak-cpu ;
cmake3 -DCMAKE_LINK_STATIC=ON . ;
make install ;
EOF
"
mv xmr-stak-cpu/bin/xmr-stak-cpu xmr-stak-cpu_centos_7
git -C xmr-stak-cpu clean -fd


########################
# CentOS 6.x
########################
docker run --rm -it -v $PWD/xmr-stak-cpu:/xmr-stak-cpu centos:6 /bin/bash -c "
set -ex ;
yum install -y -q centos-release-scl epel-release ;
yum install -y -q cmake3 devtoolset-4-gcc* hwloc-devel libmicrohttpd-devel openssl-devel make ;
scl enable devtoolset-4 - << EOF
cd /xmr-stak-cpu ;
cmake3 -DCMAKE_LINK_STATIC=ON . ;
make install ;
EOF
"
mv xmr-stak-cpu/bin/xmr-stak-cpu xmr-stak-cpu_centos_6
git -C xmr-stak-cpu clean -fd

rm -rf xmr-stak-cpu