/*
* Copyright (c) 2006 The Regents of The University of Michigan
+ * Copyright (c) 2013 Advanced Micro Devices, Inc.
+ * Copyright (c) 2013 Mark D. Hill and David A. Wood
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* Steve Reinhardt
*/
+#include "sim/core.hh"
+
#include <iostream>
#include <string>
#include "base/callback.hh"
+#include "base/cprintf.hh"
+#include "base/logging.hh"
#include "base/output.hh"
-#include "sim/core.hh"
+#include "sim/eventq.hh"
using namespace std;
-Tick curTick = 0;
-
-namespace Clock {
-/// The simulated frequency of curTick. (In ticks per second)
+namespace SimClock {
+/// The simulated frequency of curTick(). (In ticks per second)
Tick Frequency;
namespace Float {
double Hz;
double kHz;
double MHz;
-double GHZ;
-/* namespace Float */ }
+double GHz;
+} // namespace Float
namespace Int {
Tick s;
Tick us;
Tick ns;
Tick ps;
-/* namespace Float */ }
+} // namespace Float
+
+} // namespace SimClock
+
+namespace {
+
+bool _clockFrequencyFixed = false;
+
+// Default to 1 THz (1 Tick == 1 ps)
+Tick _ticksPerSecond = 1e12;
-/* namespace Clock */ }
+} // anonymous namespace
void
-setClockFrequency(Tick ticksPerSecond)
+fixClockFrequency()
{
- using namespace Clock;
- Frequency = ticksPerSecond;
+ if (_clockFrequencyFixed)
+ return;
+
+ using namespace SimClock;
+ Frequency = _ticksPerSecond;
Float::s = static_cast<double>(Frequency);
Float::ms = Float::s / 1.0e3;
Float::us = Float::s / 1.0e6;
Float::Hz = 1.0 / Float::s;
Float::kHz = 1.0 / Float::ms;
Float::MHz = 1.0 / Float::us;
- Float::GHZ = 1.0 / Float::ns;
+ Float::GHz = 1.0 / Float::ns;
Int::s = Frequency;
Int::ms = Int::s / 1000;
Int::ns = Int::us / 1000;
Int::ps = Int::ns / 1000;
+ cprintf("Global frequency set at %d ticks per second\n", _ticksPerSecond);
+
+ _clockFrequencyFixed = true;
}
+bool clockFrequencyFixed() { return _clockFrequencyFixed; }
void
-setOutputDir(const string &dir)
+setClockFrequency(Tick tps)
{
- simout.setDirectory(dir);
+ panic_if(_clockFrequencyFixed,
+ "Global frequency already fixed at %f ticks/s.", _ticksPerSecond);
+ _ticksPerSecond = tps;
}
-
-ostream *outputStream;
-ostream *configStream;
+Tick getClockFrequency() { return _ticksPerSecond; }
void
-setOutputFile(const string &file)
+setOutputDir(const string &dir)
{
- outputStream = simout.find(file);
+ simout.setDirectory(dir);
}
/**
}
/**
- * Do C++ simulator exit processing. Exported to SWIG to be invoked
+ * Do C++ simulator exit processing. Exported to Python to be invoked
* when simulator terminates via Python's atexit mechanism.
*/
void