From 17509fb1e5c3932797684b84c67e64f13573da33 Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Sat, 29 Jul 2006 19:26:13 +0000 Subject: [PATCH] - Added profiling for possible Nt I/O function optimizations. Booting and running Firefox gave an amazing "0 missed optimizations", so defintely, this has been moved down on the priority list. Also merged all tracing TODOs in one entry and added device.c tracing TODO. - Fix IRP Cancellation and enable all calls to IopQueueIrpToThread and IopUnqueueIrpFromThread. This seems to work properly now and the kernel fun entry for it has been removed. All remaining Io TODOs are now low priority. svn path=/trunk/; revision=23354 --- reactos/ntoskrnl/KrnlFun.c | 6 ++-- reactos/ntoskrnl/include/internal/io.h | 2 ++ reactos/ntoskrnl/io/iomgr/file.c | 22 ++++++++++--- reactos/ntoskrnl/io/iomgr/iofunc.c | 44 ++++++++++++++++++++++---- 4 files changed, 59 insertions(+), 15 deletions(-) diff --git a/reactos/ntoskrnl/KrnlFun.c b/reactos/ntoskrnl/KrnlFun.c index a9aa4abc50d..b6561edb396 100644 --- a/reactos/ntoskrnl/KrnlFun.c +++ b/reactos/ntoskrnl/KrnlFun.c @@ -9,14 +9,12 @@ // Failure to respect this will *ACHIEVE NOTHING*. // // Io: -// - See why queueing IRPs and cancelling them causes crashes. +// - Add tracing to iofunc.c, file.c and device.c // - Add Access Checks in IopParseDevice. // - Add validation checks in IoCreateFile. // - Add probe/alignment checks for Query/Set routines. -// - Add tracing to iofunc.c -// - Add tracing to file.c -// - Add support for some fast-paths when querying/setting data. // - Verify ShareAccess APIs, XP added some new semantics. +// - Add support for some fast-paths when querying/setting data. // - Add support for Fast Dispatch I/O. // // Ob: diff --git a/reactos/ntoskrnl/include/internal/io.h b/reactos/ntoskrnl/include/internal/io.h index 1e30e5e883f..dd7df40c58a 100644 --- a/reactos/ntoskrnl/include/internal/io.h +++ b/reactos/ntoskrnl/include/internal/io.h @@ -16,6 +16,8 @@ // These define the Debug Masks Supported // #define IO_IRP_DEBUG 0x01 +#define IO_FO_DEBUG 0x02 +#define IO_DEVICE_DEBUG 0x04 // // Debug/Tracing support diff --git a/reactos/ntoskrnl/io/iomgr/file.c b/reactos/ntoskrnl/io/iomgr/file.c index e7086eda399..6acf2caeb12 100644 --- a/reactos/ntoskrnl/io/iomgr/file.c +++ b/reactos/ntoskrnl/io/iomgr/file.c @@ -373,7 +373,7 @@ IopParseDevice(IN PVOID ParseObject, OpenPacket->FileObject = FileObject; /* Queue the IRP and call the driver */ - //IopQueueIrpToThread(Irp); + IopQueueIrpToThread(Irp); Status = IoCallDriver(DeviceObject, Irp); if (Status == STATUS_PENDING) { @@ -404,7 +404,7 @@ IopParseDevice(IN PVOID ParseObject, FileObject->Event.Header.SignalState = 1; /* Now that we've signaled the events, de-associate the IRP */ - //IopUnQueueIrpFromThread(Irp); + IopUnQueueIrpFromThread(Irp); /* Check if the IRP had an input buffer */ if ((Irp->Flags & IRP_BUFFERED_IO) && @@ -611,6 +611,7 @@ IopDeleteFile(IN PVOID ObjectBody) NTSTATUS Status; KEVENT Event; PDEVICE_OBJECT DeviceObject; + KIRQL OldIrql; /* Check if the file has a device object */ if (FileObject->DeviceObject) @@ -656,7 +657,7 @@ IopDeleteFile(IN PVOID ObjectBody) StackPtr->FileObject = FileObject; /* Queue the IRP */ - //IopQueueIrpToThread(Irp); + IopQueueIrpToThread(Irp); /* Call the FS Driver */ Status = IoCallDriver(DeviceObject, Irp); @@ -666,6 +667,11 @@ IopDeleteFile(IN PVOID ObjectBody) KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL); } + /* Raise to APC level and de-queue the IRP */ + KeRaiseIrql(APC_LEVEL, &OldIrql); + IopUnQueueIrpFromThread(Irp); + KeLowerIrql(OldIrql); + /* Free the IRP */ IoFreeIrp(Irp); @@ -830,7 +836,7 @@ IopSecurityFile(IN PVOID ObjectBody, } /* Queue the IRP */ - //IopQueueIrpToThread(Irp); + IopQueueIrpToThread(Irp); /* Update operation counts */ IopUpdateOperationCount(IopOtherTransfer); @@ -1024,6 +1030,7 @@ IopCloseFile(IN PEPROCESS Process OPTIONAL, PIO_STACK_LOCATION StackPtr; NTSTATUS Status; PDEVICE_OBJECT DeviceObject; + KIRQL OldIrql; /* Check if the file is locked and has more then one handle opened */ if ((FileObject->LockOperation) && (SystemHandleCount != 1)) @@ -1075,7 +1082,7 @@ IopCloseFile(IN PEPROCESS Process OPTIONAL, StackPtr->FileObject = FileObject; /* Queue the IRP */ - //IopQueueIrpToThread(Irp); + IopQueueIrpToThread(Irp); /* Update operation counts */ IopUpdateOperationCount(IopOtherTransfer); @@ -1088,6 +1095,11 @@ IopCloseFile(IN PEPROCESS Process OPTIONAL, KeWaitForSingleObject(&Event, UserRequest, KernelMode, FALSE, NULL); } + /* Raise to APC level and de-queue the IRP */ + KeRaiseIrql(APC_LEVEL, &OldIrql); + IopUnQueueIrpFromThread(Irp); + KeLowerIrql(OldIrql); + /* Free the IRP */ IoFreeIrp(Irp); diff --git a/reactos/ntoskrnl/io/iomgr/iofunc.c b/reactos/ntoskrnl/io/iomgr/iofunc.c index 110b6c07626..a5aac527e15 100644 --- a/reactos/ntoskrnl/io/iomgr/iofunc.c +++ b/reactos/ntoskrnl/io/iomgr/iofunc.c @@ -14,6 +14,8 @@ #define NDEBUG #include +ULONG IopMissedOptimizations; + #if 0 IOTRACE(IO_IRP_DEBUG, "%s - Queueing IRP %p\n", @@ -127,7 +129,7 @@ IopPerformSynchronousRequest(IN PDEVICE_OBJECT DeviceObject, PAGED_CODE(); /* Queue the IRP */ - //IopQueueIrpToThread(Irp); + IopQueueIrpToThread(Irp); /* Update operation counts */ IopUpdateOperationCount(TransferType); @@ -449,7 +451,7 @@ IopQueryDeviceInformation(IN PFILE_OBJECT FileObject, } /* Queue the IRP */ - //IopQueueIrpToThread(Irp); + IopQueueIrpToThread(Irp); /* Call the Driver */ Status = IoCallDriver(FileObject->DeviceObject, Irp); @@ -696,7 +698,17 @@ IoSetInformation(IN PFILE_OBJECT FileObject, StackPtr->Parameters.SetFile.Length = Length; /* Queue the IRP */ - //IopQueueIrpToThread(Irp); + IopQueueIrpToThread(Irp); + + /* FIXME BUGBUG TEMPORARY CODE */ + if ((FileInformationClass == FileModeInformation) || + (FileInformationClass == FileRenameInformation ) || + (FileInformationClass == FileLinkInformation ) || + (FileInformationClass == FileMoveClusterInformation)) + { + DPRINT1("Missed optimization: %lx\n", FileInformationClass); + IopMissedOptimizations++; + } /* Call the Driver */ Status = IoCallDriver(FileObject->DeviceObject, Irp); @@ -1635,11 +1647,21 @@ NtQueryInformationFile(IN HANDLE FileHandle, StackPtr->Parameters.QueryFile.Length = Length; /* Queue the IRP */ - //IopQueueIrpToThread(Irp); + IopQueueIrpToThread(Irp); /* Update operation counts */ IopUpdateOperationCount(IopOtherTransfer); + /* FIXME BUGBUG TEMPORARY CODE */ + if ((FileInformationClass == FileAccessInformation) || + (FileInformationClass == FileModeInformation) || + (FileInformationClass == FileAlignmentInformation) || + (FileInformationClass == FileAllInformation)) + { + DPRINT1("Missed optimization: %lx\n", FileInformationClass); + IopMissedOptimizations++; + } + /* Call the Driver */ Status = IoCallDriver(DeviceObject, Irp); if (Status == STATUS_PENDING) @@ -2181,12 +2203,22 @@ NtSetInformationFile(IN HANDLE FileHandle, StackPtr->Parameters.SetFile.Length = Length; /* Queue the IRP */ - //IopQueueIrpToThread(Irp); + IopQueueIrpToThread(Irp); /* Update operation counts */ IopUpdateOperationCount(IopOtherTransfer); - /* FIXME: Later, we can implement a lot of stuff here and avoid a driver call */ + /* FIXME BUGBUG TEMPORARY CODE */ + if ((FileInformationClass == FileModeInformation) || + (FileInformationClass == FileRenameInformation ) || + (FileInformationClass == FileLinkInformation ) || + (FileInformationClass == FileMoveClusterInformation ) || + (FileInformationClass == FileDispositionInformation )) + { + DPRINT1("Missed optimization: %lx\n", FileInformationClass); + IopMissedOptimizations++; + } + /* Handle IO Completion Port quickly */ if (FileInformationClass == FileCompletionInformation) {