1 | /* $Id: RTMpOnPair-generic.cpp 54408 2015-02-24 02:06:56Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - RTMpOnPair, generic implementation using RTMpOnAll.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 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 "internal/iprt.h"
|
---|
32 | #include <iprt/mp.h>
|
---|
33 |
|
---|
34 | #include <iprt/asm.h>
|
---|
35 | #include <iprt/assert.h>
|
---|
36 | #include <iprt/err.h>
|
---|
37 |
|
---|
38 |
|
---|
39 | /*******************************************************************************
|
---|
40 | * Structures and Typedefs *
|
---|
41 | *******************************************************************************/
|
---|
42 | /**
|
---|
43 | * Argument package for the generic RTMpOnPair implemenetation.
|
---|
44 | */
|
---|
45 | typedef struct RTMPONPAIRGENERIC
|
---|
46 | {
|
---|
47 | RTCPUID idCpu1;
|
---|
48 | RTCPUID idCpu2;
|
---|
49 | PFNRTMPWORKER pfnWorker;
|
---|
50 | void *pvUser1;
|
---|
51 | void *pvUser2;
|
---|
52 | /** Count of how many CPUs actually showed up. */
|
---|
53 | uint32_t volatile cPresent;
|
---|
54 | } RTMPONPAIRGENERIC;
|
---|
55 | /** Pointer to the an argument package for the generic RTMpOnPair
|
---|
56 | * implemenation. */
|
---|
57 | typedef RTMPONPAIRGENERIC *PRTMPONPAIRGENERIC;
|
---|
58 |
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * @callback_method_impl{FNRTMPWORKER,
|
---|
62 | * Used by RTMpOnPair to call the worker on the two specified CPUs.}
|
---|
63 | */
|
---|
64 | static DECLCALLBACK(void) rtMpOnPairGenericWorker(RTCPUID idCpu, void *pvUser1, void *pvUser2)
|
---|
65 | {
|
---|
66 | PRTMPONPAIRGENERIC pArgs = (PRTMPONPAIRGENERIC)pvUser1;
|
---|
67 |
|
---|
68 | /*
|
---|
69 | * Only the two choosen CPUs should call the worker function, count how
|
---|
70 | * many of them that showed up.
|
---|
71 | */
|
---|
72 | if ( idCpu == pArgs->idCpu1
|
---|
73 | || idCpu == pArgs->idCpu2)
|
---|
74 | {
|
---|
75 | ASMAtomicIncU32(&pArgs->cPresent);
|
---|
76 | pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 |
|
---|
81 | RTDECL(int) RTMpOnPair(RTCPUID idCpu1, RTCPUID idCpu2, uint32_t fFlags, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
|
---|
82 | {
|
---|
83 | int rc;
|
---|
84 | AssertReturn(idCpu1 != idCpu2, VERR_INVALID_PARAMETER);
|
---|
85 | AssertReturn(!(fFlags & RTMPON_F_VALID_MASK), VERR_INVALID_FLAGS);
|
---|
86 | if ((fFlags & RTMPON_F_CONCURRENT_EXEC) && !RTMpOnAllIsConcurrentSafe())
|
---|
87 | return VERR_NOT_SUPPORTED;
|
---|
88 |
|
---|
89 | /*
|
---|
90 | * Check that both CPUs are online before doing the broadcast call.
|
---|
91 | */
|
---|
92 | if ( RTMpIsCpuOnline(idCpu1)
|
---|
93 | && RTMpIsCpuOnline(idCpu2))
|
---|
94 | {
|
---|
95 | RTMPONPAIRGENERIC Args;
|
---|
96 | Args.idCpu1 = idCpu1;
|
---|
97 | Args.idCpu2 = idCpu2;
|
---|
98 | Args.pfnWorker = pfnWorker;
|
---|
99 | Args.pvUser1 = pvUser1;
|
---|
100 | Args.pvUser2 = pvUser2;
|
---|
101 | Args.cPresent = 0;
|
---|
102 | rc = RTMpOnAll(rtMpOnPairGenericWorker, &Args, pvUser2);
|
---|
103 | if (RT_SUCCESS(rc))
|
---|
104 | {
|
---|
105 | /*
|
---|
106 | * Let's see if both of the CPUs showed up.
|
---|
107 | */
|
---|
108 | if (RT_LIKELY(Args.cPresent == 2))
|
---|
109 | { /* likely */ }
|
---|
110 | else if (Args.cPresent == 0)
|
---|
111 | rc = VERR_CPU_OFFLINE;
|
---|
112 | else if (Args.cPresent == 1)
|
---|
113 | rc = VERR_NOT_ALL_CPUS_SHOWED;
|
---|
114 | else
|
---|
115 | {
|
---|
116 | rc = VERR_CPU_IPE_1;
|
---|
117 | AssertMsgFailed(("cPresent=%#x\n", Args.cPresent));
|
---|
118 | }
|
---|
119 | }
|
---|
120 | }
|
---|
121 | /*
|
---|
122 | * A CPU must be present to be considered just offline.
|
---|
123 | */
|
---|
124 | else if ( RTMpIsCpuPresent(idCpu1)
|
---|
125 | && RTMpIsCpuPresent(idCpu2))
|
---|
126 | rc = VERR_CPU_OFFLINE;
|
---|
127 | else
|
---|
128 | rc = VERR_CPU_NOT_FOUND;
|
---|
129 | return rc;
|
---|
130 | }
|
---|
131 |
|
---|
132 |
|
---|
133 | RTDECL(bool) RTMpOnPairIsConcurrentExecSupported(void)
|
---|
134 | {
|
---|
135 | return RTMpOnAllIsConcurrentSafe();
|
---|
136 | }
|
---|
137 |
|
---|