2011-02-27 00:10:14 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2011 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/>.
|
|
|
|
|
2011-09-13 21:01:42 +00:00
|
|
|
// A trickle handler that grants credit based on run time
|
2011-02-27 00:10:14 +00:00
|
|
|
//
|
|
|
|
// message format:
|
|
|
|
//
|
2011-09-13 21:01:42 +00:00
|
|
|
// <runtime>x</runtime>
|
2011-02-27 00:10:14 +00:00
|
|
|
//
|
2011-09-13 21:01:42 +00:00
|
|
|
// The credit granted is based on the host's CPU benchmarks,
|
|
|
|
// and assumes a single-threaded CPU app.
|
|
|
|
//
|
|
|
|
// Required cmdline arg:
|
|
|
|
//
|
|
|
|
// --max_runtime X Cap runtime at X
|
|
|
|
//
|
|
|
|
// This should match the frequency with which your app
|
|
|
|
// sends trickle-up messages
|
2011-08-21 11:57:00 +00:00
|
|
|
|
2011-02-27 00:10:14 +00:00
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
#include "credit.h"
|
|
|
|
#include "miofile.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "sched_msgs.h"
|
|
|
|
#include "trickle_handler.h"
|
|
|
|
|
2011-09-13 21:01:42 +00:00
|
|
|
double flops_50_percentile;
|
|
|
|
// default if host value is <= 0
|
|
|
|
double flops_95_percentile;
|
|
|
|
// limit for cheat-proofing
|
|
|
|
double max_runtime = 0;
|
|
|
|
|
|
|
|
int handle_trickle_init(int argc, char** argv) {
|
|
|
|
int retval;
|
|
|
|
for (int i=1; i<argc; i++) {
|
|
|
|
if (!strcmp(argv[i], "--max_runtime")) {
|
|
|
|
max_runtime = atof(argv[++i]);
|
|
|
|
} else {
|
|
|
|
log_messages.printf(MSG_CRITICAL, "unknown arg %s\n", argv[i]);
|
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!max_runtime) {
|
|
|
|
log_messages.printf(MSG_CRITICAL, "missing --max_runtime arg\n");
|
|
|
|
return ERR_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
DB_HOST host;
|
|
|
|
retval = host.fpops_percentile(50, flops_50_percentile);
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(MSG_CRITICAL, "fpops_percentile failed: %d\n", retval);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
retval = host.fpops_percentile(95, flops_95_percentile);
|
|
|
|
if (retval) {
|
|
|
|
log_messages.printf(MSG_CRITICAL, "fpops_percentile failed: %d\n", retval);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
log_messages.printf(MSG_NORMAL, "default FLOPS: %f\n", flops_50_percentile);
|
|
|
|
log_messages.printf(MSG_NORMAL, "max FLOPS: %f\n", flops_95_percentile);
|
|
|
|
log_messages.printf(MSG_NORMAL, "max runtime: %f\n", max_runtime);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-27 00:10:14 +00:00
|
|
|
int handle_trickle(MSG_FROM_HOST& msg) {
|
2011-09-13 21:01:42 +00:00
|
|
|
double runtime = 0;
|
2011-02-27 00:10:14 +00:00
|
|
|
MIOFILE mf;
|
|
|
|
|
|
|
|
mf.init_buf_read(msg.xml);
|
|
|
|
XML_PARSER xp(&mf);
|
|
|
|
|
2011-08-10 17:11:08 +00:00
|
|
|
while (!xp.get_tag()) {
|
2011-09-13 21:01:42 +00:00
|
|
|
if (xp.parse_double("runtime", runtime)) break;
|
2011-08-10 17:11:08 +00:00
|
|
|
log_messages.printf(MSG_NORMAL, "unexpected tag: %s\n", xp.parsed_tag);
|
2011-02-27 00:10:14 +00:00
|
|
|
}
|
2011-09-13 21:01:42 +00:00
|
|
|
if (runtime <= 0) {
|
|
|
|
log_messages.printf(MSG_NORMAL,
|
|
|
|
"unexpected nonpositive runtime: %f\n", runtime
|
|
|
|
);
|
2011-02-27 00:10:14 +00:00
|
|
|
return ERR_XML_PARSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
DB_HOST host;
|
|
|
|
int retval = host.lookup_id(msg.hostid);
|
|
|
|
if (retval) return retval;
|
|
|
|
HOST old_host = host;
|
|
|
|
|
2011-09-13 21:01:42 +00:00
|
|
|
double flops_sec = host.p_fpops;
|
2011-08-21 11:18:08 +00:00
|
|
|
|
|
|
|
// sanity checks - customize as needed
|
|
|
|
//
|
2011-09-13 21:01:42 +00:00
|
|
|
if (runtime > max_runtime) {
|
2011-08-21 11:57:00 +00:00
|
|
|
log_messages.printf(MSG_NORMAL,
|
2011-09-13 21:01:42 +00:00
|
|
|
"Reported runtime exceeds bound: %f>%f\n", runtime, max_runtime
|
2011-08-21 11:57:00 +00:00
|
|
|
);
|
2011-09-13 21:01:42 +00:00
|
|
|
runtime = max_runtime;
|
2011-08-21 11:57:00 +00:00
|
|
|
}
|
2011-09-13 21:01:42 +00:00
|
|
|
if (flops_sec < 0) {
|
2011-08-21 11:57:00 +00:00
|
|
|
log_messages.printf(MSG_NORMAL,
|
|
|
|
"host CPU speed %f < 0. Using %f instead\n",
|
2011-09-13 21:01:42 +00:00
|
|
|
flops_sec, flops_50_percentile
|
2011-08-21 11:57:00 +00:00
|
|
|
);
|
2011-09-13 21:01:42 +00:00
|
|
|
flops_sec = flops_50_percentile;
|
2011-08-21 11:57:00 +00:00
|
|
|
}
|
2011-09-13 21:01:42 +00:00
|
|
|
if (flops_sec > flops_95_percentile) {
|
2011-08-21 11:57:00 +00:00
|
|
|
log_messages.printf(MSG_NORMAL,
|
|
|
|
"host CPU speed %f exceeds %f. Using %f instead\n",
|
2011-09-13 21:01:42 +00:00
|
|
|
flops_sec, flops_95_percentile, flops_95_percentile
|
2011-08-21 11:57:00 +00:00
|
|
|
);
|
2011-09-13 21:01:42 +00:00
|
|
|
flops_sec = flops_95_percentile;
|
2011-08-21 11:57:00 +00:00
|
|
|
}
|
2011-09-13 21:01:42 +00:00
|
|
|
double credit = cpu_time_to_credit(runtime, flops_sec);
|
2011-02-27 00:10:14 +00:00
|
|
|
grant_credit(host, dtime()-86400, credit);
|
2011-08-21 11:57:00 +00:00
|
|
|
log_messages.printf(MSG_DEBUG,
|
|
|
|
"granting %f credit to host %d\n", credit, host.id
|
|
|
|
);
|
2011-02-27 00:10:14 +00:00
|
|
|
|
2011-08-21 11:18:08 +00:00
|
|
|
// update the host's credit fields
|
|
|
|
//
|
2011-02-27 00:10:14 +00:00
|
|
|
retval = host.update_diff_validator(old_host);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|