VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/linux/mp-r0drv-linux.cpp@ 7254

Last change on this file since 7254 was 7254, checked in by vboxsync, 17 years ago

Sketched out RTMp*. (All the platform specific code is disabled.)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1/* $Id: mp-r0drv-linux.cpp 7254 2008-03-04 00:52:03Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime - Multiprocessor, Ring-0 Driver, Linux.
4 */
5
6/*
7 * Copyright (C) 2008 innotek GmbH
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
33#include <iprt/mp.h>
34#include <iprt/err.h>
35#include <iprt/asm.h>
36#include "r0drv/mp-r0drv.h"
37
38
39RTDECL(RTCPUID) RTMpCpuId(void)
40{
41 return smp_processor_id();
42}
43
44
45/**
46 * Wrapper between the native linux per-cpu callbacks and PFNRTWORKER
47 *
48 * @param pvInfo Pointer to the RTMPARGS package.
49 */
50static void rtmpLinuxWrapper(void *pvInfo)
51{
52 PRTMPARGS pArgs = (PRTMPARGS)pvInfo;
53 ASMAtomicIncU32(&pArgs->cHits);
54 pArgs->pfnWorker(smp_process_id(), pArgs->pvUser1, pArgs->pvUser2);
55}
56
57
58RTDECL(int) RTMpOnAll(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
59{
60 int rc;
61 RTMPARGS Args;
62 Args.pfnWorker = pfnWorker;
63 Args.pvUser1 = pvUser1;
64 Args.pvUser2 = pvUser2;
65 Args.idCpu = NIL_RTCPUID;
66 Args.cHits = 0;
67
68#if 1 /** @todo the proper checks for 2.6.x. */
69 rc = on_each_cpu(rtmpLinuxWrapper, &Args, 0 /* retry */, 1 /* wait */);
70
71#else /* older kernels */
72
73# ifdef preempt_disable
74 preempt_disable();
75# endif
76 rc = smp_call_function(rtmpLinuxWrapper, &Args, 0 /* retry */, 1 /* wait */);
77 local_irq_disable();
78 rtmpLinuxWrapper(&Args);
79 local_irq_enable();
80# ifdef preempt_enable
81 preempt_enable();
82# endif
83#endif /* older kernels */
84 Assert(rc == 0); NOREF(rc);
85 return VINF_SUCCESS;
86}
87
88
89RTDECL(int) RTMpOnOthers(PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
90{
91 int rc;
92 RTMPARGS Args;
93 Args.pfnWorker = pfnWorker;
94 Args.pvUser1 = pvUser1;
95 Args.pvUser2 = pvUser2;
96 Args.idCpu = NIL_RTCPUID;
97 Args.cHits = 0;
98
99# ifdef preempt_disable
100 preempt_disable();
101# endif
102 rc = smp_call_function(rtmpLinuxWrapper, &Args, 0 /* retry */, 1 /* wait */);
103# ifdef preempt_enable
104 preempt_enable();
105# endif
106
107 Assert(rc == 0); NOREF(rc);
108 return VINF_SUCCESS;
109}
110
111
112RTDECL(int) RTMpOnSpecific(RTCPUID idCpu, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
113{
114 int rc;
115 RTMPARGS Args;
116 Args.pfnWorker = pfnWorker;
117 Args.pvUser1 = pvUser1;
118 Args.pvUser2 = pvUser2;
119 Args.idCpu = idCpu;
120 Args.cHits = 0;
121
122 /** @todo validate idCpu . */
123
124# ifdef preempt_disable
125 preempt_disable();
126# endif
127 if (idCpu != RTMpCpuId())
128 rc = smp_call_function_single(idCpu, rtmpLinuxWrapper, &Args, 0 /* retry */, 1 /* wait */);
129 else
130 {
131 rtmpLinuxWrapper(&Args);
132 rc = 0;
133 }
134# ifdef preempt_enable
135 preempt_enable();
136# endif
137
138 Assert(rc == 0); NOREF(rc);
139 return VINF_SUCCESS;
140}
141
Note: See TracBrowser for help on using the repository browser.

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