VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMAll/TMAllCpu.cpp@ 23

Last change on this file since 23 was 23, checked in by vboxsync, 18 years ago

string.h & stdio.h + header cleanups.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1/* $Id: TMAllCpu.cpp 23 2007-01-15 14:08:28Z vboxsync $ */
2/** @file
3 * TM - Timeout Manager, CPU Time, All Contexts.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#define LOG_GROUP LOG_GROUP_TM
27#include <VBox/tm.h>
28#include "TMInternal.h"
29#include <VBox/vm.h>
30
31#include <VBox/param.h>
32#include <VBox/err.h>
33#include <iprt/assert.h>
34#include <iprt/asm.h>
35
36
37/**
38 * Resumes the CPU timestamp counter ticking.
39 *
40 * @returns VBox status code.
41 * @param pVM The VM to operate on.
42 */
43TMDECL(int) TMCpuTickResume(PVM pVM)
44{
45 if (!pVM->tm.s.fTSCTicking)
46 {
47 pVM->tm.s.fTSCTicking = true;
48#ifndef TM_REAL_CPU_TICK
49 pVM->tm.s.u64TSCOffset = ASMReadTSC() - pVM->tm.s.u64TSC;
50#endif
51 return VINF_SUCCESS;
52 }
53 AssertFailed();
54 return VERR_INTERNAL_ERROR;
55}
56
57
58/**
59 * Pauses the CPU timestamp counter ticking.
60 *
61 * @returns VBox status code.
62 * @param pVM The VM to operate on.
63 */
64TMDECL(int) TMCpuTickPause(PVM pVM)
65{
66 if (pVM->tm.s.fTSCTicking)
67 {
68#ifndef TM_REAL_CPU_TICK
69 pVM->tm.s.u64TSC = ASMReadTSC() - pVM->tm.s.u64TSCOffset;
70#endif
71 pVM->tm.s.fTSCTicking = false;
72 return VINF_SUCCESS;
73 }
74 AssertFailed();
75 return VERR_INTERNAL_ERROR;
76}
77
78
79
80/**
81 * Read the current CPU timstamp counter.
82 *
83 * @returns Gets the CPU tsc.
84 * @param pVM The VM to operate on.
85 */
86TMDECL(uint64_t) TMCpuTickGet(PVM pVM)
87{
88#ifdef TM_REAL_CPU_TICK
89 return ASMReadTSC();
90#else
91 if (pVM->tm.s.fTSCTicking)
92 return ASMReadTSC() - pVM->tm.s.u64TSCOffset;
93 return pVM->tm.s.u64TSC;
94#endif
95}
96
97
98/**
99 * Sets the current CPU timestamp counter.
100 *
101 * @returns VBox status code.
102 * @param pVM The VM to operate on.
103 * @param u64Tick The new timestamp value.
104 */
105TMDECL(int) TMCpuTickSet(PVM pVM, uint64_t u64Tick)
106{
107 Assert(!pVM->tm.s.fTSCTicking);
108 pVM->tm.s.u64TSC = u64Tick;
109 return VINF_SUCCESS;
110}
111
112
113/**
114 * Get the timestamp frequency.
115 *
116 * @returns Number of ticks per second.
117 * @param pVM The VM.
118 */
119TMDECL(uint64_t) TMCpuTicksPerSecond(PVM pVM)
120{
121 return pVM->tm.s.cTSCTicksPerSecond;
122}
123
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette