Skip to content

Commit

Permalink
Merge pull request #5797 from BOINC/dpa_need_idle_state
Browse files Browse the repository at this point in the history
client: get 'in use' state only if computing preferences need it.
  • Loading branch information
AenBleidd authored Sep 6, 2024
2 parents 415efaa + 3b66894 commit afe1c73
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
30 changes: 21 additions & 9 deletions client/client_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,18 +1019,30 @@ bool CLIENT_STATE::poll_slow_events() {
}
#endif

bool old_user_active = user_active;
// there are 2 reasons to get idle state:
// if needed for computing prefs,
// or (on Mac) we were started by screensaver
//
bool get_idle_state = global_prefs.need_idle_state;
#ifdef __APPLE__
if (started_by_screensaver) get_idle_state = true;
#endif
long idle_time;
if (get_idle_state) {
bool old_user_active = user_active;
#ifdef ANDROID
user_active = device_status.user_active;
user_active = device_status.user_active;
#else
long idle_time = host_info.user_idle_time(check_all_logins);
user_active = idle_time < global_prefs.idle_time_to_run * 60;
idle_time = host_info.user_idle_time(check_all_logins);
user_active = idle_time < global_prefs.idle_time_to_run * 60;
#endif

if (user_active != old_user_active) {
set_n_usable_cpus();
// if niu_max_ncpus_pct pref is set, # usable CPUs may change
request_schedule_cpus(user_active?"Not idle":"Idle");
if (user_active != old_user_active) {
set_n_usable_cpus();
// if niu_max_ncpus_pct pref is set, # usable CPUs may change
request_schedule_cpus(user_active?"Not idle":"Idle");
}
} else {
user_active = false; // shouldn't matter what it is
}

#if 0
Expand Down
8 changes: 8 additions & 0 deletions client/cs_prefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,9 @@ void CLIENT_STATE::read_global_prefs(
file_xfers->set_bandwidth_limits(true);
file_xfers->set_bandwidth_limits(false);
#endif

bool have_gpu = coprocs.n_rsc > 1;
global_prefs.need_idle_state = global_prefs.get_need_idle_state(have_gpu);
print_global_prefs();
request_schedule_cpus("Prefs update");
request_work_fetch("Prefs update");
Expand Down Expand Up @@ -815,6 +818,11 @@ void CLIENT_STATE::print_global_prefs() {
allowed_disk_usage(total_disk_usage)/GIGA
);
#endif
if (!global_prefs.need_idle_state) {
msg_printf(NULL, MSG_INFO,
"- Preferences don't depend on whether computer is in use"
);
}
msg_printf(NULL, MSG_INFO,
"- (to change preferences, visit a project web site or select 'Options / Computing preferences...' in the Manager)"
);
Expand Down
13 changes: 13 additions & 0 deletions lib/prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ struct GLOBAL_PREFS {
bool host_specific;
// an account manager can set this; if set, don't propagate
bool override_file_present;
bool need_idle_state;
// whether idle state makes any difference

GLOBAL_PREFS();
void defaults();
Expand All @@ -214,6 +216,17 @@ struct GLOBAL_PREFS {
return cpu_scheduling_period_minutes*60;
}
static double parse_mod_time(const char*);
bool get_need_idle_state(bool have_gpu) {
// is any pref set that causes different behavior if user is active?
//
if (!run_if_user_active) return true;
if (have_gpu && !run_gpu_if_user_active) return true;
if (suspend_if_no_recent_input) return true;
if (niu_cpu_usage_limit && niu_cpu_usage_limit != cpu_usage_limit) return true;
if (niu_max_ncpus_pct && niu_max_ncpus_pct != max_ncpus_pct) return true;
if (niu_suspend_cpu_usage && niu_suspend_cpu_usage != suspend_cpu_usage) return true;
return false;
}
};

#endif

0 comments on commit afe1c73

Please sign in to comment.