00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef COMPONENTS_TRIG_CPU_TRIG_CPU_H
00014 #define COMPONENTS_TRIG_CPU_TRIG_CPU_H
00015
00016 #include <string>
00017 #include <list>
00018 #include <set>
00019 #include <queue>
00020 #include <vector>
00021 #include <cstdlib>
00022 #include <stdlib.h>
00023
00024 #include <sst/core/component.h>
00025 #include <sst/core/event.h>
00026 #include <sst/core/link.h>
00027 #include <sst/core/timeConverter.h>
00028
00029 #include "sst/elements/portals4_sm/trig_nic/trig_nic_event.h"
00030 #include "portals.h"
00031
00032 using namespace SST;
00033
00034 class portals;
00035 class application;
00036 class barrier_action;
00037
00038 struct posted_recv {
00039 int handle;
00040 int src;
00041 void* buffer;
00042
00043 posted_recv(int handle, int src, void* buffer) {
00044 this->handle = handle;
00045 this->src = src;
00046 this->buffer = buffer;
00047 }
00048 };
00049
00050 struct unex_msg {
00051 uint8_t* data;
00052 int src;
00053 int length;
00054
00055 unex_msg(uint8_t* data, int src, int length) {
00056 this->data = data;
00057 this->src = src;
00058 this->length = length;
00059 }
00060 };
00061
00062 class ptl_nic_event : public Event {
00063 public:
00064 ptl_nic_event(ptl_int_nic_op_t* op) : Event() {
00065 operation = op;
00066 }
00067 ptl_nic_event() : Event() {}
00068
00069 ptl_int_nic_op_t* operation;
00070 };
00071
00072 class trig_cpu : public Component {
00073 public:
00074 friend class portals;
00075
00076 trig_cpu(ComponentId_t id, Params_t& params);
00077 int Setup();
00078 int Finish();
00079
00080 void send(int dest, uint64_t data);
00081 bool recv(int src, uint64_t* buf, int& handle);
00082
00083 void isend(int dest, void* data, int length);
00084 bool irecv(int src, void* buf, int& handle);
00085
00086 bool process_pending_msg();
00087 bool waitall();
00088 bool waitall(int size, int* src);
00089
00090 int calcXPosition( int node );
00091 int calcYPosition( int node );
00092 int calcZPosition( int node );
00093 int calcNodeID(int x, int y, int z);
00094
00095 int getMyId(void) { return my_id; }
00096 int getNumNodes(void) { return num_nodes; }
00097
00098 void addBusyTime(const char* time)
00099 {
00100 busy += defaultTimeBase->convertFromCoreTime(registerTimeBase(time, false)->getFactor());
00101 }
00102
00103 portals* getPortalsHandle(void) { return ptl; }
00104 int getRadix(void) { return radix; }
00105 int getMessageSize(void) { return msg_size; }
00106 int getChunkSize(void) { return chunk_size; }
00107
00108 private:
00109 trig_cpu();
00110 trig_cpu(const trig_cpu& c);
00111 void operator=(trig_cpu const&);
00112
00113 void initPortals(void);
00114
00115
00116
00117 void event_handler(Event* ev);
00118
00119
00120
00121 void processEvent( Event* e );
00122 void processEventPortals( Event* e );
00123
00124
00125 void ptlNICHandler( Event* e );
00126
00127
00128
00129
00130 void event_nic_timing(Event* e);
00131 void event_dma_return(Event *e);
00132 void event_pio_delay(Event* e);
00133
00134 void wakeUp();
00135
00136
00137 bool writeToNIC(trig_nic_event* ev);
00138 void returnCredits(int num);
00139 void setTimingParams(int set);
00140
00141
00142 int my_id;
00143 int num_nodes;
00144 int state;
00145 int top_state;
00146 int x_size;
00147 int y_size;
00148 int z_size;
00149 int count;
00150 int latency;
00151
00152
00153 portals* ptl;
00154 int radix;
00155 int msg_size;
00156 int chunk_size;
00157 bool enable_coalescing;
00158 bool enable_putv;
00159
00160
00161 uint64_t msg_rate_delay;
00162 uint64_t busy;
00163 int outstanding_msg;
00164 int recv_handle;
00165 std::list<posted_recv*> posted_recv_q;
00166 std::set<int> outstanding_recv;
00167 std::queue<trig_nic_event*> pending_msg;
00168 std::list<unex_msg*> unex_msg_q;
00169
00170 bool waiting;
00171 SimTime_t wait_start_time;
00172
00173 bool blocking;
00174 int nic_credits;
00175 trig_nic_event* blocked_event;
00176 int blocked_busy;
00177
00178 bool pio_in_progress;
00179 bool use_portals;
00180
00181 int timing_set;
00182 int delay_host_pio_write;
00183 int delay_sfence;
00184 int delay_bus_xfer;
00185 int latency_dma_mem_access;
00186 int added_pio_latency;
00187 int recv_overhead;
00188
00189
00190 SimTime_t noise_interval;
00191 SimTime_t noise_duration;
00192 SimTime_t noise_count;
00193 int noise_runs;
00194 int current_run;
00195 bool do_noise;
00196
00197 Params_t params;
00198 Link* nic;
00199 Link* self;
00200 Link* ptl_link;
00201 Link* nic_timing_link;
00202 bool nic_timing_wakeup_scheduled;
00203 Link* dma_return_link;
00204 Link* pio_delay_link;
00205 int dma_return_count;
00206
00207 std::string frequency;
00208
00209 application *app;
00210
00211
00212
00213 std::queue<trig_nic_event*> wc_buffers;
00214 int wc_buffers_max;
00215 std::queue<trig_nic_event*> dma_buffers;
00216
00217 public:
00218 static barrier_action* barrier_act;
00219
00220 static void
00221 addTimeToStats(SimTime_t time);
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268 static int
00269 getRand(int max)
00270 {
00271 if (!rand_init) {
00272 srand(0);
00273 rand_init = true;
00274 }
00275 if ( max == 0 ) return 0;
00276 return rand() % max;
00277 }
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298 static void
00299 barrier();
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315 void start_noise_section() {
00316 do_noise = true;
00317 }
00318
00319 void end_noise_section() {
00320 do_noise = false;
00321 }
00322 private:
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333 static bool rand_init;
00334
00335
00336
00337
00338
00339
00340
00341 };
00342
00343 #endif // COMPONENTS_TRIG_CPU_TRIG_CPU_H