diff options
-rw-r--r-- | Environment.hpp | 6 | ||||
-rw-r--r-- | Params.hpp | 45 | ||||
-rw-r--r-- | backend/amd/autoAdjust.hpp | 5 | ||||
-rw-r--r-- | backend/amd/jconf.h | 3 | ||||
-rw-r--r-- | backend/amd/minethd.cpp | 11 | ||||
-rw-r--r-- | backend/cpu/autoAdjust.hpp | 5 | ||||
-rw-r--r-- | backend/cpu/autoAdjustHwloc.hpp | 5 | ||||
-rw-r--r-- | backend/cpu/jconf.h | 3 | ||||
-rw-r--r-- | backend/cpu/minethd.cpp | 5 | ||||
-rw-r--r-- | backend/nvidia/autoAdjust.hpp | 5 | ||||
-rw-r--r-- | backend/nvidia/jconf.h | 3 | ||||
-rw-r--r-- | backend/nvidia/minethd.cpp | 5 | ||||
-rw-r--r-- | cli/cli-miner.cpp | 118 | ||||
-rw-r--r-- | jconf.h | 3 |
14 files changed, 174 insertions, 48 deletions
diff --git a/Environment.hpp b/Environment.hpp index 01090a4..15f8cce 100644 --- a/Environment.hpp +++ b/Environment.hpp @@ -8,6 +8,7 @@ namespace xmrstak { class GlobalStates; +class Params; struct Environment { @@ -24,6 +25,7 @@ struct Environment this->pGlobalStates = env.pGlobalStates; this->pJconfConfig = env.pJconfConfig; this->pExecutor = env.pExecutor; + this->pParams = env.pParams; return *this; } @@ -34,12 +36,10 @@ struct Environment printer* pPrinter; - GlobalStates* pGlobalStates; - jconf* pJconfConfig; - executor* pExecutor; + Params* pParams; }; diff --git a/Params.hpp b/Params.hpp new file mode 100644 index 0000000..92d0da0 --- /dev/null +++ b/Params.hpp @@ -0,0 +1,45 @@ +#pragma once +#include <string> +#include "Environment.hpp" + +namespace xmrstak +{ + +struct Params +{ + + static inline Params& inst() + { + auto& env = Environment::inst(); + if(env.pParams == nullptr) + env.pParams = new Params; + return *env.pParams; + } + + std::string executablePrefix; + bool useAMD; + bool useNVIDIA; + bool useCPU; + + std::string poolURL; + std::string poolPasswd; + std::string poolUsername; + + std::string configFile; + std::string configFileAMD; + std::string configFileNVIDIA; + std::string configFileCPU; + + Params() : + useAMD(true), + useNVIDIA(true), + useCPU(true), + configFile("config.txt"), + configFileAMD("amd.txt"), + configFileCPU("cpu.txt"), + configFileNVIDIA("nvidia.txt") + {} + +}; + +} // namepsace xmrstak diff --git a/backend/amd/autoAdjust.hpp b/backend/amd/autoAdjust.hpp index e6e4015..442d8f1 100644 --- a/backend/amd/autoAdjust.hpp +++ b/backend/amd/autoAdjust.hpp @@ -8,6 +8,7 @@ #include "../../console.h" #include "../../ConfigEditor.hpp" #include "amd_gpu/gpu.h" +#include "../../Params.hpp" #include <vector> #include <cstdio> @@ -102,8 +103,8 @@ private: configTpl.replace("PLATFORMINDEX",std::to_string(platformIndex)); configTpl.replace("NUMGPUS",std::to_string(devVec.size())); configTpl.replace("GPUCONFIG",conf); - configTpl.write("amd.txt"); - printer::inst()->print_msg(L0, "AMD: GPU configuration stored in file '%s'", "amd.txt"); + configTpl.write(Params::inst().configFileAMD); + printer::inst()->print_msg(L0, "AMD: GPU configuration stored in file '%s'", Params::inst().configFileAMD.c_str()); } std::vector<GpuContext> devVec; diff --git a/backend/amd/jconf.h b/backend/amd/jconf.h index 463284a..9fef331 100644 --- a/backend/amd/jconf.h +++ b/backend/amd/jconf.h @@ -1,6 +1,7 @@ #pragma once #include <stdlib.h> #include <string> +#include "../../Params.hpp" namespace xmrstak { @@ -16,7 +17,7 @@ public: return oInst; }; - bool parse_config(const char* sFilename = "amd.txt"); + bool parse_config(const char* sFilename = Params::inst().configFileAMD.c_str()); struct thd_cfg { size_t index; diff --git a/backend/amd/minethd.cpp b/backend/amd/minethd.cpp index 0821c0e..b938f2d 100644 --- a/backend/amd/minethd.cpp +++ b/backend/amd/minethd.cpp @@ -40,6 +40,7 @@ #include "../../jconf.h" #include "../../crypto/cryptonight.h" #include "../../Environment.hpp" +#include "../../Params.hpp" #include "amd_gpu/gpu.h" @@ -97,19 +98,13 @@ std::vector<IBackend*>* minethd::thread_starter(uint32_t threadOffset, miner_wor { std::vector<IBackend*>* pvThreads = new std::vector<IBackend*>(); - if(!ConfigEditor::file_exist("amd.txt")) + if(!ConfigEditor::file_exist(Params::inst().configFileAMD)) { autoAdjust adjust; if(!adjust.printConfig()) return pvThreads; } -/* - if(!ConfigEditor::file_exist("amd.txt")) - { - printer::inst()->print_msg(L0, "WARNING: missing config file 'amd.txt'"); - return pvThreads; - } -*/ + if(!jconf::inst()->parse_config()) { win_exit(); diff --git a/backend/cpu/autoAdjust.hpp b/backend/cpu/autoAdjust.hpp index 092f085..32c8576 100644 --- a/backend/cpu/autoAdjust.hpp +++ b/backend/cpu/autoAdjust.hpp @@ -3,6 +3,7 @@ #include "../../console.h" #include "../../jconf.h" #include "../../ConfigEditor.hpp" +#include "../../Params.hpp" #include <string> #ifdef _WIN32 @@ -97,8 +98,8 @@ public: } configTpl.replace("CPUCONFIG",conf); - configTpl.write("cpu.txt"); - printer::inst()->print_msg(L0, "CPU configuration stored in file '%s'", "cpu.txt"); + configTpl.write(Params::inst().configFileCPU); + printer::inst()->print_msg(L0, "CPU configuration stored in file '%s'", Params::inst().configFileCPU.c_str()); return true; } diff --git a/backend/cpu/autoAdjustHwloc.hpp b/backend/cpu/autoAdjustHwloc.hpp index 161aa5c..e1916e0 100644 --- a/backend/cpu/autoAdjustHwloc.hpp +++ b/backend/cpu/autoAdjustHwloc.hpp @@ -3,6 +3,7 @@ #include "../../console.h" #include <hwloc.h> #include <stdio.h> +#include "../../Params.hpp" #ifdef _WIN32 #include <windows.h> @@ -74,8 +75,8 @@ public: } configTpl.replace("CPUCONFIG",conf); - configTpl.write("cpu.txt"); - printer::inst()->print_msg(L0, "CPU configuration stored in file '%s'", "cpu.txt"); + configTpl.write(Params::inst().configFileCPU); + printer::inst()->print_msg(L0, "CPU configuration stored in file '%s'", Params::inst().configFileCPU.c_str()); /* Destroy topology object. */ hwloc_topology_destroy(topology); diff --git a/backend/cpu/jconf.h b/backend/cpu/jconf.h index 9b46552..1f92765 100644 --- a/backend/cpu/jconf.h +++ b/backend/cpu/jconf.h @@ -1,6 +1,7 @@ #pragma once #include <stdlib.h> #include <string> +#include "../../Params.hpp" namespace xmrstak { @@ -16,7 +17,7 @@ public: return oInst; }; - bool parse_config(const char* sFilename = "cpu.txt"); + bool parse_config(const char* sFilename = Params::inst().configFileCPU.c_str()); struct thd_cfg { bool bDoubleMode; diff --git a/backend/cpu/minethd.cpp b/backend/cpu/minethd.cpp index 7991d86..3ffdf99 100644 --- a/backend/cpu/minethd.cpp +++ b/backend/cpu/minethd.cpp @@ -31,6 +31,7 @@ #include "../IBackend.hpp" #include "../GlobalStates.hpp" #include "../../ConfigEditor.hpp" +#include "../../Params.hpp" #include "../../jconf.h" #include "../../executor.h" @@ -247,14 +248,14 @@ std::vector<IBackend*> minethd::thread_starter(uint32_t threadOffset, miner_work { std::vector<IBackend*> pvThreads; - if(!ConfigEditor::file_exist("cpu.txt")) + if(!ConfigEditor::file_exist(Params::inst().configFileCPU)) { autoAdjust adjust; if(!adjust.printConfig()) return pvThreads; } - if(!xmrstak::cpu::jconf::inst()->parse_config("cpu.txt")) + if(!jconf::inst()->parse_config()) { win_exit(); } diff --git a/backend/nvidia/autoAdjust.hpp b/backend/nvidia/autoAdjust.hpp index 659bd08..84c6dfc 100644 --- a/backend/nvidia/autoAdjust.hpp +++ b/backend/nvidia/autoAdjust.hpp @@ -7,6 +7,7 @@ #include "jconf.h" #include "../../console.h" #include "../../ConfigEditor.hpp" +#include "../../Params.hpp" #include <vector> #include <cstdio> @@ -101,8 +102,8 @@ private: } configTpl.replace("GPUCONFIG",conf); - configTpl.write("nvidia.txt"); - printer::inst()->print_msg(L0, "NVIDIA: GPU configuration stored in file '%s'", "nvidia.txt"); + configTpl.write(Params::inst().configFileNVIDIA); + printer::inst()->print_msg(L0, "NVIDIA: GPU configuration stored in file '%s'", Params::inst().configFileNVIDIA.c_str()); } std::vector<nvid_ctx> nvidCtxVec; diff --git a/backend/nvidia/jconf.h b/backend/nvidia/jconf.h index e398f30..8959088 100644 --- a/backend/nvidia/jconf.h +++ b/backend/nvidia/jconf.h @@ -1,6 +1,7 @@ #pragma once #include <stdlib.h> #include <string> +#include "../../Params.hpp" namespace xmrstak { @@ -16,7 +17,7 @@ public: return oInst; }; - bool parse_config(const char* sFilename = "nvidia.txt"); + bool parse_config(const char* sFilename = Params::inst().configFileNVIDIA.c_str()); struct thd_cfg { uint32_t id; diff --git a/backend/nvidia/minethd.cpp b/backend/nvidia/minethd.cpp index 554ea69..227a2cf 100644 --- a/backend/nvidia/minethd.cpp +++ b/backend/nvidia/minethd.cpp @@ -30,6 +30,7 @@ #include "../../console.h" #include "../../crypto/cryptonight_aesni.h" #include "../cpu/minethd.h" +#include "../../Params.hpp" #include "../../executor.h" #include "minethd.h" @@ -121,14 +122,14 @@ std::vector<IBackend*>* minethd::thread_starter(uint32_t threadOffset, miner_wor { std::vector<IBackend*>* pvThreads = new std::vector<IBackend*>(); - if(!ConfigEditor::file_exist("nvidia.txt")) + if(!ConfigEditor::file_exist(Params::inst().configFileNVIDIA)) { autoAdjust adjust; if(!adjust.printConfig()) return pvThreads; } - if(!jconf::inst()->parse_config("nvidia.txt")) + if(!jconf::inst()->parse_config()) { win_exit(); } diff --git a/cli/cli-miner.cpp b/cli/cli-miner.cpp index 9cd9825..df9432e 100644 --- a/cli/cli-miner.cpp +++ b/cli/cli-miner.cpp @@ -28,6 +28,7 @@ #include "../jconf.h" #include "../console.h" #include "../donate-level.h" +#include "../Params.hpp" #include "../version.h" @@ -37,7 +38,7 @@ #include <stdlib.h> #include <stdio.h> -#include <string.h> +#include <string> #include <time.h> @@ -66,32 +67,114 @@ int main(int argc, char *argv[]) srand(time(0)); - const char* sFilename = "config.txt"; - bool benchmark_mode = false; + using namespace xmrstak; - if(argc >= 2) + std::string pathWithName(argv[0]); + auto pos = pathWithName.rfind("/"); + if(pos == std::string::npos) { - if(strcmp(argv[1], "-h") == 0) + // try windows "\" + pos = pathWithName.rfind("\\"); + } + + Params::inst().executablePrefix = std::string(pathWithName, 0, pos); + + for(int i = 1; i < argc; ++i) + { + std::string opName(argv[i]); + if(opName.compare("-h") == 0 || opName.compare("--help") == 0) { - printer::inst()->print_msg(L0, "Usage %s [CONFIG FILE]", argv[0]); + printer::inst()->print_msg(L0, "Usage: %s [--help|-h] [--benchmark] [-c CONFIGFILE] [CONFIG FILE]", argv[0]); win_exit(); return 0; } - - if(argc >= 3 && strcasecmp(argv[1], "-c") == 0) + else if(opName.compare("--noCPU") == 0) + { + Params::inst().useCPU = false; + return 0; + } + else if(opName.compare("--noAMD") == 0) + { + Params::inst().useAMD = false; + return 0; + } + else if(opName.compare("--noAMD") == 0) + { + Params::inst().useNVIDIA = false; + return 0; + } + else if(opName.compare("--cpu") == 0) { - sFilename = argv[2]; + ++i; + if( i >=argc ) + { + printer::inst()->print_msg(L0, "No argument for opName '--cpu' given"); + win_exit(); + return 1; + } + Params::inst().configFileCPU = argv[i]; } - else if(argc >= 3 && strcasecmp(argv[1], "benchmark_mode") == 0) + else if(opName.compare("--amd") == 0) { - sFilename = argv[2]; - benchmark_mode = true; + ++i; + if( i >=argc ) + { + printer::inst()->print_msg(L0, "No argument for opName '--amd' given"); + win_exit(); + return 1; + } + Params::inst().configFileAMD = argv[i]; + } + else if(opName.compare("--nvidia") == 0) + { + ++i; + if( i >=argc ) + { + printer::inst()->print_msg(L0, "No argument for opName '--nvidia' given"); + win_exit(); + return 1; + } + Params::inst().configFileNVIDIA = argv[i]; + } + else if(opName.compare("-o") == 0 || opName.compare("--url") == 0) + { + ++i; + if( i >=argc ) + { + printer::inst()->print_msg(L0, "No argument for opName '-o/--url' given"); + win_exit(); + return 1; + } + Params::inst().poolURL = argv[i]; + } + else if(opName.compare("-u") == 0 || opName.compare("--user") == 0) + { + ++i; + if( i >=argc ) + { + printer::inst()->print_msg(L0, "No argument for opName '-u/--user' given"); + win_exit(); + return 1; + } + Params::inst().poolUsername = argv[i]; + } + else if(opName.compare("-p") == 0 || opName.compare("--pass") == 0) + { + ++i; + if( i >=argc ) + { + printer::inst()->print_msg(L0, "No argument for opName '-p/--pass' given"); + win_exit(); + return 1; + } + Params::inst().poolPasswd = argv[i]; } else - sFilename = argv[1]; + Params::inst().configFile = argv[i]; } + - if(!jconf::inst()->parse_config(sFilename)) + if(!jconf::inst()->parse_config(Params::inst().configFile.c_str())) { win_exit(); return 0; @@ -103,13 +186,6 @@ int main(int argc, char *argv[]) return 0; } - if(benchmark_mode) - { - do_benchmark(); - win_exit(); - return 0; - } - #ifndef CONF_NO_HTTPD if(jconf::inst()->GetHttpdPort() != 0) { @@ -2,6 +2,7 @@ #include <stdlib.h> #include <string> #include "Environment.hpp" +#include "Params.hpp" class jconf { @@ -14,7 +15,7 @@ public: return env.pJconfConfig; }; - bool parse_config(const char* sFilename); + bool parse_config(const char* sFilename = xmrstak::Params::inst().configFile.c_str()); struct thd_cfg { bool bDoubleMode; |