diff --git a/client/app.cpp b/client/app.cpp index dc1623fc35..44717697fa 100644 --- a/client/app.cpp +++ b/client/app.cpp @@ -1031,7 +1031,6 @@ void ACTIVE_TASK::set_task_state(int val, const char* where) { #ifndef SIM #ifdef NEW_CPU_THROTTLE -#define THROTTLE_PERIOD 1. #ifdef _WIN32 DWORD WINAPI throttler(LPVOID) { #else @@ -1049,8 +1048,23 @@ void* throttler(void*) { boinc_sleep(10); continue; } - double on = THROTTLE_PERIOD * gstate.global_prefs.cpu_usage_limit / 100; - double off = THROTTLE_PERIOD - on; + double on, off, on_frac = gstate.global_prefs.cpu_usage_limit / 100; +#if 0 +// sub-second CPU throttling +#define THROTTLE_PERIOD 1. + on = THROTTLE_PERIOD * on_frac; + off = THROTTLE_PERIOD - on; +#else +// throttling w/ at least 1 sec between suspend/resume + if (on_frac > .5) { + off = 1; + on = on_frac/(1.-on_frac); + } else { + on = 1; + off = (1.-on_frac)/on_frac; + } +#endif + gstate.tasks_throttled = true; gstate.active_tasks.suspend_all(SUSPEND_REASON_CPU_THROTTLE); client_mutex.unlock(); diff --git a/client/app_control.cpp b/client/app_control.cpp index 3bed33f996..7c52c0986f 100644 --- a/client/app_control.cpp +++ b/client/app_control.cpp @@ -1129,7 +1129,7 @@ void ACTIVE_TASK_SET::unsuspend_all(int reason) { atp = active_tasks[i]; if (atp->scheduler_state != CPU_SCHED_SCHEDULED) continue; if (atp->task_state() == PROCESS_UNINITIALIZED) { - if (atp->start()) { + if (atp->resume_or_start(false)) { msg_printf(atp->wup->project, MSG_INTERNAL_ERROR, "Couldn't restart task %s", atp->result->name ); diff --git a/client/app_start.cpp b/client/app_start.cpp index c305df071b..a4801fca97 100644 --- a/client/app_start.cpp +++ b/client/app_start.cpp @@ -1143,14 +1143,19 @@ int ACTIVE_TASK::resume_or_start(bool first_time) { ); return 0; } - if (log_flags.task) { + if (log_flags.task && first_time) { + msg_printf(result->project, MSG_INFO, + "Starting task %s", result->name + ); + } + if (log_flags.cpu_sched) { char buf[256]; strcpy(buf, ""); if (strlen(app_version->plan_class)) { sprintf(buf, " (%s)", app_version->plan_class); } msg_printf(result->project, MSG_INFO, - "%s task %s using %s version %d%s in slot %d", + "[cpu_sched] %s task %s using %s version %d%s in slot %d", str, result->name, app_version->app->name, diff --git a/client/client_state.h b/client/client_state.h index 86c90d6198..f625d46e94 100644 --- a/client/client_state.h +++ b/client/client_state.h @@ -19,6 +19,8 @@ #define _CLIENT_STATE_ #define NEW_CPU_THROTTLE +// do CPU throttling using a separate thread. +// This makes it possible to throttle faster than the client's 1-sec poll period #ifndef _WIN32 #include diff --git a/client/cpu_sched.cpp b/client/cpu_sched.cpp index a0e35edfa5..e6164647b1 100644 --- a/client/cpu_sched.cpp +++ b/client/cpu_sched.cpp @@ -444,7 +444,10 @@ RESULT* first_coproc_result(int rsc_type) { for (i=0; iresource_type() != rsc_type) continue; - if (!rp->runnable()) continue; + if (!rp->runnable()) { + //msg_printf(rp->project, MSG_INFO, "not runnable: %s", rp->name); + continue; + } if (rp->non_cpu_intensive()) continue; if (rp->already_selected) continue; prio = rp->project->sched_priority; diff --git a/client/cs_prefs.cpp b/client/cs_prefs.cpp index 00f6113ded..2a6ae2ede9 100644 --- a/client/cs_prefs.cpp +++ b/client/cs_prefs.cpp @@ -336,11 +336,7 @@ int CLIENT_STATE::check_suspend_processing() { } void CLIENT_STATE::show_suspend_tasks_message(int reason) { - if (reason == SUSPEND_REASON_CPU_THROTTLE) { - if (log_flags.cpu_sched) { - msg_printf(NULL, MSG_INFO, "[cpu_sched] Suspending - CPU throttle"); - } - } else { + if (reason != SUSPEND_REASON_CPU_THROTTLE) { if (log_flags.task) { msg_printf(NULL, MSG_INFO, "Suspending computation - %s", @@ -372,10 +368,7 @@ void CLIENT_STATE::show_suspend_tasks_message(int reason) { int CLIENT_STATE::resume_tasks(int reason) { if (reason == SUSPEND_REASON_CPU_THROTTLE) { - if (log_flags.cpu_sched) { - msg_printf(NULL, MSG_INFO, "[cpu_sched] Resuming - CPU throttle"); - } - active_tasks.unsuspend_all(); + active_tasks.unsuspend_all(SUSPEND_REASON_CPU_THROTTLE); } else { if (log_flags.task) { msg_printf(NULL, MSG_INFO, "Resuming computation");