diff --git a/client/app.cpp b/client/app.cpp index 52d2b3d38b..eb6d466518 100644 --- a/client/app.cpp +++ b/client/app.cpp @@ -995,7 +995,13 @@ void ACTIVE_TASK::set_task_state(int val, const char* where) { } } +#ifdef NEW_CPU_THROTTLE +#define THROTTLE_PERIOD 1. +#ifdef _WIN32 +DWORD WINAPI throttler(LPVOID) { +#else void* throttler(void*) { +#endif while (1) { client_mutex.lock(); if (gstate.tasks_suspended || gstate.global_prefs.cpu_usage_limit > 99) { @@ -1003,18 +1009,20 @@ void* throttler(void*) { boinc_sleep(10); continue; } - double on = gstate.global_prefs.cpu_usage_limit / 100; - double off = 1 - on; - gstate.tasks_suspended = true; + double on = THROTTLE_PERIOD * gstate.global_prefs.cpu_usage_limit / 100; + double off = THROTTLE_PERIOD - on; + gstate.tasks_throttled = true; gstate.active_tasks.suspend_all(SUSPEND_REASON_CPU_THROTTLE); client_mutex.unlock(); boinc_sleep(off); client_mutex.lock(); - if (gstate.tasks_suspended && !gstate.suspend_reason) { + if (!gstate.tasks_suspended) { gstate.resume_tasks(SUSPEND_REASON_CPU_THROTTLE); } + gstate.tasks_throttled = false; client_mutex.unlock(); boinc_sleep(on); } return 0; } +#endif \ No newline at end of file diff --git a/client/app.h b/client/app.h index eaf379eb49..1c44dcad5e 100644 --- a/client/app.h +++ b/client/app.h @@ -318,5 +318,10 @@ extern double non_boinc_cpu_usage; extern void run_test_app(); +#ifdef _WIN32 +extern DWORD WINAPI throttler(void*); +#else extern void* throttler(void*); #endif + +#endif diff --git a/client/client_state.cpp b/client/client_state.cpp index d92815e45d..07d65f8a88 100644 --- a/client/client_state.cpp +++ b/client/client_state.cpp @@ -96,6 +96,7 @@ CLIENT_STATE::CLIENT_STATE() file_xfer_giveup_period = PERS_GIVEUP; had_or_requested_work = false; tasks_suspended = false; + tasks_throttled = false; network_suspended = false; suspend_reason = 0; network_suspend_reason = 0; @@ -861,11 +862,13 @@ bool CLIENT_STATE::poll_slow_events() { if (suspend_reason) { if (!tasks_suspended) { show_suspend_tasks_message(suspend_reason); - active_tasks.suspend_all(suspend_reason); + if (!tasks_throttled) { + active_tasks.suspend_all(suspend_reason); + } } last_suspend_reason = suspend_reason; } else { - if (tasks_suspended) { + if (tasks_suspended && !tasks_throttled) { resume_tasks(last_suspend_reason); } } diff --git a/client/client_state.h b/client/client_state.h index 85f2580ac5..ffa62bcbd5 100644 --- a/client/client_state.h +++ b/client/client_state.h @@ -18,7 +18,7 @@ #ifndef _CLIENT_STATE_ #define _CLIENT_STATE_ -//#define NEW_CPU_THROTTLE +#define NEW_CPU_THROTTLE #ifndef _WIN32 #include @@ -179,8 +179,10 @@ struct CLIENT_STATE { int pers_giveup; bool tasks_suspended; - // Don't run apps. + // Computing suspended for reason other than throttling int suspend_reason; + bool tasks_throttled; + // Computing suspended because of throttling bool network_suspended; // Don't use network.