[netperf-dev] netperf2 commit notice r60 - in trunk: . src

raj at netperf.org raj at netperf.org
Fri Mar 17 14:13:56 PST 2006


Author: raj
Date: 2006-03-17 14:13:53 -0800 (Fri, 17 Mar 2006)
New Revision: 60

Added:
   trunk/src/netcpu_osx.c
Modified:
   trunk/AUTHORS
   trunk/Release_Notes
   trunk/config.h.in
   trunk/configure
   trunk/configure.ac
   trunk/src/netlib.c
   trunk/src/netlib.h
Log:
Additions from "Anonymous" to enable CPU utilization measurment on OSX


Modified: trunk/AUTHORS
===================================================================
--- trunk/AUTHORS	2006-03-17 01:50:04 UTC (rev 59)
+++ trunk/AUTHORS	2006-03-17 22:13:53 UTC (rev 60)
@@ -164,4 +164,7 @@
 Studio 2003
 
 George Davis
-Changes to deal with different floating-point formats.
\ No newline at end of file
+Changes to deal with different floating-point formats.
+
+Anonymous
+Changes to retrieve CPU util on MacOS X.
\ No newline at end of file

Modified: trunk/Release_Notes
===================================================================
--- trunk/Release_Notes	2006-03-17 01:50:04 UTC (rev 59)
+++ trunk/Release_Notes	2006-03-17 22:13:53 UTC (rev 60)
@@ -5,6 +5,8 @@
 *) Fixes for floating point format differences, courtesy of George
    Davis.
 
+*) Additions for CPU util support on MacOS X, courtesy of Anonymous.
+
 These are the Release Notes for Revision 2.4.1 of netperf:
 
 Things changed in this release:

Modified: trunk/config.h.in
===================================================================
--- trunk/config.h.in	2006-03-17 01:50:04 UTC (rev 59)
+++ trunk/config.h.in	2006-03-17 22:13:53 UTC (rev 60)
@@ -252,6 +252,9 @@
 /* Use looper/soaker processes to measure CPU util. */
 #undef USE_LOOPER
 
+/* Use MacOS X's host_info interface to measure CPU util. */
+#undef USE_OSX
+
 /* Use AIX's perfstat interface to measure CPU util. */
 #undef USE_PERFSTAT
 

Modified: trunk/configure
===================================================================
--- trunk/configure	2006-03-17 01:50:04 UTC (rev 59)
+++ trunk/configure	2006-03-17 22:13:53 UTC (rev 60)
@@ -7682,6 +7682,14 @@
 ac_cv_lib_kstat=ac_cv_lib_kstat_main
 
 		;;
+	osx)
+		use_cpuutil=true
+
+cat >>confdefs.h <<\_ACEOF
+#define USE_OSX
+_ACEOF
+
+		;;
 	'')
 # ia64-hp-hpux11.23
 # i386-pc-solaris2.10
@@ -7961,6 +7969,16 @@
 			enable_cpuutil="sysctl - auto"
 			NETCPU_SOURCE="sysctl"
 			;;
+		    *-*-darwin*)
+			use_cpuutil=true
+
+cat >>confdefs.h <<\_ACEOF
+#define USE_OSX
+_ACEOF
+
+			enable_cpuutil="osx - auto"
+			NETCPU_SOURCE="osx"
+			;;
 		     *)
 			use_cpuutil=false
 			NETCPU_SOURCE="none"

Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2006-03-17 01:50:04 UTC (rev 59)
+++ trunk/configure.ac	2006-03-17 22:13:53 UTC (rev 60)
@@ -482,6 +482,10 @@
 		AC_DEFINE([USE_KSTAT],,[Use Solaris's kstat interface to measure CPU util.])
 		AC_HAVE_LIBRARY(kstat)
 		;;
+	osx)
+		use_cpuutil=true
+		AC_DEFINE([USE_OSX],,[Use MacOS X's host_info interface to measure CPU util.])
+		;;
 	'')
 # ia64-hp-hpux11.23
 # i386-pc-solaris2.10
@@ -532,6 +536,12 @@
 			enable_cpuutil="sysctl - auto"
 			NETCPU_SOURCE="sysctl"
 			;;
+		    *-*-darwin*)
+			use_cpuutil=true
+			AC_DEFINE([USE_OSX],,[Use MacOS X's host_info interface to measure CPU util.])
+			enable_cpuutil="osx - auto"
+			NETCPU_SOURCE="osx"
+			;;
 		     *)
 			use_cpuutil=false
 			NETCPU_SOURCE="none"

Added: trunk/src/netcpu_osx.c
===================================================================
--- trunk/src/netcpu_osx.c	2006-03-17 01:50:04 UTC (rev 59)
+++ trunk/src/netcpu_osx.c	2006-03-17 22:13:53 UTC (rev 60)
@@ -0,0 +1,144 @@
+char   netcpu_sysctl_id[]="\
+@(#)netcpu_osx.c  Version 2.4.0";
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+
+#if HAVE_INTTYPES_H
+# include <inttypes.h>
+#else
+# if HAVE_STDINT_H
+#  include <stdint.h>
+# endif
+#endif
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+#if HAVE_LIMITS_H
+# include <limits.h>
+# ifndef LONG_LONG_MAX
+#  define LONG_LONG_MAX LLONG_MAX
+# endif /* LONG_LONG_MAX */
+#endif
+
+
+#include <errno.h>
+
+#include <mach/host_info.h>
+#include <mach/mach_types.h>
+
+
+#include "netsh.h"
+#include "netlib.h"
+
+#define UNSIGNED_DIFFERENCE(x,y) (x >= y ? x - y : (0 - y) + x )
+
+static host_cpu_load_info_data_t lib_start_ticks;
+static host_cpu_load_info_data_t lib_end_ticks;
+
+static mach_port_t lib_host_port;
+
+void
+cpu_util_init(void) 
+{
+  lib_host_port = mach_host_self();
+  return;
+}
+
+void
+cpu_util_terminate(void)
+{
+  mach_port_deallocate(lib_host_port);
+  return;
+}
+
+int
+get_cpu_method(void)
+{
+  return OSX;
+}
+
+void
+get_cpu_idle(uint64_t *res)
+{
+    return;
+}
+
+void
+get_host_ticks(host_cpu_load_info_t info)
+{
+  mach_msg_type_number_t count;
+
+  count = HOST_CPU_LOAD_INFO_COUNT;
+  host_statistics(lib_host_port, HOST_CPU_LOAD_INFO, (host_info_t)info, &count);
+  return;
+}
+
+/* calibrate_sysctl  - perform the idle rate calculation using the
+   sysctl call - typically on BSD */
+
+float
+calibrate_idle_rate(int iterations, int interval)
+{
+    return (float)0.0;   
+}
+
+float
+calc_cpu_util_internal(float elapsed_time)
+{
+  float correction_factor;
+  natural_t	userticks, systicks, idleticks, totalticks;
+
+  lib_local_cpu_util = (float)0.0;
+  /* It is possible that the library measured a time other than */
+  /* the one that the user want for the cpu utilization */
+  /* calculations - for example, tests that were ended by */
+  /* watchdog timers such as the udp stream test. We let these */
+  /* tests tell up what the elapsed time should be. */
+  
+  if (elapsed_time != 0.0) {
+    correction_factor = (float) 1.0 + 
+      ((lib_elapsed - elapsed_time) / elapsed_time);
+  }
+  else {
+    correction_factor = (float) 1.0;
+  }
+
+  if (debug) {
+    fprintf(where, "correction factor: %f\n", correction_factor);
+  }
+
+  userticks = UNSIGNED_DIFFERENCE((lib_end_ticks.cpu_ticks[CPU_STATE_USER] + lib_end_ticks.cpu_ticks[CPU_STATE_NICE]),
+				  (lib_start_ticks.cpu_ticks[CPU_STATE_USER] + lib_start_ticks.cpu_ticks[CPU_STATE_NICE]));
+  systicks = UNSIGNED_DIFFERENCE(lib_end_ticks.cpu_ticks[CPU_STATE_SYSTEM], lib_start_ticks.cpu_ticks[CPU_STATE_SYSTEM]);
+  idleticks = UNSIGNED_DIFFERENCE(lib_end_ticks.cpu_ticks[CPU_STATE_IDLE], lib_start_ticks.cpu_ticks[CPU_STATE_IDLE]);
+  totalticks = userticks + systicks + idleticks;
+
+  lib_local_cpu_util = (float)idleticks/(float)totalticks * 100.0f;
+  lib_local_cpu_util *= correction_factor;
+
+  return lib_local_cpu_util;
+
+}
+void
+cpu_start_internal(void)
+{
+    get_host_ticks(&lib_start_ticks);
+}
+
+void
+cpu_stop_internal(void)
+{
+    get_host_ticks(&lib_end_ticks);
+}

Modified: trunk/src/netlib.c
===================================================================
--- trunk/src/netlib.c	2006-03-17 01:50:04 UTC (rev 59)
+++ trunk/src/netlib.c	2006-03-17 22:13:53 UTC (rev 60)
@@ -1629,6 +1629,9 @@
   case SYSCTL:
     method_char = 'C';
     break;
+  case OSX:
+    method_char = 'O';
+    break;
   default:
     method_char = '?';
   }

Modified: trunk/src/netlib.h
===================================================================
--- trunk/src/netlib.h	2006-03-17 01:50:04 UTC (rev 59)
+++ trunk/src/netlib.h	2006-03-17 22:13:53 UTC (rev 60)
@@ -373,6 +373,7 @@
 #define SYSCTL          9
 #define PERFSTAT       10
 #define KSTAT_10       11
+#define OSX            12
 
 #define BADCH ('?')
 



More information about the netperf-dev mailing list