gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  * Authors: Andreas Sandberg
38  */
39 
40 #ifndef __CPU_KVM_TIMER_HH__
41 #define __CPU_KVM_TIMER_HH__
42 
43 #include <ctime>
44 
45 #include "cpu/kvm/perfevent.hh"
46 #include "sim/core.hh"
47 
63 {
64  public:
74  : signo(signo), _resolution(0),
75  hostFactor(hostFactor), hostFreq(hostFreq) {};
76  virtual ~BaseKvmTimer() {};
77 
90  virtual void arm(Tick ticks) = 0;
97  virtual void disarm() = 0;
98 
107  if (_resolution == 0)
109  return _resolution;
110  }
111 
119  Tick ticksFromHostCycles(uint64_t cycles) {
120  return cycles * hostFactor * hostFreq;
121  }
122 
130  Tick ticksFromHostNs(uint64_t ns) {
131  return ns * hostFactor * SimClock::Float::ns;
132  }
133 
134  protected:
141  virtual Tick calcResolution() = 0;
142 
148  uint64_t hostNs(Tick ticks) {
149  return ticks / (SimClock::Float::ns * hostFactor);
150  }
151 
158  uint64_t hostCycles(Tick ticks) {
159  return ticks / (hostFreq * hostFactor);
160  }
161 
163  int signo;
164 
165  private:
167  mutable Tick _resolution;
168 
170  float hostFactor;
173 };
174 
184 {
185  public:
192  PosixKvmTimer(int signo, clockid_t clockID,
193  float hostFactor, Tick hostFreq);
194  ~PosixKvmTimer();
195 
196  void arm(Tick ticks);
197  void disarm();
198 
199  protected:
201 
202  private:
203  clockid_t clockID;
204  timer_t timer;
205 };
206 
216 {
217  public:
233  int signo,
234  float hostFactor, Tick hostFreq);
235  ~PerfKvmTimer();
236 
237  void arm(Tick ticks);
238  void disarm();
239 
240  protected:
242 
243  private:
245 };
246 
247 #endif
PerfKvmCounter & hwOverflow
Definition: timer.hh:244
clockid_t clockID
Definition: timer.hh:203
virtual Tick calcResolution()=0
Calculate the timer resolution, used by resolution() which caches the result.
Tick hostFreq
Host frequency.
Definition: timer.hh:172
void arm(Tick ticks)
Arm the timer so that it fires after a certain number of ticks.
Definition: timer.cc:102
PosixKvmTimer(int signo, clockid_t clockID, float hostFactor, Tick hostFreq)
Definition: timer.cc:78
Tick resolution()
Determine the resolution of the timer in ticks.
Definition: timer.hh:106
double ns
nanosecond
Definition: core.cc:53
timer_t timer
Definition: timer.hh:204
uint64_t hostNs(Tick ticks)
Convert a time in simulator ticks to host nanoseconds.
Definition: timer.hh:148
float hostFactor
Performance scaling factor.
Definition: timer.hh:170
Bitfield< 0 > ns
Definition: miscregs.hh:1521
Tick _resolution
Cached resolution.
Definition: timer.hh:167
uint64_t hostCycles(Tick ticks)
Convert a time in simulator ticks to host cycles.
Definition: timer.hh:158
uint64_t Tick
Tick count type.
Definition: types.hh:63
void disarm()
Disarm the timer.
Definition: timer.cc:181
void disarm()
Disarm the timer.
Definition: timer.cc:122
An instance of a performance counter.
Definition: perfevent.hh:170
Tick ticksFromHostCycles(uint64_t cycles)
Convert cycles executed on the host into Ticks executed in the simulator.
Definition: timer.hh:119
virtual void arm(Tick ticks)=0
Arm the timer so that it fires after a certain number of ticks.
Tick ticksFromHostNs(uint64_t ns)
Convert nanoseconds executed on the host into Ticks executed in the simulator.
Definition: timer.hh:130
Tick calcResolution()
Calculate the timer resolution, used by resolution() which caches the result.
Definition: timer.cc:187
virtual ~BaseKvmTimer()
Definition: timer.hh:76
void arm(Tick ticks)
Arm the timer so that it fires after a certain number of ticks.
Definition: timer.cc:174
Tick calcResolution()
Calculate the timer resolution, used by resolution() which caches the result.
Definition: timer.cc:134
Timer functions to interrupt VM execution after a number of simulation ticks.
Definition: timer.hh:62
~PosixKvmTimer()
Definition: timer.cc:96
virtual void disarm()=0
Disarm the timer.
BaseKvmTimer(int signo, float hostFactor, Tick hostFreq)
Setup basic timer functionality shared by all timer implementations.
Definition: timer.hh:73
Timer based on standard POSIX timers.
Definition: timer.hh:183
PerfEvent based timer using the host's CPU cycle counter.
Definition: timer.hh:215
int signo
Signal to deliver when the timer times out.
Definition: timer.hh:163
~PerfKvmTimer()
Definition: timer.cc:169
PerfKvmTimer(PerfKvmCounter &ctr, int signo, float hostFactor, Tick hostFreq)
Create a timer that uses an existing hardware cycle counter.
Definition: timer.cc:161

Generated on Fri Jun 9 2017 13:03:42 for gem5 by doxygen 1.8.6