mp-win.cpp revision 1b396f7f5a76d66e62fc9d8e66dcbe8e7bf72039
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync/* $Id$ */
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync/** @file
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * IPRT - Multiprocessor, Windows.
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync */
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync/*
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2006-2007 Oracle Corporation
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync *
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync * available from http://www.virtualbox.org. This file is free software;
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync * you can redistribute it and/or modify it under the terms of the GNU
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync * General Public License (GPL) as published by the Free Software
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync *
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync * The contents of this file may alternatively be used under the terms
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync * of the Common Development and Distribution License Version 1.0
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync * VirtualBox OSE distribution, in which case the provisions of the
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync * CDDL are applicable instead of those of the GPL.
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync *
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync * You may elect to license modified versions of this file under the
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync * terms and conditions of either the GPL or the CDDL or both.
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync */
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync/*******************************************************************************
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync* Header Files *
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync*******************************************************************************/
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync#define LOG_GROUP RTLOGGROUP_SYSTEM
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync#include <Windows.h>
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync#include <iprt/mp.h>
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync#include <iprt/cpuset.h>
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync#include <iprt/assert.h>
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
c2ac210bd84591123bb8803712887e2b016cb78fvboxsyncAssertCompile(MAXIMUM_PROCESSORS <= RTCPUSET_MAX_CPUS);
c2ac210bd84591123bb8803712887e2b016cb78fvboxsync
c2ac210bd84591123bb8803712887e2b016cb78fvboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync/** @todo RTmpCpuId(). */
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsyncRTDECL(int) RTMpCpuIdToSetIndex(RTCPUID idCpu)
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync{
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync return idCpu < MAXIMUM_PROCESSORS ? idCpu : -1;
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync}
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsyncRTDECL(RTCPUID) RTMpCpuIdFromSetIndex(int iCpu)
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync{
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync return (unsigned)iCpu < MAXIMUM_PROCESSORS ? iCpu : NIL_RTCPUID;
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync}
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsyncRTDECL(RTCPUID) RTMpGetMaxCpuId(void)
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync{
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync return MAXIMUM_PROCESSORS - 1;
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync}
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsyncRTDECL(bool) RTMpIsCpuOnline(RTCPUID idCpu)
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync{
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync RTCPUSET Set;
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync return RTCpuSetIsMember(RTMpGetOnlineSet(&Set), idCpu);
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync}
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
2a560b28131ee7efa5b73a9e9cbfdb08eae28624vboxsyncRTDECL(bool) RTMpIsCpuPossible(RTCPUID idCpu)
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync{
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync RTCPUSET Set;
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync return RTCpuSetIsMember(RTMpGetSet(&Set), idCpu);
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync}
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsyncRTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet)
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync{
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync RTCPUID idCpu = RTMpGetCount();
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync RTCpuSetEmpty(pSet);
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync while (idCpu-- > 0)
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync RTCpuSetAdd(pSet, idCpu);
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync return pSet;
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync}
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsyncRTDECL(RTCPUID) RTMpGetCount(void)
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync{
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync SYSTEM_INFO SysInfo;
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync GetSystemInfo(&SysInfo);
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync Assert((RTCPUID)SysInfo.dwNumberOfProcessors == SysInfo.dwNumberOfProcessors);
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync return SysInfo.dwNumberOfProcessors;
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync}
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsyncRTDECL(PRTCPUSET) RTMpGetOnlineSet(PRTCPUSET pSet)
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync{
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync SYSTEM_INFO SysInfo;
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync GetSystemInfo(&SysInfo);
1b396f7f5a76d66e62fc9d8e66dcbe8e7bf72039vboxsync/** @todo port to W2K8 / W7 w/ > 64 CPUs & grouping. */
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync return RTCpuSetFromU64(pSet, SysInfo.dwActiveProcessorMask);
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync}
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsyncRTDECL(RTCPUID) RTMpGetOnlineCount(void)
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync{
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync RTCPUSET Set;
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync RTMpGetOnlineSet(&Set);
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync return RTCpuSetCount(&Set);
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync}
04008c8439b294c40e670b4ea71471fa71ef9d69vboxsync