VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMAll/PDMAllQueue.cpp@ 13134

Last change on this file since 13134 was 12989, checked in by vboxsync, 16 years ago

VMM + VBox/cdefs.h: consolidated all the XYZ*DECLS of the VMM into VMM*DECL. Removed dead DECL and IN_XYZ* macros.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.5 KB
Line 
1/* $Id: PDMAllQueue.cpp 12989 2008-10-06 02:15:39Z vboxsync $ */
2/** @file
3 * PDM Queue - Transport data and tasks to EMT and R3.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#define LOG_GROUP LOG_GROUP_PDM_QUEUE
27#include "PDMInternal.h"
28#include <VBox/pdm.h>
29#ifndef IN_GC
30# include <VBox/rem.h>
31# include <VBox/mm.h>
32#endif
33#include <VBox/vm.h>
34#include <VBox/err.h>
35#include <VBox/log.h>
36#include <iprt/asm.h>
37#include <iprt/assert.h>
38
39
40/**
41 * Allocate an item from a queue.
42 * The allocated item must be handed on to PDMR3QueueInsert() after the
43 * data have been filled in.
44 *
45 * @returns Pointer to allocated queue item.
46 * @returns NULL on failure. The queue is exhausted.
47 * @param pQueue The queue handle.
48 * @thread Any thread.
49 */
50VMMDECL(PPDMQUEUEITEMCORE) PDMQueueAlloc(PPDMQUEUE pQueue)
51{
52 Assert(VALID_PTR(pQueue) && pQueue->CTX_SUFF(pVM));
53 PPDMQUEUEITEMCORE pNew;
54 uint32_t iNext;
55 uint32_t i;
56 do
57 {
58 i = pQueue->iFreeTail;
59 if (i == pQueue->iFreeHead)
60 return NULL;
61 pNew = pQueue->aFreeItems[i].CTX_SUFF(pItem);
62 iNext = (i + 1) % (pQueue->cItems + PDMQUEUE_FREE_SLACK);
63 } while (!ASMAtomicCmpXchgU32(&pQueue->iFreeTail, iNext, i));
64 return pNew;
65}
66
67
68/**
69 * Queue an item.
70 * The item must have been obtained using PDMQueueAlloc(). Once the item
71 * have been passed to this function it must not be touched!
72 *
73 * @param pQueue The queue handle.
74 * @param pItem The item to insert.
75 * @thread Any thread.
76 */
77VMMDECL(void) PDMQueueInsert(PPDMQUEUE pQueue, PPDMQUEUEITEMCORE pItem)
78{
79 Assert(VALID_PTR(pQueue) && pQueue->CTX_SUFF(pVM));
80 Assert(VALID_PTR(pItem));
81
82 PPDMQUEUEITEMCORE pNext;
83 do
84 {
85 pNext = pQueue->CTX_SUFF(pPending);
86 pItem->CTX_SUFF(pNext) = pNext;
87 } while (!ASMAtomicCmpXchgPtr((void * volatile *)&pQueue->CTX_SUFF(pPending), pItem, pNext));
88
89 if (!pQueue->pTimer)
90 {
91 PVM pVM = pQueue->CTX_SUFF(pVM);
92 Log2(("PDMQueueInsert: VM_FF_PDM_QUEUES %d -> 1\n", VM_FF_ISSET(pVM, VM_FF_PDM_QUEUES)));
93 VM_FF_SET(pVM, VM_FF_PDM_QUEUES);
94#ifdef IN_RING3
95 REMR3NotifyQueuePending(pVM); /** @todo r=bird: we can remove REMR3NotifyQueuePending and let VMR3NotifyFF do the work. */
96 VMR3NotifyFF(pVM, true);
97#endif
98 }
99}
100
101
102/**
103 * Queue an item.
104 * The item must have been obtained using PDMQueueAlloc(). Once the item
105 * have been passed to this function it must not be touched!
106 *
107 * @param pQueue The queue handle.
108 * @param pItem The item to insert.
109 * @param NanoMaxDelay The maximum delay before processing the queue, in nanoseconds.
110 * This applies only to GC.
111 * @thread Any thread.
112 */
113VMMDECL(void) PDMQueueInsertEx(PPDMQUEUE pQueue, PPDMQUEUEITEMCORE pItem, uint64_t NanoMaxDelay)
114{
115 PDMQueueInsert(pQueue, pItem);
116#ifdef IN_GC
117 PVM pVM = pQueue->CTX_SUFF(pVM);
118 /** @todo figure out where to put this, the next bit should go there too.
119 if (NanoMaxDelay)
120 {
121
122 }
123 else */
124 {
125 VM_FF_SET(pVM, VM_FF_TO_R3);
126 Log2(("PDMQueueInsertEx: Setting VM_FF_TO_R3\n"));
127 }
128#endif
129}
130
131
132
133/**
134 * Gets the RC pointer for the specified queue.
135 *
136 * @returns The RC address of the queue.
137 * @returns NULL if pQueue is invalid.
138 * @param pQueue The queue handle.
139 */
140VMMDECL(RCPTRTYPE(PPDMQUEUE)) PDMQueueRCPtr(PPDMQUEUE pQueue)
141{
142 Assert(VALID_PTR(pQueue));
143 Assert(pQueue->pVMR3 && pQueue->pVMRC);
144#ifdef IN_GC
145 return pQueue;
146#else
147 return MMHyperCCToRC(pQueue->CTX_SUFF(pVM), pQueue);
148#endif
149}
150
151
152/**
153 * Gets the ring-0 pointer for the specified queue.
154 *
155 * @returns The ring-0 address of the queue.
156 * @returns NULL if pQueue is invalid.
157 * @param pQueue The queue handle.
158 */
159VMMDECL(R0PTRTYPE(PPDMQUEUE)) PDMQueueR0Ptr(PPDMQUEUE pQueue)
160{
161 Assert(VALID_PTR(pQueue));
162 Assert(pQueue->pVMR3 && pQueue->pVMR0);
163#ifdef IN_RING0
164 return pQueue;
165#else
166 return MMHyperCCToR0(pQueue->CTX_SUFF(pVM), pQueue);
167#endif
168}
169
170
171/**
172 * Flushes a PDM queue.
173 *
174 * @param pQueue The queue handle.
175 */
176VMMDECL(void) PDMQueueFlush(PPDMQUEUE pQueue)
177{
178 Assert(VALID_PTR(pQueue));
179 Assert(pQueue->pVMR3);
180 PVM pVM = pQueue->CTX_SUFF(pVM);
181
182#ifdef IN_GC
183 Assert(pQueue->pVMRC);
184 pVM->pdm.s.CTX_SUFF(pQueueFlush) = pQueue;
185 VMMGCCallHost(pVM, VMMCALLHOST_PDM_QUEUE_FLUSH, (uintptr_t)pQueue);
186
187#elif defined(IN_RING0)
188 Assert(pQueue->pVMR0);
189 pVM->pdm.s.CTX_SUFF(pQueueFlush) = pQueue;
190 VMMR0CallHost(pVM, VMMCALLHOST_PDM_QUEUE_FLUSH, (uintptr_t)pQueue);
191
192#else /* IN_RING3: */
193 PVMREQ pReq;
194 VMR3ReqCall(pVM, &pReq, RT_INDEFINITE_WAIT, (PFNRT)PDMR3QueueFlushWorker, 2, pVM, pQueue);
195 VMR3ReqFree(pReq);
196#endif
197}
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