aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_basic/miner.h
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-02-12 23:11:44 +0200
committerRiccardo Spagni <ric@spagni.net>2017-02-12 23:11:44 +0200
commitaf48b6cf22bf772e2331194ea93b47fd3583018d (patch)
tree5f543e906da88c41936ae279c63e96ebb5909435 /src/cryptonote_basic/miner.h
parentMerge pull request #1698 (diff)
parentAdded a note about smart mining to status command. Fixed up a bug where I was... (diff)
downloadmonero-af48b6cf22bf772e2331194ea93b47fd3583018d.tar.xz
Merge pull request #1582
ad95e650 Added a note about smart mining to status command. Fixed up a bug where I was resetting bg mining enabled instead of started. Upped the miner threshold. Also moved setting of enabled on start above miner thread creation since starting with true, then stopping, then starting with false resulted in race condition. (Dion Ahmetaj) e4dfd2fb Changed ac_line_status to on_battery_power. (Dion Ahmetaj) 23c73269 Use defined directive to silence pre-proc warnings. (Dion Ahmetaj) d2c7d0f6 Cleaned up some logging. Thanks to moneromooo for help. (Dion Ahmetaj) 68652cd9 Added some //TODO comments pertaining to returning enums instead of bools in order to be better able to handle failure states. (Dion Ahmetaj) 0b1045ed Moved around checking of AC power in order to bail quicker to sleep if not plugged in. (Dion Ahmetaj) 2937fdbb Moved setting of previous process times to block where background mining is started, and added an explicit sleep in that block to wait for some mining to occur. (Dion Ahmetaj) 21a1e025 Set background mining started bool to false on bg thread start. If mining::stop then mining::start, idle logic is re-run instead of starting immediately (if it was running before stop). (Dion Ahmetaj) 345ed482 Background/smart mining. If a users' computer is plugged into a power source, and CPU has been idle for some time, then begin mining to some threshold (don't destroy the users' CPU). (Dion Ahmetaj)
Diffstat (limited to 'src/cryptonote_basic/miner.h')
-rw-r--r--src/cryptonote_basic/miner.h53
1 files changed, 48 insertions, 5 deletions
diff --git a/src/cryptonote_basic/miner.h b/src/cryptonote_basic/miner.h
index f24f6e960..a66083ead 100644
--- a/src/cryptonote_basic/miner.h
+++ b/src/cryptonote_basic/miner.h
@@ -35,7 +35,14 @@
#include "cryptonote_basic.h"
#include "difficulty.h"
#include "math_helper.h"
-
+#ifdef _WIN32
+#include <windows.h>
+#elif defined(__linux__)
+#include <unistd.h>
+#include <sys/resource.h>
+#include <sys/times.h>
+#include <time.h>
+#endif
namespace cryptonote
{
@@ -60,7 +67,7 @@ namespace cryptonote
static void init_options(boost::program_options::options_description& desc);
bool set_block_template(const block& bl, const difficulty_type& diffic, uint64_t height);
bool on_block_chain_update();
- bool start(const account_public_address& adr, size_t threads_count, const boost::thread::attributes& attrs);
+ bool start(const account_public_address& adr, size_t threads_count, const boost::thread::attributes& attrs, bool do_background = false);
uint64_t get_speed() const;
uint32_t get_threads_count() const;
void send_stop_signal();
@@ -74,6 +81,26 @@ namespace cryptonote
void pause();
void resume();
void do_print_hashrate(bool do_hr);
+ bool get_is_background_mining_enabled() const;
+ uint64_t get_min_idle_seconds() const;
+ bool set_min_idle_seconds(uint64_t min_idle_seconds);
+ uint8_t get_idle_threshold() const;
+ bool set_idle_threshold(uint8_t idle_threshold);
+ uint8_t get_mining_target() const;
+ bool set_mining_target(uint8_t mining_target);
+
+ static constexpr uint8_t BACKGROUND_MINING_DEFAULT_IDLE_THRESHOLD_PERCENTAGE = 90;
+ static constexpr uint8_t BACKGROUND_MINING_MIN_IDLE_THRESHOLD_PERCENTAGE = 50;
+ static constexpr uint8_t BACKGROUND_MINING_MAX_IDLE_THRESHOLD_PERCENTAGE = 99;
+ static constexpr uint16_t BACKGROUND_MINING_DEFAULT_MIN_IDLE_INTERVAL_IN_SECONDS = 10;
+ static constexpr uint16_t BACKGROUND_MINING_MIN_MIN_IDLE_INTERVAL_IN_SECONDS = 10;
+ static constexpr uint16_t BACKGROUND_MINING_MAX_MIN_IDLE_INTERVAL_IN_SECONDS = 3600;
+ static constexpr uint8_t BACKGROUND_MINING_DEFAULT_MINING_TARGET_PERCENTAGE = 40;
+ static constexpr uint8_t BACKGROUND_MINING_MIN_MINING_TARGET_PERCENTAGE = 5;
+ static constexpr uint8_t BACKGROUND_MINING_MAX_MINING_TARGET_PERCENTAGE = 50;
+ static constexpr uint8_t BACKGROUND_MINING_MINER_MONITOR_INVERVAL_IN_SECONDS = 10;
+ static constexpr uint64_t BACKGROUND_MINING_DEFAULT_MINER_EXTRA_SLEEP_MILLIS = 400; // ramp up
+ static constexpr uint64_t BACKGROUND_MINING_MIN_MINER_EXTRA_SLEEP_MILLIS = 5;
private:
bool worker_thread();
@@ -119,8 +146,24 @@ namespace cryptonote
bool m_do_print_hashrate;
bool m_do_mining;
+ // background mining stuffs ..
+
+ bool set_is_background_mining_enabled(bool is_background_mining_enabled);
+ bool background_worker_thread();
+ std::atomic<bool> m_is_background_mining_enabled;
+ boost::mutex m_is_background_mining_enabled_mutex;
+ boost::condition_variable m_is_background_mining_enabled_cond;
+ std::atomic<bool> m_is_background_mining_started;
+ boost::mutex m_is_background_mining_started_mutex;
+ boost::condition_variable m_is_background_mining_started_cond;
+ boost::thread m_background_mining_thread;
+ uint64_t m_min_idle_seconds;
+ uint8_t m_idle_threshold;
+ uint8_t m_mining_target;
+ std::atomic<uint64_t> m_miner_extra_sleep;
+ static bool get_system_times(uint64_t& total_time, uint64_t& idle_time);
+ static bool get_process_time(uint64_t& total_time);
+ static uint8_t get_percent_of_total(uint64_t some_time, uint64_t total_time);
+ static bool on_battery_power();
};
}
-
-
-