From: Peter C. <pc...@us...> - 2014-05-20 00:21:14
|
Update of /cvsroot/ipbench/ipbench2/src/tests/cpu_target In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv24883/src/tests/cpu_target Modified Files: cpu_target.c Log Message: Bumped version to 2.0.1-8, added Sean Peter's patch for SMP cpu usage Index: cpu_target.c =================================================================== RCS file: /cvsroot/ipbench/ipbench2/src/tests/cpu_target/cpu_target.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** cpu_target.c 16 Nov 2007 05:35:00 -0000 1.13 --- cpu_target.c 20 May 2014 00:21:12 -0000 1.14 *************** *** 9,15 **** * */ #define IPBENCH_TEST_TARGET #include "plugin.h" - #include "ipbench.h" --- 9,18 ---- * */ + /* For SMP */ + #define _GNU_SOURCE + #include <sched.h> + #define IPBENCH_TEST_TARGET #include "plugin.h" #include "ipbench.h" *************** *** 26,37 **** static int do_calibrate = 0; static int calibrate_state = 0; ! static long int nr_cpus = 1; ! static unsigned long calibrated_loops_per_sec = 0; static struct timeval alarm_time; ! static unsigned long counts_per_sec; ! static double d_counts_per_sec; ! static char *busyloop_buf; static unsigned long busyloop_size = 1000000; ! static unsigned long *busyloop_progress; static long int period_secs = 1; static int rw_ratio = 5; --- 29,41 ---- static int do_calibrate = 0; static int calibrate_state = 0; ! static long int nr_cpus; ! static unsigned long calibrated_loops_per_sec[N_CPUS]; ! static unsigned int calibration_complete = 0; static struct timeval alarm_time; ! static unsigned long counts_per_sec[N_CPUS]; ! static double d_counts_per_sec[N_CPUS]; ! static char* busyloop_buf; static unsigned long busyloop_size = 1000000; ! static unsigned long* busyloop_progress; static long int period_secs = 1; static int rw_ratio = 5; *************** *** 39,43 **** static unsigned long sum; static unsigned long twiddle = 1000; ! static int do_bonding; static pid_t kids[N_CPUS]; --- 43,47 ---- static unsigned long sum; static unsigned long twiddle = 1000; ! static int do_bonding = 1; static pid_t kids[N_CPUS]; *************** *** 62,65 **** --- 66,93 ---- #define CPS_FILE "counts_per_sec" + static long int + count_cpus(void) + { + FILE *fp; + long int n = -1UL; + char nr_cpus_str[8]; + + + fp = popen("cat /proc/cpuinfo | grep processor | wc -l", "r"); + if (fp == NULL || fgets(nr_cpus_str, sizeof(nr_cpus_str)-1, fp) == NULL) + dbprintf("Failed to count number of processors. Not performing bonding.\n" ); + else { + n = strtol(nr_cpus_str, NULL, 10); + dbprintf("%d cpus found\n", nr_cpus); + } + pclose(fp); + + if (n > N_CPUS) { + dbprintf("Recompile with more than %d N_CPU --- too many for test\n", N_CPUS); + return -1L; + } + return n; + } + static double average_cpu(void) { *************** *** 125,128 **** --- 153,157 ---- unsigned long long blp_snapshot[N_CPUS]; static unsigned long long old_blp[N_CPUS]; + char print_out [256]; int i; *************** *** 148,186 **** if (do_calibrate) { if (calibrate_state++ == 3) { ! calibrated_loops_per_sec = total_blp; } ! dbprintf("calibrating: %llu loops/sec\n", total_blp); } else { ! double this_cpu_load, d_blp; ! d_blp = total_blp; ! this_cpu_load = 1.0 - (d_blp / d_counts_per_sec); ! /* round up */ ! if (this_cpu_load < 0) this_cpu_load = 0; if (warmup_samples * period_secs < warmup_time) ! { ! if (cpu_samples % 5) ! dbprintf("Warmup period:%5.1f%%\n", this_cpu_load * 100.0); ! warmup_samples++; ! } else ! { ! cpu_load[cpu_samples % n_samples] = this_cpu_load; ! cpu_samples++; ! if (cpu_samples % 5) ! dbprintf("[%d] System load:%5.1f%%\n", getpid(), this_cpu_load * 100.0); ! } ! if (do_bonding) { ! printf(" || Free:"); ! for (i = 0; i < nr_cpus; i++) { ! d_blp = blp[i]; ! this_cpu_load = (d_blp / (d_counts_per_sec / nr_cpus)); ! printf(" %5.1f%%(%d)", this_cpu_load * 100.0, i); } } - } } --- 177,228 ---- if (do_calibrate) { if (calibrate_state++ == 3) { ! for(i = 0; i < nr_cpus; i++) { ! calibrated_loops_per_sec[i] = blp[i]; ! } ! calibration_complete = 1; } ! sprintf(print_out, "Calibrating -- total: %llu loops/sec", total_blp); ! if (do_bonding) { ! for(i = 0; i < nr_cpus; i++) { ! sprintf(print_out + strlen(print_out), ! " || CPU%d: %llu loops/sec", i, blp[i]); ! } ! } ! dbprintf("%s\n", print_out); ! } else { ! double this_cpu_load[N_CPUS]; ! double d_blp[N_CPUS]; ! double total_cpu_load = 0; ! for (i = 0; i < nr_cpus; i++) { ! d_blp[i] = blp[i]; ! this_cpu_load[i] = 1.0 - (d_blp[i] / d_counts_per_sec[i]); ! /* round up */ ! if (this_cpu_load[i] < 0) this_cpu_load[i] = 0; ! total_cpu_load += this_cpu_load[i] / nr_cpus; ! } if (warmup_samples * period_secs < warmup_time) ! { ! if (cpu_samples % 5) ! dbprintf("Warmup period:%5.1f%%\n", total_cpu_load * 100.0); ! warmup_samples++; ! } else ! { ! cpu_load[cpu_samples % n_samples] = total_cpu_load; ! cpu_samples++; ! if (cpu_samples % 5) { ! sprintf(print_out, "[%d] System load:%5.1f%%", getpid(), total_cpu_load * 100.0); ! if (do_bonding) { ! for (i = 0; i < nr_cpus; i++) ! sprintf(print_out + strlen(print_out), " || CPU%d: %5.1f%%", i, this_cpu_load[i] * 100.0); ! } ! dbprintf("%s\n", print_out); } } } } *************** *** 195,198 **** --- 237,242 ---- char buf[80]; int cpu; + cpu_set_t cpu_set; + int i; if (!do_calibrate) { *************** *** 202,216 **** exit(1); } ! if (fgets(buf, sizeof(buf), f) == 0) { ! fprintf(stderr, "fgets failed!\n"); ! exit(1); } fclose(f); - counts_per_sec = strtoul(buf, 0, 10); - if (counts_per_sec == 0) { - fprintf(stderr, "something went wrong\n"); - exit(1); - } - d_counts_per_sec = counts_per_sec; } --- 246,263 ---- exit(1); } ! ! for (i = 0; i < nr_cpus; i++) { ! if (fgets(buf, sizeof(buf), f) == 0) { ! fprintf(stderr, "Reading calibration file failed!\n"); ! exit(1); ! } ! counts_per_sec[i] = strtoul(buf, 0, 10); ! if (counts_per_sec[i] == 0) { ! fprintf(stderr, "Calibration implies 0 idle time. Likely a bug.\n"); ! exit(1); ! } ! d_counts_per_sec[i] = counts_per_sec[i]; } fclose(f); } *************** *** 234,241 **** exit(1); } ! /* XXX : no SMP support, yet. ! if (do_bonding) ! bond_to_cpu(cpu); ! */ busyloop(cpu); } --- 281,289 ---- exit(1); } ! if (do_bonding) { ! CPU_ZERO(&cpu_set); ! CPU_SET(cpu, &cpu_set); ! sched_setaffinity(kids[cpu], sizeof(cpu_set), &cpu_set); ! } busyloop(cpu); } *************** *** 253,260 **** static void calibrate(void) { prep_cyclesoak(); for ( ; ; ) { sleep(10); ! if (calibrated_loops_per_sec) { FILE *f = fopen(CPS_FILE, "w"); if (f == 0) { --- 301,311 ---- static void calibrate(void) { + int i; + prep_cyclesoak(); + for ( ; ; ) { sleep(10); ! if (calibration_complete) { FILE *f = fopen(CPS_FILE, "w"); if (f == 0) { *************** *** 263,267 **** exit(1); } ! fprintf(f, "%lu\n", calibrated_loops_per_sec); fclose(f); return; --- 314,320 ---- exit(1); } ! for (i = 0; i < nr_cpus; i++) { ! fprintf(f, "%lu\n", calibrated_loops_per_sec[i]); ! } fclose(f); return; *************** *** 346,350 **** return -1; ! /* XXX : get_cpus() (no SMP support) */ /* --- 399,405 ---- return -1; ! nr_cpus = count_cpus(); ! if (nr_cpus < 0) ! return -1; /* *************** *** 353,357 **** * period, take 3600 samples (i.e. one hour at one per second) */ ! if ( cooldown_time ) n_samples = (2 * ((cooldown_time + 1) / period_secs)); else --- 408,412 ---- * period, take 3600 samples (i.e. one hour at one per second) */ ! if (cooldown_time) n_samples = (2 * ((cooldown_time + 1) / period_secs)); else *************** *** 364,368 **** calibrate(); do_calibrate = 0; ! dbprintf("calibrated OK. %lu loops/sec\n", calibrated_loops_per_sec); exit_handler(); --- 419,423 ---- calibrate(); do_calibrate = 0; ! dbprintf("calibrated OK. %lu loops/sec\n", calibrated_loops_per_sec[0]); exit_handler(); |