kernel_stats.cc (5568:d14250d688d2) kernel_stats.cc (7823:dac01f14f20f)
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/alpha/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 "kern/tru64/tru64_syscalls.hh"
42#include "sim/system.hh"
43
44using namespace std;
45using namespace Stats;
46
47namespace AlphaISA {
48namespace Kernel {
49
50const char *modestr[] = { "kernel", "user", "idle" };
51
52Statistics::Statistics(System *system)
53 : ::Kernel::Statistics(system),
54 idleProcess((Addr)-1), themode(kernel), lastModeTick(0)
55{
56}
57
58void
59Statistics::regStats(const string &_name)
60{
61 ::Kernel::Statistics::regStats(_name);
62
63 _callpal
64 .init(256)
65 .name(name() + ".callpal")
66 .desc("number of callpals executed")
67 .flags(total | pdf | nozero | nonan)
68 ;
69
70 for (int i = 0; i < PAL::NumCodes; ++i) {
71 const char *str = PAL::name(i);
72 if (str)
73 _callpal.subname(i, str);
74 }
75
76 _hwrei
77 .name(name() + ".inst.hwrei")
78 .desc("number of hwrei instructions executed")
79 ;
80
81 _mode
82 .init(cpu_mode_num)
83 .name(name() + ".mode_switch")
84 .desc("number of protection mode switches")
85 ;
86
87 for (int i = 0; i < cpu_mode_num; ++i)
88 _mode.subname(i, modestr[i]);
89
90 _modeGood
91 .init(cpu_mode_num)
92 .name(name() + ".mode_good")
93 ;
94
95 for (int i = 0; i < cpu_mode_num; ++i)
96 _modeGood.subname(i, modestr[i]);
97
98 _modeFraction
99 .name(name() + ".mode_switch_good")
100 .desc("fraction of useful protection mode switches")
101 .flags(total)
102 ;
103
104 for (int i = 0; i < cpu_mode_num; ++i)
105 _modeFraction.subname(i, modestr[i]);
106
107 _modeFraction = _modeGood / _mode;
108
109 _modeTicks
110 .init(cpu_mode_num)
111 .name(name() + ".mode_ticks")
112 .desc("number of ticks spent at the given mode")
113 .flags(pdf)
114 ;
115 for (int i = 0; i < cpu_mode_num; ++i)
116 _modeTicks.subname(i, modestr[i]);
117
118 _swap_context
119 .name(name() + ".swap_context")
120 .desc("number of times the context was actually changed")
121 ;
122}
123
124void
125Statistics::setIdleProcess(Addr idlepcbb, ThreadContext *tc)
126{
127 assert(themode == kernel);
128 idleProcess = idlepcbb;
129 themode = idle;
130 changeMode(themode, tc);
131}
132
133void
134Statistics::changeMode(cpu_mode newmode, ThreadContext *tc)
135{
136 _mode[newmode]++;
137
138 if (newmode == themode)
139 return;
140
141 DPRINTF(Context, "old mode=%s new mode=%s pid=%d\n",
142 modestr[themode], modestr[newmode],
143 Linux::ThreadInfo(tc).curTaskPID());
144
145 _modeGood[newmode]++;
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/alpha/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 "kern/tru64/tru64_syscalls.hh"
42#include "sim/system.hh"
43
44using namespace std;
45using namespace Stats;
46
47namespace AlphaISA {
48namespace Kernel {
49
50const char *modestr[] = { "kernel", "user", "idle" };
51
52Statistics::Statistics(System *system)
53 : ::Kernel::Statistics(system),
54 idleProcess((Addr)-1), themode(kernel), lastModeTick(0)
55{
56}
57
58void
59Statistics::regStats(const string &_name)
60{
61 ::Kernel::Statistics::regStats(_name);
62
63 _callpal
64 .init(256)
65 .name(name() + ".callpal")
66 .desc("number of callpals executed")
67 .flags(total | pdf | nozero | nonan)
68 ;
69
70 for (int i = 0; i < PAL::NumCodes; ++i) {
71 const char *str = PAL::name(i);
72 if (str)
73 _callpal.subname(i, str);
74 }
75
76 _hwrei
77 .name(name() + ".inst.hwrei")
78 .desc("number of hwrei instructions executed")
79 ;
80
81 _mode
82 .init(cpu_mode_num)
83 .name(name() + ".mode_switch")
84 .desc("number of protection mode switches")
85 ;
86
87 for (int i = 0; i < cpu_mode_num; ++i)
88 _mode.subname(i, modestr[i]);
89
90 _modeGood
91 .init(cpu_mode_num)
92 .name(name() + ".mode_good")
93 ;
94
95 for (int i = 0; i < cpu_mode_num; ++i)
96 _modeGood.subname(i, modestr[i]);
97
98 _modeFraction
99 .name(name() + ".mode_switch_good")
100 .desc("fraction of useful protection mode switches")
101 .flags(total)
102 ;
103
104 for (int i = 0; i < cpu_mode_num; ++i)
105 _modeFraction.subname(i, modestr[i]);
106
107 _modeFraction = _modeGood / _mode;
108
109 _modeTicks
110 .init(cpu_mode_num)
111 .name(name() + ".mode_ticks")
112 .desc("number of ticks spent at the given mode")
113 .flags(pdf)
114 ;
115 for (int i = 0; i < cpu_mode_num; ++i)
116 _modeTicks.subname(i, modestr[i]);
117
118 _swap_context
119 .name(name() + ".swap_context")
120 .desc("number of times the context was actually changed")
121 ;
122}
123
124void
125Statistics::setIdleProcess(Addr idlepcbb, ThreadContext *tc)
126{
127 assert(themode == kernel);
128 idleProcess = idlepcbb;
129 themode = idle;
130 changeMode(themode, tc);
131}
132
133void
134Statistics::changeMode(cpu_mode newmode, ThreadContext *tc)
135{
136 _mode[newmode]++;
137
138 if (newmode == themode)
139 return;
140
141 DPRINTF(Context, "old mode=%s new mode=%s pid=%d\n",
142 modestr[themode], modestr[newmode],
143 Linux::ThreadInfo(tc).curTaskPID());
144
145 _modeGood[newmode]++;
146 _modeTicks[themode] += curTick - lastModeTick;
146 _modeTicks[themode] += curTick() - lastModeTick;
147
147
148 lastModeTick = curTick;
148 lastModeTick = curTick();
149 themode = newmode;
150}
151
152void
153Statistics::mode(cpu_mode newmode, ThreadContext *tc)
154{
155 Addr pcbb = tc->readMiscRegNoEffect(IPR_PALtemp23);
156
157 if (newmode == kernel && pcbb == idleProcess)
158 newmode = idle;
159
160 changeMode(newmode, tc);
161}
162
163void
164Statistics::context(Addr oldpcbb, Addr newpcbb, ThreadContext *tc)
165{
166 assert(themode != user);
167
168 _swap_context++;
169 changeMode(newpcbb == idleProcess ? idle : kernel, tc);
170
171 DPRINTF(Context, "Context Switch old pid=%d new pid=%d\n",
172 Linux::ThreadInfo(tc, oldpcbb).curTaskPID(),
173 Linux::ThreadInfo(tc, newpcbb).curTaskPID());
174}
175
176void
177Statistics::callpal(int code, ThreadContext *tc)
178{
179 if (!PAL::name(code))
180 return;
181
182 _callpal[code]++;
183
184 switch (code) {
185 case PAL::callsys: {
186 int number = tc->readIntReg(0);
187 if (SystemCalls<Tru64>::validSyscallNumber(number)) {
188 int cvtnum = SystemCalls<Tru64>::convert(number);
189 _syscall[cvtnum]++;
190 }
191 } break;
192 }
193}
194
195void
196Statistics::serialize(ostream &os)
197{
198 ::Kernel::Statistics::serialize(os);
199 int exemode = themode;
200 SERIALIZE_SCALAR(exemode);
201 SERIALIZE_SCALAR(idleProcess);
202 SERIALIZE_SCALAR(lastModeTick);
203}
204
205void
206Statistics::unserialize(Checkpoint *cp, const string &section)
207{
208 ::Kernel::Statistics::unserialize(cp, section);
209 int exemode;
210 UNSERIALIZE_SCALAR(exemode);
211 UNSERIALIZE_SCALAR(idleProcess);
212 UNSERIALIZE_SCALAR(lastModeTick);
213 themode = (cpu_mode)exemode;
214}
215
216} // namespace Kernel
217} // namespace AlphaISA
149 themode = newmode;
150}
151
152void
153Statistics::mode(cpu_mode newmode, ThreadContext *tc)
154{
155 Addr pcbb = tc->readMiscRegNoEffect(IPR_PALtemp23);
156
157 if (newmode == kernel && pcbb == idleProcess)
158 newmode = idle;
159
160 changeMode(newmode, tc);
161}
162
163void
164Statistics::context(Addr oldpcbb, Addr newpcbb, ThreadContext *tc)
165{
166 assert(themode != user);
167
168 _swap_context++;
169 changeMode(newpcbb == idleProcess ? idle : kernel, tc);
170
171 DPRINTF(Context, "Context Switch old pid=%d new pid=%d\n",
172 Linux::ThreadInfo(tc, oldpcbb).curTaskPID(),
173 Linux::ThreadInfo(tc, newpcbb).curTaskPID());
174}
175
176void
177Statistics::callpal(int code, ThreadContext *tc)
178{
179 if (!PAL::name(code))
180 return;
181
182 _callpal[code]++;
183
184 switch (code) {
185 case PAL::callsys: {
186 int number = tc->readIntReg(0);
187 if (SystemCalls<Tru64>::validSyscallNumber(number)) {
188 int cvtnum = SystemCalls<Tru64>::convert(number);
189 _syscall[cvtnum]++;
190 }
191 } break;
192 }
193}
194
195void
196Statistics::serialize(ostream &os)
197{
198 ::Kernel::Statistics::serialize(os);
199 int exemode = themode;
200 SERIALIZE_SCALAR(exemode);
201 SERIALIZE_SCALAR(idleProcess);
202 SERIALIZE_SCALAR(lastModeTick);
203}
204
205void
206Statistics::unserialize(Checkpoint *cp, const string &section)
207{
208 ::Kernel::Statistics::unserialize(cp, section);
209 int exemode;
210 UNSERIALIZE_SCALAR(exemode);
211 UNSERIALIZE_SCALAR(idleProcess);
212 UNSERIALIZE_SCALAR(lastModeTick);
213 themode = (cpu_mode)exemode;
214}
215
216} // namespace Kernel
217} // namespace AlphaISA