gem5  v19.0.0.0
kernel_stats.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004-2005 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  * Authors: Lisa Hsu
29  * Nathan Binkert
30  */
31 
33 
34 #include <map>
35 #include <stack>
36 #include <string>
37 
38 #include "arch/alpha/osfpal.hh"
40 #include "base/trace.hh"
41 #include "cpu/thread_context.hh"
42 #include "debug/Context.hh"
43 #include "sim/system.hh"
44 
45 using namespace std;
46 using namespace Stats;
47 
48 namespace AlphaISA {
49 namespace Kernel {
50 
51 const char *modestr[] = { "kernel", "user", "idle" };
52 
53 Statistics::Statistics()
54  : ::Kernel::Statistics(),
55  idleProcess((Addr)-1), themode(kernel), lastModeTick(0),
56  iplLast(0), iplLastTick(0)
57 {
58 }
59 
60 void
61 Statistics::regStats(const string &_name)
62 {
64 
65  _callpal
66  .init(256)
67  .name(name() + ".callpal")
68  .desc("number of callpals executed")
69  .flags(total | pdf | nozero | nonan)
70  ;
71 
72  for (int i = 0; i < PAL::NumCodes; ++i) {
73  const char *str = PAL::name(i);
74  if (str)
75  _callpal.subname(i, str);
76  }
77 
78  _hwrei
79  .name(name() + ".inst.hwrei")
80  .desc("number of hwrei instructions executed")
81  ;
82 
83  _mode
85  .name(name() + ".mode_switch")
86  .desc("number of protection mode switches")
87  ;
88 
89  for (int i = 0; i < cpu_mode_num; ++i)
90  _mode.subname(i, modestr[i]);
91 
92  _modeGood
93  .init(cpu_mode_num)
94  .name(name() + ".mode_good")
95  ;
96 
97  for (int i = 0; i < cpu_mode_num; ++i)
98  _modeGood.subname(i, modestr[i]);
99 
101  .name(name() + ".mode_switch_good")
102  .desc("fraction of useful protection mode switches")
103  .flags(total)
104  ;
105 
106  for (int i = 0; i < cpu_mode_num; ++i)
107  _modeFraction.subname(i, modestr[i]);
108 
110 
111  _modeTicks
112  .init(cpu_mode_num)
113  .name(name() + ".mode_ticks")
114  .desc("number of ticks spent at the given mode")
115  .flags(pdf)
116  ;
117  for (int i = 0; i < cpu_mode_num; ++i)
118  _modeTicks.subname(i, modestr[i]);
119 
121  .name(name() + ".swap_context")
122  .desc("number of times the context was actually changed")
123  ;
124 
125  _iplCount
126  .init(32)
127  .name(name() + ".ipl_count")
128  .desc("number of times we switched to this ipl")
129  .flags(total | pdf | nozero | nonan)
130  ;
131 
132  _iplGood
133  .init(32)
134  .name(name() + ".ipl_good")
135  .desc("number of times we switched to this ipl from a different ipl")
136  .flags(total | pdf | nozero | nonan)
137  ;
138 
139  _iplTicks
140  .init(32)
141  .name(name() + ".ipl_ticks")
142  .desc("number of cycles we spent at this ipl")
143  .flags(total | pdf | nozero | nonan)
144  ;
145 
146  _iplUsed
147  .name(name() + ".ipl_used")
148  .desc("fraction of swpipl calls that actually changed the ipl")
149  .flags(total | nozero | nonan)
150  ;
151 
153 }
154 
155 void
157 {
158  assert(themode == kernel);
159  idleProcess = idlepcbb;
160  themode = idle;
161  changeMode(themode, tc);
162 }
163 
164 void
166 {
167  _mode[newmode]++;
168 
169  if (newmode == themode)
170  return;
171 
172  DPRINTF(Context, "old mode=%s new mode=%s pid=%d\n",
173  modestr[themode], modestr[newmode],
174  Linux::ThreadInfo(tc).curTaskPID());
175 
176  _modeGood[newmode]++;
178 
179  lastModeTick = curTick();
180  themode = newmode;
181 }
182 
183 void
185 {
187 
188  if (newmode == kernel && pcbb == idleProcess)
189  newmode = idle;
190 
191  changeMode(newmode, tc);
192 }
193 
194 void
196 {
197  assert(themode != user);
198 
199  _swap_context++;
200  changeMode(newpcbb == idleProcess ? idle : kernel, tc);
201 
202  DPRINTF(Context, "Context Switch old pid=%d new pid=%d\n",
203  Linux::ThreadInfo(tc, oldpcbb).curTaskPID(),
204  Linux::ThreadInfo(tc, newpcbb).curTaskPID());
205 }
206 
207 void
209 {
210  if (!PAL::name(code))
211  return;
212 
213  _callpal[code]++;
214 }
215 
216 void
218 {
219  assert(ipl >= 0 && ipl <= 0x1f && "invalid IPL\n");
220 
221  _iplCount[ipl]++;
222 
223  if (ipl == iplLast)
224  return;
225 
226  _iplGood[ipl]++;
228  iplLastTick = curTick();
229  iplLast = ipl;
230 }
231 
232 void
234 {
236  int exemode = themode;
237  SERIALIZE_SCALAR(exemode);
242 }
243 
244 void
246 {
248  int exemode;
249  UNSERIALIZE_SCALAR(exemode);
252  themode = (cpu_mode)exemode;
255 }
256 
257 } // namespace Kernel
258 } // namespace AlphaISA
#define DPRINTF(x,...)
Definition: trace.hh:229
const FlagsType pdf
Print the percent of the total that this entry represents.
Definition: info.hh:53
Derived & subname(off_type index, const std::string &name)
Set the subfield name for the given index, and marks this stat to print at the end of simulation...
Definition: statistics.hh:379
void mode(cpu_mode newmode, ThreadContext *tc)
Bitfield< 7 > i
const FlagsType nonan
Don&#39;t print if this is NAN.
Definition: info.hh:61
void regStats(const std::string &name) override
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:586
Definition: cprintf.cc:42
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
Definition: statistics.hh:336
ThreadContext is the external interface to all thread state for anything outside of the CPU...
Derived & init(size_type size)
Set this vector to have the given size.
Definition: statistics.hh:1152
void changeMode(cpu_mode newmode, ThreadContext *tc)
void context(Addr oldpcbb, Addr newpcbb, ThreadContext *tc)
const char * modestr[]
Definition: kernel_stats.cc:51
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:645
Tick curTick()
The current simulated tick.
Definition: core.hh:47
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void callpal(int code, ThreadContext *tc)
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
static const char * name(int index)
Definition: osfpal.cc:34
const FlagsType total
Print the total.
Definition: info.hh:51
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:643
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
Definition: statistics.hh:279
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
const std::string name() const
Definition: kernel_stats.hh:55
void setIdleProcess(Addr idle, ThreadContext *tc)
std::ostream CheckpointOut
Definition: serialize.hh:68
Derived & desc(const std::string &_desc)
Set the description and marks this stat to print at the end of simulation.
Definition: statistics.hh:312
Bitfield< 15, 10 > ipl
const FlagsType nozero
Don&#39;t print if this is zero.
Definition: info.hh:59
void serialize(CheckpointOut &cp) const override
Serialize an object.

Generated on Fri Feb 28 2020 16:26:56 for gem5 by doxygen 1.8.13