gem5  v22.1.0.0
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 
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
void setDirectory(const std::string &dir)
Sets name of this directory.
Definition: output.cc:164
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:204
double ps
picosecond
Definition: core.cc:57
double us
microsecond
Definition: core.cc:55
double ms
millisecond
Definition: core.cc:54
double ns
nanosecond
Definition: core.cc:56
double Hz
These variables the inverse of above.
Definition: core.cc:59
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
Tick s
second
Definition: core.cc:68
Tick ns
nanosecond
Definition: core.cc:71
Tick ps
picosecond
Definition: core.cc:72
Tick ms
millisecond
Definition: core.cc:69
Tick us
microsecond
Definition: core.cc:70
Tick Frequency
The simulated frequency of curTick(). (In ticks per second)
Definition: core.cc:48
GEM5_DEPRECATED_NAMESPACE(Float, as_float)
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Tick getClockFrequency()
Definition: core.cc:124
void cprintf(const char *format, const Args &...args)
Definition: cprintf.hh:155
bool clockFrequencyFixed()
Definition: core.cc:115
void fixClockFrequency()
Definition: core.cc:87
OutputDirectory simout
Definition: output.cc:62
uint64_t Tick
Tick count type.
Definition: types.hh:58
void setOutputDir(const std::string &dir)
Definition: core.cc:127
CallbackQueue & exitCallbacks()
Queue of C++ callbacks to invoke on simulator exit.
Definition: core.cc:136
void setClockFrequency(Tick tps)
Definition: core.cc:118
void doExitCleanup()
Do C++ simulator exit processing.
Definition: core.cc:156
void registerExitCallback(const std::function< void()> &callback)
Register an exit callback.
Definition: core.cc:146
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)

Generated on Wed Dec 21 2022 10:22:39 for gem5 by doxygen 1.9.1