blob: eaa8df1b22aa8ecc020d48ef784cca4559ad16a5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
--- src/gpm-load.c.orig 2010-01-01 23:29:11.000000000 -0500
+++ src/gpm-load.c 2010-01-01 23:46:31.000000000 -0500
@@ -33,6 +33,10 @@
#include <kstat.h>
#include <sys/sysinfo.h>
#endif
+#if defined(__FreeBSD__)
+#include <sys/resource.h>
+#include <sys/sysctl.h>
+#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
@@ -151,6 +155,32 @@ out:
return FALSE;
}
+#elif defined(__FreeBSD__)
+
+/**
+ * gpm_load_get_cpu_values:
+ * @cpu_idle: The idle time reported by the CPU
+ * @cpu_total: The total time reported by the CPU
+ * Return value: Success of reading of the kern.cp_time sysctl.
+ **/
+static gboolean
+gpm_load_get_cpu_values (long unsigned *cpu_idle, long unsigned *cpu_total)
+{
+ long cpts[CPUSTATES];
+ size_t length;
+
+ length = sizeof (cpts);
+ if (sysctlbyname ("kern.cp_time", cpts, &length, NULL, 0)) {
+ return FALSE;
+ }
+
+ *cpu_idle = (unsigned long) cpts[CP_IDLE];
+ *cpu_total = (unsigned long) (cpts[CP_USER] + cpts[CP_NICE] + \
+ cpts[CP_SYS] + cpts[CP_IDLE] + cpts[CP_INTR]);
+
+ return TRUE;
+}
+
#else
/**
@@ -192,7 +222,7 @@ gpm_load_get_cpu_values (long unsigned *
*cpu_total = cpu_user + cpu_nice + cpu_system + *cpu_idle;
ret = TRUE;
out:
- if (!fd)
+ if (fd)
fclose (fd);
return ret;
}
|