1 | /* $Id: mpnotification-r0drv-solaris.c 54395 2015-02-23 17:34:01Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Multiprocessor Event Notifications, Ring-0 Driver, Solaris.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008-2015 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. */
|
---|
45 | static 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. */
|
---|
50 | RTCPUSET g_rtMpSolCpuSet;
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Internal solaris representation for watching CPUs.
|
---|
54 | */
|
---|
55 | typedef 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;
|
---|
62 | typedef RTMPSOLWATCHCPUS *PRTMPSOLWATCHCPUS;
|
---|
63 |
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Solaris callback function for Mp event notification.
|
---|
67 | *
|
---|
68 | * @returns Solaris error code.
|
---|
69 | * @param CpuState The current event/state of the CPU.
|
---|
70 | * @param iCpu Which CPU is this event for.
|
---|
71 | * @param pvArg Ignored.
|
---|
72 | *
|
---|
73 | * @remarks This function assumes index == RTCPUID.
|
---|
74 | * We may -not- be firing on the CPU going online/offline and called
|
---|
75 | * with preemption enabled.
|
---|
76 | */
|
---|
77 | static int rtMpNotificationCpuEvent(cpu_setup_t CpuState, int iCpu, void *pvArg)
|
---|
78 | {
|
---|
79 | RTMPEVENT enmMpEvent;
|
---|
80 |
|
---|
81 | /*
|
---|
82 | * Update our CPU set structures first regardless of whether we've been
|
---|
83 | * scheduled on the right CPU or not, this is just atomic accounting.
|
---|
84 | */
|
---|
85 | if (CpuState == CPU_ON)
|
---|
86 | {
|
---|
87 | enmMpEvent = RTMPEVENT_ONLINE;
|
---|
88 | RTCpuSetAdd(&g_rtMpSolCpuSet, iCpu);
|
---|
89 | }
|
---|
90 | else if (CpuState == CPU_OFF)
|
---|
91 | {
|
---|
92 | enmMpEvent = RTMPEVENT_OFFLINE;
|
---|
93 | RTCpuSetDel(&g_rtMpSolCpuSet, iCpu);
|
---|
94 | }
|
---|
95 | else
|
---|
96 | return 0;
|
---|
97 |
|
---|
98 | rtMpNotificationDoCallbacks(enmMpEvent, iCpu);
|
---|
99 | NOREF(pvArg);
|
---|
100 | return 0;
|
---|
101 | }
|
---|
102 |
|
---|
103 |
|
---|
104 | DECLHIDDEN(int) rtR0MpNotificationNativeInit(void)
|
---|
105 | {
|
---|
106 | if (ASMAtomicReadBool(&g_fSolCpuWatch) == true)
|
---|
107 | return VERR_WRONG_ORDER;
|
---|
108 |
|
---|
109 | /*
|
---|
110 | * Register the callback building the online cpu set as we do so.
|
---|
111 | */
|
---|
112 | RTCpuSetEmpty(&g_rtMpSolCpuSet);
|
---|
113 |
|
---|
114 | mutex_enter(&cpu_lock);
|
---|
115 | register_cpu_setup_func(rtMpNotificationCpuEvent, NULL /* pvArg */);
|
---|
116 |
|
---|
117 | for (int i = 0; i < (int)RTMpGetCount(); ++i)
|
---|
118 | if (cpu_is_online(cpu[i]))
|
---|
119 | rtMpNotificationCpuEvent(CPU_ON, i, NULL /* pvArg */);
|
---|
120 |
|
---|
121 | ASMAtomicWriteBool(&g_fSolCpuWatch, true);
|
---|
122 | mutex_exit(&cpu_lock);
|
---|
123 |
|
---|
124 | return VINF_SUCCESS;
|
---|
125 | }
|
---|
126 |
|
---|
127 |
|
---|
128 | DECLHIDDEN(void) rtR0MpNotificationNativeTerm(void)
|
---|
129 | {
|
---|
130 | if (ASMAtomicReadBool(&g_fSolCpuWatch) == true)
|
---|
131 | {
|
---|
132 | mutex_enter(&cpu_lock);
|
---|
133 | unregister_cpu_setup_func(rtMpNotificationCpuEvent, NULL /* pvArg */);
|
---|
134 | ASMAtomicWriteBool(&g_fSolCpuWatch, false);
|
---|
135 | mutex_exit(&cpu_lock);
|
---|
136 | }
|
---|
137 | }
|
---|
138 |
|
---|