Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: get 'in use' state only if computing preferences need it. #5797

Merged
merged 3 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading