VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/linux/mpnotification-r0drv-linux.c@ 37294

Last change on this file since 37294 was 37294, checked in by vboxsync, 14 years ago

Runtime/r0drv/linux: Fixed Mp event notifications.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 KB
Line 
1/* $Id: mpnotification-r0drv-linux.c 37294 2011-06-01 14:11:14Z 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 <iprt/thread.h>
38#include "r0drv/mp-r0drv.h"
39
40
41#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 5, 71) && defined(CONFIG_SMP)
42
43/*******************************************************************************
44* Internal Functions *
45*******************************************************************************/
46static int rtMpNotificationLinuxCallback(struct notifier_block *pNotifierBlock, unsigned long ulNativeEvent, void *pvCpu);
47
48
49/*******************************************************************************
50* Global Variables *
51*******************************************************************************/
52/**
53 * The notifier block we use for registering the callback.
54 */
55static struct notifier_block g_NotifierBlock =
56{
57 .notifier_call = rtMpNotificationLinuxCallback,
58 .next = NULL,
59 .priority = 0
60};
61
62# ifdef CPU_DOWN_FAILED
63/**
64 * The set of CPUs we've seen going offline recently.
65 */
66static RTCPUSET g_MpPendingOfflineSet;
67# endif
68
69
70/**
71 * Notification wrapper that updates CPU states and invokes our notification
72 * callbacks.
73 *
74 * @param idCpu The CPU Id.
75 * @param pvUser1 Pointer to the notifier_block (unused).
76 * @param pvUser2 The notification event.
77 * @remarks This can be invoked in interrupt context.
78 */
79static void rtMpNotificationLinuxOnCurrentCpu(RTCPUID idCpu, void *pvUser1, void *pvUser2)
80{
81 unsigned long ulNativeEvent = *(unsigned long *)pvUser2;
82 NOREF(pvUser1);
83
84 AssertRelease(!RTThreadPreemptIsEnabled(NIL_RTTHREAD));
85 AssertRelease(idCpu == RTMpCpuId()); /* ASSUMES iCpu == RTCPUID */
86
87 /*
88 * Note that redhat/CentOS ported _some_ of the FROZEN macros
89 * back to their 2.6.18-92.1.10.el5 kernel but actually don't
90 * use them. Thus we have to test for both CPU_TASKS_FROZEN and
91 * the individual event variants.
92 */
93
94 /* ASSUMES iCpu == RTCPUID */
95 switch (ulNativeEvent)
96 {
97 /*
98 * Pick up online events or failures to go offline.
99 * Ignore failure events for CPUs we didn't see go offline.
100 */
101# ifdef CPU_DOWN_FAILED
102 case CPU_DOWN_FAILED:
103# if defined(CPU_TASKS_FROZEN) && defined(CPU_DOWN_FAILED_FROZEN)
104 case CPU_DOWN_FAILED_FROZEN:
105# endif
106 if (!RTCpuSetIsMember(&g_MpPendingOfflineSet, idCpu))
107 return;
108 /* fall thru */
109# endif
110 case CPU_ONLINE:
111# if defined(CPU_TASKS_FROZEN) && defined(CPU_ONLINE_FROZEN)
112 case CPU_ONLINE_FROZEN:
113# endif
114# ifdef CPU_DOWN_FAILED
115 RTCpuSetDel(&g_MpPendingOfflineSet, idCpu);
116# endif
117 rtMpNotificationDoCallbacks(RTMPEVENT_ONLINE, idCpu);
118 break;
119
120 /*
121 * Pick the earliest possible offline event.
122 * The only important thing here is that we get the event and that
123 * it's exactly one.
124 */
125# ifdef CPU_DOWN_PREPARE
126 case CPU_DOWN_PREPARE:
127# if defined(CPU_TASKS_FROZEN) && defined(CPU_DOWN_PREPARE_FROZEN)
128 case CPU_DOWN_PREPARE_FROZEN:
129# endif
130# else
131 case CPU_DEAD:
132# if defined(CPU_TASKS_FROZEN) && defined(CPU_DEAD_FROZEN)
133 case CPU_DEAD_FROZEN:
134# endif
135# endif
136 rtMpNotificationDoCallbacks(RTMPEVENT_OFFLINE, idCpu);
137# ifdef CPU_DOWN_FAILED
138 RTCpuSetAdd(&g_MpPendingOfflineSet, idCpu);
139# endif
140 break;
141 }
142}
143
144
145/**
146 * The native callback.
147 *
148 * @returns NOTIFY_DONE.
149 * @param pNotifierBlock Pointer to g_NotifierBlock.
150 * @param ulNativeEvent The native event.
151 * @param pvCpu The cpu id cast into a pointer value.
152 * @remarks This can fire with preemption enabled and on any CPU.
153 */
154static int rtMpNotificationLinuxCallback(struct notifier_block *pNotifierBlock, unsigned long ulNativeEvent, void *pvCpu)
155{
156 int rc;
157 RTCPUID idCpu = (uintptr_t)pvCpu;
158 NOREF(pNotifierBlock);
159
160 /*
161 * Reschedule the callbacks to fire on the specific CPU with preemption disabled.
162 */
163 rc = RTMpOnSpecific(idCpu, rtMpNotificationLinuxOnCurrentCpu, pNotifierBlock, &ulNativeEvent);
164 Assert(RT_SUCCESS(rc));
165 return NOTIFY_DONE;
166}
167
168
169DECLHIDDEN(int) rtR0MpNotificationNativeInit(void)
170{
171 int rc;
172
173# ifdef CPU_DOWN_FAILED
174 RTCpuSetEmpty(&g_MpPendingOfflineSet);
175# endif
176
177 rc = register_cpu_notifier(&g_NotifierBlock);
178 AssertMsgReturn(!rc, ("%d\n", rc), RTErrConvertFromErrno(rc));
179 return VINF_SUCCESS;
180}
181
182
183DECLHIDDEN(void) rtR0MpNotificationNativeTerm(void)
184{
185 unregister_cpu_notifier(&g_NotifierBlock);
186}
187
188#else /* Not supported / Not needed */
189
190DECLHIDDEN(int) rtR0MpNotificationNativeInit(void)
191{
192 return VINF_SUCCESS;
193}
194
195DECLHIDDEN(void) rtR0MpNotificationNativeTerm(void)
196{
197}
198
199#endif /* Not supported / Not needed */
200
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