Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | // ========== Copyright Header Begin ========================================== |
2 | // | |
3 | // OpenSPARC T2 Processor File: specweb_traffic_pattern.vr | |
4 | // Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved | |
5 | // 4150 Network Circle, Santa Clara, California 95054, U.S.A. | |
6 | // | |
7 | // * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
8 | // | |
9 | // This program is free software; you can redistribute it and/or modify | |
10 | // it under the terms of the GNU General Public License as published by | |
11 | // the Free Software Foundation; version 2 of the License. | |
12 | // | |
13 | // This program is distributed in the hope that it will be useful, | |
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | // GNU General Public License for more details. | |
17 | // | |
18 | // You should have received a copy of the GNU General Public License | |
19 | // along with this program; if not, write to the Free Software | |
20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | // | |
22 | // For the avoidance of doubt, and except that if any non-GPL license | |
23 | // choice is available it will apply instead, Sun elects to use only | |
24 | // the General Public License version 2 (GPLv2) at this time for any | |
25 | // software where a choice of GPL license versions is made | |
26 | // available with the language indicating that GPLv2 or any later version | |
27 | // may be used, or where a choice of which version of the GPL is applied is | |
28 | // otherwise unspecified. | |
29 | // | |
30 | // Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
31 | // CA 95054 USA or visit www.sun.com if you need additional information or | |
32 | // have any questions. | |
33 | // | |
34 | // ========== Copyright Header End ============================================ | |
35 | #include <vera_defines.vrh> | |
36 | class Cspecweb_traffic_pattern { | |
37 | ||
38 | // Local | |
39 | local string name = "Cspecweb_traffic_pattern"; | |
40 | local integer specweb_rx_ptrns[]; | |
41 | local integer specweb_tx_ptrns[]; | |
42 | local integer debugOn = 0; | |
43 | local integer total_rx_ptrns_wts = 0; | |
44 | local integer total_tx_ptrns_wts = 0; | |
45 | local integer specweb_tx_dist; | |
46 | local string dirn; | |
47 | local task get_ptrn(); | |
48 | ||
49 | // Global | |
50 | function integer get_pkt_len(); | |
51 | task new(string dirnIn) { | |
52 | ||
53 | dirn = dirnIn; | |
54 | get_ptrn(); | |
55 | ||
56 | // RX | |
57 | if(dirn == "RX") { | |
58 | if(assoc_index(CHECK, specweb_rx_ptrns) == 0) { | |
59 | error("<%0d> %s: ERROR : specweb_rx_ptrns array is empty check Rx ptrn file\n", | |
60 | get_time(LO), name); | |
61 | } | |
62 | printf("<%0d> %s: total_rx_ptrns_wts:%0d \n", get_time(LO), name, total_rx_ptrns_wts); | |
63 | } | |
64 | ||
65 | // TX | |
66 | if(dirn == "TX") { | |
67 | if(assoc_index(CHECK, specweb_tx_ptrns) == 0) { | |
68 | error("<%0d> %s: ERROR : specweb_tx_ptrns array is empty check Tx ptrn file\n", | |
69 | get_time(LO), name); | |
70 | } | |
71 | printf("<%0d> %s: total_tx_ptrns_wts:%0d \n", get_time(LO), name, total_tx_ptrns_wts); | |
72 | } | |
73 | } // task new | |
74 | } // class Cspecweb_traffic_pattern | |
75 | ||
76 | function integer Cspecweb_traffic_pattern::get_pkt_len() { | |
77 | integer max_loop = 0, reset_weights = 0, len, loop, size; | |
78 | bit [30:0] rand_num= 0; | |
79 | static integer callerId = 0; | |
80 | integer total_rx_ptrns_wts_local ; | |
81 | integer total_tx_ptrns_wts_local ; | |
82 | if(dirn == "RX") { | |
83 | total_rx_ptrns_wts_local = total_rx_ptrns_wts; | |
84 | // Try getting pkt length SPECWEB_MAX_ITER times | |
85 | size = assoc_index(CHECK, specweb_rx_ptrns); | |
86 | for(loop = 0; loop < size; loop++) { | |
87 | rand_num = random(); | |
88 | rand_num = rand_num % total_rx_ptrns_wts_local; | |
89 | if(specweb_rx_ptrns[loop] > rand_num) { | |
90 | get_pkt_len = loop; | |
91 | //printf("get_pkt_len: Try getting pkt length SPECWEB_MAX_ITER times. id:%0d len:%0d\n", | |
92 | // callerId, get_pkt_len); | |
93 | callerId++; | |
94 | return; | |
95 | } else { | |
96 | total_rx_ptrns_wts_local -= specweb_rx_ptrns[loop]; | |
97 | } | |
98 | } // for | |
99 | } // if | |
100 | ||
101 | // TX | |
102 | if(dirn == "TX") { | |
103 | total_tx_ptrns_wts_local = total_tx_ptrns_wts; | |
104 | // Try getting pkt length SPECWEB_MAX_ITER times | |
105 | size = assoc_index(CHECK, specweb_tx_ptrns); | |
106 | for(loop = 0; loop < size; loop++) { | |
107 | rand_num = random(); | |
108 | rand_num = rand_num % total_tx_ptrns_wts_local; | |
109 | if(specweb_tx_ptrns[loop] > rand_num) { | |
110 | get_pkt_len = loop; | |
111 | //printf("get_pkt_len: Try getting pkt length SPECWEB_MAX_ITER times. id:%0d len:%0d\n", | |
112 | // callerId, get_pkt_len); | |
113 | callerId++; | |
114 | return; | |
115 | } else { | |
116 | total_tx_ptrns_wts_local -= specweb_tx_ptrns[loop]; | |
117 | } | |
118 | } // for | |
119 | } // if | |
120 | } | |
121 | ||
122 | task Cspecweb_traffic_pattern::get_ptrn() { | |
123 | bit [15:0] length; | |
124 | bit [1023:0] pattern_file_bits; | |
125 | string pattern_file; | |
126 | string line, str; | |
127 | integer ptrn_fh; | |
128 | integer tmp_len, tmp_num_pkts; | |
129 | integer id = 0; | |
130 | ||
131 | if(dirn == "RX") { | |
132 | if (get_plus_arg (CHECK,"NIU_TX_RX_PERF_SPECWEB_RX_PATTERN=")) | |
133 | pattern_file_bits = get_plus_arg(STR,"NIU_TX_RX_PERF_SPECWEB_RX_PATTERN="); | |
134 | } | |
135 | if(dirn == "TX") { | |
136 | if (get_plus_arg (CHECK,"NIU_TX_RX_PERF_SPECWEB_TX_PATTERN=")) | |
137 | pattern_file_bits = get_plus_arg(STR,"NIU_TX_RX_PERF_SPECWEB_TX_PATTERN="); | |
138 | } | |
139 | ||
140 | pattern_file.bittostr(pattern_file_bits); | |
141 | printf("<%0d> %s: pattern_file:%s\n", get_time(LO), name, pattern_file); | |
142 | ||
143 | ptrn_fh = fopen(pattern_file, "r"); | |
144 | if(ptrn_fh == 0) { | |
145 | error("<%0d> %s: Can't open input file : ptrn_fh:%s\n", | |
146 | get_time(LO), name, ptrn_fh); | |
147 | } | |
148 | ||
149 | line = freadstr(ptrn_fh, SILENT); | |
150 | while(line !== null) { | |
151 | sscanf (line, "%d%d", tmp_len, tmp_num_pkts); | |
152 | if((tmp_len == id) && (tmp_len <= 9600)) { | |
153 | id++; | |
154 | if(dirn == "RX") { | |
155 | specweb_rx_ptrns[tmp_len] = tmp_num_pkts ; | |
156 | total_rx_ptrns_wts +=tmp_num_pkts ; | |
157 | } | |
158 | if(dirn == "TX") { | |
159 | specweb_tx_ptrns[tmp_len] = tmp_num_pkts; | |
160 | total_tx_ptrns_wts +=tmp_num_pkts ; | |
161 | } | |
162 | if(debugOn) { | |
163 | printf("TESTING: FILE: --%s-- , dirn:%s, tmp_len:%0d tmp_num_pkts:%0d\n", | |
164 | line, dirn, tmp_len, tmp_num_pkts); | |
165 | } | |
166 | } | |
167 | line = freadstr(ptrn_fh, SILENT); | |
168 | } | |
169 | fclose(ptrn_fh); | |
170 | } | |
171 | ||
172 |