VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/solaris/vbi/timer-r0drv-solaris.c@ 37570

Last change on this file since 37570 was 37275, checked in by vboxsync, 14 years ago

timer-r0drv-solaris.c: drop the vbi version check.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.5 KB
Line 
1/* $Id: timer-r0drv-solaris.c 37275 2011-05-31 11:48:14Z vboxsync $ */
2/** @file
3 * IPRT - Timer, Ring-0 Driver, Solaris.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Oracle Corporation
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 (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include "../the-solaris-kernel.h"
32#include "internal/iprt.h"
33#include <iprt/timer.h>
34
35#include <iprt/asm.h>
36#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
37# include <iprt/asm-amd64-x86.h>
38#endif
39#include <iprt/assert.h>
40#include <iprt/err.h>
41#include <iprt/mem.h>
42#include <iprt/mp.h>
43#include <iprt/spinlock.h>
44#include <iprt/time.h>
45#include <iprt/thread.h>
46#include "internal/magics.h"
47
48
49/*******************************************************************************
50* Structures and Typedefs *
51*******************************************************************************/
52/**
53 * The internal representation of a Solaris timer handle.
54 */
55typedef struct RTTIMER
56{
57 /** Magic.
58 * This is RTTIMER_MAGIC, but changes to something else before the timer
59 * is destroyed to indicate clearly that thread should exit. */
60 uint32_t volatile u32Magic;
61 /** Flag indicating that the timer is suspended. */
62 uint8_t volatile fSuspended;
63 /** Run on all CPUs if set */
64 uint8_t fAllCpu;
65 /** Whether the timer must run on a specific CPU or not. */
66 uint8_t fSpecificCpu;
67 /** The CPU it must run on if fSpecificCpu is set. */
68 uint8_t iCpu;
69 /** The nano second interval for repeating timers */
70 uint64_t interval;
71 /** simple Solaris timer handle. */
72 vbi_stimer_t *stimer;
73 /** global Solaris timer handle. */
74 vbi_gtimer_t *gtimer;
75 /** The user callback. */
76 PFNRTTIMER pfnTimer;
77 /** The argument for the user callback. */
78 void *pvUser;
79} RTTIMER;
80
81
82/*******************************************************************************
83* Defined Constants And Macros *
84*******************************************************************************/
85/** Validates that the timer is valid. */
86#define RTTIMER_ASSERT_VALID_RET(pTimer) \
87 do \
88 { \
89 AssertPtrReturn(pTimer, VERR_INVALID_HANDLE); \
90 AssertReturn((pTimer)->u32Magic == RTTIMER_MAGIC, VERR_INVALID_HANDLE); \
91 } while (0)
92
93
94/*
95 * Need a wrapper to get the PRTTIMER passed through
96 */
97static void rtTimerSolarisCallbackWrapper(PRTTIMER pTimer, uint64_t tick)
98{
99 pTimer->pfnTimer(pTimer, pTimer->pvUser, tick);
100}
101
102
103
104
105RTDECL(int) RTTimerCreateEx(PRTTIMER *ppTimer, uint64_t u64NanoInterval, uint32_t fFlags, PFNRTTIMER pfnTimer, void *pvUser)
106{
107 RT_ASSERT_PREEMPTIBLE();
108 *ppTimer = NULL;
109
110 /*
111 * Validate flags.
112 */
113 if (!RTTIMER_FLAGS_ARE_VALID(fFlags))
114 return VERR_INVALID_PARAMETER;
115
116 if ( (fFlags & RTTIMER_FLAGS_CPU_SPECIFIC)
117 && (fFlags & RTTIMER_FLAGS_CPU_ALL) != RTTIMER_FLAGS_CPU_ALL
118 && !RTMpIsCpuPossible(RTMpCpuIdFromSetIndex(fFlags & RTTIMER_FLAGS_CPU_MASK)))
119 return VERR_CPU_NOT_FOUND;
120
121 if ((fFlags & RTTIMER_FLAGS_CPU_ALL) == RTTIMER_FLAGS_CPU_ALL && u64NanoInterval == 0)
122 return VERR_NOT_SUPPORTED;
123
124 /*
125 * Allocate and initialize the timer handle.
126 */
127 PRTTIMER pTimer = (PRTTIMER)RTMemAlloc(sizeof(*pTimer));
128 if (!pTimer)
129 return VERR_NO_MEMORY;
130
131 pTimer->u32Magic = RTTIMER_MAGIC;
132 pTimer->fSuspended = true;
133 if ((fFlags & RTTIMER_FLAGS_CPU_ALL) == RTTIMER_FLAGS_CPU_ALL)
134 {
135 pTimer->fAllCpu = true;
136 pTimer->fSpecificCpu = false;
137 pTimer->iCpu = 255;
138 }
139 else if (fFlags & RTTIMER_FLAGS_CPU_SPECIFIC)
140 {
141 pTimer->fAllCpu = false;
142 pTimer->fSpecificCpu = true;
143 pTimer->iCpu = fFlags & RTTIMER_FLAGS_CPU_MASK; /* ASSUMES: index == cpuid */
144 }
145 else
146 {
147 pTimer->fAllCpu = false;
148 pTimer->fSpecificCpu = false;
149 pTimer->iCpu = 255;
150 }
151 pTimer->interval = u64NanoInterval;
152 pTimer->pfnTimer = pfnTimer;
153 pTimer->pvUser = pvUser;
154 pTimer->stimer = NULL;
155 pTimer->gtimer = NULL;
156
157 *ppTimer = pTimer;
158 return VINF_SUCCESS;
159}
160
161
162RTDECL(int) RTTimerDestroy(PRTTIMER pTimer)
163{
164 if (pTimer == NULL)
165 return VINF_SUCCESS;
166 RTTIMER_ASSERT_VALID_RET(pTimer);
167 RT_ASSERT_INTS_ON();
168
169 /*
170 * Free the associated resources.
171 */
172 RTTimerStop(pTimer);
173 ASMAtomicWriteU32(&pTimer->u32Magic, ~RTTIMER_MAGIC);
174 RTMemFree(pTimer);
175 return VINF_SUCCESS;
176}
177
178
179RTDECL(int) RTTimerStart(PRTTIMER pTimer, uint64_t u64First)
180{
181 RTTIMER_ASSERT_VALID_RET(pTimer);
182 RT_ASSERT_INTS_ON();
183
184 if (!pTimer->fSuspended)
185 return VERR_TIMER_ACTIVE;
186
187 pTimer->fSuspended = false;
188 if (pTimer->fAllCpu)
189 {
190 pTimer->gtimer = vbi_gtimer_begin(rtTimerSolarisCallbackWrapper, pTimer, u64First, pTimer->interval);
191 if (pTimer->gtimer == NULL)
192 return VERR_INVALID_PARAMETER;
193 }
194 else
195 {
196 int iCpu = VBI_ANY_CPU;
197 if (pTimer->fSpecificCpu)
198 iCpu = pTimer->iCpu;
199 pTimer->stimer = vbi_stimer_begin(rtTimerSolarisCallbackWrapper, pTimer, u64First, pTimer->interval, iCpu);
200 if (pTimer->stimer == NULL)
201 {
202 if (iCpu != VBI_ANY_CPU)
203 return VERR_CPU_OFFLINE;
204 return VERR_INVALID_PARAMETER;
205 }
206 }
207
208 return VINF_SUCCESS;
209}
210
211
212RTDECL(int) RTTimerStop(PRTTIMER pTimer)
213{
214 RTTIMER_ASSERT_VALID_RET(pTimer);
215 RT_ASSERT_INTS_ON();
216
217 if (pTimer->fSuspended)
218 return VERR_TIMER_SUSPENDED;
219
220 pTimer->fSuspended = true;
221 if (pTimer->stimer)
222 {
223 vbi_stimer_end(pTimer->stimer);
224 pTimer->stimer = NULL;
225 }
226 else if (pTimer->gtimer)
227 {
228 vbi_gtimer_end(pTimer->gtimer);
229 pTimer->gtimer = NULL;
230 }
231
232 return VINF_SUCCESS;
233}
234
235
236
237RTDECL(int) RTTimerChangeInterval(PRTTIMER pTimer, uint64_t u64NanoInterval)
238{
239 RTTIMER_ASSERT_VALID_RET(pTimer);
240
241 /** @todo implement me! */
242
243 return VERR_NOT_SUPPORTED;
244}
245
246
247RTDECL(uint32_t) RTTimerGetSystemGranularity(void)
248{
249 return vbi_timer_granularity();
250}
251
252
253RTDECL(int) RTTimerRequestSystemGranularity(uint32_t u32Request, uint32_t *pu32Granted)
254{
255 return VERR_NOT_SUPPORTED;
256}
257
258
259RTDECL(int) RTTimerReleaseSystemGranularity(uint32_t u32Granted)
260{
261 return VERR_NOT_SUPPORTED;
262}
263
264
265RTDECL(bool) RTTimerCanDoHighResolution(void)
266{
267 /** @todo return true; - when missing bits have been implemented and tested*/
268 return false;
269}
270
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