2008-12-31 23:14:57 +00:00
|
|
|
#ifndef _WORK_FETCH_
|
|
|
|
#define _WORK_FETCH_
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#define RSC_TYPE_CPU 0
|
|
|
|
#define RSC_TYPE_CUDA 1
|
|
|
|
|
2008-12-31 23:30:38 +00:00
|
|
|
class PROJECT;
|
2008-12-31 23:14:57 +00:00
|
|
|
struct RESULT;
|
2008-12-31 23:30:38 +00:00
|
|
|
class ACTIVE_TASK;
|
2008-12-31 23:14:57 +00:00
|
|
|
struct RSC_WORK_FETCH;
|
|
|
|
|
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;
|
|
|
|
double debt;
|
|
|
|
|
|
|
|
// the following used by debt accounting
|
|
|
|
double secs_this_debt_interval;
|
|
|
|
inline void reset_debt_accounting() {
|
|
|
|
secs_this_debt_interval = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the following are used by rr_simulation()
|
|
|
|
//
|
2009-01-03 06:01:17 +00:00
|
|
|
double runnable_share;
|
|
|
|
// this project's share relative to projects that have
|
|
|
|
// nearly runnable jobs for this resource;
|
|
|
|
// determines processing rate for CPU
|
|
|
|
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
|
2008-12-31 23:14:57 +00:00
|
|
|
double instances_used;
|
2009-01-03 06:01:17 +00:00
|
|
|
//double shortfall;
|
|
|
|
//double nidle_now;
|
2008-12-31 23:14:57 +00:00
|
|
|
|
|
|
|
RSC_PROJECT_WORK_FETCH() {
|
|
|
|
memset(this, 0, sizeof(*this));
|
|
|
|
}
|
|
|
|
|
|
|
|
// whether this project is accumulating debt for this resource
|
2009-01-03 06:01:17 +00:00
|
|
|
bool debt_eligible(PROJECT*);
|
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;
|
|
|
|
debt = 0;
|
|
|
|
}
|
2009-01-08 00:41:15 +00:00
|
|
|
|
|
|
|
bool may_have_work;
|
2009-01-10 00:48:22 +00:00
|
|
|
bool compute_may_have_work();
|
2009-01-03 06:01:17 +00:00
|
|
|
//void accumulate_shortfall(RSC_WORK_FETCH&, PROJECT*, double dt, double nused);
|
2008-12-31 23:14:57 +00:00
|
|
|
bool overworked();
|
2009-01-21 20:51:33 +00:00
|
|
|
void backoff(PROJECT*, char*);
|
2009-01-10 00:48:22 +00:00
|
|
|
void rr_init();
|
|
|
|
void clear_backoff() {
|
|
|
|
backoff_time = 0;
|
|
|
|
backoff_interval = 0;
|
|
|
|
}
|
2008-12-31 23:14:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// per-resource state
|
|
|
|
//
|
|
|
|
struct RSC_WORK_FETCH {
|
|
|
|
int rsc_type;
|
|
|
|
int ninstances;
|
|
|
|
double speed; // relative to CPU
|
|
|
|
|
|
|
|
// the following used/set by rr_simulation():
|
|
|
|
//
|
|
|
|
double shortfall;
|
|
|
|
double nidle_now;
|
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
|
|
|
|
double total_runnable_share;
|
2008-12-31 23:14:57 +00:00
|
|
|
// total RS of projects with runnable jobs for this device
|
2009-01-03 06:01:17 +00:00
|
|
|
|
|
|
|
// the following specify the work request for this resource
|
|
|
|
//
|
|
|
|
double req_secs;
|
|
|
|
int req_instances;
|
2008-12-31 23:14:57 +00:00
|
|
|
|
|
|
|
// debt accounting
|
|
|
|
double secs_this_debt_interval;
|
|
|
|
inline void reset_debt_accounting() {
|
|
|
|
secs_this_debt_interval = 0;
|
|
|
|
}
|
|
|
|
void normalize_debt();
|
|
|
|
|
|
|
|
void rr_init();
|
|
|
|
void accumulate_shortfall(double d_time, double nused=0);
|
|
|
|
PROJECT* choose_project();
|
|
|
|
void accumulate_debt();
|
|
|
|
RSC_PROJECT_WORK_FETCH& project_state(PROJECT*);
|
|
|
|
void update_debts();
|
|
|
|
void print_state(char*);
|
2009-01-03 06:01:17 +00:00
|
|
|
void clear_request();
|
|
|
|
void set_request(PROJECT*);
|
2009-01-08 00:41:15 +00:00
|
|
|
bool may_have_work(PROJECT*);
|
2008-12-31 23:14:57 +00:00
|
|
|
RSC_WORK_FETCH() {
|
|
|
|
memset(this, 0, sizeof(*this));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// per project state
|
|
|
|
//
|
|
|
|
struct PROJECT_WORK_FETCH {
|
|
|
|
double overall_debt;
|
2009-01-08 00:41:15 +00:00
|
|
|
bool can_fetch_work;
|
|
|
|
bool compute_can_fetch_work(PROJECT*);
|
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*);
|
2008-12-31 23:14:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// global work fetch state
|
|
|
|
//
|
|
|
|
struct WORK_FETCH {
|
|
|
|
double estimated_delay;
|
|
|
|
void set_overall_debts();
|
|
|
|
PROJECT* choose_project();
|
2009-01-03 06:01:17 +00:00
|
|
|
// find a project to ask for work
|
2009-01-21 20:51:33 +00:00
|
|
|
PROJECT* non_cpu_intensive_project_needing_work();
|
2009-01-03 06:01:17 +00:00
|
|
|
void compute_work_request(PROJECT*);
|
|
|
|
// we're going to contact this project anyway;
|
|
|
|
// decide how much work to task for
|
2008-12-31 23:14:57 +00:00
|
|
|
void accumulate_inst_sec(ACTIVE_TASK*, double dt);
|
2009-01-10 00:48:22 +00:00
|
|
|
void write_request(FILE*);
|
2008-12-31 23:14:57 +00:00
|
|
|
void handle_reply(PROJECT*, std::vector<RESULT*>new_results);
|
2009-01-10 00:48:22 +00:00
|
|
|
void set_initial_work_request();
|
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();
|
2008-12-31 23:14:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern RSC_WORK_FETCH cuda_work_fetch;
|
|
|
|
extern RSC_WORK_FETCH cpu_work_fetch;
|
|
|
|
extern WORK_FETCH work_fetch;
|
|
|
|
|
|
|
|
#endif
|