gem5  v20.1.0.0
timer.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef __CPU_KVM_TIMER_HH__
39 #define __CPU_KVM_TIMER_HH__
40 
41 #include <ctime>
42 
43 #include "cpu/kvm/perfevent.hh"
44 #include "sim/core.hh"
45 
61 {
62  public:
72  : signo(signo), _resolution(0),
74  virtual ~BaseKvmTimer() {};
75 
88  virtual void arm(Tick ticks) = 0;
95  virtual void disarm() = 0;
96  virtual bool expired() {
97  return true;
98  }
99 
108  if (_resolution == 0)
110  return _resolution;
111  }
112 
120  Tick ticksFromHostCycles(uint64_t cycles) {
121  return cycles * hostFactor * hostFreq;
122  }
123 
131  Tick ticksFromHostNs(uint64_t ns) {
132  return ns * hostFactor * SimClock::Float::ns;
133  }
134 
135  protected:
142  virtual Tick calcResolution() = 0;
143 
149  uint64_t hostNs(Tick ticks) {
150  return ticks / (SimClock::Float::ns * hostFactor);
151  }
152 
159  uint64_t hostCycles(Tick ticks) {
160  return ticks / (hostFreq * hostFactor);
161  }
162 
164  int signo;
165 
166  private:
168  mutable Tick _resolution;
169 
171  float hostFactor;
174 };
175 
185 {
186  public:
193  PosixKvmTimer(int signo, clockid_t clockID,
194  float hostFactor, Tick hostFreq);
195  ~PosixKvmTimer();
196 
197  void arm(Tick ticks) override;
198  void disarm() override;
199  bool expired() override;
200 
201  protected:
202  Tick calcResolution() override;
203 
204  private:
205  clockid_t clockID;
206  timer_t timer;
207  struct itimerspec prevTimerSpec;
208 };
209 
219 {
220  public:
236  int signo,
237  float hostFactor, Tick hostFreq);
238  ~PerfKvmTimer();
239 
240  void arm(Tick ticks);
241  void disarm();
242 
243  protected:
245 
246  private:
248 };
249 
250 #endif
BaseKvmTimer::expired
virtual bool expired()
Definition: timer.hh:96
PerfKvmTimer::arm
void arm(Tick ticks)
Arm the timer so that it fires after a certain number of ticks.
Definition: timer.cc:181
PerfKvmCounter
An instance of a performance counter.
Definition: perfevent.hh:168
PosixKvmTimer::timer
timer_t timer
Definition: timer.hh:206
ArmISA::ns
Bitfield< 0 > ns
Definition: miscregs_types.hh:328
BaseKvmTimer::disarm
virtual void disarm()=0
Disarm the timer.
PerfKvmTimer::disarm
void disarm()
Disarm the timer.
Definition: timer.cc:188
BaseKvmTimer::arm
virtual void arm(Tick ticks)=0
Arm the timer so that it fires after a certain number of ticks.
PosixKvmTimer::~PosixKvmTimer
~PosixKvmTimer()
Definition: timer.cc:94
BaseKvmTimer::ticksFromHostNs
Tick ticksFromHostNs(uint64_t ns)
Convert nanoseconds executed on the host into Ticks executed in the simulator.
Definition: timer.hh:131
BaseKvmTimer::ticksFromHostCycles
Tick ticksFromHostCycles(uint64_t cycles)
Convert cycles executed on the host into Ticks executed in the simulator.
Definition: timer.hh:120
PerfKvmTimer::~PerfKvmTimer
~PerfKvmTimer()
Definition: timer.cc:176
PosixKvmTimer::arm
void arm(Tick ticks) override
Arm the timer so that it fires after a certain number of ticks.
Definition: timer.cc:100
BaseKvmTimer::hostNs
uint64_t hostNs(Tick ticks)
Convert a time in simulator ticks to host nanoseconds.
Definition: timer.hh:149
PerfKvmTimer::PerfKvmTimer
PerfKvmTimer(PerfKvmCounter &ctr, int signo, float hostFactor, Tick hostFreq)
Create a timer that uses an existing hardware cycle counter.
Definition: timer.cc:168
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
BaseKvmTimer::~BaseKvmTimer
virtual ~BaseKvmTimer()
Definition: timer.hh:74
BaseKvmTimer::calcResolution
virtual Tick calcResolution()=0
Calculate the timer resolution, used by resolution() which caches the result.
PosixKvmTimer::prevTimerSpec
struct itimerspec prevTimerSpec
Definition: timer.hh:207
PosixKvmTimer::disarm
void disarm() override
Disarm the timer.
Definition: timer.cc:120
PerfKvmTimer::calcResolution
Tick calcResolution()
Calculate the timer resolution, used by resolution() which caches the result.
Definition: timer.cc:194
BaseKvmTimer::signo
int signo
Signal to deliver when the timer times out.
Definition: timer.hh:164
SimClock::Float::ns
double ns
nanosecond
Definition: core.cc:52
PosixKvmTimer::PosixKvmTimer
PosixKvmTimer(int signo, clockid_t clockID, float hostFactor, Tick hostFreq)
Definition: timer.cc:76
PosixKvmTimer::calcResolution
Tick calcResolution() override
Calculate the timer resolution, used by resolution() which caches the result.
Definition: timer.cc:141
core.hh
perfevent.hh
BaseKvmTimer::BaseKvmTimer
BaseKvmTimer(int signo, float hostFactor, Tick hostFreq)
Setup basic timer functionality shared by all timer implementations.
Definition: timer.hh:71
BaseKvmTimer
Timer functions to interrupt VM execution after a number of simulation ticks.
Definition: timer.hh:60
PosixKvmTimer::clockID
clockid_t clockID
Definition: timer.hh:205
BaseKvmTimer::resolution
Tick resolution()
Determine the resolution of the timer in ticks.
Definition: timer.hh:107
PosixKvmTimer::expired
bool expired() override
Definition: timer.cc:134
PerfKvmTimer::hwOverflow
PerfKvmCounter & hwOverflow
Definition: timer.hh:247
PosixKvmTimer
Timer based on standard POSIX timers.
Definition: timer.hh:184
BaseKvmTimer::_resolution
Tick _resolution
Cached resolution.
Definition: timer.hh:168
BaseKvmTimer::hostFreq
Tick hostFreq
Host frequency.
Definition: timer.hh:173
BaseKvmTimer::hostFactor
float hostFactor
Performance scaling factor.
Definition: timer.hh:171
BaseKvmTimer::hostCycles
uint64_t hostCycles(Tick ticks)
Convert a time in simulator ticks to host cycles.
Definition: timer.hh:159
PerfKvmTimer
PerfEvent based timer using the host's CPU cycle counter.
Definition: timer.hh:218

Generated on Wed Sep 30 2020 14:02:08 for gem5 by doxygen 1.8.17