VirtualBox

Changeset 9309 in vbox


Ignore:
Timestamp:
Jun 2, 2008 3:11:59 PM (16 years ago)
Author:
vboxsync
Message:

Added RTMpNotificationRegister/Deregister that provides notification events when a cpu goes offline or comes online. (not tested)

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/cpuset.h

    r8245 r9309  
    3333#include <iprt/types.h>
    3434#include <iprt/mp.h> /* RTMpCpuIdToSetIndex */
     35#include <iprt/asm.h>
    3536
    3637
     
    8182 * @param   pSet    Pointer to the set.
    8283 * @param   idCpu   The identifier of the CPU to add.
     84 * @remarks The modification is atomic.
    8385 */
    8486DECLINLINE(int) RTCpuSetAdd(PRTCPUSET pSet, RTCPUID idCpu)
     
    8789    if (RT_UNLIKELY(iCpu < 0))
    8890        return -1;
    89     *pSet |= RT_BIT_64(iCpu);
     91    ASMAtomicBitSet(pSet, iCpu);
    9092    return 0;
    9193}
     
    98100 * @param   pSet    Pointer to the set.
    99101 * @param   idCpu   The identifier of the CPU to delete.
     102 * @remarks The modification is atomic.
    100103 */
    101104DECLINLINE(int) RTCpuSetDel(PRTCPUSET pSet, RTCPUID idCpu)
     
    104107    if (RT_UNLIKELY(iCpu < 0))
    105108        return -1;
    106     *pSet &= ~RT_BIT_64(iCpu);
     109    ASMAtomicBitClear(pSet, iCpu);
    107110    return 0;
    108111}
     
    115118 * @param   pSet    Pointer to the set.
    116119 * @param   idCpu   The identifier of the CPU to look for.
     120 * @remarks The test is atomic.
    117121 */
    118122DECLINLINE(bool) RTCpuSetIsMember(PCRTCPUSET pSet, RTCPUID idCpu)
     
    121125    if (RT_UNLIKELY(iCpu < 0))
    122126        return false;
    123     return !!(*pSet & RT_BIT_64(iCpu));
     127    return ASMBitTest((volatile void *)pSet, iCpu);
    124128}
    125129
  • trunk/include/iprt/mp.h

    r8245 r9309  
    196196RTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2);
    197197
     198
     199/**
     200 * MP event, see FNRTMPNOTIFICATION.
     201 */
     202typedef enum RTMPEVENT
     203{
     204    /** The CPU goes online. */
     205    RTMPEVENT_ONLINE = 1,
     206    /** The CPU goes offline. */
     207    RTMPEVENT_OFFLINE
     208} RTMPEVENT;
     209
     210/**
     211 * Notification callback.
     212 *
     213 * The context this is called in differs a bit from platform to
     214 * platform, so be careful while in here.
     215 *
     216 * @param   idCpu       The CPU this applies to.
     217 * @param   enmEvent    The event.
     218 * @param   pvUser      The user argument.
     219 */
     220typedef DECLCALLBACK(void) FNRTMPNOTIFICATION(RTMPEVENT enmEvent, RTCPUID idCpu, void *pvUser);
     221/** Pointer to a FNRTMPNOTIFICATION(). */
     222typedef FNRTMPNOTIFICATION *PFNRTMPNOTIFICATION;
     223
     224/**
     225 * Registers a notification callback for cpu events.
     226 *
     227 * On platforms which doesn't do cpu offline/online events this API
     228 * will just be a no-op that pretends to work.
     229 *
     230 * @returns IPRT status code.
     231 * @retval  VINF_SUCCESS on success.
     232 * @retval  VERR_NO_MEMORY if a registration record cannot be allocated.
     233 * @retval  VERR_ALREADY_EXISTS if the pfnCallback and pvUser already exist
     234 *          in the callback list.
     235 *
     236 * @param   pfnCallback     The callback.
     237 * @param   pvUser          The user argument to the callback function.
     238 */
     239RTDECL(int) RTMpNotificationRegister(PFNRTMPNOTIFICATION pfnCallback, void *pvUser);
     240
     241/**
     242 * This deregisters a notification callback registered via RTMpNotificationRegister().
     243 *
     244 * The pfnCallback and pvUser arguments must be identical to the registration call
     245 * of we won't find the right entry.
     246 *
     247 * @returns IPRT status code.
     248 * @retval  VINF_SUCCESS on success.
     249 * @retval  VERR_NOT_FOUND if no matching entry was found.
     250 *
     251 * @param   pfnCallback     The callback.
     252 * @param   pvUser          The user argument to the callback function.
     253 */
     254RTDECL(int) RTMpNotificationDeregister(PFNRTMPNOTIFICATION pfnCallback, void *pvUser);
     255
     256/**
     257 * Initializes the multiprocessor event notifcations.
     258 *
     259 * This must be called before calling RTMpNotificationRegister(). This is an
     260 * inconvenice caused Visual C++ not implmenting weak externals.
     261 *
     262 * @returns IPRT status code.
     263 * @param   pvOS            Reserved, pass NULL.
     264 */
     265RTR0DECL(int) RTR0MpNotificationInit(void *pvOS);
     266
     267
     268/**
     269 * Terminates the multiprocessor event notifcations.
     270 *
     271 * The number of RTR0MpNotificationInit calls must match the calls to this
     272 * function exactly.
     273 *
     274 * @returns IPRT status code.
     275 * @param   pvOS            Reserved, pass NULL.
     276 */
     277RTR0DECL(void) RTR0MpNotificationTerm(void *pvOS);
     278
    198279#endif /* IN_RING0 */
    199280
  • trunk/src/VBox/Runtime/Makefile.kmk

    r9236 r9309  
    923923        r0drv/linux/memobj-r0drv-linux.c \
    924924        r0drv/linux/mp-r0drv-linux.c \
     925        r0drv/linux/mpnotification-r0drv-linux.c \
    925926        r0drv/linux/process-r0drv-linux.c \
    926927        r0drv/linux/RTLogWriteDebugger-r0drv-linux.c \
     
    931932        r0drv/linux/thread-r0drv-linux.c \
    932933        r0drv/linux/time-r0drv-linux.c \
    933         r0drv/memobj-r0drv.cpp
     934        r0drv/memobj-r0drv.cpp \
     935        r0drv/mpnotification-r0drv.c
    934936## @todo thread2-r0drv-linux.c, timer-r0drv-linux.c and assert-r0drv-linux.c
     937#       r0drv/linux/timer-r0drv-linux.c \
    935938
    936939RuntimeR0Drv_SOURCES.win = \
     
    940943        common/string/strpbrk.cpp \
    941944        generic/RTAssertDoBreakpoint-generic.cpp \
    942         r0drv/nt/mp-r0drv-nt.cpp \
    943945        nt/RTErrConvertFromNtStatus.cpp \
    944946        r0drv/memobj-r0drv.cpp \
     947        r0drv/mpnotification-r0drv.c \
    945948        r0drv/nt/alloc-r0drv-nt.cpp \
    946949        r0drv/nt/initterm-r0drv-nt.cpp \
    947950        r0drv/nt/memobj-r0drv-nt.cpp \
     951        r0drv/nt/mp-r0drv-nt.cpp \
     952        r0drv/nt/mpnotification-r0drv-nt.cpp \
    948953        r0drv/nt/process-r0drv-nt.cpp \
    949954        r0drv/nt/RTLogWriteDebugger-r0drv-nt.cpp \
     
    983988        generic/timer-generic.cpp \
    984989        r0drv/generic/RTMpOn-r0drv-generic.cpp \
     990        r0drv/generic/mpnotification-r0drv-generic.cpp \
    985991        r0drv/darwin/alloc-r0drv-darwin.cpp \
    986992        r0drv/darwin/assert-r0drv-darwin.cpp \
     
    10281034        r0drv/memobj-r0drv.cpp \
    10291035        r0drv/generic/RTMpOn-r0drv-generic.cpp \
     1036        r0drv/generic/mpnotification-r0drv-generic.cpp \
    10301037        r0drv/os2/alloc-r0drv-os2.cpp \
    10311038        r0drv/os2/assert-r0drv-os2.cpp \
     
    10711078        generic/RTTimerCreate-generic.cpp \
    10721079        r0drv/generic/RTMpOn-r0drv-generic.cpp \
     1080        r0drv/generic/mpnotification-r0drv-generic.cpp \
    10731081        r0drv/freebsd/alloc-r0drv-freebsd.c \
    10741082        r0drv/freebsd/assert-r0drv-freebsd.c \
     
    10921100        generic/RTAssertDoBreakpoint-generic.cpp \
    10931101        generic/RTTimerCreate-generic.cpp \
    1094         r0drv/memobj-r0drv.cpp
     1102        r0drv/memobj-r0drv.cpp \
     1103        r0drv/mpnotification-r0drv.cpp \
     1104        r0drv/solaris/mpnotification-r0drv-solaris.cpp
    10951105
    10961106ifdef VBOX_WITH_SOLARIS_VBI
     
    11931203        generic/RTMpIsCpuOnline-generic.cpp \
    11941204        r0drv/generic/RTMpOn-r0drv-generic.cpp \
     1205        r0drv/generic/mpnotification-r0drv-generic.cpp \
    11951206        r0drv/solaris/alloc-r0drv-solaris.c \
    11961207        r0drv/solaris/assert-r0drv-solaris.c \
  • trunk/src/VBox/Runtime/r0drv/linux/the-linux-kernel.h

    r9238 r9309  
    8686#endif
    8787#include <linux/wait.h>
     88#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 71)
     89# include <linux/cpu.h>
     90#endif
    8891/* For the basic additions module */
    8992#include <linux/pci.h>
  • trunk/src/VBox/Runtime/r0drv/mp-r0drv.h

    r8245 r9309  
    4646
    4747/**
    48  * RTMpOn* argument packet used by the host specific callback 
     48 * RTMpOn* argument packet used by the host specific callback
    4949 * wrapper functions.
    5050 */
     
    6060typedef RTMPARGS *PRTMPARGS;
    6161
     62int rtR0MpNotificationNativeInit(void *pvOS);
     63void rtR0MpNotificationNativeTerm(void *pvOS);
     64void rtMpNotificationDoCallbacks(RTMPEVENT enmEvent, RTCPUID idCpu);
     65
    6266#endif
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette