[netperf-dev] netperf2 commit notice r66 - in trunk: . doc src
raj at netperf.org
raj at netperf.org
Fri Apr 14 14:27:54 PDT 2006
Author: raj
Date: 2006-04-14 14:27:52 -0700 (Fri, 14 Apr 2006)
New Revision: 66
Modified:
trunk/configure
trunk/configure.ac
trunk/doc/Makefile.am
trunk/doc/Makefile.in
trunk/src/netcpu_procstat.c
trunk/src/netcpu_sysctl.c
Log:
Avoid making the manual in a make dist and some changes to make the
sysctl CPU util method calibration-free. Still trying to figure-out
what may be going wrong in the procstat CPU method.
Modified: trunk/configure
===================================================================
--- trunk/configure 2006-04-04 01:09:54 UTC (rev 65)
+++ trunk/configure 2006-04-14 21:27:52 UTC (rev 66)
@@ -5032,19 +5032,25 @@
ac_cv_func_fork_works=cross
else
cat >conftest.$ac_ext <<_ACEOF
-/* By Ruediger Kuhlmann. */
- #include <sys/types.h>
- #if HAVE_UNISTD_H
- # include <unistd.h>
- #endif
- /* Some systems only have a dummy stub for fork() */
- int main ()
- {
- if (fork() < 0)
- exit (1);
- exit (0);
- }
+/* confdefs.h. */
_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_includes_default
+int
+main ()
+{
+
+ /* By Ruediger Kuhlmann. */
+ if (fork() < 0)
+ exit (1);
+ exit (0);
+
+ ;
+ return 0;
+}
+_ACEOF
rm -f conftest$ac_exeext
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
(eval $ac_link) 2>&5
@@ -7964,7 +7970,8 @@
enable_cpuutil="kstat - auto"
NETCPU_SOURCE="kstat"
;;
- *-*-freebsd4.*)
+ *-*-freebsd4.* | *-*-freebsd5.* | *-*-freebsd6.* | *-*-fre
+ebsd7.* )
use_cpuutil=true
cat >>confdefs.h <<\_ACEOF
Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac 2006-04-04 01:09:54 UTC (rev 65)
+++ trunk/configure.ac 2006-04-14 21:27:52 UTC (rev 66)
@@ -531,7 +531,8 @@
enable_cpuutil="kstat - auto"
NETCPU_SOURCE="kstat"
;;
- *-*-freebsd4.*)
+ *-*-freebsd4.* | *-*-freebsd5.* | *-*-freebsd6.* | *-*-fre
+ebsd7.* )
use_cpuutil=true
AC_DEFINE([USE_SYSCTL],,[Use FreeBSD's sysctl interface to measure CPU util.])
enable_cpuutil="sysctl - auto"
Modified: trunk/doc/Makefile.am
===================================================================
--- trunk/doc/Makefile.am 2006-04-04 01:09:54 UTC (rev 65)
+++ trunk/doc/Makefile.am 2006-04-14 21:27:52 UTC (rev 66)
@@ -1,4 +1,7 @@
-EXTRA_DIST = netperf.man netserver.man netperf.txt netperf.html netperf.xml netperf_old.ps netperf.pdf netperf.ps netperf.texi examples
+# what is your philosophy - distribute pre-made .pdf et al in a make dist
+# or not? choose your EXTRA_DIST line accordingly
+# EXTRA_DIST = netperf.man netserver.man netperf.txt netperf.html netperf.xml netperf_old.ps netperf.pdf netperf.ps netperf.texi examples
+EXTRA_DIST = netperf.man netserver.man netperf_old.ps netperf.texi examples
man1_MANS = netperf.man netserver.man
info_TEXINFOS = netperf.texi
CLEANFILES = netperf.txt netperf.xml netperf.html
Modified: trunk/doc/Makefile.in
===================================================================
--- trunk/doc/Makefile.in 2006-04-04 01:09:54 UTC (rev 65)
+++ trunk/doc/Makefile.in 2006-04-14 21:27:52 UTC (rev 66)
@@ -118,7 +118,11 @@
target_cpu = @target_cpu@
target_os = @target_os@
target_vendor = @target_vendor@
-EXTRA_DIST = netperf.man netserver.man netperf.txt netperf.html netperf.xml netperf_old.ps netperf.pdf netperf.ps netperf.texi examples
+
+# what is your philosophy - distribute pre-made .pdf et al in a make dist
+# or not? choose your EXTRA_DIST line accordingly
+# EXTRA_DIST = netperf.man netserver.man netperf.txt netperf.html netperf.xml netperf_old.ps netperf.pdf netperf.ps netperf.texi examples
+EXTRA_DIST = netperf.man netserver.man netperf_old.ps netperf.texi examples
man1_MANS = netperf.man netserver.man
info_TEXINFOS = netperf.texi
CLEANFILES = netperf.txt netperf.xml netperf.html
Modified: trunk/src/netcpu_procstat.c
===================================================================
--- trunk/src/netcpu_procstat.c 2006-04-04 01:09:54 UTC (rev 65)
+++ trunk/src/netcpu_procstat.c 2006-04-14 21:27:52 UTC (rev 66)
@@ -50,12 +50,20 @@
#define N_CPU_LINES(nr) (nr == 1 ? 1 : 1 + nr)
static int proc_stat_fd = -1;
-static char* proc_stat_buf = NULL;
+static char *proc_stat_buf = NULL;
static int proc_stat_buflen = 0;
void
cpu_util_init(void)
{
+
+ if (debug) {
+ fprintf(where,
+ "cpu_util_init enter, proc_stat_fd %d proc_stat_buf %p\n",
+ proc_stat_fd,
+ proc_stat_buf);
+ fflush(where);
+ }
if (proc_stat_fd < 0) {
proc_stat_fd = open (PROC_STAT_FILE_NAME, O_RDONLY, NULL);
if (proc_stat_fd < 0) {
@@ -66,12 +74,21 @@
if (!proc_stat_buf) {
proc_stat_buflen = N_CPU_LINES (lib_num_loc_cpus) * CPU_LINE_LENGTH;
+ if (debug) {
+ fprintf(where,
+ "lib_num_loc_cpus %d lines %d CPU_LINE_LENGTH %d proc_stat_buflen %d\n",
+ lib_num_loc_cpus,
+ N_CPU_LINES(lib_num_loc_cpus),
+ CPU_LINE_LENGTH,
+ proc_stat_buflen);
+ fflush(where);
+ }
proc_stat_buf = (char *)malloc (proc_stat_buflen);
if (!proc_stat_buf) {
fprintf (stderr, "Cannot allocate buffer memory!\n");
exit (1);
- };
- };
+ }
+ }
return;
}
@@ -104,6 +121,15 @@
if (!proc_stat_buf) {
proc_stat_buflen = N_CPU_LINES (lib_num_loc_cpus) * CPU_LINE_LENGTH;
+ if (debug) {
+ fprintf(where,
+ "calibrate: lib_num_loc_cpus %d lines %d CPU_LINE_LENGTH %d proc_stat_buflen %d\n",
+ lib_num_loc_cpus,
+ N_CPU_LINES(lib_num_loc_cpus),
+ CPU_LINE_LENGTH,
+ proc_stat_buflen);
+ fflush(where);
+ }
proc_stat_buf = (char *)malloc (proc_stat_buflen);
if (!proc_stat_buf) {
fprintf (stderr, "Cannot allocate buffer memory!\n");
@@ -126,7 +152,7 @@
read (proc_stat_fd, p, proc_stat_buflen);
if (debug) {
- fprintf(where,"proc_stat_buf %s\n",p);
+ fprintf(where,"proc_stat_buf '%.*s'\n",proc_stat_buflen,p);
fflush(where);
}
/* Skip first line (total) on SMP */
Modified: trunk/src/netcpu_sysctl.c
===================================================================
--- trunk/src/netcpu_sysctl.c 2006-04-04 01:09:54 UTC (rev 65)
+++ trunk/src/netcpu_sysctl.c 2006-04-14 21:27:52 UTC (rev 66)
@@ -6,6 +6,7 @@
#endif
#include <stdio.h>
+#include <unistd.h>
#if HAVE_INTTYPES_H
# include <inttypes.h>
@@ -54,8 +55,8 @@
#include "netsh.h"
#include "netlib.h"
-static uint64_t lib_start_count[MAXCPUS];
-static uint64_t lib_end_count[MAXCPUS];
+static long lib_start_count[CPUSTATES];
+static long lib_end_count[CPUSTATES];
void
cpu_util_init(void)
@@ -75,18 +76,15 @@
return SYSCTL;
}
-void
-get_cpu_idle(uint64_t *res)
+static void
+get_cpu_time(long *cpu_time)
{
- int i;
- long cp_time[CPUSTATES];
- size_t cp_time_len = sizeof(cp_time);
- if (sysctlbyname("kern.cp_time",cp_time,&cp_time_len,NULL,0) != -1) {
- for (i = 0; i < lib_num_loc_cpus; i++){
- res[i] = cp_time[CP_IDLE];
- }
+ size_t cpu_time_len = CPUSTATES * sizeof (cpu_time[0]);
+
+ if (sysctlbyname("kern.cp_time", cpu_time, &cpu_time_len, NULL, 0) == -1) {
+ fprintf (stderr, "Cannot get CPU time!\n");
+ exit (1);
}
- return;
}
/* calibrate_sysctl - perform the idle rate calculation using the
@@ -95,194 +93,35 @@
float
calibrate_idle_rate(int iterations, int interval)
{
- long
- firstcnt[MAXCPUS],
- secondcnt[MAXCPUS];
-
- long cp_time[CPUSTATES];
- size_t cp_time_len = sizeof(cp_time);
-
- float
- elapsed,
- temp_rate,
- rate[MAXTIMES],
- local_maxrate;
-
- long
- sec,
- usec;
-
- int
- i,
- j;
-
- long count;
-
- struct timeval time1, time2;
- struct timezone tz;
-
- if (iterations > MAXTIMES) {
- iterations = MAXTIMES;
- }
-
- local_maxrate = -1.0;
-
-
- for(i = 0; i < iterations; i++) {
- rate[i] = 0.0;
- /* get the idle counter for each processor */
- if (sysctlbyname("kern.cp_time",cp_time,&cp_time_len,NULL,0) != -1) {
- for (j = 0; j < lib_num_loc_cpus; j++) {
- firstcnt[j] = cp_time[CP_IDLE];
- }
- }
- else {
- fprintf(where,"sysctl failure errno %d\n",errno);
- fflush(where);
- exit(1);
- }
-
- gettimeofday (&time1, &tz);
- sleep(interval);
- gettimeofday (&time2, &tz);
-
- if (time2.tv_usec < time1.tv_usec)
- {
- time2.tv_usec += 1000000;
- time2.tv_sec -=1;
- }
- sec = time2.tv_sec - time1.tv_sec;
- usec = time2.tv_usec - time1.tv_usec;
- elapsed = (float)sec + ((float)usec/(float)1000000.0);
-
- if(debug) {
- fprintf(where, "Calibration for counter run: %d\n",i);
- fprintf(where,"\tsec = %ld usec = %ld\n",sec,usec);
- fprintf(where,"\telapsed time = %g\n",elapsed);
- }
-
- if (sysctlbyname("kern.cp_time",cp_time,&cp_time_len,NULL,0) != -1) {
- for (j = 0; j < lib_num_loc_cpus; j++) {
- secondcnt[j] = cp_time[CP_IDLE];
- if(debug) {
- /* I know that there are situations where compilers know about */
- /* long long, but the library fucntions do not... raj 4/95 */
- fprintf(where,
- "\tfirstcnt[%d] = 0x%8.8lx secondcnt[%d] = 0x%8.8lx\n",
- j,
- firstcnt[j],
- j,
- secondcnt[j]);
- }
- temp_rate = (secondcnt[j] >= firstcnt[j]) ?
- (float)(secondcnt[j] - firstcnt[j] )/elapsed :
- (float)(secondcnt[j] - firstcnt[j] + LONG_LONG_MAX)/elapsed;
- if (temp_rate > rate[i]) rate[i] = temp_rate;
- if (debug) {
- fprintf(where,"\trate[%d] = %g\n",i,rate[i]);
- fflush(where);
- }
- if (local_maxrate < rate[i]) local_maxrate = rate[i];
- }
- }
- else {
- fprintf(where,"sysctl failure; errno %d\n",errno);
- fflush(where);
- exit(1);
- }
- }
- if(debug) {
- fprintf(where,"\tlocal maxrate = %g per sec. \n",local_maxrate);
- fflush(where);
- }
- return local_maxrate;
+ return sysconf (_SC_CLK_TCK);
}
float
calc_cpu_util_internal(float elapsed_time)
{
+ long sum_idle, sum_busy;
int i;
- float actual_rate;
- float correction_factor;
-
- 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);
+ for (sum_busy = 0, i = 0; i < CPUSTATES; i++) {
+ if (i != CP_IDLE)
+ sum_busy += lib_end_count[i] - lib_start_count[i];
}
- else {
- correction_factor = (float) 1.0;
- }
- /* this looks just like the looper case. at least I think it */
- /* should :) raj 4/95 */
- for (i = 0; i < lib_num_loc_cpus; i++) {
-
- /* we assume that the two are not more than a long apart. I */
- /* know that this is bad, but trying to go from long longs to */
- /* a float (perhaps a double) is boggling my mind right now. */
- /* raj 4/95 */
-
- long long
- diff;
-
- if (lib_end_count[i] >= lib_start_count[i]) {
- diff = lib_end_count[i] - lib_start_count[i];
- }
- else {
- diff = lib_end_count[i] - lib_start_count[i] + LONG_LONG_MAX;
- }
- actual_rate = (float) diff / lib_elapsed;
- lib_local_per_cpu_util[i] = (lib_local_maxrate - actual_rate) /
- lib_local_maxrate * 100;
- lib_local_cpu_util += lib_local_per_cpu_util[i];
- if (debug) {
- fprintf(where,
- "calc_cpu_util: actual_rate on cpu %d is %g max_rate %g cpu %6.2f\n, startcount %ll endcount %ll diff %ll",
- i,
- actual_rate,
- lib_local_maxrate,
- lib_local_per_cpu_util[i],
- lib_start_count[i],
- lib_end_count[i],
- diff);
- }
- }
-
- /* we want the average across all n processors */
- lib_local_cpu_util /= (float)lib_num_loc_cpus;
-
- if (debug) {
- fprintf(where,
- "calc_cpu_util: average across CPUs is %g\n",lib_local_cpu_util);
- }
+ sum_idle = lib_end_count[CP_IDLE] - lib_start_count[CP_IDLE];
+ lib_local_cpu_util = (float)sum_busy / (float)(sum_busy + sum_idle);
+ lib_local_cpu_util *= 100.0;
- lib_local_cpu_util *= correction_factor;
-
- if (debug) {
- fprintf(where,
- "calc_cpu_util: returning %g\n",lib_local_cpu_util);
- }
-
return lib_local_cpu_util;
}
void
cpu_start_internal(void)
{
- get_cpu_idle(lib_start_count);
- return;
+ get_cpu_time(lib_start_count);
}
void
cpu_stop_internal(void)
{
- get_cpu_idle(lib_end_count);
+ get_cpu_time(lib_end_count);
}
More information about the netperf-dev
mailing list