base.hh (10407:a9023811bf9e) base.hh (10653:e3fc6bc7f97e)
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_BASE_HH__
41#define __CPU_KVM_BASE_HH__
42
43#include <pthread.h>
44
45#include <csignal>
46#include <memory>
47
48#include "base/statistics.hh"
49#include "cpu/kvm/perfevent.hh"
50#include "cpu/kvm/timer.hh"
51#include "cpu/kvm/vm.hh"
52#include "cpu/base.hh"
53#include "cpu/simple_thread.hh"
54
55/** Signal to use to trigger exits from KVM */
56#define KVM_KICK_SIGNAL SIGRTMIN
57
58// forward declarations
59class ThreadContext;
60struct BaseKvmCPUParams;
61
62/**
63 * Base class for KVM based CPU models
64 *
65 * All architecture specific KVM implementation should inherit from
66 * this class. The most basic CPU models only need to override the
67 * updateKvmState() and updateThreadContext() methods to implement
68 * state synchronization between gem5 and KVM.
69 *
70 * The architecture specific implementation is also responsible for
71 * delivering interrupts into the VM. This is typically done by
72 * overriding tick() and checking the thread context before entering
73 * into the VM. In order to deliver an interrupt, the implementation
74 * then calls KvmVM::setIRQLine() or BaseKvmCPU::kvmInterrupt()
75 * depending on the specifics of the underlying hardware/drivers.
76 */
77class BaseKvmCPU : public BaseCPU
78{
79 public:
80 BaseKvmCPU(BaseKvmCPUParams *params);
81 virtual ~BaseKvmCPU();
82
83 void init();
84 void startup();
85 void regStats();
86
87 void serializeThread(std::ostream &os, ThreadID tid);
88 void unserializeThread(Checkpoint *cp, const std::string &section,
89 ThreadID tid);
90
91 unsigned int drain(DrainManager *dm);
92 void drainResume();
93
94 void switchOut();
95 void takeOverFrom(BaseCPU *cpu);
96
97 void verifyMemoryMode() const;
98
99 MasterPort &getDataPort() { return dataPort; }
100 MasterPort &getInstPort() { return instPort; }
101
102 void wakeup();
103 void activateContext(ThreadID thread_num);
104 void suspendContext(ThreadID thread_num);
105 void deallocateContext(ThreadID thread_num);
106 void haltContext(ThreadID thread_num);
107
108 ThreadContext *getContext(int tn);
109
110 Counter totalInsts() const;
111 Counter totalOps() const;
112
113 /** Dump the internal state to the terminal. */
114 virtual void dump();
115
116 /**
117 * Force an exit from KVM.
118 *
119 * Send a signal to the thread owning this vCPU to get it to exit
120 * from KVM. Ignored if the vCPU is not executing.
121 */
122 void kick() const { pthread_kill(vcpuThread, KVM_KICK_SIGNAL); }
123
124 /**
125 * A cached copy of a thread's state in the form of a SimpleThread
126 * object.
127 *
128 * Normally the actual thread state is stored in the KVM vCPU. If KVM has
129 * been running this copy is will be out of date. If we recently handled
130 * some events within gem5 that required state to be updated this could be
131 * the most up-to-date copy. When getContext() or updateThreadContext() is
132 * called this copy gets updated. The method syncThreadContext can
133 * be used within a KVM CPU to update the thread context if the
134 * KVM state is dirty (i.e., the vCPU has been run since the last
135 * update).
136 */
137 SimpleThread *thread;
138
139 /** ThreadContext object, provides an interface for external
140 * objects to modify this thread's state.
141 */
142 ThreadContext *tc;
143
144 KvmVM &vm;
145
146 protected:
147 /**
148 *
149 * @dot
150 * digraph {
151 * Idle;
152 * Running;
153 * RunningService;
154 * RunningServiceCompletion;
155 *
156 * Idle -> Idle;
157 * Idle -> Running [label="activateContext()", URL="\ref activateContext"];
158 * Running -> Running [label="tick()", URL="\ref tick"];
159 * Running -> RunningService [label="tick()", URL="\ref tick"];
160 * Running -> Idle [label="suspendContext()", URL="\ref suspendContext"];
161 * Running -> Idle [label="drain()", URL="\ref drain"];
162 * Idle -> Running [label="drainResume()", URL="\ref drainResume"];
163 * RunningService -> RunningServiceCompletion [label="handleKvmExit()", URL="\ref handleKvmExit"];
164 * RunningServiceCompletion -> Running [label="tick()", URL="\ref tick"];
165 * RunningServiceCompletion -> RunningService [label="tick()", URL="\ref tick"];
166 * }
167 * @enddot
168 */
169 enum Status {
170 /** Context not scheduled in KVM.
171 *
172 * The CPU generally enters this state when the guest execute
173 * an instruction that halts the CPU (e.g., WFI on ARM or HLT
174 * on X86) if KVM traps this instruction. Ticks are not
175 * scheduled in this state.
176 *
177 * @see suspendContext()
178 */
179 Idle,
180 /** Running normally.
181 *
182 * This is the normal run state of the CPU. KVM will be
183 * entered next time tick() is called.
184 */
185 Running,
186 /** Requiring service at the beginning of the next cycle.
187 *
188 * The virtual machine has exited and requires service, tick()
189 * will call handleKvmExit() on the next cycle. The next state
190 * after running service is determined in handleKvmExit() and
191 * depends on what kind of service the guest requested:
192 * <ul>
193 * <li>IO/MMIO: RunningServiceCompletion
194 * <li>Halt: Idle
195 * <li>Others: Running
196 * </ul>
197 */
198 RunningService,
199 /** Service completion in progress.
200 *
201 * The VM has requested service that requires KVM to be
202 * entered once in order to get to a consistent state. This
203 * happens in handleKvmExit() or one of its friends after IO
204 * exits. After executing tick(), the CPU will transition into
205 * the Running or RunningService state.
206 */
207 RunningServiceCompletion,
208 };
209
210 /** CPU run state */
211 Status _status;
212
213 /**
214 * Execute the CPU until the next event in the main event queue or
215 * until the guest needs service from gem5.
216 */
217 void tick();
218
219 /**
220 * Get the value of the hardware cycle counter in the guest.
221 *
222 * This method is supposed to return the total number of cycles
223 * executed in hardware mode relative to some arbitrary point in
224 * the past. It's mainly used when estimating the number of cycles
225 * actually executed by the CPU in kvmRun(). The default behavior
226 * of this method is to use the cycles performance counter, but
227 * some architectures may want to use internal registers instead.
228 *
229 * @return Number of host cycles executed relative to an undefined
230 * point in the past.
231 */
232 virtual uint64_t getHostCycles() const;
233
234 /**
235 * Request KVM to run the guest for a given number of ticks. The
236 * method returns the approximate number of ticks executed.
237 *
238 * @note The returned number of ticks can be both larger or
239 * smaller than the requested number of ticks. A smaller number
240 * can, for example, occur when the guest executes MMIO. A larger
241 * number is typically due to performance counter inaccuracies.
242 *
243 * @note This method is virtual in order to allow implementations
244 * to check for architecture specific events (e.g., interrupts)
245 * before entering the VM.
246 *
247 * @note It is the response of the caller (normally tick()) to
248 * make sure that the KVM state is synchronized and that the TC is
249 * invalidated after entering KVM.
250 *
251 * @note This method does not normally cause any state
252 * transitions. However, if it may suspend the CPU by suspending
253 * the thread, which leads to a transition to the Idle state. In
254 * such a case, kvm <i>must not</i> be entered.
255 *
256 * @param ticks Number of ticks to execute, set to 0 to exit
257 * immediately after finishing pending operations.
258 * @return Number of ticks executed (see note)
259 */
260 virtual Tick kvmRun(Tick ticks);
261
262 /**
263 * Request the CPU to run until draining completes.
264 *
265 * This function normally calls kvmRun(0) to make KVM finish
266 * pending MMIO operations. Architecures implementing
267 * archIsDrained() must override this method.
268 *
269 * @see BaseKvmCPU::archIsDrained()
270 *
271 * @return Number of ticks executed
272 */
273 virtual Tick kvmRunDrain();
274
275 /**
276 * Get a pointer to the kvm_run structure containing all the input
277 * and output parameters from kvmRun().
278 */
279 struct kvm_run *getKvmRunState() { return _kvmRun; };
280
281 /**
282 * Retrieve a pointer to guest data stored at the end of the
283 * kvm_run structure. This is mainly used for PIO operations
284 * (KVM_EXIT_IO).
285 *
286 * @param offset Offset as specified by the kvm_run structure
287 * @return Pointer to guest data
288 */
289 uint8_t *getGuestData(uint64_t offset) const {
290 return (uint8_t *)_kvmRun + offset;
291 };
292
293 /**
294 * @addtogroup KvmInterrupts
295 * @{
296 */
297 /**
298 * Send a non-maskable interrupt to the guest
299 *
300 * @note The presence of this call depends on Kvm::capUserNMI().
301 */
302 void kvmNonMaskableInterrupt();
303
304 /**
305 * Send a normal interrupt to the guest
306 *
307 * @note Make sure that ready_for_interrupt_injection in kvm_run
308 * is set prior to calling this function. If not, an interrupt
309 * window must be requested by setting request_interrupt_window in
310 * kvm_run to 1 and restarting the guest.
311 *
312 * @param interrupt Structure describing the interrupt to send
313 */
314 void kvmInterrupt(const struct kvm_interrupt &interrupt);
315
316 /** @} */
317
318 /** @{ */
319 /**
320 * Get/Set the register state of the guest vCPU
321 *
322 * KVM has two different interfaces for accessing the state of the
323 * guest CPU. One interface updates 'normal' registers and one
324 * updates 'special' registers. The distinction between special
325 * and normal registers isn't very clear and is architecture
326 * dependent.
327 */
328 void getRegisters(struct kvm_regs &regs) const;
329 void setRegisters(const struct kvm_regs &regs);
330 void getSpecialRegisters(struct kvm_sregs &regs) const;
331 void setSpecialRegisters(const struct kvm_sregs &regs);
332 /** @} */
333
334 /** @{ */
335 /**
336 * Get/Set the guest FPU/vector state
337 */
338 void getFPUState(struct kvm_fpu &state) const;
339 void setFPUState(const struct kvm_fpu &state);
340 /** @} */
341
342 /** @{ */
343 /**
344 * Get/Set single register using the KVM_(SET|GET)_ONE_REG API.
345 *
346 * @note The presence of this call depends on Kvm::capOneReg().
347 */
348 void setOneReg(uint64_t id, const void *addr);
349 void setOneReg(uint64_t id, uint64_t value) { setOneReg(id, &value); }
350 void setOneReg(uint64_t id, uint32_t value) { setOneReg(id, &value); }
351 void getOneReg(uint64_t id, void *addr) const;
352 uint64_t getOneRegU64(uint64_t id) const {
353 uint64_t value;
354 getOneReg(id, &value);
355 return value;
356 }
357 uint32_t getOneRegU32(uint64_t id) const {
358 uint32_t value;
359 getOneReg(id, &value);
360 return value;
361 }
362 /** @} */
363
364 /**
365 * Get and format one register for printout.
366 *
367 * This function call getOneReg() to retrieve the contents of one
368 * register and automatically formats it for printing.
369 *
370 * @note The presence of this call depends on Kvm::capOneReg().
371 */
372 std::string getAndFormatOneReg(uint64_t id) const;
373
374 /** @{ */
375 /**
376 * Update the KVM state from the current thread context
377 *
378 * The base CPU calls this method before starting the guest CPU
379 * when the contextDirty flag is set. The architecture dependent
380 * CPU implementation is expected to update all guest state
381 * (registers, special registers, and FPU state).
382 */
383 virtual void updateKvmState() = 0;
384
385 /**
386 * Update the current thread context with the KVM state
387 *
388 * The base CPU after the guest updates any of the KVM state. In
389 * practice, this happens after kvmRun is called. The architecture
390 * dependent code is expected to read the state of the guest CPU
391 * and update gem5's thread state.
392 */
393 virtual void updateThreadContext() = 0;
394
395 /**
396 * Update a thread context if the KVM state is dirty with respect
397 * to the cached thread context.
398 */
399 void syncThreadContext();
400
401 /**
402 * Update the KVM if the thread context is dirty.
403 */
404 void syncKvmState();
405 /** @} */
406
407 /** @{ */
408 /**
409 * Main kvmRun exit handler, calls the relevant handleKvmExit*
410 * depending on exit type.
411 *
412 * @return Number of ticks spent servicing the exit request
413 */
414 virtual Tick handleKvmExit();
415
416 /**
417 * The guest performed a legacy IO request (out/inp on x86)
418 *
419 * @return Number of ticks spent servicing the IO request
420 */
421 virtual Tick handleKvmExitIO();
422
423 /**
424 * The guest requested a monitor service using a hypercall
425 *
426 * @return Number of ticks spent servicing the hypercall
427 */
428 virtual Tick handleKvmExitHypercall();
429
430 /**
431 * The guest exited because an interrupt window was requested
432 *
433 * The guest exited because an interrupt window was requested
434 * (request_interrupt_window in the kvm_run structure was set to 1
435 * before calling kvmRun) and it is now ready to receive
436 *
437 * @return Number of ticks spent servicing the IRQ
438 */
439 virtual Tick handleKvmExitIRQWindowOpen();
440
441 /**
442 * An unknown architecture dependent error occurred when starting
443 * the vCPU
444 *
445 * The kvm_run data structure contains the hardware error
446 * code. The defaults behavior of this method just prints the HW
447 * error code and panics. Architecture dependent implementations
448 * may want to override this method to provide better,
449 * hardware-aware, error messages.
450 *
451 * @return Number of ticks delay the next CPU tick
452 */
453 virtual Tick handleKvmExitUnknown();
454
455 /**
456 * An unhandled virtualization exception occured
457 *
458 * Some KVM virtualization drivers return unhandled exceptions to
459 * the user-space monitor. This interface is currently only used
460 * by the Intel VMX KVM driver.
461 *
462 * @return Number of ticks delay the next CPU tick
463 */
464 virtual Tick handleKvmExitException();
465
466 /**
467 * KVM failed to start the virtualized CPU
468 *
469 * The kvm_run data structure contains the hardware-specific error
470 * code.
471 *
472 * @return Number of ticks delay the next CPU tick
473 */
474 virtual Tick handleKvmExitFailEntry();
475 /** @} */
476
477 /**
478 * Is the architecture specific code in a state that prevents
479 * draining?
480 *
481 * This method should return false if there are any pending events
482 * in the guest vCPU that won't be carried over to the gem5 state
483 * and thus will prevent correct checkpointing or CPU handover. It
484 * might, for example, check for pending interrupts that have been
485 * passed to the vCPU but not acknowledged by the OS. Architecures
486 * implementing this method <i>must</i> override
487 * kvmRunDrain().
488 *
489 * @see BaseKvmCPU::kvmRunDrain()
490 *
491 * @return true if the vCPU is drained, false otherwise.
492 */
493 virtual bool archIsDrained() const { return true; }
494
495 /**
496 * Inject a memory mapped IO request into gem5
497 *
498 * @param paddr Physical address
499 * @param data Pointer to the source/destination buffer
500 * @param size Memory access size
501 * @param write True if write, False if read
502 * @return Number of ticks spent servicing the memory access
503 */
504 Tick doMMIOAccess(Addr paddr, void *data, int size, bool write);
505
506 /** @{ */
507 /**
508 * Set the signal mask used in kvmRun()
509 *
510 * This method allows the signal mask of the thread executing
511 * kvmRun() to be overridden inside the actual system call. This
512 * allows us to mask timer signals used to force KVM exits while
513 * in gem5.
514 *
515 * The signal mask can be disabled by setting it to NULL.
516 *
517 * @param mask Signals to mask
518 */
519 void setSignalMask(const sigset_t *mask);
520 /** @} */
521
522 /**
523 * @addtogroup KvmIoctl
524 * @{
525 */
526 /**
527 * vCPU ioctl interface.
528 *
529 * @param request KVM vCPU request
530 * @param p1 Optional request parameter
531 *
532 * @return -1 on error (error number in errno), ioctl dependent
533 * value otherwise.
534 */
535 int ioctl(int request, long p1) const;
536 int ioctl(int request, void *p1) const {
537 return ioctl(request, (long)p1);
538 }
539 int ioctl(int request) const {
540 return ioctl(request, 0L);
541 }
542 /** @} */
543
544
545 /**
546 * KVM memory port. Uses the default MasterPort behavior, but
547 * panics on timing accesses.
548 */
549 class KVMCpuPort : public MasterPort
550 {
551
552 public:
553 KVMCpuPort(const std::string &_name, BaseKvmCPU *_cpu)
554 : MasterPort(_name, _cpu)
555 { }
556
557 protected:
558 bool recvTimingResp(PacketPtr pkt)
559 {
560 panic("The KVM CPU doesn't expect recvTimingResp!\n");
561 return true;
562 }
563
564 void recvRetry()
565 {
566 panic("The KVM CPU doesn't expect recvRetry!\n");
567 }
568
569 };
570
571 /** Port for data requests */
572 KVMCpuPort dataPort;
573
574 /** Unused dummy port for the instruction interface */
575 KVMCpuPort instPort;
576
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_BASE_HH__
41#define __CPU_KVM_BASE_HH__
42
43#include <pthread.h>
44
45#include <csignal>
46#include <memory>
47
48#include "base/statistics.hh"
49#include "cpu/kvm/perfevent.hh"
50#include "cpu/kvm/timer.hh"
51#include "cpu/kvm/vm.hh"
52#include "cpu/base.hh"
53#include "cpu/simple_thread.hh"
54
55/** Signal to use to trigger exits from KVM */
56#define KVM_KICK_SIGNAL SIGRTMIN
57
58// forward declarations
59class ThreadContext;
60struct BaseKvmCPUParams;
61
62/**
63 * Base class for KVM based CPU models
64 *
65 * All architecture specific KVM implementation should inherit from
66 * this class. The most basic CPU models only need to override the
67 * updateKvmState() and updateThreadContext() methods to implement
68 * state synchronization between gem5 and KVM.
69 *
70 * The architecture specific implementation is also responsible for
71 * delivering interrupts into the VM. This is typically done by
72 * overriding tick() and checking the thread context before entering
73 * into the VM. In order to deliver an interrupt, the implementation
74 * then calls KvmVM::setIRQLine() or BaseKvmCPU::kvmInterrupt()
75 * depending on the specifics of the underlying hardware/drivers.
76 */
77class BaseKvmCPU : public BaseCPU
78{
79 public:
80 BaseKvmCPU(BaseKvmCPUParams *params);
81 virtual ~BaseKvmCPU();
82
83 void init();
84 void startup();
85 void regStats();
86
87 void serializeThread(std::ostream &os, ThreadID tid);
88 void unserializeThread(Checkpoint *cp, const std::string &section,
89 ThreadID tid);
90
91 unsigned int drain(DrainManager *dm);
92 void drainResume();
93
94 void switchOut();
95 void takeOverFrom(BaseCPU *cpu);
96
97 void verifyMemoryMode() const;
98
99 MasterPort &getDataPort() { return dataPort; }
100 MasterPort &getInstPort() { return instPort; }
101
102 void wakeup();
103 void activateContext(ThreadID thread_num);
104 void suspendContext(ThreadID thread_num);
105 void deallocateContext(ThreadID thread_num);
106 void haltContext(ThreadID thread_num);
107
108 ThreadContext *getContext(int tn);
109
110 Counter totalInsts() const;
111 Counter totalOps() const;
112
113 /** Dump the internal state to the terminal. */
114 virtual void dump();
115
116 /**
117 * Force an exit from KVM.
118 *
119 * Send a signal to the thread owning this vCPU to get it to exit
120 * from KVM. Ignored if the vCPU is not executing.
121 */
122 void kick() const { pthread_kill(vcpuThread, KVM_KICK_SIGNAL); }
123
124 /**
125 * A cached copy of a thread's state in the form of a SimpleThread
126 * object.
127 *
128 * Normally the actual thread state is stored in the KVM vCPU. If KVM has
129 * been running this copy is will be out of date. If we recently handled
130 * some events within gem5 that required state to be updated this could be
131 * the most up-to-date copy. When getContext() or updateThreadContext() is
132 * called this copy gets updated. The method syncThreadContext can
133 * be used within a KVM CPU to update the thread context if the
134 * KVM state is dirty (i.e., the vCPU has been run since the last
135 * update).
136 */
137 SimpleThread *thread;
138
139 /** ThreadContext object, provides an interface for external
140 * objects to modify this thread's state.
141 */
142 ThreadContext *tc;
143
144 KvmVM &vm;
145
146 protected:
147 /**
148 *
149 * @dot
150 * digraph {
151 * Idle;
152 * Running;
153 * RunningService;
154 * RunningServiceCompletion;
155 *
156 * Idle -> Idle;
157 * Idle -> Running [label="activateContext()", URL="\ref activateContext"];
158 * Running -> Running [label="tick()", URL="\ref tick"];
159 * Running -> RunningService [label="tick()", URL="\ref tick"];
160 * Running -> Idle [label="suspendContext()", URL="\ref suspendContext"];
161 * Running -> Idle [label="drain()", URL="\ref drain"];
162 * Idle -> Running [label="drainResume()", URL="\ref drainResume"];
163 * RunningService -> RunningServiceCompletion [label="handleKvmExit()", URL="\ref handleKvmExit"];
164 * RunningServiceCompletion -> Running [label="tick()", URL="\ref tick"];
165 * RunningServiceCompletion -> RunningService [label="tick()", URL="\ref tick"];
166 * }
167 * @enddot
168 */
169 enum Status {
170 /** Context not scheduled in KVM.
171 *
172 * The CPU generally enters this state when the guest execute
173 * an instruction that halts the CPU (e.g., WFI on ARM or HLT
174 * on X86) if KVM traps this instruction. Ticks are not
175 * scheduled in this state.
176 *
177 * @see suspendContext()
178 */
179 Idle,
180 /** Running normally.
181 *
182 * This is the normal run state of the CPU. KVM will be
183 * entered next time tick() is called.
184 */
185 Running,
186 /** Requiring service at the beginning of the next cycle.
187 *
188 * The virtual machine has exited and requires service, tick()
189 * will call handleKvmExit() on the next cycle. The next state
190 * after running service is determined in handleKvmExit() and
191 * depends on what kind of service the guest requested:
192 * <ul>
193 * <li>IO/MMIO: RunningServiceCompletion
194 * <li>Halt: Idle
195 * <li>Others: Running
196 * </ul>
197 */
198 RunningService,
199 /** Service completion in progress.
200 *
201 * The VM has requested service that requires KVM to be
202 * entered once in order to get to a consistent state. This
203 * happens in handleKvmExit() or one of its friends after IO
204 * exits. After executing tick(), the CPU will transition into
205 * the Running or RunningService state.
206 */
207 RunningServiceCompletion,
208 };
209
210 /** CPU run state */
211 Status _status;
212
213 /**
214 * Execute the CPU until the next event in the main event queue or
215 * until the guest needs service from gem5.
216 */
217 void tick();
218
219 /**
220 * Get the value of the hardware cycle counter in the guest.
221 *
222 * This method is supposed to return the total number of cycles
223 * executed in hardware mode relative to some arbitrary point in
224 * the past. It's mainly used when estimating the number of cycles
225 * actually executed by the CPU in kvmRun(). The default behavior
226 * of this method is to use the cycles performance counter, but
227 * some architectures may want to use internal registers instead.
228 *
229 * @return Number of host cycles executed relative to an undefined
230 * point in the past.
231 */
232 virtual uint64_t getHostCycles() const;
233
234 /**
235 * Request KVM to run the guest for a given number of ticks. The
236 * method returns the approximate number of ticks executed.
237 *
238 * @note The returned number of ticks can be both larger or
239 * smaller than the requested number of ticks. A smaller number
240 * can, for example, occur when the guest executes MMIO. A larger
241 * number is typically due to performance counter inaccuracies.
242 *
243 * @note This method is virtual in order to allow implementations
244 * to check for architecture specific events (e.g., interrupts)
245 * before entering the VM.
246 *
247 * @note It is the response of the caller (normally tick()) to
248 * make sure that the KVM state is synchronized and that the TC is
249 * invalidated after entering KVM.
250 *
251 * @note This method does not normally cause any state
252 * transitions. However, if it may suspend the CPU by suspending
253 * the thread, which leads to a transition to the Idle state. In
254 * such a case, kvm <i>must not</i> be entered.
255 *
256 * @param ticks Number of ticks to execute, set to 0 to exit
257 * immediately after finishing pending operations.
258 * @return Number of ticks executed (see note)
259 */
260 virtual Tick kvmRun(Tick ticks);
261
262 /**
263 * Request the CPU to run until draining completes.
264 *
265 * This function normally calls kvmRun(0) to make KVM finish
266 * pending MMIO operations. Architecures implementing
267 * archIsDrained() must override this method.
268 *
269 * @see BaseKvmCPU::archIsDrained()
270 *
271 * @return Number of ticks executed
272 */
273 virtual Tick kvmRunDrain();
274
275 /**
276 * Get a pointer to the kvm_run structure containing all the input
277 * and output parameters from kvmRun().
278 */
279 struct kvm_run *getKvmRunState() { return _kvmRun; };
280
281 /**
282 * Retrieve a pointer to guest data stored at the end of the
283 * kvm_run structure. This is mainly used for PIO operations
284 * (KVM_EXIT_IO).
285 *
286 * @param offset Offset as specified by the kvm_run structure
287 * @return Pointer to guest data
288 */
289 uint8_t *getGuestData(uint64_t offset) const {
290 return (uint8_t *)_kvmRun + offset;
291 };
292
293 /**
294 * @addtogroup KvmInterrupts
295 * @{
296 */
297 /**
298 * Send a non-maskable interrupt to the guest
299 *
300 * @note The presence of this call depends on Kvm::capUserNMI().
301 */
302 void kvmNonMaskableInterrupt();
303
304 /**
305 * Send a normal interrupt to the guest
306 *
307 * @note Make sure that ready_for_interrupt_injection in kvm_run
308 * is set prior to calling this function. If not, an interrupt
309 * window must be requested by setting request_interrupt_window in
310 * kvm_run to 1 and restarting the guest.
311 *
312 * @param interrupt Structure describing the interrupt to send
313 */
314 void kvmInterrupt(const struct kvm_interrupt &interrupt);
315
316 /** @} */
317
318 /** @{ */
319 /**
320 * Get/Set the register state of the guest vCPU
321 *
322 * KVM has two different interfaces for accessing the state of the
323 * guest CPU. One interface updates 'normal' registers and one
324 * updates 'special' registers. The distinction between special
325 * and normal registers isn't very clear and is architecture
326 * dependent.
327 */
328 void getRegisters(struct kvm_regs &regs) const;
329 void setRegisters(const struct kvm_regs &regs);
330 void getSpecialRegisters(struct kvm_sregs &regs) const;
331 void setSpecialRegisters(const struct kvm_sregs &regs);
332 /** @} */
333
334 /** @{ */
335 /**
336 * Get/Set the guest FPU/vector state
337 */
338 void getFPUState(struct kvm_fpu &state) const;
339 void setFPUState(const struct kvm_fpu &state);
340 /** @} */
341
342 /** @{ */
343 /**
344 * Get/Set single register using the KVM_(SET|GET)_ONE_REG API.
345 *
346 * @note The presence of this call depends on Kvm::capOneReg().
347 */
348 void setOneReg(uint64_t id, const void *addr);
349 void setOneReg(uint64_t id, uint64_t value) { setOneReg(id, &value); }
350 void setOneReg(uint64_t id, uint32_t value) { setOneReg(id, &value); }
351 void getOneReg(uint64_t id, void *addr) const;
352 uint64_t getOneRegU64(uint64_t id) const {
353 uint64_t value;
354 getOneReg(id, &value);
355 return value;
356 }
357 uint32_t getOneRegU32(uint64_t id) const {
358 uint32_t value;
359 getOneReg(id, &value);
360 return value;
361 }
362 /** @} */
363
364 /**
365 * Get and format one register for printout.
366 *
367 * This function call getOneReg() to retrieve the contents of one
368 * register and automatically formats it for printing.
369 *
370 * @note The presence of this call depends on Kvm::capOneReg().
371 */
372 std::string getAndFormatOneReg(uint64_t id) const;
373
374 /** @{ */
375 /**
376 * Update the KVM state from the current thread context
377 *
378 * The base CPU calls this method before starting the guest CPU
379 * when the contextDirty flag is set. The architecture dependent
380 * CPU implementation is expected to update all guest state
381 * (registers, special registers, and FPU state).
382 */
383 virtual void updateKvmState() = 0;
384
385 /**
386 * Update the current thread context with the KVM state
387 *
388 * The base CPU after the guest updates any of the KVM state. In
389 * practice, this happens after kvmRun is called. The architecture
390 * dependent code is expected to read the state of the guest CPU
391 * and update gem5's thread state.
392 */
393 virtual void updateThreadContext() = 0;
394
395 /**
396 * Update a thread context if the KVM state is dirty with respect
397 * to the cached thread context.
398 */
399 void syncThreadContext();
400
401 /**
402 * Update the KVM if the thread context is dirty.
403 */
404 void syncKvmState();
405 /** @} */
406
407 /** @{ */
408 /**
409 * Main kvmRun exit handler, calls the relevant handleKvmExit*
410 * depending on exit type.
411 *
412 * @return Number of ticks spent servicing the exit request
413 */
414 virtual Tick handleKvmExit();
415
416 /**
417 * The guest performed a legacy IO request (out/inp on x86)
418 *
419 * @return Number of ticks spent servicing the IO request
420 */
421 virtual Tick handleKvmExitIO();
422
423 /**
424 * The guest requested a monitor service using a hypercall
425 *
426 * @return Number of ticks spent servicing the hypercall
427 */
428 virtual Tick handleKvmExitHypercall();
429
430 /**
431 * The guest exited because an interrupt window was requested
432 *
433 * The guest exited because an interrupt window was requested
434 * (request_interrupt_window in the kvm_run structure was set to 1
435 * before calling kvmRun) and it is now ready to receive
436 *
437 * @return Number of ticks spent servicing the IRQ
438 */
439 virtual Tick handleKvmExitIRQWindowOpen();
440
441 /**
442 * An unknown architecture dependent error occurred when starting
443 * the vCPU
444 *
445 * The kvm_run data structure contains the hardware error
446 * code. The defaults behavior of this method just prints the HW
447 * error code and panics. Architecture dependent implementations
448 * may want to override this method to provide better,
449 * hardware-aware, error messages.
450 *
451 * @return Number of ticks delay the next CPU tick
452 */
453 virtual Tick handleKvmExitUnknown();
454
455 /**
456 * An unhandled virtualization exception occured
457 *
458 * Some KVM virtualization drivers return unhandled exceptions to
459 * the user-space monitor. This interface is currently only used
460 * by the Intel VMX KVM driver.
461 *
462 * @return Number of ticks delay the next CPU tick
463 */
464 virtual Tick handleKvmExitException();
465
466 /**
467 * KVM failed to start the virtualized CPU
468 *
469 * The kvm_run data structure contains the hardware-specific error
470 * code.
471 *
472 * @return Number of ticks delay the next CPU tick
473 */
474 virtual Tick handleKvmExitFailEntry();
475 /** @} */
476
477 /**
478 * Is the architecture specific code in a state that prevents
479 * draining?
480 *
481 * This method should return false if there are any pending events
482 * in the guest vCPU that won't be carried over to the gem5 state
483 * and thus will prevent correct checkpointing or CPU handover. It
484 * might, for example, check for pending interrupts that have been
485 * passed to the vCPU but not acknowledged by the OS. Architecures
486 * implementing this method <i>must</i> override
487 * kvmRunDrain().
488 *
489 * @see BaseKvmCPU::kvmRunDrain()
490 *
491 * @return true if the vCPU is drained, false otherwise.
492 */
493 virtual bool archIsDrained() const { return true; }
494
495 /**
496 * Inject a memory mapped IO request into gem5
497 *
498 * @param paddr Physical address
499 * @param data Pointer to the source/destination buffer
500 * @param size Memory access size
501 * @param write True if write, False if read
502 * @return Number of ticks spent servicing the memory access
503 */
504 Tick doMMIOAccess(Addr paddr, void *data, int size, bool write);
505
506 /** @{ */
507 /**
508 * Set the signal mask used in kvmRun()
509 *
510 * This method allows the signal mask of the thread executing
511 * kvmRun() to be overridden inside the actual system call. This
512 * allows us to mask timer signals used to force KVM exits while
513 * in gem5.
514 *
515 * The signal mask can be disabled by setting it to NULL.
516 *
517 * @param mask Signals to mask
518 */
519 void setSignalMask(const sigset_t *mask);
520 /** @} */
521
522 /**
523 * @addtogroup KvmIoctl
524 * @{
525 */
526 /**
527 * vCPU ioctl interface.
528 *
529 * @param request KVM vCPU request
530 * @param p1 Optional request parameter
531 *
532 * @return -1 on error (error number in errno), ioctl dependent
533 * value otherwise.
534 */
535 int ioctl(int request, long p1) const;
536 int ioctl(int request, void *p1) const {
537 return ioctl(request, (long)p1);
538 }
539 int ioctl(int request) const {
540 return ioctl(request, 0L);
541 }
542 /** @} */
543
544
545 /**
546 * KVM memory port. Uses the default MasterPort behavior, but
547 * panics on timing accesses.
548 */
549 class KVMCpuPort : public MasterPort
550 {
551
552 public:
553 KVMCpuPort(const std::string &_name, BaseKvmCPU *_cpu)
554 : MasterPort(_name, _cpu)
555 { }
556
557 protected:
558 bool recvTimingResp(PacketPtr pkt)
559 {
560 panic("The KVM CPU doesn't expect recvTimingResp!\n");
561 return true;
562 }
563
564 void recvRetry()
565 {
566 panic("The KVM CPU doesn't expect recvRetry!\n");
567 }
568
569 };
570
571 /** Port for data requests */
572 KVMCpuPort dataPort;
573
574 /** Unused dummy port for the instruction interface */
575 KVMCpuPort instPort;
576
577 /** Pre-allocated MMIO memory request */
578 Request mmio_req;
579
580 /**
581 * Is the gem5 context dirty? Set to true to force an update of
582 * the KVM vCPU state upon the next call to kvmRun().
583 */
584 bool threadContextDirty;
585
586 /**
587 * Is the KVM state dirty? Set to true to force an update of
588 * the KVM vCPU state upon the next call to kvmRun().
589 */
590 bool kvmStateDirty;
591
592 /** KVM internal ID of the vCPU */
593 const long vcpuID;
594
595 /** ID of the vCPU thread */
596 pthread_t vcpuThread;
597
598 private:
599 struct TickEvent : public Event
600 {
601 BaseKvmCPU &cpu;
602
603 TickEvent(BaseKvmCPU &c)
604 : Event(CPU_Tick_Pri), cpu(c) {}
605
606 void process() { cpu.tick(); }
607
608 const char *description() const {
609 return "BaseKvmCPU tick";
610 }
611 };
612
613 /**
614 * Service MMIO requests in the mmioRing.
615 *
616 *
617 * @return Number of ticks spent servicing the MMIO requests in
618 * the MMIO ring buffer
619 */
620 Tick flushCoalescedMMIO();
621
622 /**
623 * Setup a signal handler to catch the timer signal used to
624 * switch back to the monitor.
625 */
626 void setupSignalHandler();
627
628 /**
629 * Discard a (potentially) pending signal.
630 *
631 * @param signum Signal to discard
632 * @return true if the signal was pending, false otherwise.
633 */
634 bool discardPendingSignal(int signum) const;
635
636 /**
637 * Thread-specific initialization.
638 *
639 * Some KVM-related initialization requires us to know the TID of
640 * the thread that is going to execute our event queue. For
641 * example, when setting up timers, we need to know the TID of the
642 * thread executing in KVM in order to deliver the timer signal to
643 * that thread. This method is called as the first event in this
644 * SimObject's event queue.
645 *
646 * @see startup
647 */
648 void startupThread();
649
650 /** Try to drain the CPU if a drain is pending */
651 bool tryDrain();
652
653 /** Execute the KVM_RUN ioctl */
654 void ioctlRun();
655
656 /** KVM vCPU file descriptor */
657 int vcpuFD;
658 /** Size of MMAPed kvm_run area */
659 int vcpuMMapSize;
660 /**
661 * Pointer to the kvm_run structure used to communicate parameters
662 * with KVM.
663 *
664 * @note This is the base pointer of the MMAPed KVM region. The
665 * first page contains the kvm_run structure. Subsequent pages may
666 * contain other data such as the MMIO ring buffer.
667 */
668 struct kvm_run *_kvmRun;
669 /**
670 * Coalesced MMIO ring buffer. NULL if coalesced MMIO is not
671 * supported.
672 */
673 struct kvm_coalesced_mmio_ring *mmioRing;
674 /** Cached page size of the host */
675 const long pageSize;
676
677 TickEvent tickEvent;
678
679 /**
680 * Setup an instruction break if there is one pending.
681 *
682 * Check if there are pending instruction breaks in the CPU's
683 * instruction event queue and schedule an instruction break using
684 * PerfEvent.
685 *
686 * @note This method doesn't currently handle the main system
687 * instruction event queue.
688 */
689 void setupInstStop();
690
691 /** @{ */
692 /** Setup hardware performance counters */
693 void setupCounters();
694
695 /**
696 * Setup the guest instruction counter.
697 *
698 * Setup the guest instruction counter and optionally request a
699 * signal every N instructions executed by the guest. This method
700 * will re-attach the counter if the counter has already been
701 * attached and its sampling settings have changed.
702 *
703 * @param period Signal period, set to 0 to disable signaling.
704 */
705 void setupInstCounter(uint64_t period = 0);
706
707 /** Currently active instruction count breakpoint */
708 uint64_t activeInstPeriod;
709
710 /**
711 * Guest cycle counter.
712 *
713 * This is the group leader of all performance counters measuring
714 * the guest system. It can be used in conjunction with the
715 * PerfKvmTimer (see perfControlledByTimer) to trigger exits from
716 * KVM.
717 */
718 PerfKvmCounter hwCycles;
719
720 /**
721 * Guest instruction counter.
722 *
723 * This counter is typically only used to measure the number of
724 * instructions executed by the guest. However, it can also be
725 * used to trigger exits from KVM if the configuration script
726 * requests an exit after a certain number of instructions.
727 *
728 * @see setupInstBreak
729 * @see scheduleInstStop
730 */
731 PerfKvmCounter hwInstructions;
732
733 /**
734 * Does the runTimer control the performance counters?
735 *
736 * The run timer will automatically enable and disable performance
737 * counters if a PerfEvent-based timer is used to control KVM
738 * exits.
739 */
740 bool perfControlledByTimer;
741 /** @} */
742
743 /**
744 * Timer used to force execution into the monitor after a
745 * specified number of simulation tick equivalents have executed
746 * in the guest. This counter generates the signal specified by
747 * KVM_TIMER_SIGNAL.
748 */
749 std::unique_ptr<BaseKvmTimer> runTimer;
750
751 /** Host factor as specified in the configuration */
752 float hostFactor;
753
754 /**
755 * Drain manager to use when signaling drain completion
756 *
757 * This pointer is non-NULL when draining and NULL otherwise.
758 */
759 DrainManager *drainManager;
760
761 public:
762 /* @{ */
763 Stats::Scalar numInsts;
764 Stats::Scalar numVMExits;
765 Stats::Scalar numVMHalfEntries;
766 Stats::Scalar numExitSignal;
767 Stats::Scalar numMMIO;
768 Stats::Scalar numCoalescedMMIO;
769 Stats::Scalar numIO;
770 Stats::Scalar numHalt;
771 Stats::Scalar numInterrupts;
772 Stats::Scalar numHypercalls;
773 /* @} */
774
775 /** Number of instructions executed by the CPU */
776 Counter ctrInsts;
777};
778
779#endif
577 /**
578 * Is the gem5 context dirty? Set to true to force an update of
579 * the KVM vCPU state upon the next call to kvmRun().
580 */
581 bool threadContextDirty;
582
583 /**
584 * Is the KVM state dirty? Set to true to force an update of
585 * the KVM vCPU state upon the next call to kvmRun().
586 */
587 bool kvmStateDirty;
588
589 /** KVM internal ID of the vCPU */
590 const long vcpuID;
591
592 /** ID of the vCPU thread */
593 pthread_t vcpuThread;
594
595 private:
596 struct TickEvent : public Event
597 {
598 BaseKvmCPU &cpu;
599
600 TickEvent(BaseKvmCPU &c)
601 : Event(CPU_Tick_Pri), cpu(c) {}
602
603 void process() { cpu.tick(); }
604
605 const char *description() const {
606 return "BaseKvmCPU tick";
607 }
608 };
609
610 /**
611 * Service MMIO requests in the mmioRing.
612 *
613 *
614 * @return Number of ticks spent servicing the MMIO requests in
615 * the MMIO ring buffer
616 */
617 Tick flushCoalescedMMIO();
618
619 /**
620 * Setup a signal handler to catch the timer signal used to
621 * switch back to the monitor.
622 */
623 void setupSignalHandler();
624
625 /**
626 * Discard a (potentially) pending signal.
627 *
628 * @param signum Signal to discard
629 * @return true if the signal was pending, false otherwise.
630 */
631 bool discardPendingSignal(int signum) const;
632
633 /**
634 * Thread-specific initialization.
635 *
636 * Some KVM-related initialization requires us to know the TID of
637 * the thread that is going to execute our event queue. For
638 * example, when setting up timers, we need to know the TID of the
639 * thread executing in KVM in order to deliver the timer signal to
640 * that thread. This method is called as the first event in this
641 * SimObject's event queue.
642 *
643 * @see startup
644 */
645 void startupThread();
646
647 /** Try to drain the CPU if a drain is pending */
648 bool tryDrain();
649
650 /** Execute the KVM_RUN ioctl */
651 void ioctlRun();
652
653 /** KVM vCPU file descriptor */
654 int vcpuFD;
655 /** Size of MMAPed kvm_run area */
656 int vcpuMMapSize;
657 /**
658 * Pointer to the kvm_run structure used to communicate parameters
659 * with KVM.
660 *
661 * @note This is the base pointer of the MMAPed KVM region. The
662 * first page contains the kvm_run structure. Subsequent pages may
663 * contain other data such as the MMIO ring buffer.
664 */
665 struct kvm_run *_kvmRun;
666 /**
667 * Coalesced MMIO ring buffer. NULL if coalesced MMIO is not
668 * supported.
669 */
670 struct kvm_coalesced_mmio_ring *mmioRing;
671 /** Cached page size of the host */
672 const long pageSize;
673
674 TickEvent tickEvent;
675
676 /**
677 * Setup an instruction break if there is one pending.
678 *
679 * Check if there are pending instruction breaks in the CPU's
680 * instruction event queue and schedule an instruction break using
681 * PerfEvent.
682 *
683 * @note This method doesn't currently handle the main system
684 * instruction event queue.
685 */
686 void setupInstStop();
687
688 /** @{ */
689 /** Setup hardware performance counters */
690 void setupCounters();
691
692 /**
693 * Setup the guest instruction counter.
694 *
695 * Setup the guest instruction counter and optionally request a
696 * signal every N instructions executed by the guest. This method
697 * will re-attach the counter if the counter has already been
698 * attached and its sampling settings have changed.
699 *
700 * @param period Signal period, set to 0 to disable signaling.
701 */
702 void setupInstCounter(uint64_t period = 0);
703
704 /** Currently active instruction count breakpoint */
705 uint64_t activeInstPeriod;
706
707 /**
708 * Guest cycle counter.
709 *
710 * This is the group leader of all performance counters measuring
711 * the guest system. It can be used in conjunction with the
712 * PerfKvmTimer (see perfControlledByTimer) to trigger exits from
713 * KVM.
714 */
715 PerfKvmCounter hwCycles;
716
717 /**
718 * Guest instruction counter.
719 *
720 * This counter is typically only used to measure the number of
721 * instructions executed by the guest. However, it can also be
722 * used to trigger exits from KVM if the configuration script
723 * requests an exit after a certain number of instructions.
724 *
725 * @see setupInstBreak
726 * @see scheduleInstStop
727 */
728 PerfKvmCounter hwInstructions;
729
730 /**
731 * Does the runTimer control the performance counters?
732 *
733 * The run timer will automatically enable and disable performance
734 * counters if a PerfEvent-based timer is used to control KVM
735 * exits.
736 */
737 bool perfControlledByTimer;
738 /** @} */
739
740 /**
741 * Timer used to force execution into the monitor after a
742 * specified number of simulation tick equivalents have executed
743 * in the guest. This counter generates the signal specified by
744 * KVM_TIMER_SIGNAL.
745 */
746 std::unique_ptr<BaseKvmTimer> runTimer;
747
748 /** Host factor as specified in the configuration */
749 float hostFactor;
750
751 /**
752 * Drain manager to use when signaling drain completion
753 *
754 * This pointer is non-NULL when draining and NULL otherwise.
755 */
756 DrainManager *drainManager;
757
758 public:
759 /* @{ */
760 Stats::Scalar numInsts;
761 Stats::Scalar numVMExits;
762 Stats::Scalar numVMHalfEntries;
763 Stats::Scalar numExitSignal;
764 Stats::Scalar numMMIO;
765 Stats::Scalar numCoalescedMMIO;
766 Stats::Scalar numIO;
767 Stats::Scalar numHalt;
768 Stats::Scalar numInterrupts;
769 Stats::Scalar numHypercalls;
770 /* @} */
771
772 /** Number of instructions executed by the CPU */
773 Counter ctrInsts;
774};
775
776#endif