gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
46namespace gem5
47{
48
64{
65 public:
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
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:
172
177};
178
188{
189 public:
196 PosixKvmTimer(int signo, clockid_t clockID,
197 float hostFactor, Tick hostFreq);
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);
242
243 void arm(Tick ticks);
244 void disarm();
245
246 protected:
248
249 private:
251};
252
253} // namespace gem5
254
255#endif
Timer functions to interrupt VM execution after a number of simulation ticks.
Definition timer.hh:64
Tick ticksFromHostNs(uint64_t ns)
Convert nanoseconds executed on the host into Ticks executed in the simulator.
Definition timer.hh:134
uint64_t hostCycles(Tick ticks)
Convert a time in simulator ticks to host cycles.
Definition timer.hh:162
BaseKvmTimer(int signo, float hostFactor, Tick hostFreq)
Setup basic timer functionality shared by all timer implementations.
Definition timer.hh:74
Tick hostFreq
Host frequency.
Definition timer.hh:176
Tick resolution()
Determine the resolution of the timer in ticks.
Definition timer.hh:110
int signo
Signal to deliver when the timer times out.
Definition timer.hh:167
Tick _resolution
Cached resolution.
Definition timer.hh:171
virtual Tick calcResolution()=0
Calculate the timer resolution, used by resolution() which caches the result.
uint64_t hostNs(Tick ticks)
Convert a time in simulator ticks to host nanoseconds.
Definition timer.hh:152
Tick ticksFromHostCycles(uint64_t cycles)
Convert cycles executed on the host into Ticks executed in the simulator.
Definition timer.hh:123
virtual void disarm()=0
Disarm the timer.
virtual bool expired()
Definition timer.hh:99
virtual ~BaseKvmTimer()
Definition timer.hh:77
virtual void arm(Tick ticks)=0
Arm the timer so that it fires after a certain number of ticks.
float hostFactor
Performance scaling factor.
Definition timer.hh:174
An instance of a performance counter.
Definition perfevent.hh:172
PerfEvent based timer using the host's CPU cycle counter.
Definition timer.hh:222
Tick calcResolution()
Calculate the timer resolution, used by resolution() which caches the result.
Definition timer.cc:197
void disarm()
Disarm the timer.
Definition timer.cc:191
PerfKvmCounter & hwOverflow
Definition timer.hh:250
PerfKvmTimer(PerfKvmCounter &ctr, int signo, float hostFactor, Tick hostFreq)
Create a timer that uses an existing hardware cycle counter.
Definition timer.cc:171
void arm(Tick ticks)
Arm the timer so that it fires after a certain number of ticks.
Definition timer.cc:184
Timer based on standard POSIX timers.
Definition timer.hh:188
bool expired() override
Definition timer.cc:137
clockid_t clockID
Definition timer.hh:208
void arm(Tick ticks) override
Arm the timer so that it fires after a certain number of ticks.
Definition timer.cc:103
PosixKvmTimer(int signo, clockid_t clockID, float hostFactor, Tick hostFreq)
Definition timer.cc:79
Tick calcResolution() override
Calculate the timer resolution, used by resolution() which caches the result.
Definition timer.cc:144
struct itimerspec prevTimerSpec
Definition timer.hh:210
void disarm() override
Disarm the timer.
Definition timer.cc:123
Bitfield< 0 > ns
double ns
nanosecond
Definition core.cc:54
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t Tick
Tick count type.
Definition types.hh:58

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