gem5  v21.1.0.2
core.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006 The Regents of The University of Michigan
3  * Copyright (c) 2013 Advanced Micro Devices, Inc.
4  * Copyright (c) 2013 Mark D. Hill and David A. Wood
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are
9  * met: redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer;
11  * redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution;
14  * neither the name of the copyright holders nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "sim/core.hh"
32 
33 #include <iostream>
34 #include <string>
35 
36 #include "base/callback.hh"
37 #include "base/cprintf.hh"
38 #include "base/logging.hh"
39 #include "base/output.hh"
40 
41 namespace gem5
42 {
43 
44 GEM5_DEPRECATED_NAMESPACE(SimClock, sim_clock);
45 namespace sim_clock
46 {
49 
50 GEM5_DEPRECATED_NAMESPACE(Float, as_float);
51 namespace as_float
52 {
53 double s;
54 double ms;
55 double us;
56 double ns;
57 double ps;
58 
59 double Hz;
60 double kHz;
61 double MHz;
62 double GHz;
63 } // namespace as_float
64 
65 GEM5_DEPRECATED_NAMESPACE(Int, as_int);
66 namespace as_int
67 {
73 } // namespace as_float
74 
75 } // namespace sim_clock
76 
77 namespace {
78 
79 bool _clockFrequencyFixed = false;
80 
81 // Default to 1 THz (1 Tick == 1 ps)
82 Tick _ticksPerSecond = 1e12;
83 
84 } // anonymous namespace
85 
86 void
88 {
89  if (_clockFrequencyFixed)
90  return;
91 
92  using namespace sim_clock;
93  Frequency = _ticksPerSecond;
94  as_float::s = static_cast<double>(Frequency);
95  as_float::ms = as_float::s / 1.0e3;
96  as_float::us = as_float::s / 1.0e6;
97  as_float::ns = as_float::s / 1.0e9;
98  as_float::ps = as_float::s / 1.0e12;
99 
100  as_float::Hz = 1.0 / as_float::s;
101  as_float::kHz = 1.0 / as_float::ms;
102  as_float::MHz = 1.0 / as_float::us;
103  as_float::GHz = 1.0 / as_float::ns;
104 
106  as_int::ms = as_int::s / 1000;
107  as_int::us = as_int::ms / 1000;
108  as_int::ns = as_int::us / 1000;
109  as_int::ps = as_int::ns / 1000;
110 
111  cprintf("Global frequency set at %d ticks per second\n", _ticksPerSecond);
112 
113  _clockFrequencyFixed = true;
114 }
115 bool clockFrequencyFixed() { return _clockFrequencyFixed; }
116 
117 void
119 {
120  panic_if(_clockFrequencyFixed,
121  "Global frequency already fixed at %f ticks/s.", _ticksPerSecond);
122  _ticksPerSecond = tps;
123 }
124 Tick getClockFrequency() { return _ticksPerSecond; }
125 
126 void
127 setOutputDir(const std::string &dir)
128 {
129  simout.setDirectory(dir);
130 }
131 
135 inline CallbackQueue &
137 {
138  static CallbackQueue theQueue;
139  return theQueue;
140 }
141 
145 void
146 registerExitCallback(const std::function<void()> &callback)
147 {
148  exitCallbacks().push_back(callback);
149 }
150 
155 void
157 {
159  exitCallbacks().clear();
160 
161  std::cout.flush();
162 }
163 
164 } // namespace gem5
gem5::CallbackQueue
Definition: callback.hh:38
gem5::cprintf
void cprintf(const char *format, const Args &...args)
Definition: cprintf.hh:155
gem5::sim_clock::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(Float, as_float)
gem5::sim_clock::as_float::us
double us
microsecond
Definition: core.cc:55
gem5::simout
OutputDirectory simout
Definition: output.cc:62
gem5::sim_clock::Frequency
Tick Frequency
The simulated frequency of curTick(). (In ticks per second)
Definition: core.cc:48
gem5::sim_clock::as_int::us
Tick us
microsecond
Definition: core.cc:70
gem5::sim_clock::as_int::s
Tick s
second
Definition: core.cc:68
gem5::sim_clock::as_float::Hz
double Hz
These variables the inverse of above.
Definition: core.cc:59
output.hh
gem5::doExitCleanup
void doExitCleanup()
Do C++ simulator exit processing.
Definition: core.cc:156
gem5::exitCallbacks
CallbackQueue & exitCallbacks()
Queue of C++ callbacks to invoke on simulator exit.
Definition: core.cc:136
gem5::sim_clock::as_float::GHz
double GHz
GHz.
Definition: core.cc:62
gem5::getClockFrequency
Tick getClockFrequency()
Definition: core.cc:124
gem5::sim_clock::as_int::ps
Tick ps
picosecond
Definition: core.cc:72
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::OutputDirectory::setDirectory
void setDirectory(const std::string &dir)
Sets name of this directory.
Definition: output.cc:164
gem5::sim_clock::as_float::ns
double ns
nanosecond
Definition: core.cc:56
gem5::sim_clock::as_float::ps
double ps
picosecond
Definition: core.cc:57
gem5::clockFrequencyFixed
bool clockFrequencyFixed()
Definition: core.cc:115
cprintf.hh
gem5::sim_clock::as_float::ms
double ms
millisecond
Definition: core.cc:54
gem5::fixClockFrequency
void fixClockFrequency()
Definition: core.cc:87
core.hh
gem5::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:203
gem5::setOutputDir
void setOutputDir(const std::string &dir)
Definition: core.cc:127
gem5::sim_clock::as_float::kHz
double kHz
kHz
Definition: core.cc:60
gem5::setClockFrequency
void setClockFrequency(Tick tps)
Definition: core.cc:118
logging.hh
gem5::registerExitCallback
void registerExitCallback(const std::function< void()> &callback)
Register an exit callback.
Definition: core.cc:146
gem5::sim_clock::as_int::ms
Tick ms
millisecond
Definition: core.cc:69
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::CallbackQueue::process
void process()
Definition: callback.hh:49
callback.hh
gem5::sim_clock::as_float::MHz
double MHz
MHz.
Definition: core.cc:61
gem5::sim_clock::as_float::s
double s
These variables equal the number of ticks in the unit of time they're named after in a double.
Definition: core.cc:53
gem5::sim_clock::as_int::ns
Tick ns
nanosecond
Definition: core.cc:71

Generated on Tue Sep 21 2021 12:25:47 for gem5 by doxygen 1.8.17