Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/.gitignore b/.gitignore
- index 30ce3a1..3094469 100644
- --- a/.gitignore
- +++ b/.gitignore
- @@ -1,3 +1,2 @@
- -/build
- -/CMakeLists.txt.user
- -/build2
- +.DS_Store
- +build
- diff --git a/.travis.yml b/.travis.yml
- new file mode 100644
- index 0000000..da46bf0
- --- /dev/null
- +++ b/.travis.yml
- @@ -0,0 +1,12 @@
- +sudo: required
- +
- +language: cpp
- +
- +services:
- + - docker
- +
- +before_install:
- + - docker build .
- +
- +script:
- + - echo Done
- diff --git a/CHANGELOG.md b/CHANGELOG.md
- index d4f057b..e69de29 100644
- --- a/CHANGELOG.md
- +++ b/CHANGELOG.md
- @@ -1,31 +0,0 @@
- -# v2.5.2
- -- [#448](https://github.com/xmrig/xmrig/issues/478) Fixed broken reconnect.
- -
- -# v2.5.1
- -- [#454](https://github.com/xmrig/xmrig/issues/454) Fixed build with libmicrohttpd version below v0.9.35.
- -- [#456](https://github.com/xmrig/xmrig/issues/459) Verbose errors related to donation pool was not fully silenced.
- -- [#459](https://github.com/xmrig/xmrig/issues/459) Fixed regression (version 2.5.0 affected) with connection to **xmr.f2pool.com**.
- -
- -# v2.5.0
- -- [#434](https://github.com/xmrig/xmrig/issues/434) **Added support for Monero v7 PoW, scheduled on April 6.**
- -- Added full IPv6 support.
- -- Added protocol extension, when use the miner with xmrig-proxy 2.5+ no more need manually specify `nicehash` option.
- -- [#51](https://github.com/xmrig/xmrig-amd/issues/51) Fixed multiple pools in initial config was saved incorrectly.
- -- [#123](https://github.com/xmrig/xmrig-proxy/issues/123) Fixed regression (all versions since 2.4 affected) fragmented responses from pool/proxy was parsed incorrectly.
- -
- -# v2.4.5
- - - [#49](https://github.com/xmrig/xmrig-amd/issues/49) Fixed, in some cases, pause was cause an infinite loop.
- - - [#200](https://github.com/xmrig/xmrig/issues/200) In some cases miner was doesn't write log to stdout.
- - - Added libmicrohttpd version to --version output.
- - - Fixed bug in singal handler, in some cases miner wasn't shutdown properly.
- - - Fixed recent MSVC 2017 version detection.
- -
- -# v2.4.3-beta2
- - - Fixed, auto config wasn't write opencl-platform to config.json.
- - - Added command line option `--print-platforms`.
- - - Fixed 32 bit build.
- - - [#2](https://github.com/xmrig/xmrig-amd/issues/2) Fixed Linux build.
- - - [#3](https://github.com/xmrig/xmrig-amd/issues/3) Fixed macOS build.
- -
- -# v2.4.3-beta1
- - - First public release.
- diff --git a/CMakeLists.txt b/CMakeLists.txt
- index 282288e..941db55 100644
- --- a/CMakeLists.txt
- +++ b/CMakeLists.txt
- @@ -1,5 +1,6 @@
- cmake_minimum_required(VERSION 2.8)
- -project(xmrig-amd)
- +
- +project(xrig)
- option(WITH_AEON "CryptoNight-Lite support" ON)
- option(WITH_HTTPD "HTTP REST API" ON)
- @@ -8,7 +9,9 @@ include (CheckIncludeFile)
- set(HEADERS
- + src/3rdparty/align.h
- src/amd/cryptonight.h
- + src/amd/Adl.h
- src/amd/GpuContext.h
- src/amd/OclCLI.h
- src/amd/OclGPU.h
- @@ -29,8 +32,8 @@ set(HEADERS
- src/log/FileLog.h
- src/log/Log.h
- src/net/Client.h
- - src/net/Id.h
- src/net/Job.h
- + src/net/JobId.h
- src/net/JobResult.h
- src/net/Network.h
- src/net/strategies/DonateStrategy.h
- @@ -47,7 +50,6 @@ set(HEADERS
- src/workers/OclThread.h
- src/workers/OclWorker.h
- src/workers/Workers.h
- - src/xmrig.h
- )
- set(HEADERS_CRYPTO
- @@ -84,6 +86,7 @@ set(SOURCES
- src/net/strategies/SinglePoolStrategy.cpp
- src/net/SubmitResult.cpp
- src/net/Url.cpp
- + src/amd/Adl.cpp
- src/amd/OclCLI.cpp
- src/amd/OclGPU.cpp
- src/Options.cpp
- @@ -94,7 +97,7 @@ set(SOURCES
- src/workers/Handle.cpp
- src/workers/Hashrate.cpp
- src/workers/Workers.cpp
- - src/xmrig.cpp
- + src/xrig.cpp
- )
- set(SOURCES_CRYPTO
- @@ -132,7 +135,6 @@ else()
- set(EXTRA_LIBS pthread)
- endif()
- -add_definitions(/DXMRIG_AMD_PROJECT)
- add_definitions(/DUNICODE)
- add_definitions(/DXMRIG_NO_LIBCPUID)
- add_definitions(/D__STDC_FORMAT_MACROS)
- @@ -143,6 +145,10 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
- find_package(UV REQUIRED)
- +if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
- + set(CMAKE_BUILD_TYPE Release)
- +endif()
- +
- include(cmake/flags.cmake)
- include(cmake/OpenCL.cmake)
- diff --git a/Dockerfile b/Dockerfile
- new file mode 100644
- index 0000000..e199a7b
- --- /dev/null
- +++ b/Dockerfile
- @@ -0,0 +1,15 @@
- +FROM ubuntu:xenial
- +
- +# Install utilities
- +RUN apt-get update --fix-missing && apt-get -y upgrade &&\
- +apt-get install -y build-essential cmake ocl-icd-opencl-dev libuv1-dev libmicrohttpd-dev
- +
- +# Copy files
- +COPY src /src/
- +COPY res /res/
- +COPY cmake /cmake/
- +COPY build.sh /
- +COPY CMakeLists.txt /
- +RUN chmod +x build.sh
- +
- +RUN sh build.sh
- diff --git a/README.md b/README.md
- index 7bb62e6..aa1dcc1 100644
- --- a/README.md
- +++ b/README.md
- @@ -1,94 +1,216 @@
- -# XMRig AMD
- +| Platform | Build Status |
- +| --- | --- |
- +| Linux | [![Build Status](https://travis-ci.org/arnesson/xrig.svg?branch=master)](https://travis-ci.org/arnesson/xrig) |
- +| Win64 | [![Build Status](https://ci.appveyor.com/api/projects/status/github/arnesson/xrig?branch=master&svg=true)](https://ci.appveyor.com/project/arnesson/xrig) |
- -:warning: **You must update miners to version 2.5 before April 6 due [Monero PoW change](https://getmonero.org/2018/02/11/PoW-change-and-key-reuse.html).**
- -[![Github All Releases](https://img.shields.io/github/downloads/xmrig/xmrig-amd/total.svg)](https://github.com/xmrig/xmrig-amd/releases)
- -[![GitHub release](https://img.shields.io/github/release/xmrig/xmrig-amd/all.svg)](https://github.com/xmrig/xmrig-amd/releases)
- -[![GitHub Release Date](https://img.shields.io/github/release-date-pre/xmrig/xmrig-amd.svg)](https://github.com/xmrig/xmrig-amd/releases)
- -[![GitHub license](https://img.shields.io/github/license/xmrig/xmrig-amd.svg)](https://github.com/xmrig/xmrig-amd/blob/master/LICENSE)
- -[![GitHub stars](https://img.shields.io/github/stars/xmrig/xmrig-amd.svg)](https://github.com/xmrig/xmrig-amd/stargazers)
- -[![GitHub forks](https://img.shields.io/github/forks/xmrig/xmrig-amd.svg)](https://github.com/xmrig/xmrig-amd/network)
- -
- -XMRig is high performance Monero (XMR) OpenCL miner, with the official full Windows support.
- -
- -GPU mining part based on [Wolf9466](https://github.com/OhGodAPet) and [psychocrypt](https://github.com/psychocrypt) code.
- -
- -* This is the AMD (OpenCL) GPU mining version, there is also a [CPU version](https://github.com/xmrig/xmrig) and [NVIDIA GPU version](https://github.com/xmrig/xmrig-nvidia).
- -* [Roadmap](https://github.com/xmrig/xmrig/issues/106) for next releases.
- -
- -:warning: Suggested values for GPU auto configuration can be not optimal or not working, you may need tweak your threads options. Please fell free open an [issue](https://github.com/xmrig/xmrig-amd/issues) if auto configuration suggest wrong values.
- +# Xrig
- +Xrig is a high performance cryptonight miner for AMD cards. Designed for large-scale use of RX Vega.
- +GPU mining based on [Wolf9466](https://github.com/OhGodAPet) and [psychocrypt](https://github.com/psychocrypt) code. Forked with love from [XMRig AMD](https://github.com/xmrig/xmrig-amd).
- +<!--
- <img src="https://i.imgur.com/TFncsi7.png" width="696" >
- -
- -#### Table of contents
- -* [Features](#features)
- -* [Download](#download)
- -* [Usage](#usage)
- -* [Build](https://github.com/xmrig/xmrig-amd/wiki/Build)
- -* [Donations](#donations)
- -* [Release checksums](#release-checksums)
- -* [Contacts](#contacts)
- -
- +-->
- ## Features
- -* High performance.
- -* Official Windows support.
- -* Support for backup (failover) mining server.
- -* CryptoNight-Lite support for AEON.
- -* Automatic GPU configuration.
- -* Nicehash support.
- -* It's open source software.
- -
- -## Download
- -* Binary releases: https://github.com/xmrig/xmrig-amd/releases
- -* Git tree: https://github.com/xmrig/xmrig-amd.git
- - * Clone with `git clone https://github.com/xmrig/xmrig-amd.git` :hammer: [Build instructions](https://github.com/xmrig/xmrig-amd/wiki/Build).
- +* CryptoNightV7 ready
- +* High performance
- +* Designed for large-scale use of RX Vega, but will run any AMD card
- +* High level of automation necessary for managing many cards
- +* Rich API
- +* Hardware monitoring (fans, temperature, clock speeds, performance levels)
- +* OverdriveN capabilities (set your under/overclock profile in config.json - replaces Wattman and OverdriveNTool)
- +* Fixes the different shenanigans of mining on the Vega's (e.g. the "underclock toggle" and gpu reset)
- +* Windows and Linux support
- +* Pre-compiled binary has 1% dev donation (donation runs at start rather than after x minutes)
- +
- +## Work-in-progress
- +* Faster OpenCL compile time (cut startup time in half)
- +* Option(s) for automatic fine-tuning of each individual card during mining. This should maximize the utilization of each card and increase the hashrate over time
- ## Usage
- -Use [config.xmrig.com](https://config.xmrig.com/amd) to generate, edit or share configurations.
- ### Command line options
- ```
- -a, --algo=ALGO cryptonight (default) or cryptonight-lite
- -o, --url=URL URL of mining server
- - -O, --userpass=U:P username:password pair for mining server
- -u, --user=USERNAME username for mining server
- -p, --pass=PASSWORD password for mining server
- - -k, --keepalive send keepalived for prevent timeout (need pool support)
- - -r, --retries=N number of times to retry before switch to backup server (default: 5)
- - -R, --retry-pause=N time to pause between retries (default: 5)
- - --opencl-devices=N list of OpenCL devices to use.
- - --opencl-launch=IxW list of launch config, intensity and worksize
- - --opencl-affinity=N affine GPU threads to a CPU
- - --opencl-platform=N OpenCL platform index
- - --no-color disable colored output
- - --donate-level=N donate level, default 5% (5 minutes in 100 minutes)
- - --user-agent set custom user-agent string for pool
- - -B, --background run the miner in the background
- + --variant=N PoW variant (defaults to -1 = automatic)
- + -k, --keepalive send keepalive to prevent timeout (needs pool support)
- + --intensity=N thread intensity
- + --platform-index=N OpenCL platform index
- + --colors enable colored output
- + -b, --background run the miner in the background
- -c, --config=FILE load a JSON-format configuration file
- - -l, --log-file=FILE log all output to a file
- + -l, --log=FILE log all output to a file
- --nicehash enable nicehash support
- - --print-time=N print hashrate report every N seconds
- - --api-port=N port for the miner API
- - --api-access-token=T access token for API
- - --api-worker-id=ID custom worker-id for API
- + --port=N port for the miner API
- + --token=T access token for API
- + --id=ID miner id (defaults to machine name)
- -h, --help display this help and exit
- - -V, --version output version information and exit
- + -v, --version output version information and exit
- ```
- -## Donations
- -Default donation 5% (5 minutes in 100 minutes) can be reduced to 1% via command line option `--donate-level`.
- -
- -* XMR: `48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD`
- -* BTC: `1P7ujsXeX7GxQwHNnJsRMgAdNkFZmNVqJT`
- -
- -## Release checksums
- -### SHA-256
- +### Config file
- +Sample config for an array of Vega's:
- +```js
- +{
- + "algo": "cryptonight",
- + "intensity": 1932,
- + "platform_index": 0,
- + "pools": [
- + {
- + "url": "pool.monero.hashvault.pro:5555",
- + "user": "",
- + "pass": "x"
- + }
- + ],
- + "api": {
- + "port": 4444
- + },
- + "profile": {
- + "system": [
- + {"clock": 852, "vddc": 0.9},
- + {"clock": 991, "vddc": 0.9},
- + {"clock": 1084, "vddc": 0.9},
- + {"clock": 1138, "vddc": 0.9},
- + {"clock": 1150, "vddc": 0.9},
- + {"clock": 1202, "vddc": 0.9},
- + {"clock": 1350, "vddc": 0.8},
- + {"clock": 1350, "vddc": 0.8}
- + ],
- + "memory": [
- + {"clock": 167, "vddc": 0.8},
- + {"clock": 500, "vddc": 0.8},
- + {"clock": 700, "vddc": 0.9},
- + {"clock": 950, "vddc": 0.9}
- + ],
- + "target_temperature": 75,
- + "power_limit": 0
- + }
- +}
- ```
- -9587e92b84b28417427d3e3740c61ea12d86291264caf1c4634704211c030713 xmrig-amd-2.5.2-win32.zip/xmrig-amd.exe
- -f8f1d869e508a24188531f507f0b9f3552accc55d05ef44ee63a98184eb51f26 xmrig-amd-2.5.2-win64.zip/xmrig-amd.exe
- -4ffee947278e7cf5b1fc600d54984cf116cb59658329ef98c341b543770c3389 xmrig-amd-2.5.2-debug-win64/xmrig-amd.exe
- +Note: to change all P-states you need to have a soft powerplaytable for all cards in your registry.
- +
- +You can also configure the threads manually as usual:
- +```js
- +{
- + "algo": "cryptonight",
- + "platform_index": 0,
- + "pools": [
- + {
- + "url": "pool.monero.hashvault.pro:5555",
- + "user": "",
- + "pass": "x"
- + }
- + ],
- + "api": {
- + "port": 4444
- + },
- + "threads": [
- + {"index": 0, "intensity": 1932},
- + {"index": 0, "intensity": 1932}
- + ],
- + "profile": {
- + // ...
- + }
- +}
- ```
- -## Contacts
- -* support@xmrig.com
- -* [reddit](https://www.reddit.com/user/XMRig/)
- +### Rich API in JSON format
- +
- +Example output:
- +```js
- +{
- + "id": "DESKTOP-TEST",
- + "version": "Xrig/0.8.0 (Windows NT 10.0; Win64; x64) libuv/1.14.1 OpenCL/2.0 libmicrohttpd/0.9.58 msvc/2017",
- + "algo": "cryptonight",
- + "uptime": 14729.0,
- + "hashrate_10s": 11454.67,
- + "hashrate_60s": 11456.87,
- + "hashrate_15m": 11451.38,
- + "hashrate_max": 11482.48,
- + "gpus": [
- + {
- + "bus_id": 9,
- + "adapter_index": 23,
- + "device_name": "687F:C3",
- + "temperature": 74,
- + "core_clock": 1350,
- + "memory_clock": 950,
- + "fan_speed": 1934,
- + "profile": {
- + "system": [
- + {"clock": 852, "vddc": 0.9},
- + {"clock": 991, "vddc": 0.9},
- + {"clock": 1084, "vddc": 0.9},
- + {"clock": 1138, "vddc": 0.9},
- + {"clock": 1150, "vddc": 0.9},
- + {"clock": 1202, "vddc": 0.9},
- + {"clock": 1350, "vddc": 0.8},
- + {"clock": 1350, "vddc": 0.8}
- + ],
- + "memory": [
- + {"clock": 167, "vddc": 0.8},
- + {"clock": 500, "vddc": 0.8},
- + {"clock": 700, "vddc": 0.9},
- + {"clock": 950, "vddc": 0.9}
- + ],
- + "target_temperature": 75,
- + "power_limit": 0
- + },
- + "threads": [
- + {
- + "intensity": 1928,
- + "hashrate_10s": 951.86,
- + "hashrate_60s": 951.31,
- + "hashrate_15m": 949.24
- + },
- + {
- + "intensity": 1928,
- + "hashrate_10s": 951.39,
- + "hashrate_60s": 952.29,
- + "hashrate_15m": 951.5
- + }
- + ],
- + "hashrate_10s": 1903.25,
- + "hashrate_60s": 1903.6,
- + "hashrate_15m": 1900.74
- + },
- + {
- + // ...
- + },
- + {
- + // ...
- + },
- + {
- + // ...
- + },
- + {
- + // ...
- + },
- + {
- + // ...
- + }
- + ],
- + "results": {
- + "diff_current": 526795,
- + "shares_good": 308,
- + "shares_total": 321,
- + "avg_time": 48,
- + "hashes_total": 152108212,
- + "best": [
- + // ...
- + ],
- + "error_log": []
- + },
- + "connection": {
- + "pool": "cryptonight.eu.nicehash.com:3355",
- + "user": "******************************xR7M",
- + "uptime": 7056,
- + "ping": 84,
- + "failures": 2,
- + "error_log": []
- + }
- +}
- +```
- diff --git a/appveyor.yml b/appveyor.yml
- new file mode 100644
- index 0000000..71ac4e0
- --- /dev/null
- +++ b/appveyor.yml
- @@ -0,0 +1,48 @@
- +# Inspired by https://github.com/clMathLibraries/clBLAS/blob/master/appveyor.yml
- +version: Build {build}
- +
- +skip_tags: true
- +
- +shallow_clone: true
- +
- +image: Visual Studio 2017
- +
- +platform: x64
- +
- +environment:
- + global:
- + OPENCL_ROOT: "%APPVEYOR_BUILD_FOLDER%\\opencl"
- + OPENCL_REGISTRY: "https://www.khronos.org/registry/cl"
- +
- +init:
- + - C:\"Program Files (x86)"\"Microsoft Visual Studio"\2017\Community\VC\Auxiliary\Build\vcvars64.bat
- +
- +install:
- + - ps: mkdir $env:OPENCL_ROOT
- + - ps: pushd $env:OPENCL_ROOT
- + - ps: $opencl_registry = $env:OPENCL_REGISTRY
- + # This downloads the source to the Khronos ICD library
- + - git clone --depth 1 https://github.com/KhronosGroup/OpenCL-ICD-Loader.git
- + - ps: mv ./OpenCL-ICD-Loader/* .
- + # This downloads all the opencl header files
- + # The cmake build files expect a directory called inc
- + - ps: mkdir inc/CL
- + - git clone --depth 1 https://github.com/KhronosGroup/OpenCL-Headers.git
- + - ps: mv ./OpenCL-Headers/opencl22/CL/* inc/CL
- + - ps: wget $opencl_registry/api/2.1/cl.hpp -OutFile inc/CL/cl.hpp
- + # Create the static import lib in a directory called lib/x86_64, so FindOpencl() will find it
- + - ps: mkdir lib/x86_64
- + - ps: pushd lib/x86_64
- + - cmake -G "NMake Makefiles" ../..
- + - nmake
- + - ps: popd
- + # Create include directory with OpenCL 2.0 headers, so FindOpencl() will find it
- + - ps: mkdir include/CL
- + - ps: mv ./OpenCL-Headers/opencl20/CL/* include/CL
- + - ps: popd
- +
- +before_build:
- + - generate_sln.bat
- +
- +build_script:
- + - build.bat
- diff --git a/build.bat b/build.bat
- new file mode 100644
- index 0000000..efab415
- --- /dev/null
- +++ b/build.bat
- @@ -0,0 +1,26 @@
- +set project_dir=%~dp0
- +set configuration=MinSizeRel
- +call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
- +cd %project_dir%
- +msbuild build\xrig.sln /p:Configuration=%configuration%
- +IF %ERRORLEVEL% NEQ 0 (
- + EXIT /B %ERRORLEVEL%
- +)
- +xcopy libuv-1.14.1-x64\libuv.dll build\%configuration%\ /Y
- +xcopy devcon\devcon.exe build\%configuration%\ /Y
- +(
- +echo @echo off
- +echo cd %%~dp0
- +echo xrig.exe
- +echo pause
- +) > build\%configuration%\run.bat
- +(
- +echo @echo off
- +echo cd %%~dp0
- +echo devcon.exe disable "PCI\VEN_1002&DEV_687F"
- +echo timeout /t 5
- +echo devcon.exe enable "PCI\VEN_1002&DEV_687F"
- +echo timeout /t 5
- +echo xrig.exe
- +echo pause
- +) > build\%configuration%\run_with_reset.bat
- diff --git a/build.sh b/build.sh
- new file mode 100644
- index 0000000..93b9049
- --- /dev/null
- +++ b/build.sh
- @@ -0,0 +1,4 @@
- +mkdir -p build
- +cd build
- +cmake ..
- +make
- diff --git a/cmake/FindMHD.cmake b/cmake/FindMHD.cmake
- index 7a598e0..8505b33 100644
- --- a/cmake/FindMHD.cmake
- +++ b/cmake/FindMHD.cmake
- @@ -8,25 +8,15 @@
- find_path(
- MHD_INCLUDE_DIR
- NAMES microhttpd.h
- - PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS"
- - PATH_SUFFIXES "include"
- DOC "microhttpd include dir"
- - NO_DEFAULT_PATH
- )
- -find_path(MHD_INCLUDE_DIR NAMES microhttpd.h)
- -
- find_library(
- MHD_LIBRARY
- - NAMES libmicrohttpd.a microhttpd libmicrohttpd
- - PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS"
- - PATH_SUFFIXES "lib"
- + NAMES microhttpd microhttpd-10 libmicrohttpd libmicrohttpd-dll
- DOC "microhttpd library"
- - NO_DEFAULT_PATH
- )
- -find_library(MHD_LIBRARY NAMES microhttpd libmicrohttpd)
- -
- set(MHD_INCLUDE_DIRS ${MHD_INCLUDE_DIR})
- set(MHD_LIBRARIES ${MHD_LIBRARY})
- @@ -44,6 +34,6 @@ if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
- endif()
- include(FindPackageHandleStandardArgs)
- -find_package_handle_standard_args(MHD DEFAULT_MSG MHD_LIBRARY MHD_INCLUDE_DIR)
- +find_package_handle_standard_args(mhd DEFAULT_MSG MHD_INCLUDE_DIR MHD_LIBRARY)
- mark_as_advanced(MHD_INCLUDE_DIR MHD_LIBRARY)
- diff --git a/cmake/FindUV.cmake b/cmake/FindUV.cmake
- index ba59d1d..147afdc 100644
- --- a/cmake/FindUV.cmake
- +++ b/cmake/FindUV.cmake
- @@ -1,25 +1,9 @@
- -find_path(
- - UV_INCLUDE_DIR
- - NAMES uv.h
- - PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS"
- - PATH_SUFFIXES "include"
- - NO_DEFAULT_PATH
- -)
- -
- find_path(UV_INCLUDE_DIR NAMES uv.h)
- -
- -find_library(
- - UV_LIBRARY
- - NAMES libuv.a uv libuv
- - PATHS "${XMRIG_DEPS}" ENV "XMRIG_DEPS"
- - PATH_SUFFIXES "lib"
- - NO_DEFAULT_PATH
- -)
- -
- -find_library(UV_LIBRARY NAMES libuv.a uv libuv)
- +find_library(UV_LIBRARY NAMES uv libuv)
- set(UV_LIBRARIES ${UV_LIBRARY})
- set(UV_INCLUDE_DIRS ${UV_INCLUDE_DIR})
- include(FindPackageHandleStandardArgs)
- find_package_handle_standard_args(UV DEFAULT_MSG UV_LIBRARY UV_INCLUDE_DIR)
- +
- diff --git a/cmake/flags.cmake b/cmake/flags.cmake
- index 4688f95..22f230a 100644
- --- a/cmake/flags.cmake
- +++ b/cmake/flags.cmake
- @@ -1,11 +1,3 @@
- -if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
- - set(CMAKE_BUILD_TYPE Release)
- -endif()
- -
- -if (CMAKE_BUILD_TYPE STREQUAL "Release")
- - add_definitions(/DNDEBUG)
- -endif()
- -
- set(CMAKE_CXX_STANDARD_REQUIRED ON)
- set(CMAKE_CXX_EXTENSIONS OFF)
- set(CMAKE_CXX_STANDARD 11)
- @@ -22,6 +14,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
- else()
- set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
- + set(LIBS ${LIBS} -ldl)
- endif()
- add_definitions(/D_GNU_SOURCE)
- diff --git a/devcon/devcon.exe b/devcon/devcon.exe
- new file mode 100644
- index 0000000..2143c53
- Binary files /dev/null and b/devcon/devcon.exe differ
- diff --git a/generate_sln.bat b/generate_sln.bat
- new file mode 100755
- index 0000000..3dc0283
- --- /dev/null
- +++ b/generate_sln.bat
- @@ -0,0 +1,10 @@
- +set project_dir=%~dp0
- +rd /s /q "build"
- +mkdir build
- +cd build
- +cmake .. -G "Visual Studio 15 2017 Win64" -DUV_INCLUDE_DIR="..\libuv-1.14.1-x64\include" -DUV_LIBRARY="..\libuv-1.14.1-x64\libuv.lib" -DMHD_INCLUDE_DIR="..\libmicrohttpd-0.9.58-w32-bin\x86_64\VS2017\Release-static" -DMHD_LIBRARY="..\libmicrohttpd-0.9.58-w32-bin\x86_64\VS2017\Release-static\libmicrohttpd.lib"
- +IF %ERRORLEVEL% NEQ 0 (
- + cd %project_dir%
- + EXIT /B %ERRORLEVEL%
- +)
- +cd %project_dir%
- diff --git a/res/app.ico b/res/app.ico
- index 8c3d628..7ab97ba 100644
- Binary files a/res/app.ico and b/res/app.ico differ
- diff --git a/res/app.rc b/res/app.rc
- index aa41334..9c77b53 100644
- --- a/res/app.rc
- +++ b/res/app.rc
- @@ -24,7 +24,7 @@ VS_VERSION_INFO VERSIONINFO
- VALUE "FileDescription", APP_DESC
- VALUE "FileVersion", APP_VERSION
- VALUE "LegalCopyright", APP_COPYRIGHT
- - VALUE "OriginalFilename", "xmrig-nvidia.exe"
- + VALUE "OriginalFilename", "xrig.exe"
- VALUE "ProductName", APP_NAME
- VALUE "ProductVersion", APP_VERSION
- END
- diff --git a/src/3rdparty/align.h b/src/3rdparty/align.h
- new file mode 100644
- index 0000000..b61179b
- --- /dev/null
- +++ b/src/3rdparty/align.h
- @@ -0,0 +1,33 @@
- +/* XMRig
- + * Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
- + * Copyright 2012-2014 pooler <pooler@litecoinpool.org>
- + * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
- + * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
- + * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
- + * Copyright 2016-2017 XMRig <support@xmrig.com>
- + *
- + *
- + * This program is free software: you can redistribute it and/or modify
- + * it under the terms of the GNU General Public License as published by
- + * the Free Software Foundation, either version 3 of the License, or
- + * (at your option) any later version.
- + *
- + * This program is distributed in the hope that it will be useful,
- + * but WITHOUT ANY WARRANTY; without even the implied warranty of
- + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- + * GNU General Public License for more details.
- + *
- + * You should have received a copy of the GNU General Public License
- + * along with this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +
- +#ifndef __ALIGN_H__
- +#define __ALIGN_H__
- +
- +#ifdef _MSC_VER
- +# define VAR_ALIGN(x, decl) __declspec(align(x)) decl
- +#else
- +# define VAR_ALIGN(x, decl) decl __attribute__ ((aligned(x)))
- +#endif
- +
- +#endif /* __ALIGN_H__ */
- diff --git a/src/App.cpp b/src/App.cpp
- index 568593a..0c02bf7 100644
- --- a/src/App.cpp
- +++ b/src/App.cpp
- @@ -76,8 +76,8 @@ App::App(int argc, char **argv) :
- m_console = new Console(this);
- }
- - if (m_options->logFile()) {
- - Log::add(new FileLog(m_options->logFile()));
- + if (m_options->log()) {
- + Log::add(new FileLog(m_options->log()));
- }
- # ifdef HAVE_SYSLOG_H
- @@ -86,7 +86,7 @@ App::App(int argc, char **argv) :
- }
- # endif
- - Platform::init(m_options->userAgent());
- + Platform::init();
- m_network = new Network(m_options);
- @@ -133,7 +133,7 @@ int App::exec()
- # endif
- # ifndef XMRIG_NO_HTTPD
- - m_httpd = new Httpd(m_options->apiPort(), m_options->apiToken());
- + m_httpd = new Httpd(m_options->port(), m_options->accessToken());
- m_httpd->start();
- # endif
- diff --git a/src/App_unix.cpp b/src/App_unix.cpp
- index 5c8c3f6..bffca08 100644
- --- a/src/App_unix.cpp
- +++ b/src/App_unix.cpp
- @@ -4,8 +4,8 @@
- * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
- * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
- * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
- - * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
- - * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
- + * Copyright 2016-2017 XMRig <support@xmrig.com>
- + *
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- @@ -36,8 +36,6 @@
- void App::background()
- {
- - signal(SIGPIPE, SIG_IGN);
- -
- if (!m_options->background()) {
- return;
- }
- diff --git a/src/Options.cpp b/src/Options.cpp
- index 3355cf6..c0b173e 100644
- --- a/src/Options.cpp
- +++ b/src/Options.cpp
- @@ -6,6 +6,7 @@
- * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
- * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
- * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
- +
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- @@ -32,15 +33,14 @@
- # include <getopt.h>
- #endif
- -
- #ifndef XMRIG_NO_HTTPD
- # include <microhttpd.h>
- #endif
- +#include "amd/Adl.h"
- #include "amd/OclGPU.h"
- #include "Cpu.h"
- -#include "donate.h"
- #include "log/Log.h"
- #include "net/Url.h"
- #include "Options.h"
- @@ -52,7 +52,6 @@
- #include "rapidjson/prettywriter.h"
- #include "version.h"
- #include "workers/OclThread.h"
- -#include "xmrig.h"
- #ifndef ARRAY_SIZE
- @@ -69,87 +68,63 @@ Usage: " APP_ID " [OPTIONS]\n\
- Options:\n\
- -a, --algo=ALGO cryptonight (default) or cryptonight-lite\n\
- -o, --url=URL URL of mining server\n\
- - -O, --userpass=U:P username:password pair for mining server\n\
- -u, --user=USERNAME username for mining server\n\
- -p, --pass=PASSWORD password for mining server\n\
- - -k, --keepalive send keepalived for prevent timeout (need pool support)\n\
- - -r, --retries=N number of times to retry before switch to backup server (default: 5)\n\
- - -R, --retry-pause=N time to pause between retries (default: 5)\n\
- - --opencl-devices=N list of OpenCL devices to use.\n\
- - --opencl-launch=IxW list of launch config, intensity and worksize\n\
- - --opencl-affinity=N affine GPU threads to a CPU\n\
- - --opencl-platform=N OpenCL platform index\n\
- - --print-platforms print available OpenCL platforms and exit\n\
- - --no-color disable colored output\n\
- - --variant algorithm PoW variant\n\
- - --donate-level=N donate level, default 5%% (5 minutes in 100 minutes)\n\
- - --user-agent set custom user-agent string for pool\n\
- - -B, --background run the miner in the background\n\
- + --variant=N PoW variant (defaults to -1 = automatic)\n\
- + -k, --keepalive send keepalive to prevent timeout (needs pool support)\n\
- + --intensity=N thread intensity\n\
- + --platform-index=N OpenCL platform index\n\
- + -b, --background run the miner in the background\n\
- -c, --config=FILE load a JSON-format configuration file\n\
- - -l, --log-file=FILE log all output to a file\n"
- + -l, --log=FILE log all output to a file\n"
- # ifdef HAVE_SYSLOG_H
- "\
- - -S, --syslog use system log for output messages\n"
- + -s, --syslog use system log for output messages\n"
- # endif
- "\
- --nicehash enable nicehash support\n\
- - --print-time=N print hashrate report every N seconds\n\
- - --api-port=N port for the miner API\n\
- - --api-access-token=T access token for API\n\
- - --api-worker-id=ID custom worker-id for API\n\
- + --port=N port for the miner API\n\
- + --token=T access token for API\n\
- + --id=ID miner id (defaults to machine name)\n\
- -h, --help display this help and exit\n\
- - -V, --version output version information and exit\n\
- + -v, --version output version information and exit\n\
- ";
- -static char const short_options[] = "a:c:khBp:Px:r:R:s:T:o:u:O:Vl:S";
- +static char const short_options[] = "a:c:khbp:o:u:vl:s";
- static struct option const options[] = {
- { "algo", 1, nullptr, 'a' },
- - { "api-access-token", 1, nullptr, 4001 },
- - { "api-port", 1, nullptr, 4000 },
- - { "api-worker-id", 1, nullptr, 4002 },
- - { "background", 0, nullptr, 'B' },
- + { "token", 1, nullptr, 4001 },
- + { "port", 1, nullptr, 4000 },
- + { "id", 1, nullptr, 4002 },
- + { "background", 0, nullptr, 'b' },
- { "config", 1, nullptr, 'c' },
- - { "donate-level", 1, nullptr, 1003 },
- { "help", 0, nullptr, 'h' },
- { "keepalive", 0, nullptr ,'k' },
- - { "log-file", 1, nullptr, 'l' },
- + { "log", 1, nullptr, 'l' },
- { "nicehash", 0, nullptr, 1006 },
- { "no-color", 0, nullptr, 1002 },
- { "variant", 1, nullptr, 1010 },
- - { "opencl-affinity", 1, nullptr, 1401 },
- - { "opencl-devices", 1, nullptr, 1402 },
- - { "opencl-launch", 1, nullptr, 1403 },
- - { "opencl-platform", 1, nullptr, 1400 },
- + { "intensity", 1, nullptr, 1401 },
- + { "platform-index", 1, nullptr, 1400 },
- { "pass", 1, nullptr, 'p' },
- - { "print-platforms", 0, nullptr, 1404 },
- - { "print-time", 1, nullptr, 1007 },
- - { "retries", 1, nullptr, 'r' },
- - { "retry-pause", 1, nullptr, 'R' },
- - { "syslog", 0, nullptr, 'S' },
- + { "syslog", 0, nullptr, 's' },
- { "url", 1, nullptr, 'o' },
- { "user", 1, nullptr, 'u' },
- - { "user-agent", 1, nullptr, 1008 },
- - { "userpass", 1, nullptr, 'O' },
- - { "version", 0, nullptr, 'V' },
- + { "version", 0, nullptr, 'v' },
- { 0, 0, 0, 0 }
- };
- static struct option const config_options[] = {
- { "algo", 1, nullptr, 'a' },
- - { "background", 0, nullptr, 'B' },
- - { "colors", 0, nullptr, 2000 },
- - { "donate-level", 1, nullptr, 1003 },
- - { "log-file", 1, nullptr, 'l' },
- - { "opencl-platform", 1, nullptr, 1400 },
- - { "print-time", 1, nullptr, 1007 },
- - { "retries", 1, nullptr, 'r' },
- - { "retry-pause", 1, nullptr, 'R' },
- - { "syslog", 0, nullptr, 'S' },
- - { "user-agent", 1, nullptr, 1008 },
- + { "background", 0, nullptr, 'b' },
- + { "log", 1, nullptr, 'l' },
- + { "platform_index", 1, nullptr, 1400 },
- + { "intensity", 1, nullptr, 1401 },
- + { "syslog", 0, nullptr, 's' },
- { 0, 0, 0, 0 }
- };
- @@ -158,7 +133,6 @@ static struct option const pool_options[] = {
- { "url", 1, nullptr, 'o' },
- { "pass", 1, nullptr, 'p' },
- { "user", 1, nullptr, 'u' },
- - { "userpass", 1, nullptr, 'O' },
- { "keepalive", 0, nullptr ,'k' },
- { "nicehash", 0, nullptr, 1006 },
- { "variant", 1, nullptr, 1010 },
- @@ -168,8 +142,16 @@ static struct option const pool_options[] = {
- static struct option const api_options[] = {
- { "port", 1, nullptr, 4000 },
- - { "access-token", 1, nullptr, 4001 },
- - { "worker-id", 1, nullptr, 4002 },
- + { "token", 1, nullptr, 4001 },
- + { "id", 1, nullptr, 4002 },
- + { 0, 0, 0, 0 }
- +};
- +
- +static struct option const profile_options[] = {
- + { "system", 1, nullptr, 5000 },
- + { "memory", 1, nullptr, 5001 },
- + { "target_temperature", 1, nullptr, 5002 },
- + { "power_limit", 1, nullptr, 5003 },
- { 0, 0, 0, 0 }
- };
- @@ -197,110 +179,16 @@ Options *Options::parse(int argc, char **argv)
- bool Options::oclInit()
- {
- - LOG_WARN("compiling code and initializing GPUs. This will take a while...");
- + LOG_WARN("Compiling code and initializing GPUs...");
- if (m_threads.empty() && !m_oclCLI.setup(m_threads)) {
- - m_autoConf = true;
- - m_shouldSave = true;
- - m_oclCLI.autoConf(m_threads, &m_platformIndex);
- + m_oclCLI.autoConf(m_threads, &m_platformIndex, &m_intensity);
- }
- return true;
- }
- -bool Options::save()
- -{
- - if (!m_shouldSave || m_configName == nullptr) {
- - return false;
- - }
- -
- - uv_fs_t req;
- - const int fd = uv_fs_open(uv_default_loop(), &req, m_configName, O_WRONLY | O_CREAT | O_TRUNC, 0644, nullptr);
- - if (fd < 0) {
- - return false;
- - }
- -
- - uv_fs_req_cleanup(&req);
- -
- - rapidjson::Document doc;
- - doc.SetObject();
- -
- - auto &allocator = doc.GetAllocator();
- -
- - doc.AddMember("algo", rapidjson::StringRef(algoName()), allocator);
- - doc.AddMember("background", m_background, allocator);
- - doc.AddMember("colors", m_colors, allocator);
- - doc.AddMember("donate-level", m_donateLevel, allocator);
- - doc.AddMember("log-file", m_logFile ? rapidjson::Value(rapidjson::StringRef(logFile())).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator);
- - doc.AddMember("print-time", m_printTime, allocator);
- - doc.AddMember("retries", m_retries, allocator);
- - doc.AddMember("retry-pause", m_retryPause, allocator);
- -
- -# ifdef HAVE_SYSLOG_H
- - doc.AddMember("syslog", m_syslog, allocator);
- -# endif
- -
- - doc.AddMember("opencl-platform", m_platformIndex, allocator);
- -
- - rapidjson::Value threads(rapidjson::kArrayType);
- - for (const OclThread *thread : m_threads) {
- - rapidjson::Value obj(rapidjson::kObjectType);
- -
- - obj.AddMember("index", (uint64_t) thread->index(), allocator);
- - obj.AddMember("intensity", (uint64_t) thread->intensity(), allocator);
- - obj.AddMember("worksize", (uint64_t) thread->worksize(), allocator);
- -
- - if (thread->affinity() >= 0) {
- - obj.AddMember("affine_to_cpu", thread->affinity(), allocator);
- - }
- - else {
- - obj.AddMember("affine_to_cpu", false, allocator);
- - }
- -
- - threads.PushBack(obj, allocator);
- - }
- -
- - rapidjson::Value pools(rapidjson::kArrayType);
- -
- - for (const Url *url : m_pools) {
- - rapidjson::Value obj(rapidjson::kObjectType);
- - obj.AddMember("url", rapidjson::StringRef(url->url()), allocator);
- - obj.AddMember("user", rapidjson::StringRef(url->user()), allocator);
- - obj.AddMember("pass", rapidjson::StringRef(url->password()), allocator);
- - obj.AddMember("keepalive", url->isKeepAlive(), allocator);
- - obj.AddMember("nicehash", url->isNicehash(), allocator);
- - obj.AddMember("variant", url->variant(), allocator);
- -
- - pools.PushBack(obj, allocator);
- - }
- -
- - rapidjson::Value api(rapidjson::kObjectType);
- - api.AddMember("port", m_apiPort, allocator);
- - api.AddMember("access-token", m_apiToken ? rapidjson::Value(rapidjson::StringRef(m_apiToken)).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator);
- - api.AddMember("worker-id", m_apiWorkerId ? rapidjson::Value(rapidjson::StringRef(m_apiWorkerId)).Move() : rapidjson::Value(rapidjson::kNullType).Move(), allocator);
- -
- - doc.AddMember("threads", threads, allocator);
- - doc.AddMember("pools", pools, allocator);
- - doc.AddMember("api", api, allocator);
- -
- - FILE *fp = fdopen(fd, "w");
- -
- - char buf[4096];
- - rapidjson::FileWriteStream os(fp, buf, sizeof(buf));
- - rapidjson::PrettyWriter<rapidjson::FileWriteStream> writer(os);
- - doc.Accept(writer);
- -
- - fclose(fp);
- -
- - uv_fs_close(uv_default_loop(), &req, fd, nullptr);
- - uv_fs_req_cleanup(&req);
- -
- - LOG_NOTICE("Configuration saved to: %s", configName());
- - return true;
- -}
- -
- -
- const char *Options::algoName() const
- {
- return algo_names[m_algo];
- @@ -308,26 +196,24 @@ const char *Options::algoName() const
- Options::Options(int argc, char **argv) :
- - m_autoConf(false),
- m_background(false),
- m_colors(true),
- m_ready(false),
- - m_shouldSave(false),
- m_syslog(false),
- - m_apiToken(nullptr),
- - m_apiWorkerId(nullptr),
- - m_configName(nullptr),
- - m_logFile(nullptr),
- - m_userAgent(nullptr),
- + m_accessToken(nullptr),
- + m_id(nullptr),
- + m_config(nullptr),
- + m_log(nullptr),
- m_algo(0),
- m_algoVariant(0),
- - m_apiPort(0),
- - m_donateLevel(kDonateLevel),
- + m_port(0),
- + m_intensity(0),
- m_platformIndex(0),
- - m_printTime(60),
- - m_retries(5),
- - m_retryPause(5),
- - m_threads(0)
- + m_threads(0),
- + m_systemClocks(0),
- + m_memoryClocks(0),
- + m_targetTemperature(0),
- + m_powerLimit(0)
- {
- m_pools.push_back(new Url());
- @@ -350,17 +236,20 @@ Options::Options(int argc, char **argv) :
- }
- if (!m_pools[0]->isValid()) {
- - parseConfig(Platform::defaultConfigName());
- + parseConfig(Platform::defaultConfig());
- }
- if (!m_pools[0]->isValid()) {
- - fprintf(stderr, "No pool URL supplied. Exiting.\n");
- - return;
- + Url *url = new Url("cryptonight.eu.nicehash.com", 3355, "3EXnQ9TLnco6hqjL8S7685YF7mgkaN4LFq", nullptr, false, true);
- + m_pools[0] = url;
- }
- m_algoVariant = Cpu::hasAES() ? AV1_AESNI : AV3_SOFT_AES;
- - adjust();
- + for (Url *url : m_pools) {
- + url->setAlgo(m_algo);
- + url->applyExceptions();
- + }
- m_ready = true;
- }
- @@ -428,12 +317,6 @@ bool Options::parseArg(int key, const char *arg)
- }
- break;
- - case 'O': /* --userpass */
- - if (!m_pools.back()->setUserpass(arg)) {
- - return false;
- - }
- - break;
- -
- case 'u': /* --user */
- m_pools.back()->setUser(arg);
- break;
- @@ -442,56 +325,36 @@ bool Options::parseArg(int key, const char *arg)
- m_pools.back()->setPassword(arg);
- break;
- - case 'l': /* --log-file */
- - free(m_logFile);
- - m_logFile = strdup(arg);
- - m_colors = false;
- - break;
- -
- - case 4001: /* --access-token */
- - free(m_apiToken);
- - m_apiToken = strdup(arg);
- - break;
- -
- - case 4002: /* --worker-id */
- - free(m_apiWorkerId);
- - m_apiWorkerId = strdup(arg);
- + case 'l': /* --log */
- + free(m_log);
- + m_log = strdup(arg);
- break;
- - case 1402: /* --opencl-devices */
- - m_oclCLI.parseDevices(arg);
- + case 4001: /* --token */
- + free(m_accessToken);
- + m_accessToken = strdup(arg);
- break;
- - case 1403: /* --opencl-launch */
- - m_oclCLI.parseLaunch(arg);
- + case 4002: /* --id */
- + free(m_id);
- + m_id = strdup(arg);
- break;
- - case 1401: /* --opencl-affinity */
- - m_oclCLI.parseAffinity(arg);
- - break;
- + case 4000: /* --port */
- + case 1400: /* --platform-index */
- + case 1401: /* --intensity */
- + return parseArg(key, (uint64_t) strtol(arg, nullptr, 10));
- - case 'r': /* --retries */
- - case 'R': /* --retry-pause */
- - case 't': /* --threads */
- - case 'v': /* --av */
- - case 1003: /* --donate-level */
- - case 1007: /* --print-time */
- - case 4000: /* --api-port */
- - case 1400: /* --opencl-platform */
- case 1010: /* --variant */
- - return parseArg(key, strtol(arg, nullptr, 10));
- + return parseArg(key, (int64_t) strtol(arg, nullptr, 10));
- - case 'B': /* --background */
- + case 'b': /* --background */
- case 'k': /* --keepalive */
- - case 'S': /* --syslog */
- - case 1005: /* --safe */
- + case 's': /* --syslog */
- case 1006: /* --nicehash */
- return parseBoolean(key, true);
- - case 1002: /* --no-color */
- - return parseBoolean(key, false);
- -
- - case 'V': /* --version */
- + case 'v': /* --version */
- showVersion();
- return false;
- @@ -499,19 +362,10 @@ bool Options::parseArg(int key, const char *arg)
- showUsage(0);
- return false;
- - case 1404: /* --print-platforms */
- - printPlatforms();
- - return false;
- -
- case 'c': /* --config */
- parseConfig(arg);
- break;
- - case 1008: /* --user-agent */
- - free(m_userAgent);
- - m_userAgent = strdup(arg);
- - break;
- -
- default:
- showUsage(1);
- return false;
- @@ -524,64 +378,28 @@ bool Options::parseArg(int key, const char *arg)
- bool Options::parseArg(int key, uint64_t arg)
- {
- switch (key) {
- - case 'r': /* --retries */
- - if (arg < 1 || arg > 1000) {
- - showUsage(1);
- - return false;
- - }
- -
- - m_retries = (int) arg;
- - break;
- -
- - case 'R': /* --retry-pause */
- - if (arg < 1 || arg > 3600) {
- - showUsage(1);
- - return false;
- - }
- -
- - m_retryPause = (int) arg;
- - break;
- -
- - case 't': /* --threads */
- - if (arg < 1 || arg > 1024) {
- - showUsage(1);
- - return false;
- - }
- -
- - //m_threads = arg;
- - break;
- -
- - case 1003: /* --donate-level */
- - if (arg < 1 || arg > 99) {
- - return true;
- - }
- -
- - m_donateLevel = (int) arg;
- - break;
- -
- - case 1007: /* --print-time */
- - if (arg > 1000) {
- - showUsage(1);
- - return false;
- - }
- -
- - m_printTime = (int) arg;
- - break;
- -
- case 1010: /* --variant */
- m_pools.back()->setVariant((int) arg);
- break;
- - case 1400: /* --opencl-platform */
- + case 1400: /* --platform-index */
- m_platformIndex = (int) arg;
- break;
- - case 4000: /* --api-port */
- + case 1401: /* --intensity */
- + m_intensity = (size_t) arg;
- + break;
- +
- + case 4000: /* --port */
- if (arg <= 65536) {
- - m_apiPort = (int) arg;
- + m_port = (int) arg;
- }
- break;
- + case 5002: /* profile.target_temperature */
- + m_targetTemperature = (int) arg;
- + break;
- +
- default:
- break;
- }
- @@ -590,6 +408,21 @@ bool Options::parseArg(int key, uint64_t arg)
- }
- +bool Options::parseArg(int key, int64_t arg)
- +{
- + switch (key) {
- + case 5003: /* profile.power_limit */
- + m_powerLimit = (int)arg;
- + break;
- +
- + default:
- + break;
- + }
- +
- + return true;
- +}
- +
- +
- bool Options::parseBoolean(int key, bool enable)
- {
- switch (key) {
- @@ -597,28 +430,18 @@ bool Options::parseBoolean(int key, bool enable)
- m_pools.back()->setKeepAlive(enable);
- break;
- - case 'B': /* --background */
- + case 'b': /* --background */
- m_background = enable;
- - m_colors = enable ? false : m_colors;
- break;
- - case 'S': /* --syslog */
- + case 's': /* --syslog */
- m_syslog = enable;
- - m_colors = enable ? false : m_colors;
- - break;
- -
- - case 1002: /* --no-color */
- - m_colors = enable;
- break;
- case 1006: /* --nicehash */
- m_pools.back()->setNicehash(enable);
- break;
- - case 2000: /* colors */
- - m_colors = enable;
- - break;
- -
- default:
- break;
- }
- @@ -639,14 +462,6 @@ Url *Options::parseUrl(const char *arg) const
- }
- -void Options::adjust()
- -{
- - for (Url *url : m_pools) {
- - url->adjust(m_algo);
- - }
- -}
- -
- -
- void Options::parseConfig(const char *fileName)
- {
- rapidjson::Document doc;
- @@ -654,7 +469,7 @@ void Options::parseConfig(const char *fileName)
- return;
- }
- - m_configName = strdup(fileName);
- + m_config = strdup(fileName);
- for (size_t i = 0; i < ARRAY_SIZE(config_options); i++) {
- parseJSON(&config_options[i], doc);
- @@ -674,7 +489,7 @@ void Options::parseConfig(const char *fileName)
- }
- const rapidjson::Value &threads = doc["threads"];
- - if (pools.IsArray()) {
- + if (threads.IsArray()) {
- for (const rapidjson::Value &value : threads.GetArray()) {
- if (!value.IsObject()) {
- continue;
- @@ -690,6 +505,45 @@ void Options::parseConfig(const char *fileName)
- parseJSON(&api_options[i], api);
- }
- }
- +
- + const rapidjson::Value &profile = doc["profile"];
- + if (profile.IsObject()) {
- + for (size_t i = 0; i < ARRAY_SIZE(profile_options); i++) {
- + parseProfile(&profile_options[i], profile);
- + }
- + }
- +}
- +
- +
- +void Options::parseProfile(const struct option *option, const rapidjson::Value &object)
- +{
- + if (!option->name || !object.HasMember(option->name)) {
- + return;
- + }
- +
- + const rapidjson::Value &value = object[option->name];
- +
- + if (option->has_arg && value.IsArray()) {
- + for (const rapidjson::Value &level : value.GetArray()) {
- + if (!level.IsObject()) {
- + continue;
- + }
- +
- + parseLevel(option->val, level);
- + }
- + }
- + else if (option->has_arg && value.IsString()) {
- + parseArg(option->val, value.GetString());
- + }
- + else if (option->has_arg && value.IsUint64()) {
- + parseArg(option->val, value.GetUint64());
- + }
- + else if (option->has_arg && value.IsInt64()) {
- + parseArg(option->val, value.GetInt64());
- + }
- + else if (!option->has_arg && value.IsBool()) {
- + parseBoolean(option->val, value.IsTrue());
- + }
- }
- @@ -704,21 +558,61 @@ void Options::parseJSON(const struct option *option, const rapidjson::Value &obj
- if (option->has_arg && value.IsString()) {
- parseArg(option->val, value.GetString());
- }
- - else if (option->has_arg && value.IsInt64()) {
- + else if (option->has_arg && value.IsUint64()) {
- parseArg(option->val, value.GetUint64());
- }
- + else if (option->has_arg && value.IsInt64()) {
- + parseArg(option->val, value.GetInt64());
- + }
- else if (!option->has_arg && value.IsBool()) {
- parseBoolean(option->val, value.IsTrue());
- }
- }
- +void Options::parseLevel(int key, const rapidjson::Value &object)
- +{
- + ADLODNPerformanceLevelX2 *odNPerformanceLevel = new ADLODNPerformanceLevelX2();
- +
- + const rapidjson::Value &clock = object["clock"];
- + if (clock.IsInt()) {
- + odNPerformanceLevel->iClock = clock.GetInt() * 100;
- + }
- +
- + const rapidjson::Value &vddc = object["vddc"];
- + if (vddc.IsDouble()) {
- + odNPerformanceLevel->iVddc = (int) (vddc.GetDouble() * 1000);
- + }
- +
- + switch (key) {
- + case 5000: /* profile.system */
- + m_systemClocks.push_back(odNPerformanceLevel);
- + break;
- +
- + case 5001: /* profile.memory */
- + m_memoryClocks.push_back(odNPerformanceLevel);
- + break;
- +
- + default:
- + break;
- + }
- +}
- +
- +
- void Options::parseThread(const rapidjson::Value &object)
- {
- OclThread *thread = new OclThread();
- thread->setIndex(object["index"].GetInt());
- - thread->setIntensity(object["intensity"].GetUint());
- - thread->setWorksize(object["worksize"].GetUint());
- +
- + const rapidjson::Value &intensity = object["intensity"];
- + if (intensity.IsUint()) {
- + thread->setRawIntensity(intensity.GetUint());
- + }
- +
- + const rapidjson::Value &worksize = object["worksize"];
- + if (worksize.IsUint()) {
- + thread->setWorksize(worksize.GetUint());
- + }
- const rapidjson::Value &affinity = object["affine_to_cpu"];
- if (affinity.IsInt()) {
- @@ -729,7 +623,6 @@ void Options::parseThread(const rapidjson::Value &object)
- }
- -
- void Options::showUsage(int status) const
- {
- if (status) {
- @@ -743,37 +636,7 @@ void Options::showUsage(int status) const
- void Options::showVersion()
- {
- - printf(APP_NAME " " APP_VERSION "\n built on " __DATE__
- -
- -# if defined(__clang__)
- - " with clang " __clang_version__);
- -# elif defined(__GNUC__)
- - " with GCC");
- - printf(" %d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
- -# elif defined(_MSC_VER)
- - " with MSVC");
- - printf(" %d", MSVC_VERSION);
- -# else
- - );
- -# endif
- -
- - printf("\n features:"
- -# if defined(__i386__) || defined(_M_IX86)
- - " i386"
- -# elif defined(__x86_64__) || defined(_M_AMD64)
- - " x86_64"
- -# endif
- -
- -# if defined(__AES__) || defined(_MSC_VER)
- - " AES-NI"
- -# endif
- - "\n");
- -
- - printf("\nlibuv/%s\n", uv_version_string());
- -
- -# ifndef XMRIG_NO_HTTPD
- - printf("libmicrohttpd/%s\n", MHD_get_version());
- -# endif
- + printf("%s\n", Platform::versionString());
- }
- @@ -787,7 +650,7 @@ bool Options::setAlgo(const char *algo)
- # ifndef XMRIG_NO_AEON
- if (i == ARRAY_SIZE(algo_names) - 1 && !strcmp(algo, "cryptonight-light")) {
- - m_algo = xmrig::ALGO_CRYPTONIGHT_LITE;
- + m_algo = ALGO_CRYPTONIGHT_LITE;
- break;
- }
- # endif
- diff --git a/src/Options.h b/src/Options.h
- index defee60..be80562 100644
- --- a/src/Options.h
- +++ b/src/Options.h
- @@ -6,6 +6,7 @@
- * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
- * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
- * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
- +
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- @@ -29,6 +30,7 @@
- #include <vector>
- +#include "amd/Adl.h"
- #include "amd/OclCLI.h"
- #include "rapidjson/fwd.h"
- @@ -37,10 +39,20 @@ class OclThread;
- class Url;
- struct option;
- -
- class Options
- {
- public:
- + enum Algo {
- + ALGO_CRYPTONIGHT, /* CryptoNight (Monero) */
- + ALGO_CRYPTONIGHT_LITE, /* CryptoNight-Lite (AEON) */
- + };
- +
- + enum Variant {
- + VARIANT_AUTO = -1,
- + VARIANT_NONE = 0,
- + VARIANT_V1 = 1
- + };
- +
- enum AlgoVariant {
- AV0_AUTO,
- AV1_AESNI,
- @@ -55,29 +67,30 @@ public:
- inline bool background() const { return m_background; }
- inline bool colors() const { return m_colors; }
- - inline bool isAutoConf() const { return m_autoConf; }
- inline bool syslog() const { return m_syslog; }
- - inline const char *apiToken() const { return m_apiToken; }
- - inline const char *apiWorkerId() const { return m_apiWorkerId; }
- - inline const char *configName() const { return m_configName; }
- - inline const char *logFile() const { return m_logFile; }
- - inline const char *userAgent() const { return m_userAgent; }
- + inline const char *accessToken() const { return m_accessToken; }
- + inline const char *id() const { return m_id; }
- + inline const char *log() const { return m_log; }
- inline const std::vector<OclThread*> &threads() const { return m_threads; }
- inline const std::vector<Url*> &pools() const { return m_pools; }
- inline int algo() const { return m_algo; }
- inline int algoVariant() const { return m_algoVariant; }
- - inline int apiPort() const { return m_apiPort; }
- - inline int donateLevel() const { return m_donateLevel; }
- + inline int port() const { return m_port; }
- + inline size_t intensity() const { return m_intensity; }
- inline int platformIndex() const { return m_platformIndex; }
- - inline int printTime() const { return m_printTime; }
- - inline int retries() const { return m_retries; }
- - inline int retryPause() const { return m_retryPause; }
- + inline int printTime() const { return 60; }
- + inline int retries() const { return 5; }
- + inline int retryPause() const { return 5; }
- inline void setColors(bool colors) { m_colors = colors; }
- + inline const std::vector<ADLODNPerformanceLevelX2*> &systemClocks() const { return m_systemClocks; }
- + inline const std::vector<ADLODNPerformanceLevelX2*> &memoryClocks() const { return m_memoryClocks; }
- + inline int targetTemperature() const { return m_targetTemperature; }
- + inline int powerLimit() const { return m_powerLimit; }
- inline static void release() { delete m_self; }
- bool oclInit();
- - bool save();
- +
- const char *algoName() const;
- private:
- @@ -91,39 +104,39 @@ private:
- bool getJSON(const char *fileName, rapidjson::Document &doc);
- bool parseArg(int key, const char *arg);
- bool parseArg(int key, uint64_t arg);
- + bool parseArg(int key, int64_t arg);
- bool parseBoolean(int key, bool enable);
- Url *parseUrl(const char *arg) const;
- - void adjust();
- void parseConfig(const char *fileName);
- + void parseProfile(const struct option *option, const rapidjson::Value &object);
- void parseJSON(const struct option *option, const rapidjson::Value &object);
- + void parseLevel(int key, const rapidjson::Value &object);
- void parseThread(const rapidjson::Value &object);
- void showUsage(int status) const;
- void showVersion(void);
- bool setAlgo(const char *algo);
- - bool m_autoConf;
- bool m_background;
- bool m_colors;
- bool m_ready;
- - bool m_shouldSave;
- bool m_syslog;
- - char *m_apiToken;
- - char *m_apiWorkerId;
- - char *m_configName;
- - char *m_logFile;
- - char *m_userAgent;
- + char *m_accessToken;
- + char *m_id;
- + char *m_config;
- + char *m_log;
- int m_algo;
- int m_algoVariant;
- - int m_apiPort;
- - int m_donateLevel;
- + int m_port;
- + size_t m_intensity;
- int m_platformIndex;
- - int m_printTime;
- - int m_retries;
- - int m_retryPause;
- OclCLI m_oclCLI;
- std::vector<OclThread*> m_threads;
- std::vector<Url*> m_pools;
- + std::vector<ADLODNPerformanceLevelX2*> m_systemClocks;
- + std::vector<ADLODNPerformanceLevelX2*> m_memoryClocks;
- + int m_targetTemperature;
- + int m_powerLimit;
- };
- #endif /* __OPTIONS_H__ */
- diff --git a/src/Platform.cpp b/src/Platform.cpp
- index 4ddb142..c6826c8 100644
- --- a/src/Platform.cpp
- +++ b/src/Platform.cpp
- @@ -29,34 +29,34 @@
- #include "Platform.h"
- -char *Platform::m_defaultConfigName = nullptr;
- -char *Platform::m_userAgent = nullptr;
- +char *Platform::m_defaultConfig = nullptr;
- +char *Platform::m_versionString = nullptr;
- -const char *Platform::defaultConfigName()
- +const char *Platform::defaultConfig()
- {
- size_t size = 520;
- - if (m_defaultConfigName == nullptr) {
- - m_defaultConfigName = new char[size];
- + if (m_defaultConfig == nullptr) {
- + m_defaultConfig = new char[size];
- }
- - if (uv_exepath(m_defaultConfigName, &size) < 0) {
- + if (uv_exepath(m_defaultConfig, &size) < 0) {
- return nullptr;
- }
- if (size < 500) {
- # ifdef WIN32
- - char *p = strrchr(m_defaultConfigName, '\\');
- + char *p = strrchr(m_defaultConfig, '\\');
- # else
- - char *p = strrchr(m_defaultConfigName, '/');
- + char *p = strrchr(m_defaultConfig, '/');
- # endif
- if (p) {
- strcpy(p + 1, "config.json");
- - return m_defaultConfigName;
- + return m_defaultConfig;
- }
- }
- return nullptr;
- -}
- +}
- \ No newline at end of file
- diff --git a/src/Platform.h b/src/Platform.h
- index 4abbba7..92df63d 100644
- --- a/src/Platform.h
- +++ b/src/Platform.h
- @@ -28,19 +28,19 @@
- class Platform
- {
- public:
- - static const char *defaultConfigName();
- - static void init(const char *userAgent);
- + static const char *defaultConfig();
- + static void init();
- static void release();
- static void setProcessPriority(int priority);
- static void setThreadAffinity(uint64_t cpu_id);
- static void setThreadPriority(int priority);
- - static inline const char *userAgent() { return m_userAgent; }
- + static inline const char *versionString() { return m_versionString; }
- private:
- - static char *m_defaultConfigName;
- - static char *m_userAgent;
- + static char *m_defaultConfig;
- + static char *m_versionString;
- };
- -#endif /* __PLATFORM_H__ */
- +#endif /* __PLATFORM_H__ */
- \ No newline at end of file
- diff --git a/src/Platform_mac.cpp b/src/Platform_mac.cpp
- index 61246bc..aa3188f 100644
- --- a/src/Platform_mac.cpp
- +++ b/src/Platform_mac.cpp
- @@ -36,33 +36,56 @@
- # include "nvidia/cryptonight.h"
- #endif
- +#ifndef XMRIG_NO_HTTPD
- +# include <microhttpd.h>
- +#endif
- +
- +#include <OpenCL/cl.h>
- +
- +#if CL_VERSION_2_0
- +# define CL_VERSION_STRING "2.0"
- +#elif CL_VERSION_1_2
- +# define CL_VERSION_STRING "1.2"
- +#elif CL_VERSION_1_1
- +# define CL_VERSION_STRING "1.1"
- +#elif CL_VERSION_1_0
- +# define CL_VERSION_STRING "1.0"
- +#endif
- +
- -static inline char *createUserAgent()
- +
- +static inline char *createVersionString()
- {
- const size_t max = 160;
- char *buf = new char[max];
- + int length = snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s OpenCL/%s", APP_NAME, APP_VERSION, uv_version_string(), CL_VERSION_STRING);
- +
- +# ifndef XMRIG_NO_HTTPD
- + length += snprintf(buf + length, max - length, " libmicrohttpd/%s", MHD_get_version());
- +# endif
- # ifdef XMRIG_NVIDIA_PROJECT
- const int cudaVersion = cuda_get_runtime_version();
- - snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s CUDA/%d.%d clang/%d.%d.%d", APP_NAME, APP_VERSION, uv_version_string(), cudaVersion / 1000, cudaVersion % 100, __clang_major__, __clang_minor__, __clang_patchlevel__);
- -# else
- - snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s clang/%d.%d.%d", APP_NAME, APP_VERSION, uv_version_string(), __clang_major__, __clang_minor__, __clang_patchlevel__);
- + length += snprintf(buf + length, max - length, " CUDA/%d.%d", cudaVersion / 1000, cudaVersion % 100);
- # endif
- + length += snprintf(buf + length, max - length, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__);
- +
- return buf;
- }
- -void Platform::init(const char *userAgent)
- +void Platform::init()
- {
- - m_userAgent = userAgent ? strdup(userAgent) : createUserAgent();
- + m_versionString = createVersionString();
- }
- void Platform::release()
- {
- - delete [] m_userAgent;
- + delete [] m_defaultConfig;
- + delete [] m_versionString;
- }
- @@ -115,4 +138,3 @@ void Platform::setThreadPriority(int priority)
- setpriority(PRIO_PROCESS, 0, prio);
- }
- -
- diff --git a/src/Platform_unix.cpp b/src/Platform_unix.cpp
- index f47b6c4..d62002a 100644
- --- a/src/Platform_unix.cpp
- +++ b/src/Platform_unix.cpp
- @@ -46,13 +46,28 @@
- # include "nvidia/cryptonight.h"
- #endif
- +#ifndef XMRIG_NO_HTTPD
- +# include <microhttpd.h>
- +#endif
- +
- +#include <CL/cl.h>
- +
- +#if CL_VERSION_2_0
- +# define CL_VERSION_STRING "2.0"
- +#elif CL_VERSION_1_2
- +# define CL_VERSION_STRING "1.2"
- +#elif CL_VERSION_1_1
- +# define CL_VERSION_STRING "1.1"
- +#elif CL_VERSION_1_0
- +# define CL_VERSION_STRING "1.0"
- +#endif
- #ifdef __FreeBSD__
- typedef cpuset_t cpu_set_t;
- #endif
- -static inline char *createUserAgent()
- +static inline char *createVersionString()
- {
- const size_t max = 160;
- @@ -60,9 +75,13 @@ static inline char *createUserAgent()
- int length = snprintf(buf, max, "%s/%s (Linux ", APP_NAME, APP_VERSION);
- # if defined(__x86_64__)
- - length += snprintf(buf + length, max - length, "x86_64) libuv/%s", uv_version_string());
- + length += snprintf(buf + length, max - length, "x86_64) libuv/%s OpenCL/%s", uv_version_string(), CL_VERSION_STRING);
- # else
- - length += snprintf(buf + length, max - length, "i686) libuv/%s", uv_version_string());
- + length += snprintf(buf + length, max - length, "i686) libuv/%s OpenCL/%s", uv_version_string(), CL_VERSION_STRING);
- +# endif
- +
- +# ifndef XMRIG_NO_HTTPD
- + length += snprintf(buf + length, max - length, " libmicrohttpd/%s", MHD_get_version());
- # endif
- # ifdef XMRIG_NVIDIA_PROJECT
- @@ -78,15 +97,16 @@ static inline char *createUserAgent()
- }
- -void Platform::init(const char *userAgent)
- +void Platform::init()
- {
- - m_userAgent = userAgent ? strdup(userAgent) : createUserAgent();
- + m_versionString = createVersionString();
- }
- void Platform::release()
- {
- - delete [] m_userAgent;
- + delete [] m_defaultConfig;
- + delete [] m_versionString;
- }
- @@ -149,4 +169,4 @@ void Platform::setThreadPriority(int priority)
- }
- }
- # endif
- -}
- +}
- \ No newline at end of file
- diff --git a/src/Platform_win.cpp b/src/Platform_win.cpp
- index ae12581..2615885 100644
- --- a/src/Platform_win.cpp
- +++ b/src/Platform_win.cpp
- @@ -34,6 +34,37 @@
- # include "nvidia/cryptonight.h"
- #endif
- +#ifndef XMRIG_NO_HTTPD
- +# include <microhttpd.h>
- +#endif
- +
- +#include <CL/cl.h>
- +
- +#if CL_VERSION_2_0
- +# define CL_VERSION_STRING "2.0"
- +#elif CL_VERSION_1_2
- +# define CL_VERSION_STRING "1.2"
- +#elif CL_VERSION_1_1
- +# define CL_VERSION_STRING "1.1"
- +#elif CL_VERSION_1_0
- +# define CL_VERSION_STRING "1.0"
- +#endif
- +
- +#ifdef _MSC_VER
- +# if (_MSC_VER >= 1910)
- +# define MSVC_VERSION 2017
- +# elif _MSC_VER == 1900
- +# define MSVC_VERSION 2015
- +# elif _MSC_VER == 1800
- +# define MSVC_VERSION 2013
- +# elif _MSC_VER == 1700
- +# define MSVC_VERSION 2012
- +# elif _MSC_VER == 1600
- +# define MSVC_VERSION 2010
- +# else
- +# define MSVC_VERSION 0
- +# endif
- +#endif
- static inline OSVERSIONINFOEX winOsVersion()
- {
- @@ -53,7 +84,7 @@ static inline OSVERSIONINFOEX winOsVersion()
- }
- -static inline char *createUserAgent()
- +static inline char *createVersionString()
- {
- const auto osver = winOsVersion();
- const size_t max = 160;
- @@ -62,9 +93,13 @@ static inline char *createUserAgent()
- int length = snprintf(buf, max, "%s/%s (Windows NT %lu.%lu", APP_NAME, APP_VERSION, osver.dwMajorVersion, osver.dwMinorVersion);
- # if defined(__x86_64__) || defined(_M_AMD64)
- - length += snprintf(buf + length, max - length, "; Win64; x64) libuv/%s", uv_version_string());
- + length += snprintf(buf + length, max - length, "; Win64; x64) libuv/%s OpenCL/%s", uv_version_string(), CL_VERSION_STRING);
- # else
- - length += snprintf(buf + length, max - length, ") libuv/%s", uv_version_string());
- + length += snprintf(buf + length, max - length, ") libuv/%s OpenCL/%s", uv_version_string(), CL_VERSION_STRING);
- +# endif
- +
- +# ifndef XMRIG_NO_HTTPD
- + length += snprintf(buf + length, max - length, " libmicrohttpd/%s", MHD_get_version());
- # endif
- # ifdef XMRIG_NVIDIA_PROJECT
- @@ -82,16 +117,16 @@ static inline char *createUserAgent()
- }
- -void Platform::init(const char *userAgent)
- +void Platform::init()
- {
- - m_userAgent = userAgent ? strdup(userAgent) : createUserAgent();
- + m_versionString = createVersionString();
- }
- void Platform::release()
- {
- - delete [] m_defaultConfigName;
- - delete [] m_userAgent;
- + delete [] m_defaultConfig;
- + delete [] m_versionString;
- }
- @@ -172,4 +207,3 @@ void Platform::setThreadPriority(int priority)
- SetThreadPriority(GetCurrentThread(), prio);
- }
- -
- diff --git a/src/Summary.cpp b/src/Summary.cpp
- index 8e7b3ff..affa668 100644
- --- a/src/Summary.cpp
- +++ b/src/Summary.cpp
- @@ -23,54 +23,20 @@
- #include <inttypes.h>
- -#include <uv.h>
- -
- -
- -#if defined(__APPLE__)
- -# include <OpenCL/cl.h>
- -#else
- -# include <CL/cl.h>
- -#endif
- -
- #include "Cpu.h"
- #include "log/Log.h"
- #include "net/Url.h"
- #include "Options.h"
- #include "Summary.h"
- -#include "version.h"
- +#include "Platform.h"
- #include "workers/OclThread.h"
- -static void print_versions()
- +static void print_version()
- {
- - char buf[16];
- -
- -# if defined(__clang__)
- - snprintf(buf, 16, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__);
- -# elif defined(__GNUC__)
- - snprintf(buf, 16, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
- -# elif defined(_MSC_VER)
- - snprintf(buf, 16, " MSVC/%d", MSVC_VERSION);
- -# else
- - buf[0] = '\0';
- -# endif
- -
- -
- -# if CL_VERSION_2_0
- - const char *ocl = "2.0";
- -# elif CL_VERSION_1_2
- - const char *ocl = "1.2";
- -# elif CL_VERSION_1_1
- - const char *ocl = "1.1";
- -# elif CL_VERSION_1_0
- - const char *ocl = "1.0";
- -# else
- - const char *ocl = "0.0";
- -# endif
- -
- - Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mVERSIONS: \x1B[01;36mXMRig/%s\x1B[01;37m libuv/%s OpenCL/%s%s" : " * VERSIONS: XMRig/%s libuv/%s OpenCL/%s%s",
- - APP_VERSION, uv_version_string(), ocl, buf);
- + Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mVERSION: %s" : " * VERSION: %s",
- + Platform::versionString());
- }
- @@ -90,10 +56,8 @@ static void print_cpu()
- static void print_algo()
- {
- - Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mALGO: %s, %sdonate=%d%%" : " * ALGO: %s, %sdonate=%d%%",
- - Options::i()->algoName(),
- - Options::i()->colors() && Options::i()->donateLevel() == 0 ? "\x1B[01;31m" : "",
- - Options::i()->donateLevel()
- + Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mALGO: %s" : " * ALGO: %s",
- + Options::i()->algoName()
- );
- }
- @@ -120,11 +84,11 @@ static void print_pools()
- #ifndef XMRIG_NO_API
- static void print_api()
- {
- - if (Options::i()->apiPort() == 0) {
- + if (Options::i()->port() == 0) {
- return;
- }
- - Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mAPI PORT: \x1B[01;36m%d" : " * API PORT: %d", Options::i()->apiPort());
- + Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mAPI PORT: \x1B[01;36m%d" : " * API PORT: %d", Options::i()->port());
- }
- #endif
- @@ -142,7 +106,7 @@ static void print_commands()
- void Summary::print()
- {
- - print_versions();
- + print_version();
- print_cpu();
- print_algo();
- print_pools();
- @@ -155,4 +119,3 @@ void Summary::print()
- }
- -
- diff --git a/src/amd/GpuContext.h b/src/amd/GpuContext.h
- index 8587b52..fc7f49c 100644
- --- a/src/amd/GpuContext.h
- +++ b/src/amd/GpuContext.h
- @@ -46,28 +46,32 @@ struct GpuContext
- CommandQueues(nullptr),
- InputBuffer(nullptr),
- OutputBuffer(nullptr),
- - ExtraBuffers{ nullptr },
- + ExtraBuffers{nullptr},
- Program(nullptr),
- - Kernels{ nullptr },
- + Kernels{nullptr},
- freeMem(0),
- computeUnits(0),
- + threadId(0),
- + busId(0),
- Nonce(0)
- {}
- - inline GpuContext(size_t index, size_t intensity, size_t worksize) :
- + inline GpuContext(size_t index, size_t rawIntensity, size_t worksize) :
- deviceIdx(index),
- - rawIntensity(intensity),
- + rawIntensity(rawIntensity),
- workSize(worksize),
- DeviceID(nullptr),
- CommandQueues(nullptr),
- InputBuffer(nullptr),
- OutputBuffer(nullptr),
- - ExtraBuffers{ nullptr },
- + ExtraBuffers{nullptr},
- Program(nullptr),
- - Kernels{ nullptr },
- + Kernels{nullptr},
- freeMem(0),
- computeUnits(0),
- + threadId(0),
- + busId(0),
- Nonce(0)
- {}
- @@ -86,7 +90,9 @@ struct GpuContext
- cl_kernel Kernels[7];
- size_t freeMem;
- int computeUnits;
- - std::string name;
- + int threadId;
- + int busId;
- + std::string deviceName;
- uint32_t Nonce;
- };
- diff --git a/src/amd/OclCLI.cpp b/src/amd/OclCLI.cpp
- index 7e47e69..e5b1880 100644
- --- a/src/amd/OclCLI.cpp
- +++ b/src/amd/OclCLI.cpp
- @@ -34,7 +34,6 @@
- #include "log/Log.h"
- #include "Options.h"
- #include "workers/OclThread.h"
- -#include "xmrig.h"
- OclCLI::OclCLI()
- @@ -56,75 +55,42 @@ bool OclCLI::setup(std::vector<OclThread*> &threads)
- }
- -void OclCLI::autoConf(std::vector<OclThread*> &threads, int *platformIndex)
- +void OclCLI::autoConf(std::vector<OclThread*> &threads, int *platformIndex, size_t *intensity)
- {
- *platformIndex = getAMDPlatformIdx();
- if (*platformIndex == -1) {
- - LOG_ERR("No AMD OpenCL platform found. Possible driver issues or wrong vendor driver.");
- + LOG_ERR("No AMD OpenCL platform found");
- return;
- }
- std::vector<GpuContext> devices = getAMDDevices(*platformIndex);
- if (devices.empty()) {
- - LOG_ERR("No AMD device found.");
- + LOG_ERR("No AMD devices found.");
- return;
- }
- constexpr size_t byteToMiB = 1024u * 1024u;
- - const size_t hashMemSize = Options::i()->algo() == xmrig::ALGO_CRYPTONIGHT ? MONERO_MEMORY : AEON_MEMORY;
- + const size_t hashMemSize = Options::i()->algo() == Options::ALGO_CRYPTONIGHT ? MONERO_MEMORY : AEON_MEMORY;
- for (GpuContext &ctx : devices) {
- size_t maxThreads = 1000u;
- - if (ctx.name.compare("gfx901") == 0) {
- + int gpuThreads = 1;
- +
- + // rx vega
- + if (ctx.deviceName.find("687F") == 0 || ctx.deviceName.find("Radeon RX Vega") == 0) {
- maxThreads = 2024u;
- + gpuThreads = 2;
- }
- const size_t availableMem = ctx.freeMem - (128u * byteToMiB);
- const size_t perThread = hashMemSize + 224u;
- - const size_t maxIntensity = availableMem / perThread;
- - const size_t possibleIntensity = std::min(maxThreads, maxIntensity);
- - const size_t intensity = (possibleIntensity / (8 * ctx.computeUnits)) * ctx.computeUnits * 8;
- -
- - threads.push_back(new OclThread(ctx.deviceIdx, intensity, 8));
- - }
- -}
- -
- + const size_t maxIntensity = std::min(maxThreads, availableMem / perThread);
- + const size_t rawIntensity = (maxIntensity / (8 * ctx.computeUnits)) * ctx.computeUnits * 8;
- -void OclCLI::parseLaunch(const char *arg)
- -{
- - char *value = strdup(arg);
- - char *pch = strtok(value, ",");
- - std::vector<char *> tmp;
- -
- - while (pch != nullptr) {
- - tmp.push_back(pch);
- - pch = strtok(nullptr, ",");
- - }
- -
- - for (char *config : tmp) {
- - pch = strtok(config, "x");
- - int count = 0;
- -
- - while (pch != nullptr && count < 2) {
- - count++;
- -
- - const int v = (int) strtoul(pch, nullptr, 10);
- - if (count == 1) {
- - m_intensity.push_back(v > 0 ? v : 0);
- - }
- - else if (count == 2) {
- - m_worksize.push_back(v > 0 ? v : 8);
- - }
- -
- - pch = strtok(nullptr, "x");
- - }
- -
- - if (count == 1) {
- - m_worksize.push_back(8);
- + for (int i = 0; i < gpuThreads; i++) {
- + threads.push_back(new OclThread(ctx.deviceIdx, *intensity ? *intensity : std::min(rawIntensity, maxIntensity), 8));
- }
- }
- -
- - free(value);
- }
- @@ -154,4 +120,4 @@ void OclCLI::parse(std::vector<int> &vector, const char *arg) const
- }
- free(value);
- -}
- +}
- \ No newline at end of file
- diff --git a/src/amd/OclCLI.h b/src/amd/OclCLI.h
- index 4aac45a..6768216 100644
- --- a/src/amd/OclCLI.h
- +++ b/src/amd/OclCLI.h
- @@ -37,11 +37,7 @@ public:
- OclCLI();
- bool setup(std::vector<OclThread*> &threads);
- - void autoConf(std::vector<OclThread*> &threads, int *platformIndex);
- - void parseLaunch(const char *arg);
- -
- - inline void parseAffinity(const char *arg) { parse(m_affinity, arg); }
- - inline void parseDevices(const char *arg) { parse(m_devices, arg); }
- + void autoConf(std::vector<OclThread*> &threads, int *platformIndex, size_t *intensity);
- private:
- inline bool isEmpty() const { return m_devices.empty() && m_intensity.empty(); }
- @@ -59,4 +55,4 @@ private:
- };
- -#endif /* __OCLCLI_H__ */
- +#endif /* __OCLCLI_H__ */
- \ No newline at end of file
- diff --git a/src/amd/OclGPU.cpp b/src/amd/OclGPU.cpp
- index c200b1e..ba8a2ea 100644
- --- a/src/amd/OclGPU.cpp
- +++ b/src/amd/OclGPU.cpp
- @@ -56,7 +56,16 @@ static inline void port_sleep(size_t sec)
- #include "cryptonight.h"
- #include "log/Log.h"
- #include "Options.h"
- -#include "xmrig.h"
- +
- +#if defined(__APPLE__)
- +# include <OpenCL/cl_ext.h>
- +#else
- +# include <CL/cl_ext.h>
- +#endif
- +
- +#ifndef CL_MEM_USE_PERSISTENT_MEM_AMD
- +#define CL_MEM_USE_PERSISTENT_MEM_AMD 0
- +#endif
- constexpr const char *kSetKernelArgErr = "Error %s when calling clSetKernelArg for kernel %d, argument %d.";
- @@ -205,13 +214,36 @@ inline static int getDeviceMaxComputeUnits(cl_device_id id)
- }
- -inline static void getDeviceName(cl_device_id id, char *buf, size_t size)
- +inline static std::string getDeviceName(cl_device_id id)
- {
- - if (clGetDeviceInfo(id, 0x4038 /* CL_DEVICE_BOARD_NAME_AMD */, size, buf, nullptr) == CL_SUCCESS) {
- - return;
- + char buf[128] = { 0 };
- +
- + if (clGetDeviceInfo(id, 0x4038 /* CL_DEVICE_BOARD_NAME_AMD */, sizeof(buf), buf, nullptr) == CL_SUCCESS) {
- + return buf;
- + }
- +
- + if (clGetDeviceInfo(id, CL_DEVICE_NAME, sizeof(buf), buf, nullptr) == CL_SUCCESS) {
- + return buf;
- }
- - clGetDeviceInfo(id, CL_DEVICE_NAME, size, buf, nullptr);
- + return "";
- +}
- +
- +
- +inline static int getBusId(cl_device_id id)
- +{
- +#if defined(CL_DEVICE_TOPOLOGY_AMD)
- + cl_device_topology_amd topology;
- + if(clGetDeviceInfo(id, CL_DEVICE_TOPOLOGY_AMD,
- + sizeof(cl_device_topology_amd), &topology, nullptr) != CL_SUCCESS) {
- + // handle error
- + }
- +
- + if (topology.raw.type == CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD) {
- + return (int)topology.pcie.bus;
- + }
- +#endif
- + return -1;
- }
- @@ -228,7 +260,7 @@ inline static bool setKernelArgFromExtraBuffers(GpuContext *ctx, size_t kernel,
- }
- -size_t InitOpenCLGpu(int index, cl_context opencl_ctx, GpuContext* ctx, const char* source_code)
- +size_t InitOpenCLGpu(int index, cl_context opencl_ctx, GpuContext* ctx)
- {
- size_t MaximumWorkSize;
- cl_int ret;
- @@ -238,12 +270,12 @@ size_t InitOpenCLGpu(int index, cl_context opencl_ctx, GpuContext* ctx, const ch
- return OCL_ERR_API;
- }
- - char buf[128] = { 0 };
- - getDeviceName(ctx->DeviceID, buf, sizeof(buf));
- ctx->computeUnits = getDeviceMaxComputeUnits(ctx->DeviceID);
- + ctx->busId = getBusId(ctx->DeviceID);
- + ctx->deviceName = getDeviceName(ctx->DeviceID);
- LOG_INFO(Options::i()->colors() ? "\x1B[01;37m#%d\x1B[0m, GPU \x1B[01;37m#%zu\x1B[0m \x1B[01;32m%s\x1B[0m, intensity: \x1B[01;37m%zu\x1B[0m (%zu/%zu), cu: \x1B[01;37m%d" : "#%d, GPU #%zu (%s), intensity: %zu (%zu/%zu), cu: %d",
- - index, ctx->deviceIdx, buf, ctx->rawIntensity, ctx->workSize, MaximumWorkSize, ctx->computeUnits);
- + index, ctx->deviceIdx, ctx->deviceName.c_str(), ctx->rawIntensity, ctx->workSize, MaximumWorkSize, ctx->computeUnits);
- # ifdef CL_VERSION_2_0
- const cl_queue_properties CommandQueueProperties[] = { 0, 0, 0 };
- @@ -253,29 +285,25 @@ size_t InitOpenCLGpu(int index, cl_context opencl_ctx, GpuContext* ctx, const ch
- ctx->CommandQueues = clCreateCommandQueue(opencl_ctx, ctx->DeviceID, CommandQueueProperties, &ret);
- # endif
- + size_t hashMemSize = MONERO_MEMORY;
- +
- +# if !defined(XMRIG_NO_AEON)
- + if (Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE) {
- + hashMemSize = AEON_MEMORY;
- + }
- +# endif
- +
- if (ret != CL_SUCCESS) {
- LOG_ERR("Error %s when calling clCreateCommandQueueWithProperties.", err_to_str(ret));
- return OCL_ERR_API;
- }
- - ctx->InputBuffer = clCreateBuffer(opencl_ctx, CL_MEM_READ_ONLY, 88, NULL, &ret);
- + ctx->InputBuffer = clCreateBuffer(opencl_ctx, CL_MEM_READ_ONLY | CL_MEM_USE_PERSISTENT_MEM_AMD, 88, NULL, &ret);
- if (ret != CL_SUCCESS) {
- LOG_ERR("Error %s when calling clCreateBuffer to create input buffer.", err_to_str(ret));
- return OCL_ERR_API;
- }
- - size_t hashMemSize = MONERO_MEMORY;
- - int threadMemMask = MONERO_MASK;
- - int hasIterations = MONERO_ITER;
- -
- -# if !defined(XMRIG_NO_AEON)
- - if (Options::i()->algo() == xmrig::ALGO_CRYPTONIGHT_LITE) {
- - hashMemSize = AEON_MEMORY;
- - threadMemMask = AEON_MASK;
- - hasIterations = AEON_ITER;
- - }
- -# endif
- -
- size_t g_thd = ctx->rawIntensity;
- ctx->ExtraBuffers[0] = clCreateBuffer(opencl_ctx, CL_MEM_READ_WRITE, hashMemSize * g_thd, NULL, &ret);
- if (ret != CL_SUCCESS) {
- @@ -283,101 +311,47 @@ size_t InitOpenCLGpu(int index, cl_context opencl_ctx, GpuContext* ctx, const ch
- return OCL_ERR_API;
- }
- - ctx->ExtraBuffers[1] = clCreateBuffer(opencl_ctx, CL_MEM_READ_WRITE, 200 * g_thd, NULL, &ret);
- + ctx->ExtraBuffers[1] = clCreateBuffer(opencl_ctx, CL_MEM_READ_WRITE | CL_MEM_USE_PERSISTENT_MEM_AMD, 200 * g_thd, NULL, &ret);
- if(ret != CL_SUCCESS) {
- LOG_ERR("Error %s when calling clCreateBuffer to create hash states buffer.", err_to_str(ret));
- return OCL_ERR_API;
- }
- // Blake-256 branches
- - ctx->ExtraBuffers[2] = clCreateBuffer(opencl_ctx, CL_MEM_READ_WRITE, sizeof(cl_uint) * (g_thd + 2), NULL, &ret);
- + ctx->ExtraBuffers[2] = clCreateBuffer(opencl_ctx, CL_MEM_READ_WRITE | CL_MEM_USE_PERSISTENT_MEM_AMD, sizeof(cl_uint) * (g_thd + 2), NULL, &ret);
- if (ret != CL_SUCCESS){
- LOG_ERR("Error %s when calling clCreateBuffer to create Branch 0 buffer.", err_to_str(ret));
- return OCL_ERR_API;
- }
- // Groestl-256 branches
- - ctx->ExtraBuffers[3] = clCreateBuffer(opencl_ctx, CL_MEM_READ_WRITE, sizeof(cl_uint) * (g_thd + 2), NULL, &ret);
- + ctx->ExtraBuffers[3] = clCreateBuffer(opencl_ctx, CL_MEM_READ_WRITE | CL_MEM_USE_PERSISTENT_MEM_AMD, sizeof(cl_uint) * (g_thd + 2), NULL, &ret);
- if(ret != CL_SUCCESS) {
- LOG_ERR("Error %s when calling clCreateBuffer to create Branch 1 buffer.", err_to_str(ret));
- return OCL_ERR_API;
- }
- // JH-256 branches
- - ctx->ExtraBuffers[4] = clCreateBuffer(opencl_ctx, CL_MEM_READ_WRITE, sizeof(cl_uint) * (g_thd + 2), NULL, &ret);
- + ctx->ExtraBuffers[4] = clCreateBuffer(opencl_ctx, CL_MEM_READ_WRITE | CL_MEM_USE_PERSISTENT_MEM_AMD, sizeof(cl_uint) * (g_thd + 2), NULL, &ret);
- if (ret != CL_SUCCESS) {
- LOG_ERR("Error %s when calling clCreateBuffer to create Branch 2 buffer.", err_to_str(ret));
- return OCL_ERR_API;
- }
- // Skein-512 branches
- - ctx->ExtraBuffers[5] = clCreateBuffer(opencl_ctx, CL_MEM_READ_WRITE, sizeof(cl_uint) * (g_thd + 2), NULL, &ret);
- + ctx->ExtraBuffers[5] = clCreateBuffer(opencl_ctx, CL_MEM_READ_WRITE | CL_MEM_USE_PERSISTENT_MEM_AMD, sizeof(cl_uint) * (g_thd + 2), NULL, &ret);
- if (ret != CL_SUCCESS) {
- LOG_ERR("Error %s when calling clCreateBuffer to create Branch 3 buffer.", err_to_str(ret));
- return OCL_ERR_API;
- }
- // Assume we may find up to 0xFF nonces in one run - it's reasonable
- - ctx->OutputBuffer = clCreateBuffer(opencl_ctx, CL_MEM_READ_WRITE, sizeof(cl_uint) * 0x100, NULL, &ret);
- + ctx->OutputBuffer = clCreateBuffer(opencl_ctx, CL_MEM_READ_WRITE | CL_MEM_USE_PERSISTENT_MEM_AMD, sizeof(cl_uint) * 0x100, NULL, &ret);
- if (ret != CL_SUCCESS) {
- LOG_ERR("Error %s when calling clCreateBuffer to create output buffer.", err_to_str(ret));
- return OCL_ERR_API;
- }
- - ctx->Program = clCreateProgramWithSource(opencl_ctx, 1, (const char**)&source_code, NULL, &ret);
- - if (ret != CL_SUCCESS) {
- - LOG_ERR("Error %s when calling clCreateProgramWithSource on the contents of cryptonight.cl", err_to_str(ret));
- - return OCL_ERR_API;
- - }
- -
- - char options[256];
- - snprintf(options, sizeof(options), "-DITERATIONS=%d -DMASK=%d -DWORKSIZE=%zu", hasIterations, threadMemMask, ctx->workSize);
- - ret = clBuildProgram(ctx->Program, 1, &ctx->DeviceID, options, NULL, NULL);
- - if (ret != CL_SUCCESS) {
- - size_t len;
- - LOG_ERR("Error %s when calling clBuildProgram.", err_to_str(ret));
- -
- - if ((ret = clGetProgramBuildInfo(ctx->Program, ctx->DeviceID, CL_PROGRAM_BUILD_LOG, 0, NULL, &len)) != CL_SUCCESS) {
- - LOG_ERR("Error %s when calling clGetProgramBuildInfo for length of build log output.", err_to_str(ret));
- - return OCL_ERR_API;
- - }
- -
- - char* BuildLog = (char*)malloc(len + 1);
- - BuildLog[0] = '\0';
- -
- - if ((ret = clGetProgramBuildInfo(ctx->Program, ctx->DeviceID, CL_PROGRAM_BUILD_LOG, len, BuildLog, NULL)) != CL_SUCCESS) {
- - free(BuildLog);
- - LOG_ERR("Error %s when calling clGetProgramBuildInfo for build log.", err_to_str(ret));
- - return OCL_ERR_API;
- - }
- -
- - Log::i()->text("Build log:");
- - std::cerr << BuildLog << std::endl;
- -
- - free(BuildLog);
- - return OCL_ERR_API;
- - }
- -
- - cl_build_status status;
- - do
- - {
- - if ((ret = clGetProgramBuildInfo(ctx->Program, ctx->DeviceID, CL_PROGRAM_BUILD_STATUS, sizeof(cl_build_status), &status, NULL)) != CL_SUCCESS) {
- - LOG_ERR("Error %s when calling clGetProgramBuildInfo for status of build.", err_to_str(ret));
- - return OCL_ERR_API;
- - }
- - port_sleep(1);
- - }
- - while(status == CL_BUILD_IN_PROGRESS);
- -
- - const char *KernelNames[] = { "cn0", "cn1", "cn2", "Blake", "Groestl", "JH", "Skein" };
- - for(int i = 0; i < 7; ++i) {
- - ctx->Kernels[i] = clCreateKernel(ctx->Program, KernelNames[i], &ret);
- - if (ret != CL_SUCCESS) {
- - LOG_ERR("Error %s when calling clCreateKernel for kernel %s.", err_to_str(ret), KernelNames[i]);
- - return OCL_ERR_API;
- - }
- - }
- -
- ctx->Nonce = 0;
- return 0;
- }
- @@ -426,6 +400,8 @@ std::vector<GpuContext> getAMDDevices(int index)
- ctx.deviceIdx = i;
- ctx.DeviceID = device_list[i];
- ctx.computeUnits = getDeviceMaxComputeUnits(ctx.DeviceID);
- + ctx.busId = getBusId(ctx.DeviceID);
- + ctx.deviceName = getDeviceName(ctx.DeviceID);
- size_t maxMem;
- clGetDeviceInfo(ctx.DeviceID, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof(size_t), &(maxMem), nullptr);
- @@ -433,12 +409,7 @@ std::vector<GpuContext> getAMDDevices(int index)
- // if environment variable GPU_SINGLE_ALLOC_PERCENT is not set we can not allocate the full memory
- ctx.freeMem = std::min(ctx.freeMem, maxMem);
- - getDeviceName(ctx.DeviceID, buf, sizeof(buf));
- -
- - LOG_INFO(Options::i()->colors() ? "\x1B[01;32mfound\x1B[0m OpenCL GPU: \x1B[01;37m%s\x1B[0m, cu: \x1B[01;37m%d" : "found OpenCL GPU: %s, cu:", buf, ctx.computeUnits);
- -
- - clGetDeviceInfo(ctx.DeviceID, CL_DEVICE_NAME, sizeof(buf), buf, nullptr);
- - ctx.name = buf;
- + LOG_INFO(Options::i()->colors() ? "\x1B[01;32mfound\x1B[0m OpenCL GPU: \x1B[01;37m%s\x1B[0m, cu: \x1B[01;37m%d" : "found OpenCL GPU: %s, cu:", ctx.deviceName.c_str(), ctx.computeUnits);
- ctxVec.push_back(ctx);
- }
- @@ -616,8 +587,77 @@ size_t InitOpenCL(GpuContext* ctx, size_t num_gpus, size_t platform_idx)
- source_code = std::regex_replace(source_code, std::regex("XMRIG_INCLUDE_BLAKE256"), blake256CL);
- source_code = std::regex_replace(source_code, std::regex("XMRIG_INCLUDE_GROESTL256"), groestl256CL);
- + ctx[0].Program = clCreateProgramWithSource(opencl_ctx, 1, (const char**)&source_code, NULL, &ret);
- + if (ret != CL_SUCCESS) {
- + LOG_ERR("Error %s when calling clCreateProgramWithSource on the contents of cryptonight.cl", err_to_str(ret));
- + return OCL_ERR_API;
- + }
- +
- + int threadMemMask = MONERO_MASK;
- + int hasIterations = MONERO_ITER;
- +
- +# if !defined(XMRIG_NO_AEON)
- + if (Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE) {
- + threadMemMask = AEON_MASK;
- + hasIterations = AEON_ITER;
- + }
- +# endif
- +
- + char options[256];
- + snprintf(options, sizeof(options), "-DITERATIONS=%d -DMASK=%d -DWORKSIZE=%zu", hasIterations, threadMemMask, ctx[0].workSize);
- + ret = clBuildProgram(ctx[0].Program, 0, NULL, options, NULL, NULL);
- + if (ret != CL_SUCCESS) {
- + size_t len;
- + LOG_ERR("Error %s when calling clBuildProgram.", err_to_str(ret));
- +
- + if ((ret = clGetProgramBuildInfo(ctx[0].Program, ctx[0].DeviceID, CL_PROGRAM_BUILD_LOG, 0, NULL, &len)) != CL_SUCCESS) {
- + LOG_ERR("Error %s when calling clGetProgramBuildInfo for length of build log output.", err_to_str(ret));
- + return OCL_ERR_API;
- + }
- +
- + char* BuildLog = (char*)malloc(len + 1);
- + BuildLog[0] = '\0';
- +
- + if ((ret = clGetProgramBuildInfo(ctx[0].Program, ctx[0].DeviceID, CL_PROGRAM_BUILD_LOG, len, BuildLog, NULL)) != CL_SUCCESS) {
- + free(BuildLog);
- + LOG_ERR("Error %s when calling clGetProgramBuildInfo for build log.", err_to_str(ret));
- + return OCL_ERR_API;
- + }
- +
- + Log::i()->text("Build log:");
- + std::cerr << BuildLog << std::endl;
- +
- + free(BuildLog);
- + return OCL_ERR_API;
- + }
- +
- + cl_build_status status;
- + do
- + {
- + if ((ret = clGetProgramBuildInfo(ctx[0].Program, ctx[0].DeviceID, CL_PROGRAM_BUILD_STATUS, sizeof(cl_build_status), &status, NULL)) != CL_SUCCESS) {
- + LOG_ERR("Error %s when calling clGetProgramBuildInfo for status of build.", err_to_str(ret));
- + return OCL_ERR_API;
- + }
- + port_sleep(1);
- + }
- + while(status == CL_BUILD_IN_PROGRESS);
- +
- + const char *KernelNames[] = { "cn0", "cn1", "cn2", "Blake", "Groestl", "JH", "Skein" };
- +
- for (int i = 0; i < num_gpus; ++i) {
- - if ((ret = InitOpenCLGpu(i, opencl_ctx, &ctx[i], source_code.c_str())) != OCL_ERR_SUCCESS) {
- + if (i > 0) {
- + ctx[i].Program = ctx[0].Program;
- + }
- +
- + for (int k = 0; k < 7; ++k) {
- + ctx[i].Kernels[k] = clCreateKernel(ctx[i].Program, KernelNames[k], &ret);
- + if (ret != CL_SUCCESS) {
- + LOG_ERR("Error %s when calling clCreateKernel for kernel %s.", err_to_str(ret), KernelNames[k]);
- + return OCL_ERR_API;
- + }
- + }
- +
- + if ((ret = InitOpenCLGpu(i, opencl_ctx, &ctx[i])) != OCL_ERR_SUCCESS) {
- return ret;
- }
- }
- @@ -841,4 +881,4 @@ size_t XMRRunJob(GpuContext* ctx, cl_uint* HashOutput)
- ctx->Nonce += (uint32_t) g_intensity;
- return OCL_ERR_SUCCESS;
- -}
- +}
- \ No newline at end of file
- diff --git a/src/amd/OclGPU.h b/src/amd/OclGPU.h
- index e912823..1c5fdda 100644
- --- a/src/amd/OclGPU.h
- +++ b/src/amd/OclGPU.h
- @@ -39,7 +39,6 @@
- uint32_t getNumPlatforms();
- -void printPlatforms();
- int getAMDPlatformIdx();
- std::vector<GpuContext> getAMDDevices(int index);
- diff --git a/src/api/ApiState.cpp b/src/api/ApiState.cpp
- index f0ee803..3f21f59 100644
- --- a/src/api/ApiState.cpp
- +++ b/src/api/ApiState.cpp
- @@ -23,7 +23,10 @@
- #include <math.h>
- #include <string.h>
- +#include <time.h>
- #include <uv.h>
- +#include <map>
- +#include <vector>
- #if _WIN32
- # include "winsock2.h"
- @@ -32,17 +35,19 @@
- #endif
- +#include "amd/Adl.h"
- #include "api/ApiState.h"
- #include "Cpu.h"
- #include "net/Job.h"
- +#include "net/Url.h"
- #include "Options.h"
- #include "Platform.h"
- #include "rapidjson/document.h"
- #include "rapidjson/stringbuffer.h"
- #include "rapidjson/prettywriter.h"
- -#include "version.h"
- +#include "workers/Workers.h"
- #include "workers/Hashrate.h"
- -
- +#include "workers/Handle.h"
- extern "C"
- {
- @@ -50,7 +55,7 @@ extern "C"
- }
- -static inline double normalize(double d)
- +static inline double normalize2(double d)
- {
- if (!isnormal(d)) {
- return 0.0;
- @@ -60,25 +65,37 @@ static inline double normalize(double d)
- }
- +static inline double normalize3(double d)
- +{
- + if (!isnormal(d)) {
- + return 0.0;
- + }
- +
- + return floor(d * 1000.0) / 1000.0;
- +}
- +
- +
- +static inline time_t now()
- +{
- + auto now = std::chrono::system_clock::now();
- + return std::chrono::system_clock::to_time_t( now );
- +}
- +
- +
- ApiState::ApiState()
- {
- m_threads = (int) Options::i()->threads().size();
- m_hashrate = new double[m_threads * 3]();
- + m_start = now();
- memset(m_totalHashrate, 0, sizeof(m_totalHashrate));
- - memset(m_workerId, 0, sizeof(m_workerId));
- + memset(m_id, 0, sizeof(m_id));
- - if (Options::i()->apiWorkerId()) {
- - strncpy(m_workerId, Options::i()->apiWorkerId(), sizeof(m_workerId) - 1);
- + if (Options::i()->id()) {
- + strncpy(m_id, Options::i()->id(), sizeof(m_id) - 1);
- }
- else {
- - gethostname(m_workerId, sizeof(m_workerId) - 1);
- - }
- -
- - genId();
- -
- - for (const OclThread *thread : Options::i()->threads()) {
- - m_gpuThreads.push_back(*thread);
- + gethostname(m_id, sizeof(m_id) - 1);
- }
- }
- @@ -94,9 +111,10 @@ char *ApiState::get(const char *url, int *status) const
- rapidjson::Document doc;
- doc.SetObject();
- - getIdentify(doc);
- + getId(doc);
- getMiner(doc);
- getHashrate(doc);
- + getGpus(doc);
- getResults(doc);
- getConnection(doc);
- @@ -136,45 +154,13 @@ char *ApiState::finalize(rapidjson::Document &doc) const
- }
- -void ApiState::genId()
- -{
- - memset(m_id, 0, sizeof(m_id));
- -
- - uv_interface_address_t *interfaces;
- - int count = 0;
- -
- - if (uv_interface_addresses(&interfaces, &count) < 0) {
- - return;
- - }
- -
- - for (int i = 0; i < count; i++) {
- - if (!interfaces[i].is_internal && interfaces[i].address.address4.sin_family == AF_INET) {
- - uint8_t hash[200];
- - const size_t addrSize = sizeof(interfaces[i].phys_addr);
- - const size_t inSize = strlen(APP_KIND) + addrSize;
- -
- - uint8_t *input = new uint8_t[inSize]();
- - memcpy(input, interfaces[i].phys_addr, addrSize);
- - memcpy(input + addrSize, APP_KIND, strlen(APP_KIND));
- -
- - keccak(input, static_cast<int>(inSize), hash, sizeof(hash));
- - Job::toHex(hash, 8, m_id);
- -
- - delete [] input;
- - break;
- - }
- - }
- -
- - uv_free_interface_addresses(interfaces, count);
- -}
- -
- -
- void ApiState::getConnection(rapidjson::Document &doc) const
- {
- auto &allocator = doc.GetAllocator();
- rapidjson::Value connection(rapidjson::kObjectType);
- connection.AddMember("pool", rapidjson::StringRef(m_network.pool), allocator);
- + connection.AddMember("user", rapidjson::StringRef(m_network.userMask), allocator);
- connection.AddMember("uptime", m_network.connectionTime(), allocator);
- connection.AddMember("ping", m_network.latency(), allocator);
- connection.AddMember("failures", m_network.failures, allocator);
- @@ -184,38 +170,114 @@ void ApiState::getConnection(rapidjson::Document &doc) const
- }
- -void ApiState::getHashrate(rapidjson::Document &doc) const
- +void ApiState::getGpus(rapidjson::Document &doc) const
- {
- auto &allocator = doc.GetAllocator();
- - rapidjson::Value hashrate(rapidjson::kObjectType);
- - rapidjson::Value total(rapidjson::kArrayType);
- - rapidjson::Value threads(rapidjson::kArrayType);
- + rapidjson::Value gpus(rapidjson::kArrayType);
- - for (int i = 0; i < 3; ++i) {
- - total.PushBack(normalize(m_totalHashrate[i]), allocator);
- - }
- + for (const auto& map : Workers::gpus()) {
- + std::vector<Handle*> handles = map.second;
- +
- + rapidjson::Value gpu(rapidjson::kObjectType);
- + gpu.AddMember("bus_id", handles[0]->ctx()->busId, allocator);
- + gpu.AddMember("adapter_index", Adl::i()->getAdapterIndex(handles[0]->ctx()->busId), allocator);
- + gpu.AddMember("device_name", rapidjson::StringRef(handles[0]->ctx()->deviceName.c_str()), allocator);
- + gpu.AddMember("temperature", Adl::i()->getTemperature(handles[0]->ctx()->busId) / 1000, allocator);
- +
- + const ADLODNPerformanceStatus* odNPerformanceStatus = Adl::i()->getPerformanceStatus(handles[0]->ctx()->busId);
- + gpu.AddMember("core_clock", odNPerformanceStatus->iCoreClock / 100, allocator);
- + gpu.AddMember("memory_clock", odNPerformanceStatus->iMemoryClock / 100, allocator);
- +
- + const ADLODNFanControl* odNFanControl = Adl::i()->getFanControl(handles[0]->ctx()->busId);
- + gpu.AddMember("fan_speed", odNFanControl->iCurrentFanSpeed, allocator);
- +
- + const ADLODNPowerLimitSetting* odNPowerControl = Adl::i()->getPowerLimit(handles[0]->ctx()->busId);
- +
- + const ADLODNPerformanceLevelsX2* odNSystemClocks = Adl::i()->getSystemClocks(handles[0]->ctx()->busId);
- + const ADLODNPerformanceLevelsX2* odNMemoryClocks = Adl::i()->getMemoryClocks(handles[0]->ctx()->busId);
- + rapidjson::Value profile(rapidjson::kObjectType);
- + rapidjson::Value system(rapidjson::kArrayType);
- + rapidjson::Value memory(rapidjson::kArrayType);
- +
- + for (int i=0 ;i <ADL_PERFORMANCE_LEVELS; i++) {
- + if (odNSystemClocks->aLevels[i].iEnabled) {
- + rapidjson::Value level(rapidjson::kObjectType);
- + level.AddMember("clock", odNSystemClocks->aLevels[i].iClock / 100, allocator);
- + level.AddMember("vddc", normalize3(odNSystemClocks->aLevels[i].iVddc / 1000.0), allocator);
- + system.PushBack(level, allocator);
- + }
- + }
- +
- + for (int i=0 ;i <ADL_PERFORMANCE_LEVELS; i++) {
- + if (odNMemoryClocks->aLevels[i].iEnabled) {
- + rapidjson::Value level(rapidjson::kObjectType);
- + level.AddMember("clock", odNMemoryClocks->aLevels[i].iClock / 100, allocator);
- + level.AddMember("vddc", normalize3(odNMemoryClocks->aLevels[i].iVddc / 1000.0), allocator);
- + memory.PushBack(level, allocator);
- + }
- + }
- +
- + profile.AddMember("system", system, allocator);
- + profile.AddMember("memory", memory, allocator);
- + profile.AddMember("target_temperature", odNFanControl->iTargetTemperature, allocator);
- + profile.AddMember("power_limit", odNPowerControl->iTDPLimit, allocator);
- +
- + gpu.AddMember("profile", profile, allocator);
- +
- + rapidjson::Value threads(rapidjson::kArrayType);
- +
- + double sum_hashrate_10s = 0.0;
- + double sum_hashrate_60s = 0.0;
- + double sum_hashrate_15m = 0.0;
- +
- + for (const Handle *handle : handles) {
- + rapidjson::Value thread(rapidjson::kObjectType);
- + thread.AddMember("intensity", (uint64_t)handle->ctx()->rawIntensity, allocator);
- - for (int i = 0; i < m_threads * 3; i += 3) {
- - rapidjson::Value thread(rapidjson::kArrayType);
- - thread.PushBack(normalize(m_hashrate[i]), allocator);
- - thread.PushBack(normalize(m_hashrate[i + 1]), allocator);
- - thread.PushBack(normalize(m_hashrate[i + 2]), allocator);
- + int i = handle->threadId() * 3;
- + double hashrate_10s = normalize2(m_hashrate[i]);
- + double hashrate_60s = normalize2(m_hashrate[i + 1]);
- + double hashrate_15m = normalize2(m_hashrate[i + 2]);
- - threads.PushBack(thread, allocator);
- + thread.AddMember("hashrate_10s", hashrate_10s, allocator);
- + thread.AddMember("hashrate_60s", hashrate_60s, allocator);
- + thread.AddMember("hashrate_15m", hashrate_15m, allocator);
- +
- + sum_hashrate_10s += hashrate_10s;
- + sum_hashrate_60s += hashrate_60s;
- + sum_hashrate_15m += hashrate_15m;
- +
- + threads.PushBack(thread, allocator);
- + }
- +
- + gpu.AddMember("threads", threads, allocator);
- +
- + gpu.AddMember("hashrate_10s", sum_hashrate_10s, allocator);
- + gpu.AddMember("hashrate_60s", sum_hashrate_60s, allocator);
- + gpu.AddMember("hashrate_15m", sum_hashrate_15m, allocator);
- +
- + gpus.PushBack(gpu, allocator);
- }
- - hashrate.AddMember("total", total, allocator);
- - hashrate.AddMember("highest", normalize(m_highestHashrate), allocator);
- - hashrate.AddMember("threads", threads, allocator);
- - doc.AddMember("hashrate", hashrate, allocator);
- + doc.AddMember("gpus", gpus, allocator);
- }
- -void ApiState::getIdentify(rapidjson::Document &doc) const
- +void ApiState::getHashrate(rapidjson::Document &doc) const
- {
- - doc.AddMember("id", rapidjson::StringRef(m_id), doc.GetAllocator());
- - doc.AddMember("worker_id", rapidjson::StringRef(m_workerId), doc.GetAllocator());
- + auto &allocator = doc.GetAllocator();
- +
- + doc.AddMember("hashrate_10s", normalize2(m_totalHashrate[0]), allocator);
- + doc.AddMember("hashrate_60s", normalize2(m_totalHashrate[1]), allocator);
- + doc.AddMember("hashrate_15m", normalize2(m_totalHashrate[2]), allocator);
- + doc.AddMember("hashrate_max", normalize2(m_highestHashrate), allocator);
- +}
- +
- +
- +void ApiState::getId(rapidjson::Document &doc) const
- +{
- + doc.AddMember("id", rapidjson::StringRef(m_id), doc.GetAllocator());
- }
- @@ -223,19 +285,9 @@ void ApiState::getMiner(rapidjson::Document &doc) const
- {
- auto &allocator = doc.GetAllocator();
- - rapidjson::Value cpu(rapidjson::kObjectType);
- - cpu.AddMember("brand", rapidjson::StringRef(Cpu::brand()), allocator);
- - cpu.AddMember("aes", Cpu::hasAES(), allocator);
- - cpu.AddMember("x64", Cpu::isX64(), allocator);
- - cpu.AddMember("sockets", Cpu::sockets(), allocator);
- -
- - doc.AddMember("version", APP_VERSION, allocator);
- - doc.AddMember("kind", APP_KIND, allocator);
- - doc.AddMember("ua", rapidjson::StringRef(Platform::userAgent()), allocator);
- - doc.AddMember("cpu", cpu, allocator);
- + doc.AddMember("version", rapidjson::StringRef(Platform::versionString()), allocator);
- doc.AddMember("algo", rapidjson::StringRef(Options::i()->algoName()), allocator);
- - doc.AddMember("hugepages", false, allocator);
- - doc.AddMember("donate_level", Options::i()->donateLevel(), allocator);
- + doc.AddMember("uptime", difftime(now(), m_start), allocator);
- }
- @@ -260,4 +312,4 @@ void ApiState::getResults(rapidjson::Document &doc) const
- results.AddMember("error_log", rapidjson::Value(rapidjson::kArrayType), allocator);
- doc.AddMember("results", results, allocator);
- -}
- +}
- \ No newline at end of file
- diff --git a/src/api/ApiState.h b/src/api/ApiState.h
- index 3fc641b..479b6a6 100644
- --- a/src/api/ApiState.h
- +++ b/src/api/ApiState.h
- @@ -26,6 +26,8 @@
- #include <vector>
- +#include <chrono>
- +#include <time.h>
- #include "api/NetworkState.h"
- @@ -48,21 +50,20 @@ public:
- private:
- char *finalize(rapidjson::Document &doc) const;
- - void genId();
- void getConnection(rapidjson::Document &doc) const;
- + void getGpus(rapidjson::Document &doc) const;
- void getHashrate(rapidjson::Document &doc) const;
- - void getIdentify(rapidjson::Document &doc) const;
- + void getId(rapidjson::Document &doc) const;
- void getMiner(rapidjson::Document &doc) const;
- void getResults(rapidjson::Document &doc) const;
- - char m_id[17];
- - char m_workerId[128];
- + char m_id[128];
- double *m_hashrate;
- double m_highestHashrate;
- double m_totalHashrate[3];
- + time_t m_start;
- int m_threads;
- NetworkState m_network;
- - std::vector<OclThread> m_gpuThreads;
- };
- -#endif /* __APISTATE_H__ */
- +#endif /* __APISTATE_H__ */
- \ No newline at end of file
- diff --git a/src/api/Httpd.cpp b/src/api/Httpd.cpp
- index 861086e..99bb9d1 100644
- --- a/src/api/Httpd.cpp
- +++ b/src/api/Httpd.cpp
- @@ -4,8 +4,8 @@
- * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
- * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
- * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
- - * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
- - * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
- + * Copyright 2016-2017 XMRig <support@xmrig.com>
- + *
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- @@ -45,19 +45,7 @@ bool Httpd::start()
- return false;
- }
- - unsigned int flags = MHD_USE_SELECT_INTERNALLY;
- -
- -# if MHD_VERSION >= 0x00093500
- - if (MHD_is_feature_supported(MHD_FEATURE_EPOLL)) {
- - flags = MHD_USE_EPOLL_LINUX_ONLY | MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY;
- - }
- -
- - if (MHD_is_feature_supported(MHD_FEATURE_IPv6)) {
- - flags |= MHD_USE_DUAL_STACK;
- - }
- -# endif
- -
- - m_daemon = MHD_start_daemon(flags, m_port, nullptr, nullptr, &Httpd::handler, this, MHD_OPTION_END);
- + m_daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, m_port, nullptr, nullptr, &Httpd::handler, this, MHD_OPTION_END);
- if (!m_daemon) {
- LOG_ERR("HTTP Daemon failed to start.");
- return false;
- @@ -123,6 +111,6 @@ int Httpd::handler(void *cls, struct MHD_Connection *connection, const char *url
- return MHD_NO;
- }
- - MHD_Response *rsp = MHD_create_response_from_buffer(strlen(buf), (void*) buf, MHD_RESPMEM_MUST_FREE);
- + MHD_Response *rsp = MHD_create_response_from_buffer(strlen(buf), (void*)buf, MHD_RESPMEM_MUST_FREE);
- return done(connection, status, rsp);
- }
- diff --git a/src/api/Httpd.h b/src/api/Httpd.h
- index 30618e2..7a4dd93 100644
- --- a/src/api/Httpd.h
- +++ b/src/api/Httpd.h
- @@ -4,8 +4,8 @@
- * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
- * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
- * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
- - * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
- - * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
- + * Copyright 2016-2017 XMRig <support@xmrig.com>
- + *
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- diff --git a/src/api/NetworkState.cpp b/src/api/NetworkState.cpp
- index d3ffddd..f918c95 100644
- --- a/src/api/NetworkState.cpp
- +++ b/src/api/NetworkState.cpp
- @@ -23,8 +23,8 @@
- #include <algorithm>
- -#include <stdio.h>
- #include <string.h>
- +#include <string>
- #include <uv.h>
- @@ -40,13 +40,14 @@ NetworkState::NetworkState() :
- total(0),
- m_active(false)
- {
- + memset(userMask, 0, sizeof(userMask));
- memset(pool, 0, sizeof(pool));
- }
- int NetworkState::connectionTime() const
- {
- - return m_active ? (int)((uv_now(uv_default_loop()) - m_connectionTime) / 1000) : 0;
- + return m_active ? ((uv_now(uv_default_loop()) - m_connectionTime) / 1000) : 0;
- }
- @@ -56,7 +57,7 @@ uint32_t NetworkState::avgTime() const
- return 0;
- }
- - return connectionTime() / (uint32_t)m_latency.size();
- + return (uint32_t) connectionTime() / m_latency.size();
- }
- @@ -94,6 +95,12 @@ void NetworkState::add(const SubmitResult &result, const char *error)
- }
- +void NetworkState::setUserMask(const char *user)
- +{
- + snprintf(userMask, sizeof(userMask) - 1, "%s%s", std::string(strlen(user) - 4, '*').c_str(), std::string(user).substr(strlen(user) - 4).c_str());
- +}
- +
- +
- void NetworkState::setPool(const char *host, int port, const char *ip)
- {
- snprintf(pool, sizeof(pool) - 1, "%s:%d", host, port);
- diff --git a/src/api/NetworkState.h b/src/api/NetworkState.h
- index d099807..cbd516a 100644
- --- a/src/api/NetworkState.h
- +++ b/src/api/NetworkState.h
- @@ -41,9 +41,11 @@ public:
- uint32_t avgTime() const;
- uint32_t latency() const;
- void add(const SubmitResult &result, const char *error);
- + void setUserMask(const char *user);
- void setPool(const char *host, int port, const char *ip);
- void stop();
- + char userMask[256];
- char pool[256];
- std::array<uint64_t, 10> topDiff { { } };
- uint32_t diff;
- diff --git a/src/config.json b/src/config.json
- index 750f17b..66497a7 100644
- --- a/src/config.json
- +++ b/src/config.json
- @@ -12,12 +12,11 @@
- "threads": null,
- "pools": [
- {
- - "url": "failover.xmrig.com:443",
- - "user": "YOUR_WALLET",
- + "url": "pool.monero.hashvault.pro:5555",
- + "user": "",
- "pass": "x",
- "keepalive": true,
- - "nicehash": false,
- - "variant": -1
- + "nicehash": false
- }
- ],
- "api": {
- diff --git a/src/crypto/CryptoNight.cpp b/src/crypto/CryptoNight.cpp
- index d4b0a39..c6fecad 100644
- --- a/src/crypto/CryptoNight.cpp
- +++ b/src/crypto/CryptoNight.cpp
- @@ -29,47 +29,46 @@
- #include "net/Job.h"
- #include "net/JobResult.h"
- #include "Options.h"
- -#include "xmrig.h"
- -void (*cryptonight_hash_ctx)(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) = nullptr;
- +void (*cryptonight_hash_ctx)(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) = nullptr;
- #define CRYPTONIGHT_HASH(NAME, ITERATIONS, MEM, MASK, SOFT_AES) \
- switch (variant) { \
- - case xmrig::VARIANT_V1: \
- - return cryptonight_##NAME##_hash<ITERATIONS, MEM, MASK, SOFT_AES, xmrig::VARIANT_V1>(input, size, output, ctx); \
- + case Options::VARIANT_V1: \
- + return cryptonight_##NAME##_hash<ITERATIONS, MEM, MASK, SOFT_AES, Options::VARIANT_V1>(input, size, output, ctx); \
- \
- - case xmrig::VARIANT_NONE: \
- - return cryptonight_##NAME##_hash<ITERATIONS, MEM, MASK, SOFT_AES, xmrig::VARIANT_NONE>(input, size, output, ctx); \
- + case Options::VARIANT_NONE: \
- + return cryptonight_##NAME##_hash<ITERATIONS, MEM, MASK, SOFT_AES, Options::VARIANT_NONE>(input, size, output, ctx); \
- \
- default: \
- break; \
- }
- -static void cryptonight_av1_aesni(const uint8_t *input, size_t size, uint8_t *output, struct cryptonight_ctx *ctx, int variant) {
- +static void cryptonight_av1_aesni(const void *input, size_t size, void *output, struct cryptonight_ctx *ctx, int variant) {
- CRYPTONIGHT_HASH(single, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, false)
- }
- -static void cryptonight_av3_softaes(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
- +static void cryptonight_av3_softaes(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) {
- CRYPTONIGHT_HASH(single, MONERO_ITER, MONERO_MEMORY, MONERO_MASK, true)
- }
- #ifndef XMRIG_NO_AEON
- -static void cryptonight_lite_av1_aesni(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
- +static void cryptonight_lite_av1_aesni(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) {
- CRYPTONIGHT_HASH(single, AEON_ITER, AEON_MEMORY, AEON_MASK, false)
- }
- -static void cryptonight_lite_av3_softaes(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) {
- +static void cryptonight_lite_av3_softaes(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) {
- CRYPTONIGHT_HASH(single, AEON_ITER, AEON_MEMORY, AEON_MASK, true)
- }
- -void (*cryptonight_variations[8])(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) = {
- +void (*cryptonight_variations[8])(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) = {
- cryptonight_av1_aesni,
- nullptr,
- cryptonight_av3_softaes,
- @@ -80,7 +79,7 @@ void (*cryptonight_variations[8])(const uint8_t *input, size_t size, uint8_t *ou
- nullptr
- };
- #else
- -void (*cryptonight_variations[4])(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx, int variant) = {
- +void (*cryptonight_variations[4])(const void *input, size_t size, void *output, cryptonight_ctx *ctx, int variant) = {
- cryptonight_av1_aesni,
- nullptr,
- cryptonight_av3_softaes,
- @@ -104,7 +103,7 @@ bool CryptoNight::init(int algo, int variant)
- }
- # ifndef XMRIG_NO_AEON
- - const int index = algo == xmrig::ALGO_CRYPTONIGHT_LITE ? (variant + 3) : (variant - 1);
- + const int index = algo == Options::ALGO_CRYPTONIGHT_LITE ? (variant + 3) : (variant - 1);
- # else
- const int index = variant - 1;
- # endif
- @@ -126,14 +125,14 @@ bool CryptoNight::selfTest(int algo) {
- return false;
- }
- - uint8_t output[32];
- + char output[32];
- cryptonight_ctx *ctx = static_cast<cryptonight_ctx *>(_mm_malloc(sizeof(cryptonight_ctx), 16));
- cryptonight_hash_ctx(test_input, 76, output, ctx, 0);
- # ifndef XMRIG_NO_AEON
- - bool rc = memcmp(output, algo == xmrig::ALGO_CRYPTONIGHT_LITE ? test_output_v0_lite : test_output_v0, 32) == 0;
- + bool rc = memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_v0_lite : test_output_v0, 32) == 0;
- # else
- bool rc = memcmp(output, test_output_v0, 32) == 0;
- # endif
- @@ -142,7 +141,7 @@ bool CryptoNight::selfTest(int algo) {
- cryptonight_hash_ctx(test_input, 76, output, ctx, 1);
- # ifndef XMRIG_NO_AEON
- - rc = memcmp(output, algo == xmrig::ALGO_CRYPTONIGHT_LITE ? test_output_v1_lite : test_output_v1, 32) == 0;
- + rc = memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output_v1_lite : test_output_v1, 32) == 0;
- # else
- rc = memcmp(output, test_output_v1, 32) == 0;
- # endif
- @@ -151,4 +150,4 @@ bool CryptoNight::selfTest(int algo) {
- _mm_free(ctx);
- return rc;
- -}
- +}
- \ No newline at end of file
- diff --git a/src/crypto/CryptoNight_monero.h b/src/crypto/CryptoNight_monero.h
- index a667a3b..3c6146a 100644
- --- a/src/crypto/CryptoNight_monero.h
- +++ b/src/crypto/CryptoNight_monero.h
- @@ -27,22 +27,12 @@
- // VARIANT ALTERATIONS
- -#ifndef XMRIG_ARM
- -# define VARIANT1_INIT(part) \
- +#define VARIANT1_INIT(part) \
- uint64_t tweak1_2_##part = 0; \
- if (VARIANT > 0) { \
- - tweak1_2_##part = (*reinterpret_cast<const uint64_t*>(input + 35 + part * size) ^ \
- + tweak1_2_##part = (*reinterpret_cast<const uint64_t*>(reinterpret_cast<const uint8_t*>(input) + 35 + part * size) ^ \
- *(reinterpret_cast<const uint64_t*>(ctx->state##part) + 24)); \
- }
- -#else
- -# define VARIANT1_INIT(part) \
- - uint64_t tweak1_2_##part = 0; \
- - if (VARIANT > 0) { \
- - volatile const uint64_t a = *reinterpret_cast<const uint64_t*>(input + 35 + part * size); \
- - volatile const uint64_t b = *(reinterpret_cast<const uint64_t*>(ctx->state##part) + 24); \
- - tweak1_2_##part = a ^ b; \
- - }
- -#endif
- #define VARIANT1_1(p) \
- if (VARIANT > 0) { \
- diff --git a/src/crypto/CryptoNight_x86.h b/src/crypto/CryptoNight_x86.h
- index 059163c..b1bff94 100644
- --- a/src/crypto/CryptoNight_x86.h
- +++ b/src/crypto/CryptoNight_x86.h
- @@ -49,27 +49,27 @@ extern "C"
- }
- -static inline void do_blake_hash(const uint8_t *input, size_t len, uint8_t *output) {
- - blake256_hash(output, input, len);
- +static inline void do_blake_hash(const void* input, size_t len, char* output) {
- + blake256_hash(reinterpret_cast<uint8_t*>(output), static_cast<const uint8_t*>(input), len);
- }
- -static inline void do_groestl_hash(const uint8_t *input, size_t len, uint8_t *output) {
- - groestl(input, len * 8, output);
- +static inline void do_groestl_hash(const void* input, size_t len, char* output) {
- + groestl(static_cast<const uint8_t*>(input), len * 8, reinterpret_cast<uint8_t*>(output));
- }
- -static inline void do_jh_hash(const uint8_t *input, size_t len, uint8_t *output) {
- - jh_hash(32 * 8, input, 8 * len, output);
- +static inline void do_jh_hash(const void* input, size_t len, char* output) {
- + jh_hash(32 * 8, static_cast<const uint8_t*>(input), 8 * len, reinterpret_cast<uint8_t*>(output));
- }
- -static inline void do_skein_hash(const uint8_t *input, size_t len, uint8_t *output) {
- - xmr_skein(input, output);
- +static inline void do_skein_hash(const void* input, size_t len, char* output) {
- + xmr_skein(static_cast<const uint8_t*>(input), reinterpret_cast<uint8_t*>(output));
- }
- -void (* const extra_hashes[4])(const uint8_t *, size_t, uint8_t *) = {do_blake_hash, do_groestl_hash, do_jh_hash, do_skein_hash};
- +void (* const extra_hashes[4])(const void *, size_t, char *) = {do_blake_hash, do_groestl_hash, do_jh_hash, do_skein_hash};
- @@ -310,9 +310,9 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output)
- template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES, int VARIANT>
- -inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t *__restrict__ output, cryptonight_ctx *__restrict__ ctx)
- +inline void cryptonight_single_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, cryptonight_ctx *__restrict__ ctx)
- {
- - keccak(input, (int) size, ctx->state0, 200);
- + keccak(static_cast<const uint8_t*>(input), (int) size, ctx->state0, 200);
- VARIANT1_INIT(0);
- @@ -363,8 +363,7 @@ inline void cryptonight_single_hash(const uint8_t *__restrict__ input, size_t si
- cn_implode_scratchpad<MEM, SOFT_AES>((__m128i*) ctx->memory, (__m128i*) ctx->state0);
- keccakf(h0, 24);
- - extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, output);
- + extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, static_cast<char*>(output));
- }
- -
- #endif /* __CRYPTONIGHT_X86_H__ */
- diff --git a/src/interfaces/IStrategy.h b/src/interfaces/IStrategy.h
- index 9f2795f..660529e 100644
- --- a/src/interfaces/IStrategy.h
- +++ b/src/interfaces/IStrategy.h
- @@ -4,8 +4,8 @@
- * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
- * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
- * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
- - * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
- - * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
- + * Copyright 2016-2017 XMRig <support@xmrig.com>
- + *
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- diff --git a/src/interfaces/IStrategyListener.h b/src/interfaces/IStrategyListener.h
- index 9f2c448..60f9573 100644
- --- a/src/interfaces/IStrategyListener.h
- +++ b/src/interfaces/IStrategyListener.h
- @@ -4,8 +4,8 @@
- * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
- * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
- * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
- - * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
- - * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
- + * Copyright 2016-2017 XMRig <support@xmrig.com>
- + *
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- @@ -39,10 +39,10 @@ class IStrategyListener
- public:
- virtual ~IStrategyListener() {}
- - virtual void onActive(IStrategy *strategy, Client *client) = 0;
- - virtual void onJob(IStrategy *strategy, Client *client, const Job &job) = 0;
- - virtual void onPause(IStrategy *strategy) = 0;
- - virtual void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) = 0;
- + virtual void onActive(Client *client) = 0;
- + virtual void onJob(Client *client, const Job &job) = 0;
- + virtual void onPause(IStrategy *strategy) = 0;
- + virtual void onResultAccepted(Client *client, const SubmitResult &result, const char *error) = 0;
- };
- diff --git a/src/net/Client.cpp b/src/net/Client.cpp
- index c8a93f2..f6543b4 100644
- --- a/src/net/Client.cpp
- +++ b/src/net/Client.cpp
- @@ -21,7 +21,6 @@
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- -#include <assert.h>
- #include <inttypes.h>
- #include <iterator>
- #include <stdio.h>
- @@ -66,7 +65,6 @@ Client::Client(int id, const char *agent, IClientListener *listener) :
- m_recvBufPos(0),
- m_state(UnconnectedState),
- m_expire(0),
- - m_jobs(0),
- m_stream(nullptr),
- m_socket(nullptr)
- {
- @@ -113,20 +111,6 @@ void Client::connect(const Url *url)
- }
- -void Client::deleteLater()
- -{
- - if (!m_listener) {
- - return;
- - }
- -
- - m_listener = nullptr;
- -
- - if (!disconnect()) {
- - delete this;
- - }
- -}
- -
- -
- void Client::setUrl(const Url *url)
- {
- if (!url || !url->isValid()) {
- @@ -187,12 +171,7 @@ int64_t Client::submit(const JobResult &result)
- const size_t size = snprintf(m_sendBuf, sizeof(m_sendBuf), "{\"id\":%" PRIu64 ",\"jsonrpc\":\"2.0\",\"method\":\"submit\",\"params\":{\"id\":\"%s\",\"job_id\":\"%s\",\"nonce\":\"%s\",\"result\":\"%s\"}}\n",
- m_sequence, m_rpcId.data(), result.jobId.data(), nonce, data);
- -# ifdef XMRIG_PROXY_PROJECT
- - m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff(), result.id);
- -# else
- m_results[m_sequence] = SubmitResult(m_sequence, result.diff, result.actualDiff());
- -# endif
- -
- return send(size);
- }
- @@ -205,28 +184,7 @@ bool Client::close()
- setState(ClosingState);
- - uv_stream_t *stream = reinterpret_cast<uv_stream_t*>(m_socket);
- -
- - if (uv_is_readable(stream) == 1) {
- - uv_read_stop(stream);
- - }
- -
- - if (uv_is_writable(stream) == 1) {
- - const int rc = uv_shutdown(new uv_shutdown_t, stream, [](uv_shutdown_t* req, int status) {
- - if (uv_is_closing(reinterpret_cast<uv_handle_t*>(req->handle)) == 0) {
- - uv_close(reinterpret_cast<uv_handle_t*>(req->handle), Client::onClose);
- - }
- -
- - delete req;
- - });
- -
- - assert(rc == 0);
- -
- - if (rc != 0) {
- - onClose();
- - }
- - }
- - else {
- + if (uv_is_closing(reinterpret_cast<uv_handle_t*>(m_socket)) == 0) {
- uv_close(reinterpret_cast<uv_handle_t*>(m_socket), Client::onClose);
- }
- @@ -263,14 +221,7 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code)
- return false;
- }
- -# ifdef XMRIG_PROXY_PROJECT
- - Job job(m_id, m_url.variant());
- - job.setClientId(m_rpcId);
- - job.setCoin(m_url.coin());
- -# else
- Job job(m_id, m_nicehash, m_url.algo(), m_url.variant());
- -# endif
- -
- if (!job.setId(params["job_id"].GetString())) {
- *code = 3;
- return false;
- @@ -294,22 +245,17 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code)
- job.setVariant(params["variant"].GetInt());
- }
- - if (m_job != job) {
- - m_jobs++;
- - m_job = std::move(job);
- - return true;
- - }
- + if (m_job == job) {
- + if (!m_quiet) {
- + LOG_WARN("[%s:%u] duplicate job received, reconnect", m_url.host(), m_url.port());
- + }
- - if (m_jobs == 0) { // https://github.com/xmrig/xmrig/issues/459
- + close();
- return false;
- }
- - if (!m_quiet) {
- - LOG_WARN("[%s:%u] duplicate job received, reconnect", m_url.host(), m_url.port());
- - }
- -
- - close();
- - return false;
- + m_job = std::move(job);
- + return true;
- }
- @@ -320,18 +266,13 @@ bool Client::parseLogin(const rapidjson::Value &result, int *code)
- return false;
- }
- -# ifndef XMRIG_PROXY_PROJECT
- m_nicehash = m_url.isNicehash();
- -# endif
- if (result.HasMember("extensions")) {
- parseExtensions(result["extensions"]);
- }
- - const bool rc = parseJob(result["job"], code);
- - m_jobs = 0;
- -
- - return rc;
- + return parseJob(result["job"], code);
- }
- @@ -346,7 +287,7 @@ int Client::resolve(const char *host)
- m_failures = 0;
- }
- - const int r = uv_getaddrinfo(uv_default_loop(), &m_resolver, Client::onResolved, host, nullptr, &m_hints);
- + const int r = uv_getaddrinfo(uv_default_loop(), &m_resolver, Client::onResolved, host, NULL, &m_hints);
- if (r) {
- if (!m_quiet) {
- LOG_ERR("[%s:%u] getaddrinfo error: \"%s\"", host, m_url.port(), uv_strerror(r));
- @@ -457,18 +398,6 @@ void Client::login()
- }
- -void Client::onClose()
- -{
- - delete m_socket;
- -
- - m_stream = nullptr;
- - m_socket = nullptr;
- - setState(UnconnectedState);
- -
- - reconnect();
- -}
- -
- -
- void Client::parse(char *line, size_t len)
- {
- startTimeout();
- @@ -478,10 +407,7 @@ void Client::parse(char *line, size_t len)
- LOG_DEBUG("[%s:%u] received (%d bytes): \"%s\"", m_url.host(), m_url.port(), len, line);
- if (len < 32 || line[0] != '{') {
- - if (!m_quiet) {
- - LOG_ERR("[%s:%u] JSON decode failed", m_url.host(), m_url.port());
- - }
- -
- + LOG_ERR("[%s:%u] JSON decode failed", m_url.host(), m_url.port());
- return;
- }
- @@ -612,12 +538,6 @@ void Client::ping()
- void Client::reconnect()
- {
- - if (!m_listener) {
- - delete this;
- -
- - return;
- - }
- -
- setState(ConnectingState);
- # ifndef XMRIG_PROXY_PROJECT
- @@ -666,9 +586,6 @@ void Client::startTimeout()
- void Client::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf)
- {
- auto client = getClient(handle->data);
- - if (!client) {
- - return;
- - }
- buf->base = &client->m_recvBuf.base[client->m_recvBufPos];
- buf->len = client->m_recvBuf.len - client->m_recvBufPos;
- @@ -678,21 +595,20 @@ void Client::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t
- void Client::onClose(uv_handle_t *handle)
- {
- auto client = getClient(handle->data);
- - if (!client) {
- - return;
- - }
- - client->onClose();
- + delete client->m_socket;
- +
- + client->m_stream = nullptr;
- + client->m_socket = nullptr;
- + client->setState(UnconnectedState);
- +
- + client->reconnect();
- }
- void Client::onConnect(uv_connect_t *req, int status)
- {
- auto client = getClient(req->data);
- - if (!client) {
- - return;
- - }
- -
- if (status < 0) {
- if (!client->m_quiet) {
- LOG_ERR("[%s:%u] connect error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror(status));
- @@ -717,10 +633,6 @@ void Client::onConnect(uv_connect_t *req, int status)
- void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
- {
- auto client = getClient(stream->data);
- - if (!client) {
- - return;
- - }
- -
- if (nread < 0) {
- if (nread != UV_EOF && !client->m_quiet) {
- LOG_ERR("[%s:%u] read error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror((int) nread));
- @@ -767,15 +679,8 @@ void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
- void Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res)
- {
- auto client = getClient(req->data);
- - if (!client) {
- - return;
- - }
- -
- if (status < 0) {
- - if (!client->m_quiet) {
- - LOG_ERR("[%s:%u] DNS error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror(status));
- - }
- -
- + LOG_ERR("[%s:%u] DNS error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror(status));
- return client->reconnect();
- }
- @@ -796,9 +701,7 @@ void Client::onResolved(uv_getaddrinfo_t *req, int status, struct addrinfo *res)
- }
- if (ipv4.empty() && ipv6.empty()) {
- - if (!client->m_quiet) {
- - LOG_ERR("[%s:%u] DNS error: \"No IPv4 (A) or IPv6 (AAAA) records found\"", client->m_url.host(), client->m_url.port());
- - }
- + LOG_ERR("[%s:%u] DNS error: \"No IPv4 (A) or IPv6 (AAAA) records found\"", client->m_url.host(), client->m_url.port());
- uv_freeaddrinfo(res);
- return client->reconnect();
- diff --git a/src/net/Client.h b/src/net/Client.h
- index fff7a15..f5cb91f 100644
- --- a/src/net/Client.h
- +++ b/src/net/Client.h
- @@ -30,7 +30,7 @@
- #include <vector>
- -#include "net/Id.h"
- +#include "net/JobId.h"
- #include "net/Job.h"
- #include "net/SubmitResult.h"
- #include "net/Url.h"
- @@ -56,16 +56,17 @@ public:
- constexpr static int kKeepAliveTimeout = 60 * 1000;
- Client(int id, const char *agent, IClientListener *listener);
- + ~Client();
- bool disconnect();
- int64_t submit(const JobResult &result);
- void connect();
- void connect(const Url *url);
- - void deleteLater();
- void setUrl(const Url *url);
- void tick(uint64_t now);
- inline bool isReady() const { return m_state == ConnectedState && m_failures == 0; }
- + inline const char *user() const { return m_url.user(); }
- inline const char *host() const { return m_url.host(); }
- inline const char *ip() const { return m_ip; }
- inline const Job &job() const { return m_job; }
- @@ -76,8 +77,6 @@ public:
- inline void setRetryPause(int ms) { m_retryPause = ms; }
- private:
- - ~Client();
- -
- bool close();
- bool isCriticalError(const char *message);
- bool parseJob(const rapidjson::Value ¶ms, int *code);
- @@ -87,7 +86,6 @@ private:
- void connect(const std::vector<addrinfo*> &ipv4, const std::vector<addrinfo*> &ipv6);
- void connect(sockaddr *addr);
- void login();
- - void onClose();
- void parse(char *line, size_t len);
- void parseExtensions(const rapidjson::Value &value);
- void parseNotification(const char *method, const rapidjson::Value ¶ms, const rapidjson::Value &error);
- @@ -123,13 +121,12 @@ private:
- static int64_t m_sequence;
- std::map<int64_t, SubmitResult> m_results;
- uint64_t m_expire;
- - uint64_t m_jobs;
- Url m_url;
- uv_buf_t m_recvBuf;
- uv_getaddrinfo_t m_resolver;
- uv_stream_t *m_stream;
- uv_tcp_t *m_socket;
- - xmrig::Id m_rpcId;
- + JobId m_rpcId;
- # ifndef XMRIG_PROXY_PROJECT
- uv_timer_t m_keepAliveTimer;
- @@ -137,4 +134,4 @@ private:
- };
- -#endif /* __CLIENT_H__ */
- +#endif /* __CLIENT_H__ */
- \ No newline at end of file
- diff --git a/src/net/Job.cpp b/src/net/Job.cpp
- index 7d137fa..93a3d4e 100644
- --- a/src/net/Job.cpp
- +++ b/src/net/Job.cpp
- @@ -59,10 +59,10 @@ static inline char hf_bin2hex(unsigned char c)
- Job::Job() :
- m_nicehash(false),
- m_coin(),
- - m_algo(xmrig::ALGO_CRYPTONIGHT),
- + m_algo(Options::ALGO_CRYPTONIGHT),
- m_poolId(-2),
- m_threadId(-1),
- - m_variant(xmrig::VARIANT_AUTO),
- + m_variant(Options::VARIANT_AUTO),
- m_size(0),
- m_diff(0),
- m_target(0),
- @@ -164,16 +164,16 @@ void Job::setCoin(const char *coin)
- }
- strncpy(m_coin, coin, sizeof(m_coin));
- - m_algo = strcmp(m_coin, "AEON") == 0 ? xmrig::ALGO_CRYPTONIGHT_LITE : xmrig::ALGO_CRYPTONIGHT;
- + m_algo = strcmp(m_coin, "AEON") == 0 ? Options::ALGO_CRYPTONIGHT_LITE : Options::ALGO_CRYPTONIGHT;
- }
- void Job::setVariant(int variant)
- {
- switch (variant) {
- - case xmrig::VARIANT_AUTO:
- - case xmrig::VARIANT_NONE:
- - case xmrig::VARIANT_V1:
- + case Options::VARIANT_AUTO:
- + case Options::VARIANT_NONE:
- + case Options::VARIANT_V1:
- m_variant = variant;
- break;
- @@ -210,9 +210,3 @@ bool Job::operator==(const Job &other) const
- {
- return m_id == other.m_id && memcmp(m_blob, other.m_blob, sizeof(m_blob)) == 0;
- }
- -
- -
- -bool Job::operator!=(const Job &other) const
- -{
- - return m_id != other.m_id || memcmp(m_blob, other.m_blob, sizeof(m_blob)) != 0;
- -}
- diff --git a/src/net/Job.h b/src/net/Job.h
- index b8b9d6b..e1718df 100644
- --- a/src/net/Job.h
- +++ b/src/net/Job.h
- @@ -30,8 +30,8 @@
- #include <stdint.h>
- -#include "net/Id.h"
- -#include "xmrig.h"
- +#include "net/JobId.h"
- +#include "Options.h"
- class Job
- @@ -52,16 +52,15 @@ public:
- inline const char *coin() const { return m_coin; }
- inline const uint32_t *nonce() const { return reinterpret_cast<const uint32_t*>(m_blob + 39); }
- inline const uint8_t *blob() const { return m_blob; }
- - inline const xmrig::Id &id() const { return m_id; }
- + inline const JobId &id() const { return m_id; }
- inline int poolId() const { return m_poolId; }
- inline int threadId() const { return m_threadId; }
- - inline int variant() const { return (m_variant == xmrig::VARIANT_AUTO ? (m_blob[0] > 6 ? 1 : 0) : m_variant); }
- + inline int variant() const { return (m_variant == Options::VARIANT_AUTO ? (m_blob[0] > 6 ? 1 : 0) : m_variant); }
- inline size_t size() const { return m_size; }
- inline uint32_t *nonce() { return reinterpret_cast<uint32_t*>(m_blob + 39); }
- inline uint32_t diff() const { return (uint32_t) m_diff; }
- inline uint64_t target() const { return m_target; }
- inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
- - inline void setPoolId(int poolId) { m_poolId = poolId; }
- inline void setThreadId(int threadId) { m_threadId = threadId; }
- static bool fromHex(const char* in, unsigned int len, unsigned char* out);
- @@ -70,7 +69,6 @@ public:
- static void toHex(const unsigned char* in, unsigned int len, char* out);
- bool operator==(const Job &other) const;
- - bool operator!=(const Job &other) const;
- private:
- bool m_nicehash;
- @@ -83,7 +81,7 @@ private:
- uint64_t m_diff;
- uint64_t m_target;
- uint8_t m_blob[96]; // Max blob size is 84 (75 fixed + 9 variable), aligned to 96. https://github.com/xmrig/xmrig/issues/1 Thanks fireice-uk.
- - xmrig::Id m_id;
- + JobId m_id;
- };
- #endif /* __JOB_H__ */
- diff --git a/src/net/JobId.h b/src/net/JobId.h
- new file mode 100644
- index 0000000..0618977
- --- /dev/null
- +++ b/src/net/JobId.h
- @@ -0,0 +1,83 @@
- +/* XMRig
- + * Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
- + * Copyright 2012-2014 pooler <pooler@litecoinpool.org>
- + * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
- + * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
- + * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
- + * Copyright 2016-2017 XMRig <support@xmrig.com>
- + *
- + *
- + * This program is free software: you can redistribute it and/or modify
- + * it under the terms of the GNU General Public License as published by
- + * the Free Software Foundation, either version 3 of the License, or
- + * (at your option) any later version.
- + *
- + * This program is distributed in the hope that it will be useful,
- + * but WITHOUT ANY WARRANTY; without even the implied warranty of
- + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- + * GNU General Public License for more details.
- + *
- + * You should have received a copy of the GNU General Public License
- + * along with this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +
- +#ifndef __JOBID_H__
- +#define __JOBID_H__
- +
- +
- +#include <string.h>
- +
- +
- +class JobId
- +{
- +public:
- + inline JobId()
- + {
- + memset(m_data, 0, sizeof(m_data));
- + }
- +
- +
- + inline JobId(const char *id, size_t sizeFix = 0)
- + {
- + setId(id, sizeFix);
- + }
- +
- +
- + inline bool operator==(const JobId &other) const
- + {
- + return memcmp(m_data, other.m_data, sizeof(m_data)) == 0;
- + }
- +
- +
- + inline bool operator!=(const JobId &other) const
- + {
- + return memcmp(m_data, other.m_data, sizeof(m_data)) != 0;
- + }
- +
- +
- + inline bool setId(const char *id, size_t sizeFix = 0)
- + {
- + memset(m_data, 0, sizeof(m_data));
- + if (!id) {
- + return false;
- + }
- +
- + const size_t size = strlen(id);
- + if (size >= sizeof(m_data)) {
- + return false;
- + }
- +
- + memcpy(m_data, id, size - sizeFix);
- + return true;
- + }
- +
- +
- + inline const char *data() const { return m_data; }
- + inline bool isValid() const { return *m_data != '\0'; }
- +
- +
- +private:
- + char m_data[64];
- +};
- +
- +#endif /* __JOBID_H__ */
- diff --git a/src/net/JobResult.h b/src/net/JobResult.h
- index e328258..b9000f1 100644
- --- a/src/net/JobResult.h
- +++ b/src/net/JobResult.h
- @@ -36,11 +36,11 @@ class JobResult
- {
- public:
- inline JobResult() : poolId(0), diff(0), nonce(0) {}
- - inline JobResult(int poolId, const xmrig::Id &jobId, uint32_t nonce, const uint8_t *result, uint32_t diff) :
- + inline JobResult(int poolId, const JobId &jobId, uint32_t nonce, const uint8_t *result, uint32_t diff) :
- poolId(poolId),
- + jobId(jobId),
- diff(diff),
- - nonce(nonce),
- - jobId(jobId)
- + nonce(nonce)
- {
- memcpy(this->result, result, sizeof(this->result));
- }
- @@ -71,10 +71,10 @@ public:
- int poolId;
- + JobId jobId;
- uint32_t diff;
- uint32_t nonce;
- uint8_t result[32];
- - xmrig::Id jobId;
- };
- #endif /* __JOBRESULT_H__ */
- diff --git a/src/net/Network.cpp b/src/net/Network.cpp
- index ede3f8b..ce2565d 100644
- --- a/src/net/Network.cpp
- +++ b/src/net/Network.cpp
- @@ -4,8 +4,8 @@
- * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
- * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
- * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
- - * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
- - * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
- + * Copyright 2016-2017 XMRig <support@xmrig.com>
- + *
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- @@ -40,6 +40,7 @@
- #include "net/SubmitResult.h"
- #include "net/Url.h"
- #include "Options.h"
- +#include "Platform.h"
- #include "workers/Workers.h"
- @@ -54,15 +55,13 @@ Network::Network(const Options *options) :
- const std::vector<Url*> &pools = options->pools();
- if (pools.size() > 1) {
- - m_strategy = new FailoverStrategy(pools, options->retryPause(), options->retries(), this);
- + m_strategy = new FailoverStrategy(pools, Platform::versionString(), this);
- }
- else {
- - m_strategy = new SinglePoolStrategy(pools.front(), options->retryPause(), this);
- + m_strategy = new SinglePoolStrategy(pools.front(), Platform::versionString(), this);
- }
- - if (m_options->donateLevel() > 0) {
- - m_donate = new DonateStrategy(options->donateLevel(), options->pools().front()->user(), options->algo(), this);
- - }
- + m_donate = new DonateStrategy(Platform::versionString(), this);
- m_timer.data = this;
- uv_timer_init(uv_default_loop(), &m_timer);
- @@ -84,40 +83,37 @@ void Network::connect()
- void Network::stop()
- {
- - if (m_donate) {
- - m_donate->stop();
- - }
- -
- + m_donate->stop();
- m_strategy->stop();
- }
- -void Network::onActive(IStrategy *strategy, Client *client)
- +void Network::onActive(Client *client)
- {
- - if (m_donate && m_donate == strategy) {
- - LOG_NOTICE("dev donate started");
- + if (client->id() == -1) {
- return;
- }
- m_state.setPool(client->host(), client->port(), client->ip());
- + m_state.setUserMask(client->user());
- LOG_INFO(m_options->colors() ? "\x1B[01;37muse pool \x1B[01;36m%s:%d \x1B[01;30m%s" : "use pool %s:%d %s", client->host(), client->port(), client->ip());
- }
- -void Network::onJob(IStrategy *strategy, Client *client, const Job &job)
- +void Network::onJob(Client *client, const Job &job)
- {
- - if (m_donate && m_donate->isActive() && m_donate != strategy) {
- + if (m_donate->isActive() && client->id() != -1) {
- return;
- }
- - setJob(client, job, m_donate == strategy);
- + setJob(client, job);
- }
- void Network::onJobResult(const JobResult &result)
- {
- - if (result.poolId == -1 && m_donate) {
- + if (result.poolId == -1) {
- m_donate->submit(result);
- return;
- }
- @@ -128,38 +124,53 @@ void Network::onJobResult(const JobResult &result)
- void Network::onPause(IStrategy *strategy)
- {
- - if (m_donate && m_donate == strategy) {
- - LOG_NOTICE("dev donate finished");
- + if (m_donate == strategy) {
- m_strategy->resume();
- }
- if (!m_strategy->isActive()) {
- - LOG_ERR("no active pools, stop mining");
- m_state.stop();
- return Workers::pause();
- }
- }
- -void Network::onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error)
- +void Network::onResultAccepted(Client *client, const SubmitResult &result, const char *error)
- {
- m_state.add(result, error);
- - if (error) {
- - LOG_INFO(m_options->colors() ? "\x1B[01;31mrejected\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[31m\"%s\"\x1B[0m \x1B[01;30m(%" PRIu64 " ms)"
- + if (client->id() == -1) {
- + if (error) {
- + LOG_INFO(m_options->colors() ? "\x1B[01;33mdonation rejected\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[31m\"%s\"\x1B[0m \x1B[01;30m(%" PRIu64 " ms)"
- : "rejected (%" PRId64 "/%" PRId64 ") diff %u \"%s\" (%" PRIu64 " ms)",
- m_state.accepted, m_state.rejected, result.diff, error, result.elapsed);
- - }
- - else {
- - LOG_INFO(m_options->colors() ? "\x1B[01;32maccepted\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[01;30m(%" PRIu64 " ms)"
- - : "accepted (%" PRId64 "/%" PRId64 ") diff %u (%" PRIu64 " ms)",
- - m_state.accepted, m_state.rejected, result.diff, result.elapsed);
- + }
- + else {
- + LOG_INFO(m_options->colors() ? "\x1B[01;33mdonation accepted\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[01;30m(%" PRIu64 " ms)"
- + : "accepted (%" PRId64 "/%" PRId64 ") diff %u (%" PRIu64 " ms)",
- + m_state.accepted, m_state.rejected, result.diff, result.elapsed);
- + }
- + } else {
- + if (error) {
- + LOG_INFO(m_options->colors() ? "\x1B[01;31mrejected\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[31m\"%s\"\x1B[0m \x1B[01;30m(%" PRIu64 " ms)"
- + : "rejected (%" PRId64 "/%" PRId64 ") diff %u \"%s\" (%" PRIu64 " ms)",
- + m_state.accepted, m_state.rejected, result.diff, error, result.elapsed);
- + }
- + else {
- + LOG_INFO(m_options->colors() ? "\x1B[01;32maccepted\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[01;30m(%" PRIu64 " ms)"
- + : "accepted (%" PRId64 "/%" PRId64 ") diff %u (%" PRIu64 " ms)",
- + m_state.accepted, m_state.rejected, result.diff, result.elapsed);
- + }
- }
- }
- -void Network::setJob(Client *client, const Job &job, bool donate)
- +void Network::setJob(Client *client, const Job &job)
- {
- + if (client->id() == -1) {
- + return;
- + }
- +
- if (m_options->colors()) {
- LOG_INFO("\x1B[01;35mnew job\x1B[0m from \x1B[01;37m%s:%d\x1B[0m diff \x1B[01;37m%d", client->host(), client->port(), job.diff());
- }
- @@ -168,7 +179,7 @@ void Network::setJob(Client *client, const Job &job, bool donate)
- }
- m_state.diff = job.diff();
- - Workers::setJob(job, donate);
- + Workers::setJob(job);
- }
- @@ -177,10 +188,7 @@ void Network::tick()
- const uint64_t now = uv_now(uv_default_loop());
- m_strategy->tick(now);
- -
- - if (m_donate) {
- - m_donate->tick(now);
- - }
- + m_donate->tick(now);
- # ifndef XMRIG_NO_API
- Api::tick(m_state);
- @@ -191,4 +199,4 @@ void Network::tick()
- void Network::onTick(uv_timer_t *handle)
- {
- static_cast<Network*>(handle->data)->tick();
- -}
- +}
- \ No newline at end of file
- diff --git a/src/net/Network.h b/src/net/Network.h
- index fae5c56..fe13d9b 100644
- --- a/src/net/Network.h
- +++ b/src/net/Network.h
- @@ -4,8 +4,8 @@
- * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
- * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
- * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
- - * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
- - * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
- + * Copyright 2016-2017 XMRig <support@xmrig.com>
- + *
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- @@ -49,16 +49,16 @@ public:
- void stop();
- protected:
- - void onActive(IStrategy *strategy, Client *client) override;
- - void onJob(IStrategy *strategy, Client *client, const Job &job) override;
- + void onActive(Client *client) override;
- + void onJob(Client *client, const Job &job) override;
- void onJobResult(const JobResult &result) override;
- void onPause(IStrategy *strategy) override;
- - void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) override;
- + void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override;
- private:
- constexpr static int kTickInterval = 1 * 1000;
- - void setJob(Client *client, const Job &job, bool donate);
- + void setJob(Client *client, const Job &job);
- void tick();
- static void onTick(uv_timer_t *handle);
- diff --git a/src/net/Url.cpp b/src/net/Url.cpp
- index c17ef69..f090826 100644
- --- a/src/net/Url.cpp
- +++ b/src/net/Url.cpp
- @@ -28,7 +28,6 @@
- #include "net/Url.h"
- -#include "xmrig.h"
- #ifdef _MSC_VER
- @@ -42,8 +41,8 @@ Url::Url() :
- m_host(nullptr),
- m_password(nullptr),
- m_user(nullptr),
- - m_algo(xmrig::ALGO_CRYPTONIGHT),
- - m_variant(xmrig::VARIANT_AUTO),
- + m_algo(Options::ALGO_CRYPTONIGHT),
- + m_variant(Options::VARIANT_AUTO),
- m_url(nullptr),
- m_port(kDefaultPort)
- {
- @@ -67,8 +66,8 @@ Url::Url(const char *url) :
- m_host(nullptr),
- m_password(nullptr),
- m_user(nullptr),
- - m_algo(xmrig::ALGO_CRYPTONIGHT),
- - m_variant(xmrig::VARIANT_AUTO),
- + m_algo(Options::ALGO_CRYPTONIGHT),
- + m_variant(Options::VARIANT_AUTO),
- m_url(nullptr),
- m_port(kDefaultPort)
- {
- @@ -81,7 +80,7 @@ Url::Url(const char *host, uint16_t port, const char *user, const char *password
- m_nicehash(nicehash),
- m_password(password ? strdup(password) : nullptr),
- m_user(user ? strdup(user) : nullptr),
- - m_algo(xmrig::ALGO_CRYPTONIGHT),
- + m_algo(Options::ALGO_CRYPTONIGHT),
- m_variant(variant),
- m_url(nullptr),
- m_port(port)
- @@ -130,6 +129,7 @@ bool Url::parse(const char *url)
- }
- const size_t size = port++ - base + 1;
- +
- m_host = new char[size]();
- memcpy(m_host, base, size - 1);
- @@ -138,24 +138,6 @@ bool Url::parse(const char *url)
- }
- -bool Url::setUserpass(const char *userpass)
- -{
- - const char *p = strchr(userpass, ':');
- - if (!p) {
- - return false;
- - }
- -
- - free(m_user);
- - free(m_password);
- -
- - m_user = static_cast<char*>(calloc(p - userpass + 1, 1));
- - strncpy(m_user, userpass, p - userpass);
- - m_password = strdup(p + 1);
- -
- - return true;
- -}
- -
- -
- const char *Url::url() const
- {
- if (!m_url) {
- @@ -169,14 +151,26 @@ const char *Url::url() const
- }
- -void Url::adjust(int algo)
- +void Url::setAlgo(int algo)
- +{
- + switch (algo) {
- + case Options::ALGO_CRYPTONIGHT:
- + case Options::ALGO_CRYPTONIGHT_LITE:
- + m_algo = algo;
- + break;
- +
- + default:
- + break;
- + }
- +}
- +
- +
- +void Url::applyExceptions()
- {
- if (!isValid()) {
- return;
- }
- - m_algo = algo;
- -
- if (strstr(m_host, ".nicehash.com")) {
- m_keepAlive = false;
- m_nicehash = true;
- @@ -212,16 +206,16 @@ void Url::setUser(const char *user)
- void Url::setVariant(int variant)
- {
- - switch (variant) {
- - case xmrig::VARIANT_AUTO:
- - case xmrig::VARIANT_NONE:
- - case xmrig::VARIANT_V1:
- - m_variant = variant;
- - break;
- -
- - default:
- - break;
- - }
- + switch (variant) {
- + case Options::VARIANT_AUTO:
- + case Options::VARIANT_NONE:
- + case Options::VARIANT_V1:
- + m_variant = variant;
- + break;
- +
- + default:
- + break;
- + }
- }
- diff --git a/src/net/Url.h b/src/net/Url.h
- index f861fec..661443a 100644
- --- a/src/net/Url.h
- +++ b/src/net/Url.h
- @@ -26,6 +26,7 @@
- #include <stdint.h>
- +#include "Options.h"
- class Url
- @@ -37,7 +38,7 @@ public:
- Url();
- Url(const char *url);
- - Url(const char *host, uint16_t port, const char *user = nullptr, const char *password = nullptr, bool keepAlive = false, bool nicehash = false, int variant = -1);
- + Url(const char *host, uint16_t port, const char *user = nullptr, const char *password = nullptr, bool keepAlive = false, bool nicehash = false, int variant = Options::VARIANT_AUTO);
- ~Url();
- inline bool isKeepAlive() const { return m_keepAlive; }
- @@ -54,12 +55,12 @@ public:
- inline void setVariant(bool monero) { m_variant = monero; }
- bool parse(const char *url);
- - bool setUserpass(const char *userpass);
- const char *url() const;
- - void adjust(int algo);
- + void setAlgo(int algo);
- void setPassword(const char *password);
- void setUser(const char *user);
- void setVariant(int variant);
- + void applyExceptions();
- bool operator==(const Url &other) const;
- Url &operator=(const Url *other);
- diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp
- index ae707e2..3d267d7 100644
- --- a/src/net/strategies/DonateStrategy.cpp
- +++ b/src/net/strategies/DonateStrategy.cpp
- @@ -4,8 +4,8 @@
- * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
- * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
- * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
- - * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
- - * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
- + * Copyright 2016-2017 XMRig <support@xmrig.com>
- + *
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- @@ -24,11 +24,8 @@
- #include "interfaces/IStrategyListener.h"
- #include "net/Client.h"
- -#include "net/Job.h"
- #include "net/strategies/DonateStrategy.h"
- -#include "net/strategies/FailoverStrategy.h"
- -#include "Platform.h"
- -#include "xmrig.h"
- +#include "Options.h"
- extern "C"
- @@ -37,120 +34,111 @@ extern "C"
- }
- -const static char *kDonatePool1 = "miner.fee.xmrig.com";
- -const static char *kDonatePool2 = "emergency.fee.xmrig.com";
- -
- -
- -static inline int random(int min, int max){
- - return min + rand() / (RAND_MAX / (max - min + 1) + 1);
- -}
- -
- -
- -DonateStrategy::DonateStrategy(int level, const char *user, int algo, IStrategyListener *listener) :
- +DonateStrategy::DonateStrategy(const char *agent, IStrategyListener *listener) :
- m_active(false),
- - m_donateTime(level * 60 * 1000),
- - m_idleTime((100 - level) * 60 * 1000),
- - m_strategy(nullptr),
- + m_client(nullptr),
- m_listener(listener)
- {
- - uint8_t hash[200];
- - char userId[65] = { 0 };
- + if (DONATESTRATEGY_TIME > 0) {
- + if (Options::i()->algo() == Options::ALGO_CRYPTONIGHT) {
- + Url *url = new Url("cryptonight.eu.nicehash.com", 3355, "3EXnQ9TLnco6hqjL8S7685YF7mgkaN4LFq", nullptr, false, true);
- - keccak(reinterpret_cast<const uint8_t *>(user), static_cast<int>(strlen(user)), hash, sizeof(hash));
- - Job::toHex(hash, 32, userId);
- + m_client = new Client(-1, agent, this);
- + m_client->setUrl(url);
- + m_client->setRetryPause(Options::i()->retryPause() * 1000);
- + m_client->setQuiet(true);
- - if (algo == xmrig::ALGO_CRYPTONIGHT) {
- - m_pools.push_back(new Url(kDonatePool1, 6666, userId, nullptr, false, true));
- - m_pools.push_back(new Url(kDonatePool1, 80, userId, nullptr, false, true));
- - m_pools.push_back(new Url(kDonatePool2, 5555, "48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD", "emergency", false, false));
- - }
- - else {
- - m_pools.push_back(new Url(kDonatePool1, 5555, userId, nullptr, false, true));
- - m_pools.push_back(new Url(kDonatePool1, 7777, userId, nullptr, false, true));
- + delete url;
- + }
- }
- - m_strategy = new FailoverStrategy(m_pools, 1, 1, this, true);
- + if (m_client) {
- + m_timer.data = this;
- + uv_timer_init(uv_default_loop(), &m_timer);
- - m_timer.data = this;
- - uv_timer_init(uv_default_loop(), &m_timer);
- -
- - idle(random(3000, 9000) * 1000 - m_donateTime);
- -}
- -
- -
- -DonateStrategy::~DonateStrategy()
- -{
- - delete m_strategy;
- + connect();
- + }
- }
- int64_t DonateStrategy::submit(const JobResult &result)
- {
- - return m_strategy->submit(result);
- + if (m_client) {
- + return m_client->submit(result);
- + }
- + return -1;
- }
- void DonateStrategy::connect()
- {
- - m_strategy->connect();
- + if (m_client) {
- + m_client->connect();
- + }
- }
- void DonateStrategy::stop()
- {
- uv_timer_stop(&m_timer);
- - m_strategy->stop();
- + if (m_client) {
- + m_client->disconnect();
- + }
- }
- void DonateStrategy::tick(uint64_t now)
- {
- - m_strategy->tick(now);
- + if (m_client) {
- + m_client->tick(now);
- + }
- }
- -void DonateStrategy::onActive(IStrategy *strategy, Client *client)
- +void DonateStrategy::onClose(Client *client, int failures)
- {
- - if (!isActive()) {
- - uv_timer_start(&m_timer, DonateStrategy::onTimer, m_donateTime, 0);
- - }
- -
- - m_active = true;
- - m_listener->onActive(this, client);
- }
- -void DonateStrategy::onJob(IStrategy *strategy, Client *client, const Job &job)
- +void DonateStrategy::onJobReceived(Client *client, const Job &job)
- {
- - m_listener->onJob(this, client, job);
- + m_listener->onJob(client, job);
- }
- -void DonateStrategy::onPause(IStrategy *strategy)
- +void DonateStrategy::onLoginSuccess(Client *client)
- {
- + if (!isActive()) {
- + uv_timer_start(&m_timer, DonateStrategy::onTimer, DONATESTRATEGY_TIME, 0);
- + }
- +
- + m_active = true;
- + m_listener->onActive(client);
- }
- -void DonateStrategy::onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error)
- +void DonateStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error)
- {
- - m_listener->onResultAccepted(this, client, result, error);
- + m_listener->onResultAccepted(client, result, error);
- }
- -void DonateStrategy::idle(uint64_t timeout)
- +void DonateStrategy::idle()
- {
- - uv_timer_start(&m_timer, DonateStrategy::onTimer, timeout, 0);
- + uv_timer_start(&m_timer, DonateStrategy::onTimer, DONATESTRATEGY_INTERVAL - DONATESTRATEGY_TIME, 0);
- }
- void DonateStrategy::suspend()
- {
- - m_strategy->stop();
- + if (m_client) {
- + m_client->disconnect();
- + }
- m_active = false;
- m_listener->onPause(this);
- - idle(m_idleTime);
- + idle();
- }
- @@ -163,4 +151,4 @@ void DonateStrategy::onTimer(uv_timer_t *handle)
- }
- strategy->suspend();
- -}
- +}
- \ No newline at end of file
- diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h
- index 4ef2995..0f3940c 100644
- --- a/src/net/strategies/DonateStrategy.h
- +++ b/src/net/strategies/DonateStrategy.h
- @@ -4,8 +4,8 @@
- * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
- * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
- * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
- - * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
- - * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
- + * Copyright 2016-2017 XMRig <support@xmrig.com>
- + *
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- @@ -23,15 +23,14 @@
- #ifndef __DONATESTRATEGY_H__
- #define __DONATESTRATEGY_H__
- -
- +#define DONATESTRATEGY_TIME 1.2e+5
- +#define DONATESTRATEGY_INTERVAL 1.2e+7
- #include <uv.h>
- -#include <vector>
- #include "interfaces/IClientListener.h"
- #include "interfaces/IStrategy.h"
- -#include "interfaces/IStrategyListener.h"
- class Client;
- @@ -39,11 +38,10 @@ class IStrategyListener;
- class Url;
- -class DonateStrategy : public IStrategy, public IStrategyListener
- +class DonateStrategy : public IStrategy, public IClientListener
- {
- public:
- - DonateStrategy(int level, const char *user, int algo, IStrategyListener *listener);
- - ~DonateStrategy();
- + DonateStrategy(const char *agent, IStrategyListener *listener);
- public:
- inline bool isActive() const override { return m_active; }
- @@ -55,24 +53,21 @@ public:
- void tick(uint64_t now) override;
- protected:
- - void onActive(IStrategy *strategy, Client *client) override;
- - void onJob(IStrategy *strategy, Client *client, const Job &job) override;
- - void onPause(IStrategy *strategy) override;
- - void onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error) override;
- + void onClose(Client *client, int failures) override;
- + void onJobReceived(Client *client, const Job &job) override;
- + void onLoginSuccess(Client *client) override;
- + void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override;
- private:
- - void idle(uint64_t timeout);
- + void idle();
- void suspend();
- static void onTimer(uv_timer_t *handle);
- bool m_active;
- - const int m_donateTime;
- - const int m_idleTime;
- - IStrategy *m_strategy;
- + Client *m_client;
- IStrategyListener *m_listener;
- - std::vector<Url*> m_pools;
- uv_timer_t m_timer;
- };
- -#endif /* __DONATESTRATEGY_H__ */
- +#endif /* __DONATESTRATEGY_H__ */
- \ No newline at end of file
- diff --git a/src/net/strategies/FailoverStrategy.cpp b/src/net/strategies/FailoverStrategy.cpp
- index dbfeb31..47d390b 100644
- --- a/src/net/strategies/FailoverStrategy.cpp
- +++ b/src/net/strategies/FailoverStrategy.cpp
- @@ -4,8 +4,8 @@
- * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
- * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
- * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
- - * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
- - * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
- + * Copyright 2016-2017 XMRig <support@xmrig.com>
- + *
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- @@ -25,37 +25,22 @@
- #include "interfaces/IStrategyListener.h"
- #include "net/Client.h"
- #include "net/strategies/FailoverStrategy.h"
- -#include "Platform.h"
- +#include "Options.h"
- -FailoverStrategy::FailoverStrategy(const std::vector<Url*> &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet) :
- - m_quiet(quiet),
- - m_retries(retries),
- - m_retryPause(retryPause),
- +FailoverStrategy::FailoverStrategy(const std::vector<Url*> &urls, const char *agent, IStrategyListener *listener) :
- m_active(-1),
- m_index(0),
- m_listener(listener)
- {
- for (const Url *url : urls) {
- - add(url);
- - }
- -}
- -
- -
- -FailoverStrategy::~FailoverStrategy()
- -{
- - for (Client *client : m_pools) {
- - client->deleteLater();
- + add(url, agent);
- }
- }
- int64_t FailoverStrategy::submit(const JobResult &result)
- {
- - if (m_active == -1) {
- - return -1;
- - }
- -
- return m_pools[m_active]->submit(result);
- }
- @@ -72,7 +57,7 @@ void FailoverStrategy::resume()
- return;
- }
- - m_listener->onJob(this, m_pools[m_active], m_pools[m_active]->job());
- + m_listener->onJob( m_pools[m_active], m_pools[m_active]->job());
- }
- @@ -108,7 +93,7 @@ void FailoverStrategy::onClose(Client *client, int failures)
- m_listener->onPause(this);
- }
- - if (m_index == 0 && failures < m_retries) {
- + if (m_index == 0 && failures < Options::i()->retries()) {
- return;
- }
- @@ -121,7 +106,7 @@ void FailoverStrategy::onClose(Client *client, int failures)
- void FailoverStrategy::onJobReceived(Client *client, const Job &job)
- {
- if (m_active == client->id()) {
- - m_listener->onJob(this, client, job);
- + m_listener->onJob(client, job);
- }
- }
- @@ -142,23 +127,22 @@ void FailoverStrategy::onLoginSuccess(Client *client)
- if (active >= 0 && active != m_active) {
- m_index = m_active = active;
- - m_listener->onActive(this, client);
- + m_listener->onActive(client);
- }
- }
- void FailoverStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error)
- {
- - m_listener->onResultAccepted(this, client, result, error);
- + m_listener->onResultAccepted(client, result, error);
- }
- -void FailoverStrategy::add(const Url *url)
- +void FailoverStrategy::add(const Url *url, const char *agent)
- {
- - Client *client = new Client((int) m_pools.size(), Platform::userAgent(), this);
- + Client *client = new Client((int) m_pools.size(), agent, this);
- client->setUrl(url);
- - client->setRetryPause(m_retryPause * 1000);
- - client->setQuiet(m_quiet);
- + client->setRetryPause(Options::i()->retryPause() * 1000);
- m_pools.push_back(client);
- }
- diff --git a/src/net/strategies/FailoverStrategy.h b/src/net/strategies/FailoverStrategy.h
- index 8ad767c..963d315 100644
- --- a/src/net/strategies/FailoverStrategy.h
- +++ b/src/net/strategies/FailoverStrategy.h
- @@ -4,8 +4,8 @@
- * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
- * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
- * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
- - * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
- - * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
- + * Copyright 2016-2017 XMRig <support@xmrig.com>
- + *
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- @@ -40,8 +40,7 @@ class Url;
- class FailoverStrategy : public IStrategy, public IClientListener
- {
- public:
- - FailoverStrategy(const std::vector<Url*> &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet = false);
- - ~FailoverStrategy();
- + FailoverStrategy(const std::vector<Url*> &urls, const char *agent, IStrategyListener *listener);
- public:
- inline bool isActive() const override { return m_active >= 0; }
- @@ -59,11 +58,8 @@ protected:
- void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override;
- private:
- - void add(const Url *url);
- + void add(const Url *url, const char *agent);
- - const bool m_quiet;
- - const int m_retries;
- - const int m_retryPause;
- int m_active;
- int m_index;
- IStrategyListener *m_listener;
- diff --git a/src/net/strategies/SinglePoolStrategy.cpp b/src/net/strategies/SinglePoolStrategy.cpp
- index fc7f209..997dc00 100644
- --- a/src/net/strategies/SinglePoolStrategy.cpp
- +++ b/src/net/strategies/SinglePoolStrategy.cpp
- @@ -4,8 +4,8 @@
- * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
- * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
- * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
- - * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
- - * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
- + * Copyright 2016-2017 XMRig <support@xmrig.com>
- + *
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- @@ -25,23 +25,16 @@
- #include "interfaces/IStrategyListener.h"
- #include "net/Client.h"
- #include "net/strategies/SinglePoolStrategy.h"
- -#include "Platform.h"
- +#include "Options.h"
- -SinglePoolStrategy::SinglePoolStrategy(const Url *url, int retryPause, IStrategyListener *listener, bool quiet) :
- +SinglePoolStrategy::SinglePoolStrategy(const Url *url, const char *agent, IStrategyListener *listener) :
- m_active(false),
- m_listener(listener)
- {
- - m_client = new Client(0, Platform::userAgent(), this);
- + m_client = new Client(0, agent, this);
- m_client->setUrl(url);
- - m_client->setRetryPause(retryPause * 1000);
- - m_client->setQuiet(quiet);
- -}
- -
- -
- -SinglePoolStrategy::~SinglePoolStrategy()
- -{
- - m_client->deleteLater();
- + m_client->setRetryPause(Options::i()->retryPause() * 1000);
- }
- @@ -63,7 +56,7 @@ void SinglePoolStrategy::resume()
- return;
- }
- - m_listener->onJob(this, m_client, m_client->job());
- + m_listener->onJob(m_client, m_client->job());
- }
- @@ -92,18 +85,18 @@ void SinglePoolStrategy::onClose(Client *client, int failures)
- void SinglePoolStrategy::onJobReceived(Client *client, const Job &job)
- {
- - m_listener->onJob(this, client, job);
- + m_listener->onJob(client, job);
- }
- void SinglePoolStrategy::onLoginSuccess(Client *client)
- {
- m_active = true;
- - m_listener->onActive(this, client);
- + m_listener->onActive(client);
- }
- void SinglePoolStrategy::onResultAccepted(Client *client, const SubmitResult &result, const char *error)
- {
- - m_listener->onResultAccepted(this, client, result, error);
- + m_listener->onResultAccepted(client, result, error);
- }
- diff --git a/src/net/strategies/SinglePoolStrategy.h b/src/net/strategies/SinglePoolStrategy.h
- index d5682cf..95e2154 100644
- --- a/src/net/strategies/SinglePoolStrategy.h
- +++ b/src/net/strategies/SinglePoolStrategy.h
- @@ -4,8 +4,8 @@
- * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
- * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
- * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
- - * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
- - * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
- + * Copyright 2016-2017 XMRig <support@xmrig.com>
- + *
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- @@ -37,8 +37,7 @@ class Url;
- class SinglePoolStrategy : public IStrategy, public IClientListener
- {
- public:
- - SinglePoolStrategy(const Url *url, int retryPause, IStrategyListener *listener, bool quiet = false);
- - ~SinglePoolStrategy();
- + SinglePoolStrategy(const Url *url, const char *agent, IStrategyListener *listener);
- public:
- inline bool isActive() const override { return m_active; }
- diff --git a/src/version.h b/src/version.h
- index b90e889..86de324 100644
- --- a/src/version.h
- +++ b/src/version.h
- @@ -4,8 +4,8 @@
- * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
- * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
- * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
- - * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
- - * Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
- + * Copyright 2016-2018 XMRig <support@xmrig.com>
- + *
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- @@ -24,34 +24,16 @@
- #ifndef __VERSION_H__
- #define __VERSION_H__
- -#define APP_ID "xmrig"
- -#define APP_NAME "XMRig"
- -#define APP_DESC "XMRig OpenCL miner"
- -#define APP_VERSION "2.5.2"
- -#define APP_DOMAIN "xmrig.com"
- -#define APP_SITE "www.xmrig.com"
- -#define APP_COPYRIGHT "Copyright (C) 2016-2018 xmrig.com"
- -#define APP_KIND "amd"
- +#define APP_ID "xrig"
- +#define APP_NAME "Xrig"
- +#define APP_DESC "Xrig cryptonight miner"
- +#define APP_VERSION "0.8.1"
- +#define APP_SITE "https://github.com/robertarnesson/xrig/"
- +#define APP_COPYRIGHT "Copyright (C) 2018 Robert Arnesson"
- -#define APP_VER_MAJOR 2
- -#define APP_VER_MINOR 5
- -#define APP_VER_BUILD 2
- +#define APP_VER_MAJOR 0
- +#define APP_VER_MINOR 8
- +#define APP_VER_BUILD 0
- #define APP_VER_REV 0
- -#ifdef _MSC_VER
- -# if (_MSC_VER >= 1910)
- -# define MSVC_VERSION 2017
- -# elif _MSC_VER == 1900
- -# define MSVC_VERSION 2015
- -# elif _MSC_VER == 1800
- -# define MSVC_VERSION 2013
- -# elif _MSC_VER == 1700
- -# define MSVC_VERSION 2012
- -# elif _MSC_VER == 1600
- -# define MSVC_VERSION 2010
- -# else
- -# define MSVC_VERSION 0
- -# endif
- -#endif
- -
- #endif /* __VERSION_H__ */
- diff --git a/src/workers/Handle.cpp b/src/workers/Handle.cpp
- index dd359d0..df6d67f 100644
- --- a/src/workers/Handle.cpp
- +++ b/src/workers/Handle.cpp
- @@ -35,6 +35,7 @@ Handle::Handle(int threadId, OclThread *thread, GpuContext *ctx, int threads, bo
- m_worker(nullptr)
- {
- thread->setThreadId(threadId);
- + ctx->threadId = threadId;
- }
- diff --git a/src/workers/OclThread.cpp b/src/workers/OclThread.cpp
- index d91eac5..e4c763b 100644
- --- a/src/workers/OclThread.cpp
- +++ b/src/workers/OclThread.cpp
- @@ -29,21 +29,21 @@
- OclThread::OclThread() :
- - m_affinity(-1),
- m_threadId(0),
- m_index(0),
- - m_intensity(0),
- - m_worksize(0)
- + m_rawIntensity(0),
- + m_worksize(8),
- + m_affinity(-1)
- {
- }
- -OclThread::OclThread(size_t index, size_t intensity, size_t worksize, int affinity) :
- - m_affinity(affinity),
- +OclThread::OclThread(size_t index, size_t rawIntensity, size_t worksize, int affinity) :
- m_threadId(0),
- - m_index(index),
- - m_intensity(intensity),
- - m_worksize(worksize)
- + m_index(index),
- + m_rawIntensity(rawIntensity),
- + m_worksize(worksize),
- + m_affinity(affinity)
- {
- }
- diff --git a/src/workers/OclThread.h b/src/workers/OclThread.h
- index 2e02df8..8409636 100644
- --- a/src/workers/OclThread.h
- +++ b/src/workers/OclThread.h
- @@ -35,27 +35,27 @@ class OclThread
- {
- public:
- OclThread();
- - OclThread(size_t index, size_t intensity, size_t worksize, int affinity = -1);
- + OclThread(size_t index, size_t rawIntensity = 0, size_t worksize = 8, int affinity = -1);
- ~OclThread();
- - inline int affinity() const { return m_affinity; }
- inline int threadId() const { return m_threadId; }
- - inline size_t index() const { return m_index; }
- - inline size_t intensity() const { return m_intensity; }
- + inline size_t index() const { return m_index; }
- + inline size_t rawIntensity() const { return m_rawIntensity; }
- inline size_t worksize() const { return m_worksize; }
- + inline int affinity() const { return m_affinity; }
- - inline void setAffinity(int affinity) { m_affinity = affinity; }
- inline void setIndex(size_t index) { m_index = index; }
- - inline void setIntensity(size_t intensity) { m_intensity = intensity; }
- + inline void setRawIntensity(size_t intensity) { m_rawIntensity = intensity; }
- inline void setThreadId(int threadId) { m_threadId = threadId; }
- - inline void setWorksize(size_t worksize) { m_worksize = worksize; }
- + inline void setWorksize(size_t worksize) { m_worksize = worksize; }
- + inline void setAffinity(int affinity) { m_affinity = affinity; }
- private:
- - int m_affinity;
- int m_threadId;
- size_t m_index;
- - size_t m_intensity;
- + size_t m_rawIntensity;
- size_t m_worksize;
- + int m_affinity;
- };
- diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp
- index 4675d96..61a3531 100644
- --- a/src/workers/Workers.cpp
- +++ b/src/workers/Workers.cpp
- @@ -30,6 +30,7 @@
- #endif
- +#include "amd/Adl.h"
- #include "amd/OclGPU.h"
- #include "api/Api.h"
- #include "crypto/CryptoNight.h"
- @@ -41,7 +42,6 @@
- #include "workers/Hashrate.h"
- #include "workers/OclThread.h"
- #include "workers/Workers.h"
- -#include "xmrig.h"
- bool Workers::m_active = false;
- @@ -52,7 +52,8 @@ Job Workers::m_job;
- std::atomic<int> Workers::m_paused;
- std::atomic<uint64_t> Workers::m_sequence;
- std::list<Job> Workers::m_queue;
- -std::vector<Handle*> Workers::m_workers;
- +std::vector<Handle*> Workers::m_handles;
- +std::map<int, std::vector<Handle*>> Workers::m_gpus;
- uint64_t Workers::m_ticks = 0;
- uv_async_t Workers::m_async;
- uv_mutex_t Workers::m_mutex;
- @@ -80,6 +81,7 @@ struct JobBaton
- bool Workers::start(const std::vector<OclThread*> &threads)
- {
- + std::vector<int> busIds;
- const size_t count = threads.size();
- m_hashrate = new Hashrate((int) count);
- @@ -99,7 +101,7 @@ bool Workers::start(const std::vector<OclThread*> &threads)
- for (size_t i = 0; i < count; ++i) {
- const OclThread *thread = threads[i];
- - contexts[i] = GpuContext(thread->index(), thread->intensity(), thread->worksize());
- + contexts[i] = GpuContext(thread->index(), thread->rawIntensity(), thread->worksize());
- }
- if (InitOpenCL(contexts.data(), count, Options::i()->platformIndex()) != OCL_ERR_SUCCESS) {
- @@ -107,8 +109,10 @@ bool Workers::start(const std::vector<OclThread*> &threads)
- }
- for (size_t i = 0; i < count; ++i) {
- - Handle *handle = new Handle((int) i, threads[i], &contexts[i], (int) count, Options::i()->algo() == xmrig::ALGO_CRYPTONIGHT_LITE);
- - m_workers.push_back(handle);
- + Handle *handle = new Handle((int) i, threads[i], &contexts[i], (int) count, Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE);
- + m_handles.push_back(handle);
- + m_gpus[handle->ctx()->busId].push_back(handle);
- + busIds.push_back(handle->ctx()->busId);
- handle->start(Workers::onReady);
- }
- @@ -121,7 +125,8 @@ bool Workers::start(const std::vector<OclThread*> &threads)
- uv_timer_start(&m_reportTimer, Workers::onReport, (printTime + 4) * 1000, printTime * 1000);
- }
- - Options::i()->save();
- + Adl::start(busIds);
- +
- return true;
- }
- @@ -164,14 +169,10 @@ void Workers::setEnabled(bool enabled)
- }
- -void Workers::setJob(const Job &job, bool donate)
- +void Workers::setJob(const Job &job)
- {
- uv_rwlock_wrlock(&m_rwlock);
- m_job = job;
- -
- - if (donate) {
- - m_job.setPoolId(-1);
- - }
- uv_rwlock_wrunlock(&m_rwlock);
- m_active = true;
- @@ -197,8 +198,8 @@ void Workers::stop()
- m_paused = 0;
- m_sequence = 0;
- - for (size_t i = 0; i < m_workers.size(); ++i) {
- - m_workers[i]->join();
- + for (size_t i = 0; i < m_handles.size(); ++i) {
- + m_handles[i]->join();
- }
- }
- @@ -259,7 +260,7 @@ void Workers::onResult(uv_async_t *handle)
- }
- if (baton->errors > 0 && !baton->jobs.empty()) {
- - LOG_ERR("GPU #%d COMPUTE ERROR", baton->jobs[0].threadId());
- + LOG_ERR("THREAD #%d COMPUTE ERROR", baton->jobs[0].threadId());
- }
- delete baton;
- @@ -276,7 +277,7 @@ void Workers::onReport(uv_timer_t *handle)
- void Workers::onTick(uv_timer_t *handle)
- {
- - for (Handle *handle : m_workers) {
- + for (Handle *handle : m_handles) {
- if (!handle->worker()) {
- return;
- }
- @@ -284,11 +285,12 @@ void Workers::onTick(uv_timer_t *handle)
- m_hashrate->add(handle->threadId(), handle->worker()->hashCount(), handle->worker()->timestamp());
- }
- - if ((m_ticks++ & 0xF) == 0) {
- + if ((m_ticks++ & 0xF) == 0) {
- m_hashrate->updateHighest();
- + Adl::i()->tick();
- }
- # ifndef XMRIG_NO_API
- Api::tick(m_hashrate);
- # endif
- -}
- +}
- \ No newline at end of file
- diff --git a/src/workers/Workers.h b/src/workers/Workers.h
- index 40bdff9..6180114 100644
- --- a/src/workers/Workers.h
- +++ b/src/workers/Workers.h
- @@ -29,6 +29,7 @@
- #include <list>
- #include <uv.h>
- #include <vector>
- +#include <map>
- #include "net/Job.h"
- #include "net/JobResult.h"
- @@ -46,7 +47,7 @@ public:
- static Job job();
- static void printHashrate(bool detail);
- static void setEnabled(bool enabled);
- - static void setJob(const Job &job, bool donate);
- + static void setJob(const Job &job);
- static void stop();
- static void submit(const Job &result);
- @@ -57,6 +58,9 @@ public:
- static inline void pause() { m_active = false; m_paused = 1; m_sequence++; }
- static inline void setListener(IJobResultListener *listener) { m_listener = listener; }
- + static const std::vector<Handle*> &handles() { return m_handles; }
- + static const std::map<int, std::vector<Handle*>> &gpus() { return m_gpus; }
- +
- private:
- static void onReady(void *arg);
- static void onResult(uv_async_t *handle);
- @@ -71,7 +75,8 @@ private:
- static std::atomic<int> m_paused;
- static std::atomic<uint64_t> m_sequence;
- static std::list<Job> m_queue;
- - static std::vector<Handle*> m_workers;
- + static std::vector<Handle*> m_handles;
- + static std::map<int, std::vector<Handle*>> m_gpus;
- static uint64_t m_ticks;
- static uv_async_t m_async;
- static uv_mutex_t m_mutex;
- @@ -81,4 +86,4 @@ private:
- };
- -#endif /* __WORKERS_H__ */
- +#endif /* __WORKERS_H__ */
- \ No newline at end of file
- diff --git a/src/xrig.cpp b/src/xrig.cpp
- new file mode 100644
- index 0000000..48362ad
- --- /dev/null
- +++ b/src/xrig.cpp
- @@ -0,0 +1,31 @@
- +/* XMRig
- + * Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
- + * Copyright 2012-2014 pooler <pooler@litecoinpool.org>
- + * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
- + * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
- + * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
- + * Copyright 2016-2017 XMRig <support@xmrig.com>
- + *
- + *
- + * This program is free software: you can redistribute it and/or modify
- + * it under the terms of the GNU General Public License as published by
- + * the Free Software Foundation, either version 3 of the License, or
- + * (at your option) any later version.
- + *
- + * This program is distributed in the hope that it will be useful,
- + * but WITHOUT ANY WARRANTY; without even the implied warranty of
- + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- + * GNU General Public License for more details.
- + *
- + * You should have received a copy of the GNU General Public License
- + * along with this program. If not, see <http://www.gnu.org/licenses/>.
- + */
- +
- +#include "App.h"
- +
- +
- +int main(int argc, char **argv) {
- + App app(argc, argv);
- +
- + return app.exec();
- +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement