gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 namespace sim_clock
45 {
48 
49 namespace as_float
50 {
51 double s;
52 double ms;
53 double us;
54 double ns;
55 double ps;
56 
57 double Hz;
58 double kHz;
59 double MHz;
60 double GHz;
61 } // namespace as_float
62 
63 namespace as_int
64 {
70 } // namespace as_float
71 
72 } // namespace sim_clock
73 
74 namespace {
75 
76 bool _clockFrequencyFixed = false;
77 
78 // Default to 1 THz (1 Tick == 1 ps)
79 Tick _ticksPerSecond = 1e12;
80 
81 } // anonymous namespace
82 
83 void
85 {
86  if (_clockFrequencyFixed)
87  return;
88 
89  using namespace sim_clock;
90  Frequency = _ticksPerSecond;
91  as_float::s = static_cast<double>(Frequency);
92  as_float::ms = as_float::s / 1.0e3;
93  as_float::us = as_float::s / 1.0e6;
94  as_float::ns = as_float::s / 1.0e9;
95  as_float::ps = as_float::s / 1.0e12;
96 
97  as_float::Hz = 1.0 / as_float::s;
100  as_float::GHz = 1.0 / as_float::ns;
101 
103  as_int::ms = as_int::s / 1000;
104  as_int::us = as_int::ms / 1000;
105  as_int::ns = as_int::us / 1000;
106  as_int::ps = as_int::ns / 1000;
107 
108  cprintf("Global frequency set at %d ticks per second\n", _ticksPerSecond);
109 
110  _clockFrequencyFixed = true;
111 }
112 bool clockFrequencyFixed() { return _clockFrequencyFixed; }
113 
114 void
116 {
117  panic_if(_clockFrequencyFixed,
118  "Global frequency already fixed at %f ticks/s.", _ticksPerSecond);
119  _ticksPerSecond = tps;
120 }
121 Tick getClockFrequency() { return _ticksPerSecond; }
122 
123 void
124 setOutputDir(const std::string &dir)
125 {
126  simout.setDirectory(dir);
127 }
128 
132 inline CallbackQueue &
134 {
135  static CallbackQueue theQueue;
136  return theQueue;
137 }
138 
142 void
143 registerExitCallback(const std::function<void()> &callback)
144 {
145  exitCallbacks().push_back(callback);
146 }
147 
152 void
154 {
156  exitCallbacks().clear();
157 
158  std::cout.flush();
159 }
160 
161 } // 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::as_float::us
double us
microsecond
Definition: core.cc:53
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:47
gem5::sim_clock::as_int::us
Tick us
microsecond
Definition: core.cc:67
gem5::sim_clock::as_int::s
Tick s
second
Definition: core.cc:65
gem5::sim_clock::as_float::Hz
double Hz
These variables the inverse of above.
Definition: core.cc:57
output.hh
gem5::doExitCleanup
void doExitCleanup()
Do C++ simulator exit processing.
Definition: core.cc:153
gem5::exitCallbacks
CallbackQueue & exitCallbacks()
Queue of C++ callbacks to invoke on simulator exit.
Definition: core.cc:133
gem5::sim_clock::as_float::GHz
double GHz
GHz.
Definition: core.cc:60
gem5::getClockFrequency
Tick getClockFrequency()
Definition: core.cc:121
gem5::sim_clock::as_int::ps
Tick ps
picosecond
Definition: core.cc:69
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:54
gem5::sim_clock::as_float::ps
double ps
picosecond
Definition: core.cc:55
gem5::clockFrequencyFixed
bool clockFrequencyFixed()
Definition: core.cc:112
cprintf.hh
gem5::sim_clock::as_float::ms
double ms
millisecond
Definition: core.cc:52
gem5::fixClockFrequency
void fixClockFrequency()
Definition: core.cc:84
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:214
gem5::setOutputDir
void setOutputDir(const std::string &dir)
Definition: core.cc:124
gem5::sim_clock::as_float::kHz
double kHz
kHz
Definition: core.cc:58
core.hh
gem5::setClockFrequency
void setClockFrequency(Tick tps)
Definition: core.cc:115
logging.hh
gem5::registerExitCallback
void registerExitCallback(const std::function< void()> &callback)
Register an exit callback.
Definition: core.cc:143
gem5::sim_clock::as_int::ms
Tick ms
millisecond
Definition: core.cc:66
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::CallbackQueue::process
void process()
Definition: callback.hh:49
callback.hh
gem5::sim_clock::as_float::MHz
double MHz
MHz.
Definition: core.cc:59
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:51
gem5::sim_clock::as_int::ns
Tick ns
nanosecond
Definition: core.cc:68

Generated on Sun Jul 30 2023 01:56:59 for gem5 by doxygen 1.8.17