Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef INCLUDED_GC_JOB_MANAGER_IMPL_H
00023 #define INCLUDED_GC_JOB_MANAGER_IMPL_H
00024
00025 #include <gcell/gc_job_manager.h>
00026 #include <gcell/gc_jd_stack.h>
00027 #include <gcell/gc_jd_queue.h>
00028 #include <gcell/gc_spu_args.h>
00029 #include "gc_client_thread_info.h"
00030 #include <libspe2.h>
00031 #include <vector>
00032 #include <boost/scoped_array.hpp>
00033
00034 typedef boost::shared_ptr<spe_gang_context> spe_gang_context_sptr;
00035 typedef boost::shared_ptr<spe_program_handle_t> spe_program_handle_sptr;
00036 typedef boost::scoped_array<gc_client_thread_info> gc_client_thread_info_sa;
00037
00038
00039 enum worker_state {
00040 WS_FREE,
00041 WS_INIT,
00042 WS_RUNNING,
00043 WS_DEAD,
00044 };
00045
00046 struct worker_ctx {
00047 volatile worker_state state;
00048 unsigned int spe_idx;
00049 spe_context_ptr_t spe_ctx;
00050 spe_spu_control_area_t *spe_ctrl;
00051 pthread_t thread;
00052 gc_spu_args_t *spu_args;
00053
00054 worker_ctx()
00055 : state(WS_FREE), spe_idx(0), spe_ctx(0), spe_ctrl(0),
00056 thread(0), spu_args(0) {}
00057 ~worker_ctx();
00058 };
00059
00060 enum evt_handler_state {
00061 EHS_INIT,
00062 EHS_RUNNING,
00063 EHS_SHUTTING_DOWN,
00064 EHS_WAITING_FOR_WORKERS_TO_DIE,
00065 EHS_DEAD,
00066 };
00067
00068 enum job_completer_state {
00069 JCS_INIT,
00070 JCS_RUNNING,
00071 JCS_DEAD,
00072 };
00073
00074 struct spe_event_handler {
00075 spe_event_handler_ptr_t ptr;
00076
00077 spe_event_handler() : ptr(0) {}
00078 ~spe_event_handler(){
00079 if (ptr){
00080 if (spe_event_handler_destroy(ptr) != 0){
00081 perror("spe_event_handler_destroy");
00082 }
00083 }
00084 }
00085 };
00086
00087
00088
00089
00090
00091
00092
00093 class gc_job_manager_impl : public gc_job_manager
00094 {
00095 enum { MAX_SPES = 16 };
00096
00097 int d_debug;
00098 gc_jm_options d_options;
00099 spe_program_handle_sptr d_spe_image;
00100 spe_gang_context_sptr d_gang;
00101
00102 worker_ctx d_worker[MAX_SPES];
00103 gc_spu_args_t *d_spu_args;
00104 boost::shared_ptr<void> _d_spu_args_boost;
00105
00106 gc_comp_info_t *d_comp_info;
00107 boost::shared_ptr<void> _d_comp_info_boost;
00108
00109
00110 omni_mutex d_eh_mutex;
00111 omni_condition d_eh_cond;
00112 pthread_t d_eh_thread;
00113 volatile evt_handler_state d_eh_state;
00114 volatile bool d_shutdown_requested;
00115 spe_event_handler d_spe_event_handler;
00116
00117
00118 omni_mutex d_jc_mutex;
00119 omni_condition d_jc_cond;
00120 pthread_t d_jc_thread;
00121 volatile job_completer_state d_jc_state;
00122 int d_jc_njobs_active;
00123
00124
00125 int d_ntell;
00126 unsigned int d_tell_start;
00127
00128
00129
00130 gc_job_desc_t *d_jd;
00131 boost::shared_ptr<void> _d_jd_boost;
00132
00133 gc_client_thread_info_sa d_client_thread;
00134
00135
00136
00137 int d_bvlen;
00138
00139
00140
00141
00142 boost::shared_ptr<void> _d_all_bitvectors;
00143
00144
00145 gc_jd_stack_t *d_free_list;
00146 boost::shared_ptr<void> _d_free_list_boost;
00147
00148
00149 gc_jd_queue_t *d_queue;
00150 boost::shared_ptr<void> _d_queue_boost;
00151
00152 int d_ea_args_maxsize;
00153
00154 struct gc_proc_def *d_proc_def;
00155 uint32_t d_proc_def_ls_addr;
00156 int d_nproc_defs;
00157
00158 gc_client_thread_info *alloc_cti();
00159 void free_cti(gc_client_thread_info *cti);
00160
00161 void create_event_handler();
00162 void set_eh_state(evt_handler_state s);
00163 void set_ea_args_maxsize(int maxsize);
00164
00165 void notify_clients_jobs_are_done(unsigned int spe_num,
00166 unsigned int completion_info_idx);
00167
00168 public:
00169 void event_handler_loop();
00170 void job_completer_loop();
00171
00172 private:
00173 bool send_all_spes(uint32_t msg);
00174 bool send_spe(unsigned int spe, uint32_t msg);
00175 void print_event(spe_event_unit_t *evt);
00176 void handle_event(spe_event_unit_t *evt);
00177 bool incr_njobs_active();
00178 void decr_njobs_active(int n);
00179 void tell_spes_to_check_queue();
00180 void poll_for_job_completion();
00181
00182
00183 void bv_zero(unsigned long *bv);
00184 void bv_clr(unsigned long *bv, unsigned int bitno);
00185 void bv_set(unsigned long *bv, unsigned int bitno);
00186 bool bv_isset(unsigned long *bv, unsigned int bitno);
00187 bool bv_isclr(unsigned long *bv, unsigned int bitno);
00188
00189 void setup_logfiles();
00190 void sync_logfiles();
00191 void unmap_logfiles();
00192
00193 friend gc_job_manager_sptr gc_make_job_manager(const gc_jm_options *options);
00194
00195 gc_job_manager_impl(const gc_jm_options *options = 0);
00196
00197 public:
00198 virtual ~gc_job_manager_impl();
00199
00200
00201
00202
00203
00204 virtual bool shutdown();
00205
00206
00207
00208
00209 virtual int nspes() const;
00210
00211
00212
00213
00214
00215 virtual gc_job_desc *alloc_job_desc();
00216
00217
00218
00219
00220
00221
00222 virtual void free_job_desc(gc_job_desc *jd);
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 virtual bool submit_job(gc_job_desc *jd);
00237
00238
00239
00240
00241
00242
00243
00244
00245 virtual bool
00246 wait_job(gc_job_desc *jd);
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 virtual int
00262 wait_jobs(unsigned int njobs,
00263 gc_job_desc *jd[], bool done[], gc_wait_mode mode);
00264
00265 virtual int ea_args_maxsize();
00266
00267 virtual gc_proc_id_t lookup_proc(const std::string &name);
00268 virtual std::vector<std::string> proc_names();
00269
00270 virtual void set_debug(int debug);
00271 virtual int debug();
00272 };
00273
00274 #endif