gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
41namespace gem5
42{
43
44namespace sim_clock
45{
48
49namespace as_float
50{
51double s;
52double ms;
53double us;
54double ns;
55double ps;
56
57double Hz;
58double kHz;
59double MHz;
60double GHz;
61} // namespace as_float
62
63namespace as_int
64{
70} // namespace as_float
71
72} // namespace sim_clock
73
74namespace {
75
76bool _clockFrequencyFixed = false;
77
78// Default to 1 THz (1 Tick == 1 ps)
79Tick _ticksPerSecond = 1e12;
80
81} // anonymous namespace
82
83void
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;
98 as_float::kHz = 1.0 / as_float::ms;
99 as_float::MHz = 1.0 / as_float::us;
100 as_float::GHz = 1.0 / as_float::ns;
101
102 as_int::s = Frequency;
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}
112bool clockFrequencyFixed() { return _clockFrequencyFixed; }
113
114void
116{
117 panic_if(_clockFrequencyFixed,
118 "Global frequency already fixed at %f ticks/s.", _ticksPerSecond);
119 _ticksPerSecond = tps;
120}
121Tick getClockFrequency() { return _ticksPerSecond; }
122
123void
124setOutputDir(const std::string &dir)
125{
126 simout.setDirectory(dir);
127}
128
132inline CallbackQueue &
134{
135 static CallbackQueue theQueue;
136 return theQueue;
137}
138
142void
143registerExitCallback(const std::function<void()> &callback)
144{
145 exitCallbacks().push_back(callback);
146}
147
152void
154{
156 exitCallbacks().clear();
157
158 std::cout.flush();
159}
160
161} // 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:214
double ps
picosecond
Definition core.cc:55
double us
microsecond
Definition core.cc:53
double ms
millisecond
Definition core.cc:52
double ns
nanosecond
Definition core.cc:54
double Hz
These variables the inverse of above.
Definition core.cc:57
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
Tick ns
nanosecond
Definition core.cc:68
Tick ps
picosecond
Definition core.cc:69
Tick ms
millisecond
Definition core.cc:66
Tick us
microsecond
Definition core.cc:67
Tick Frequency
The simulated frequency of curTick(). (In ticks per second)
Definition core.cc:47
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
Tick getClockFrequency()
Definition core.cc:121
CallbackQueue & exitCallbacks()
Queue of C++ callbacks to invoke on simulator exit.
Definition core.cc:133
void cprintf(const char *format, const Args &...args)
Definition cprintf.hh:155
bool clockFrequencyFixed()
Definition core.cc:112
void fixClockFrequency()
Definition core.cc:84
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:124
void setClockFrequency(Tick tps)
Definition core.cc:115
void doExitCleanup()
Do C++ simulator exit processing.
Definition core.cc:153
void registerExitCallback(const std::function< void()> &callback)
Register an exit callback.
Definition core.cc:143

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0