VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/solaris/mpnotification-r0drv-solaris.c@ 42586

Last change on this file since 42586 was 40968, checked in by vboxsync, 13 years ago

Runtime/r0drv/solaris: VBI integrate, move files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1/* $Id: mpnotification-r0drv-solaris.c 40968 2012-04-17 17:35:53Z vboxsync $ */
2/** @file
3 * IPRT - Multiprocessor Event Notifications, Ring-0 Driver, Solaris.
4 */
5
6/*
7 * Copyright (C) 2008 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#include "the-solaris-kernel.h"
31#include "internal/iprt.h"
32
33#include <iprt/err.h>
34#include <iprt/mp.h>
35#include <iprt/cpuset.h>
36#include <iprt/string.h>
37#include <iprt/thread.h>
38#include "r0drv/mp-r0drv.h"
39
40
41/*******************************************************************************
42* Global Variables *
43*******************************************************************************/
44/** Whether CPUs are being watched or not. */
45static volatile bool g_fSolCpuWatch = false;
46/** Set of online cpus that is maintained by the MP callback.
47 * This avoids locking issues querying the set from the kernel as well as
48 * eliminating any uncertainty regarding the online status during the
49 * callback. */
50RTCPUSET g_rtMpSolCpuSet;
51
52/**
53 * Internal solaris representation for watching CPUs.
54 */
55typedef struct RTMPSOLWATCHCPUS
56{
57 /** Function pointer to Mp worker. */
58 PFNRTMPWORKER pfnWorker;
59 /** Argument to pass to the Mp worker. */
60 void *pvArg;
61} RTMPSOLWATCHCPUS;
62typedef RTMPSOLWATCHCPUS *PRTMPSOLWATCHCPUS;
63
64
65/**
66 * PFNRTMPWORKER worker for executing Mp events on the target CPU.
67 *
68 * @param idCpu The current CPU Id.
69 * @param pvArg Opaque pointer to event type (online/offline).
70 * @param pvIgnored1 Ignored.
71 */
72static void rtMpNotificationSolOnCurrentCpu(RTCPUID idCpu, void *pvArg, void *pvIgnored1)
73{
74 NOREF(pvIgnored1);
75 NOREF(idCpu);
76
77 PRTMPARGS pArgs = (PRTMPARGS)pvArg;
78 AssertRelease(pArgs && pArgs->idCpu == RTMpCpuId());
79 Assert(pArgs->pvUser1);
80 Assert(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));
81
82 RTMPEVENT enmMpEvent = *(RTMPEVENT *)pArgs->pvUser1;
83 rtMpNotificationDoCallbacks(enmMpEvent, pArgs->idCpu);
84}
85
86
87/**
88 * Solaris callback function for Mp event notification.
89 *
90 * @param CpuState The current event/state of the CPU.
91 * @param iCpu Which CPU is this event fore.
92 * @param pvArg Ignored.
93 *
94 * @remarks This function assumes index == RTCPUID.
95 * @returns Solaris error code.
96 */
97static int rtMpNotificationCpuEvent(cpu_setup_t CpuState, int iCpu, void *pvArg)
98{
99 RTMPEVENT enmMpEvent;
100
101 RTTHREADPREEMPTSTATE PreemptState = RTTHREADPREEMPTSTATE_INITIALIZER;
102 RTThreadPreemptDisable(&PreemptState);
103
104 /*
105 * Update our CPU set structures first regardless of whether we've been
106 * scheduled on the right CPU or not, this is just atomic accounting.
107 */
108 if (CpuState == CPU_ON)
109 {
110 enmMpEvent = RTMPEVENT_ONLINE;
111 RTCpuSetAdd(&g_rtMpSolCpuSet, iCpu);
112 }
113 else if (CpuState == CPU_OFF)
114 {
115 enmMpEvent = RTMPEVENT_OFFLINE;
116 RTCpuSetDel(&g_rtMpSolCpuSet, iCpu);
117 }
118 else
119 return 0;
120
121 /*
122 * Since we don't absolutely need to do CPU bound code in any of the CPU offline
123 * notification hooks, run it on the current CPU. Scheduling a callback to execute
124 * on the CPU going offline at this point is too late and will not work reliably.
125 */
126 bool fRunningOnTargetCpu = iCpu == RTMpCpuId();
127 if ( fRunningOnTargetCpu == true
128 || enmMpEvent == RTMPEVENT_OFFLINE)
129 {
130 rtMpNotificationDoCallbacks(enmMpEvent, iCpu);
131 }
132 else
133 {
134 /*
135 * We're not on the target CPU, schedule (synchronous) the event notification callback
136 * to run on the target CPU i.e. the CPU that was online'd.
137 */
138 RTMPARGS Args;
139 RT_ZERO(Args);
140 Args.pvUser1 = &enmMpEvent;
141 Args.pvUser2 = NULL;
142 Args.idCpu = iCpu;
143 RTMpOnSpecific(iCpu, rtMpNotificationSolOnCurrentCpu, &Args, NULL /* pvIgnored1 */);
144 }
145
146 RTThreadPreemptRestore(&PreemptState);
147
148 NOREF(pvArg);
149 return 0;
150}
151
152
153DECLHIDDEN(int) rtR0MpNotificationNativeInit(void)
154{
155 if (ASMAtomicReadBool(&g_fSolCpuWatch) == true)
156 return VERR_WRONG_ORDER;
157
158 /*
159 * Register the callback building the online cpu set as we do so.
160 */
161 RTCpuSetEmpty(&g_rtMpSolCpuSet);
162
163 mutex_enter(&cpu_lock);
164 register_cpu_setup_func(rtMpNotificationCpuEvent, NULL /* pvArg */);
165
166 for (int i = 0; i < (int)RTMpGetCount(); ++i)
167 if (cpu_is_online(cpu[i]))
168 rtMpNotificationCpuEvent(CPU_ON, i, NULL /* pvArg */);
169
170 ASMAtomicWriteBool(&g_fSolCpuWatch, true);
171 mutex_exit(&cpu_lock);
172
173 return VINF_SUCCESS;
174}
175
176
177DECLHIDDEN(void) rtR0MpNotificationNativeTerm(void)
178{
179 if (ASMAtomicReadBool(&g_fSolCpuWatch) == true)
180 {
181 mutex_enter(&cpu_lock);
182 unregister_cpu_setup_func(rtMpNotificationCpuEvent, NULL /* pvArg */);
183 ASMAtomicWriteBool(&g_fSolCpuWatch, false);
184 mutex_exit(&cpu_lock);
185 }
186}
187
Note: See TracBrowser for help on using the repository browser.

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