69
73
vector<APP_VERSION*> app_versions;
70
74
vector<WORKUNIT*> workunits;
71
75
vector<RESULT*> results;
76
// list of jobs, ordered by increasing arrival time
73
78
PERS_FILE_XFER_SET* pers_file_xfers;
74
79
HTTP_OP_SET* http_ops;
75
80
FILE_XFER_SET* file_xfers;
82
GUI_RPC_CONN_SET gui_rpcs;
85
AUTO_UPDATE auto_update;
86
LOOKUP_WEBSITE_OP lookup_website_op;
87
GET_CURRENT_VERSION_OP get_current_version_op;
88
GET_PROJECT_LIST_OP get_project_list_op;
89
ACCT_MGR_OP acct_mgr_op;
91
TIME_STATS time_stats;
92
GLOBAL_PREFS global_prefs;
76
94
ACTIVE_TASK_SET active_tasks;
77
95
HOST_INFO host_info;
78
GLOBAL_PREFS global_prefs;
80
GUI_RPC_CONN_SET gui_rpcs;
81
TIME_STATS time_stats;
82
PROXY_INFO proxy_info;
86
97
VERSION_INFO core_client_version;
87
98
string statefile_platform_name;
88
99
int file_xfer_giveup_period;
90
102
MODE network_mode;
91
103
bool started_by_screensaver;
93
104
bool exit_before_start;
94
bool exit_after_finish;
95
105
bool check_all_logins;
96
106
bool user_active; // there has been recent mouse/kbd input
97
bool allow_remote_gui_rpc;
98
107
int cmdline_gui_rpc_port;
99
108
bool show_projects;
100
109
bool requested_exit;
101
/// stores URL for -detach_project option
110
bool requested_suspend;
111
bool requested_resume;
112
bool cleanup_completed;
113
bool in_abort_sequence;
114
// Determine when it is safe to leave the quit_client() handler
115
// and to finish cleaning up.
102
116
char detach_project_url[256];
103
/// stores URL for -reset_project option
117
// stores URL for -detach_project option
104
118
char reset_project_url[256];
105
/// stores URL for -update_prefs option
119
// stores URL for -reset_project option
106
120
char update_prefs_url[256];
107
/// venue from project or AMS that gave us general prefs
121
// stores URL for -update_prefs option
108
122
char main_host_venue[256];
123
// venue from project or AMS that gave us general prefs
109
124
char attach_project_url[256];
110
125
char attach_project_auth[256];
111
/// exit when about to upload a file
112
126
bool exit_before_upload;
127
// exit when about to upload a file
114
129
gid_t boinc_project_gid;
117
132
// backoff-related variables
119
/// fetch project's master URL (and stop doing scheduler RPCs)
120
/// if get this many successive RPC failures (default 10)
121
134
int master_fetch_period;
122
/// cap project->nrpc_failures at this number
135
// fetch project's master URL (and stop doing scheduler RPCs)
136
// if get this many successive RPC failures (default 10)
124
/// after this many master-fetch failures,
125
/// move into a state in which we retry master fetch
126
/// at the frequency below
138
// cap project->nrpc_failures at this number
127
139
int master_fetch_retry_cap;
140
// after this many master-fetch failures,
141
// move into a state in which we retry master fetch
142
// at the frequency below
129
143
int master_fetch_interval;
131
146
int sched_retry_delay_min;
132
147
int sched_retry_delay_max;
134
149
int pers_retry_delay_max;
137
/// Don't use CPU. See check_suspend_activities for logic
138
152
bool tasks_suspended;
139
/// Don't use network. See check_suspend_network for logic
140
156
bool network_suspended;
157
// Don't use network.
158
bool file_xfers_suspended;
159
// Don't do file xfers (but allow other network activity).
142
160
int network_suspend_reason;
143
/// true if --daemon is on the commandline
145
/// this means we are running as a daemon on unix,
146
/// or as a service on Windows
147
bool executing_as_daemon;
148
/// redirect stdout, stderr to log files
162
bool executing_as_daemon;
163
// true if --daemon is on the commandline
164
// this means we are running as a daemon on unix,
165
// or as a service on Windows
149
166
bool redirect_io;
150
/// a condition has occurred in which we know graphics will
151
/// not be displayable, so GUIs shouldn't offer graphics.
167
// redirect stdout, stderr to log files
152
168
bool disable_graphics;
169
// a condition has occurred in which we know graphics will
170
// not be displayable, so GUIs shouldn't offer graphics.
153
171
bool detach_console;
154
/// this affects auto-update
155
172
bool launched_by_manager;
173
// this affects auto-update
156
174
bool run_by_updater;
158
176
double client_start_time;
159
177
double last_wakeup_time;
160
178
bool initialized;
161
/// failed to write state file.
163
/// In this case we continue to run for 1 minute,
164
/// handling GUI RPCs but doing nothing else,
165
/// so that the Manager can tell the user what the problem is
166
179
bool cant_write_state_file;
180
// failed to write state file.
181
// In this case we continue to run for 1 minute,
182
// handling GUI RPCs but doing nothing else,
183
// so that the Manager can tell the user what the problem is
168
185
bool client_state_dirty;
169
186
int old_major_version;
170
187
int old_minor_version;
172
/// if set, use hardwired numbers rather than running benchmarks
173
bool skip_cpu_benchmarks;
174
/// if set, run benchmarks on client startup
175
189
bool run_cpu_benchmarks;
176
/// set if a benchmark fails to start because of a process that doesn't stop.
177
/// Persists so that the next start of BOINC runs the benchmarks.
190
// if set, run benchmarks on client startup
178
191
bool cpu_benchmarks_pending;
192
// set if a benchmark fails to start because of a job that doesn't exit
193
// Persists so that the next start of BOINC runs the benchmarks.
180
/// if nonzero, exit this many seconds after starting an app
181
195
int exit_after_app_start_secs;
182
/// when the most recent app was started
196
// if nonzero, exit this many seconds after starting an app
183
197
double app_started;
198
// when the most recent app was started
185
200
// --------------- acct_mgr.cpp:
187
ACCT_MGR_OP acct_mgr_op;
188
201
ACCT_MGR_INFO acct_mgr_info;
190
203
// --------------- acct_setup.cpp:
192
204
PROJECT_INIT project_init;
193
205
PROJECT_ATTACH project_attach;
194
LOOKUP_WEBSITE_OP lookup_website_op;
195
GET_CURRENT_VERSION_OP get_current_version_op;
196
GET_PROJECT_LIST_OP get_project_list_op;
197
206
void new_version_check();
198
207
void all_projects_list_check();
199
208
double new_version_check_time;
200
209
double all_projects_list_check_time;
201
210
string newer_version;
203
// --------------- auto_update.cpp:
205
AUTO_UPDATE auto_update;
207
212
// --------------- client_state.cpp:
210
214
void show_host_info();
211
void show_proxy_info();
214
/// Returns true if it actually did something,
215
/// in which case it should be called again immediately.
216
216
bool poll_slow_events();
218
// Returns true if it actually did something,
219
// in which case it should be called again immediately.
217
220
void do_io_or_sleep(double dt);
218
221
bool time_to_exit();
219
222
PROJECT* lookup_project(const char*);
243
250
void check_clock_reset();
245
252
// --------------- cpu_sched.cpp:
253
double total_resource_share();
254
double potentially_runnable_resource_share();
255
double nearly_runnable_resource_share();
256
double fetchable_resource_share();
247
257
double debt_interval_start;
248
double total_wall_cpu_time_this_debt_interval;
249
// "wall CPU time" accumulated since last adjust_debts()
250
258
double total_cpu_time_this_debt_interval;
251
double cpu_shortfall;
252
bool work_fetch_no_new_work;
253
259
bool must_enforce_cpu_schedule;
254
260
bool must_schedule_cpus;
255
261
bool must_check_work_fetch;
256
262
void assign_results_to_projects();
257
263
RESULT* largest_debt_project_best_result();
258
RESULT* earliest_deadline_result();
259
264
void reset_debt_accounting();
261
265
bool possibly_schedule_cpus();
262
266
void schedule_cpus();
263
267
bool enforce_schedule();
264
bool no_work_for_a_cpu();
265
void make_preemptable_task_list(vector<ACTIVE_TASK*>&, double&);
268
void append_unfinished_time_slice(vector<RESULT*>&);
270
double runnable_resource_share(int);
267
272
std::vector <RESULT*> ordered_scheduled_results;
268
/// if we fail to start a task due to no shared-mem segments,
269
/// wait until at least this time to try running
270
/// another task that needs a shared-mem seg
271
273
double retry_shmem_time;
272
inline double work_buf_min() {
273
return global_prefs.work_buf_min_days * 86400;
274
// if we fail to start a task due to no shared-mem segments,
275
// wait until at least this time to try running
276
// another task that needs a shared-mem seg
277
inline double work_buf_min() {
278
return global_prefs.work_buf_min_days * 86400;
275
280
inline double work_buf_additional() {
276
281
return global_prefs.work_buf_additional_days *86400;
280
285
if (x < 1) x = 1;
283
void request_enforce_schedule(const char*);
284
/// Check for reschedule CPUs ASAP.
287
/// - core client starts (CS::init())
288
/// - an app exits (ATS::check_app_exited())
289
/// - Tasks are killed (ATS::exit_tasks())
290
/// - a result's input files finish downloading (CS::update_results())
291
/// - an app fails to start (CS::schedule_cpus())
292
/// - any project op is done via RPC (suspend/resume)
293
/// - any result op is done via RPC (suspend/resume)
294
289
void request_schedule_cpus(const char*);
290
// Reschedule CPUs ASAP.
292
// - core client starts (CS::init())
293
// - an app exits (ATS::check_app_exited())
294
// - Tasks are killed (ATS::exit_tasks())
295
// - a result's input files finish downloading (CS::update_results())
296
// - an app fails to start (CS::schedule_cpus())
297
// - any project op is done via RPC (suspend/resume)
298
// - any result op is done via RPC (suspend/resume)
296
301
// --------------- cs_account.cpp:
299
303
const char* master_url, const char* authenticator,
300
304
const char* project_name, bool attached_via_acct_mgr
303
307
int parse_account_files();
304
308
int parse_account_files_venue();
305
309
int parse_preferences_for_user_files();
307
311
// should be move to a new file, but this will do it for testing
309
313
// --------------- cs_apps.cpp:
311
double total_resource_share();
312
double potentially_runnable_resource_share();
313
double nearly_runnable_resource_share();
314
double fetchable_resource_share();
316
double runnable_resource_share();
317
/// Check if work fetch needed.
320
/// - core client starts (CS::init())
321
/// - task is completed or fails
322
/// - tasks are killed
323
/// - an RPC completes
324
/// - project suspend/detch/attach/reset GUI RPC
325
/// - result suspend/abort GUI RPC
326
void request_work_fetch(const char*);
327
int quit_activities();
329
double estimate_cpu_time(WORKUNIT&);
330
314
double get_fraction_done(RESULT* result);
331
315
int input_files_available(RESULT*, bool, FILE_INFO** f=0);
332
316
ACTIVE_TASK* lookup_active_task_by_result(RESULT*);
333
/// number of usable cpus
318
// Act like there are this many CPUs.
319
// By default this is the # of physical CPUs,
320
// but it can be changed in two ways:
321
// - type <ncpus>N</ncpus> in the config file
322
// - type the max_ncpus_pct pref
338
324
int latest_version(APP*, char*);
339
325
int app_finished(ACTIVE_TASK&);
340
326
bool start_apps();
341
327
bool handle_finished_apps();
343
329
ACTIVE_TASK* get_task(RESULT*);
345
331
// --------------- cs_benchmark.cpp:
347
332
bool should_run_cpu_benchmarks();
348
void start_cpu_benchmarks();
333
void start_cpu_benchmarks();
349
334
bool cpu_benchmarks_poll();
350
335
void abort_cpu_benchmarks();
351
336
bool are_cpu_benchmarks_running();
352
bool cpu_benchmarks_done();
353
void cpu_benchmarks_set_defaults();
337
bool cpu_benchmarks_done();
338
void cpu_benchmarks_set_defaults();
354
339
void print_benchmark_results();
356
341
// --------------- cs_cmdline.cpp:
358
342
void parse_cmdline(int argc, char** argv);
359
343
void parse_env_vars();
360
344
void do_cmdline_actions();
362
346
// --------------- cs_files.cpp:
364
347
void check_file_existence();
365
348
bool start_new_file_xfer(PERS_FILE_XFER&);
367
350
int make_project_dirs();
368
351
bool handle_pers_file_xfers();
370
353
// --------------- cs_platforms.cpp:
372
354
const char* get_primary_platform();
374
355
void add_platform(const char*);
375
356
void detect_platforms();
376
357
void write_platforms(PROJECT*, MIOFILE&);
377
358
bool is_supported_platform(const char*);
379
360
// --------------- cs_prefs.cpp:
381
361
int project_disk_usage(PROJECT*, double&);
382
/// returns the total disk usage of BOINC on this host
383
362
int total_disk_usage(double&);
363
// returns the total disk usage of BOINC on this host
384
364
double allowed_disk_usage(double boinc_total);
385
365
int allowed_project_disk_usage(double&);
386
366
int suspend_tasks(int reason);
387
367
int resume_tasks(int reason=0);
388
int suspend_network(int reason);
389
int resume_network();
390
368
void read_global_prefs();
391
369
int save_global_prefs(char* prefs, char* url, char* sched);
392
double available_ram();
393
double max_available_ram();
370
double available_ram();
371
double max_available_ram();
395
372
int check_suspend_processing();
396
int check_suspend_network();
373
void check_suspend_network();
397
374
void install_global_prefs();
398
375
PROJECT* global_prefs_source_project();
399
376
void show_global_prefs_source(bool);
401
378
// --------------- cs_scheduler.cpp:
379
void request_work_fetch(const char*);
381
// - core client starts (CS::init())
382
// - task is completed or fails
383
// - tasks are killed
384
// - an RPC completes
385
// - project suspend/detch/attach/reset GUI RPC
386
// - result suspend/abort GUI RPC
403
387
int make_scheduler_request(PROJECT*);
404
int handle_scheduler_reply(PROJECT*, char* scheduler_url, int& nresults);
388
int handle_scheduler_reply(PROJECT*, char* scheduler_url);
405
389
SCHEDULER_OP* scheduler_op;
407
bool contacted_sched_server;
408
int overall_work_fetch_urgency;
390
PROJECT* next_project_master_pending();
391
PROJECT* next_project_sched_rpc_pending();
392
PROJECT* next_project_trickle_up_pending();
393
PROJECT* find_project_with_overdue_results();
394
bool had_or_requested_work;
410
395
bool scheduler_rpc_poll();
411
double avg_proc_rate();
412
bool should_get_work();
414
397
// --------------- cs_statefile.cpp:
416
398
void set_client_state_dirty(const char*);
417
399
int parse_state_file();
418
400
int write_state(MIOFILE&);
419
401
int write_state_file();
420
402
int write_state_file_if_needed();
421
void check_anonymous();
422
int parse_app_info(PROJECT*, FILE*);
403
void check_anonymous();
404
int parse_app_info(PROJECT*, FILE*);
423
405
int write_state_gui(MIOFILE&);
424
406
int write_file_transfers_gui(MIOFILE&);
425
int write_tasks_gui(MIOFILE&);
407
int write_tasks_gui(MIOFILE&, bool);
427
410
// --------------- cs_trickle.cpp:
429
411
int read_trickle_files(PROJECT*, FILE*);
430
412
int remove_trickle_files(PROJECT*);
432
413
int handle_trickle_down(PROJECT*, FILE*);
434
415
// --------------- check_state.cpp:
435
416
// stuff related to data-structure integrity checking
438
418
void check_project_pointer(PROJECT*);
439
419
void check_app_pointer(APP*);
440
420
void check_file_info_pointer(FILE_INFO*);
462
442
void print_deadline_misses();
464
444
// --------------- work_fetch.cpp:
466
445
int proj_min_results(PROJECT*, double);
467
void check_project_timeout();
468
PROJECT* next_project_master_pending();
469
PROJECT* next_project_sched_rpc_pending();
470
PROJECT* next_project_trickle_up_pending();
471
PROJECT* next_project_need_work();
472
PROJECT* find_project_with_overdue_results();
473
double overall_cpu_frac();
446
void check_project_timeout();
447
double overall_cpu_frac();
448
double overall_gpu_frac();
474
449
double time_until_work_done(PROJECT*, int, double);
475
450
bool compute_work_requests();
476
451
void scale_duration_correction_factors(double);
477
452
void generate_new_host_cpid();
478
453
void compute_nuploading_results();
456
RANDOM_PROCESS available;
459
double connection_interval;
460
// don't connect more often than this
462
void html_start(bool);
465
std::string html_msg;
466
double share_violation();
469
void do_client_simulation();
470
void handle_completed_results(PROJECT*);
471
void get_workload(vector<IP_RESULT>&);
473
bool simulate_rpc(PROJECT*);
474
void print_project_results(FILE*);
482
478
extern CLIENT_STATE gstate;
484
/// return a random double in the range [MIN,min(e^n,MAX))
480
extern bool gpus_usable;
482
// return a random double in the range [MIN,min(e^n,MAX))
486
484
extern double calculate_exponential_backoff(
487
485
int n, double MIN, double MAX
490
488
extern void print_suspend_tasks_message(int);
490
//////// TIME-RELATED CONSTANTS ////////////
492
//////// CLIENT INTERNAL
492
494
#define POLL_INTERVAL 1.0
493
495
// the client will handle I/O (including GUI RPCs)
494
496
// for up to POLL_INTERVAL seconds before calling poll_slow_events()
495
497
// to call the polling functions
497
#define CPU_PESSIMISM_FACTOR 0.9
498
// assume actual CPU utilization will be this multiple
499
// of what we've actually measured recently
499
#define GARBAGE_COLLECT_PERIOD 10
500
// how often to garbage collect
502
#define TASK_POLL_PERIOD 1.0
504
#define UPDATE_RESULTS_PERIOD 1.0
506
#define HANDLE_FINISHED_APPS_PERIOD 1.0
508
#define BENCHMARK_POLL_PERIOD 1.0
510
#define PERS_FILE_XFER_START_PERIOD 1.0
511
#define PERS_FILE_XFER_POLL_PERIOD 1.0
513
#define SCHEDULER_RPC_POLL_PERIOD 5.0
515
#define FILE_XFER_POLL_PERIOD 1.0
517
#define GUI_HTTP_POLL_PERIOD 1.0
521
#define WORK_FETCH_PERIOD 60
522
// see if we need to fetch work at least this often
523
#define WF_MIN_BACKOFF_INTERVAL 600
524
#define WF_MAX_BACKOFF_INTERVAL 86400
525
// if we ask a project for work for a resource and don't get it,
526
// we do exponential backoff.
527
// This constant is an upper bound for this.
528
// E.g., if we need GPU work, we'll end up asking once a day,
529
// so if the project develops a GPU app,
530
// we'll find out about it within a day.
532
//////// CPU SCHEDULING
534
#define CPU_SCHED_PERIOD 60
535
// do CPU schedule at least this often
537
#define DEBT_ADJUST_PERIOD CPU_SCHED_PERIOD
538
// debt is adjusted at least this often,
539
// since adjust_debts() is called from enforce_schedule()
543
#define CONNECT_ERROR_PERIOD 600.0
545
#define ALLOW_NETWORK_IF_RECENT_RPC_PERIOD 300
546
// if there has been a GUI RPC within this period
547
// that requires network access (e.g. attach to project)
548
// allow it even if setting is "no access"
552
#define DAILY_XFER_HISTORY_PERIOD 60
554
#define MAX_STD (86400)
555
// maximum short-term debt
557
#define ACCT_MGR_MIN_BACKOFF 600
558
#define ACCT_MGR_MAX_BACKOFF 86400
559
// min/max account manager RPC backoff