2009-01-26 05:00:49 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 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/>.
|
|
|
|
|
|
|
|
// Work fetch logic for CPU, GPU, and other processing resources.
|
|
|
|
// See http://boinc.berkeley.edu/trac/wiki/GpuWorkFetch
|
|
|
|
|
2008-12-31 23:14:57 +00:00
|
|
|
#ifndef _WORK_FETCH_
|
|
|
|
#define _WORK_FETCH_
|
|
|
|
|
|
|
|
#include <vector>
|
2011-10-24 17:53:09 +00:00
|
|
|
#include <deque>
|
2008-12-31 23:14:57 +00:00
|
|
|
|
2011-07-11 05:34:09 +00:00
|
|
|
#define RSC_TYPE_ANY -1
|
|
|
|
#define RSC_TYPE_CPU 0
|
2008-12-31 23:14:57 +00:00
|
|
|
|
2014-10-10 14:15:10 +00:00
|
|
|
// reasons for not fetching work from a project
|
2012-07-02 03:43:05 +00:00
|
|
|
//
|
2013-05-16 19:38:55 +00:00
|
|
|
#define CANT_FETCH_WORK_NON_CPU_INTENSIVE 1
|
|
|
|
#define CANT_FETCH_WORK_SUSPENDED_VIA_GUI 2
|
|
|
|
#define CANT_FETCH_WORK_MASTER_URL_FETCH_PENDING 3
|
|
|
|
#define CANT_FETCH_WORK_MIN_RPC_TIME 4
|
|
|
|
#define CANT_FETCH_WORK_DONT_REQUEST_MORE_WORK 5
|
|
|
|
#define CANT_FETCH_WORK_DOWNLOAD_STALLED 6
|
|
|
|
#define CANT_FETCH_WORK_RESULT_SUSPENDED 7
|
|
|
|
#define CANT_FETCH_WORK_TOO_MANY_UPLOADS 8
|
|
|
|
#define CANT_FETCH_WORK_NOT_HIGHEST_PRIORITY 9
|
|
|
|
#define CANT_FETCH_WORK_DONT_NEED 10
|
2013-07-07 20:13:57 +00:00
|
|
|
#define CANT_FETCH_WORK_TOO_MANY_RUNNABLE 11
|
2012-07-02 03:43:05 +00:00
|
|
|
|
2014-02-25 02:45:25 +00:00
|
|
|
// in case of DONT_NEED, per-resource reason
|
|
|
|
//
|
|
|
|
#define DONT_FETCH_GPUS_NOT_USABLE 1
|
|
|
|
#define DONT_FETCH_PREFS 2
|
|
|
|
#define DONT_FETCH_CONFIG 3
|
|
|
|
#define DONT_FETCH_NO_APPS 4
|
|
|
|
#define DONT_FETCH_AMS 5
|
|
|
|
#define DONT_FETCH_ZERO_SHARE 7
|
|
|
|
#define DONT_FETCH_BUFFER_FULL 8
|
|
|
|
#define DONT_FETCH_NOT_HIGHEST_PRIO 9
|
2014-10-10 17:37:07 +00:00
|
|
|
#define DONT_FETCH_BACKED_OFF 10
|
|
|
|
#define DONT_FETCH_DEFER_SCHED 11
|
2012-07-02 03:43:05 +00:00
|
|
|
|
2009-12-21 19:20:28 +00:00
|
|
|
struct PROJECT;
|
2008-12-31 23:14:57 +00:00
|
|
|
struct RESULT;
|
2009-12-21 19:20:28 +00:00
|
|
|
struct ACTIVE_TASK;
|
2008-12-31 23:14:57 +00:00
|
|
|
struct RSC_WORK_FETCH;
|
2009-09-16 17:34:19 +00:00
|
|
|
struct SCHEDULER_REPLY;
|
2010-09-24 21:24:02 +00:00
|
|
|
struct APP_VERSION;
|
2008-12-31 23:14:57 +00:00
|
|
|
|
2014-11-24 08:14:23 +00:00
|
|
|
typedef long long COPROC_INSTANCE_BITMAP;
|
|
|
|
// should be at least MAX_COPROC_INSTANCES (64) bits
|
|
|
|
|
2009-01-03 06:01:17 +00:00
|
|
|
// state per (resource, project) pair
|
2008-12-31 23:14:57 +00:00
|
|
|
//
|
|
|
|
struct RSC_PROJECT_WORK_FETCH {
|
2009-01-03 06:01:17 +00:00
|
|
|
// the following are persistent (saved in state file)
|
2008-12-31 23:14:57 +00:00
|
|
|
double backoff_time;
|
|
|
|
double backoff_interval;
|
2010-11-23 19:39:47 +00:00
|
|
|
|
2013-03-24 18:22:01 +00:00
|
|
|
// the following used by REC accounting
|
|
|
|
double secs_this_rec_interval;
|
|
|
|
inline void reset_rec_accounting() {
|
|
|
|
secs_this_rec_interval = 0;
|
2008-12-31 23:14:57 +00:00
|
|
|
}
|
2010-01-21 00:14:56 +00:00
|
|
|
double queue_est;
|
|
|
|
// an estimate of instance-secs of queued work;
|
2014-10-10 14:15:10 +00:00
|
|
|
bool anonymous_platform_no_apps;
|
2010-02-11 22:19:22 +00:00
|
|
|
// set if this project is anonymous platform
|
|
|
|
// and it has no app version that uses this resource
|
2009-01-03 06:01:17 +00:00
|
|
|
double fetchable_share;
|
|
|
|
// this project's share relative to projects from which
|
|
|
|
// we could probably get work for this resource;
|
|
|
|
// determines how many instances this project deserves
|
2012-08-18 23:26:10 +00:00
|
|
|
int n_runnable_jobs;
|
2009-02-02 18:47:34 +00:00
|
|
|
double sim_nused;
|
2013-06-21 04:47:34 +00:00
|
|
|
// # of instances used at this point in the simulation
|
2009-12-24 20:40:27 +00:00
|
|
|
double nused_total; // sum of instances over all runnable jobs
|
2012-10-20 07:43:44 +00:00
|
|
|
int ncoprocs_excluded;
|
|
|
|
// number of excluded instances
|
2014-11-24 08:14:23 +00:00
|
|
|
COPROC_INSTANCE_BITMAP non_excluded_instances;
|
2012-10-20 07:43:44 +00:00
|
|
|
// bitmap of non-excluded instances
|
|
|
|
// (i.e. instances this project's jobs can run on)
|
2009-04-10 19:01:38 +00:00
|
|
|
int deadlines_missed;
|
|
|
|
int deadlines_missed_copy;
|
2009-08-14 16:54:45 +00:00
|
|
|
// copy of the above used during schedule_cpus()
|
2011-10-24 17:53:09 +00:00
|
|
|
std::deque<RESULT*> pending;
|
|
|
|
std::deque<RESULT*>::iterator pending_iter;
|
2014-10-10 21:35:00 +00:00
|
|
|
bool has_deferred_job;
|
|
|
|
// This project has a coproc job of the given type for which
|
|
|
|
// the job is deferred because of a temporary_exit() call.
|
|
|
|
// Don't fetch more jobs of this type; they might have same problem
|
2008-12-31 23:14:57 +00:00
|
|
|
|
|
|
|
RSC_PROJECT_WORK_FETCH() {
|
2011-10-24 17:53:09 +00:00
|
|
|
backoff_time = 0;
|
|
|
|
backoff_interval = 0;
|
2013-03-24 18:22:01 +00:00
|
|
|
secs_this_rec_interval = 0;
|
2011-10-24 17:53:09 +00:00
|
|
|
queue_est = 0;
|
2014-10-10 14:15:10 +00:00
|
|
|
anonymous_platform_no_apps = false;
|
2011-10-24 17:53:09 +00:00
|
|
|
fetchable_share = 0;
|
2012-08-18 23:26:10 +00:00
|
|
|
n_runnable_jobs = 0;
|
2011-10-24 17:53:09 +00:00
|
|
|
sim_nused = 0;
|
|
|
|
nused_total = 0;
|
2012-10-20 07:43:44 +00:00
|
|
|
ncoprocs_excluded = 0;
|
|
|
|
non_excluded_instances = 0;
|
2011-10-24 17:53:09 +00:00
|
|
|
deadlines_missed = 0;
|
|
|
|
deadlines_missed_copy = 0;
|
2014-10-10 21:35:00 +00:00
|
|
|
has_deferred_job = false;
|
2008-12-31 23:14:57 +00:00
|
|
|
}
|
|
|
|
|
2009-01-23 18:29:28 +00:00
|
|
|
inline void reset() {
|
2008-12-31 23:14:57 +00:00
|
|
|
backoff_time = 0;
|
|
|
|
backoff_interval = 0;
|
|
|
|
}
|
2009-01-08 00:41:15 +00:00
|
|
|
|
2014-10-10 17:37:07 +00:00
|
|
|
int rsc_project_reason;
|
|
|
|
int compute_rsc_project_reason(PROJECT*, int rsc_type);
|
2013-03-22 03:44:53 +00:00
|
|
|
void resource_backoff(PROJECT*, const char*);
|
2014-11-17 21:56:06 +00:00
|
|
|
void rr_init();
|
2009-01-10 00:48:22 +00:00
|
|
|
void clear_backoff() {
|
|
|
|
backoff_time = 0;
|
|
|
|
backoff_interval = 0;
|
|
|
|
}
|
2008-12-31 23:14:57 +00:00
|
|
|
};
|
|
|
|
|
2011-11-22 07:47:45 +00:00
|
|
|
// estimate the time a resource will be saturated
|
2009-09-03 20:31:04 +00:00
|
|
|
// with high-priority jobs.
|
|
|
|
//
|
|
|
|
struct BUSY_TIME_ESTIMATOR {
|
|
|
|
std::vector<double> busy_time;
|
|
|
|
int ninstances;
|
|
|
|
inline void reset() {
|
|
|
|
for (int i=0; i<ninstances; i++) {
|
|
|
|
busy_time[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inline void init(int n) {
|
|
|
|
ninstances = n;
|
|
|
|
busy_time.resize(n);
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
// called for each high-priority job.
|
|
|
|
// Find the least-busy instance, and put this job
|
|
|
|
// on that and following instances
|
|
|
|
//
|
|
|
|
inline void update(double dur, double nused) {
|
2012-03-02 03:56:26 +00:00
|
|
|
if (ninstances==0) return;
|
2009-09-03 20:31:04 +00:00
|
|
|
int i, j;
|
|
|
|
if (nused < 1) return;
|
2012-03-12 23:34:41 +00:00
|
|
|
double best = 0;
|
2009-09-03 20:31:04 +00:00
|
|
|
int ibest = 0;
|
2012-03-02 03:56:26 +00:00
|
|
|
for (i=0; i<ninstances; i++) {
|
|
|
|
if (!i || busy_time[i] < best) {
|
2009-09-03 20:31:04 +00:00
|
|
|
best = busy_time[i];
|
|
|
|
ibest = i;
|
|
|
|
}
|
|
|
|
}
|
2009-09-16 16:54:42 +00:00
|
|
|
int inused = (int) nused; // ignore fractional usage
|
|
|
|
for (i=0; i<inused; i++) {
|
2009-09-03 20:31:04 +00:00
|
|
|
j = (ibest + i) % ninstances;
|
|
|
|
busy_time[j] += dur;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// the overall busy time is the busy time of
|
|
|
|
// the least busy instance
|
|
|
|
//
|
|
|
|
inline double get_busy_time() {
|
2012-03-02 03:56:26 +00:00
|
|
|
double best = 0;
|
|
|
|
for (int i=0; i<ninstances; i++) {
|
|
|
|
if (!i || busy_time[i] < best) {
|
2009-09-03 20:31:04 +00:00
|
|
|
best = busy_time[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-12-31 23:14:57 +00:00
|
|
|
// per-resource state
|
|
|
|
//
|
|
|
|
struct RSC_WORK_FETCH {
|
|
|
|
int rsc_type;
|
|
|
|
int ninstances;
|
2010-01-21 00:14:56 +00:00
|
|
|
double relative_speed; // total FLOPS relative to CPU total FLOPS
|
2013-04-07 20:00:15 +00:00
|
|
|
bool has_exclusions;
|
2008-12-31 23:14:57 +00:00
|
|
|
|
|
|
|
// the following used/set by rr_simulation():
|
|
|
|
//
|
|
|
|
double shortfall;
|
2009-03-18 15:53:02 +00:00
|
|
|
// seconds of idle instances between now and now+work_buf_total()
|
2008-12-31 23:14:57 +00:00
|
|
|
double nidle_now;
|
2009-02-02 18:47:34 +00:00
|
|
|
double sim_nused;
|
2014-11-24 08:14:23 +00:00
|
|
|
COPROC_INSTANCE_BITMAP sim_used_instances;
|
2012-10-20 07:43:44 +00:00
|
|
|
// bitmap of instances used in simulation,
|
|
|
|
// taking into account GPU exclusions
|
2014-11-24 08:14:23 +00:00
|
|
|
COPROC_INSTANCE_BITMAP sim_excluded_instances;
|
2012-10-20 07:43:44 +00:00
|
|
|
// bitmap of instances not used (i.e. starved because of exclusion)
|
2009-01-03 06:01:17 +00:00
|
|
|
double total_fetchable_share;
|
|
|
|
// total RS of projects from which we could fetch jobs for this device
|
2009-07-17 18:29:10 +00:00
|
|
|
double saturated_time;
|
|
|
|
// estimated time until resource is not saturated
|
|
|
|
// used to calculate work request
|
2009-03-19 16:55:04 +00:00
|
|
|
double deadline_missed_instances;
|
|
|
|
// instance count for jobs that miss deadline
|
2009-09-03 20:31:04 +00:00
|
|
|
BUSY_TIME_ESTIMATOR busy_time_estimator;
|
2014-02-25 02:45:25 +00:00
|
|
|
int dont_fetch_reason;
|
2010-11-01 16:53:41 +00:00
|
|
|
#ifdef SIM
|
|
|
|
double estimated_delay;
|
|
|
|
#endif
|
2009-01-03 06:01:17 +00:00
|
|
|
|
2009-09-03 20:31:04 +00:00
|
|
|
void init(int t, int n, double sp) {
|
|
|
|
rsc_type = t;
|
|
|
|
ninstances = n;
|
2010-01-21 00:14:56 +00:00
|
|
|
relative_speed = sp;
|
2009-09-03 20:31:04 +00:00
|
|
|
busy_time_estimator.init(n);
|
|
|
|
}
|
2009-01-03 06:01:17 +00:00
|
|
|
// the following specify the work request for this resource
|
|
|
|
//
|
|
|
|
double req_secs;
|
2009-12-24 20:40:27 +00:00
|
|
|
double req_instances;
|
2008-12-31 23:14:57 +00:00
|
|
|
|
2013-03-24 18:22:01 +00:00
|
|
|
// REC accounting
|
|
|
|
double secs_this_rec_interval;
|
|
|
|
inline void reset_rec_accounting() {
|
|
|
|
this->secs_this_rec_interval = 0;
|
2008-12-31 23:14:57 +00:00
|
|
|
}
|
|
|
|
|
2013-04-02 19:32:28 +00:00
|
|
|
// temp in choose_project()
|
|
|
|
PROJECT* found_project; // a project able to ask for this work
|
|
|
|
|
2008-12-31 23:14:57 +00:00
|
|
|
void rr_init();
|
2013-02-27 22:52:37 +00:00
|
|
|
void update_stats(double sim_now, double dt, double buf_end);
|
2009-07-17 18:29:10 +00:00
|
|
|
void update_busy_time(double dur, double nused);
|
2010-12-30 22:41:50 +00:00
|
|
|
void supplement(PROJECT*);
|
2008-12-31 23:14:57 +00:00
|
|
|
RSC_PROJECT_WORK_FETCH& project_state(PROJECT*);
|
2009-04-03 21:55:26 +00:00
|
|
|
void print_state(const char*);
|
2009-01-03 06:01:17 +00:00
|
|
|
void clear_request();
|
2011-09-13 22:58:39 +00:00
|
|
|
void set_request(PROJECT*);
|
2014-08-10 04:44:39 +00:00
|
|
|
void copy_request(COPROC&);
|
2012-10-20 07:43:44 +00:00
|
|
|
void set_request_excluded(PROJECT*);
|
2009-01-08 00:41:15 +00:00
|
|
|
bool may_have_work(PROJECT*);
|
2014-02-25 02:45:25 +00:00
|
|
|
int cant_fetch(PROJECT*);
|
2013-04-04 17:25:56 +00:00
|
|
|
bool backed_off(PROJECT*);
|
2013-04-02 19:32:28 +00:00
|
|
|
bool uses_starved_excluded_instances(PROJECT*);
|
2008-12-31 23:14:57 +00:00
|
|
|
RSC_WORK_FETCH() {
|
2010-07-15 21:43:51 +00:00
|
|
|
rsc_type = 0;
|
|
|
|
ninstances = 0;
|
|
|
|
relative_speed = 0;
|
|
|
|
shortfall = 0;
|
|
|
|
nidle_now = 0;
|
|
|
|
sim_nused = 0;
|
|
|
|
total_fetchable_share = 0;
|
|
|
|
saturated_time = 0;
|
|
|
|
deadline_missed_instances = 0;
|
2013-04-07 20:00:15 +00:00
|
|
|
has_exclusions = false;
|
2008-12-31 23:14:57 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// per project state
|
|
|
|
//
|
|
|
|
struct PROJECT_WORK_FETCH {
|
2010-10-29 23:41:34 +00:00
|
|
|
double rec;
|
|
|
|
// recent estimated credit
|
|
|
|
double rec_time;
|
|
|
|
// when it was last updated
|
2010-11-23 19:39:47 +00:00
|
|
|
double rec_temp;
|
2011-10-24 17:53:09 +00:00
|
|
|
// temporary copy used during schedule_cpus() and work fetch
|
|
|
|
double rec_temp_save;
|
|
|
|
// temporary used during RR simulation
|
2014-10-10 17:37:07 +00:00
|
|
|
int project_reason;
|
|
|
|
int compute_project_reason(PROJECT*);
|
2012-08-18 23:26:10 +00:00
|
|
|
int n_runnable_jobs;
|
2014-03-10 00:09:21 +00:00
|
|
|
bool request_if_idle_and_uploading;
|
|
|
|
// Set when a job finishes.
|
|
|
|
// If we're uploading but a resource is idle, make a work request.
|
|
|
|
// If this succeeds, clear the flag.
|
2008-12-31 23:14:57 +00:00
|
|
|
PROJECT_WORK_FETCH() {
|
|
|
|
memset(this, 0, sizeof(*this));
|
|
|
|
}
|
2009-01-23 18:29:28 +00:00
|
|
|
void reset(PROJECT*);
|
2014-10-10 17:37:07 +00:00
|
|
|
void rr_init(PROJECT*);
|
2014-10-10 21:35:00 +00:00
|
|
|
void print_state(PROJECT*);
|
2008-12-31 23:14:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// global work fetch state
|
|
|
|
//
|
|
|
|
struct WORK_FETCH {
|
2014-12-17 17:56:01 +00:00
|
|
|
std::vector<PROJECT*> projects_sorted;
|
|
|
|
// projects in decreasing priority order
|
2013-04-02 19:32:28 +00:00
|
|
|
void setup();
|
|
|
|
PROJECT* choose_project();
|
2012-08-10 18:29:00 +00:00
|
|
|
// Find a project to ask for work.
|
2009-01-21 20:51:33 +00:00
|
|
|
PROJECT* non_cpu_intensive_project_needing_work();
|
2012-11-13 22:36:56 +00:00
|
|
|
void piggyback_work_request(PROJECT*);
|
2009-01-03 06:01:17 +00:00
|
|
|
// we're going to contact this project anyway;
|
2012-11-13 22:36:56 +00:00
|
|
|
// piggyback a work request if appropriate.
|
2008-12-31 23:14:57 +00:00
|
|
|
void accumulate_inst_sec(ACTIVE_TASK*, double dt);
|
2009-09-02 21:36:25 +00:00
|
|
|
void write_request(FILE*, PROJECT*);
|
2009-09-16 17:34:19 +00:00
|
|
|
void handle_reply(
|
|
|
|
PROJECT*, SCHEDULER_REPLY*, std::vector<RESULT*>new_results
|
|
|
|
);
|
2012-08-20 23:41:27 +00:00
|
|
|
void set_initial_work_request(PROJECT*);
|
2009-12-24 20:40:27 +00:00
|
|
|
void set_all_requests(PROJECT*);
|
2010-12-30 22:41:50 +00:00
|
|
|
void set_all_requests_hyst(PROJECT*, int rsc_type);
|
2008-12-31 23:14:57 +00:00
|
|
|
void print_state();
|
|
|
|
void init();
|
|
|
|
void rr_init();
|
2009-01-03 06:01:17 +00:00
|
|
|
void clear_request();
|
|
|
|
void compute_shares();
|
2010-09-24 21:24:02 +00:00
|
|
|
void clear_backoffs(APP_VERSION&);
|
2010-09-27 20:34:47 +00:00
|
|
|
void request_string(char*);
|
2013-04-26 19:19:43 +00:00
|
|
|
bool requested_work();
|
2014-08-10 04:44:39 +00:00
|
|
|
void copy_requests();
|
2008-12-31 23:14:57 +00:00
|
|
|
};
|
|
|
|
|
2011-03-25 03:44:09 +00:00
|
|
|
extern RSC_WORK_FETCH rsc_work_fetch[MAX_RSC];
|
2008-12-31 23:14:57 +00:00
|
|
|
extern WORK_FETCH work_fetch;
|
|
|
|
|
2011-12-06 09:20:30 +00:00
|
|
|
extern void project_priority_init(bool for_work_fetch);
|
|
|
|
extern double project_priority(PROJECT*);
|
|
|
|
extern void adjust_rec_sched(RESULT*);
|
|
|
|
extern void adjust_rec_work_fetch(RESULT*);
|
2010-11-23 19:39:47 +00:00
|
|
|
|
2011-12-06 09:20:30 +00:00
|
|
|
extern double total_peak_flops();
|
2014-10-10 17:37:07 +00:00
|
|
|
extern const char* project_reason_string(PROJECT* p, char* buf);
|
2014-10-10 21:35:00 +00:00
|
|
|
extern const char* rsc_project_reason_string(int);
|
2011-12-06 04:21:27 +00:00
|
|
|
|
2008-12-31 23:14:57 +00:00
|
|
|
#endif
|