timer-r0drv-solaris.c revision 35958bc7e3a101f864e2e380d6f57dcae7f33f33
/* $Id$ */
/** @file
* IPRT - Timer, Ring-0 Driver, Solaris.
*/
/*
* Copyright (C) 2006-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "the-solaris-kernel.h"
#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
# include <iprt/asm-amd64-x86.h>
#endif
#include <iprt/spinlock.h>
#define SOL_TIMER_ANY_CPU (-1)
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Single-CPU timer handle.
*/
typedef struct RTR0SINGLETIMERSOL
{
/** Cyclic handler. */
/** Cyclic time and interval representation. */
/** Timer ticks. */
typedef RTR0SINGLETIMERSOL *PRTR0SINGLETIMERSOL;
/**
* Omni-CPU timer handle.
*/
typedef struct RTR0OMNITIMERSOL
{
/** Absolute timestamp of when the timer should fire next. */
/** Array of timer ticks per CPU. Reinitialized when a CPU is online'd. */
typedef RTR0OMNITIMERSOL *PRTR0OMNITIMERSOL;
/**
* The internal representation of a Solaris timer handle.
*/
typedef struct RTTIMER
{
/** Magic.
* This is RTTIMER_MAGIC, but changes to something else before the timer
* is destroyed to indicate clearly that thread should exit. */
/** Flag indicating that the timer is suspended. */
uint8_t volatile fSuspended;
/** Whether the timer must run on all CPUs or not. */
/** Whether the timer must run on a specific CPU or not. */
/** The CPU it must run on if fSpecificCpu is set. */
/** The nano second interval for repeating timers. */
/** Cyclic timer Id. */
/** @todo Make this a union unless we intend to support omni<=>single timers
* conversions. */
/** Single-CPU timer handle. */
/** Omni-CPU timer handle. */
/** The user callback. */
/** The argument for the user callback. */
void *pvUser;
} RTTIMER;
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** Validates that the timer is valid. */
#define RTTIMER_ASSERT_VALID_RET(pTimer) \
do \
{ \
AssertMsgReturn((pTimer)->u32Magic == RTTIMER_MAGIC, ("pTimer=%p u32Magic=%x expected %x\n", (pTimer), (pTimer)->u32Magic, RTTIMER_MAGIC), \
} while (0)
/**
* Callback wrapper for specific timers if they happened to have been fired on
* the wrong CPU. See rtTimerSolCallbackWrapper().
*
* @param idCpu The CPU this is fired on.
* @param pvUser1 Opaque pointer to the timer.
* @param pvUser2 Not used, NULL.
*/
{
/* Make sure one-shots do not fire another time. */
/* For one-shot specific timers, allow RTTimer to restart them. */
pTimer->fSuspended = true;
}
/**
* Callback wrapper for Omni-CPU and single-CPU timers.
*
* @param pvArg Opaque pointer to the timer.
*
* @remarks This will be executed in interrupt context but only at the specified
* level i.e. CY_LOCK_LEVEL in our case. We -CANNOT- call into the
* cyclic subsystem here, neither should pfnTimer().
*/
static void rtTimerSolCallbackWrapper(void *pvArg)
{
if (pTimer->pSingleTimer)
{
/* Make sure one-shots do not fire another time. */
/* For specific timers, we might fire on the wrong CPU between cyclic_add() and cyclic_bind().
Redirect these shots to the right CPU as we are temporarily rebinding to the right CPU. */
if ( pTimer->fSpecificCpu
{
return;
}
/* For one-shot any-cpu timers, allow RTTimer to restart them. */
pTimer->fSuspended = true;
}
else if (pTimer->pOmniTimer)
{
}
}
/**
* Omni-CPU cyclic online event. This is called before the omni cycle begins to
* fire on the specified CPU.
*
* @param pvArg Opaque pointer to the timer.
* @param pCpu Pointer to the CPU on which it will fire.
* @param pCyclicHandler Pointer to a cyclic handler to add to the CPU
* specified in @a pCpu.
* @param pCyclicTime Pointer to the cyclic time and interval object.
*
* @remarks We -CANNOT- call back into the cyclic subsystem here, we can however
* block (sleep).
*/
static void rtTimerSolOmniCpuOnline(void *pvArg, cpu_t *pCpu, cyc_handler_t *pCyclicHandler, cyc_time_t *pCyclicTime)
{
else
}
RTDECL(int) RTTimerCreateEx(PRTTIMER *ppTimer, uint64_t u64NanoInterval, uint32_t fFlags, PFNRTTIMER pfnTimer, void *pvUser)
{
/*
* Validate flags.
*/
if (!RTTIMER_FLAGS_ARE_VALID(fFlags))
return VERR_INVALID_PARAMETER;
if ( (fFlags & RTTIMER_FLAGS_CPU_SPECIFIC)
return VERR_CPU_NOT_FOUND;
/* One-shot omni timers are not supported by the cyclic system. */
&& u64NanoInterval == 0)
{
return VERR_NOT_SUPPORTED;
}
/*
* Allocate and initialize the timer handle.
*/
if (!pTimer)
return VERR_NO_MEMORY;
pTimer->fSuspended = true;
{
pTimer->fSpecificCpu = false;
}
else if (fFlags & RTTIMER_FLAGS_CPU_SPECIFIC)
{
pTimer->fSpecificCpu = true;
}
else
{
pTimer->fSpecificCpu = false;
}
return VINF_SUCCESS;
}
{
return VINF_SUCCESS;
/*
* Free the associated resources.
*/
return VINF_SUCCESS;
}
{
if (!pTimer->fSuspended)
return VERR_TIMER_ACTIVE;
pTimer->fSuspended = false;
{
if (RT_UNLIKELY(!pOmniTimer))
return VERR_NO_MEMORY;
{
return VERR_NO_MEMORY;
}
/*
* Setup omni (all CPU) timer. The Omni-CPU online event will fire
* and from there we setup periodic timers per CPU.
*/
}
else
{
int iCpu = SOL_TIMER_ANY_CPU;
if (pTimer->fSpecificCpu)
{
return VERR_CPU_OFFLINE;
}
if (RT_UNLIKELY(!pSingleTimer))
return VERR_NO_MEMORY;
if ( iCpu != SOL_TIMER_ANY_CPU
{
return VERR_CPU_OFFLINE;
}
{
/*
* cylic_add() comment: "The caller is responsible for assuring that cyt_when + cyt_interval <= INT64_MAX"
* but it contradicts itself because cyclic_reprogram() updates only the interval and accepts CY_INFINITY as
* a valid, special value. See cyclic_fire().
*/
}
else
if (iCpu != SOL_TIMER_ANY_CPU)
}
return VINF_SUCCESS;
}
{
if (pTimer->fSuspended)
return VERR_TIMER_SUSPENDED;
pTimer->fSuspended = true;
if (pTimer->pSingleTimer)
{
}
else if (pTimer->pOmniTimer)
{
}
return VINF_SUCCESS;
}
{
/** @todo implement me! */
return VERR_NOT_SUPPORTED;
}
{
return nsec_per_tick;
}
{
return VERR_NOT_SUPPORTED;
}
{
return VERR_NOT_SUPPORTED;
}
RTDECL(bool) RTTimerCanDoHighResolution(void)
{
/** @todo return true; - when missing bits have been implemented and tested*/
return false;
}