gem5  v21.1.0.2
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 
46 namespace gem5
47 {
48 
64 {
65  public:
75  : signo(signo), _resolution(0),
77  virtual ~BaseKvmTimer() {};
78 
91  virtual void arm(Tick ticks) = 0;
98  virtual void disarm() = 0;
99  virtual bool expired() {
100  return true;
101  }
102 
111  if (_resolution == 0)
113  return _resolution;
114  }
115 
123  Tick ticksFromHostCycles(uint64_t cycles) {
124  return cycles * hostFactor * hostFreq;
125  }
126 
134  Tick ticksFromHostNs(uint64_t ns) {
136  }
137 
138  protected:
145  virtual Tick calcResolution() = 0;
146 
152  uint64_t hostNs(Tick ticks) {
153  return ticks / (sim_clock::as_float::ns * hostFactor);
154  }
155 
162  uint64_t hostCycles(Tick ticks) {
163  return ticks / (hostFreq * hostFactor);
164  }
165 
167  int signo;
168 
169  private:
171  mutable Tick _resolution;
172 
174  float hostFactor;
177 };
178 
188 {
189  public:
196  PosixKvmTimer(int signo, clockid_t clockID,
197  float hostFactor, Tick hostFreq);
198  ~PosixKvmTimer();
199 
200  void arm(Tick ticks) override;
201  void disarm() override;
202  bool expired() override;
203 
204  protected:
205  Tick calcResolution() override;
206 
207  private:
208  clockid_t clockID;
209  timer_t timer;
210  struct itimerspec prevTimerSpec;
211 };
212 
222 {
223  public:
239  int signo,
240  float hostFactor, Tick hostFreq);
241  ~PerfKvmTimer();
242 
243  void arm(Tick ticks);
244  void disarm();
245 
246  protected:
248 
249  private:
251 };
252 
253 } // namespace gem5
254 
255 #endif
gem5::BaseKvmTimer::hostFactor
float hostFactor
Performance scaling factor.
Definition: timer.hh:174
gem5::BaseKvmTimer::BaseKvmTimer
BaseKvmTimer(int signo, float hostFactor, Tick hostFreq)
Setup basic timer functionality shared by all timer implementations.
Definition: timer.hh:74
gem5::PerfKvmTimer::PerfKvmTimer
PerfKvmTimer(PerfKvmCounter &ctr, int signo, float hostFactor, Tick hostFreq)
Create a timer that uses an existing hardware cycle counter.
Definition: timer.cc:171
gem5::PosixKvmTimer::prevTimerSpec
struct itimerspec prevTimerSpec
Definition: timer.hh:210
gem5::PerfKvmTimer::disarm
void disarm()
Disarm the timer.
Definition: timer.cc:191
gem5::BaseKvmTimer::ticksFromHostCycles
Tick ticksFromHostCycles(uint64_t cycles)
Convert cycles executed on the host into Ticks executed in the simulator.
Definition: timer.hh:123
gem5::PosixKvmTimer::arm
void arm(Tick ticks) override
Arm the timer so that it fires after a certain number of ticks.
Definition: timer.cc:103
gem5::PosixKvmTimer::expired
bool expired() override
Definition: timer.cc:137
gem5::PerfKvmCounter
An instance of a performance counter.
Definition: perfevent.hh:171
gem5::BaseKvmTimer::expired
virtual bool expired()
Definition: timer.hh:99
gem5::PerfKvmTimer::calcResolution
Tick calcResolution()
Calculate the timer resolution, used by resolution() which caches the result.
Definition: timer.cc:197
gem5::ArmISA::ns
Bitfield< 0 > ns
Definition: misc_types.hh:331
gem5::PosixKvmTimer::disarm
void disarm() override
Disarm the timer.
Definition: timer.cc:123
gem5::BaseKvmTimer::calcResolution
virtual Tick calcResolution()=0
Calculate the timer resolution, used by resolution() which caches the result.
gem5::PerfKvmTimer::~PerfKvmTimer
~PerfKvmTimer()
Definition: timer.cc:179
gem5::BaseKvmTimer::~BaseKvmTimer
virtual ~BaseKvmTimer()
Definition: timer.hh:77
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::sim_clock::as_float::ns
double ns
nanosecond
Definition: core.cc:56
gem5::BaseKvmTimer::_resolution
Tick _resolution
Cached resolution.
Definition: timer.hh:171
gem5::BaseKvmTimer::hostFreq
Tick hostFreq
Host frequency.
Definition: timer.hh:176
gem5::PosixKvmTimer::calcResolution
Tick calcResolution() override
Calculate the timer resolution, used by resolution() which caches the result.
Definition: timer.cc:144
core.hh
gem5::BaseKvmTimer::arm
virtual void arm(Tick ticks)=0
Arm the timer so that it fires after a certain number of ticks.
gem5::BaseKvmTimer::disarm
virtual void disarm()=0
Disarm the timer.
perfevent.hh
gem5::PerfKvmTimer
PerfEvent based timer using the host's CPU cycle counter.
Definition: timer.hh:221
gem5::PerfKvmTimer::arm
void arm(Tick ticks)
Arm the timer so that it fires after a certain number of ticks.
Definition: timer.cc:184
gem5::PosixKvmTimer::PosixKvmTimer
PosixKvmTimer(int signo, clockid_t clockID, float hostFactor, Tick hostFreq)
Definition: timer.cc:79
gem5::BaseKvmTimer::hostNs
uint64_t hostNs(Tick ticks)
Convert a time in simulator ticks to host nanoseconds.
Definition: timer.hh:152
gem5::BaseKvmTimer
Timer functions to interrupt VM execution after a number of simulation ticks.
Definition: timer.hh:63
gem5::PosixKvmTimer
Timer based on standard POSIX timers.
Definition: timer.hh:187
gem5::BaseKvmTimer::signo
int signo
Signal to deliver when the timer times out.
Definition: timer.hh:167
gem5::PosixKvmTimer::clockID
clockid_t clockID
Definition: timer.hh:208
gem5::PerfKvmTimer::hwOverflow
PerfKvmCounter & hwOverflow
Definition: timer.hh:250
gem5::BaseKvmTimer::ticksFromHostNs
Tick ticksFromHostNs(uint64_t ns)
Convert nanoseconds executed on the host into Ticks executed in the simulator.
Definition: timer.hh:134
gem5::PosixKvmTimer::timer
timer_t timer
Definition: timer.hh:209
gem5::BaseKvmTimer::hostCycles
uint64_t hostCycles(Tick ticks)
Convert a time in simulator ticks to host cycles.
Definition: timer.hh:162
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::BaseKvmTimer::resolution
Tick resolution()
Determine the resolution of the timer in ticks.
Definition: timer.hh:110
gem5::PosixKvmTimer::~PosixKvmTimer
~PosixKvmTimer()
Definition: timer.cc:97

Generated on Tue Sep 21 2021 12:25:00 for gem5 by doxygen 1.8.17