-
Notifications
You must be signed in to change notification settings - Fork 515
Expand file tree
/
Copy pathclient_state.cpp
More file actions
2581 lines (2335 loc) · 76.2 KB
/
Copy pathclient_state.cpp
File metadata and controls
2581 lines (2335 loc) · 76.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This file is part of BOINC.
// https://boinc.berkeley.edu
// Copyright (C) 2024 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
// client initialization and main loop
#ifdef _WIN32
#include "boinc_win.h"
#else
#include "config.h"
#include <unistd.h>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cstdarg>
#include <cstring>
#include <cmath>
#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#endif
#ifdef __EMX__
#define INCL_DOS
#include <os2.h>
#endif
#include "cpp.h"
#include "error_numbers.h"
#include "filesys.h"
#include "parse.h"
#include "str_replace.h"
#include "str_util.h"
#include "url.h"
#include "util.h"
#ifdef _WIN32
#include "run_app_windows.h"
#endif
#include "app_config.h"
#include "async_file.h"
#include "client_msgs.h"
#include "cs_notice.h"
#include "cs_proxy.h"
#include "cs_trickle.h"
#include "file_names.h"
#include "hostinfo.h"
#include "http_curl.h"
#include "network.h"
#include "project.h"
#include "result.h"
#include "sandbox.h"
#include "shmem.h"
#include "client_state.h"
using std::max;
CLIENT_STATE gstate;
COPROCS coprocs;
#ifndef SIM
THREAD_LOCK client_thread_mutex;
THREAD throttle_thread;
#endif
CLIENT_STATE::CLIENT_STATE()
: lookup_website_op(&gui_http),
get_current_version_op(&gui_http),
get_project_list_op(&gui_http),
acct_mgr_op(&gui_http),
lookup_login_token_op(&gui_http)
{
http_ops = new HTTP_OP_SET();
file_xfers = new FILE_XFER_SET(http_ops);
pers_file_xfers = new PERS_FILE_XFER_SET(file_xfers);
#ifndef SIM
scheduler_op = new SCHEDULER_OP(http_ops);
#endif
time_stats.init();
client_state_dirty = false;
old_major_version = 0;
old_minor_version = 0;
old_release = 0;
clock_change = false;
check_all_logins = false;
user_active = false;
cmdline_gui_rpc_port = 0;
run_cpu_benchmarks = false;
file_xfer_giveup_period = PERS_GIVEUP;
had_or_requested_work = false;
tasks_suspended = false;
tasks_throttled = false;
network_suspended = false;
file_xfers_suspended = false;
suspend_reason = 0;
network_suspend_reason = 0;
core_client_version.major = BOINC_MAJOR_VERSION;
core_client_version.minor = BOINC_MINOR_VERSION;
core_client_version.release = BOINC_RELEASE;
#ifdef BOINC_PRERELEASE
core_client_version.prerelease = true;
#else
core_client_version.prerelease = false;
#endif
safe_strcpy(language, "");
safe_strcpy(client_brand, "");
exit_after_app_start_secs = 0;
app_started = 0;
cmdline_dir = false;
exit_before_upload = false;
#ifndef _WIN32
boinc_project_gid = 0;
#endif
show_projects = false;
safe_strcpy(detach_project_url, "");
safe_strcpy(reset_project_url, "");
safe_strcpy(update_prefs_url, "");
safe_strcpy(main_host_venue, "");
safe_strcpy(attach_project_url, "");
safe_strcpy(attach_project_auth, "");
cpu_run_mode.set(RUN_MODE_AUTO, 0);
gpu_run_mode.set(RUN_MODE_AUTO, 0);
network_run_mode.set(RUN_MODE_AUTO, 0);
started_by_screensaver = false;
requested_exit = false;
os_requested_suspend = false;
os_requested_suspend_time = 0;
cleanup_completed = false;
in_abort_sequence = false;
master_fetch_period = MASTER_FETCH_PERIOD;
retry_cap = RETRY_CAP;
master_fetch_retry_cap = MASTER_FETCH_RETRY_CAP;
master_fetch_interval = MASTER_FETCH_INTERVAL;
sched_retry_delay_min = SCHED_RETRY_DELAY_MIN;
sched_retry_delay_max = SCHED_RETRY_DELAY_MAX;
pers_retry_delay_min = PERS_RETRY_DELAY_MIN;
pers_retry_delay_max = PERS_RETRY_DELAY_MAX;
pers_giveup = PERS_GIVEUP;
executing_as_daemon = false;
redirect_io = false;
disable_graphics = false;
cant_write_state_file = false;
n_usable_cpus = 1;
benchmarks_running = false;
client_disk_usage = 0.0;
total_disk_usage = 0.0;
#ifdef ANDROID
device_status_time = dtime();
battery_charge_resume_time = 0;
battery_heat_resume_time = 0;
#endif
rec_interval_start = 0;
total_cpu_time_this_rec_interval = 0.0;
must_enforce_cpu_schedule = false;
must_schedule_cpus = true;
must_check_work_fetch = true;
retry_shmem_time = 0;
no_gui_rpc = false;
autologin_in_progress = false;
autologin_fetching_project_list = false;
gui_rpc_unix_domain = false;
new_version_check_time = 0;
all_projects_list_check_time = 0;
client_version_check_url = DEFAULT_VERSION_CHECK_URL;
detach_console = false;
#ifdef SANDBOX
g_use_sandbox = true; // User can override with -insecure command-line arg
#endif
launched_by_manager = false;
run_by_updater = false;
now = 0.0;
initialized = false;
last_wakeup_time = dtime();
#ifdef _WIN32
have_sysmon_msg = false;
#endif
have_sporadic_app = false;
}
void CLIENT_STATE::show_host_info() {
char buf[256], buf2[256];
msg_printf(NULL, MSG_INFO,
"Computer name: %s",
host_info.domain_name
);
nbytes_to_string(host_info.m_cache, 0, buf, sizeof(buf));
msg_printf(NULL, MSG_INFO,
"Processor: %d %s %s",
host_info.p_ncpus, host_info.p_vendor, host_info.p_model
);
if (n_usable_cpus != host_info.p_ncpus) {
msg_printf(NULL, MSG_INFO, "Using %d CPUs", n_usable_cpus);
}
msg_printf(NULL, MSG_INFO,
"Processor features: %s", host_info.p_features
);
#ifdef __APPLE__
buf[0] = '\0';
FILE *f = popen("sw_vers -productVersion", "r");
fgets(buf, sizeof(buf), f);
strip_whitespace(buf);
pclose(f);
msg_printf(NULL, MSG_INFO,
"OS: MacOS %s (%s %s)", buf,
host_info.os_name, host_info.os_version
);
#else
msg_printf(NULL, MSG_INFO,
"OS: %s: %s", host_info.os_name, host_info.os_version
);
#endif
nbytes_to_string(host_info.m_nbytes, 0, buf, sizeof(buf));
if (is_swap_defined()) {
nbytes_to_string(host_info.m_swap, 0, buf2, sizeof(buf2));
msg_printf(NULL, MSG_INFO, "Memory: %s RAM, %s swap space", buf, buf2);
} else {
msg_printf(NULL, MSG_INFO, "Memory: %s RAM", buf);
}
nbytes_to_string(host_info.d_total, 0, buf, sizeof(buf));
nbytes_to_string(host_info.d_free, 0, buf2, sizeof(buf2));
msg_printf(NULL, MSG_INFO, "Disk: %s total, %s free", buf, buf2);
int tz = host_info.timezone/3600;
msg_printf(0, MSG_INFO, "Local time is UTC %s%d hours",
tz<0?"":"+", tz
);
#ifdef _WIN64
if (host_info.wsl_distros.distros.empty()) {
// Don't print this message when running as a service (WSL detection is skipped)
if (!executing_as_daemon) {
msg_printf(NULL, MSG_INFO, "WSL: no usable distros found");
}
} else {
msg_printf(NULL, MSG_INFO, "Usable WSL distros:");
for (WSL_DISTRO &wsl : host_info.wsl_distros.distros) {
msg_printf(NULL, MSG_INFO,
"- %s (WSL %d)%s",
wsl.distro_name.c_str(),
wsl.wsl_version,
wsl.is_default ? " (default)" : ""
);
msg_printf(NULL, MSG_INFO,
"- OS: %s (%s)",
wsl.os_name.c_str(), wsl.os_version.c_str()
);
if (!wsl.libc_version.empty()) {
msg_printf(NULL, MSG_INFO,
"- libc version: %s", wsl.libc_version.c_str()
);
}
if (!wsl.docker_version.empty()) {
msg_printf(NULL, MSG_INFO, "- %s version %s",
docker_type_str(wsl.docker_type),
wsl.docker_version.c_str()
);
}
if (!wsl.docker_compose_version.empty()) {
msg_printf(NULL, MSG_INFO, "- %s compose version %s",
docker_type_str(wsl.docker_compose_type),
wsl.docker_compose_version.c_str()
);
}
if (wsl.boinc_buda_runner_version) {
msg_printf(NULL, MSG_INFO, "- BOINC WSL distro version %d",
wsl.boinc_buda_runner_version
);
if (!wsl.base_path.empty()) {
double size;
int retval = dir_size_alloc(wsl.base_path.c_str(), size);
if (!retval) {
nbytes_to_string(size, 0, buf, sizeof(buf));
msg_printf(NULL, MSG_INFO, "- Disk usage: %s", buf);
}
}
}
for (WSL_GPU &wg: wsl.wsl_gpus) {
msg_printf(NULL, MSG_INFO,
"- Usable GPU: %s,%s%s",
wg.name.c_str(),
wg.has_cuda?" CUDA":"",
wg.has_opencl?" OpenCL":""
);
}
}
}
#endif
// show Docker-related messages
//
#ifndef ANDROID
show_docker_messages();
#endif
if (strlen(host_info.virtualbox_version)) {
msg_printf(NULL, MSG_INFO,
"VirtualBox version: %s",
host_info.virtualbox_version
);
} else {
#if defined (_WIN32) && !defined(_WIN64)
if (!strcmp(get_primary_platform(), "windows_x86_64")) {
msg_printf(NULL, MSG_USER_ALERT,
"Can't detect VirtualBox because this is a 32-bit version of BOINC; to fix, please install a 64-bit version."
);
}
#endif
}
#ifndef _WIN64
if (strlen(host_info.docker_version)) {
msg_printf(NULL, MSG_INFO, "%s: version %s",
docker_type_str(host_info.docker_type),
host_info.docker_version
);
}
if (strlen(host_info.docker_compose_version)) {
msg_printf(NULL, MSG_INFO, "%s compose: version %s",
docker_type_str(host_info.docker_compose_type),
host_info.docker_compose_version
);
}
#endif
}
// TODO: the following 3 should be members of COPROCS
int rsc_index(const char* name) {
const char* nm = strcmp(name, "CUDA")?name:GPU_TYPE_NVIDIA;
// handle old state files
for (int i=0; i<coprocs.n_rsc; i++) {
if (!strcmp(nm, coprocs.coprocs[i].type)) {
return i;
}
}
return -1;
}
// used in XML and COPROC::type
//
const char* rsc_name(int i) {
return coprocs.coprocs[i].type;
}
// user-friendly version
//
const char* rsc_name_long(int i) {
int num = coproc_type_name_to_num(coprocs.coprocs[i].type);
if (num >= 0) return proc_type_name(num); // CPU, NVIDIA GPU, AMD GPU or Intel GPU
return coprocs.coprocs[i].type; // Some other type
}
#ifndef SIM
// alert user if any jobs need more RAM than available
// (based on RAM estimate, not measured size)
//
static void check_too_large_jobs() {
double m = gstate.max_available_ram();
for (PROJECT* p: gstate.projects) {
bool found = false;
for (RESULT* rp: gstate.results) {
if (rp->project == p && rp->wup->rsc_memory_bound > m) {
found = true;
break;
}
}
if (found) {
msg_printf(p, MSG_USER_ALERT,
_("Some tasks need more memory than allowed by your preferences. Please check the preferences.")
);
}
}
}
#endif
// Something has failed N times.
// Calculate an exponential backoff between MIN and MAX
//
double calculate_exponential_backoff(int n, double MIN, double MAX) {
double x = pow(2, (double)n);
x *= MIN;
if (x > MAX) x = MAX;
x *= (.5 + .5*drand());
return x;
}
#ifndef SIM
void CLIENT_STATE::set_now() {
double x = dtime();
// if time went backward significantly, clear delays
//
clock_change = false;
if (x < (now-60)) {
clock_change = true;
msg_printf(NULL, MSG_INFO,
"New system time (%.0f) < old system time (%.0f); clearing timeouts",
x, now
);
clear_absolute_times();
}
#ifdef _WIN32
// On Win, check for evidence that we're awake after a suspension
// (in case we missed the event announcing this)
//
if (os_requested_suspend) {
if (x > now+10) {
msg_printf(0, MSG_INFO, "Resuming after OS suspension");
os_requested_suspend = false;
} else if (x > os_requested_suspend_time + 300) {
msg_printf(0, MSG_INFO, "Resuming after OS suspension");
os_requested_suspend = false;
}
}
#endif
now = x;
}
// Check if version or platform has changed;
// if so we're running a different client than before.
//
bool CLIENT_STATE::is_new_client() {
bool new_client = false;
if ((core_client_version.major != old_major_version)
|| (core_client_version.minor != old_minor_version)
|| (core_client_version.release != old_release)
) {
if (old_major_version) {
msg_printf_notice(0, true, 0,
"The BOINC client version has changed from %d.%d.%d to %d.%d.%d.<br>To see what's new, view the <a href=%s>Client release notes</a>.",
old_major_version, old_minor_version, old_release,
core_client_version.major,
core_client_version.minor,
core_client_version.release,
"https://github.com/BOINC/boinc/wiki/Client-release-notes"
);
}
new_client = true;
}
if (statefile_platform_name.size() && strcmp(get_primary_platform(), statefile_platform_name.c_str())) {
msg_printf(NULL, MSG_INFO,
"Platform changed from %s to %s",
statefile_platform_name.c_str(), get_primary_platform()
);
new_client = true;
}
return new_client;
}
#ifdef _WIN32
typedef DWORD (WINAPI *STP)(HANDLE, DWORD);
#endif
static void set_client_priority() {
#ifdef _WIN32
STP stp = (STP) GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "SetThreadPriority");
if (!stp) return;
if (stp(GetCurrentThread(), THREAD_MODE_BACKGROUND_BEGIN)) {
msg_printf(NULL, MSG_INFO, "Running at background priority");
} else {
msg_printf(NULL, MSG_INFO, "Failed to set background priority");
}
#endif
#ifdef __linux__
char buf[1024];
snprintf(buf, sizeof(buf), "ionice -c 3 -p %d", getpid());
if (!system(buf)) {}
#endif
}
// initialize the client, and print messages about
// the host HW/SW and the configuration.
//
int CLIENT_STATE::init() {
int retval;
unsigned int i;
char buf[MAXPATHLEN];
srand((unsigned int)time(0));
now = dtime();
scheduler_op->url_random = drand();
notices.init();
daily_xfer_history.init();
time_stats.init();
detect_platforms();
time_stats.start();
msg_printf(
NULL, MSG_INFO, "Starting BOINC client version %d.%d.%d for %s%s",
core_client_version.major,
core_client_version.minor,
core_client_version.release,
HOSTTYPE,
#ifdef _DEBUG
" (DEBUG)"
#else
""
#endif
);
if (core_client_version.prerelease) {
msg_printf(NULL, MSG_INFO,
"This a development version of BOINC and may not function properly"
);
}
log_flags.show();
msg_printf(NULL, MSG_INFO, "cURL libraries: %s", curl_version());
if (cc_config.lower_client_priority) {
set_client_priority();
}
if (executing_as_daemon) {
#ifdef _WIN32
msg_printf(NULL, MSG_INFO, "Running as a daemon (GPU computing disabled)");
#else
msg_printf(NULL, MSG_INFO, "Running as a daemon");
#endif
}
relative_to_absolute("", buf);
msg_printf(NULL, MSG_INFO, "Data directory: %s", buf);
#ifdef _WIN32
DWORD buf_size = sizeof(buf);
LPTSTR pbuf = buf;
GetUserName(pbuf, &buf_size);
msg_printf(NULL, MSG_INFO, "Running under account %s", pbuf);
#endif
FILE* f = fopen(CLIENT_BRAND_FILENAME, "r");
if (f) {
if (fgets(client_brand, sizeof(client_brand), f)) {
strip_whitespace(client_brand);
msg_printf(NULL, MSG_INFO, "Client brand: %s", client_brand);
}
fclose(f);
}
// parse keyword file if present
//
f = fopen(KEYWORD_FILENAME, "r");
if (f) {
MIOFILE mf;
mf.init_file(f);
XML_PARSER xp(&mf);
retval = keywords.parse(xp);
if (!retval) keywords.present = true;
fclose(f);
#if 0
std::map<int, KEYWORD>::iterator it;
for (it = keywords.keywords.begin(); it != keywords.keywords.end(); it++) {
int id = it->first;
KEYWORD& kw = it->second;
printf("keyword %d: %s\n", id, kw.name.c_str());
}
#endif
}
parse_account_files();
parse_statistics_files();
// check for GPUs.
//
coprocs.bound_counts(); // show GPUs described in cc_config.xml
if (!cc_config.no_gpus
#ifdef _WIN32
&& !executing_as_daemon
#endif
) {
vector<string> descs;
vector<string> warnings;
coprocs.get(
cc_config.use_all_gpus, descs, warnings, cc_config.ignore_gpu_instance
);
for (const string &s: descs) {
msg_printf(NULL, MSG_INFO, "%s", s.c_str());
}
if (log_flags.coproc_debug) {
for (const string &s: warnings) {
msg_printf(NULL, MSG_INFO, "[coproc] %s", s.c_str());
}
}
#if 0
msg_printf(NULL, MSG_INFO, "Faking an NVIDIA GPU");
coprocs.nvidia.fake(18000, 512*MEGA, 490*MEGA, 2);
#endif
#if 0
msg_printf(NULL, MSG_INFO, "Faking an ATI GPU");
coprocs.ati.fake(512*MEGA, 256*MEGA, 2);
#endif
#if 0
msg_printf(NULL, MSG_INFO, "Faking an Intel GPU");
coprocs.intel_gpu.fake(512*MEGA, 256*MEGA, 2);
#endif
#if 0
fake_opencl_gpu("Mali-T628");
#endif
}
if (coprocs.have_nvidia()) {
if (rsc_index(GPU_TYPE_NVIDIA)>0) {
msg_printf(NULL, MSG_INFO, "NVIDIA GPU info taken from cc_config.xml");
} else {
coprocs.add(coprocs.nvidia);
}
}
if (coprocs.have_ati()) {
if (rsc_index(GPU_TYPE_ATI)>0) {
msg_printf(NULL, MSG_INFO, "ATI GPU info taken from cc_config.xml");
} else {
coprocs.add(coprocs.ati);
}
}
if (coprocs.have_intel_gpu()) {
if (rsc_index(GPU_TYPE_INTEL)>0) {
msg_printf(NULL, MSG_INFO, "INTEL GPU info taken from cc_config.xml");
} else {
coprocs.add(coprocs.intel_gpu);
}
}
if (coprocs.have_apple_gpu()) {
if (rsc_index(GPU_TYPE_APPLE)>0) {
msg_printf(NULL, MSG_INFO, "APPLE GPU info taken from cc_config.xml");
} else {
coprocs.add(coprocs.apple_gpu);
}
}
coprocs.add_other_coproc_types();
host_info.coprocs = coprocs;
if (coprocs.none() ) {
msg_printf(NULL, MSG_INFO, "No usable GPUs found");
}
set_no_rsc_config();
// check for app_info.xml file in project dirs.
// If find, read app info from there, set project.anonymous_platform
// - this must follow coproc.get() (need to know if GPUs are present)
// - this is being done before CPU speed has been read from state file,
// so we'll need to patch up avp->flops later;
//
check_anonymous();
// first time, set p_fpops nonzero to avoid div by zero
//
cpu_benchmarks_set_defaults();
// Parse the client state file,
// ignoring any <project> tags (and associated stuff)
// for projects with no account file
//
parse_state_file();
app_test_init();
bool new_client = is_new_client();
// this follows parse_state_file() since we need to have read
// domain_name for Android
//
host_info.get_host_info(true);
// clear the VM extensions disabled flag.
// It's possible that the user enabled them since the last VM failure,
// or that the last failure was specious.
//
host_info.p_vm_extensions_disabled = false;
set_n_usable_cpus();
show_host_info();
// this follows parse_state_file() because that's where we read project names
//
sort_projects_by_name();
// check for app_config.xml files in project dirs
//
check_app_config();
show_app_config();
// fill in resource usage for app versions that are missing it
// (typically anonymous platform)
//
for (APP_VERSION* avp: app_versions) {
avp->fill_in_resource_usage();
}
// must go after check_app_config() and parse_state_file()
// and after the above app version stuff
//
init_result_resource_usage();
// this needs to go after parse_state_file() because
// GPU exclusions refer to projects
//
cc_config.show();
// inform the user if there's a newer version of client
// NOTE: this must be called AFTER
// read_nvc_config_file()
//
newer_version_startup_check();
// parse account files again,
// now that we know the host's venue on each project
//
parse_account_files_venue();
// fill in p->no_X_apps for anon platform projects,
// and check no_rsc_apps for others
//
for (PROJECT *p: projects) {
if (p->anonymous_platform) {
p->check_no_apps();
} else {
p->check_no_rsc_apps();
}
}
process_gpu_exclusions();
// delete Docker images and containers not used by current jobs.
// Skip this if multiple clients are allowed;
// otherwise we'd delete other clients' containers
//
if (!cc_config.allow_multiple_clients) {
docker_cleanup();
}
check_clock_reset();
// Check to see if we can write the state file.
//
retval = write_state_file();
if (retval) {
msg_printf_notice(NULL, false,
"https://boinc.berkeley.edu/manager_links.php?target=notice&controlid=statefile",
_("Couldn't write state file; check directory permissions")
);
cant_write_state_file = true;
}
// scan user prefs; create file records
//
parse_preferences_for_user_files();
if (log_flags.state_debug) {
print_summary();
}
do_cmdline_actions();
// if new version of client,
// - run CPU benchmarks
// - get new project list
// - contact reference site (or some project) to trigger firewall alert
//
if (new_client) {
run_cpu_benchmarks = true;
all_projects_list_check_time = 0;
if (cc_config.dont_contact_ref_site) {
if (projects.size() > 0) {
projects[0]->master_url_fetch_pending = true;
}
} else {
net_status.need_to_contact_reference_site = true;
}
}
if (host_info.p_fpops == 0) {
run_cpu_benchmarks = true;
}
check_if_need_benchmarks();
read_global_prefs();
// do CPU scheduler and work fetch
//
request_schedule_cpus("Startup");
request_work_fetch("Startup");
work_fetch.init();
rec_interval_start = now;
// set up the project and slot directories
//
msg_printf(NULL, MSG_INFO, "Setting up project and slot directories");
delete_old_slot_dirs();
retval = make_project_dirs();
if (retval) return retval;
msg_printf(NULL, MSG_INFO, "Checking active tasks");
active_tasks.init();
check_overdue();
active_tasks.handle_upload_files();
had_or_requested_work = (active_tasks.active_tasks.size() > 0);
// Just to be on the safe side; something may have been modified
//
set_client_state_dirty("init");
// check for initialization files
//
process_autologin(true);
acct_mgr_info.init();
project_init.init();
// if project_init.xml specifies an account, attach
//
if (strlen(project_init.url) && strlen(project_init.account_key)) {
add_project(
project_init.url, project_init.account_key, project_init.name, "",
false
);
project_init.remove();
}
log_show_projects(); // this must follow acct_mgr_info.init()
// set up for handling GUI RPCs
//
if (!no_gui_rpc) {
msg_printf(NULL, MSG_INFO, "Setting up GUI RPC socket");
if (gui_rpc_unix_domain) {
retval = gui_rpcs.init_unix_domain();
} else {
// When we're running at boot time,
// it may be a few seconds before we can socket/bind/listen.
// So retry a few times.
//
for (i=0; i<30; i++) {
bool last_time = (i==29);
retval = gui_rpcs.init_tcp(last_time);
if (!retval) break;
boinc_sleep(1.0);
}
}
if (retval) return retval;
}
if (g_use_sandbox) get_project_gid();
#ifdef _WIN32
get_sandbox_account_service_token();
if (sandbox_account_service_token != NULL) {
g_use_sandbox = true;
}
#endif
msg_printf(NULL, MSG_INFO,
"Checking presence of %d project files", (int)file_infos.size()
);
check_file_existence();
if (!boinc_file_exists(ALL_PROJECTS_LIST_FILENAME)) {
all_projects_list_check_time = 0;
}
#ifdef ENABLE_AUTO_UPDATE
auto_update.init();
#endif
http_ops->cleanup_temp_files();
// must parse env vars after parsing state file
// otherwise items will get overwritten with state file info
//
parse_env_vars();
// do this after parsing env vars
//
proxy_info_startup();
if (!autologin_in_progress) {
if (gstate.projects.size() == 0) {
msg_printf(NULL, MSG_INFO,
"This computer is not attached to any projects"
);
}
}
// get list of BOINC projects occasionally,
// and initialize notice RSS feeds
//
if (!cc_config.no_info_fetch) {
all_projects_list_check();
notices.init_rss();
}
// check for jobs with finish files
// (i.e. they finished just as client was exiting)
//
active_tasks.check_for_finished_jobs();
// warn user if some jobs need more memory than available
//
check_too_large_jobs();
// initialize project priorities (for the GUI, in case we're suspended)
//
project_priority_init(false);
client_thread_mutex.lock();
throttle_thread.run(throttler, NULL);
sporadic_init();
initialized = true;
return 0;
}
static void double_to_timeval(double x, timeval& t) {
t.tv_sec = (int)x;
t.tv_usec = (int)(1000000*(x - (int)x));
}
FDSET_GROUP curl_fds;
FDSET_GROUP gui_rpc_fds;
FDSET_GROUP all_fds;
// Spend x seconds either doing I/O (if possible) or sleeping.
//
void CLIENT_STATE::do_io_or_sleep(double max_time) {
int n;
struct timeval tv;
set_now();
double end_time = now + max_time;
double time_remaining = max_time;
while (1) {
curl_fds.zero();
gui_rpc_fds.zero();
http_ops->get_fdset(curl_fds);
all_fds = curl_fds;
if (!autologin_in_progress) {
gui_rpcs.get_fdset(gui_rpc_fds, all_fds);
}
bool have_async = have_async_file_op();
// prioritize network (including GUI RPC) over async file ops.
// if there's a pending asynch file op, do the select with zero timeout;
// otherwise do it for the remaining amount of time.
double_to_timeval(have_async?0:time_remaining, tv);
client_thread_mutex.unlock();
if (all_fds.max_fd == -1) {
boinc_sleep(time_remaining);
n = 0;
} else {
n = select(
all_fds.max_fd+1,
&all_fds.read_fds, &all_fds.write_fds, &all_fds.exc_fds,
&tv
);
}
//printf("select in %d out %d\n", all_fds.max_fd, n);
client_thread_mutex.lock();
// Note: curl apparently likes to have curl_multi_perform()
// (called from net_xfers->got_select())
// called pretty often, even if no descriptors are enabled.
// So do the "if (n==0) break" AFTER the got_selects().
http_ops->got_select(all_fds, time_remaining);
gui_rpcs.got_select(all_fds);
if (have_async) {
// do the async file op only if no network activity
//
if (n == 0) {
do_async_file_op();
}
} else {
if (n == 0) {