1 | /* $Id: mpnotification-r0drv-linux.c 28800 2010-04-27 08:22:32Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Multiprocessor Event Notifications, Ring-0 Driver, Linux.
|
---|
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 | /*******************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *******************************************************************************/
|
---|
31 | #include "the-linux-kernel.h"
|
---|
32 | #include "internal/iprt.h"
|
---|
33 |
|
---|
34 | #include <iprt/mp.h>
|
---|
35 | #include <iprt/err.h>
|
---|
36 | #include <iprt/cpuset.h>
|
---|
37 | #include "r0drv/mp-r0drv.h"
|
---|
38 |
|
---|
39 |
|
---|
40 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 71) && defined(CONFIG_SMP)
|
---|
41 |
|
---|
42 | /*******************************************************************************
|
---|
43 | * Internal Functions *
|
---|
44 | *******************************************************************************/
|
---|
45 | static int rtMpNotificationLinuxCallback(struct notifier_block *pNotifierBlock, unsigned long ulNativeEvent, void *pvCpu);
|
---|
46 |
|
---|
47 |
|
---|
48 | /*******************************************************************************
|
---|
49 | * Global Variables *
|
---|
50 | *******************************************************************************/
|
---|
51 | /**
|
---|
52 | * The notifier block we use for registering the callback.
|
---|
53 | */
|
---|
54 | static struct notifier_block g_NotifierBlock =
|
---|
55 | {
|
---|
56 | .notifier_call = rtMpNotificationLinuxCallback,
|
---|
57 | .next = NULL,
|
---|
58 | .priority = 0
|
---|
59 | };
|
---|
60 |
|
---|
61 | # ifdef CPU_DOWN_FAILED
|
---|
62 | /**
|
---|
63 | * The set of CPUs we've seen going offline recently.
|
---|
64 | */
|
---|
65 | static RTCPUSET g_MpPendingOfflineSet;
|
---|
66 | # endif
|
---|
67 |
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * The native callback.
|
---|
71 | *
|
---|
72 | * @returns 0.
|
---|
73 | * @param pNotifierBlock Pointer to g_NotifierBlock.
|
---|
74 | * @param ulNativeEvent The native event.
|
---|
75 | * @param pvCpu The cpu id cast into a pointer value.
|
---|
76 | */
|
---|
77 | static int rtMpNotificationLinuxCallback(struct notifier_block *pNotifierBlock, unsigned long ulNativeEvent, void *pvCpu)
|
---|
78 | {
|
---|
79 | RTCPUID idCpu = (uintptr_t)pvCpu;
|
---|
80 | NOREF(pNotifierBlock);
|
---|
81 |
|
---|
82 | /*
|
---|
83 | * Note that redhat/CentOS ported _some_ of the FROZEN macros
|
---|
84 | * back to their 2.6.18-92.1.10.el5 kernel but actually don't
|
---|
85 | * use them. Thus we have to test for both CPU_TASKS_FROZEN and
|
---|
86 | * the individual event variants.
|
---|
87 | */
|
---|
88 |
|
---|
89 | /* ASSUMES iCpu == RTCPUID */
|
---|
90 | switch (ulNativeEvent)
|
---|
91 | {
|
---|
92 | /*
|
---|
93 | * Pick up online events or failures to go offline.
|
---|
94 | * Ignore failure events for CPUs we didn't see go offline.
|
---|
95 | */
|
---|
96 | # ifdef CPU_DOWN_FAILED
|
---|
97 | case CPU_DOWN_FAILED:
|
---|
98 | # if defined(CPU_TASKS_FROZEN) && defined(CPU_DOWN_FAILED_FROZEN)
|
---|
99 | case CPU_DOWN_FAILED_FROZEN:
|
---|
100 | # endif
|
---|
101 | if (!RTCpuSetIsMember(&g_MpPendingOfflineSet, idCpu))
|
---|
102 | return 0;
|
---|
103 | /* fall thru */
|
---|
104 | # endif
|
---|
105 | case CPU_ONLINE:
|
---|
106 | # if defined(CPU_TASKS_FROZEN) && defined(CPU_ONLINE_FROZEN)
|
---|
107 | case CPU_ONLINE_FROZEN:
|
---|
108 | # endif
|
---|
109 | # ifdef CPU_DOWN_FAILED
|
---|
110 | RTCpuSetDel(&g_MpPendingOfflineSet, idCpu);
|
---|
111 | # endif
|
---|
112 | rtMpNotificationDoCallbacks(RTMPEVENT_ONLINE, idCpu);
|
---|
113 | break;
|
---|
114 |
|
---|
115 | /*
|
---|
116 | * Pick the earlies possible offline event.
|
---|
117 | * The only important thing here is that we get the event and that
|
---|
118 | * it's exactly one.
|
---|
119 | */
|
---|
120 | # ifdef CPU_DOWN_PREPARE
|
---|
121 | case CPU_DOWN_PREPARE:
|
---|
122 | # if defined(CPU_TASKS_FROZEN) && defined(CPU_DOWN_PREPARE_FROZEN)
|
---|
123 | case CPU_DOWN_PREPARE_FROZEN:
|
---|
124 | # endif
|
---|
125 | # else
|
---|
126 | case CPU_DEAD:
|
---|
127 | # if defined(CPU_TASKS_FROZEN) && defined(CPU_DEAD_FROZEN)
|
---|
128 | case CPU_DEAD_FROZEN:
|
---|
129 | # endif
|
---|
130 | # endif
|
---|
131 | rtMpNotificationDoCallbacks(RTMPEVENT_OFFLINE, idCpu);
|
---|
132 | # ifdef CPU_DOWN_FAILED
|
---|
133 | RTCpuSetAdd(&g_MpPendingOfflineSet, idCpu);
|
---|
134 | # endif
|
---|
135 | break;
|
---|
136 | }
|
---|
137 |
|
---|
138 | return NOTIFY_DONE;
|
---|
139 | }
|
---|
140 |
|
---|
141 |
|
---|
142 | int rtR0MpNotificationNativeInit(void)
|
---|
143 | {
|
---|
144 | int rc;
|
---|
145 |
|
---|
146 | # ifdef CPU_DOWN_FAILED
|
---|
147 | RTCpuSetEmpty(&g_MpPendingOfflineSet);
|
---|
148 | # endif
|
---|
149 |
|
---|
150 | rc = register_cpu_notifier(&g_NotifierBlock);
|
---|
151 | AssertMsgReturn(!rc, ("%d\n", rc), RTErrConvertFromErrno(rc));
|
---|
152 | return VINF_SUCCESS;
|
---|
153 | }
|
---|
154 |
|
---|
155 |
|
---|
156 | void rtR0MpNotificationNativeTerm(void)
|
---|
157 | {
|
---|
158 | unregister_cpu_notifier(&g_NotifierBlock);
|
---|
159 | }
|
---|
160 |
|
---|
161 | #else /* Not supported / Not needed */
|
---|
162 |
|
---|
163 | int rtR0MpNotificationNativeInit(void)
|
---|
164 | {
|
---|
165 | return VINF_SUCCESS;
|
---|
166 | }
|
---|
167 |
|
---|
168 | void rtR0MpNotificationNativeTerm(void)
|
---|
169 | {
|
---|
170 | }
|
---|
171 |
|
---|
172 | #endif /* Not supported / Not needed */
|
---|
173 |
|
---|