Damjan Jovanovic : ntdll: Implement setting SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION.IdleTime on FreeBSD.

Alexandre Julliard julliard at winehq.org
Wed Nov 3 16:42:01 CDT 2021


Module: wine
Branch: master
Commit: 478a7dbc90477de85dc8c98429af99e156e92b8a
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=478a7dbc90477de85dc8c98429af99e156e92b8a

Author: Damjan Jovanovic <damjan.jov at gmail.com>
Date:   Sun Oct 31 17:47:26 2021 +0200

ntdll: Implement setting SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION.IdleTime on FreeBSD.

Signed-off-by: Damjan Jovanovic <damjan.jov at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/unix/system.c | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c
index c37fc360f3e..6640a66597b 100644
--- a/dlls/ntdll/unix/system.c
+++ b/dlls/ntdll/unix/system.c
@@ -52,6 +52,9 @@
 #ifdef HAVE_SYS_RANDOM_H
 # include <sys/random.h>
 #endif
+#ifdef HAVE_SYS_RESOURCE_H
+# include <sys/resource.h>
+#endif
 #ifdef HAVE_IOKIT_IOKITLIB_H
 # include <CoreFoundation/CoreFoundation.h>
 # include <IOKit/IOKitLib.h>
@@ -2611,7 +2614,7 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
                 vm_deallocate (mach_task_self (), (vm_address_t) pinfo, info_count * sizeof(natural_t));
             }
         }
-#else
+#elif defined(linux)
         {
             FILE *cpuinfo = fopen("/proc/stat", "r");
             if (cpuinfo)
@@ -2644,6 +2647,33 @@ NTSTATUS WINAPI NtQuerySystemInformation( SYSTEM_INFORMATION_CLASS class,
                 fclose(cpuinfo);
             }
         }
+#elif defined(__FreeBSD__) || defined (__FreeBSD_kernel__)
+        {
+            static int clockrate_name[] = { CTL_KERN, KERN_CLOCKRATE };
+            size_t size = 0;
+            struct clockinfo clockrate;
+            int have_clockrate;
+            long *ptimes;
+
+            size = sizeof(clockrate);
+            have_clockrate = !sysctl(clockrate_name, 2, &clockrate, &size, NULL, 0);
+            size = out_cpus * CPUSTATES * sizeof(long);
+            ptimes = malloc(size + 1);
+            if (ptimes)
+            {
+                if (have_clockrate && (!sysctlbyname("kern.cp_times", ptimes, &size, NULL, 0) || errno == ENOMEM))
+                {
+                    for (cpus = 0; cpus < out_cpus; cpus++)
+                    {
+                        if (cpus * CPUSTATES * sizeof(long) >= size) break;
+                        sppi[cpus].IdleTime.QuadPart = (ULONGLONG)ptimes[cpus*CPUSTATES + CP_IDLE] * 10000000 / clockrate.stathz;
+                        sppi[cpus].KernelTime.QuadPart = (ULONGLONG)ptimes[cpus*CPUSTATES + CP_SYS] * 10000000 / clockrate.stathz;
+                        sppi[cpus].UserTime.QuadPart = (ULONGLONG)ptimes[cpus*CPUSTATES + CP_USER] * 10000000 / clockrate.stathz;
+                    }
+                }
+                free(ptimes);
+            }
+        }
 #endif
         if (cpus == 0)
         {




More information about the wine-cvs mailing list