diff options
Diffstat (limited to 'src')
-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 | ||||
-rw-r--r-- | src/wallet/wallet_rpc_server.cpp | 11 | ||||
-rw-r--r-- | src/wallet/wallet_rpc_server_commands_defs.h | 3 |
10 files changed, 59 insertions, 9 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 25131f66d..cc7b7138b 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}; @@ -1706,7 +1707,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; @@ -3306,6 +3307,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(); @@ -3391,6 +3393,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); diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 5b678fa38..a082f731b 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -842,10 +842,17 @@ namespace tools return false; } + uint64_t min_height = 0, max_height = (uint64_t)-1; + if (req.filter_by_height) + { + min_height = req.min_height; + max_height = req.max_height; + } + if (req.in) { std::list<std::pair<crypto::hash, tools::wallet2::payment_details>> payments; - m_wallet.get_payments(payments, req.min_height, req.max_height); + m_wallet.get_payments(payments, min_height, max_height); for (std::list<std::pair<crypto::hash, tools::wallet2::payment_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) { res.in.push_back(wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry()); wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry &entry = res.in.back(); @@ -866,7 +873,7 @@ namespace tools if (req.out) { std::list<std::pair<crypto::hash, tools::wallet2::confirmed_transfer_details>> payments; - m_wallet.get_payments_out(payments, req.min_height, req.max_height); + m_wallet.get_payments_out(payments, min_height, max_height); for (std::list<std::pair<crypto::hash, tools::wallet2::confirmed_transfer_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) { res.in.push_back(wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry()); wallet_rpc::COMMAND_RPC_GET_TRANSFERS::entry &entry = res.in.back(); diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h index 9fe85dfc1..f8c04c007 100644 --- a/src/wallet/wallet_rpc_server_commands_defs.h +++ b/src/wallet/wallet_rpc_server_commands_defs.h @@ -496,6 +496,8 @@ namespace wallet_rpc bool out; bool pending; bool failed; + + bool filter_by_height; uint64_t min_height; uint64_t max_height; @@ -504,6 +506,7 @@ namespace wallet_rpc KV_SERIALIZE(out); KV_SERIALIZE(pending); KV_SERIALIZE(failed); + KV_SERIALIZE(filter_by_height); KV_SERIALIZE(min_height); KV_SERIALIZE(max_height); END_KV_SERIALIZE_MAP() |