Skip to content

Commit afe1c73

Browse files
authored
Merge pull request #5797 from BOINC/dpa_need_idle_state
client: get 'in use' state only if computing preferences need it.
2 parents 415efaa + 3b66894 commit afe1c73

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

client/client_state.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,18 +1019,30 @@ bool CLIENT_STATE::poll_slow_events() {
10191019
}
10201020
#endif
10211021

1022-
bool old_user_active = user_active;
1022+
// there are 2 reasons to get idle state:
1023+
// if needed for computing prefs,
1024+
// or (on Mac) we were started by screensaver
1025+
//
1026+
bool get_idle_state = global_prefs.need_idle_state;
1027+
#ifdef __APPLE__
1028+
if (started_by_screensaver) get_idle_state = true;
1029+
#endif
1030+
long idle_time;
1031+
if (get_idle_state) {
1032+
bool old_user_active = user_active;
10231033
#ifdef ANDROID
1024-
user_active = device_status.user_active;
1034+
user_active = device_status.user_active;
10251035
#else
1026-
long idle_time = host_info.user_idle_time(check_all_logins);
1027-
user_active = idle_time < global_prefs.idle_time_to_run * 60;
1036+
idle_time = host_info.user_idle_time(check_all_logins);
1037+
user_active = idle_time < global_prefs.idle_time_to_run * 60;
10281038
#endif
1029-
1030-
if (user_active != old_user_active) {
1031-
set_n_usable_cpus();
1032-
// if niu_max_ncpus_pct pref is set, # usable CPUs may change
1033-
request_schedule_cpus(user_active?"Not idle":"Idle");
1039+
if (user_active != old_user_active) {
1040+
set_n_usable_cpus();
1041+
// if niu_max_ncpus_pct pref is set, # usable CPUs may change
1042+
request_schedule_cpus(user_active?"Not idle":"Idle");
1043+
}
1044+
} else {
1045+
user_active = false; // shouldn't matter what it is
10341046
}
10351047

10361048
#if 0

client/cs_prefs.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,9 @@ void CLIENT_STATE::read_global_prefs(
675675
file_xfers->set_bandwidth_limits(true);
676676
file_xfers->set_bandwidth_limits(false);
677677
#endif
678+
679+
bool have_gpu = coprocs.n_rsc > 1;
680+
global_prefs.need_idle_state = global_prefs.get_need_idle_state(have_gpu);
678681
print_global_prefs();
679682
request_schedule_cpus("Prefs update");
680683
request_work_fetch("Prefs update");
@@ -815,6 +818,11 @@ void CLIENT_STATE::print_global_prefs() {
815818
allowed_disk_usage(total_disk_usage)/GIGA
816819
);
817820
#endif
821+
if (!global_prefs.need_idle_state) {
822+
msg_printf(NULL, MSG_INFO,
823+
"- Preferences don't depend on whether computer is in use"
824+
);
825+
}
818826
msg_printf(NULL, MSG_INFO,
819827
"- (to change preferences, visit a project web site or select 'Options / Computing preferences...' in the Manager)"
820828
);

lib/prefs.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ struct GLOBAL_PREFS {
197197
bool host_specific;
198198
// an account manager can set this; if set, don't propagate
199199
bool override_file_present;
200+
bool need_idle_state;
201+
// whether idle state makes any difference
200202

201203
GLOBAL_PREFS();
202204
void defaults();
@@ -214,6 +216,17 @@ struct GLOBAL_PREFS {
214216
return cpu_scheduling_period_minutes*60;
215217
}
216218
static double parse_mod_time(const char*);
219+
bool get_need_idle_state(bool have_gpu) {
220+
// is any pref set that causes different behavior if user is active?
221+
//
222+
if (!run_if_user_active) return true;
223+
if (have_gpu && !run_gpu_if_user_active) return true;
224+
if (suspend_if_no_recent_input) return true;
225+
if (niu_cpu_usage_limit && niu_cpu_usage_limit != cpu_usage_limit) return true;
226+
if (niu_max_ncpus_pct && niu_max_ncpus_pct != max_ncpus_pct) return true;
227+
if (niu_suspend_cpu_usage && niu_suspend_cpu_usage != suspend_cpu_usage) return true;
228+
return false;
229+
}
217230
};
218231

219232
#endif

0 commit comments

Comments
 (0)