ntdll: Rewrite the SystemProcessorPerformanceInformation handing to avoid code duplication.
Also include idle time in kernel time.
This commit is contained in:
parent
c3dc0cfa32
commit
cc01c46f41
|
@ -1310,25 +1310,6 @@ void fill_cpu_info(void)
|
||||||
cached_sci.Architecture, cached_sci.Level, cached_sci.Revision, cached_sci.FeatureSet);
|
cached_sci.Architecture, cached_sci.Level, cached_sci.Revision, cached_sci.FeatureSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fill_in_sppi(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *sppi, DWORD64 idle, DWORD64 sys, DWORD64 usr)
|
|
||||||
{
|
|
||||||
DWORD64 steal;
|
|
||||||
sppi->IdleTime.QuadPart = idle * 10000000 / sysconf(_SC_CLK_TCK);
|
|
||||||
sppi->KernelTime.QuadPart = sys * 10000000 / sysconf(_SC_CLK_TCK);
|
|
||||||
sppi->UserTime.QuadPart = usr * 10000000 / sysconf(_SC_CLK_TCK);
|
|
||||||
|
|
||||||
/* Add 1% from idle time to kernel time, to make .NET happy */
|
|
||||||
steal = sppi->IdleTime.QuadPart / 100;
|
|
||||||
sppi->IdleTime.QuadPart -= steal;
|
|
||||||
sppi->KernelTime.QuadPart += steal;
|
|
||||||
|
|
||||||
/* DPC time */
|
|
||||||
sppi->Reserved1[0].QuadPart = 0;
|
|
||||||
/* Interrupt time */
|
|
||||||
sppi->Reserved1[1].QuadPart = 0;
|
|
||||||
sppi->Reserved2 = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* NtQuerySystemInformation [NTDLL.@]
|
* NtQuerySystemInformation [NTDLL.@]
|
||||||
* ZwQuerySystemInformation [NTDLL.@]
|
* ZwQuerySystemInformation [NTDLL.@]
|
||||||
|
@ -1605,66 +1586,36 @@ NTSTATUS WINAPI NtQuerySystemInformation(
|
||||||
FILE *cpuinfo = fopen("/proc/stat", "r");
|
FILE *cpuinfo = fopen("/proc/stat", "r");
|
||||||
if (cpuinfo)
|
if (cpuinfo)
|
||||||
{
|
{
|
||||||
|
unsigned long clk_tck = sysconf(_SC_CLK_TCK);
|
||||||
unsigned long usr,nice,sys,idle,remainder[8];
|
unsigned long usr,nice,sys,idle,remainder[8];
|
||||||
int count;
|
int i, count;
|
||||||
char name[10];
|
char name[32];
|
||||||
char line[255];
|
char line[255];
|
||||||
|
|
||||||
/* first line is combined usage */
|
/* first line is combined usage */
|
||||||
if (fgets(line,255,cpuinfo))
|
while (fgets(line,255,cpuinfo))
|
||||||
count = sscanf(line, "%s %lu %lu %lu %lu "
|
|
||||||
"%lu %lu %lu %lu %lu %lu %lu %lu",
|
|
||||||
name, &usr, &nice, &sys, &idle,
|
|
||||||
&remainder[0], &remainder[1], &remainder[2],
|
|
||||||
&remainder[3], &remainder[4], &remainder[5],
|
|
||||||
&remainder[6], &remainder[7]);
|
|
||||||
else
|
|
||||||
count = 0;
|
|
||||||
/* we set this up in the for older non-smp enabled kernels */
|
|
||||||
if (count >= 5 && strcmp(name, "cpu") == 0)
|
|
||||||
{
|
{
|
||||||
int i;
|
count = sscanf(line, "%s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu",
|
||||||
for (i = 0; i + 5 < count; ++i)
|
name, &usr, &nice, &sys, &idle,
|
||||||
sys += remainder[i];
|
&remainder[0], &remainder[1], &remainder[2], &remainder[3],
|
||||||
usr += nice;
|
&remainder[4], &remainder[5], &remainder[6], &remainder[7]);
|
||||||
sppi = RtlAllocateHeap(GetProcessHeap(), 0,
|
|
||||||
sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION));
|
|
||||||
fill_in_sppi(sppi, idle, sys, usr);
|
|
||||||
cpus = 1;
|
|
||||||
len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
do
|
if (count < 5 || strncmp( name, "cpu", 3 )) break;
|
||||||
{
|
for (i = 0; i + 5 < count; ++i) sys += remainder[i];
|
||||||
if (fgets(line, 255, cpuinfo))
|
sys += idle;
|
||||||
count = sscanf(line, "%s %lu %lu %lu %lu "
|
|
||||||
"%lu %lu %lu %lu %lu %lu %lu %lu",
|
|
||||||
name, &usr, &nice, &sys, &idle,
|
|
||||||
&remainder[0], &remainder[1], &remainder[2],
|
|
||||||
&remainder[3], &remainder[4], &remainder[5],
|
|
||||||
&remainder[6], &remainder[7]);
|
|
||||||
else
|
|
||||||
count = 0;
|
|
||||||
if (count >= 5 && strncmp(name, "cpu", 3)==0)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for (i = 0; i + 5 < count; ++i)
|
|
||||||
sys += remainder[i];
|
|
||||||
usr += nice;
|
usr += nice;
|
||||||
out_cpus --;
|
cpus = atoi( name + 3 ) + 1;
|
||||||
if (name[3]=='0') /* first cpu */
|
if (cpus > out_cpus) break;
|
||||||
fill_in_sppi(sppi, idle, sys, usr);
|
len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * cpus;
|
||||||
else /* new cpu */
|
if (sppi)
|
||||||
{
|
sppi = RtlReAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, sppi, len );
|
||||||
len = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * (cpus+1);
|
|
||||||
sppi = RtlReAllocateHeap(GetProcessHeap(), 0, sppi, len);
|
|
||||||
fill_in_sppi(sppi + cpus, idle, sys, usr);
|
|
||||||
cpus++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
break;
|
sppi = RtlAllocateHeap( GetProcessHeap(), HEAP_ZERO_MEMORY, len );
|
||||||
} while (out_cpus > 0);
|
|
||||||
|
sppi[cpus-1].IdleTime.QuadPart = (ULONGLONG)idle * 10000000 / clk_tck;
|
||||||
|
sppi[cpus-1].KernelTime.QuadPart = (ULONGLONG)sys * 10000000 / clk_tck;
|
||||||
|
sppi[cpus-1].UserTime.QuadPart = (ULONGLONG)usr * 10000000 / clk_tck;
|
||||||
|
}
|
||||||
fclose(cpuinfo);
|
fclose(cpuinfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue