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