kernel_stats.cc (9329:3fe8438cbcfc) kernel_stats.cc (10905:a6ca6831e775)
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
32#include <map>
33#include <stack>
34#include <string>
35
36#include "arch/generic/linux/threadinfo.hh"
37#include "arch/alpha/kernel_stats.hh"
38#include "arch/alpha/osfpal.hh"
39#include "base/trace.hh"
40#include "cpu/thread_context.hh"
41#include "debug/Context.hh"
42#include "kern/tru64/tru64_syscalls.hh"
43#include "sim/system.hh"
44
45using namespace std;
46using namespace Stats;
47
48namespace AlphaISA {
49namespace Kernel {
50
51const char *modestr[] = { "kernel", "user", "idle" };
52
53Statistics::Statistics(System *system)
54 : ::Kernel::Statistics(system),
55 idleProcess((Addr)-1), themode(kernel), lastModeTick(0)
56{
57}
58
59void
60Statistics::regStats(const string &_name)
61{
62 ::Kernel::Statistics::regStats(_name);
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
83 .init(cpu_mode_num)
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
99 _modeFraction
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)
106 _modeFraction.subname(i, modestr[i]);
107
108 _modeFraction = _modeGood / _mode;
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
119 _swap_context
120 .name(name() + ".swap_context")
121 .desc("number of times the context was actually changed")
122 ;
123}
124
125void
126Statistics::setIdleProcess(Addr idlepcbb, ThreadContext *tc)
127{
128 assert(themode == kernel);
129 idleProcess = idlepcbb;
130 themode = idle;
131 changeMode(themode, tc);
132}
133
134void
135Statistics::changeMode(cpu_mode newmode, ThreadContext *tc)
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]++;
147 _modeTicks[themode] += curTick() - lastModeTick;
148
149 lastModeTick = curTick();
150 themode = newmode;
151}
152
153void
154Statistics::mode(cpu_mode newmode, ThreadContext *tc)
155{
156 Addr pcbb = tc->readMiscRegNoEffect(IPR_PALtemp23);
157
158 if (newmode == kernel && pcbb == idleProcess)
159 newmode = idle;
160
161 changeMode(newmode, tc);
162}
163
164void
165Statistics::context(Addr oldpcbb, Addr newpcbb, ThreadContext *tc)
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
177void
178Statistics::callpal(int code, ThreadContext *tc)
179{
180 if (!PAL::name(code))
181 return;
182
183 _callpal[code]++;
184
185 switch (code) {
186 case PAL::callsys: {
187 int number = tc->readIntReg(0);
188 if (SystemCalls<Tru64>::validSyscallNumber(number)) {
189 int cvtnum = SystemCalls<Tru64>::convert(number);
190 _syscall[cvtnum]++;
191 }
192 } break;
193 }
194}
195
196void
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
32#include <map>
33#include <stack>
34#include <string>
35
36#include "arch/generic/linux/threadinfo.hh"
37#include "arch/alpha/kernel_stats.hh"
38#include "arch/alpha/osfpal.hh"
39#include "base/trace.hh"
40#include "cpu/thread_context.hh"
41#include "debug/Context.hh"
42#include "kern/tru64/tru64_syscalls.hh"
43#include "sim/system.hh"
44
45using namespace std;
46using namespace Stats;
47
48namespace AlphaISA {
49namespace Kernel {
50
51const char *modestr[] = { "kernel", "user", "idle" };
52
53Statistics::Statistics(System *system)
54 : ::Kernel::Statistics(system),
55 idleProcess((Addr)-1), themode(kernel), lastModeTick(0)
56{
57}
58
59void
60Statistics::regStats(const string &_name)
61{
62 ::Kernel::Statistics::regStats(_name);
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
83 .init(cpu_mode_num)
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
99 _modeFraction
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)
106 _modeFraction.subname(i, modestr[i]);
107
108 _modeFraction = _modeGood / _mode;
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
119 _swap_context
120 .name(name() + ".swap_context")
121 .desc("number of times the context was actually changed")
122 ;
123}
124
125void
126Statistics::setIdleProcess(Addr idlepcbb, ThreadContext *tc)
127{
128 assert(themode == kernel);
129 idleProcess = idlepcbb;
130 themode = idle;
131 changeMode(themode, tc);
132}
133
134void
135Statistics::changeMode(cpu_mode newmode, ThreadContext *tc)
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]++;
147 _modeTicks[themode] += curTick() - lastModeTick;
148
149 lastModeTick = curTick();
150 themode = newmode;
151}
152
153void
154Statistics::mode(cpu_mode newmode, ThreadContext *tc)
155{
156 Addr pcbb = tc->readMiscRegNoEffect(IPR_PALtemp23);
157
158 if (newmode == kernel && pcbb == idleProcess)
159 newmode = idle;
160
161 changeMode(newmode, tc);
162}
163
164void
165Statistics::context(Addr oldpcbb, Addr newpcbb, ThreadContext *tc)
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
177void
178Statistics::callpal(int code, ThreadContext *tc)
179{
180 if (!PAL::name(code))
181 return;
182
183 _callpal[code]++;
184
185 switch (code) {
186 case PAL::callsys: {
187 int number = tc->readIntReg(0);
188 if (SystemCalls<Tru64>::validSyscallNumber(number)) {
189 int cvtnum = SystemCalls<Tru64>::convert(number);
190 _syscall[cvtnum]++;
191 }
192 } break;
193 }
194}
195
196void
197Statistics::serialize(ostream &os)
197Statistics::serialize(CheckpointOut &cp) const
198{
198{
199 ::Kernel::Statistics::serialize(os);
199 ::Kernel::Statistics::serialize(cp);
200 int exemode = themode;
201 SERIALIZE_SCALAR(exemode);
202 SERIALIZE_SCALAR(idleProcess);
203 SERIALIZE_SCALAR(lastModeTick);
204}
205
206void
200 int exemode = themode;
201 SERIALIZE_SCALAR(exemode);
202 SERIALIZE_SCALAR(idleProcess);
203 SERIALIZE_SCALAR(lastModeTick);
204}
205
206void
207Statistics::unserialize(Checkpoint *cp, const string &section)
207Statistics::unserialize(CheckpointIn &cp)
208{
208{
209 ::Kernel::Statistics::unserialize(cp, section);
209 ::Kernel::Statistics::unserialize(cp);
210 int exemode;
211 UNSERIALIZE_SCALAR(exemode);
212 UNSERIALIZE_SCALAR(idleProcess);
213 UNSERIALIZE_SCALAR(lastModeTick);
214 themode = (cpu_mode)exemode;
215}
216
217} // namespace Kernel
218} // namespace AlphaISA
210 int exemode;
211 UNSERIALIZE_SCALAR(exemode);
212 UNSERIALIZE_SCALAR(idleProcess);
213 UNSERIALIZE_SCALAR(lastModeTick);
214 themode = (cpu_mode)exemode;
215}
216
217} // namespace Kernel
218} // namespace AlphaISA