summaryrefslogtreecommitdiff
path: root/parallel/sge/patches/patch-ax
blob: bff311c0c30d70790c47421d1b2be9681093bf3b (plain)
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
$NetBSD: patch-ax,v 1.1.1.1 2004/05/03 00:38:35 dmcmahill Exp $

--- source/libs/uti/sge_getloadavg.c	2003-10-02 14:25:49.000000000 +0200
+++ source/libs/uti/sge_getloadavg.c	2003-10-01 17:11:38.000000000 +0200
@@ -185,6 +185,8 @@
 #  define KERNEL_AVG_TYPE double 
 #  define VMUNIX "/stand/vmunix"
 #  define X_CP_TIME 0 
+#elif defined(NETBSD)
+#  include <sys/sched.h>
 #endif
 
 #if defined(SOLARIS) || defined(SOLARIS64) || defined(FREEBSD)
@@ -827,6 +829,30 @@
    return cpu_load;
 }
 
+#elif defined(NETBSD)
+
+#include <sys/param.h>
+#include <sys/sysctl.h>
+
+double get_cpu_load() {
+  int mib[2];
+  static long cpu_time[CPUSTATES];
+  static long cpu_old[CPUSTATES];
+  static long cpu_diff[CPUSTATES];
+  double cpu_states[CPUSTATES];
+  double cpu_load;
+  size_t size;
+
+  mib[0] = CTL_KERN; mib[1] = KERN_CP_TIME;
+  size = sizeof(cpu_time);
+  sysctl(mib, 2, &cpu_time, &size, NULL, 0);
+  percentages(CPUSTATES, cpu_states, cpu_time, cpu_old, cpu_diff);
+  cpu_load = cpu_states[0] + cpu_states[1] + cpu_states[2];
+  if (cpu_load < 0.0) {
+    cpu_load = -1.0; }
+
+  return cpu_load; }
+
 #endif
 
 #if defined(ALPHA4) || defined(ALPHA5) || defined(IRIX6) || defined(HP10) || (defined(SOLARIS) && !defined(SOLARIS64))
@@ -1150,7 +1176,7 @@
 ) {
    int elem = 0;   
 
-#if defined(SOLARIS64) || defined(FREEBSD) || defined(DARWIN)
+#if defined(SOLARIS64) || defined(FREEBSD) || defined(DARWIN) || defined(NETBSD)
    elem = getloadavg(loadavg, nelem); /* <== library function */
 #elif (defined(SOLARIS) && !defined(SOLARIS64)) || defined(ALPHA4) || defined(ALPHA5) || defined(IRIX6) || defined(HP10) || defined(HP11) || defined(CRAY) || defined(NECSX4) || defined(NECSX5) || defined(LINUX)
    elem = get_load_avg(loadavg, nelem);