Client: debug sub-second CPU throttling

This commit is contained in:
David Anderson 2013-09-20 23:18:33 -07:00
parent ebde7809ce
commit 35f489d36f
4 changed files with 26 additions and 8 deletions

View File

@ -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*) { void* throttler(void*) {
#endif
while (1) { while (1) {
client_mutex.lock(); client_mutex.lock();
if (gstate.tasks_suspended || gstate.global_prefs.cpu_usage_limit > 99) { if (gstate.tasks_suspended || gstate.global_prefs.cpu_usage_limit > 99) {
@ -1003,18 +1009,20 @@ void* throttler(void*) {
boinc_sleep(10); boinc_sleep(10);
continue; continue;
} }
double on = gstate.global_prefs.cpu_usage_limit / 100; double on = THROTTLE_PERIOD * gstate.global_prefs.cpu_usage_limit / 100;
double off = 1 - on; double off = THROTTLE_PERIOD - on;
gstate.tasks_suspended = true; gstate.tasks_throttled = true;
gstate.active_tasks.suspend_all(SUSPEND_REASON_CPU_THROTTLE); gstate.active_tasks.suspend_all(SUSPEND_REASON_CPU_THROTTLE);
client_mutex.unlock(); client_mutex.unlock();
boinc_sleep(off); boinc_sleep(off);
client_mutex.lock(); client_mutex.lock();
if (gstate.tasks_suspended && !gstate.suspend_reason) { if (!gstate.tasks_suspended) {
gstate.resume_tasks(SUSPEND_REASON_CPU_THROTTLE); gstate.resume_tasks(SUSPEND_REASON_CPU_THROTTLE);
} }
gstate.tasks_throttled = false;
client_mutex.unlock(); client_mutex.unlock();
boinc_sleep(on); boinc_sleep(on);
} }
return 0; return 0;
} }
#endif

View File

@ -318,5 +318,10 @@ extern double non_boinc_cpu_usage;
extern void run_test_app(); extern void run_test_app();
#ifdef _WIN32
extern DWORD WINAPI throttler(void*);
#else
extern void* throttler(void*); extern void* throttler(void*);
#endif #endif
#endif

View File

@ -96,6 +96,7 @@ CLIENT_STATE::CLIENT_STATE()
file_xfer_giveup_period = PERS_GIVEUP; file_xfer_giveup_period = PERS_GIVEUP;
had_or_requested_work = false; had_or_requested_work = false;
tasks_suspended = false; tasks_suspended = false;
tasks_throttled = false;
network_suspended = false; network_suspended = false;
suspend_reason = 0; suspend_reason = 0;
network_suspend_reason = 0; network_suspend_reason = 0;
@ -861,11 +862,13 @@ bool CLIENT_STATE::poll_slow_events() {
if (suspend_reason) { if (suspend_reason) {
if (!tasks_suspended) { if (!tasks_suspended) {
show_suspend_tasks_message(suspend_reason); 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; last_suspend_reason = suspend_reason;
} else { } else {
if (tasks_suspended) { if (tasks_suspended && !tasks_throttled) {
resume_tasks(last_suspend_reason); resume_tasks(last_suspend_reason);
} }
} }

View File

@ -18,7 +18,7 @@
#ifndef _CLIENT_STATE_ #ifndef _CLIENT_STATE_
#define _CLIENT_STATE_ #define _CLIENT_STATE_
//#define NEW_CPU_THROTTLE #define NEW_CPU_THROTTLE
#ifndef _WIN32 #ifndef _WIN32
#include <string> #include <string>
@ -179,8 +179,10 @@ struct CLIENT_STATE {
int pers_giveup; int pers_giveup;
bool tasks_suspended; bool tasks_suspended;
// Don't run apps. // Computing suspended for reason other than throttling
int suspend_reason; int suspend_reason;
bool tasks_throttled;
// Computing suspended because of throttling
bool network_suspended; bool network_suspended;
// Don't use network. // Don't use network.