gem5  v19.0.0.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  * Authors: Nathan Binkert
31  * Steve Reinhardt
32  */
33 
34 #include "sim/core.hh"
35 
36 #include <iostream>
37 #include <string>
38 
39 #include "base/callback.hh"
40 #include "base/cprintf.hh"
41 #include "base/logging.hh"
42 #include "base/output.hh"
43 #include "sim/eventq.hh"
44 
45 using namespace std;
46 
47 namespace SimClock {
50 
51 namespace Float {
52 double s;
53 double ms;
54 double us;
55 double ns;
56 double ps;
57 
58 double Hz;
59 double kHz;
60 double MHz;
61 double GHz;
62 } // namespace Float
63 
64 namespace Int {
70 } // namespace Float
71 
72 } // namespace SimClock
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 SimClock;
90  Frequency = _ticksPerSecond;
91  Float::s = static_cast<double>(Frequency);
92  Float::ms = Float::s / 1.0e3;
93  Float::us = Float::s / 1.0e6;
94  Float::ns = Float::s / 1.0e9;
95  Float::ps = Float::s / 1.0e12;
96 
97  Float::Hz = 1.0 / Float::s;
98  Float::kHz = 1.0 / Float::ms;
99  Float::MHz = 1.0 / Float::us;
100  Float::GHz = 1.0 / Float::ns;
101 
102  Int::s = Frequency;
103  Int::ms = Int::s / 1000;
104  Int::us = Int::ms / 1000;
105  Int::ns = Int::us / 1000;
106  Int::ps = 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 string &dir)
125 {
126  simout.setDirectory(dir);
127 }
128 
132 inline CallbackQueue &
134 {
135  static CallbackQueue theQueue;
136  return theQueue;
137 }
138 
142 void
144 {
145  exitCallbacks().add(callback);
146 }
147 
152 void
154 {
156  exitCallbacks().clear();
157 
158  cout.flush();
159 }
160 
OutputDirectory simout
Definition: output.cc:65
Tick us
microsecond
Definition: core.cc:67
Generic callback class.
Definition: callback.hh:41
Tick ps
picosecond
Definition: core.cc:69
void process()
process all callbacks
Definition: callback.hh:135
void doExitCleanup()
Do C++ simulator exit processing.
Definition: core.cc:153
Tick getClockFrequency()
Definition: core.cc:121
double GHz
GHz.
Definition: core.cc:61
CallbackQueue & exitCallbacks()
Queue of C++ callbacks to invoke on simulator exit.
Definition: core.cc:133
double kHz
kHz
Definition: core.cc:59
void setClockFrequency(Tick tps)
Definition: core.cc:115
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:586
void setDirectory(const std::string &dir)
Sets name of this directory.
Definition: output.cc:160
Tick Frequency
The simulated frequency of curTick(). (In ticks per second)
Definition: core.cc:49
double MHz
MHz.
Definition: core.cc:60
void setOutputDir(const string &dir)
Definition: core.cc:124
These are variables that are set based on the simulator frequency.
Definition: core.cc:47
void add(Callback *callback)
Add a callback to the end of the queue.
Definition: callback.hh:107
uint64_t Tick
Tick count type.
Definition: types.hh:63
bool clockFrequencyFixed()
Definition: core.cc:112
void registerExitCallback(Callback *callback)
Register an exit callback.
Definition: core.cc:143
void fixClockFrequency()
Definition: core.cc:84
Tick s
second
Definition: core.cc:65
Tick ms
millisecond
Definition: core.cc:66
void clear()
clear the callback queue
Definition: callback.hh:150
double Hz
These variables the inverse of above.
Definition: core.cc:58
Tick ns
nanosecond
Definition: core.cc:68
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:185
void cprintf(const char *format, const Args &...args)
Definition: cprintf.hh:156

Generated on Fri Feb 28 2020 16:27:02 for gem5 by doxygen 1.8.13