00001 /* 00002 * ===================================================================================== 00003 * 00004 * Filename: myFullyVirtualArbiter.cc 00005 * 00006 * Description: 00007 * 00008 * Version: 1.0 00009 * Created: 04/27/2010 12:58:11 AM 00010 * Revision: none 00011 * Compiler: gcc 00012 * 00013 * Author: Mitchelle Rasquinha (), mitchelle.rasquinha@gatech.edu 00014 * Company: Georgia Institute of Technology 00015 * 00016 * ===================================================================================== 00017 */ 00018 00019 #ifndef _ptopswitcharbitervcs_cc_INC 00020 #define _ptopswitcharbitervcs_cc_INC 00021 00022 #include "ptopSwaVcs.h" 00023 00024 PToPSwitchArbiterVcs::PToPSwitchArbiterVcs() 00025 { 00026 name = "swa"; 00027 } 00028 00029 PToPSwitchArbiterVcs::~PToPSwitchArbiterVcs() 00030 { 00031 } 00032 00033 void 00034 PToPSwitchArbiterVcs::resize(uint p, uint v) 00035 { 00036 ports = p; 00037 vcs = v; 00038 requested.resize(ports); 00039 priority_reqs.resize(ports); 00040 last_port_winner.resize(ports); 00041 requesting_inputs.resize(ports); 00042 last_winner.resize(ports); 00043 00044 for ( uint i=0; i<ports; i++) 00045 { 00046 requested[i].resize(ports*vcs); 00047 requesting_inputs[i].resize(ports*vcs); 00048 last_winner[i].win_cycle = 0; 00049 } 00050 00051 for ( uint i=0; i<ports; i++) 00052 for ( uint j=0; j<(ports*vcs); j++) 00053 { 00054 requested[i][j]=false; 00055 } 00056 00057 for ( uint i=0; i<ports; i++) 00058 { 00059 last_port_winner[i] = -1; 00060 } 00061 00062 } 00063 00064 bool 00065 PToPSwitchArbiterVcs::is_requested( uint oport, uint inport, uint och ) 00066 { 00067 if( oport >= ports || inport >= ports || och >= vcs) 00068 { 00069 cout << " Error in SWA oport: "<< oport <<" inp: " << inport <<" och: " << och << endl; 00070 exit(1); 00071 } 00072 return requested[oport][inport*vcs+och]; 00073 } 00074 00075 void 00076 PToPSwitchArbiterVcs::request(uint oport, uint ovc, uint inport, uint ivc ) 00077 { 00078 requested[oport][inport*vcs+ovc] = true; 00079 requesting_inputs[oport][inport*vcs+ovc].port = inport; 00080 requesting_inputs[oport][inport*vcs+ovc].ch=ivc; 00081 requesting_inputs[oport][inport*vcs+ovc].in_time = (ullint)Simulator::Now(); 00082 return; 00083 } 00084 00085 SA_unit 00086 PToPSwitchArbiterVcs::pick_winner( uint oport) 00087 { 00088 return do_round_robin_arbitration(oport); 00089 } 00090 00091 SA_unit 00092 PToPSwitchArbiterVcs::do_round_robin_arbitration( uint oport) 00093 { 00094 00095 if( last_winner[oport].win_cycle >= Simulator::Now()) 00096 return last_winner[oport]; 00097 00098 /* Now look at contesting input ports on this channel and pick 00099 * a winner*/ 00100 bool winner_found = false; 00101 for( uint i=last_port_winner[oport]+1; i<(ports*vcs); i++) 00102 { 00103 if(requested[oport][i]) 00104 { 00105 last_port_winner[oport] = i; 00106 winner_found = true; 00107 last_winner[oport].port = requesting_inputs[oport][i].port; 00108 last_winner[oport].ch= requesting_inputs[oport][i].ch; 00109 last_winner[oport].win_cycle= Simulator::Now(); 00110 return last_winner[oport]; 00111 } 00112 } 00113 00114 if(!winner_found) 00115 for( uint i=0; i<=last_port_winner[oport]; i++) 00116 { 00117 if(requested[oport][i]) 00118 { 00119 last_port_winner[oport] = i; 00120 winner_found = true; 00121 last_winner[oport].port = requesting_inputs[oport][i].port; 00122 last_winner[oport].ch= requesting_inputs[oport][i].ch; 00123 last_winner[oport].win_cycle= Simulator::Now(); 00124 return last_winner[oport]; 00125 } 00126 } 00127 if(!winner_found) 00128 { 00129 _DBG_NOARG("ERROR: RR Cant find port winner" ); 00130 exit(1); 00131 } 00132 00133 00134 return last_winner[oport]; 00135 } 00136 00137 void 00138 PToPSwitchArbiterVcs::clear_requestor( uint oport, uint inport, uint och) 00139 { 00140 requested[oport][inport*vcs+och] = false; 00141 return; 00142 } 00143 00144 00145 bool 00146 PToPSwitchArbiterVcs::is_empty() 00147 { 00148 00149 for( uint i=0; i<ports; i++) 00150 for( uint j=0; j<(ports*vcs); j++) 00151 if(requested[i][j] ) 00152 return false; 00153 00154 return true; 00155 00156 } 00157 00158 string 00159 PToPSwitchArbiterVcs::toString() const 00160 { 00161 stringstream str; 00162 str << "PToPSwitchArbiterVcs: matrix size " 00163 << "\t requested_qu row_size: " << requested.size(); 00164 if( requested.size()) 00165 str << " col_size: " << requested[0].size() 00166 ; 00167 return str.str(); 00168 } 00169 #endif /* ----- #ifndef _ptopswitcharbitervcs_cc_INC ----- */