gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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(System *system)
54  : ::Kernel::Statistics(system),
55  idleProcess((Addr)-1), themode(kernel), lastModeTick(0)
56 {
57 }
58 
59 void
60 Statistics::regStats(const string &_name)
61 {
63 
64  _callpal
65  .init(256)
66  .name(name() + ".callpal")
67  .desc("number of callpals executed")
68  .flags(total | pdf | nozero | nonan)
69  ;
70 
71  for (int i = 0; i < PAL::NumCodes; ++i) {
72  const char *str = PAL::name(i);
73  if (str)
74  _callpal.subname(i, str);
75  }
76 
77  _hwrei
78  .name(name() + ".inst.hwrei")
79  .desc("number of hwrei instructions executed")
80  ;
81 
82  _mode
84  .name(name() + ".mode_switch")
85  .desc("number of protection mode switches")
86  ;
87 
88  for (int i = 0; i < cpu_mode_num; ++i)
89  _mode.subname(i, modestr[i]);
90 
91  _modeGood
92  .init(cpu_mode_num)
93  .name(name() + ".mode_good")
94  ;
95 
96  for (int i = 0; i < cpu_mode_num; ++i)
97  _modeGood.subname(i, modestr[i]);
98 
100  .name(name() + ".mode_switch_good")
101  .desc("fraction of useful protection mode switches")
102  .flags(total)
103  ;
104 
105  for (int i = 0; i < cpu_mode_num; ++i)
107 
109 
110  _modeTicks
111  .init(cpu_mode_num)
112  .name(name() + ".mode_ticks")
113  .desc("number of ticks spent at the given mode")
114  .flags(pdf)
115  ;
116  for (int i = 0; i < cpu_mode_num; ++i)
117  _modeTicks.subname(i, modestr[i]);
118 
120  .name(name() + ".swap_context")
121  .desc("number of times the context was actually changed")
122  ;
123 }
124 
125 void
127 {
128  assert(themode == kernel);
129  idleProcess = idlepcbb;
130  themode = idle;
131  changeMode(themode, tc);
132 }
133 
134 void
136 {
137  _mode[newmode]++;
138 
139  if (newmode == themode)
140  return;
141 
142  DPRINTF(Context, "old mode=%s new mode=%s pid=%d\n",
143  modestr[themode], modestr[newmode],
144  Linux::ThreadInfo(tc).curTaskPID());
145 
146  _modeGood[newmode]++;
148 
149  lastModeTick = curTick();
150  themode = newmode;
151 }
152 
153 void
155 {
157 
158  if (newmode == kernel && pcbb == idleProcess)
159  newmode = idle;
160 
161  changeMode(newmode, tc);
162 }
163 
164 void
166 {
167  assert(themode != user);
168 
169  _swap_context++;
170  changeMode(newpcbb == idleProcess ? idle : kernel, tc);
171 
172  DPRINTF(Context, "Context Switch old pid=%d new pid=%d\n",
173  Linux::ThreadInfo(tc, oldpcbb).curTaskPID(),
174  Linux::ThreadInfo(tc, newpcbb).curTaskPID());
175 }
176 
177 void
179 {
180  if (!PAL::name(code))
181  return;
182 
183  _callpal[code]++;
184 }
185 
186 void
188 {
190  int exemode = themode;
191  SERIALIZE_SCALAR(exemode);
194 }
195 
196 void
198 {
200  int exemode;
201  UNSERIALIZE_SCALAR(exemode);
204  themode = (cpu_mode)exemode;
205 }
206 
207 } // namespace Kernel
208 } // namespace AlphaISA
#define DPRINTF(x,...)
Definition: trace.hh:212
const FlagsType pdf
Print the percent of the total that this entry represents.
Definition: info.hh:51
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:358
void mode(cpu_mode newmode, ThreadContext *tc)
Bitfield< 7 > i
Definition: miscregs.hh:1378
void regStats(const std::string &name)
const FlagsType nonan
Don't print if this is NAN.
Definition: info.hh:59
virtual MiscReg readMiscRegNoEffect(int misc_reg) const =0
Definition: system.hh:83
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
Definition: statistics.hh:311
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:1118
void changeMode(cpu_mode newmode, ThreadContext *tc)
void context(Addr oldpcbb, Addr newpcbb, ThreadContext *tc)
const char * modestr[]
Definition: kernel_stats.cc:51
const std::string name() const
Definition: kernel_stats.hh:69
#define UNSERIALIZE_SCALAR(scalar)
Definition: serialize.hh:145
system
Definition: isa.cc:226
Tick curTick()
The current simulated tick.
Definition: core.hh:47
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Stats::Scalar _hwrei
Definition: kernel_stats.hh:54
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:49
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:143
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
Definition: statistics.hh:254
void setIdleProcess(Addr idle, ThreadContext *tc)
std::ostream CheckpointOut
Definition: serialize.hh:67
Derived & desc(const std::string &_desc)
Set the description and marks this stat to print at the end of simulation.
Definition: statistics.hh:287
const FlagsType nozero
Don't print if this is zero.
Definition: info.hh:57
void serialize(CheckpointOut &cp) const override
Serialize an object.

Generated on Fri Jun 9 2017 13:03:35 for gem5 by doxygen 1.8.6