mp.h revision 3c1c973ceaac2fdf7f3b0305f57ae30531acb9cc
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync/** @file
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * innotek Portable Runtime - Multiprocessor.
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync */
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync/*
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * Copyright (C) 2008 innotek GmbH
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync *
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * available from http://www.virtualbox.org. This file is free software;
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * you can redistribute it and/or modify it under the terms of the GNU
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * General Public License (GPL) as published by the Free Software
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync *
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * The contents of this file may alternatively be used under the terms
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * of the Common Development and Distribution License Version 1.0
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * VirtualBox OSE distribution, in which case the provisions of the
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * CDDL are applicable instead of those of the GPL.
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync *
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * You may elect to license modified versions of this file under the
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * terms and conditions of either the GPL or the CDDL or both.
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync */
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync#ifndef ___iprt_mp_h
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync#define ___iprt_mp_h
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync#include <iprt/cdefs.h>
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync#include <iprt/types.h>
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync__BEGIN_DECLS
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync/** @defgroup grp_rt_mp RTMp - Multiprocessor
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @ingroup grp_rt
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @{
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync */
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync/** Maximum number of CPUs we support in one system.
6ffe15b8a1730e56a0a818da51c4e7a115da5763vboxsync * @remarks The current limit in Windows (affinity mask)
6ffe15b8a1730e56a0a818da51c4e7a115da5763vboxsync */
6ffe15b8a1730e56a0a818da51c4e7a115da5763vboxsync#define RT_MP_MAX_CPU 64
6ffe15b8a1730e56a0a818da51c4e7a115da5763vboxsync
6ffe15b8a1730e56a0a818da51c4e7a115da5763vboxsync
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync/**
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * Gets the identifier of the CPU executing the call.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync *
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * When called from a system mode where scheduling is active, like ring-3 or
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * kernel mode with interrupts enabled on some systems, no assumptions should
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * be made about the current CPU when the call returns.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync *
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @returns CPU Id.
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync */
165b506f4c024dabd5a4caaeda31c66712d154eavboxsyncRTDECL(RTCPUID) RTMpCpuId(void);
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync/**
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync * Checks if a CPU is online or not.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync *
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync * @returns true/false accordingly.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync * @param idCpu The identifier of the CPU.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync */
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsyncRTDECL(bool) RTMpIsCpuOnline(RTCPUID idCpu);
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync/**
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync * Checks if a CPU exist or not / validates a CPU id.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync *
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync * @returns true/false accordingly.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync * @param idCpu The identifier of the CPU.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync */
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsyncRTDECL(bool) RTMpDoesCpuExist(RTCPUID idCpu);
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync
5c1381fc884d30a749517579368ff6cb4b43e809vboxsync/**
5c1381fc884d30a749517579368ff6cb4b43e809vboxsync * Converts a CPU identifier to a CPU set index.
5c1381fc884d30a749517579368ff6cb4b43e809vboxsync *
5c1381fc884d30a749517579368ff6cb4b43e809vboxsync * @returns The CPU set index on success, -1 on failure.
5c1381fc884d30a749517579368ff6cb4b43e809vboxsync * @param idCpu The identifier of the CPU.
5c1381fc884d30a749517579368ff6cb4b43e809vboxsync */
5c1381fc884d30a749517579368ff6cb4b43e809vboxsyncRTDECL(int) RTMpCpuIdToSetIndex(RTCPUID idCpu);
5c1381fc884d30a749517579368ff6cb4b43e809vboxsync
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync/**
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync * Gets set of the CPUs present in the system.
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync *
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync * This set includes CPUs in any state, see RTGetOnlineSet()
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync * for an alternative.
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync *
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync * @returns pSet.
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync * @param pSet Where to put the set.
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync */
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsyncRTDECL(PRTCPUSET) RTMpGetSet(PRTCPUSET pSet);
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync/**
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync * Get the count of CPUs presetn in the system.
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync *
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync * @return The count.
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync */
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsyncRTDECL(RTCPUID) RTMpGetCount(void);
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync/**
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync * Gets set of the CPUs present that are currently online.
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync *
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync * @returns pSet.
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync * @param pSet Where to put the set.
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync */
3c1c973ceaac2fdf7f3b0305f57ae30531acb9ccvboxsyncRTDECL(PRTCPUSET) RTMpGetOnlineSet(PRTCPUSET pSet);
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync/**
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync * Get the count of CPUs that are currently online.
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync *
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync * @return The count.
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsync */
ab7139411cba3600213877c953b69fc11a7ef0cfvboxsyncRTDECL(RTCPUID) RTMpGetOnlineCount(void);
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync#ifdef IN_RING0
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync/**
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * Worker function passed to RTMpOnAll, RTMpOnOthers and RTMpOnSpecific that
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * is to be called on the target cpus.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync *
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @param idCpu The identifier for the CPU the function is called on.
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @param pvUser1 The 1st user argument.
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @param pvUser2 The 2nd user argument.
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync */
e0dec59adb362e8486c0622785420ad10e720972vboxsynctypedef DECLCALLBACK(void) FNRTMPWORKER(RTCPUID idCpu, void *pvUser1, void *pvUser2);
e0dec59adb362e8486c0622785420ad10e720972vboxsync/** Pointer to a FNRTMPWORKER. */
e0dec59adb362e8486c0622785420ad10e720972vboxsynctypedef FNRTMPWORKER *PFNRTMPWORKER;
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync/**
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * Executes a function on each (online) CPU in the system.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync *
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @returns IPRT status code.
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @retval VINF_SUCCESS on success.
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @retval VERR_NOT_SUPPORTED if this kind of operation isn't supported by the system.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync *
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @param pfnWorker The worker function.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync * @param pvUser1 The first user argument for the worker.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync * @param pvUser2 The second user argument for the worker.
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync *
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @remarks The execution isn't in any way guaranteed to be simultaneous,
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * it might even be serial (cpu by cpu).
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync */
e0dec59adb362e8486c0622785420ad10e720972vboxsyncRTDECL(int) RTMpOnAll(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2);
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync/**
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * Executes a function on a all other (online) CPUs in the system.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync *
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @returns IPRT status code.
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @retval VINF_SUCCESS on success.
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @retval VERR_NOT_SUPPORTED if this kind of operation isn't supported by the system.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync *
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @param pfnWorker The worker function.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync * @param pvUser1 The first user argument for the worker.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync * @param pvUser2 The second user argument for the worker.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync *
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @remarks The execution isn't in any way guaranteed to be simultaneous,
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * it might even be serial (cpu by cpu).
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync */
e0dec59adb362e8486c0622785420ad10e720972vboxsyncRTDECL(int) RTMpOnOthers(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2);
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync/**
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * Executes a function on a specific CPU in the system.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync *
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @returns IPRT status code.
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @retval VINF_SUCCESS on success.
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @retval VERR_NOT_SUPPORTED if this kind of operation isn't supported by the system.
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @retval VERR_CPU_OFFLINE if the CPU is offline.
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @retval VERR_CPU_NOT_FOUND if the CPU wasn't found.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync *
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @param idCpu The id of the CPU.
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync * @param pfnWorker The worker function.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync * @param pvUser1 The first user argument for the worker.
2c19fa7a35e93931f995c196426585b16f8bf2c0vboxsync * @param pvUser2 The second user argument for the worker.
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync */
e0dec59adb362e8486c0622785420ad10e720972vboxsyncRTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2);
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync#endif /* IN_RING0 */
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync/** @} */
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync__END_DECLS
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync#endif
165b506f4c024dabd5a4caaeda31c66712d154eavboxsync