kernel_stats.cc revision 11705:d40bdd3c5778
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#include "sim/system.hh"
38
39using namespace std;
40using namespace Stats;
41
42namespace Kernel {
43
44Statistics::Statistics(System *system)
45    : iplLast(0), iplLastTick(0)
46{
47}
48
49void
50Statistics::regStats(const string &_name)
51{
52    myname = _name;
53
54    _arm
55        .name(name() + ".inst.arm")
56        .desc("number of arm instructions executed")
57        ;
58
59    _quiesce
60        .name(name() + ".inst.quiesce")
61        .desc("number of quiesce instructions executed")
62        ;
63
64    _iplCount
65        .init(32)
66        .name(name() + ".ipl_count")
67        .desc("number of times we switched to this ipl")
68        .flags(total | pdf | nozero | nonan)
69        ;
70
71    _iplGood
72        .init(32)
73        .name(name() + ".ipl_good")
74        .desc("number of times we switched to this ipl from a different ipl")
75        .flags(total | pdf | nozero | nonan)
76        ;
77
78    _iplTicks
79        .init(32)
80        .name(name() + ".ipl_ticks")
81        .desc("number of cycles we spent at this ipl")
82        .flags(total | pdf | nozero | nonan)
83        ;
84
85    _iplUsed
86        .name(name() + ".ipl_used")
87        .desc("fraction of swpipl calls that actually changed the ipl")
88        .flags(total | nozero | nonan)
89        ;
90
91    _iplUsed = _iplGood / _iplCount;
92}
93
94void
95Statistics::swpipl(int ipl)
96{
97    assert(ipl >= 0 && ipl <= 0x1f && "invalid IPL\n");
98
99    _iplCount[ipl]++;
100
101    if (ipl == iplLast)
102        return;
103
104    _iplGood[ipl]++;
105    _iplTicks[iplLast] += curTick() - iplLastTick;
106    iplLastTick = curTick();
107    iplLast = ipl;
108}
109
110void
111Statistics::serialize(CheckpointOut &cp) const
112{
113    SERIALIZE_SCALAR(iplLast);
114    SERIALIZE_SCALAR(iplLastTick);
115}
116
117void
118Statistics::unserialize(CheckpointIn &cp)
119{
120    UNSERIALIZE_SCALAR(iplLast);
121    UNSERIALIZE_SCALAR(iplLastTick);
122}
123
124} // namespace Kernel
125