Author: sir_richard
Date: Mon Mar 8 21:37:24 2010
New Revision: 46001
URL:
http://svn.reactos.org/svn/reactos?rev=46001&view=rev
Log:
[NTOS]: Implement CmSetLazyFlushState to disable lazy writing in the Cm.
[NTOS]: Implement ExSwapInWorkerThreads to in-swap any worker threads when needed.
[NTOS]: Add HAL stubs for HalEndOfBoot and HalSetWakeEnable since most HALs set this to
NULL.
[DDK]: Add some missing definitions.
Modified:
trunk/reactos/include/ddk/winddk.h
trunk/reactos/ntoskrnl/config/cmlazy.c
trunk/reactos/ntoskrnl/ex/work.c
trunk/reactos/ntoskrnl/fstub/halstub.c
trunk/reactos/ntoskrnl/include/internal/cm.h
trunk/reactos/ntoskrnl/include/internal/ex.h
trunk/reactos/ntoskrnl/include/internal/hal.h
Modified: trunk/reactos/include/ddk/winddk.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ddk/winddk.h?rev=4…
==============================================================================
--- trunk/reactos/include/ddk/winddk.h [iso-8859-1] (original)
+++ trunk/reactos/include/ddk/winddk.h [iso-8859-1] Mon Mar 8 21:37:24 2010
@@ -897,6 +897,41 @@
SYSTEM_POWER_STATE SystemState;
DEVICE_POWER_STATE DeviceState;
} POWER_STATE, *PPOWER_STATE;
+
+typedef struct _POWER_ACTION_POLICY {
+ POWER_ACTION Action;
+ ULONG Flags;
+ ULONG EventCode;
+} POWER_ACTION_POLICY, *PPOWER_ACTION_POLICY;
+
+/* POWER_ACTION_POLICY.Flags constants */
+#define POWER_ACTION_QUERY_ALLOWED 0x00000001
+#define POWER_ACTION_UI_ALLOWED 0x00000002
+#define POWER_ACTION_OVERRIDE_APPS 0x00000004
+#define POWER_ACTION_LIGHTEST_FIRST 0x10000000
+#define POWER_ACTION_LOCK_CONSOLE 0x20000000
+#define POWER_ACTION_DISABLE_WAKES 0x40000000
+#define POWER_ACTION_CRITICAL 0x80000000
+
+/* POWER_ACTION_POLICY.EventCode constants */
+#define POWER_LEVEL_USER_NOTIFY_TEXT 0x00000001
+#define POWER_LEVEL_USER_NOTIFY_SOUND 0x00000002
+#define POWER_LEVEL_USER_NOTIFY_EXEC 0x00000004
+#define POWER_USER_NOTIFY_BUTTON 0x00000008
+#define POWER_USER_NOTIFY_SHUTDOWN 0x00000010
+#define POWER_FORCE_TRIGGER_RESET 0x80000000
+
+#define DISCHARGE_POLICY_CRITICAL 0
+#define DISCHARGE_POLICY_LOW 1
+#define NUM_DISCHARGE_POLICIES 4
+
+#define PO_THROTTLE_NONE 0
+#define PO_THROTTLE_CONSTANT 1
+#define PO_THROTTLE_DEGRADE 2
+#define PO_THROTTLE_ADAPTIVE 3
+#define PO_THROTTLE_MAXIMUM 4
+
+
typedef enum _POWER_STATE_TYPE {
SystemPowerState,
Modified: trunk/reactos/ntoskrnl/config/cmlazy.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/config/cmlazy.c?r…
==============================================================================
--- trunk/reactos/ntoskrnl/config/cmlazy.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/config/cmlazy.c [iso-8859-1] Mon Mar 8 21:37:24 2010
@@ -298,4 +298,12 @@
KeCancelTimer(&CmpLazyFlushTimer);
}
+VOID
+NTAPI
+CmSetLazyFlushState(IN BOOLEAN Enable)
+{
+ /* Set state for lazy flusher */
+ CmpHoldLazyFlush = !Enable;
+}
+
/* EOF */
Modified: trunk/reactos/ntoskrnl/ex/work.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ex/work.c?rev=460…
==============================================================================
--- trunk/reactos/ntoskrnl/ex/work.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ex/work.c [iso-8859-1] Mon Mar 8 21:37:24 2010
@@ -43,7 +43,7 @@
/* Future support for stack swapping worker threads */
BOOLEAN ExpWorkersCanSwap;
LIST_ENTRY ExpWorkerListHead;
-KMUTANT ExpWorkerSwapinMutex;
+FAST_MUTEX ExpWorkerSwapinMutex;
/* The worker balance set manager events */
KEVENT ExpThreadSetManagerEvent;
@@ -513,7 +513,7 @@
ULONG i;
/* Setup the stack swap support */
- KeInitializeMutex(&ExpWorkerSwapinMutex, FALSE);
+ ExInitializeFastMutex(&ExpWorkerSwapinMutex);
InitializeListHead(&ExpWorkerListHead);
ExpWorkersCanSwap = TRUE;
@@ -587,6 +587,89 @@
/* Close the handle and return */
ObCloseHandle(ThreadHandle, KernelMode);
+}
+
+VOID
+NTAPI
+ExpSetSwappingKernelApc(IN PKAPC Apc,
+ OUT PKNORMAL_ROUTINE *NormalRoutine,
+ IN OUT PVOID *NormalContext,
+ IN OUT PVOID *SystemArgument1,
+ IN OUT PVOID *SystemArgument2)
+{
+ PBOOLEAN AllowSwap;
+ PKEVENT Event = (PKEVENT)*SystemArgument1;
+
+ /* Make sure it's an active worker */
+ if (PsGetCurrentThread()->ActiveExWorker)
+ {
+ /* Read the setting from the context flag */
+ AllowSwap = (PBOOLEAN)NormalContext;
+ KeSetKernelStackSwapEnable(*AllowSwap);
+ }
+
+ /* Let caller know that we're done */
+ KeSetEvent(Event, 0, FALSE);
+}
+
+VOID
+NTAPI
+ExSwapinWorkerThreads(IN BOOLEAN AllowSwap)
+{
+ KEVENT Event;
+ PETHREAD CurrentThread = PsGetCurrentThread(), Thread;
+ PEPROCESS Process = PsInitialSystemProcess;
+ KAPC Apc;
+ PAGED_CODE();
+
+ /* Initialize an event so we know when we're done */
+ KeInitializeEvent(&Event, NotificationEvent, FALSE);
+
+ /* Lock this routine */
+ ExAcquireFastMutex(&ExpWorkerSwapinMutex);
+
+ /* New threads cannot swap anymore */
+ ExpWorkersCanSwap = AllowSwap;
+
+ /* Loop all threads in the system process */
+ Thread = PsGetNextProcessThread(Process, NULL);
+ while (Thread)
+ {
+ /* Skip threads with explicit permission to do this */
+ if (Thread->ExWorkerCanWaitUser) goto Next;
+
+ /* Check if we reached ourselves */
+ if (Thread == CurrentThread)
+ {
+ /* Do it inline */
+ KeSetKernelStackSwapEnable(AllowSwap);
+ }
+ else
+ {
+ /* Queue an APC */
+ KeInitializeApc(&Apc,
+ &Thread->Tcb,
+ InsertApcEnvironment,
+ ExpSetSwappingKernelApc,
+ NULL,
+ NULL,
+ KernelMode,
+ &AllowSwap);
+ if (KeInsertQueueApc(&Apc, &Event, NULL, 3))
+ {
+ /* Wait for the APC to run */
+ KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
+ KeClearEvent(&Event);
+ }
+ }
+
+ /* Next thread */
+Next:
+ Thread = PsGetNextProcessThread(Process, Thread);
+ }
+
+ /* Release the lock */
+ ExReleaseFastMutex(&ExpWorkerSwapinMutex);
}
/* PUBLIC FUNCTIONS **********************************************************/
Modified: trunk/reactos/ntoskrnl/fstub/halstub.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/fstub/halstub.c?r…
==============================================================================
--- trunk/reactos/ntoskrnl/fstub/halstub.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/fstub/halstub.c [iso-8859-1] Mon Mar 8 21:37:24 2010
@@ -36,7 +36,7 @@
(pHalStartMirroring)NULL,
(pHalEndMirroring)NULL,
(pHalMirrorPhysicalMemory)NULL,
- (pHalEndOfBoot)NULL,
+ xHalEndOfBoot,
(pHalMirrorVerify)NULL
};
@@ -47,7 +47,7 @@
(pHalHandlerForConfigSpace)NULL,
(pHalLocateHiberRanges)NULL,
(pHalRegisterBusHandler)NULL,
- (pHalSetWakeEnable)NULL,
+ xHalSetWakeEnable,
(pHalSetWakeAlarm)NULL,
(pHalTranslateBusAddress)NULL,
(pHalAssignSlotResources)NULL,
@@ -81,3 +81,19 @@
/* Halt execution */
while (TRUE);
}
+
+VOID
+NTAPI
+xHalEndOfBoot(VOID)
+{
+ /* Nothing */
+ return;
+}
+
+VOID
+NTAPI
+xHalSetWakeEnable(IN BOOLEAN Enable)
+{
+ /* Nothing */
+ return;
+}
Modified: trunk/reactos/ntoskrnl/include/internal/cm.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/cm.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/cm.h [iso-8859-1] Mon Mar 8 21:37:24 2010
@@ -1452,6 +1452,12 @@
NTAPI
CmShutdownSystem(
VOID
+);
+
+VOID
+NTAPI
+CmSetLazyFlushState(
+ IN BOOLEAN Enable
);
//
Modified: trunk/reactos/ntoskrnl/include/internal/ex.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/ex.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/ex.h [iso-8859-1] Mon Mar 8 21:37:24 2010
@@ -26,6 +26,7 @@
extern ULONG ExpInitializationPhase;
extern ULONG ExpAltTimeZoneBias;
extern LIST_ENTRY ExSystemLookasideListHead;
+extern PCALLBACK_OBJECT PowerStateCallback;
typedef struct _EXHANDLE
{
@@ -157,6 +158,10 @@
VOID
NTAPI
ExpInitializeWorkerThreads(VOID);
+
+VOID
+NTAPI
+ExSwapinWorkerThreads(IN BOOLEAN AllowSwap);
VOID
NTAPI
Modified: trunk/reactos/ntoskrnl/include/internal/hal.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/hal.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/hal.h [iso-8859-1] Mon Mar 8 21:37:24 2010
@@ -51,6 +51,18 @@
NTAPI
xHalHaltSystem(
VOID
+);
+
+VOID
+NTAPI
+xHalEndOfBoot(
+ VOID
+);
+
+VOID
+NTAPI
+xHalSetWakeEnable(
+ IN BOOLEAN Enable
);
UCHAR