https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f15afdbc43c078bb53e7b…
commit f15afdbc43c078bb53e7b9d7a82aacf2ec0a9cd4
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Fri May 25 21:40:39 2018 +0200
Commit: Pierre Schweitzer <pierre(a)reactos.org>
CommitDate: Fri May 25 21:40:39 2018 +0200
[NTOSKRNL] Implement KeQueryValuesProcess().
And make use of it.
---
ntoskrnl/include/internal/ke.h | 12 ++++++++++
ntoskrnl/ke/procobj.c | 52 ++++++++++++++++++++++++++++++++++++++++++
ntoskrnl/ps/job.c | 21 +++++++++--------
ntoskrnl/ps/query.c | 12 ++++------
4 files changed, 80 insertions(+), 17 deletions(-)
diff --git a/ntoskrnl/include/internal/ke.h b/ntoskrnl/include/internal/ke.h
index f2c32fb266..7bdd97fd8e 100644
--- a/ntoskrnl/include/internal/ke.h
+++ b/ntoskrnl/include/internal/ke.h
@@ -36,6 +36,13 @@ typedef struct _DISPATCH_INFO
PKINTERRUPT_ROUTINE *FlatDispatch;
} DISPATCH_INFO, *PDISPATCH_INFO;
+typedef struct _PROCESS_VALUES
+{
+ LARGE_INTEGER TotalKernelTime;
+ LARGE_INTEGER TotalUserTime;
+ IO_COUNTERS IoInfo;
+} PROCESS_VALUES, *PPROCESS_VALUES;
+
typedef struct _DEFERRED_REVERSE_BARRIER
{
ULONG Barrier;
@@ -710,6 +717,11 @@ NTAPI
KeQueryRuntimeProcess(IN PKPROCESS Process,
OUT PULONG UserTime);
+VOID
+NTAPI
+KeQueryValuesProcess(IN PKPROCESS Process,
+ PPROCESS_VALUES Values);
+
/* INITIALIZATION FUNCTIONS *************************************************/
BOOLEAN
diff --git a/ntoskrnl/ke/procobj.c b/ntoskrnl/ke/procobj.c
index a448202f38..865d7881f8 100644
--- a/ntoskrnl/ke/procobj.c
+++ b/ntoskrnl/ke/procobj.c
@@ -517,6 +517,58 @@ KeSetPriorityAndQuantumProcess(IN PKPROCESS Process,
return OldPriority;
}
+VOID
+NTAPI
+KeQueryValuesProcess(IN PKPROCESS Process,
+ PPROCESS_VALUES Values)
+{
+ PEPROCESS EProcess;
+ PLIST_ENTRY NextEntry;
+ ULONG TotalKernel, TotalUser;
+ KLOCK_QUEUE_HANDLE ProcessLock;
+
+ ASSERT_PROCESS(Process);
+ ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
+
+ /* Lock the process */
+ KiAcquireProcessLock(Process, &ProcessLock);
+
+ /* Initialize user and kernel times */
+ TotalKernel = Process->KernelTime;
+ TotalUser = Process->UserTime;
+
+ /* Copy the IO_COUNTERS from the process */
+ EProcess = (PEPROCESS)Process;
+ Values->IoInfo.ReadOperationCount = EProcess->ReadOperationCount.QuadPart;
+ Values->IoInfo.WriteOperationCount = EProcess->WriteOperationCount.QuadPart;
+ Values->IoInfo.OtherOperationCount = EProcess->OtherOperationCount.QuadPart;
+ Values->IoInfo.ReadTransferCount = EProcess->ReadTransferCount.QuadPart;
+ Values->IoInfo.WriteTransferCount = EProcess->WriteTransferCount.QuadPart;
+ Values->IoInfo.OtherTransferCount = EProcess->OtherTransferCount.QuadPart;
+
+ /* Loop all child threads and sum up their times */
+ for (NextEntry = Process->ThreadListHead.Flink;
+ NextEntry != &Process->ThreadListHead;
+ NextEntry = NextEntry->Flink)
+ {
+ PKTHREAD Thread;
+
+ /* Get the thread */
+ Thread = CONTAINING_RECORD(NextEntry, KTHREAD, ThreadListEntry);
+
+ /* Sum up times */
+ TotalKernel += Thread->KernelTime;
+ TotalUser += Thread->UserTime;
+ }
+
+ /* Release the process lock */
+ KiReleaseProcessLock(&ProcessLock);
+
+ /* Compute total times */
+ Values->TotalKernelTime.QuadPart = TotalKernel * (LONGLONG)KeMaximumIncrement;
+ Values->TotalUserTime.QuadPart = TotalUser * (LONGLONG)KeMaximumIncrement;
+}
+
/* PUBLIC FUNCTIONS **********************************************************/
/*
diff --git a/ntoskrnl/ps/job.c b/ntoskrnl/ps/job.c
index 141398be15..fd0049c991 100644
--- a/ntoskrnl/ps/job.c
+++ b/ntoskrnl/ps/job.c
@@ -631,16 +631,17 @@ NtQueryInformationJobObject (
Process = CONTAINING_RECORD(NextEntry, EPROCESS, JobLinks);
if (!BooleanFlagOn(Process->JobStatus, 2))
{
- /* FIXME: Call KeQueryValuesProcess()
- * We should sum BasicInfo values here,
- * but we don't have them
- */
- BasicAndIo.IoInfo.ReadOperationCount +=
Process->ReadOperationCount.QuadPart;
- BasicAndIo.IoInfo.WriteOperationCount +=
Process->WriteOperationCount.QuadPart;
- BasicAndIo.IoInfo.OtherOperationCount +=
Process->OtherOperationCount.QuadPart;
- BasicAndIo.IoInfo.ReadTransferCount +=
Process->ReadTransferCount.QuadPart;
- BasicAndIo.IoInfo.WriteTransferCount +=
Process->WriteTransferCount.QuadPart;
- BasicAndIo.IoInfo.OtherTransferCount +=
Process->OtherTransferCount.QuadPart;
+ PROCESS_VALUES Values;
+
+ KeQueryValuesProcess(&Process->Pcb, &Values);
+ BasicAndIo.BasicInfo.TotalUserTime.QuadPart +=
Values.TotalUserTime.QuadPart;
+ BasicAndIo.BasicInfo.TotalKernelTime.QuadPart +=
Values.TotalKernelTime.QuadPart;
+ BasicAndIo.IoInfo.ReadOperationCount +=
Values.IoInfo.ReadOperationCount;
+ BasicAndIo.IoInfo.WriteOperationCount +=
Values.IoInfo.WriteOperationCount;
+ BasicAndIo.IoInfo.OtherOperationCount +=
Values.IoInfo.OtherOperationCount;
+ BasicAndIo.IoInfo.ReadTransferCount +=
Values.IoInfo.ReadTransferCount;
+ BasicAndIo.IoInfo.WriteTransferCount +=
Values.IoInfo.WriteTransferCount;
+ BasicAndIo.IoInfo.OtherTransferCount +=
Values.IoInfo.OtherTransferCount;
}
}
diff --git a/ntoskrnl/ps/query.c b/ntoskrnl/ps/query.c
index 40a365a253..7a1767d54f 100644
--- a/ntoskrnl/ps/query.c
+++ b/ntoskrnl/ps/query.c
@@ -82,6 +82,7 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
PUNICODE_STRING ImageName;
ULONG Cookie, ExecuteOptions = 0;
ULONG_PTR Wow64 = 0;
+ PROCESS_VALUES ProcessValues;
PAGED_CODE();
/* Check for user-mode caller */
@@ -251,15 +252,12 @@ NtQueryInformationProcess(IN HANDLE ProcessHandle,
NULL);
if (!NT_SUCCESS(Status)) break;
+ /* Query IO counters from the process */
+ KeQueryValuesProcess(&Process->Pcb, &ProcessValues);
+
_SEH2_TRY
{
- /* FIXME: Call KeQueryValuesProcess */
- IoCounters->ReadOperationCount =
Process->ReadOperationCount.QuadPart;
- IoCounters->ReadTransferCount =
Process->ReadTransferCount.QuadPart;
- IoCounters->WriteOperationCount =
Process->WriteOperationCount.QuadPart;
- IoCounters->WriteTransferCount =
Process->WriteTransferCount.QuadPart;
- IoCounters->OtherOperationCount =
Process->OtherOperationCount.QuadPart;
- IoCounters->OtherTransferCount =
Process->OtherTransferCount.QuadPart;
+ RtlCopyMemory(IoCounters, &ProcessValues.IoInfo,
sizeof(IO_COUNTERS));
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{