diff options
-rw-r--r-- | src/blockchain_db/berkeleydb/db_bdb.cpp | 2 | ||||
-rw-r--r-- | src/common/util.cpp | 23 | ||||
-rw-r--r-- | src/common/util.h | 3 | ||||
-rw-r--r-- | src/cryptonote_core/blockchain.cpp | 6 | ||||
-rw-r--r-- | src/daemon/command_line_args.h | 5 | ||||
-rw-r--r-- | src/daemon/main.cpp | 4 | ||||
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 7 | ||||
-rw-r--r-- | src/wallet/wallet2.cpp | 4 |
8 files changed, 47 insertions, 7 deletions
diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp index a7fa556bd..b11570e37 100644 --- a/src/blockchain_db/berkeleydb/db_bdb.cpp +++ b/src/blockchain_db/berkeleydb/db_bdb.cpp @@ -135,7 +135,7 @@ const unsigned int DB_BUFFER_LENGTH = 32 * MB; const unsigned int DB_DEF_CACHESIZE = 256 * MB; #if defined(BDB_BULK_CAN_THREAD) -const unsigned int DB_BUFFER_COUNT = boost::thread::hardware_concurrency(); +const unsigned int DB_BUFFER_COUNT = tools::get_max_concurrency(); #else const unsigned int DB_BUFFER_COUNT = 1; #endif diff --git a/src/common/util.cpp b/src/common/util.cpp index 2337f5766..a53a9be52 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -422,4 +422,27 @@ std::string get_nix_version_display_string() umask(mode); #endif } + + namespace + { + boost::mutex max_concurrency_lock; + unsigned max_concurrency = boost::thread::hardware_concurrency(); + } + + void set_max_concurrency(unsigned n) + { + if (n < 1) + n = boost::thread::hardware_concurrency(); + unsigned hwc = boost::thread::hardware_concurrency(); + if (n > hwc) + n = hwc; + boost::lock_guard<boost::mutex> lock(max_concurrency_lock); + max_concurrency = n; + } + + unsigned get_max_concurrency() + { + boost::lock_guard<boost::mutex> lock(max_concurrency_lock); + return max_concurrency; + } } diff --git a/src/common/util.h b/src/common/util.h index ed1c16cb0..4fcf66b8f 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -160,4 +160,7 @@ namespace tools }; void set_strict_default_file_permissions(bool strict); + + void set_max_concurrency(unsigned n); + unsigned get_max_concurrency(); } diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 88ecb2dad..b4445756d 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -2124,7 +2124,7 @@ bool Blockchain::check_tx_inputs(const transaction& tx, tx_verification_context std::vector < uint64_t > results; results.resize(tx.vin.size(), 0); - int threads = boost::thread::hardware_concurrency(); + int threads = tools::get_max_concurrency(); boost::asio::io_service ioservice; boost::thread_group threadpool; @@ -3001,7 +3001,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e return true; bool blocks_exist = false; - uint64_t threads = boost::thread::hardware_concurrency(); + uint64_t threads = tools::get_max_concurrency(); if (blocks_entry.size() > 1 && threads > 1 && m_max_prepare_blocks_threads > 1) { @@ -3200,7 +3200,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list<block_complete_e // [output] stores all transactions for each tx_out_index::hash found std::vector<std::unordered_map<crypto::hash, cryptonote::transaction>> transactions(amounts.size()); - threads = boost::thread::hardware_concurrency(); + threads = tools::get_max_concurrency(); if (!m_db->can_thread_bulk_indices()) threads = 1; diff --git a/src/daemon/command_line_args.h b/src/daemon/command_line_args.h index 2dca5e3e7..1fe2ddcf6 100644 --- a/src/daemon/command_line_args.h +++ b/src/daemon/command_line_args.h @@ -59,6 +59,11 @@ namespace daemon_args "os-version" , "OS for which this executable was compiled" }; + const command_line::arg_descriptor<unsigned> arg_max_concurrency = { + "max-concurrency" + , "Max number of threads to use for a parallel job" + , 0 + }; } // namespace daemon_args #endif // DAEMON_COMMAND_LINE_ARGS_H diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp index 0717fd89b..bfd829dea 100644 --- a/src/daemon/main.cpp +++ b/src/daemon/main.cpp @@ -81,6 +81,7 @@ int main(int argc, char const * argv[]) bf::path default_log = default_data_dir / std::string(CRYPTONOTE_NAME ".log"); command_line::add_arg(core_settings, daemon_args::arg_log_file, default_log.string()); command_line::add_arg(core_settings, daemon_args::arg_log_level); + command_line::add_arg(core_settings, daemon_args::arg_max_concurrency); daemonizer::init_options(hidden_options, visible_options); daemonize::t_executor::init_options(core_settings); @@ -260,6 +261,9 @@ int main(int argc, char const * argv[]) ); } + if (command_line::has_arg(vm, daemon_args::arg_max_concurrency)) + tools::set_max_concurrency(command_line::get_arg(vm, daemon_args::arg_max_concurrency)); + _note_c("dbg/main", "Moving from main() into the daemonize now."); return daemonizer::daemonize(argc, argv, daemonize::t_executor{}, vm); diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 8c6b8f689..543fb6ad4 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -110,6 +110,7 @@ namespace const command_line::arg_descriptor<bool> arg_non_deterministic = {"non-deterministic", sw::tr("Create non-deterministic view and spend keys"), false}; const command_line::arg_descriptor<int> arg_daemon_port = {"daemon-port", sw::tr("Use daemon instance at port <arg> instead of 18081"), 0}; const command_line::arg_descriptor<uint32_t> arg_log_level = {"log-level", "", LOG_LEVEL_0}; + const command_line::arg_descriptor<uint32_t> arg_max_concurrency = {"max-concurrency", "Max number of threads to use for a parallel job", 0}; const command_line::arg_descriptor<std::string> arg_log_file = {"log-file", sw::tr("Specify log file"), ""}; const command_line::arg_descriptor<bool> arg_testnet = {"testnet", sw::tr("For testnet. Daemon must also be launched with --testnet flag"), false}; const command_line::arg_descriptor<bool> arg_restricted = {"restricted-rpc", sw::tr("Restricts RPC to view-only commands"), false}; @@ -1689,7 +1690,7 @@ bool simple_wallet::start_mining(const std::vector<std::string>& args) req.miner_address = m_wallet->get_account().get_public_address_str(m_wallet->testnet()); bool ok = true; - size_t max_mining_threads_count = (std::max)(boost::thread::hardware_concurrency(), static_cast<unsigned>(2)); + size_t max_mining_threads_count = (std::max)(tools::get_max_concurrency(), static_cast<unsigned>(2)); if (0 == args.size()) { req.threads_count = 1; @@ -3289,6 +3290,7 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_params, arg_daemon_port); command_line::add_arg(desc_params, arg_command); command_line::add_arg(desc_params, arg_log_level); + command_line::add_arg(desc_params, arg_max_concurrency); bf::path default_log {log_space::log_singletone::get_default_log_folder()}; std::string log_file_name = log_space::log_singletone::get_default_log_file(); @@ -3374,6 +3376,9 @@ int main(int argc, char* argv[]) LOG_LEVEL_4 ); + if(command_line::has_arg(vm, arg_max_concurrency)) + tools::set_max_concurrency(command_line::get_arg(vm, arg_max_concurrency)); + message_writer(epee::log_space::console_color_white, true) << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")"; if(command_line::has_arg(vm, arg_log_level)) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 53ce23490..dd83891df 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -213,7 +213,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_ tx_pub_key = pub_key_field.pub_key; bool r = true; - int threads = boost::thread::hardware_concurrency(); + int threads = tools::get_max_concurrency(); if (miner_tx && m_refresh_type == RefreshNoCoinbase) { // assume coinbase isn't for us @@ -603,7 +603,7 @@ void wallet2::process_blocks(uint64_t start_height, const std::list<cryptonote:: size_t current_index = start_height; blocks_added = 0; - int threads = boost::thread::hardware_concurrency(); + int threads = tools::get_max_concurrency(); if (threads > 1) { std::vector<crypto::hash> round_block_hashes(threads); |