mp-linux.cpp revision b6e4d4f558446e1e13101ca3313b7bdf287dec36
/* $Id$ */
/** @file
* IPRT - Multiprocessor, Linux.
*/
/*
* Copyright (C) 2006-2010 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_SYSTEM
#include <stdio.h>
#include <errno.h>
/**
* Internal worker that determines 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 (!pFile)
return 0;
char sz[256];
{
char *psz;
{
psz += 2;
if (RT_SUCCESS(rc))
idCpuFound = iCpu;
}
else if ( idCpu == idCpuFound
{
psz += 2;
int64_t v;
if (RT_SUCCESS(rc))
{
Frequency = v;
break;
}
}
}
return Frequency;
}
/** @todo RTmpCpuId(). */
{
}
{
}
{
return rtMpLinuxMaxCpus() - 1;
}
{
/** @todo check if there is a simpler interface than this... */
if ( i == -1
{
* (int)idCpu));
* Unfortunately, the online file wasn't always world readable (centos
* 2.6.18-164). */
i = 1;
}
return i != 0 && i != -1;
}
{
/** @todo check this up with hotplugging! */
}
{
if (RTMpIsCpuPossible(idCpu))
return pSet;
}
{
RTMpGetSet(&Set);
return RTCpuSetCount(&Set);
}
{
{
if (RTMpIsCpuPossible(idCpu))
{
uint32_t idCore = (uint32_t)RTLinuxSysFsReadIntFile(0, "devices/system/cpu/cpu%d/topology/core_id", (int)idCpu);
uint32_t i;
for (i = 0; i < cCores; i++)
break;
if (i >= cCores)
}
}
return cCores;
}
{
if (RTMpIsCpuOnline(idCpu))
return pSet;
}
{
return RTCpuSetCount(&Set);
}
{
{
if (RTMpIsCpuOnline(idCpu))
{
uint32_t idCore = (uint32_t)RTLinuxSysFsReadIntFile(0, "devices/system/cpu/cpu%d/topology/core_id", (int)idCpu);
uint32_t i;
for (i = 0; i < cCores; i++)
break;
if (i >= cCores)
}
}
return cCores;
}
{
int64_t kHz = RTLinuxSysFsReadIntFile(0, "devices/system/cpu/cpu%d/cpufreq/cpuinfo_cur_freq", (int)idCpu);
if (kHz == -1)
{
/*
* The file may be just unreadable - in that case use plan B, i.e.
* cpuinfo_cur_freq doesn't exist then the speed won't change, and
* thus cur == max. If it does exist then cpuinfo contains the
* current frequency.
*/
}
}
{
int64_t kHz = RTLinuxSysFsReadIntFile(0, "devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", (int)idCpu);
if (kHz == -1)
{
/*
* would provide current frequency information, which is wrong.
*/
else
kHz = 0;
}
}