timer-r0drv-nt.cpp revision 81b90ddcc2cd990f9e45b8b993471aa7f290a4a6
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * IPRT - Timers, Ring-0 Driver, NT.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Copyright (C) 2006-2008 Sun Microsystems, Inc.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * available from http://www.virtualbox.org. This file is free software;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * General Public License (GPL) as published by the Free Software
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * The contents of this file may alternatively be used under the terms
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * of the Common Development and Distribution License Version 1.0
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * VirtualBox OSE distribution, in which case the provisions of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * CDDL are applicable instead of those of the GPL.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * You may elect to license modified versions of this file under the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * terms and conditions of either the GPL or the CDDL or both.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * additional information or have any questions.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/*******************************************************************************
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync* Header Files *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync*******************************************************************************/
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/*******************************************************************************
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync* Structures and Typedefs *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync*******************************************************************************/
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * A sub timer structure.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * This is used for keeping the per-cpu tick and DPC object.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The tick counter. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** Pointer to the parent timer. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The NT DPC object. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** Pointer to a NT sub-timer structure. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * The internal representation of an Linux timer handle.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsynctypedef struct RTTIMER
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * This is RTTIMER_MAGIC, but changes to something else before the timer
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * is destroyed to indicate clearly that thread should exit. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** Flag indicating the the timer is suspended. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync bool volatile fSuspended;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** Whether the timer must run on one specific CPU or not. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** Whether the timer must run on all CPUs or not. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The CPU it must run on if fSpecificCpu is set.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * The master CPU for an omni-timer. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** Callback. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** User argument. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The timer interval. 0 if one-shot. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The Nt timer object. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** The number of sub-timers. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** Sub-timers.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Normally there is just one, but for RTTIMER_FLAGS_CPU_ALL this will contain
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * an entry for all possible cpus. In that case the index will be the same as
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * for the RTCpuSet. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Timer callback function for the non-omni timers.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @returns HRTIMER_NORESTART or HRTIMER_RESTART depending on whether it's a one-shot or interval timer.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pHrTimer Pointer to the timer structure.
static void _stdcall rtTimerNtSimpleCallback(IN PKDPC pDpc, IN PVOID pvUser, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
#ifdef RT_STRICT
static void _stdcall rtTimerNtOmniSlaveCallback(IN PKDPC pDpc, IN PVOID pvUser, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
#ifdef RT_STRICT
AssertMsg2("rtTimerNtOmniSlaveCallback: Irql=%d expected >=%d\n", KeGetCurrentIrql(), DISPATCH_LEVEL);
AssertMsg2("rtTimerNtOmniSlaveCallback: iCpuSelf=%d pSubTimer=%p / %d\n", iCpuSelf, pSubTimer, pSubTimer - &pTimer->aSubTimers[0]);
static void _stdcall rtTimerNtOmniMasterCallback(IN PKDPC pDpc, IN PVOID pvUser, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
#ifdef RT_STRICT
AssertMsg2("rtTimerNtOmniMasterCallback: Irql=%d expected >=%d\n", KeGetCurrentIrql(), DISPATCH_LEVEL);
AssertMsg2("rtTimerNtOmniMasterCallback: iCpuSelf=%d pSubTimer=%p / %d\n", iCpuSelf, pSubTimer, pSubTimer - &pTimer->aSubTimers[0]);
return VERR_TIMER_ACTIVE;
return VINF_SUCCESS;
return VERR_TIMER_SUSPENDED;
return VINF_SUCCESS;
return VINF_SUCCESS;
return VINF_SUCCESS;
RTDECL(int) RTTimerCreateEx(PRTTIMER *ppTimer, uint64_t u64NanoInterval, unsigned fFlags, PFNRTTIMER pfnTimer, void *pvUser)
return VERR_INVALID_PARAMETER;
Assert(cSubTimers <= RTCPUSET_MAX_CPUS); /* On Windows we have a 1:1 relationship between cpuid and set index. */
if (!pTimer)
return VERR_NO_MEMORY;
pTimer->fSpecificCpu = (fFlags & RTTIMER_FLAGS_CPU_SPECIFIC) && (fFlags & RTTIMER_FLAGS_CPU_ALL) != RTTIMER_FLAGS_CPU_ALL;
KeInitializeDpc(&pTimer->aSubTimers[iCpu].NtDpc, rtTimerNtOmniMasterCallback, &pTimer->aSubTimers[iCpu]);
KeInitializeDpc(&pTimer->aSubTimers[iCpu].NtDpc, rtTimerNtOmniSlaveCallback, &pTimer->aSubTimers[iCpu]);
return VINF_SUCCESS;
AssertMsg(ulResolution1 == ulResolution2, ("%ld, %ld\n", ulResolution1, ulResolution2)); /* not supposed to change it! */
return VERR_NOT_SUPPORTED;
if (pu32Granted)
return VINF_SUCCESS;
return VERR_NOT_SUPPORTED;
return VINF_SUCCESS;