Skip to content

Commit 4cceee3

Browse files
authored
Merge pull request #7084 from BOINC/dpa_app_network
Client, Manager, API, docker_wrapper: support network access from apps
2 parents 01e8d61 + cbe058e commit 4cceee3

29 files changed

Lines changed: 363 additions & 270 deletions

api/boinc_api.cpp

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,6 @@ static volatile int running_interrupt_count = 0;
190190
static volatile bool finishing;
191191
// used for worker/timer synch during boinc_finish();
192192
static int want_network = 0;
193-
static int have_network = 1;
194-
static double bytes_sent = 0;
195-
static double bytes_received = 0;
196193
bool boinc_disable_timer_thread = false;
197194
// simulate unresponsive app by setting to true (debugging)
198195
static FUNC_PTR timer_callback = 0;
@@ -205,6 +202,7 @@ int app_min_checkpoint_period = 0;
205202
static volatile SPORADIC_AC_STATE ac_state;
206203
static volatile int ac_fd, ca_fd;
207204
static volatile bool do_sporadic_files;
205+
volatile bool got_heartbeat_message = false;
208206

209207
#define TIMER_PERIOD 0.1
210208
// Sleep interval for timer thread;
@@ -425,26 +423,17 @@ static bool update_app_progress(double cpu_t, double cp_cpu_t) {
425423

426424
snprintf(msg_buf, sizeof(msg_buf),
427425
"<current_cpu_time>%e</current_cpu_time>\n"
428-
"<checkpoint_cpu_time>%e</checkpoint_cpu_time>\n",
429-
cpu_t, cp_cpu_t
426+
"<checkpoint_cpu_time>%e</checkpoint_cpu_time>\n"
427+
"<want_network>%d</want_network>\n",
428+
cpu_t, cp_cpu_t,
429+
want_network?1:0
430430
);
431-
if (want_network) {
432-
strlcat(msg_buf, "<want_network>1</want_network>\n", sizeof(msg_buf));
433-
}
434431
if (fraction_done >= 0) {
435432
double range = aid.fraction_done_end - aid.fraction_done_start;
436433
double fdone = aid.fraction_done_start + fraction_done*range;
437434
snprintf(buf, sizeof(buf), "<fraction_done>%e</fraction_done>\n", fdone);
438435
strlcat(msg_buf, buf, sizeof(msg_buf));
439436
}
440-
if (bytes_sent) {
441-
snprintf(buf, sizeof(buf), "<bytes_sent>%f</bytes_sent>\n", bytes_sent);
442-
strlcat(msg_buf, buf, sizeof(msg_buf));
443-
}
444-
if (bytes_received) {
445-
snprintf(buf, sizeof(buf), "<bytes_received>%f</bytes_received>\n", bytes_received);
446-
strlcat(msg_buf, buf, sizeof(msg_buf));
447-
}
448437
if (ac_state) {
449438
sprintf(buf, "<sporadic_ac>%d</sporadic_ac>\n", ac_state);
450439
strlcat(msg_buf, buf, sizeof(msg_buf));
@@ -480,12 +469,13 @@ static void handle_heartbeat_msg() {
480469
if (parse_double(buf, "<max_wss>", dtemp)) {
481470
boinc_status.max_working_set_size = dtemp;
482471
}
483-
if (parse_bool(buf, "suspend_network", btemp)) {
472+
if (parse_bool(buf, "network_suspended", btemp)) {
484473
boinc_status.network_suspended = btemp;
485474
}
486475
if (parse_int(buf, "<sporadic_ca>", i)) {
487476
boinc_status.ca_state = (SPORADIC_CA_STATE)i;
488477
}
478+
got_heartbeat_message = true;
489479
}
490480

491481
// called in timer thread
@@ -970,11 +960,6 @@ void boinc_exit(int status) {
970960
#endif
971961
}
972962

973-
void boinc_network_usage(double sent, double received) {
974-
bytes_sent = sent;
975-
bytes_received = received;
976-
}
977-
978963
int boinc_is_standalone() {
979964
if (standalone) return 1;
980965
return 0;
@@ -1087,8 +1072,8 @@ int boinc_report_app_status_aux(
10871072
double checkpoint_cpu_time,
10881073
double _fraction_done,
10891074
int other_pid,
1090-
double _bytes_sent,
1091-
double _bytes_received,
1075+
double /* _bytes_sent*/,
1076+
double /* _bytes_received*/,
10921077
double wss
10931078
) {
10941079
char msg_buf[MSG_CHANNEL_SIZE], buf[1024];
@@ -1106,14 +1091,6 @@ int boinc_report_app_status_aux(
11061091
snprintf(buf, sizeof(buf), "<other_pid>%d</other_pid>\n", other_pid);
11071092
safe_strcat(msg_buf, buf);
11081093
}
1109-
if (_bytes_sent) {
1110-
snprintf(buf, sizeof(buf), "<bytes_sent>%f</bytes_sent>\n", _bytes_sent);
1111-
safe_strcat(msg_buf, buf);
1112-
}
1113-
if (_bytes_received) {
1114-
snprintf(buf, sizeof(buf), "<bytes_received>%f</bytes_received>\n", _bytes_received);
1115-
safe_strcat(msg_buf, buf);
1116-
}
11171094
if (ac_state) {
11181095
sprintf(buf, "<sporadic_ac>%d</sporadic_ac>\n", ac_state);
11191096
strlcat(msg_buf, buf, sizeof(msg_buf));
@@ -1122,6 +1099,9 @@ int boinc_report_app_status_aux(
11221099
sprintf(buf, "<wss>%f</wss>\n", wss);
11231100
strlcat(msg_buf, buf, sizeof(msg_buf));
11241101
}
1102+
if (want_network) {
1103+
strlcat(msg_buf, "<want_network>1</want_network>\n", sizeof(msg_buf));
1104+
}
11251105
#ifdef MSGS_FROM_FILE
11261106
if (fout) {
11271107
fputs(msg_buf, fout);
@@ -1371,9 +1351,6 @@ static void handle_process_control_msg() {
13711351
if (match_tag(buf, "<reread_app_info/>")) {
13721352
boinc_status.reread_init_data_file = true;
13731353
}
1374-
if (match_tag(buf, "<network_available/>")) {
1375-
have_network = 1;
1376-
}
13771354
#ifdef ANDROID
13781355
// Trigger call to worker_signal_handler() in the worker thread
13791356
//
@@ -1794,17 +1771,8 @@ int boinc_upload_status(std::string& name) {
17941771
return ERR_NOT_FOUND;
17951772
}
17961773

1797-
void boinc_need_network() {
1798-
want_network = 1;
1799-
have_network = 0;
1800-
}
1801-
1802-
int boinc_network_poll() {
1803-
return have_network?0:1;
1804-
}
1805-
1806-
void boinc_network_done() {
1807-
want_network = 0;
1774+
void boinc_waiting_for_network(bool x) {
1775+
want_network = x;
18081776
}
18091777

18101778
#ifndef _WIN32

api/boinc_api.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ typedef struct BOINC_OPTIONS {
6363
// set this if application creates subprocesses.
6464
} BOINC_OPTIONS;
6565

66-
// info passed from client to app in heartbeat message
66+
// info passed from client to app in heartbeat and process control messages
6767
//
6868
typedef struct BOINC_STATUS {
6969
int no_heartbeat;
@@ -100,10 +100,6 @@ extern int boinc_report_app_status(
100100
extern int boinc_time_to_checkpoint(void);
101101
extern void boinc_begin_critical_section(void);
102102
extern void boinc_end_critical_section(void);
103-
extern void boinc_need_network(void);
104-
extern int boinc_network_poll(void);
105-
extern void boinc_network_done(void);
106-
extern void boinc_network_usage(double sent, double received);
107103
extern int boinc_is_standalone(void);
108104
extern void boinc_ops_per_cpu_sec(double fp, double integer);
109105
extern void boinc_ops_cumulative(double fp, double integer);
@@ -132,6 +128,7 @@ extern int setMacIcon(char *filename, char *iconData, long iconSize);
132128
#include <string>
133129
#include "app_ipc.h"
134130

131+
extern void boinc_waiting_for_network(bool);
135132
extern int boinc_resolve_filename_s(const char*, std::string&);
136133
extern int boinc_get_init_data(APP_INIT_DATA&);
137134
extern int boinc_wu_cpu_time(double&);
@@ -166,6 +163,7 @@ extern HANDLE worker_thread_handle;
166163
extern int boinc_init_options_general(BOINC_OPTIONS& opt);
167164
extern int start_timer_thread(void);
168165
extern bool boinc_disable_timer_thread;
166+
extern volatile bool got_heartbeat_message;
169167

170168
inline void boinc_options_defaults(BOINC_OPTIONS& b) {
171169
b.main_program = 1;
@@ -178,7 +176,6 @@ inline void boinc_options_defaults(BOINC_OPTIONS& b) {
178176
b.multi_process = 0;
179177
}
180178

181-
182179
/////////// IMPLEMENTATION STUFF ENDS HERE
183180

184181
#endif // C++ part

client/app.cpp

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,6 @@ ACTIVE_TASK::ACTIVE_TASK() {
121121
run_interval_start_wall_time = gstate.now;
122122
checkpoint_wall_time = 0;
123123
elapsed_time = 0;
124-
bytes_sent_episode = 0;
125-
bytes_received_episode = 0;
126-
bytes_sent = 0;
127-
bytes_received = 0;
128124
safe_strcpy(slot_dir, "");
129125
safe_strcpy(slot_path, "");
130126
max_elapsed_time = 0;
@@ -795,9 +791,7 @@ int ACTIVE_TASK::write(MIOFILE& fout) {
795791
" <swap_size>%f</swap_size>\n"
796792
" <working_set_size>%f</working_set_size>\n"
797793
" <working_set_size_smoothed>%f</working_set_size_smoothed>\n"
798-
" <page_fault_rate>%f</page_fault_rate>\n"
799-
" <bytes_sent>%f</bytes_sent>\n"
800-
" <bytes_received>%f</bytes_received>\n",
794+
" <page_fault_rate>%f</page_fault_rate>\n",
801795
result->project->master_url,
802796
result->name,
803797
task_state(),
@@ -812,9 +806,7 @@ int ACTIVE_TASK::write(MIOFILE& fout) {
812806
procinfo.swap_size,
813807
procinfo.working_set_size,
814808
procinfo.working_set_size_smoothed,
815-
procinfo.page_fault_rate,
816-
bytes_sent,
817-
bytes_received
809+
procinfo.page_fault_rate
818810
);
819811
fout.printf("</active_task>\n");
820812
return 0;
@@ -848,10 +840,7 @@ int ACTIVE_TASK::write_gui(MIOFILE& fout) {
848840
" <working_set_size>%f</working_set_size>\n"
849841
" <working_set_size_smoothed>%f</working_set_size_smoothed>\n"
850842
" <page_fault_rate>%f</page_fault_rate>\n"
851-
" <bytes_sent>%f</bytes_sent>\n"
852-
" <bytes_received>%f</bytes_received>\n"
853-
"%s"
854-
"%s",
843+
"%s%s%s",
855844
task_state(),
856845
app_version->version_num,
857846
slot,
@@ -865,10 +854,9 @@ int ACTIVE_TASK::write_gui(MIOFILE& fout) {
865854
procinfo.working_set_size,
866855
procinfo.working_set_size_smoothed,
867856
procinfo.page_fault_rate,
868-
bytes_sent,
869-
bytes_received,
870857
too_large?" <too_large/>\n":"",
871-
needs_shmem?" <needs_shmem/>\n":""
858+
needs_shmem?" <needs_shmem/>\n":"",
859+
want_network?" <want_network/>\n":""
872860
);
873861
if (elapsed_time > first_fraction_done_elapsed_time) {
874862
fout.printf(
@@ -1008,8 +996,6 @@ int ACTIVE_TASK::parse(XML_PARSER& xp) {
1008996
else if (xp.parse_double("working_set_size_smoothed", procinfo.working_set_size_smoothed)) continue;
1009997
else if (xp.parse_double("page_fault_rate", procinfo.page_fault_rate)) continue;
1010998
else if (xp.parse_double("current_cpu_time", x)) continue;
1011-
else if (xp.parse_double("bytes_sent", bytes_sent)) continue;
1012-
else if (xp.parse_double("bytes_received", bytes_received)) continue;
1013999
else {
10141000
if (log_flags.unparsed_xml) {
10151001
msg_printf(project, MSG_INFO,
@@ -1220,23 +1206,13 @@ void ACTIVE_TASK_SET::handle_upload_files() {
12201206
}
12211207
}
12221208

1223-
bool ACTIVE_TASK_SET::want_network() {
1209+
bool ACTIVE_TASK_SET::some_task_wants_network() {
12241210
for (ACTIVE_TASK* atp: active_tasks) {
12251211
if (atp->want_network) return true;
12261212
}
12271213
return false;
12281214
}
12291215

1230-
void ACTIVE_TASK_SET::network_available() {
1231-
#ifndef SIM
1232-
for (ACTIVE_TASK* atp: active_tasks) {
1233-
if (atp->want_network) {
1234-
atp->send_network_available();
1235-
}
1236-
}
1237-
#endif
1238-
}
1239-
12401216
void ACTIVE_TASK::upload_notify_app(const FILE_INFO* fip, const FILE_REF* frp) {
12411217
char path[MAXPATHLEN];
12421218
snprintf(path, sizeof(path),

client/app.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,6 @@ struct ACTIVE_TASK {
127127
// wall time at the last checkpoint
128128
double elapsed_time;
129129
// current total running time, adjusted for CPU throttling
130-
double bytes_sent_episode;
131-
// bytes sent in current episode of job,
132-
// as (optionally) reported by boinc_network_usage()
133-
double bytes_received_episode;
134-
double bytes_sent;
135-
// bytes in all episodes
136-
double bytes_received;
137130
char slot_dir[256];
138131
// directory where process runs (relative)
139132
char slot_path[MAXPATHLEN];
@@ -159,8 +152,9 @@ struct ACTIVE_TASK {
159152
bool needs_shmem;
160153
// waiting for a free shared memory segment
161154
int want_network;
162-
// This task wants to do network comm (for F@h)
163-
// this is passed via share-memory message (app_status channel)
155+
// This task is waiting for the network
156+
// (physical connection or no suspension)
157+
// This is passed via share-memory message (app_status channel)
164158
double abort_time;
165159
// when we sent an abort message to this app
166160
// kill it 5 seconds later if it doesn't exit
@@ -300,7 +294,6 @@ struct ACTIVE_TASK {
300294
int preempt(PREEMPT_TYPE preempt_type, int reason=0);
301295
// preempt (via suspend or quit) a running task
302296
int resume_or_start(bool);
303-
void send_network_available();
304297
#ifdef _WIN32
305298
void handle_exited_app(unsigned long);
306299
#else
@@ -363,8 +356,7 @@ class ACTIVE_TASK_SET {
363356
void report_overdue();
364357
void handle_upload_files();
365358
void upload_notify_app(FILE_INFO*);
366-
bool want_network(); // does any task want network?
367-
void network_available(); // notify tasks that network is available
359+
bool some_task_wants_network();
368360
void free_mem();
369361
bool slot_taken(int);
370362
void get_memory_usage();

0 commit comments

Comments
 (0)