manifold_fullsim.cc

Go to the documentation of this file.
00001 /*
00002  * =====================================================================================
00003  *
00004  *       Filename:  simMc2Mesh.cc
00005  *
00006  *    Description:  This is a 2x2 mesh network with 3 trace packet generators
00007  *    and a single memory controller
00008  *
00009  *        Version:  1.0
00010  *        Created:  04/20/2010 02:59:08 AM
00011  *       Revision:  none
00012  *       Compiler:  gcc
00013  *
00014  *         Author:  Mitchelle Rasquinha (), mitchelle.rasquinha@gatech.edu
00015  *        Company:  Georgia Institute of Technology
00016  *
00017  * =====================================================================================
00018  */
00019 
00020 #ifndef  _simmc2mesh_cc_INC
00021 #define  _simmc2mesh_cc_INC
00022 
00023 #include        "mesh.h"
00024 #include        "../../util/genericData.h"
00025 #include        "../../util/config_params.h"
00026 #include        "../../zesto/zesto-uncore.h"
00027 #include        "../../simIris/components/impl/genericFlatMc.h"
00028 
00029 
00030 
00031 /*Declarations and default values for Network parameters
00032 unsigned int vcs=0, ports=0, buffer_size=0, credits=0;
00033 unsigned int no_nodes=0, no_mcs=0;
00034 unsigned long long int max_sim_time = 10000;
00035 unsigned int do_two_stage_router = 0;
00036 unsigned int  max_phy_link_bits = 128;
00037 ROUTING_SCHEME rc_method = XY;
00038 SW_ARBITRATION sw_arbitration = ROUND_ROBIN;
00039 message_class priority_msg_type = PRIORITY_REQ;
00040 unsigned int print_setup = 1;
00041 unsigned int grid_size=0;
00042 string routing_scheme, sw_arbitration_scheme;
00043 vector<string> traces;
00044 vector<uint> mc_positions;
00045 string trace_name, output_path, msg_type_string;
00046 unsigned int links;
00047  * */
00048 string data, word;
00049 unsigned int cores_per_node=1;
00050 /*These objects are declared externally in mesh.h*/
00051 
00052 
00053 
00054 
00055 /*The main Mesh object*/
00056 Mesh* mesh;
00057 void print_state_at_deadlock(void);
00058 
00059 char *s;
00060 int  exit_code;
00061 
00062 /* stats signal handler */
00063 static void
00064 signal_sim_stats(int sigtype)
00065 {
00066   sim_dump_stats = TRUE;
00067 }
00068 
00069 /* exit signal handler */
00070 static void
00071 signal_exit_now(int sigtype)
00072 {
00073   sim_exit_now = TRUE;
00074 }
00075 
00076 /* execution start/end times */
00077 time_t sim_start_time;
00078 time_t sim_end_time;
00079 int sim_elapsed_time;
00080 
00081 /* byte/word swapping required to execute target executable on this host */
00082 int sim_swap_bytes;
00083 int sim_swap_words;
00084 
00085 /* exit when this becomes non-zero */
00086 int sim_exit_now = FALSE;
00087 
00088 /* longjmp here when simulation is completed */
00089 jmp_buf sim_exit_buf;
00090 
00091 /* set to non-zero when simulator should dump statistics */
00092 int sim_dump_stats = FALSE;
00093 
00094 /* options database */
00095 struct opt_odb_t *sim_odb;
00096 
00097 /* stats database */
00098 struct stat_sdb_t *sim_sdb;
00099 
00100 /* redirected program/simulator output file names */
00101 char *sim_simout = NULL;
00102 char *sim_progout = NULL;
00103 FILE *sim_progfd = NULL;
00104 
00105 /* track first argument orphan, this is the program to execute */
00106 static int exec_index = -1;
00107 
00108 /* dump help information */
00109 bool help_me;
00110 
00111 /* random number generator seed */
00112 int rand_seed;
00113 
00114 /* initialize and quit immediately */
00115 bool init_quit;
00116 
00117 /* simulator scheduling priority */
00118 int nice_priority;
00119 
00120 
00121 static int
00122 orphan_fn(int i, int argc, char **argv)
00123 {
00124   exec_index = i;
00125   return /* done */FALSE;
00126 }
00127 
00128 static void
00129 banner(FILE *fd, int argc, char **argv)
00130 {
00131   char *s;
00132 
00133   fprintf(fd,
00134           "%s: SimpleScalar/%s Tool Set version %d.%d of %s.\n"
00135           "Copyright (C) 2000-2002 by The Regents of The University of Michigan.\n"
00136           "Copyright (C) 1994-2002 by Todd M. Austin, Ph.D. and SimpleScalar, LLC.\n"
00137           "This version of SimpleScalar is licensed for academic non-commercial use only.\n"
00138           "\n",
00139           ((s = strrchr(argv[0], '/')) ? s+1 : argv[0]),
00140           VER_TARGET, VER_MAJOR, VER_MINOR, VER_UPDATE);
00141 }
00142 
00143 
00144 static void
00145 usage(FILE *fd, int argc, char **argv)
00146 {
00147   fprintf(fd, "Usage: %s {-options} executable {arguments}\n", argv[0]);
00148   opt_print_help(sim_odb, fd);
00149 }
00150 
00151 static int running = FALSE;
00152 
00153 /* print all simulator stats */
00154 void
00155 print_state_at_deadlock(void)
00156 {
00157     for ( uint i=0; i<no_nodes; i++)
00158     {
00159         static_cast<GenericRouterVcs*>(mesh->routers[i])->dump_buffer_state();
00160     }
00161     exit(1);
00162 }
00163 
00164 void
00165 sim_print_stats(FILE *fd)               /* output stream */
00166 {
00167   if (!running)
00168     return;
00169 
00170   /* get stats time */
00171   sim_end_time = time((time_t *)NULL);
00172   sim_elapsed_time = MAX(sim_end_time - sim_start_time, 1);
00173 
00174   /* print simulation stats */
00175   fprintf(fd, "\nsim: ** simulation statistics **\n");
00176   stat_print_stats(sim_sdb, fd);
00177   sim_aux_stats(fd);
00178   fprintf(fd, "\n");
00179 
00180   cerr << mesh->print_stats();
00181   ullint total_link_utilization = 0;
00182   uint no_of_non_zero_util_links = 0;
00183   uint edge_links = 0;
00184   for ( uint i=0 ; i<links ; i++ )
00185   {
00186       double link_util = mesh->link_a[i]->get_flits_utilization();
00187       if( link_util )
00188           no_of_non_zero_util_links++;
00189       if( mesh->link_a[i]->input_connection == NULL || mesh->link_a[i]->output_connection == NULL )
00190           edge_links++;
00191 
00192       total_link_utilization += (ullint)link_util;
00193   }
00194 
00195   for ( uint i=0 ; i<links ; i++ )
00196   {
00197       double link_util = mesh->link_b[i]->get_flits_utilization();
00198       total_link_utilization += (ullint)link_util;
00199       if( link_util )
00200           no_of_non_zero_util_links++;
00201       if( mesh->link_b[i]->input_connection == NULL || mesh->link_b[i]->output_connection == NULL )
00202           edge_links++;
00203   }
00204     
00205   double max_net_bw = (no_of_non_zero_util_links * max_phy_link_bits*max_sim_time*1.0)/(3e9*8); /* Assuming 1flit=1phit */
00206     double used_bw = (total_link_utilization+0.0)*max_phy_link_bits/8;
00207     cerr << "\n\n************** Link Stats ***************\n";
00208     cerr << " max_phy_link_bits: " << max_phy_link_bits << endl;
00209     cerr << " max_sim_time: " << max_sim_time << endl;
00210     cerr << " Total flits passed on the links: " << total_link_utilization << endl;
00211     cerr << " Links used (L): " << no_of_non_zero_util_links << " of " << 2*links - edge_links << " links." << endl;
00212     cerr << " Available BW (L*ch_w/8*sim_time/freq): " << max_net_bw << "MB." << endl;
00213     cerr << " BW Used " << used_bw << endl;
00214     cerr << " total_link_utilization" << total_link_utilization << endl;
00215     cerr << " \% A/B " << used_bw/max_net_bw<< endl;
00216 
00217   unsigned long long int tot_pkts = 0, tot_pkts_out = 0, tot_flits = 0;
00218   for ( uint i=0 ; i<no_nodes ; i++ )
00219   {
00220       tot_pkts_out += mesh->interfaces[i]->get_packets_out();
00221       tot_pkts += mesh->interfaces[i]->get_packets();
00222       tot_flits += mesh->interfaces[i]->get_flits_out();
00223   }
00224 
00225   unsigned long long int sim_time_ms = (time(NULL) - sim_start_time);
00226   cerr << "\n\n************** Simulation Stats ***************\n";
00227   cerr << " Simulation Time: " << sim_time_ms << " s. " << endl;
00228   cerr << " No of pkts per s: " << (tot_pkts+0.0)/sim_time_ms<< endl;
00229   cerr << " No of flits per s: " << (tot_flits+0.0)/sim_time_ms << endl;
00230 
00231   cerr << " Total Mem Req serviced: " << tot_pkts_out/2 << endl;
00232   cerr << "------------ End SimIris ---------------------" << endl;
00233 
00234 }
00235 
00236 /* print stats, uninitialize simulator components, and exit w/ exitcode */
00237 static void
00238 exit_now(int exit_code)
00239 {
00240   /* print simulation stats */
00241   sim_print_stats(stderr);
00242 
00243   /* un-initialize the simulator */
00244   sim_uninit();
00245 
00246   /* all done! */
00247   exit(exit_code);
00248 }
00249 
00250 
00251 unsigned int iris_process_options(int argc,char *argv[])
00252 {
00253 /* The following parameters must be specified in the config with the
00254      * correct knobs */
00255     unsigned int offset;    
00256     ifstream fd(argv[1]);
00257     while(!fd.eof())
00258     {
00259         getline(fd,data);
00260         string::size_type position = -1;
00261         position = data.find("#");
00262         istringstream iss( data, istringstream::in);
00263         while ( position > data.size() && iss >> word )
00264         {
00265             if ( word.compare("PRINT_SETUP") == 0)   
00266                 iss >> print_setup;
00267             if ( word.compare("VCS") == 0)   
00268                 iss >> vcs;
00269             if ( word.compare("PORTS") == 0) 
00270                 iss >> ports;
00271             if ( word.compare("CORES_PER_NODE") == 0) 
00272                 iss >> cores_per_node;
00273             if ( word.compare("BUFFER_SIZE") == 0)
00274                  iss >> buffer_size;
00275             if ( word.compare("CREDITS") == 0)
00276                  iss >> credits;
00277             if ( word.compare("GRID_SIZE") == 0)
00278                  iss >> grid_size;
00279             if ( word.compare("NO_OF_NODES") == 0)
00280                 iss >> no_nodes;
00281             if ( word.compare("MCS") == 0)
00282                 iss >> no_mcs;
00283             if ( word.compare("MAX_SIM_TIME") == 0)
00284                 iss >> max_sim_time;
00285             if ( word.compare("OUTPUT_PATH") == 0)
00286                 iss >> output_path;
00287              if ( word.compare("PHY_LINK_WIDTH") == 0)
00288                 iss >> max_phy_link_bits;
00289     //        if ( word.compare("ROUTER_MODEL") == 0)
00290       //          iss >> router_model_string;
00291             NO_OF_THREADS = no_nodes;
00292             /* Init parameters of mc_constants*/
00293         //    if ( word.compare("MC_MODEL") == 0)
00294           //      iss >> mc_model_string;
00295             if ( word.compare("THREAD_BITS_POSITION") == 0)
00296                 iss >> THREAD_BITS_POSITION;
00297             if ( word.compare("MC_ADDR_BITS") == 0)
00298                 iss >> MC_ADDR_BITS;
00299             if ( word.compare("BANK_BITS") == 0)
00300                 iss >> BANK_BITS;
00301             if ( word.compare("NO_OF_CHANNELS") == 0)
00302                 iss >> NO_OF_CHANNELS;
00303                 
00304             if ( word.compare("NO_OF_RANKS") == 0)
00305                 iss >> NO_OF_RANKS;
00306             if ( word.compare("NO_OF_BANKS") == 0)
00307                 iss >> NO_OF_BANKS;
00308                 
00309             if ( word.compare("NO_OF_ROWS") == 0)
00310                 iss >> NO_OF_ROWS;
00311             if ( word.compare("NO_OF_COLUMNS") == 0)
00312                 iss >> NO_OF_COLUMNS;
00313             if ( word.compare("COLUMN_SIZE") == 0)
00314                 iss >> COLUMN_SIZE;
00315             if ( word.compare("MSHR_SIZE") == 0)
00316                 iss >> MSHR_SIZE;
00317                 
00318             if ( word.compare("MAX_BUFFER_SIZE") == 0)
00319                 iss >> MAX_BUFFER_SIZE;
00320             if ( word.compare("MAX_CMD_BUFFER_SIZE") == 0)
00321                 iss >> MAX_CMD_BUFFER_SIZE;
00322             if ( word.compare("RESPONSE_BUFFER_SIZE") == 0)
00323                 iss >> RESPONSE_BUFFER_SIZE;
00324              
00325             if ( word.compare("NETWORK_ADDRESS_BITS") == 0)
00326                 iss >> NETWORK_ADDRESS_BITS;
00327             if ( word.compare("NETWORK_THREADID_BITS") == 0)
00328                 iss >> NETWORK_THREADID_BITS ;
00329             if ( word.compare("NETWORK_COMMAND_BITS") == 0)
00330                 iss >> NETWORK_COMMAND_BITS;
00331 
00332             /*  ******************************************* */
00333             if ( word.compare("TWO_STAGE_ROUTER") == 0)
00334                 iss >> do_two_stage_router;
00335             if ( word.compare("ROUTING_SCHEME") == 0)
00336                 iss >> routing_scheme;
00337             if ( word.compare("SW_ARBITRATION") == 0)
00338                 iss >> sw_arbitration_scheme;
00339             if ( word.compare("PRIORITY_MSG_TYPE") == 0)
00340                 iss >> msg_type_string;
00341             if ( word.compare("DRAM_PAGE_POLICY") == 0)
00342                 iss >> dram_page_policy_string;
00343             if ( word.compare("ADDRESS_MAP_SCHEME") == 0)
00344                 iss >> addr_map_scheme_string;
00345             if ( word.compare("MC_SCHEDULING_ALGORITHM") == 0)
00346                 iss >> mc_scheduling_algorithm_string;
00347             if ( word.compare("MC_LOC") == 0)
00348             {
00349                 uint mc_xpos, mc_ypos;
00350                 iss >> mc_xpos;
00351                 iss >> mc_ypos;
00352                 mc_positions.push_back(mc_xpos*grid_size + mc_ypos);
00353             }
00354             NO_OF_THREADS = no_nodes;
00355         }
00356     }
00357 
00358     for ( uint i=0; i<argc; i++)
00359     {
00360         if( strcmp(argv[i],"--thread_id_bits")==0)
00361         {
00362             THREAD_BITS_POSITION = atoi(argv[i+1]);
00363             continue;
00364         }
00365         if( strcmp(argv[i],"--mc_bits")==0)
00366         {
00367             MC_ADDR_BITS = atoi(argv[i+1]);
00368             continue;
00369         }
00370         if( strcmp(argv[i],"--router_two_stg")==0)
00371         {
00372             do_two_stage_router = atoi(argv[i+1]);
00373             continue;
00374         }
00375         if( strcmp(argv[i],"--routing_scheme")==0)
00376         { 
00377             routing_scheme = argv[i+1];
00378             continue;
00379         }
00380         if( strcmp(argv[i],"--sw_arbitration")==0)
00381         {
00382             sw_arbitration_scheme = argv[i+1];
00383             continue;
00384         }
00385         if( strcmp(argv[i],"--msg_type")==0)
00386         {
00387             msg_type_string = argv[i+1];
00388             continue;
00389         }
00390         if( strcmp(argv[i],"--bank_bits")==0)
00391         {
00392             BANK_BITS = atoi(argv[i+1]);
00393             continue;
00394         }
00395         offset=i;
00396     }
00397 
00398 
00399 
00400 
00401     if( routing_scheme.compare("odd-even") == 0)
00402         rc_method = ODD_EVEN;
00403     if( strcmp(routing_scheme.c_str(),"negative-first") == 0)
00404         rc_method = NEGATIVE_FIRST;
00405     if( strcmp(routing_scheme.c_str(),"west-first") == 0)
00406         rc_method = WEST_FIRST;
00407     if( strcmp(routing_scheme.c_str(),"north-last") == 0)
00408         rc_method = NORTH_LAST;
00409     if( strcmp(routing_scheme.c_str(),"north-last-nm") == 0)
00410         rc_method = NORTH_LAST_NON_MINIMAL;
00411     if( routing_scheme.compare("xy") == 0)
00412         rc_method = XY;
00413            
00414     if( strcmp(sw_arbitration_scheme.c_str(),"round-robin") == 0)
00415         sw_arbitration = ROUND_ROBIN;
00416     if( strcmp(sw_arbitration_scheme.c_str(),"round-robin-p") == 0)
00417         sw_arbitration = ROUND_ROBIN_PRIORITY;
00418     if( strcmp(sw_arbitration_scheme.c_str(),"fcfs") == 0)
00419         sw_arbitration = FCFS;
00420 
00421     if( strcmp(msg_type_string.c_str(),"PRIORITY_REQ") == 0)
00422         priority_msg_type = PRIORITY_REQ;
00423     if( strcmp(msg_type_string.c_str(),"ONE_FLIT_REQ") == 0)
00424         priority_msg_type = ONE_FLIT_REQ;
00425     if( strcmp(msg_type_string.c_str(),"RESPONSE_PKT") == 0)
00426         priority_msg_type = RESPONSE_PKT;
00427 
00428     /* Number of MC's and the size of the position vector should be the same. */
00429 //    assert(mc_positions.size() == no_mcs);
00430 
00431     /* Compute additional parameters */
00432     links = (ports + (grid_size -1)*(ports-1)) + ( (ports-1) + (grid_size -1)*(ports-2))*(grid_size-1);
00433     fd.close();
00434 
00435         /* Creating mesh topology with the following config */
00436         cerr << "\n-----------------------------------------------------------------------------------\n";
00437         cerr << "** CAPSTONE - Cycle Accurate Parallel Simulator Technologgy for On-Chip Networks **\n";
00438         cerr << " This is simIris. A second version of Capstone." << endl;
00439         cerr << "-- Computer Architecture and Systems Lab                                         --\n"
00440             << "-- Georgia Institute of Technology                                               --\n"
00441             << "-----------------------------------------------------------------------------------\n";
00442         cerr << "Cmd line: ";
00443         for( int i=0; i<argc; i++)
00444             cerr << argv[i] << " ";
00445         cerr << endl;
00446         cerr << " vcs:\t" << vcs << endl;
00447         cerr << " ports:\t" << ports << endl;
00448         cerr << " buffer_size:\t" << buffer_size << endl;
00449         cerr << " credits:\t" << credits << endl;
00450         cerr << " no_nodes( spread over a 2D Mesh topology):\t" << no_nodes << endl;
00451         cerr << " grid size:\t" << grid_size << endl;
00452         cerr << " links:  \t" << links << endl;
00453         cerr << " no_of_mcs:\t" << no_mcs << endl;
00454         cerr << " no_of_traces:\t" << traces.size() << endl;
00455         cerr << " max_sim_time:\t" << max_sim_time << endl;
00456         cerr << " max_phy_link_bits:\t" << max_phy_link_bits << endl;
00457         cerr << " THREAD_BITS_POSITION:\t" << THREAD_BITS_POSITION<< endl;
00458     cerr << " MC_ADDR_BITS:\t" << MC_ADDR_BITS<< endl;
00459     cerr << " TWO_STAGE_ROUTER:\t" << do_two_stage_router << endl;
00460     cerr << " ROUTING_SCHEME:\t" << routing_scheme << " " << rc_method << endl;
00461     cerr << " SW_ARBITRATION:\t" << sw_arbitration_scheme<< " " << sw_arbitration<< endl;
00462     cerr << " BANK_BITS:\t" << BANK_BITS << endl;
00463     cerr << " NETWORK_BITS:\t" << NETWORK_ADDRESS_BITS << endl;
00464     cerr << " COMMAND_BITS:\t" << NETWORK_THREADID_BITS << endl;
00465     cerr << " COREID_BITS:\t" << NETWORK_COMMAND_BITS << endl;
00466     cerr << " NO_OF_THREADS:\t" << NO_OF_THREADS << endl;
00467     cerr << " NO_OF_CHANNELS:\t" << NO_OF_RANKS << endl;
00468     cerr << " NO_OF_RANKS:\t" << NO_OF_RANKS << endl;
00469     cerr << " NO_OF_BANKS:\t" << NO_OF_BANKS << endl;
00470     cerr << " NO_OF_ROWS:\t" << NO_OF_ROWS << endl;
00471     cerr << " NO_OF_COLUMNS:\t" << NO_OF_COLUMNS << endl;
00472     cerr << " COLUMN_SIZE:\t" << COLUMN_SIZE << endl;
00473     cerr << " Msg_class with arbitration priority:\t" << msg_type_string << endl;
00474         return offset;  
00475 }
00476 
00477 
00478 void iris_init()
00479 {
00480    
00481     mesh = new Mesh();
00482     mesh->init( ports, vcs, credits, buffer_size, no_nodes, grid_size, links);
00483     mesh->max_sim_time = max_sim_time;
00484 
00485     /* Create the mesh->routers and mesh->interfaces */
00486     for( uint i=0; i<no_nodes; i++)
00487     {
00488         mesh->routers.push_back( new GenericRouterVcs());
00489         mesh->interfaces.push_back ( new GenericInterfaceVcs());
00490     }
00491 
00492     /*  Create the mc modules and link to the uncores */
00493     vector<unsigned int>::iterator itr;
00494     /*j is the index of the uncores that have been linked in the Mesh*/
00495     unsigned int j=0;   
00496     for(unsigned int i=0; i<no_nodes; i++)
00497     {
00498         itr = find(mc_positions.begin(), mc_positions.end(), i);
00499         if( itr != mc_positions.end())
00500         {
00501             mesh->processors.push_back( new NI() );
00502         }
00503         else
00504         {
00505             mesh->processors.push_back( static_cast <Processor*> (uncores[j]) );
00506             j++;
00507             for ( unsigned int jj=0; jj<mc_positions.size(); jj++)
00508             {
00509                 static_cast<uncore_t*>(mesh->processors[i])->mc_node_ip.push_back(mc_positions[jj]);
00510             }
00511         }
00512     }
00513 
00514     /* Create the links connecting all nodes in the mesh */
00515     for (unsigned int  i=0; i<links; i++)
00516     { 
00517         mesh->link_a.push_back(new GenericLink());
00518         mesh->link_b.push_back(new GenericLink());
00519     }
00520 
00521     /*Coonects the interfaces to the processors which are either Memory Controller NI's or Zesto Uncores*/
00522     mesh->connect_interface_processor();
00523 
00524     /* Set all the component ids */
00525     unsigned int comp_id = 0, alink_comp_id = 1000, blink_comp_id = 5000;
00526     for ( uint i=0 ; i<no_nodes; i++ )
00527     {
00528         mesh->processors[i]->setComponentId(comp_id++);
00529         mesh->interfaces[i]->setComponentId(comp_id++);
00530         mesh->routers[i]->setComponentId(comp_id++);
00531     }
00532 
00533     for ( uint i=0 ; i<links; i++ )
00534     {
00535         mesh->link_a[i]->setComponentId(alink_comp_id++);
00536         mesh->link_b[i]->setComponentId(blink_comp_id++);
00537         mesh->link_a[i]->setup();
00538         mesh->link_b[i]->setup();
00539     }
00540 
00541     /*  Set up the node ips for components Node ip's are the actual number of the node in the mesh */
00542     for ( uint i=0 ; i<no_nodes ; i++ )
00543     {
00544         mesh->interfaces[i]->node_ip = i;
00545         mesh->routers[i]->node_ip = i;
00546         mesh->processors[i]->node_ip = i;
00547     }
00548 
00549     /* Set the number of ports, vcs, credits and buffer sizes for the
00550      * components */
00551     for ( uint i=0 ; i<no_nodes ; i++ )
00552     {
00553         mesh->interfaces[i]->set_no_vcs(vcs);
00554         mesh->interfaces[i]->set_no_credits(credits);
00555         mesh->interfaces[i]->set_buffer_size(credits);
00556         //mesh->processors[i]->set_output_path(output_path);
00557     }
00558 
00559     /*Sets up the routers,links,interfaces*/
00560     mesh->setup();
00561     //for ( uint i=0 ; i<no_nodes ; i++ )
00562         //mesh->processors[i]->set_output_path(output_path);
00563 
00564     /*  Set no of ports and positions for routing */
00565     vector< uint > grid_x;
00566     vector< uint > grid_y;
00567     grid_x.resize(no_nodes);
00568     grid_y.resize(no_nodes);
00569 
00570     /* Limitation of only modelling squares */
00571     for ( uint i=0 ; i<grid_size ; i++ )
00572         for ( uint j=0 ; j<grid_size ; j++ )
00573         {
00574             grid_x[(i*grid_size)+j] = j;
00575             grid_y[(i*grid_size)+j] = i;
00576         }
00577 
00578 
00579     for ( uint i=0 ; i<no_nodes ; i++ )
00580         mesh->routers[i]->set_no_nodes(no_nodes);
00581 
00582     for ( uint i=0 ; i<no_nodes ; i++ )
00583         for( uint j=0; j < ports ; j++)
00584             for( uint k=0; k < no_nodes ; k++) // Assuming is a square mesh. 
00585             {
00586                 static_cast<GenericRouterVcs*>(mesh->routers[i])->set_grid_x_location(j,k, grid_x[k]);
00587                 static_cast<GenericRouterVcs*>(mesh->routers[i])->set_grid_y_location(j,k, grid_y[k]);
00588             }
00589 
00590     mesh->connect_interface_routers();
00591     mesh->connect_routers();
00592 
00593     /*  Printing out all component after setup */
00594     if( print_setup )
00595     {
00596     //for ( uint i=0 ; i<no_nodes; i++ )
00597     //{
00598       //  cout << "\nUncore: " << i << " " << mesh->processors[i]->toString();
00599         //cout << "\ninterface: " << i << " " << mesh->interfaces[i]->toString();
00600         //cout << "\nrouter: " << i << " " << mesh->routers[i]->toString();
00601     //}
00602 
00603     //for ( uint i=0 ; i<links ; i++ )
00604     //{
00605       //  cout << "\nlinka_" << i << " " << mesh->link_a[i]->toString();
00606         //cout << "\nlinkb_" << i << " " << mesh->link_b[i]->toString();
00607     //}
00608     }
00609 }
00610 
00611 
00612 
00613 
00614 int main( int argc, char *argv[] )
00615 {
00616   unsigned long long int sim_start_time = time(NULL);
00617   if(argc<2)
00618   {
00619       cout << "Error: Requires config file for input parameters\n";
00620       return 1;
00621   }
00622 
00623 
00624   /* catch SIGUSR1 and dump intermediate stats */
00625   signal(SIGUSR1, signal_sim_stats);
00626 
00627   /* catch SIGUSR2 and dump final stats and exit */
00628   signal(SIGUSR2, signal_exit_now);
00629 
00630   /* register an error handler */
00631   fatal_hook(sim_print_stats);
00632 
00633 
00634   /* set up a non-local exit point */
00635   if ((exit_code = setjmp(sim_exit_buf)) != 0)
00636   {
00637      /* special handling as longjmp cannot pass 0 */
00638      exit_now(exit_code-1);
00639   }
00640 
00641 
00642   /* Sets up default values for  core knobs*/
00643   sim_pre_init();
00644 
00645   /* register global options - Initialising the options database */
00646   sim_odb = opt_new(orphan_fn);
00647 
00648   /* register all simulator-specific options in the options database */
00649   sim_reg_options(sim_odb);
00650 
00651   /*IRIS: Processing the commandline options and config file of IRIS*/
00652   unsigned int offset = iris_process_options(argc,argv);
00653   
00654   /*num_threads is set by the -cores option in Zesto, we need to set it to no_nodes*cores_per_node */
00655   num_threads= no_nodes*cores_per_node;
00656 
00657   /* parse zesto simulator options, options for Network and MC are parsed ahead */
00658   exec_index = -1;
00659 
00660   /*opt_process options looks for the keyword zesto and process only the commandline after that*/
00661   opt_process_options(sim_odb, argc, argv );
00662 
00663   /* redirect I/O? */
00664   if (sim_simout != NULL)
00665     {
00666       /* send simulator non-interactive output (STDERR) to file SIM_SIMOUT */
00667       fflush(stderr);
00668       if (!freopen(sim_simout, "w", stderr))
00669         fatal("unable to redirect simulator output to file `%s'", sim_simout);
00670     }
00671 
00672   if (sim_progout != NULL)
00673     {
00674       /* redirect simulated program output to file SIM_PROGOUT */
00675       sim_progfd = fopen(sim_progout, "w");
00676       if (!sim_progfd)
00677         fatal("unable to redirect program output to file `%s'", sim_progout);
00678     }
00679 
00680   /* need at least two argv values to run */
00681   if (argc < 2)
00682     {
00683       banner(stderr, argc, argv);
00684       usage(stderr, argc, argv);
00685       exit(1);
00686     }
00687 
00688   /* opening banner */
00689   banner(stderr, argc, argv);
00690 
00691   if(help_me)
00692   {
00693     /* print help message and exit */
00694     usage(stderr, argc, argv);
00695     exit(1);
00696   }
00697 
00698   /* seed the random number generator */
00699   if (rand_seed == 0)
00700   {
00701     /* seed with the timer value, true random */
00702     mysrand(time((time_t *)NULL));
00703   }
00704   else
00705   {
00706     /* seed with default or user-specified random number generator seed */
00707     mysrand(rand_seed);
00708   }
00709 
00710   /* check simulator-specific options - Located in file zesto-opts.c*/
00711   sim_check_options(sim_odb, argc-offset, argv+offset);
00712 
00713   /* set simulator scheduling priority */
00714   if (nice(0) < nice_priority)
00715     {
00716       if (nice(nice_priority - nice(0)) < 0)
00717         fatal("could not renice simulator process");
00718     }
00719 
00720   /* initialize the instruction decoder - sets up macros in file:machine.c , no code executed */
00721   md_init_decoder();
00722 
00723   opt_print_options(sim_odb, stderr, /* long */TRUE, /* !notes */TRUE);
00724 
00725   /* initialize all simulation modules - thread structures, uncore & core structures,register files, oracle/exec/alloc/decode models for all cores */
00726   sim_post_init();
00727   
00728   init_dram_timing_parameters();
00729   /*IRIS: Instatiates the mesh,routers,MC's,interfaces and links them to the uncore*/
00730   iris_init();
00731 
00732   /* register all simulator stats */
00733   sim_sdb = stat_new();
00734   sim_reg_stats(threads,sim_sdb);
00735 
00736   /* record start of execution time, used in rate stats */
00737   sim_start_time = time((time_t *)NULL);
00738 
00739   /* output simulation conditions */
00740   //s = ctime(&sim_start_time);
00741   //if (s[strlen(s)-1] == '\n')
00742   //  s[strlen(s)-1] = '\0';
00743   //fprintf(stderr, "\nsim: simulation started @ %s, options follow:\n", s);
00744   opt_print_options(sim_odb, stderr, /* short */TRUE, /* notes */TRUE);
00745   sim_aux_config(stderr);
00746   fprintf(stderr, "\n");
00747 
00748   /* omit option dump time from rate stats */
00749   sim_start_time = time((time_t *)NULL);
00750 
00751   if (init_quit)
00752     exit_now(0);
00753 
00754   running = TRUE;
00755   sim_main();//Register the timer tick component, turn sim_main into a component
00756 
00757   class zesto_component *tick = new zesto_component();
00758 
00759   Simulator::StopAt(1000000000);
00760   Simulator::Run();
00761 
00762   sim_print_stats(stderr);
00763 
00764   delete mesh;
00765 
00766   return(0);
00767 }                               /* ----------  end of function main  ---------- */
00768 
00769 #endif   /* ----- #ifndef _simmc2mesh_cc_INC  ----- */

Generated on Tue Oct 19 17:22:00 2010 for IRIS by  doxygen 1.5.8