remote_gdb.cc:
[gem5.git] / base / sat_counter.cc
1 /*
2 * Copyright (c) 2003 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sstream>
30
31 #include "base/sat_counter.hh"
32
33 #include "base/statistics.hh"
34 #include "sim/sim_stats.hh"
35
36
37 using namespace std;
38
39
40 SaturatingCounterPred::SaturatingCounterPred(string p_name,
41 string z_name,
42 string o_name,
43 unsigned _index_bits,
44 unsigned _counter_bits,
45 unsigned _zero_change,
46 unsigned _one_change,
47 unsigned _thresh,
48 unsigned _init_value)
49 {
50 pred_name = p_name;
51 zero_name = z_name;
52 one_name = o_name;
53
54 index_bits = _index_bits;
55 counter_bits = _counter_bits;
56 zero_change = _zero_change;
57 one_change = _one_change;
58 thresh = _thresh;
59 init_value = _init_value;
60
61 max_index = (1 << index_bits) - 1;
62 max_value = (1 << counter_bits) - 1;
63
64 table = new unsigned[max_index + 1];
65
66 // Initialize with the right parameters & clear the counter
67 for (int i = 0; i <= max_index; ++i)
68 table[i] = init_value;
69 }
70
71 void SaturatingCounterPred::regStats()
72 {
73 using namespace Statistics;
74 stringstream name, description;
75
76 //
77 // Number of predictions
78 //
79 name << pred_name << ":" << zero_name << ":preds";
80 description << "number of predictions of " << zero_name;
81 predicted_zero
82 .name(name.str())
83 .desc(description.str())
84 ;
85 description.str("");
86 name.str("");
87
88 name << pred_name << ":" << one_name << ":preds";
89 description << "number of predictions of " << one_name;
90 predicted_one
91 .name(name.str())
92 .desc(description.str())
93 ;
94 description.str("");
95 name.str("");
96
97 //
98 // Count the number of correct predictions
99 //
100 name << pred_name << ":" << zero_name << ":corr_preds";
101 description << "number of correct " << zero_name << " preds";
102 correct_pred_zero
103 .name(name.str())
104 .desc(description.str())
105 ;
106 description.str("");
107 name.str("");
108
109 name << pred_name << ":" << one_name << ":corr_preds";
110 description << "number of correct " << one_name << " preds";
111 correct_pred_one
112 .name(name.str())
113 .desc(description.str())
114 ;
115 description.str("");
116 name.str("");
117
118 //
119 // Number of predictor updates
120 //
121 name << pred_name << ":" << zero_name << ":updates";
122 description << "number of actual " << zero_name << "s";
123 record_zero
124 .name(name.str())
125 .desc(description.str())
126 ;
127 description.str("");
128 name.str("");
129
130 name << pred_name << ":" << one_name << ":updates";
131 description << "number of actual " << one_name << "s";
132 record_one
133 .name(name.str())
134 .desc(description.str())
135 ;
136 description.str("");
137 name.str("");
138 }
139
140 void SaturatingCounterPred::regFormulas()
141 {
142 using namespace Statistics;
143 stringstream name, description;
144
145 //
146 // Number of predictions
147 //
148 name << pred_name << ":predictions";
149 preds_total
150 .name(name.str())
151 .desc("total number of predictions made")
152 ;
153 preds_total = predicted_zero + predicted_one;
154 name.str("");
155
156 //
157 // Fraction of all predictions that are one or zero
158 //
159 name << pred_name << ":" << zero_name << ":pred_frac";
160 description << "fraction of all preds that were " << zero_name;
161 pred_frac_zero
162 .name(name.str())
163 .desc(description.str())
164 ;
165 pred_frac_zero = 100 * predicted_zero / preds_total;
166 description.str("");
167 name.str("");
168
169 name << pred_name << ":" << one_name << ":pred_frac";
170 description << "fraction of all preds that were " << one_name;
171 pred_frac_one
172 .name(name.str())
173 .desc(description.str())
174 ;
175 pred_frac_one = 100 * predicted_one / preds_total;
176 description.str("");
177 name.str("");
178
179
180 //
181 // Count the number of correct predictions
182 //
183 name << pred_name << ":correct_preds";
184 correct_total
185 .name(name.str())
186 .desc("total correct predictions made")
187 ;
188 correct_total = correct_pred_one + correct_pred_zero;
189 name.str("");
190
191 //
192 // Number of predictor updates
193 //
194 name << pred_name << ":updates";
195 updates_total
196 .name(name.str())
197 .desc("total number of updates")
198 ;
199 updates_total = record_zero + record_one;
200 name.str("");
201
202 //
203 // Prediction accuracy rates
204 //
205 name << pred_name << ":pred_rate";
206 pred_rate
207 .name(name.str())
208 .desc("correct fraction of all preds")
209 ;
210 pred_rate = correct_total / updates_total;
211 name.str("");
212
213 name << pred_name << ":" << zero_name << ":pred_rate";
214 description << "fraction of " << zero_name << " preds that were correct";
215 frac_correct_zero
216 .name(name.str())
217 .desc(description.str())
218 ;
219 frac_correct_zero = 100 * correct_pred_zero /
220 (correct_pred_zero + record_one - correct_pred_one);
221 description.str("");
222 name.str("");
223
224 name << pred_name << ":" << one_name << ":pred_rate";
225 description << "fraction of " << one_name << " preds that were correct";
226 frac_correct_one
227 .name(name.str())
228 .desc(description.str())
229 ;
230 frac_correct_one = 100 * correct_pred_one /
231 (correct_pred_one + record_zero - correct_pred_zero);
232 description.str("");
233 name.str("");
234
235 //
236 // Coverage
237 //
238 name << pred_name << ":" << zero_name << ":coverage";
239 description << "fraction of " << zero_name
240 << "s that were predicted correctly";
241 coverage_zero
242 .name(name.str())
243 .desc(description.str())
244 ;
245 coverage_zero = 100 * correct_pred_zero / record_zero;
246 description.str("");
247 name.str("");
248
249 name << pred_name << ":" << one_name << ":coverage";
250 description << "fraction of " << one_name
251 << "s that were predicted correctly";
252 coverage_one
253 .name(name.str())
254 .desc(description.str())
255 ;
256 coverage_one = 100 * correct_pred_one / record_one;
257 description.str("");
258 name.str("");
259 }
260
261
262
263
264
265
266
267
268
269