kernel_stats.cc revision 8777
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 <string>
33
34#include "base/trace.hh"
35#include "cpu/thread_context.hh"
36#include "kern/kernel_stats.hh"
37#if THE_ISA == ALPHA_ISA
38#include "kern/tru64/tru64_syscalls.hh"
39#endif
40#include "sim/system.hh"
41
42using namespace std;
43using namespace Stats;
44
45namespace Kernel {
46
47Statistics::Statistics(System *system)
48    : iplLast(0), iplLastTick(0)
49{
50}
51
52void
53Statistics::regStats(const string &_name)
54{
55    myname = _name;
56
57    _arm
58        .name(name() + ".inst.arm")
59        .desc("number of arm instructions executed")
60        ;
61
62    _quiesce
63        .name(name() + ".inst.quiesce")
64        .desc("number of quiesce instructions executed")
65        ;
66
67    _iplCount
68        .init(32)
69        .name(name() + ".ipl_count")
70        .desc("number of times we switched to this ipl")
71        .flags(total | pdf | nozero | nonan)
72        ;
73
74    _iplGood
75        .init(32)
76        .name(name() + ".ipl_good")
77        .desc("number of times we switched to this ipl from a different ipl")
78        .flags(total | pdf | nozero | nonan)
79        ;
80
81    _iplTicks
82        .init(32)
83        .name(name() + ".ipl_ticks")
84        .desc("number of cycles we spent at this ipl")
85        .flags(total | pdf | nozero | nonan)
86        ;
87
88    _iplUsed
89        .name(name() + ".ipl_used")
90        .desc("fraction of swpipl calls that actually changed the ipl")
91        .flags(total | nozero | nonan)
92        ;
93
94    _iplUsed = _iplGood / _iplCount;
95#if THE_ISA == ALPHA_ISA
96    _syscall
97        .init(SystemCalls<Tru64>::Number)
98        .name(name() + ".syscall")
99        .desc("number of syscalls executed")
100        .flags(total | pdf | nozero | nonan)
101        ;
102#endif
103
104    //@todo This needs to get the names of syscalls from an appropriate place.
105#if 0
106    for (int i = 0; i < SystemCalls<Tru64>::Number; ++i) {
107        const char *str = SystemCalls<Tru64>::name(i);
108        if (str) {
109            _syscall.subname(i, str);
110        }
111    }
112#endif
113}
114
115void
116Statistics::swpipl(int ipl)
117{
118    assert(ipl >= 0 && ipl <= 0x1f && "invalid IPL\n");
119
120    _iplCount[ipl]++;
121
122    if (ipl == iplLast)
123        return;
124
125    _iplGood[ipl]++;
126    _iplTicks[iplLast] += curTick() - iplLastTick;
127    iplLastTick = curTick();
128    iplLast = ipl;
129}
130
131void
132Statistics::serialize(ostream &os)
133{
134    SERIALIZE_SCALAR(iplLast);
135    SERIALIZE_SCALAR(iplLastTick);
136}
137
138void
139Statistics::unserialize(Checkpoint *cp, const string &section)
140{
141    UNSERIALIZE_SCALAR(iplLast);
142    UNSERIALIZE_SCALAR(iplLastTick);
143}
144
145} // namespace Kernel
146