ReactOS  0.4.14-dev-115-g4576127
ipi.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Kernel
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: ntoskrnl/ke/ipi.c
5  * PURPOSE: Inter-Processor Packet Interface
6  * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7  */
8 
9 /* INCLUDES ******************************************************************/
10 
11 #include <ntoskrnl.h>
12 #define NDEBUG
13 #include <debug.h>
14 
15 /* GLOBALS *******************************************************************/
16 
18 
19 /* PRIVATE FUNCTIONS *********************************************************/
20 
21 VOID
22 NTAPI
24  IN PVOID BroadcastFunction,
25  IN PVOID Argument,
26  IN PVOID Count)
27 {
28  /* FIXME: TODO */
29  ASSERTMSG("Not yet implemented\n", FALSE);
30 }
31 
32 VOID
34 KiIpiSend(IN KAFFINITY TargetProcessors,
35  IN ULONG IpiRequest)
36 {
37  /* FIXME: TODO */
38  ASSERTMSG("Not yet implemented\n", FALSE);
39 }
40 
41 VOID
42 NTAPI
43 KiIpiSendPacket(IN KAFFINITY TargetProcessors,
44  IN PKIPI_WORKER WorkerFunction,
45  IN PKIPI_BROADCAST_WORKER BroadcastFunction,
47  IN PULONG Count)
48 {
49  /* FIXME: TODO */
50  ASSERTMSG("Not yet implemented\n", FALSE);
51 }
52 
53 VOID
56 {
57  /* FIXME: TODO */
58  ASSERTMSG("Not yet implemented\n", FALSE);
59 }
60 
61 VOID
64  IN volatile PULONG ReverseStall)
65 {
66  /* FIXME: TODO */
67  ASSERTMSG("Not yet implemented\n", FALSE);
68 }
69 
70 #if 0
71 VOID
72 NTAPI
73 KiIpiSendRequest(IN KAFFINITY TargetSet,
74  IN ULONG IpiRequest)
75 {
76 #ifdef CONFIG_SMP
77  LONG i;
78  PKPRCB Prcb;
79  KAFFINITY Current;
80 
81  for (i = 0, Current = 1; i < KeNumberProcessors; i++, Current <<= 1)
82  {
83  if (TargetSet & Current)
84  {
85  /* Get the PRCB for this CPU */
86  Prcb = KiProcessorBlock[i];
87 
88  InterlockedBitTestAndSet((PLONG)&Prcb->IpiFrozen, IpiRequest);
90  }
91  }
92 #endif
93 }
94 
95 VOID
96 NTAPI
97 KiIpiSendPacket(IN KAFFINITY TargetSet,
99  IN ULONG_PTR Argument,
100  IN ULONG Count,
101  IN BOOLEAN Synchronize)
102 {
103 #ifdef CONFIG_SMP
105  LONG i;
106  PKPRCB Prcb, CurrentPrcb;
107  KIRQL oldIrql;
108 
110 
111  CurrentPrcb = KeGetCurrentPrcb();
112  (void)InterlockedExchangeUL(&CurrentPrcb->TargetSet, TargetSet);
114  (void)InterlockedExchangePointer(&CurrentPrcb->CurrentPacket[0], Argument);
115  (void)InterlockedExchangeUL(&CurrentPrcb->CurrentPacket[1], Count);
116  (void)InterlockedExchangeUL(&CurrentPrcb->CurrentPacket[2], Synchronize ? 1 : 0);
117 
118  for (i = 0, Processor = 1; i < KeNumberProcessors; i++, Processor <<= 1)
119  {
120  if (TargetSet & Processor)
121  {
122  Prcb = KiProcessorBlock[i];
123  while (0 != InterlockedCompareExchangeUL(&Prcb->SignalDone, (LONG)CurrentPrcb, 0));
125  if (Processor != CurrentPrcb->SetMember)
126  {
127  HalRequestIpi(i);
128  }
129  }
130  }
131  if (TargetSet & CurrentPrcb->SetMember)
132  {
133  KeRaiseIrql(IPI_LEVEL, &oldIrql);
135  KeLowerIrql(oldIrql);
136  }
137 #endif
138 }
139 #endif
140 
141 /* PUBLIC FUNCTIONS **********************************************************/
142 
143 /*
144  * @implemented
145  */
146 BOOLEAN
147 NTAPI
149  IN PKEXCEPTION_FRAME ExceptionFrame)
150 {
151 #ifdef CONFIG_SMP
152  PKPRCB Prcb;
154 
155  Prcb = KeGetCurrentPrcb();
156 
158  {
160  }
161 
163  {
164  Prcb->DpcInterruptRequested = TRUE;
166  }
167 
169  {
170 #ifdef _M_ARM
171  DbgBreakPoint();
172 #else
173  (void)InterlockedDecrementUL(&Prcb->SignalDone->CurrentPacket[1]);
174  if (InterlockedCompareExchangeUL(&Prcb->SignalDone->CurrentPacket[2], 0, 0))
175  {
176  while (0 != InterlockedCompareExchangeUL(&Prcb->SignalDone->CurrentPacket[1], 0, 0));
177  }
178  ((VOID (NTAPI*)(PVOID))(Prcb->SignalDone->WorkerRoutine))(Prcb->SignalDone->CurrentPacket[0]);
180  if (InterlockedCompareExchangeUL(&Prcb->SignalDone->CurrentPacket[2], 0, 0))
181  {
182  while (0 != InterlockedCompareExchangeUL(&Prcb->SignalDone->TargetSet, 0, 0));
183  }
185 #endif // _M_ARM
186  }
187 #endif
188  return TRUE;
189 }
190 
191 /*
192  * @implemented
193  */
194 ULONG_PTR
195 NTAPI
197  IN ULONG_PTR Argument)
198 {
200  KIRQL OldIrql, OldIrql2;
201 #ifdef CONFIG_SMP
203  ULONG Count;
204  PKPRCB Prcb = KeGetCurrentPrcb();
205 #endif
206 
207  /* Raise to DPC level if required */
210 
211 #ifdef CONFIG_SMP
212  /* Get current processor count and affinity */
215 
216  /* Exclude ourselves */
217  Affinity &= ~Prcb->SetMember;
218 #endif
219 
220  /* Acquire the IPI lock */
222 
223 #ifdef CONFIG_SMP
224  /* Make sure this is MP */
225  if (Affinity)
226  {
227  /* Send an IPI */
230  Function,
231  Argument,
232  &Count);
233 
234  /* Spin until the other processors are ready */
235  while (Count != 1)
236  {
237  YieldProcessor();
239  }
240  }
241 #endif
242 
243  /* Raise to IPI level */
244  KeRaiseIrql(IPI_LEVEL, &OldIrql2);
245 
246 #ifdef CONFIG_SMP
247  /* Let the other processors know it is time */
248  Count = 0;
249 #endif
250 
251  /* Call the function */
252  Status = Function(Argument);
253 
254 #ifdef CONFIG_SMP
255  /* If this is MP, wait for the other processors to finish */
256  if (Affinity)
257  {
258  /* Sanity check */
259  ASSERT(Prcb == KeGetCurrentPrcb());
260 
261  /* FIXME: TODO */
262  ASSERTMSG("Not yet implemented\n", FALSE);
263  }
264 #endif
265 
266  /* Release the lock */
268 
269  /* Lower IRQL back */
271  return Status;
272 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define IN
Definition: typedefs.h:38
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define TRUE
Definition: types.h:120
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
UINT64 TargetSet
Definition: ketypes.h:670
KIPI_BROADCAST_WORKER * PKIPI_BROADCAST_WORKER
Definition: ketypes.h:605
VOID NTAPI KiIpiSendPacket(IN KAFFINITY TargetProcessors, IN PKIPI_WORKER WorkerFunction, IN PKIPI_BROADCAST_WORKER BroadcastFunction, IN ULONG_PTR Context, IN PULONG Count)
Definition: ipi.c:43
VOID NTAPI HalRequestIpi(KAFFINITY TargetProcessors)
Definition: processor.c:96
VOID FASTCALL KiIpiSend(IN KAFFINITY TargetProcessors, IN ULONG IpiRequest)
Definition: ipi.c:34
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
_Must_inspect_result_ _In_ PFLT_CALLBACK_DATA _In_ PFLT_DEFERRED_IO_WORKITEM_ROUTINE WorkerRoutine
Definition: fltkernel.h:1977
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1062
ULONG IpiFrozen
Definition: ketypes.h:671
KSPIN_LOCK KiReverseStallIpiLock
Definition: krnlinit.c:64
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
_In_ UCHAR Processor
Definition: kefuncs.h:695
void DbgBreakPoint()
Definition: mach.c:553
#define FASTCALL
Definition: nt_native.h:50
#define InterlockedCompareExchangeUL(Destination, Exchange, Comperand)
Definition: ex.h:1522
uint32_t ULONG_PTR
Definition: typedefs.h:63
FORCEINLINE VOID YieldProcessor(VOID)
Definition: ke.h:32
FORCEINLINE ULONG KeGetCurrentProcessorNumber(VOID)
Definition: ke.h:325
UCHAR KIRQL
Definition: env_spec_w32.h:591
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
static LPOVERLAPPED_COMPLETION_ROUTINE Function
Definition: sync.c:684
#define KeMemoryBarrierWithoutFence()
Definition: ke.h:66
long LONG
Definition: pedump.c:60
#define ASSERTMSG(msg, exp)
Definition: nt_native.h:431
#define InterlockedBitTestAndReset
Definition: interlocked.h:35
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define IPI_DPC
Definition: ketypes.h:233
#define IPI_SYNCH_REQUEST
Definition: ketypes.h:236
void * PVOID
Definition: retypes.h:9
#define InterlockedExchangeUL(Target, Value)
Definition: ex.h:1516
#define InterlockedBitTestAndSet
Definition: interlocked.h:30
#define IPI_LEVEL
Definition: env_spec_w32.h:701
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
VOID FASTCALL KiIpiSignalPacketDone(IN PKIPI_CONTEXT PacketContext)
Definition: ipi.c:55
_In_ ULONG _In_ ULONG _In_ ULONG _Out_ PKIRQL _Out_ PKAFFINITY Affinity
Definition: halfuncs.h:170
VOID FASTCALL KiIpiSignalPacketDoneAndStall(IN PKIPI_CONTEXT PacketContext, IN volatile PULONG ReverseStall)
Definition: ipi.c:63
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
UCHAR DpcInterruptRequested
Definition: ketypes.h:686
#define VOID
Definition: acefi.h:82
#define InterlockedDecrementUL(Addend)
Definition: ex.h:1510
#define SYNCH_LEVEL
Definition: env_spec_w32.h:704
VOID(NTAPI * PKIPI_WORKER)(IN OUT PKIPI_CONTEXT PacketContext, IN PVOID Parameter1 OPTIONAL, IN PVOID Parameter2 OPTIONAL, IN PVOID Parameter3 OPTIONAL)
Definition: ketypes.h:576
volatile PKIPI_WORKER WorkerRoutine
Definition: ketypes.h:616
KAFFINITY KeActiveProcessors
Definition: krnlinit.c:23
CCHAR KeNumberProcessors
Definition: krnlinit.c:35
Status
Definition: gdiplustypes.h:24
UINT64 SetMember
Definition: ketypes.h:578
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
BOOLEAN NTAPI KiIpiServiceRoutine(IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame)
Definition: ipi.c:148
volatile struct _KPRCB * SignalDone
Definition: ketypes.h:620
VOID FASTCALL HalRequestSoftwareInterrupt(IN KIRQL Irql)
Definition: pic.c:271
ULONG_PTR KAFFINITY
Definition: compat.h:75
PKPRCB KiProcessorBlock[]
Definition: krnlinit.c:32
VOID NTAPI KiIpiGenericCallTarget(IN PKIPI_CONTEXT PacketContext, IN PVOID BroadcastFunction, IN PVOID Argument, IN PVOID Count)
Definition: ipi.c:23
ULONG KSPIN_LOCK
Definition: env_spec_w32.h:72
unsigned int * PULONG
Definition: retypes.h:1
unsigned int ULONG
Definition: retypes.h:1
#define IPI_APC
Definition: ketypes.h:232
volatile PVOID CurrentPacket[3]
Definition: ketypes.h:614
signed int * PLONG
Definition: retypes.h:5
#define APC_LEVEL
Definition: env_spec_w32.h:695
ULONG_PTR NTAPI KeIpiGenericCall(IN PKIPI_BROADCAST_WORKER Function, IN ULONG_PTR Argument)
Definition: ipi.c:196