2008-08-05 22:52:17 +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/>.
|
|
|
|
//
|
2007-02-15 21:11:05 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "app.h"
|
|
|
|
#include "time_stats.h"
|
2007-02-23 17:29:19 +00:00
|
|
|
#include "client_types.h"
|
2007-05-08 01:55:28 +00:00
|
|
|
#include "../sched/edf_sim.h"
|
2008-10-28 22:10:09 +00:00
|
|
|
#include "rr_sim.h"
|
2007-02-15 21:11:05 +00:00
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
2007-02-24 14:55:59 +00:00
|
|
|
#define WORK_FETCH_DONT_NEED 0
|
|
|
|
// project: suspended, deferred, or no new work (can't ask for more work)
|
|
|
|
// overall: not work_fetch_ok (from CPU policy)
|
|
|
|
#define WORK_FETCH_OK 1
|
|
|
|
// project: has more than min queue * share, not suspended/def/nonewwork
|
|
|
|
// overall: at least min queue, work fetch OK
|
|
|
|
#define WORK_FETCH_NEED 2
|
|
|
|
// project: less than min queue * resource share of DL/runnable results
|
|
|
|
// overall: less than min queue
|
|
|
|
#define WORK_FETCH_NEED_IMMEDIATELY 3
|
|
|
|
// project: no downloading or runnable results
|
|
|
|
// overall: at least one idle CPU
|
|
|
|
|
2007-04-10 20:13:15 +00:00
|
|
|
struct SIM_RESULTS {
|
|
|
|
double cpu_used;
|
|
|
|
double cpu_wasted;
|
|
|
|
double cpu_idle;
|
|
|
|
int nresults_met_deadline;
|
|
|
|
int nresults_missed_deadline;
|
2007-04-10 21:56:11 +00:00
|
|
|
double share_violation;
|
2007-07-12 19:52:58 +00:00
|
|
|
double monotony;
|
2007-04-10 21:56:11 +00:00
|
|
|
double cpu_wasted_frac;
|
|
|
|
double cpu_idle_frac;
|
2007-04-10 20:13:15 +00:00
|
|
|
|
2007-04-10 21:56:11 +00:00
|
|
|
void compute();
|
|
|
|
void print(FILE* f, const char* title=0);
|
2007-04-10 20:13:15 +00:00
|
|
|
void parse(FILE* f);
|
|
|
|
void add(SIM_RESULTS& r);
|
2007-05-04 23:05:17 +00:00
|
|
|
void divide(int);
|
|
|
|
void clear();
|
2007-04-10 20:13:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PROJECT_RESULTS {
|
|
|
|
double cpu_used;
|
|
|
|
double cpu_wasted;
|
|
|
|
int nresults_met_deadline;
|
|
|
|
int nresults_missed_deadline;
|
|
|
|
};
|
2007-02-24 20:10:06 +00:00
|
|
|
|
2010-04-28 16:22:06 +00:00
|
|
|
struct NORMAL_DIST {
|
2007-02-24 20:10:06 +00:00
|
|
|
double mean;
|
2007-04-04 19:34:01 +00:00
|
|
|
double stdev;
|
2007-02-24 20:10:06 +00:00
|
|
|
int parse(XML_PARSER&, char* end_tag);
|
|
|
|
double sample();
|
|
|
|
};
|
|
|
|
|
2010-04-28 16:22:06 +00:00
|
|
|
struct UNIFORM_DIST {
|
2007-02-24 20:10:06 +00:00
|
|
|
double lo;
|
|
|
|
double hi;
|
|
|
|
int parse(XML_PARSER&, char* end_tag);
|
|
|
|
double sample();
|
|
|
|
};
|
|
|
|
|
|
|
|
class RANDOM_PROCESS {
|
2007-04-09 02:17:26 +00:00
|
|
|
double last_time;
|
|
|
|
double time_left;
|
|
|
|
bool value;
|
|
|
|
double off_lambda;
|
2007-02-24 20:10:06 +00:00
|
|
|
public:
|
|
|
|
double frac;
|
|
|
|
double lambda;
|
|
|
|
int parse(XML_PARSER&, char* end_tag);
|
2007-04-09 02:17:26 +00:00
|
|
|
bool sample(double);
|
2010-01-21 00:14:56 +00:00
|
|
|
void init(double);
|
2007-04-09 02:17:26 +00:00
|
|
|
RANDOM_PROCESS();
|
2007-02-24 20:10:06 +00:00
|
|
|
};
|
|
|
|
|
2010-04-28 16:22:06 +00:00
|
|
|
struct SIM_APP: public APP {
|
2007-02-24 20:10:06 +00:00
|
|
|
double latency_bound;
|
2007-03-29 16:40:43 +00:00
|
|
|
double fpops_est;
|
2007-02-24 20:10:06 +00:00
|
|
|
NORMAL_DIST fpops;
|
|
|
|
NORMAL_DIST checkpoint_period;
|
|
|
|
double working_set;
|
2007-03-29 16:40:43 +00:00
|
|
|
double weight;
|
2007-02-24 20:10:06 +00:00
|
|
|
|
2007-04-03 17:16:39 +00:00
|
|
|
SIM_APP(){}
|
2007-02-24 20:10:06 +00:00
|
|
|
int parse(XML_PARSER&);
|
|
|
|
};
|
|
|
|
|
2010-04-28 16:22:06 +00:00
|
|
|
struct SIM_PROJECT: public PROJECT {
|
2007-02-24 20:10:06 +00:00
|
|
|
RANDOM_PROCESS available;
|
2007-04-04 19:34:01 +00:00
|
|
|
int index;
|
|
|
|
int result_index;
|
2007-05-04 23:05:17 +00:00
|
|
|
double idle_time;
|
|
|
|
double idle_time_sumsq;
|
2007-04-10 20:13:15 +00:00
|
|
|
bool idle;
|
2007-05-08 23:12:40 +00:00
|
|
|
int max_infeasible_count;
|
2007-05-09 15:23:10 +00:00
|
|
|
// for DCF variants:
|
|
|
|
int completed_task_count;
|
|
|
|
double completions_ratio_mean;
|
|
|
|
double completions_ratio_s;
|
|
|
|
double completions_ratio_stdev;
|
|
|
|
double completions_required_stdevs;
|
2007-04-10 20:13:15 +00:00
|
|
|
|
2007-02-24 20:10:06 +00:00
|
|
|
int parse(XML_PARSER&);
|
2007-04-10 20:13:15 +00:00
|
|
|
PROJECT_RESULTS project_results;
|
|
|
|
void print_results(FILE*, SIM_RESULTS&);
|
|
|
|
void init();
|
2007-05-08 01:55:28 +00:00
|
|
|
void backoff();
|
2007-05-09 15:23:10 +00:00
|
|
|
void update_dcf_stats(RESULT*);
|
2007-02-24 20:10:06 +00:00
|
|
|
};
|
|
|
|
|
2010-04-28 16:22:06 +00:00
|
|
|
struct SIM_HOST: public HOST_INFO {
|
2007-02-24 20:10:06 +00:00
|
|
|
RANDOM_PROCESS available;
|
|
|
|
RANDOM_PROCESS idle;
|
2007-04-06 22:19:17 +00:00
|
|
|
double connection_interval;
|
|
|
|
// min time between network connections
|
2007-02-24 20:10:06 +00:00
|
|
|
int parse(XML_PARSER&);
|
|
|
|
};
|
|
|
|
|
2007-02-15 21:11:05 +00:00
|
|
|
class CLIENT_STATE {
|
|
|
|
public:
|
|
|
|
double now;
|
|
|
|
vector<PROJECT*> projects;
|
|
|
|
vector<WORKUNIT*> workunits;
|
|
|
|
vector<RESULT*> results;
|
2009-04-09 17:26:41 +00:00
|
|
|
vector<APP_VERSION*> app_versions;
|
2007-02-24 00:11:30 +00:00
|
|
|
vector<APP*> apps;
|
2007-02-15 21:11:05 +00:00
|
|
|
ACTIVE_TASK_SET active_tasks;
|
|
|
|
GLOBAL_PREFS global_prefs;
|
2007-02-24 20:10:06 +00:00
|
|
|
SIM_HOST host_info;
|
2007-02-15 21:11:05 +00:00
|
|
|
TIME_STATS time_stats;
|
2008-04-01 20:46:41 +00:00
|
|
|
COPROCS coprocs;
|
2007-02-24 04:29:58 +00:00
|
|
|
CLIENT_STATE();
|
2007-04-03 17:16:39 +00:00
|
|
|
bool initialized;
|
|
|
|
bool run_cpu_benchmarks;
|
2007-04-04 15:40:07 +00:00
|
|
|
FILE* html_out;
|
2007-07-12 18:38:53 +00:00
|
|
|
void html_start(bool);
|
2007-04-04 15:40:07 +00:00
|
|
|
void html_rec();
|
2007-07-12 18:38:53 +00:00
|
|
|
void html_end(bool);
|
2007-04-04 15:40:07 +00:00
|
|
|
std::string html_msg;
|
2007-04-10 20:13:15 +00:00
|
|
|
double share_violation();
|
2007-07-12 19:52:58 +00:00
|
|
|
double monotony();
|
2009-02-12 19:34:27 +00:00
|
|
|
bool user_active;
|
2010-06-02 18:21:30 +00:00
|
|
|
bool had_or_requested_work;
|
2007-02-15 21:11:05 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
double app_started;
|
|
|
|
public:
|
|
|
|
ACTIVE_TASK* lookup_active_task_by_result(RESULT*);
|
|
|
|
int report_result_error(RESULT&, const char *format, ...);
|
|
|
|
double available_ram();
|
|
|
|
double max_available_ram();
|
|
|
|
void set_client_state_dirty(const char*);
|
2007-02-21 22:27:35 +00:00
|
|
|
RESULT* lookup_result(PROJECT*, const char*);
|
2007-02-15 21:11:05 +00:00
|
|
|
|
|
|
|
// cpu_sched.C
|
|
|
|
private:
|
|
|
|
double debt_interval_start;
|
|
|
|
double total_wall_cpu_time_this_debt_interval;
|
|
|
|
// "wall CPU time" accumulated since last adjust_debts()
|
2007-04-11 21:49:57 +00:00
|
|
|
double fetchable_resource_share();
|
2007-02-15 21:11:05 +00:00
|
|
|
double total_cpu_time_this_debt_interval;
|
|
|
|
double cpu_shortfall;
|
|
|
|
bool must_enforce_cpu_schedule;
|
|
|
|
bool must_schedule_cpus;
|
|
|
|
bool must_check_work_fetch;
|
|
|
|
void assign_results_to_projects();
|
|
|
|
RESULT* largest_debt_project_best_result();
|
2009-02-26 22:04:53 +00:00
|
|
|
RESULT* earliest_deadline_result(bool);
|
2007-03-15 23:39:22 +00:00
|
|
|
void reset_debt_accounting();
|
2007-02-15 21:11:05 +00:00
|
|
|
bool possibly_schedule_cpus();
|
|
|
|
void schedule_cpus();
|
|
|
|
bool enforce_schedule();
|
|
|
|
bool no_work_for_a_cpu();
|
2009-05-10 04:42:47 +00:00
|
|
|
void append_unfinished_time_slice(vector<RESULT*> &runnable_jobs);
|
2007-02-15 21:11:05 +00:00
|
|
|
void print_deadline_misses();
|
2007-04-03 19:06:26 +00:00
|
|
|
public:
|
2009-01-10 00:48:22 +00:00
|
|
|
void adjust_debts();
|
2008-12-31 23:07:59 +00:00
|
|
|
void rr_simulation();
|
2008-10-29 22:13:04 +00:00
|
|
|
std::vector <RESULT*> ordered_scheduled_results;
|
2007-06-25 19:05:29 +00:00
|
|
|
double retry_shmem_time;
|
2007-02-15 21:11:05 +00:00
|
|
|
inline double work_buf_min() {
|
|
|
|
return global_prefs.work_buf_min_days * 86400;
|
|
|
|
}
|
2007-03-28 21:30:45 +00:00
|
|
|
double work_buf_additional() {
|
|
|
|
return global_prefs.work_buf_additional_days * 86400;
|
|
|
|
}
|
2007-04-17 22:24:53 +00:00
|
|
|
inline double work_buf_total() {
|
|
|
|
double x = work_buf_min() + work_buf_additional();
|
|
|
|
if (x < 1) x = 1;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2009-12-19 17:21:37 +00:00
|
|
|
void request_enforce_schedule(PROJECT*, const char*);
|
2007-02-15 21:11:05 +00:00
|
|
|
void request_schedule_cpus(const char*);
|
2008-04-01 20:46:41 +00:00
|
|
|
bool sufficient_coprocs(APP_VERSION&);
|
|
|
|
void reserve_coprocs(APP_VERSION&);
|
|
|
|
void free_coprocs(APP_VERSION&);
|
2007-02-15 21:11:05 +00:00
|
|
|
|
|
|
|
// --------------- cs_apps.C:
|
|
|
|
private:
|
|
|
|
double total_resource_share();
|
|
|
|
double potentially_runnable_resource_share();
|
|
|
|
double nearly_runnable_resource_share();
|
|
|
|
public:
|
2009-12-02 04:47:42 +00:00
|
|
|
double runnable_resource_share(int);
|
2007-02-15 21:11:05 +00:00
|
|
|
void request_work_fetch(const char*);
|
|
|
|
// Check if work fetch needed. Called when:
|
|
|
|
// - core client starts (CS::init())
|
|
|
|
// - task is completed or fails
|
|
|
|
// - tasks are killed
|
|
|
|
// - an RPC completes
|
|
|
|
// - project suspend/detch/attach/reset GUI RPC
|
|
|
|
// - result suspend/abort GUI RPC
|
|
|
|
int quit_activities();
|
|
|
|
void set_ncpus();
|
|
|
|
double estimate_cpu_time(WORKUNIT&);
|
|
|
|
double get_fraction_done(RESULT* result);
|
2007-11-07 19:32:32 +00:00
|
|
|
int input_files_available(RESULT*, bool, FILE_INFO** f=0);
|
2007-02-15 21:11:05 +00:00
|
|
|
int ncpus;
|
|
|
|
// number of usable cpus
|
|
|
|
private:
|
|
|
|
int nslots;
|
|
|
|
|
|
|
|
int app_finished(ACTIVE_TASK&);
|
|
|
|
bool start_apps();
|
|
|
|
bool handle_finished_apps();
|
|
|
|
public:
|
|
|
|
ACTIVE_TASK* get_task(RESULT*);
|
2007-02-23 17:29:19 +00:00
|
|
|
|
2007-02-24 14:55:59 +00:00
|
|
|
// --------------- cs_scheduler.C
|
|
|
|
private:
|
|
|
|
bool contacted_sched_server;
|
|
|
|
int overall_work_fetch_urgency;
|
|
|
|
double avg_proc_rate();
|
|
|
|
|
2007-02-23 17:29:19 +00:00
|
|
|
// --------------- work_fetch.C:
|
|
|
|
public:
|
|
|
|
int proj_min_results(PROJECT*, double);
|
|
|
|
void check_project_timeout();
|
|
|
|
PROJECT* next_project_master_pending();
|
|
|
|
PROJECT* next_project_sched_rpc_pending();
|
|
|
|
PROJECT* next_project_trickle_up_pending();
|
|
|
|
PROJECT* next_project_need_work();
|
|
|
|
PROJECT* find_project_with_overdue_results();
|
|
|
|
double overall_cpu_frac();
|
|
|
|
double time_until_work_done(PROJECT*, int, double);
|
|
|
|
bool compute_work_requests();
|
|
|
|
void scale_duration_correction_factors(double);
|
|
|
|
void generate_new_host_cpid();
|
|
|
|
void compute_nuploading_results();
|
|
|
|
|
|
|
|
//////////////////
|
2007-05-08 01:55:28 +00:00
|
|
|
void make_job(SIM_PROJECT*, WORKUNIT*, RESULT*);
|
|
|
|
void handle_completed_results();
|
|
|
|
void get_workload(vector<IP_RESULT>&);
|
2007-02-23 17:29:19 +00:00
|
|
|
int parse_projects(char*);
|
|
|
|
int parse_host(char*);
|
2007-04-06 19:47:37 +00:00
|
|
|
void simulate();
|
2007-02-23 17:29:19 +00:00
|
|
|
bool scheduler_rpc_poll();
|
2007-04-05 23:15:20 +00:00
|
|
|
bool simulate_rpc(PROJECT*);
|
2007-04-10 20:13:15 +00:00
|
|
|
void print_project_results(FILE*);
|
2009-02-18 21:21:12 +00:00
|
|
|
bool in_abort_sequence;
|
2007-02-15 21:11:05 +00:00
|
|
|
};
|
|
|
|
|
2007-02-21 22:27:35 +00:00
|
|
|
class NET_STATUS {
|
|
|
|
public:
|
|
|
|
bool have_sporadic_connection;
|
|
|
|
};
|
|
|
|
|
2007-02-15 21:11:05 +00:00
|
|
|
extern CLIENT_STATE gstate;
|
2007-02-24 14:55:59 +00:00
|
|
|
extern NET_STATUS net_status;
|
2007-05-08 01:55:28 +00:00
|
|
|
extern FILE* logfile;
|
|
|
|
extern bool user_active;
|
|
|
|
extern SIM_RESULTS sim_results;
|
|
|
|
extern double calculate_exponential_backoff(
|
|
|
|
int n, double MIN, double MAX
|
|
|
|
);
|
|
|
|
|
2007-05-09 15:23:10 +00:00
|
|
|
extern bool dcf_dont_use;
|
|
|
|
extern bool dcf_stats;
|
2007-05-15 20:29:26 +00:00
|
|
|
extern bool cpu_sched_rr_only;
|
|
|
|
extern bool dual_dcf;
|
2007-07-11 20:13:53 +00:00
|
|
|
extern bool work_fetch_old;
|
2009-12-07 00:53:32 +00:00
|
|
|
extern bool gpus_usable;
|
2008-10-29 00:00:01 +00:00
|
|
|
|
2010-01-21 00:14:56 +00:00
|
|
|
#define SCHEDULER_RPC_POLL_PERIOD 5.0
|
|
|
|
|
2009-02-20 18:37:27 +00:00
|
|
|
#define WORK_FETCH_PERIOD 60
|
|
|
|
|
|
|
|
#define CPU_SCHED_ENFORCE_PERIOD 60
|
|
|
|
// enforce CPU schedule at least this often
|
|
|
|
|
|
|
|
#define DEBT_ADJUST_PERIOD CPU_SCHED_ENFORCE_PERIOD
|
|
|
|
// debt is adjusted at least this often,
|
|
|
|
// since adjust_debts() is called from enforce_schedule()
|
2009-02-26 22:04:53 +00:00
|
|
|
#define HANDLE_FINISHED_APPS_PERIOD 1.0
|
2009-12-03 23:27:32 +00:00
|
|
|
|
|
|
|
#define MAX_STD (86400)
|
|
|
|
// maximum short-term debt
|
2010-01-21 00:14:56 +00:00
|
|
|
|
|
|
|
#define START_TIME 946684800
|
|
|
|
// Jan 1 2000
|