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