- scheduler: code cleanup: use global var for SCHED_SHMEM

instead of passing it around as argument
    (should do same for request and reply at some point)

svn path=/trunk/boinc/; revision=14781
This commit is contained in:
David Anderson 2008-02-22 22:21:00 +00:00
parent cdb7f2375f
commit e5f1f2f9cb
14 changed files with 74 additions and 97 deletions

View File

@ -1575,3 +1575,10 @@ Charlie Feb 22 2008
clientscr/
mac_saver_module.cpp
Mac_Saver_ModuleView.m
David Feb 22 2008
- scheduler: code cleanup: use global var for SCHED_SHMEM
instead of passing it around as argument
(should do same for request and reply at some point)
sched/sched_*

View File

@ -578,9 +578,7 @@ static int update_host_record(HOST& initial_host, HOST& xhost, USER& user) {
// Figure out which of the results the host currently has
// should be aborted outright, or aborted if not started yet
//
int send_result_abort(
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, SCHED_SHMEM&
) {
int send_result_abort( SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply) {
int aborts_sent = 0;
int retval = 0;
DB_IN_PROGRESS_RESULT result;
@ -1000,8 +998,7 @@ void handle_msgs_to_host(SCHEDULER_REPLY& reply) {
}
void process_request(
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, SCHED_SHMEM& ss,
char* code_sign_key
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, char* code_sign_key
) {
PLATFORM* platform;
int retval;
@ -1038,7 +1035,7 @@ void process_request(
have_no_work = false;
} else {
lock_sema();
have_no_work = ss.no_work(g_pid);
have_no_work = ssp->no_work(g_pid);
unlock_sema();
}
@ -1152,10 +1149,10 @@ void process_request(
// look up the client's platform(s) in the DB
//
platform = ss.lookup_platform(sreq.platform.name);
platform = ssp->lookup_platform(sreq.platform.name);
if (platform) sreq.platforms.list.push_back(platform);
for (i=0; i<sreq.alt_platforms.size(); i++) {
platform = ss.lookup_platform(sreq.alt_platforms[i].name);
platform = ssp->lookup_platform(sreq.alt_platforms[i].name);
if (platform) sreq.platforms.list.push_back(platform);
}
if (sreq.platforms.list.size() == 0) {
@ -1177,12 +1174,12 @@ void process_request(
reply.wreq.nresults_on_host = sreq.other_results.size();
if (sreq.have_other_results_list) {
if (config.resend_lost_results) {
if (resend_lost_work(sreq, reply, ss)) {
if (resend_lost_work(sreq, reply)) {
ok_to_send_work = false;
}
}
if (config.send_result_abort) {
send_result_abort(sreq, reply, ss);
send_result_abort(sreq, reply);
}
}
@ -1209,7 +1206,7 @@ void process_request(
}
}
if (ok_to_send_work) {
send_work(sreq, reply, ss);
send_work(sreq, reply);
}
}
@ -1224,13 +1221,11 @@ void process_request(
leave:
if (!have_no_work) {
ss.restore_work(g_pid);
ssp->restore_work(g_pid);
}
}
void handle_request(
FILE* fin, FILE* fout, SCHED_SHMEM& ss, char* code_sign_key
) {
void handle_request(FILE* fin, FILE* fout, char* code_sign_key) {
SCHEDULER_REQUEST sreq;
SCHEDULER_REPLY sreply;
@ -1248,7 +1243,7 @@ void handle_request(
sreq.core_client_release,
(int)sreq.work_req_seconds
);
process_request(sreq, sreply, ss, code_sign_key);
process_request(sreq, sreply, code_sign_key);
#ifdef _USING_FCGI_
log_messages.set_indent_level(2);

View File

@ -23,5 +23,5 @@
#include "server_types.h"
extern void handle_request(
FILE* fin, FILE* fout, SCHED_SHMEM&, char* code_sign_key
FILE* fin, FILE* fout, char* code_sign_key
);

View File

@ -458,7 +458,7 @@ int main(int argc, char** argv) {
exit(1);
}
handle_request(fin, fout, *ssp, code_sign_key);
handle_request(fin, fout, code_sign_key);
fclose(fin);
fclose(fout);
fin = fopen(reply_path, "r");
@ -480,12 +480,12 @@ int main(int argc, char** argv) {
#ifndef _USING_FCGI_
} else if (batch) {
while (!feof(stdin)) {
handle_request(stdin, stdout, *ssp, code_sign_key);
handle_request(stdin, stdout, code_sign_key);
fflush(stdout);
}
#endif
} else {
handle_request(stdin, stdout, *ssp, code_sign_key);
handle_request(stdin, stdout, code_sign_key);
}
done:
#ifdef _USING_FCGI_

View File

@ -43,9 +43,7 @@
// If reply.wreq.infeasible_only is true,
// send only results that were previously infeasible for some host
//
void scan_work_array(
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, SCHED_SHMEM& ss
) {
void scan_work_array(SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply) {
int i, j, retval, n, rnd_off;
WORKUNIT wu;
DB_RESULT result;
@ -56,12 +54,12 @@ void scan_work_array(
lock_sema();
rnd_off = rand() % ss.max_wu_results;
for (j=0; j<ss.max_wu_results; j++) {
i = (j+rnd_off) % ss.max_wu_results;
rnd_off = rand() % ssp->max_wu_results;
for (j=0; j<ssp->max_wu_results; j++) {
i = (j+rnd_off) % ssp->max_wu_results;
if (!reply.work_needed()) break;
WU_RESULT& wu_result = ss.wu_results[i];
WU_RESULT& wu_result = ssp->wu_results[i];
// do fast checks on this wu_result;
// i.e. ones that don't require DB access
@ -74,7 +72,7 @@ void scan_work_array(
// If we are looking for beta results and result is not a beta result
// then move on
//
app = ss.lookup_app(wu_result.workunit.appid);
app = ssp->lookup_app(wu_result.workunit.appid);
if (app == NULL) continue; // this should never happen
if (reply.wreq.beta_only) {
if (!app->beta) {
@ -125,14 +123,14 @@ void scan_work_array(
// If none, treat the WU as infeasible
//
if (anonymous(sreq.platforms.list[0])) {
app = ss.lookup_app(wu.appid);
app = ssp->lookup_app(wu.appid);
found = sreq.has_version(*app);
if (!found) {
continue;
}
avp = NULL;
} else {
found = find_app_version(sreq, reply.wreq, wu, ss, app, avp);
found = find_app_version(sreq, reply.wreq, wu, app, avp);
if (!found) {
continue;
}

View File

@ -1,3 +1 @@
extern void scan_work_array(
SCHEDULER_REQUEST&, SCHEDULER_REPLY&, SCHED_SHMEM&
);
extern void scan_work_array(SCHEDULER_REQUEST&, SCHEDULER_REPLY&);

View File

@ -61,7 +61,7 @@ static int send_assigned_job(
log_messages.printf(MSG_CRITICAL, "ERROR: APP NOT FOUND\n");
return ERR_NOT_FOUND;
}
bool found = find_app_version(request, reply.wreq, wu, *ssp, app, avp);
bool found = find_app_version(request, reply.wreq, wu, app, avp);
if (!found) {
log_messages.printf(MSG_CRITICAL, "ERROR: APP VERSION NOT FOUND\n");
return ERR_NOT_FOUND;

View File

@ -269,7 +269,7 @@ int decrement_disk_space_locality(
//
static int possibly_send_result(
DB_RESULT& result,
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, SCHED_SHMEM& ss
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply
) {
DB_WORKUNIT wu;
DB_RESULT result2;
@ -281,7 +281,7 @@ static int possibly_send_result(
retval = wu.lookup_id(result.workunitid);
if (retval) return ERR_DB_NOT_FOUND;
retval = get_app_version(wu, app, avp, sreq, reply, ss);
retval = get_app_version(wu, app, avp, sreq, reply);
if (retval==ERR_NO_APP_VERSION && anonymous(sreq.platforms.list[0])) {
char help_msg_buf[512];
@ -482,7 +482,6 @@ static int send_results_for_file(
char* filename,
int& nsent,
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply,
SCHED_SHMEM& ss,
bool /*in_working_set*/
) {
DB_RESULT result, prev_result;
@ -636,7 +635,7 @@ static int send_results_for_file(
// we found an unsent result, so try sending it.
// This *should* always work.
//
retval_send = possibly_send_result(result, sreq, reply, ss);
retval_send = possibly_send_result(result, sreq, reply);
boinc_db.commit_transaction();
// if no app version or not enough resources, give up completely
@ -700,7 +699,7 @@ static int send_results_for_file(
//
static int send_new_file_work_deterministic_seeded(
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply,
SCHED_SHMEM& ss, int& nsent, const char *start_f, const char *end_f
int& nsent, const char *start_f, const char *end_f
) {
DB_RESULT result;
char filename[256], min_resultname[256], query[1024];
@ -739,9 +738,7 @@ static int send_new_file_work_deterministic_seeded(
"send_new_file_work_deterministic will try filename %s\n", filename
);
retval = send_results_for_file(
filename, nsent, sreq, reply, ss, false
);
retval = send_results_for_file(filename, nsent, sreq, reply, false);
if (retval==ERR_NO_APP_VERSION || retval==ERR_INSUFFICIENT_RESOURCE) return retval;
@ -777,7 +774,7 @@ static bool is_host_slow(SCHEDULER_REQUEST& sreq) {
// if it has not sent any new work.
//
static int send_new_file_work_deterministic(
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, SCHED_SHMEM& ss
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply
) {
char start_filename[256];
int getfile_retval, nsent=0;
@ -791,7 +788,7 @@ static int send_new_file_work_deterministic(
// start deterministic search with randomly chosen filename, go to
// lexical maximum
send_new_file_work_deterministic_seeded(sreq, reply, ss, nsent, start_filename, NULL);
send_new_file_work_deterministic_seeded(sreq, reply, nsent, start_filename, NULL);
if (nsent) {
return 0;
}
@ -800,7 +797,7 @@ static int send_new_file_work_deterministic(
// filename, continue to randomly choosen one
if (!getfile_retval && reply.work_needed(true)) {
send_new_file_work_deterministic_seeded(
sreq, reply, ss, nsent, "", start_filename
sreq, reply, nsent, "", start_filename
);
if (nsent) {
return 0;
@ -812,7 +809,7 @@ static int send_new_file_work_deterministic(
static int send_new_file_work_working_set(
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, SCHED_SHMEM& ss
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply
) {
char filename[256];
int retval, nsent;
@ -824,22 +821,19 @@ static int send_new_file_work_working_set(
"send_new_file_working_set will try filename %s\n", filename
);
return send_results_for_file(
filename, nsent, sreq, reply, ss, true
);
return send_results_for_file(filename, nsent, sreq, reply, true);
}
// prototype
static int send_old_work(
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply,
SCHED_SHMEM& ss, int t_min, int t_max
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, int t_min, int t_max
);
// The host doesn't have any files for which work is available.
// Pick new file to send. Returns nonzero if no work is available.
//
static int send_new_file_work(
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, SCHED_SHMEM& ss
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply
) {
while (reply.work_needed(true)) {
@ -860,7 +854,7 @@ static int send_new_file_work(
"send_new_file_work(): try to send old work\n"
);
retval_sow=send_old_work(sreq, reply, ss, start, end);
retval_sow=send_old_work(sreq, reply, start, end);
if (retval_sow==ERR_NO_APP_VERSION || retval_sow==ERR_INSUFFICIENT_RESOURCE) return retval_sow;
@ -870,7 +864,7 @@ static int send_new_file_work(
"send_new_file_work(%d): try to send from working set\n", retry
);
retry++;
retval_snfwws=send_new_file_work_working_set(sreq, reply, ss);
retval_snfwws=send_new_file_work_working_set(sreq, reply);
if (retval_snfwws==ERR_NO_APP_VERSION || retval_snfwws==ERR_INSUFFICIENT_RESOURCE) return retval_snfwws;
}
@ -879,7 +873,7 @@ static int send_new_file_work(
log_messages.printf(MSG_DEBUG,
"send_new_file_work(): try deterministic method\n"
);
if (send_new_file_work_deterministic(sreq, reply, ss)) {
if (send_new_file_work_deterministic(sreq, reply)) {
// if no work remains at all,
// we learn it here and return nonzero.
//
@ -899,8 +893,7 @@ static int send_new_file_work(
// t_min=INT_MIN if you wish to leave off the left constraint.
//
static int send_old_work(
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply,
SCHED_SHMEM& ss, int t_min, int t_max
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, int t_min, int t_max
) {
char buf[1024], filename[256];
int retval, extract_retval, nsent;
@ -927,7 +920,7 @@ static int send_old_work(
retval = result.lookup(buf);
if (!retval) {
retval = possibly_send_result(result, sreq, reply, ss);
retval = possibly_send_result(result, sreq, reply);
boinc_db.commit_transaction();
if (!retval) {
double age=(now-result.create_time)/3600.0;
@ -936,9 +929,7 @@ static int send_old_work(
);
extract_retval=extract_filename(result.name, filename);
if (!extract_retval) {
send_results_for_file(
filename, nsent, sreq, reply, ss, false
);
send_results_for_file(filename, nsent, sreq, reply, false);
} else {
// David, is this right? Is this the only place in
// the locality scheduler that non-locality work //
@ -985,7 +976,7 @@ bool file_info_order(const FILE_INFO& fi1, const FILE_INFO& fi2) {
}
void send_work_locality(
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, SCHED_SHMEM& ss
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply
) {
int i, nsent, nfiles, j;
@ -1068,7 +1059,7 @@ void send_work_locality(
//
if (config.locality_scheduling_send_timeout && sreq.host.n_bwdown>100000) {
int until=time(0)-config.locality_scheduling_send_timeout;
int retval_sow=send_old_work(sreq, reply, ss, INT_MIN, until);
int retval_sow=send_old_work(sreq, reply, INT_MIN, until);
if (retval_sow==ERR_NO_APP_VERSION || retval_sow==ERR_INSUFFICIENT_RESOURCE) return;
}
@ -1081,7 +1072,7 @@ void send_work_locality(
if (!reply.work_needed(true)) break;
FILE_INFO& fi = sreq.file_infos[k];
retval_srff=send_results_for_file(
fi.name, nsent, sreq, reply, ss, false
fi.name, nsent, sreq, reply, false
);
if (retval_srff==ERR_NO_APP_VERSION || retval_srff==ERR_INSUFFICIENT_RESOURCE) return;
@ -1116,7 +1107,7 @@ void send_work_locality(
// send new files if needed
//
if (reply.work_needed(true)) {
send_new_file_work(sreq, reply, ss);
send_new_file_work(sreq, reply);
}
}

View File

@ -17,9 +17,7 @@
// or write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
extern void send_work_locality(
SCHEDULER_REQUEST&, SCHEDULER_REPLY&, SCHED_SHMEM&
);
extern void send_work_locality(SCHEDULER_REQUEST&, SCHEDULER_REPLY&);
extern int decrement_disk_space_locality(
WORKUNIT& wu, SCHEDULER_REQUEST& request, SCHEDULER_REPLY& reply

View File

@ -92,9 +92,7 @@ static int possibly_give_result_new_deadline(
// 3) aren't present on the host
// Return true if there were any such jobs
//
bool resend_lost_work(
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, SCHED_SHMEM& ss
) {
bool resend_lost_work(SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply) {
DB_RESULT result;
std::vector<DB_RESULT>results;
unsigned int i;
@ -140,7 +138,7 @@ bool resend_lost_work(
reply.wreq.core_client_version =
sreq.core_client_major_version*100 + sreq.core_client_minor_version;
retval = get_app_version(wu, app, avp, sreq, reply, ss);
retval = get_app_version(wu, app, avp, sreq, reply);
if (retval) {
log_messages.printf(MSG_CRITICAL,
"[HOST#%d] no app version [RESULT#%d]\n",

View File

@ -1,4 +1,2 @@
extern bool resend_lost_work(
SCHEDULER_REQUEST&, SCHEDULER_REPLY&, SCHED_SHMEM&
);
extern bool resend_lost_work(SCHEDULER_REQUEST&, SCHEDULER_REPLY&);

View File

@ -103,12 +103,11 @@ bool SCHEDULER_REQUEST::has_version(APP& app) {
//
int get_app_version(
WORKUNIT& wu, APP* &app, APP_VERSION* &avp,
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply,
SCHED_SHMEM& ss
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply
) {
bool found;
if (anonymous(sreq.platforms.list[0])) {
app = ss.lookup_app(wu.appid);
app = ssp->lookup_app(wu.appid);
found = sreq.has_version(*app);
if (!found) {
log_messages.printf(MSG_DEBUG,
@ -118,7 +117,7 @@ int get_app_version(
}
avp = NULL;
} else {
found = find_app_version(sreq, reply.wreq, wu, ss, app, avp);
found = find_app_version(sreq, reply.wreq, wu, app, avp);
if (!found) {
log_messages.printf(MSG_DEBUG, "Didn't find app version\n");
return ERR_NO_APP_VERSION;
@ -551,10 +550,10 @@ int insert_wu_tags(WORKUNIT& wu, APP& app) {
// return false if none
//
bool find_app_version(
SCHEDULER_REQUEST& sreq, WORK_REQ& wreq, WORKUNIT& wu, SCHED_SHMEM& ss,
SCHEDULER_REQUEST& sreq, WORK_REQ& wreq, WORKUNIT& wu,
APP*& app, APP_VERSION*& avp
) {
app = ss.lookup_app(wu.appid);
app = ssp->lookup_app(wu.appid);
if (!app) {
log_messages.printf(MSG_CRITICAL,
"Can't find APP#%d\n", wu.appid
@ -564,7 +563,7 @@ bool find_app_version(
unsigned int i;
for (i=0; i<sreq.platforms.list.size(); i++) {
PLATFORM* p = sreq.platforms.list[i];
avp = ss.lookup_app_version(app->id, p->id, app->min_version);
avp = ssp->lookup_app_version(app->id, p->id, app->min_version);
if (avp) return true;
}
log_messages.printf(MSG_DEBUG,
@ -908,9 +907,7 @@ int add_result_to_reply(
return 0;
}
void send_work(
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply, SCHED_SHMEM& ss
) {
void send_work(SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply) {
char helpful[512];
reply.wreq.disk_available = max_allowable_disk(sreq, reply);
@ -954,14 +951,14 @@ void send_work(
if (config.locality_scheduling) {
reply.wreq.infeasible_only = false;
send_work_locality(sreq, reply, ss);
send_work_locality(sreq, reply);
} else {
// give top priority to results that require a 'reliable host'
//
if (reply.wreq.host_info.reliable) {
reply.wreq.reliable_only = true;
reply.wreq.infeasible_only = false;
scan_work_array(sreq, reply, ss);
scan_work_array(sreq, reply);
}
reply.wreq.reliable_only = false;
@ -975,17 +972,17 @@ void send_work(
"[HOST#%d] will accept beta work. Scanning for beta work.\n",
reply.host.id
);
scan_work_array(sreq, reply, ss);
scan_work_array(sreq, reply);
}
reply.wreq.beta_only = false;
// give next priority to results that were infeasible for some other host
//
reply.wreq.infeasible_only = true;
scan_work_array(sreq, reply, ss);
scan_work_array(sreq, reply);
reply.wreq.infeasible_only = false;
scan_work_array(sreq, reply, ss);
scan_work_array(sreq, reply);
}
log_messages.printf(MSG_NORMAL,

View File

@ -19,13 +19,10 @@
extern int get_app_version(
WORKUNIT& wu, APP* &app, APP_VERSION* &avp,
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply,
SCHED_SHMEM& ss
SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply
);
extern void send_work(
SCHEDULER_REQUEST&, SCHEDULER_REPLY&, SCHED_SHMEM&
);
extern void send_work(SCHEDULER_REQUEST&, SCHEDULER_REPLY&);
extern int add_result_to_reply(
DB_RESULT& result, WORKUNIT& wu, SCHEDULER_REQUEST&, SCHEDULER_REPLY&,
@ -35,7 +32,7 @@ extern int add_result_to_reply(
extern bool anonymous(PLATFORM*);
extern bool find_app_version(
SCHEDULER_REQUEST&, WORK_REQ& wreq, WORKUNIT& wu, SCHED_SHMEM& ss,
SCHEDULER_REQUEST&, WORK_REQ& wreq, WORKUNIT& wu,
APP*& app, APP_VERSION*& avp
);

View File

@ -262,7 +262,7 @@ int handle_wu(
// if WU has results with errors and no success yet,
// reset homogeneous redundancy class to give other platforms a try
//
if (nerrors & !(nsuccess | ninprogress)) {
if (nerrors & !(nsuccess || ninprogress)) {
wu_item.hr_class = 0;
}