VirtualBox

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

Last change on this file since 54395 was 54395, checked in by vboxsync, 10 years ago

IPRT, HostDriver, VMMR0: MP notifications fixes for TSC-delta measurements, scheduling of notification callback taken care by the API consumer instead of IPRT.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1/* $Id: mpnotification-r0drv-linux.c 54395 2015-02-23 17:34:01Z vboxsync $ */
2/** @file
3 * IPRT - Multiprocessor Event Notifications, Ring-0 Driver, Linux.
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/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include "the-linux-kernel.h"
32#include "internal/iprt.h"
33
34#include <iprt/asm-amd64-x86.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 * The native callback.
72 *
73 * @returns NOTIFY_DONE.
74 * @param pNotifierBlock Pointer to g_NotifierBlock.
75 * @param ulNativeEvent The native event.
76 * @param pvCpu The cpu id cast into a pointer value.
77 *
78 * @remarks This can fire with preemption enabled and on any CPU.
79 */
80static int rtMpNotificationLinuxCallback(struct notifier_block *pNotifierBlock, unsigned long ulNativeEvent, void *pvCpu)
81{
82 bool fProcessEvent = false;
83 RTCPUID idCpu = (uintptr_t)pvCpu;
84 NOREF(pNotifierBlock);
85
86 /*
87 * Note that redhat/CentOS ported _some_ of the FROZEN macros
88 * back to their 2.6.18-92.1.10.el5 kernel but actually don't
89 * use them. Thus we have to test for both CPU_TASKS_FROZEN and
90 * the individual event variants.
91 */
92 switch (ulNativeEvent)
93 {
94 /*
95 * Pick up online events or failures to go offline.
96 * Ignore failure events for CPUs we didn't see go offline.
97 */
98# ifdef CPU_DOWN_FAILED
99 case CPU_DOWN_FAILED:
100# if defined(CPU_TASKS_FROZEN) && defined(CPU_DOWN_FAILED_FROZEN)
101 case CPU_DOWN_FAILED_FROZEN:
102# endif
103 if (!RTCpuSetIsMember(&g_MpPendingOfflineSet, idCpu))
104 break; /* fProcessEvents = false */
105 /* fall thru */
106# endif
107 case CPU_ONLINE:
108# if defined(CPU_TASKS_FROZEN) && defined(CPU_ONLINE_FROZEN)
109 case CPU_ONLINE_FROZEN:
110# endif
111# ifdef CPU_DOWN_FAILED
112 RTCpuSetDel(&g_MpPendingOfflineSet, idCpu);
113# endif
114 fProcessEvent = true;
115 break;
116
117 /*
118 * Pick the earliest possible offline event.
119 * The only important thing here is that we get the event and that
120 * it's exactly one.
121 */
122# ifdef CPU_DOWN_PREPARE
123 case CPU_DOWN_PREPARE:
124# if defined(CPU_TASKS_FROZEN) && defined(CPU_DOWN_PREPARE_FROZEN)
125 case CPU_DOWN_PREPARE_FROZEN:
126# endif
127 fProcessEvent = true;
128# else
129 case CPU_DEAD:
130# if defined(CPU_TASKS_FROZEN) && defined(CPU_DEAD_FROZEN)
131 case CPU_DEAD_FROZEN:
132# endif
133 /* Don't process CPU_DEAD notifications. */
134# endif
135# ifdef CPU_DOWN_FAILED
136 RTCpuSetAdd(&g_MpPendingOfflineSet, idCpu);
137# endif
138 break;
139 }
140
141 if (!fProcessEvent)
142 return NOTIFY_DONE;
143
144 switch (ulNativeEvent)
145 {
146# ifdef CPU_DOWN_FAILED
147 case CPU_DOWN_FAILED:
148# if defined(CPU_TASKS_FROZEN) && defined(CPU_DOWN_FAILED_FROZEN)
149 case CPU_DOWN_FAILED_FROZEN:
150# endif
151# endif
152 case CPU_ONLINE:
153# if defined(CPU_TASKS_FROZEN) && defined(CPU_ONLINE_FROZEN)
154 case CPU_ONLINE_FROZEN:
155# endif
156 rtMpNotificationDoCallbacks(RTMPEVENT_ONLINE, idCpu);
157 break;
158
159# ifdef CPU_DOWN_PREPARE
160 case CPU_DOWN_PREPARE:
161# if defined(CPU_TASKS_FROZEN) && defined(CPU_DOWN_PREPARE_FROZEN)
162 case CPU_DOWN_PREPARE_FROZEN:
163# endif
164 rtMpNotificationDoCallbacks(RTMPEVENT_OFFLINE, idCpu);
165 break;
166# endif
167 }
168
169 return NOTIFY_DONE;
170}
171
172
173DECLHIDDEN(int) rtR0MpNotificationNativeInit(void)
174{
175 int rc;
176
177# ifdef CPU_DOWN_FAILED
178 RTCpuSetEmpty(&g_MpPendingOfflineSet);
179# endif
180
181 rc = register_cpu_notifier(&g_NotifierBlock);
182 AssertMsgReturn(!rc, ("%d\n", rc), RTErrConvertFromErrno(rc));
183 return VINF_SUCCESS;
184}
185
186
187DECLHIDDEN(void) rtR0MpNotificationNativeTerm(void)
188{
189 unregister_cpu_notifier(&g_NotifierBlock);
190}
191
192#else /* Not supported / Not needed */
193
194DECLHIDDEN(int) rtR0MpNotificationNativeInit(void)
195{
196 return VINF_SUCCESS;
197}
198
199DECLHIDDEN(void) rtR0MpNotificationNativeTerm(void)
200{
201}
202
203#endif /* Not supported / Not needed */
204
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