2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2008-05-06 19:53:49 +00:00
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// 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.
|
2008-05-06 19:53:49 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2008-05-06 19:53:49 +00:00
|
|
|
// 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.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2012-08-02 16:17:10 +00:00
|
|
|
|
2016-06-24 22:42:11 +00:00
|
|
|
// logic for handling the HR info file (hr_info.txt)
|
|
|
|
// which is written by census.cpp
|
|
|
|
// and used by the feeder to assign job array slots to HR classes
|
|
|
|
|
2012-08-02 16:17:10 +00:00
|
|
|
#include "hr_info.h"
|
|
|
|
|
2008-09-09 19:10:42 +00:00
|
|
|
#ifndef _USING_FCGI_
|
2009-02-26 00:23:23 +00:00
|
|
|
#include <cstdio>
|
2008-09-09 19:10:42 +00:00
|
|
|
#else
|
|
|
|
#include "boinc_fcgi.h"
|
|
|
|
#endif
|
2009-02-26 00:23:23 +00:00
|
|
|
#include <cmath>
|
2007-06-25 23:56:03 +00:00
|
|
|
|
|
|
|
#include "error_numbers.h"
|
|
|
|
#include "sched_msgs.h"
|
|
|
|
|
|
|
|
int HR_INFO::write_file() {
|
|
|
|
int i, j;
|
|
|
|
|
2008-09-09 19:10:42 +00:00
|
|
|
#ifndef _USING_FCGI_
|
2007-06-25 23:56:03 +00:00
|
|
|
FILE* f = fopen(HR_INFO_FILENAME, "w");
|
2008-09-09 19:10:42 +00:00
|
|
|
#else
|
|
|
|
FCGI_FILE* f = FCGI::fopen(HR_INFO_FILENAME, "w");
|
|
|
|
#endif
|
2007-06-25 23:56:03 +00:00
|
|
|
if (!f) return ERR_FOPEN;
|
|
|
|
for (i=1; i<HR_NTYPES; i++) {
|
|
|
|
fprintf(f, "--------- %s ----------\n", hr_names[i]);
|
|
|
|
for (j=0; j<hr_nclasses[i]; j++) {
|
|
|
|
fprintf(f, "%d %f\n", j, rac_per_class[i][j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int HR_INFO::read_file() {
|
|
|
|
char buf[256];
|
2008-09-09 19:10:42 +00:00
|
|
|
#ifndef _USING_FCGI_
|
2008-09-17 15:59:14 +00:00
|
|
|
FILE* f = fopen(HR_INFO_FILENAME, "r");
|
2008-09-09 19:10:42 +00:00
|
|
|
#else
|
2008-09-17 15:59:14 +00:00
|
|
|
FCGI_FILE* f = FCGI::fopen(HR_INFO_FILENAME, "r");
|
2008-09-09 19:10:42 +00:00
|
|
|
#endif
|
2007-06-25 23:56:03 +00:00
|
|
|
if (!f) return ERR_FOPEN;
|
|
|
|
int i, j, jj;
|
|
|
|
double x;
|
|
|
|
|
|
|
|
for (i=1; i<HR_NTYPES; i++) {
|
2008-09-22 17:52:41 +00:00
|
|
|
if (!fgets(buf, sizeof(buf), f)) {
|
|
|
|
fprintf(stderr, "unexpected EOF in HR info\n");
|
2007-06-25 23:56:03 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
for (j=0; j<hr_nclasses[i]; j++) {
|
2008-09-22 17:52:41 +00:00
|
|
|
if (!fgets(buf, sizeof(buf), f)) {
|
|
|
|
fprintf(stderr, "unexpected EOF in HR info");
|
2007-06-25 23:56:03 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
int n = sscanf(buf, "%d %lf", &jj, &x);
|
|
|
|
if (n!=2 || j!=jj) {
|
|
|
|
fprintf(stderr, "bad line %s in HR info: %d; %d != %d\n", buf, n, j, jj);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
rac_per_class[i][j] = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HR_INFO::init() {
|
|
|
|
int i;
|
|
|
|
for (i=1; i<HR_NTYPES; i++) {
|
|
|
|
rac_per_class[i] = (double*) calloc(hr_nclasses[i], sizeof(double));
|
|
|
|
max_slots[i] = (int*) calloc(hr_nclasses[i], sizeof(int));
|
|
|
|
cur_slots[i] = (int*) calloc(hr_nclasses[i], sizeof(int));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HR_INFO::scan_db() {
|
|
|
|
DB_HOST host;
|
|
|
|
int retval;
|
2008-05-06 19:53:49 +00:00
|
|
|
int i, n=0;
|
|
|
|
double sum=0, sum_sqr=0;
|
2007-06-25 23:56:03 +00:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
retval = host.enumerate("where expavg_credit>1");
|
|
|
|
if (retval) break;
|
2008-05-06 19:53:49 +00:00
|
|
|
if (host.p_fpops > 1e7 && host.p_fpops < 1e13) {
|
|
|
|
n++;
|
|
|
|
sum += host.p_fpops;
|
|
|
|
sum_sqr += host.p_fpops*host.p_fpops;
|
|
|
|
}
|
2007-07-06 21:58:32 +00:00
|
|
|
//printf("host %d: %s | %s | %s\n", host.id, host.os_name, host.p_vendor, host.p_model);
|
2007-06-25 23:56:03 +00:00
|
|
|
for (i=1; i<HR_NTYPES; i++) {
|
2010-04-05 18:59:16 +00:00
|
|
|
if (hr_unknown_class(host, i)) {
|
2007-07-06 21:58:32 +00:00
|
|
|
//printf("type %d: unknown\n", i);
|
2007-06-25 23:56:03 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int hrc = hr_class(host, i);
|
2007-07-06 21:58:32 +00:00
|
|
|
//printf("type %d: class %d\n", i, hrc);
|
2007-06-25 23:56:03 +00:00
|
|
|
if (!hrc) continue;
|
|
|
|
rac_per_class[i][hrc] += host.expavg_credit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (retval != ERR_DB_NOT_FOUND) {
|
|
|
|
fprintf(stderr, "host enum: %d", retval);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HR_INFO::allocate(int total_slots) {
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
double weight_total = 0;
|
|
|
|
for (i=1; i<HR_NTYPES; i++) {
|
|
|
|
weight_total += type_weights[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
// decide how many slots to allocate to each HR type
|
|
|
|
//
|
|
|
|
for (i=1; i<HR_NTYPES; i++) {
|
|
|
|
slots_per_type[i] = (int)(total_slots*type_weights[i]/weight_total);
|
|
|
|
}
|
|
|
|
|
|
|
|
// within each type, decide how many slots to allocate to each class
|
|
|
|
//
|
|
|
|
for (i=1; i<HR_NTYPES; i++) {
|
|
|
|
int nuncom = slots_per_type[i]/2;
|
|
|
|
int ncom = slots_per_type[i] - nuncom;
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_DEBUG,
|
2007-10-05 22:32:47 +00:00
|
|
|
"type %d: %d total slots\n", i, slots_per_type[i]
|
|
|
|
);
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_DEBUG,
|
2007-10-05 22:32:47 +00:00
|
|
|
"type %d uncommitted: allocating %d slots\n", i, nuncom
|
2007-06-25 23:56:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
double total_rac = 0;
|
|
|
|
for (j=1; j<hr_nclasses[i]; j++) {
|
|
|
|
total_rac += rac_per_class[i][j];
|
|
|
|
}
|
|
|
|
max_slots[i][0] = nuncom;
|
|
|
|
for (j=1; j<hr_nclasses[i]; j++) {
|
|
|
|
int n = (int)(ncom*rac_per_class[i][j]/total_rac);
|
|
|
|
|
|
|
|
// every HR class has a max of at least one,
|
|
|
|
// so that new classes can get "on the board".
|
|
|
|
// This means that the sum of the maxes can exceed the # of slots
|
|
|
|
//
|
|
|
|
if (n == 0) n = 1;
|
|
|
|
max_slots[i][j] = n;
|
|
|
|
if (n > 1) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_DEBUG,
|
2007-06-25 23:56:03 +00:00
|
|
|
"type %d class %d: allocating %d slots\n", i, j, n
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (j=0; j<hr_nclasses[i]; j++) {
|
|
|
|
cur_slots[i][j] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decide if job of the given HR type and class should be added to array,
|
2012-03-15 19:50:10 +00:00
|
|
|
// and if so update counts
|
2007-06-25 23:56:03 +00:00
|
|
|
//
|
|
|
|
bool HR_INFO::accept(int hrt, int hrc) {
|
|
|
|
if (cur_slots[hrt][hrc] >= max_slots[hrt][hrc]) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_DEBUG,
|
2007-06-25 23:56:03 +00:00
|
|
|
"skipping job because HR class (%d, %d) full\n", hrt, hrc
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
cur_slots[hrt][hrc]++;
|
2008-09-09 19:10:42 +00:00
|
|
|
return true;
|
2007-06-25 23:56:03 +00:00
|
|
|
}
|
2007-07-05 23:06:18 +00:00
|
|
|
|
|
|
|
void HR_INFO::show(FILE* f) {
|
|
|
|
for (int ht=1; ht<HR_NTYPES; ht++) {
|
|
|
|
fprintf(f, "HR type %s: weight %f nslots %d\n",
|
|
|
|
hr_names[ht], type_weights[ht], slots_per_type[ht]
|
|
|
|
);
|
|
|
|
for (int hc=0; hc<hr_nclasses[ht]; hc++) {
|
|
|
|
if (hc && rac_per_class[ht][hc] == 0) continue;
|
|
|
|
fprintf(f,
|
|
|
|
" class %d: rac %f max_slots %d cur_slots %d\n",
|
|
|
|
hc, rac_per_class[ht][hc], max_slots[ht][hc], cur_slots[ht][hc]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|