// 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 . // Work fetch logic for CPU, GPU, and other processing resources. // See http://boinc.berkeley.edu/trac/wiki/GpuWorkFetch #ifndef _WORK_FETCH_ #define _WORK_FETCH_ #include #include extern bool use_hyst_fetch; #define RSC_TYPE_ANY -1 #define RSC_TYPE_CPU 0 struct PROJECT; struct RESULT; struct ACTIVE_TASK; struct RSC_WORK_FETCH; struct SCHEDULER_REPLY; struct APP_VERSION; // state per (resource, project) pair // struct RSC_PROJECT_WORK_FETCH { // the following are persistent (saved in state file) double backoff_time; double backoff_interval; // the following used by debt accounting double secs_this_debt_interval; inline void reset_debt_accounting() { secs_this_debt_interval = 0; } double queue_est; // an estimate of instance-secs of queued work; // a temp used in computing overall debts bool anon_skip; // set if this project is anonymous platform // and it has no app version that uses this resource 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 bool has_runnable_jobs; double sim_nused; double nused_total; // sum of instances over all runnable jobs int deadlines_missed; int deadlines_missed_copy; // copy of the above used during schedule_cpus() std::deque pending; std::deque::iterator pending_iter; RSC_PROJECT_WORK_FETCH() { backoff_time = 0; backoff_interval = 0; secs_this_debt_interval = 0; queue_est = 0; anon_skip = false; fetchable_share = 0; has_runnable_jobs = false; sim_nused = 0; nused_total = 0; deadlines_missed = 0; deadlines_missed_copy = 0; } inline void reset() { backoff_time = 0; backoff_interval = 0; } bool may_have_work; bool compute_may_have_work(PROJECT*, int rsc_type); void backoff(PROJECT*, const char*); void rr_init(PROJECT*, int rsc_type); void clear_backoff() { backoff_time = 0; backoff_interval = 0; } }; // estimate the time a resource will be saturated // with high-priority jobs. // struct BUSY_TIME_ESTIMATOR { std::vector busy_time; int ninstances; inline void reset() { for (int i=0; isecs_this_debt_interval = 0; } void rr_init(); void accumulate_shortfall(double d_time); void update_saturated_time(double dt); void update_busy_time(double dur, double nused); PROJECT* choose_project_hyst(); PROJECT* choose_project(int); void supplement(PROJECT*); RSC_PROJECT_WORK_FETCH& project_state(PROJECT*); void print_state(const char*); void clear_request(); void set_request(PROJECT*); bool may_have_work(PROJECT*); RSC_WORK_FETCH() { 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; } }; // per project state // struct PROJECT_WORK_FETCH { double rec; // recent estimated credit double rec_time; // when it was last updated double rec_temp; // temporary copy used during schedule_cpus() and work fetch double rec_temp_save; // temporary used during RR simulation bool can_fetch_work; bool compute_can_fetch_work(PROJECT*); bool has_runnable_jobs; PROJECT_WORK_FETCH() { memset(this, 0, sizeof(*this)); } void reset(PROJECT*); }; // global work fetch state // struct WORK_FETCH { PROJECT* choose_project(); // find a project to ask for work PROJECT* non_cpu_intensive_project_needing_work(); void compute_work_request(PROJECT*); // we're going to contact this project anyway; // decide how much work to task for void accumulate_inst_sec(ACTIVE_TASK*, double dt); void write_request(FILE*, PROJECT*); void handle_reply( PROJECT*, SCHEDULER_REPLY*, std::vectornew_results ); void set_initial_work_request(); void set_all_requests(PROJECT*); void set_all_requests_hyst(PROJECT*, int rsc_type); void print_state(); void init(); void rr_init(); void clear_request(); void compute_shares(); void clear_backoffs(APP_VERSION&); void request_string(char*); }; extern RSC_WORK_FETCH rsc_work_fetch[MAX_RSC]; extern WORK_FETCH work_fetch; extern void set_no_rsc_config(); 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*); extern double total_peak_flops(); #endif