mp-solaris.cpp revision e64031e20c39650a7bc902a3e1aba613b9415dee
/* $Id$ */
/** @file
* IPRT - Multiprocessor, Solaris.
*/
/*
* Copyright (C) 2008 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 *
*******************************************************************************/
#define LOG_GROUP RTLOGGROUP_DEFAULT
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <kstat.h>
#include <sys/processor.h>
#include <iprt/critsect.h>
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** Initialization serializing (rtMpSolarisOnce). */
/** Critical section serializing access to kstat. */
static RTCRITSECT g_MpSolarisCritSect;
/** The kstat handle. */
static kstat_ctl_t *g_pKsCtl;
/** Array pointing to the cpu_info instances. */
static kstat_t **g_papCpuInfo;
/** The number of entries in g_papCpuInfo */
static RTCPUID g_capCpuInfo;
/**
* Run once function that initializes the kstats we need here.
*
* @returns IPRT status code.
* @param pvUser1 Unused.
* @param pvUser2 Unused.
*/
{
int rc = VINF_SUCCESS;
/*
* Open kstat and find the cpu_info entries for each of the CPUs.
*/
g_pKsCtl = kstat_open();
if (g_pKsCtl)
{
g_capCpuInfo = RTMpGetCount();
if (g_papCpuInfo)
{
if (RT_SUCCESS(rc))
{
RTCPUID i = 0;
{
{
AssertBreak(i < g_capCpuInfo);
g_papCpuInfo[i++] = pKsp;
}
}
return VINF_SUCCESS;
}
/* bail out, we failed. */
}
else
rc = VERR_NO_MEMORY;
}
else
{
if (RT_SUCCESS(rc))
}
return rc;
}
/**
* Worker for RTMpGetCurFrequency and RTMpGetMaxFrequency.
*
* @returns The desired frequency on success, 0 on failure.
*
* @param idCpu The CPU ID.
* @param pszStatName The cpu_info stat name.
*/
{
if (RT_SUCCESS(rc))
{
if ( idCpu < g_capCpuInfo
&& g_papCpuInfo[idCpu])
{
if (RT_SUCCESS(rc))
{
{
if (pStat)
{
{
/* just in case... */
default:
break;
}
}
else
}
else
}
}
else
}
return u64;
}
{
}
{
}
{
}
{
}
{
return RTMpGetCount() - 1;
}
{
return idCpu != NIL_RTCPUID
}
{
}
{
return iStatus != -1;
}
{
/*
* Solaris has sysconf.
*/
if (cCpus < 0)
return cCpus;
}
{
int idCpu = RTMpGetCount();
while (idCpu-- > 0)
return pSet;
}
{
/*
* Solaris has sysconf.
*/
return sysconf(_SC_NPROCESSORS_ONLN);
}
{
if (RTMpIsCpuOnline(idCpu))
return pSet;
}
{
#ifdef RT_STRICT
long cCpusPresent = 0;
#endif
if (RTMpIsCpuPresent(idCpu))
{
#ifdef RT_STRICT
cCpusPresent++;
#endif
}
return pSet;
}
{
/*
* Solaris has sysconf.
*/
return sysconf(_SC_NPROCESSORS_CONF);
}