mp-linux.cpp revision a8f466a5935aa489fa148f1de46225c7bd137a81
/* $Id$ */
/** @file
* IPRT - Multiprocessor, Linux.
*/
/*
* Copyright (C) 2006-2008 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP RTLOGGROUP_SYSTEM
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
/**
* Checks if a sysfs file (or directory, device, symlink, whatever) exists.
*
* @returns true / false, errno is preserved.
* @param pszFormat The name format, without "/sys/".
* @param va The format args.
*/
{
int iSavedErrno = errno;
/*
* Construct the filename and call stat.
*/
char szFilename[128];
errno = iSavedErrno;
return fRet;
}
/**
* Checks if a sysfs file (or directory, device, symlink, whatever) exists.
*
* @returns true / false, errno is preserved.
* @param pszFormat The name format, without "/sys/".
* @param ... The format args.
*/
bool rtLinuxSysFsExists(const char *pszFormat, ...)
{
return fRet;
}
/**
* Opens a sysfs file.
*
* @returns The file descriptor. -1 and errno on failure.
* @param pszFormat The name format, without "/sys/".
* @param va The format args.
*/
{
/*
* Construct the filename and call open.
*/
char szFilename[128];
}
/**
* Opens a sysfs file.
*
* @returns The file descriptor. -1 and errno on failure.
* @param pszFormat The name format, without "/sys/".
* @param ... The format args.
*/
int rtLinuxSysFsOpen(const char *pszFormat, ...)
{
return fd;
}
/**
* Closes a file opened with rtLinuxSysFsOpen or rtLinuxSysFsOpenV.
*
* @param fd
*/
void rtLinuxSysFsClose(int fd)
{
int iSavedErrno = errno;
errno = iSavedErrno;
}
/**
* Closes a file opened with rtLinuxSysFsOpen or rtLinuxSysFsOpenV.
*
* @returns The number of bytes read. -1 and errno on failure.
* @param fd The file descriptor returned by rtLinuxSysFsOpen or rtLinuxSysFsOpenV.
* @param pszBuf Where to store the string.
* @param cchBuf The size of the buffer. Must be at least 2 bytes.
*/
{
return cchRead;
}
/**
* Reads a sysfs file.
*
* @returns 64-bit signed value on success, -1 and errno on failure.
* @param uBase The number base, 0 for autodetect.
* @param pszFormat The filename format, without "/sys/".
* @param va Format args.
*/
{
if (fd == -1)
return -1;
char szNum[128];
if (cchNum > 0)
{
if (RT_FAILURE(rc))
{
i64Ret = -1;
}
}
else if (cchNum == 0)
return i64Ret;
}
/**
* Reads a sysfs file.
*
* @returns 64-bit signed value on success, -1 and errno on failure.
* @param uBase The number base, 0 for autodetect.
* @param pszFormat The filename format, without "/sys/".
* @param ... Format args.
*/
{
return i64Ret;
}
/**
* Internal worker that determins the max possible CPU count.
*
* @returns Max cpus.
*/
static RTCPUID rtMpLinuxMaxCpus(void)
{
#if 0 /* this doesn't do the right thing :-/ */
return cMax;
#else
if (!s_cMax)
{
int cMax = 1;
return cMax;
}
return s_cMax;
#endif
}
/**
*
* @returns CPU frequency.
*/
{
if (!f)
return 0;
char sz[256];
{
{
psz += 2;
if (RT_SUCCESS(rc))
idCpuFound = iCpu;
}
else if ( idCpu == idCpuFound
{
psz += 2;
int64_t v;
if (RT_SUCCESS(rc))
{
freq = v;
break;
}
}
}
fclose(f);
return freq;
}
/** @todo RTmpCpuId(). */
{
}
{
}
{
return rtMpLinuxMaxCpus() - 1;
}
{
/** @todo check if there is a simpler interface than this... */
if ( i == -1
{
i = 1;
}
return i != 0 && i != -1;
}
{
/** @todo check this up with hotplugging! */
}
{
if (RTMpIsCpuPossible(idCpu))
return pSet;
}
{
RTMpGetSet(&Set);
return RTCpuSetCount(&Set);
}
{
if (RTMpIsCpuOnline(idCpu))
return pSet;
}
{
return RTCpuSetCount(&Set);
}
{
int64_t kHz = rtLinuxSysFsReadIntFile(0, "devices/system/cpu/cpu%d/cpufreq/cpuinfo_cur_freq", (int)idCpu);
if (kHz == -1)
{
else
kHz = 0;
}
}
{
int64_t kHz = rtLinuxSysFsReadIntFile(0, "devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", (int)idCpu);
if (kHz == -1)
}