VirtualBox

source: vbox/trunk/src/VBox/Runtime/generic/RTMpOnPair-generic.cpp@ 75251

Last change on this file since 75251 was 69111, checked in by vboxsync, 7 years ago

(C) year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/* $Id: RTMpOnPair-generic.cpp 69111 2017-10-17 14:26:02Z vboxsync $ */
2/** @file
3 * IPRT - RTMpOnPair, generic implementation using RTMpOnAll.
4 */
5
6/*
7 * Copyright (C) 2015-2017 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 */
45typedef 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. */
57typedef RTMPONPAIRGENERIC *PRTMPONPAIRGENERIC;
58
59
60/**
61 * @callback_method_impl{FNRTMPWORKER,
62 * Used by RTMpOnPair to call the worker on the two specified CPUs.}
63 */
64static DECLCALLBACK(void) rtMpOnPairGenericWorker(RTCPUID idCpu, void *pvUser1, void *pvUser2)
65{
66 RT_NOREF(pvUser2);
67 PRTMPONPAIRGENERIC pArgs = (PRTMPONPAIRGENERIC)pvUser1;
68
69 /*
70 * Only the two choosen CPUs should call the worker function, count how
71 * many of them that showed up.
72 */
73 if ( idCpu == pArgs->idCpu1
74 || idCpu == pArgs->idCpu2)
75 {
76 ASMAtomicIncU32(&pArgs->cPresent);
77 pArgs->pfnWorker(idCpu, pArgs->pvUser1, pArgs->pvUser2);
78 }
79}
80
81
82RTDECL(int) RTMpOnPair(RTCPUID idCpu1, RTCPUID idCpu2, uint32_t fFlags, PFNRTMPWORKER pfnWorker, void *pvUser1, void *pvUser2)
83{
84 int rc;
85 AssertReturn(idCpu1 != idCpu2, VERR_INVALID_PARAMETER);
86 AssertReturn(!(fFlags & RTMPON_F_VALID_MASK), VERR_INVALID_FLAGS);
87 if ((fFlags & RTMPON_F_CONCURRENT_EXEC) && !RTMpOnAllIsConcurrentSafe())
88 return VERR_NOT_SUPPORTED;
89
90 /*
91 * Check that both CPUs are online before doing the broadcast call.
92 */
93 if ( RTMpIsCpuOnline(idCpu1)
94 && RTMpIsCpuOnline(idCpu2))
95 {
96 RTMPONPAIRGENERIC Args;
97 Args.idCpu1 = idCpu1;
98 Args.idCpu2 = idCpu2;
99 Args.pfnWorker = pfnWorker;
100 Args.pvUser1 = pvUser1;
101 Args.pvUser2 = pvUser2;
102 Args.cPresent = 0;
103 rc = RTMpOnAll(rtMpOnPairGenericWorker, &Args, pvUser2);
104 if (RT_SUCCESS(rc))
105 {
106 /*
107 * Let's see if both of the CPUs showed up.
108 */
109 if (RT_LIKELY(Args.cPresent == 2))
110 { /* likely */ }
111 else if (Args.cPresent == 0)
112 rc = VERR_CPU_OFFLINE;
113 else if (Args.cPresent == 1)
114 rc = VERR_NOT_ALL_CPUS_SHOWED;
115 else
116 {
117 rc = VERR_CPU_IPE_1;
118 AssertMsgFailed(("cPresent=%#x\n", Args.cPresent));
119 }
120 }
121 }
122 /*
123 * A CPU must be present to be considered just offline.
124 */
125 else if ( RTMpIsCpuPresent(idCpu1)
126 && RTMpIsCpuPresent(idCpu2))
127 rc = VERR_CPU_OFFLINE;
128 else
129 rc = VERR_CPU_NOT_FOUND;
130 return rc;
131}
132
133
134RTDECL(bool) RTMpOnPairIsConcurrentExecSupported(void)
135{
136 return RTMpOnAllIsConcurrentSafe();
137}
138
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