1 |
2 |
acastong |
//fairness_l3.cpp
|
2 |
|
|
|
3 |
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
4 |
|
|
* Version: MPL 1.1
|
5 |
|
|
*
|
6 |
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
7 |
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
8 |
|
|
* the License. You may obtain a copy of the License at
|
9 |
|
|
* http://www.mozilla.org/MPL/
|
10 |
|
|
*
|
11 |
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
12 |
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
13 |
|
|
* for the specific language governing rights and limitations under the
|
14 |
|
|
* License.
|
15 |
|
|
*
|
16 |
|
|
* The Original Code is HyperTransport Tunnel IP Core.
|
17 |
|
|
*
|
18 |
|
|
* The Initial Developer of the Original Code is
|
19 |
|
|
* Ecole Polytechnique de Montreal.
|
20 |
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
21 |
|
|
* the Initial Developer. All Rights Reserved.
|
22 |
|
|
*
|
23 |
|
|
* Contributor(s):
|
24 |
|
|
* Ami Castonguay <acastong@grm.polymtl.ca>
|
25 |
|
|
*
|
26 |
|
|
* Alternatively, the contents of this file may be used under the terms
|
27 |
|
|
* of the Polytechnique HyperTransport Tunnel IP Core Source Code License
|
28 |
|
|
* (the "PHTICSCL License", see the file PHTICSCL.txt), in which case the
|
29 |
|
|
* provisions of PHTICSCL License are applicable instead of those
|
30 |
|
|
* above. If you wish to allow use of your version of this file only
|
31 |
|
|
* under the terms of the PHTICSCL License and not to allow others to use
|
32 |
|
|
* your version of this file under the MPL, indicate your decision by
|
33 |
|
|
* deleting the provisions above and replace them with the notice and
|
34 |
|
|
* other provisions required by the PHTICSCL License. If you do not delete
|
35 |
|
|
* the provisions above, a recipient may use your version of this file
|
36 |
|
|
* under either the MPL or the PHTICSCL License."
|
37 |
|
|
*
|
38 |
|
|
* ***** END LICENSE BLOCK ***** */
|
39 |
|
|
|
40 |
|
|
#include "fairness_l3.h"
|
41 |
|
|
|
42 |
|
|
fairness_l3::fairness_l3(sc_module_name name) : sc_module(name){
|
43 |
|
|
SC_METHOD(clocked_process);
|
44 |
|
|
sensitive_pos(clk);
|
45 |
|
|
sensitive_neg(resetx);
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
void fairness_l3::clocked_process(){
|
49 |
|
|
if(!resetx.read()){
|
50 |
|
|
//Reset to 0 the 3-bit counters
|
51 |
|
|
for(int n = 0; n < 32; n++)
|
52 |
|
|
forward_tracker[n] = 0;
|
53 |
|
|
|
54 |
|
|
forward_count = 0;
|
55 |
|
|
window = 1;
|
56 |
|
|
local_priority = false;
|
57 |
|
|
lfsr = 0;
|
58 |
|
|
denominator = 0;
|
59 |
|
|
last_fwd_ack_ro = false;
|
60 |
|
|
last_ro_packet_fwd_unitid = 0;
|
61 |
|
|
last_ro_packet_fwd_chain = false;
|
62 |
|
|
}
|
63 |
|
|
else{
|
64 |
|
|
//Register stuff
|
65 |
|
|
sc_bv<64> pkt = ro_packet_fwd.read().packet;
|
66 |
|
|
last_ro_packet_fwd_chain = isChain(pkt);
|
67 |
|
|
last_fwd_ack_ro = fwd_ack_ro.read();
|
68 |
|
|
last_ro_packet_fwd_unitid = ((sc_uint<5>)(sc_bv<5>)pkt.range(12,8));
|
69 |
|
|
|
70 |
|
|
////////////////////////////////////////
|
71 |
|
|
// Check if an increment is in order
|
72 |
|
|
////////////////////////////////////////
|
73 |
|
|
|
74 |
|
|
bool count_fwd_packet_sent = last_fwd_ack_ro.read() && !last_ro_packet_fwd_chain.read();
|
75 |
|
|
|
76 |
|
|
/////////////////////////////////////////
|
77 |
|
|
// Calculate value of 3-bit counters
|
78 |
|
|
/////////////////////////////////////////
|
79 |
|
|
|
80 |
|
|
//Determine if a buffer needs to be incremented
|
81 |
|
|
bool increment[32];
|
82 |
|
|
for(int n = 0; n < 32; n++)
|
83 |
|
|
increment[n] = (count_fwd_packet_sent && last_ro_packet_fwd_unitid.read() == n);
|
84 |
|
|
|
85 |
|
|
//Determine if a buffer overflows
|
86 |
|
|
bool overflow_per_tracker[32];
|
87 |
|
|
for(int n = 0; n < 32; n++)
|
88 |
|
|
overflow_per_tracker[n] = forward_tracker[n].read() == 7 && increment[n];
|
89 |
|
|
|
90 |
|
|
bool overflow = false;
|
91 |
|
|
for(int n = 0; n < 32; n++)
|
92 |
|
|
overflow = overflow || overflow_per_tracker[n];
|
93 |
|
|
|
94 |
|
|
//Set the new value of the counters
|
95 |
|
|
for(int n = 0; n < 32; n++){
|
96 |
|
|
if(overflow) forward_tracker[n] = 0;
|
97 |
|
|
else if(increment[n])forward_tracker[n] = forward_tracker[n].read() + 1;
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
/////////////////////////////////////////
|
101 |
|
|
// Calculate value of 8-bit counter
|
102 |
|
|
/////////////////////////////////////////
|
103 |
|
|
|
104 |
|
|
sc_bv<8> forward_count_p1 = forward_count.read() + 1;
|
105 |
|
|
|
106 |
|
|
if(overflow){
|
107 |
|
|
denominator = forward_count_p1;
|
108 |
|
|
forward_count = 0;
|
109 |
|
|
}
|
110 |
|
|
else if(last_fwd_ack_ro.read()){
|
111 |
|
|
forward_count = forward_count_p1;
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
/////////////////////////////////////////
|
115 |
|
|
// Calculate value of window
|
116 |
|
|
/////////////////////////////////////////
|
117 |
|
|
|
118 |
|
|
//Checks if window is equal to 1 or 0
|
119 |
|
|
bool window_low = window.read().range(5,1) == 0;
|
120 |
|
|
|
121 |
|
|
if(last_fwd_ack_ro.read()){
|
122 |
|
|
if(window_low){
|
123 |
|
|
sc_uint<9> windowx8 = (sc_uint<9>)denominator.read() + lfsr.read().range(2,0);
|
124 |
|
|
window = windowx8.range(8,2);
|
125 |
|
|
}
|
126 |
|
|
else{
|
127 |
|
|
window = window.read() - 1;
|
128 |
|
|
}
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
////////////////////////////////////////////////////////
|
132 |
|
|
// Calculate value of the linear feedback shift register
|
133 |
|
|
////////////////////////////////////////////////////////
|
134 |
|
|
|
135 |
|
|
bool window_cleared = count_fwd_packet_sent && window_low;
|
136 |
|
|
|
137 |
|
|
if(window_cleared){
|
138 |
|
|
sc_uint<9> lfsr_tmp;
|
139 |
|
|
lfsr_tmp.range(7,0) = lfsr.read().range(8,1);
|
140 |
|
|
lfsr_tmp[8] = lfsr.read()[0] ^ lfsr.read()[4];
|
141 |
|
|
lfsr = lfsr_tmp;
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
/////////////////////////////////////////
|
145 |
|
|
// Calculate value of priority bit
|
146 |
|
|
/////////////////////////////////////////
|
147 |
|
|
|
148 |
|
|
if(window_cleared) local_priority = true;
|
149 |
|
|
else if(local_packet_issued.read()) local_priority = false;
|
150 |
|
|
}
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
#ifndef SYSTEMC_SIM
|
154 |
|
|
#include "../core_synth/synth_control_packet.cpp"
|
155 |
|
|
#endif
|
156 |
|
|
|