PAPI  5.0.1.0
iozone.c
Go to the documentation of this file.
00001 /************************************************************************/
00002 /*  Original Author:                        */
00003 /*      William Norcott (wnorcott@us.oracle.com)        */
00004 /*              4 Dunlap Drive                      */
00005 /*              Nashua, NH 03060                    */
00006 /*                                      */
00007 /************************************************************************/
00008 /*      Enhancements by:                        */
00009 /*      Don Capps (capps@iozone.org)                */
00010 /*      7417 Crenshaw                       */
00011 /*      Plano, TX 75025                     */
00012 /*                                      */
00013 /************************************************************************/
00014 /*  Copyright 1991, 1992, 1994, 1998, 2000, 2001  William D. Norcott    */
00015 /************************************************************************/
00016 /*                                  */
00017 /* Iozone is based on the original work done by William Norrcot. It has */
00018 /* been enhanced so that it provides a more complete filesystem     */
00019 /* characterization.                            */
00020 /* Its purpose is to provide automated filesystem characterization. */
00021 /* Enhancements have been made by:                  */
00022 /*                                  */
00023 /* Don Capps                 capps@iozone.org           */ 
00024 /*                                  */
00025 /* Iozone can perform single stream and multi stream I/O        */
00026 /* also it now performs read, write, re-read, re-write,         */
00027 /* read backwards, read/write random, re-read record,           */
00028 /* pread, re-pread, re-pwrite, preadv, re-preadv, pwritev,      */
00029 /* stride read, and re-pwritev,mmap, POSIX async I/O, NFS               */
00030 /* cluster testing and much more.                   */
00031 /*                                  */
00032 /* The frontend now uses getopt() and the user can control many more    */
00033 /* of the actions.                          */
00034 /*                                  */
00035 /*                                  */
00036 /************************************************************************/
00037 /* THIS SOFTWARE IS PROVIDED BY DON CAPPS AND THE IOZONE CREW "AS IS    */
00038 /* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED    */
00039 /* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A      */
00040 /* PARTICULAR PURPOSE ARE DISCLAIMED.                   */
00041 /*                                  */
00042 /* IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY      */
00043 /* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL   */
00044 /* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE    */
00045 /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS        */
00046 /* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER */
00047 /* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR      */
00048 /* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE.       */
00049 /************************************************************************/
00050 
00051 /************************************************************************/
00052 /* For the beginner...                              */
00053 /*                                  */
00054 /* 1. make linux  (linux, hpux, convex, hpux_no_ansi)           */
00055 /* 2. type ./iozone -Ra                         */
00056 /*                                  */
00057 /*  Hint: Type make    (it will give you a list of valid targets)   */
00058 /*                                  */
00059 /************************************************************************/
00060 
00061 
00062 /* The version number */
00063 #define THISVERSION "        Version $Revision$"
00064 
00065 #if defined(linux)
00066   #define _GNU_SOURCE
00067 #endif
00068 /* Include for Cygnus development environment for Windows */
00069 #if defined (Windows)
00070 #include <windows.h>
00071 #include <errno.h>
00072 #else
00073 #if defined(linux) || defined(solaris) || defined(macosx) || defined(__AIX__) || defined(FreeBSD) || defined(_HPUX_SOURCE)
00074 #include <errno.h>
00075 #else
00076 extern  int errno;   /* imported for errors */
00077 extern  int h_errno; /* imported for errors */
00078 #endif
00079 #endif
00080 
00081 
00082 #include <sys/types.h>
00083 #include <sys/stat.h>
00084 #if defined (__LP64__) || defined(OSF_64) || defined(__alpha__) || defined(__arch64__) || defined(_LP64) || defined(__s390x__) || defined(__AMD64__)
00085 #define MODE "\tCompiled for 64 bit mode."
00086 #define _64BIT_ARCH_
00087 #else
00088 #define MODE "\tCompiled for 32 bit mode."
00089 #endif
00090 
00091 #ifndef NO_THREADS
00092 #include <pthread.h>
00093 #endif
00094 
00095 #if defined(HAVE_ANSIC_C) && defined(linux)
00096 #include <stdlib.h>
00097 #include <sys/wait.h>
00098 #endif
00099 
00100 #ifdef HAVE_PROTO
00101 #include "proto.h"
00102 #else
00103 int atoi();
00104 int close();
00105 int unlink();
00106 int main();
00107 void record_command_line();
00108 #if !defined(linux)
00109 int wait();
00110 #endif
00111 int fsync();
00112 void srand48();
00113 long lrand48();
00114 void create_list();
00115 void Poll();
00116 void print_header();
00117 void Kill();
00118 long long l_min();
00119 long long l_max();
00120 long long mythread_create();
00121 int gen_new_buf();
00122 void touch_dedup();
00123 void init_by_array64(unsigned long long *, unsigned long long );
00124 unsigned long long genrand64_int64(void);
00125 #endif
00126 
00127 #include <fcntl.h>
00128 
00129 char *help[] = {
00130 "    Usage: iozone [-s filesize_Kb] [-r record_size_Kb] [-f [path]filename] [-h]",
00131 "                  [-i test] [-E] [-p] [-a] [-A] [-z] [-Z] [-m] [-M] [-t children]",
00132 "                  [-l min_number_procs] [-u max_number_procs] [-v] [-R] [-x] [-o]",
00133 "                  [-d microseconds] [-F path1 path2...] [-V pattern] [-j stride]",
00134 "                  [-T] [-C] [-B] [-D] [-G] [-I] [-H depth] [-k depth] [-U mount_point]",
00135 "                  [-S cache_size] [-O] [-L cacheline_size] [-K] [-g maxfilesize_Kb]",
00136 "                  [-n minfilesize_Kb] [-N] [-Q] [-P start_cpu] [-e] [-c] [-b Excel.xls]",
00137 "                  [-J milliseconds] [-X write_telemetry_filename] [-w] [-W]",
00138 "                  [-Y read_telemetry_filename] [-y minrecsize_Kb] [-q maxrecsize_Kb]",
00139 "                  [-+u] [-+m cluster_filename] [-+d] [-+x multiplier] [-+p # ]",
00140 "                  [-+r] [-+t] [-+X] [-+Z] [-+w percent dedupable] [-+y percent_interior_dedup]",
00141 "                  [-+C percent_dedup_within]",
00142 " ",
00143 "           -a  Auto mode",
00144 "           -A  Auto2 mode",
00145 "           -b Filename  Create Excel worksheet file",
00146 "           -B  Use mmap() files",
00147 "           -c  Include close in the timing calculations",
00148 "           -C  Show bytes transferred by each child in throughput testing",
00149 "           -d #  Microsecond delay out of barrier",
00150 "           -D  Use msync(MS_ASYNC) on mmap files",
00151 "           -e  Include flush (fsync,fflush) in the timing calculations",
00152 "           -E  Run extension tests",
00153 "           -f filename  to use",
00154 "           -F filenames  for each process/thread in throughput test",
00155 "           -g #  Set maximum file size (in Kbytes) for auto mode (or #m or #g)",
00156 "           -G  Use msync(MS_SYNC) on mmap files",
00157 "           -h  help",
00158 "           -H #  Use POSIX async I/O with # async operations",
00159 "           -i #  Test to run (0=write/rewrite, 1=read/re-read, 2=random-read/write",
00160 "                 3=Read-backwards, 4=Re-write-record, 5=stride-read, 6=fwrite/re-fwrite",
00161 "                 7=fread/Re-fread, 8=random_mix, 9=pwrite/Re-pwrite, 10=pread/Re-pread",
00162 "                 11=pwritev/Re-pwritev, 12=preadv/Re-preadv)",
00163 "           -I  Use VxFS VX_DIRECT, O_DIRECT,or O_DIRECTIO for all file operations",
00164 "           -j #  Set stride of file accesses to (# * record size)",
00165 "           -J #  milliseconds of compute cycle before each I/O operation",
00166 "           -k #  Use POSIX async I/O (no bcopy) with # async operations",
00167 "           -K  Create jitter in the access pattern for readers",
00168 "           -l #  Lower limit on number of processes to run",
00169 "           -L #  Set processor cache line size to value (in bytes)",
00170 "           -m  Use multiple buffers",
00171 "           -M  Report uname -a output",
00172 "           -n #  Set minimum file size (in Kbytes) for auto mode (or #m or #g)",
00173 "           -N  Report results in microseconds per operation",
00174 "           -o  Writes are synch (O_SYNC)",
00175 "           -O  Give results in ops/sec.",
00176 "           -p  Purge on",
00177 "           -P #  Bind processes/threads to processors, starting with this cpu",
00178 "           -q #  Set maximum record size (in Kbytes) for auto mode (or #m or #g)",
00179 "           -Q  Create offset/latency files",
00180 "           -r #  record size in Kb",
00181 "              or -r #k .. size in Kb",
00182 "              or -r #m .. size in Mb",
00183 "              or -r #g .. size in Gb",
00184 "           -R  Generate Excel report",
00185 "           -s #  file size in Kb",
00186 "              or -s #k .. size in Kb",
00187 "              or -s #m .. size in Mb",
00188 "              or -s #g .. size in Gb",
00189 "           -S #  Set processor cache size to value (in Kbytes)",
00190 "           -t #  Number of threads or processes to use in throughput test",
00191 "           -T  Use POSIX pthreads for throughput tests",
00192 "           -u #  Upper limit on number of processes to run",
00193 "           -U  Mount point to remount between tests",
00194 "           -v  version information",
00195 "           -V #  Verify data pattern write/read",
00196 "           -w  Do not unlink temporary file",
00197 "           -W  Lock file when reading or writing",
00198 "           -x  Turn off stone-walling",
00199 "           -X filename  Write telemetry file. Contains lines with (offset reclen compute_time) in ascii",
00200 "           -y #  Set minimum record size (in Kbytes) for auto mode (or #m or #g)",
00201 "           -Y filename  Read  telemetry file. Contains lines with (offset reclen compute_time) in ascii",
00202 "           -z  Used in conjunction with -a to test all possible record sizes",
00203 "           -Z  Enable mixing of mmap I/O and file I/O",
00204 "           -+E Use existing non-Iozone file for read-only testing",
00205 "           -+K Sony special. Manual control of test 8.",
00206 "           -+m  Cluster_filename   Enable Cluster testing",
00207 "           -+d  File I/O diagnostic mode. (To troubleshoot a broken file I/O subsystem)",
00208 "           -+u  Enable CPU utilization output (Experimental)",
00209 "           -+x # Multiplier to use for incrementing file and record sizes",
00210 "           -+p # Percentage of mix to be reads",
00211 "           -+r Enable O_RSYNC|O_SYNC for all testing.",
00212 "           -+t Enable network performance test. Requires -+m ",
00213 "           -+n No retests selected.",
00214 "           -+k Use constant aggregate data set size.",
00215 "           -+q Delay in seconds between tests.",
00216 "           -+l Enable record locking mode.",
00217 "           -+L Enable record locking mode, with shared file.",
00218 "           -+B Sequential mixed workload.",
00219 #if defined(O_DSYNC)
00220 "           -+D Enable O_DSYNC mode.",
00221 #endif
00222 #ifndef NO_MADVISE
00223 "           -+A #  Enable madvise. 0 = normal, 1=random, 2=sequential",
00224 "                                  3=dontneed, 4=willneed",
00225 #endif
00226 "           -+N Do not truncate existing files on sequential writes.",
00227 "           -+S # Dedup-able data is limited to sharing within each numerically",
00228 "                 identified file set",
00229 "           -+V Enable shared file. No locking.",
00230 #if defined(Windows)
00231 "           -+U Windows Unbufferd I/O API (Very Experimental)",
00232 #endif
00233 "           -+X Enable short circuit mode for filesystem testing ONLY",
00234 "               ALL Results are NOT valid in this mode.",
00235 "           -+Z Enable old data set compatibility mode. WARNING.. Published",
00236 "               hacks may invalidate these results and generate bogus, high",
00237 "               values for results.",
00238 "           -+w ## Percent of dedup-able data in buffers.",
00239 "           -+y ## Percent of dedup-able within & across files in buffers.",
00240 "           -+C ## Percent of dedup-able within & not across files in buffers.",
00241 "           -+H Hostname    Hostname of the PIT server.",
00242 "           -+P Service     Service  of the PIT server.",
00243 "           -+z Enable latency histogram logging.",
00244 "" };
00245 
00246 char *head1[] = {
00247   "       'Iozone' Filesystem Benchmark Program",
00248   " ",
00249 THISVERSION,
00250   MODE,
00251   " ",
00252   "       Original Author: William Norcott (wnorcott@us.oracle.com)",
00253   "               4 Dunlap Drive",
00254   "               Nashua, NH 03060",
00255   " ",
00256   "       Enhancements: Don Capps (capps@iozone.org)",
00257   "           7417 Crenshaw",
00258   "           Plano, TX 75025",
00259   " ",
00260   "  Copyright 1991, 1992, 1994, 1998, 1999, 2002   William D. Norcott",
00261   " ",
00262   "  License to freely use and distribute this software is hereby granted ",
00263   "  by the author, subject to the condition that this copyright notice ",
00264   "  remains intact.  The author retains the exclusive right to publish ",
00265   "  derivative works based on this work, including, but not limited to, ",
00266   "  revised versions of this work",
00267   " ",
00268   "  Other contributors:",
00269   " ",
00270   "  Don Capps       (Network Appliance)    capps@iozone.org",
00271   " ",
00272   ""};
00273 
00274 /******************************************************************
00275 
00276     INCLUDE FILES (system-dependent)
00277 
00278 ******************************************************************/
00279 #include <sys/mman.h>
00280 #include <stdio.h>
00281 #include <signal.h>
00282 #include <unistd.h>
00283 
00284 #include <fcntl.h>
00285 #if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__APPLE__) && !defined(__DragonFly__)
00286 #include <malloc.h>
00287 #endif
00288 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__DragonFly__)
00289 #include <stdlib.h>
00290 #include <string.h>
00291 #endif
00292 
00293 #if defined (__FreeBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__APPLE__) || defined(__DragonFly__)
00294 #ifndef O_SYNC
00295 #define O_SYNC O_FSYNC
00296 #endif
00297 #endif
00298 
00299 #if defined (__FreeBSD__)
00300 #ifndef O_RSYNC
00301 #define O_RSYNC O_FSYNC
00302 #endif
00303 #endif
00304 
00305 #if ((defined(solaris) && defined(__LP64__)) || defined(__s390x__))
00306 /* If we are building for 64-bit Solaris, all functions that return pointers
00307  * must be declared before they are used; otherwise the compiler will assume
00308  * that they return ints and the top 32 bits of the pointer will be lost,
00309  * causing segmentation faults.  The following includes take care of this.
00310  * It should be safe to add these for all other OSs too, but we're only
00311  * doing it for Solaris now in case another OS turns out to be a special case.
00312  */
00313 #include <strings.h>
00314 #include <stdlib.h>
00315 #include <sys/socket.h>
00316 #include <netinet/in.h>
00317 #include <arpa/inet.h>
00318 
00319 #endif
00320 #if ( defined(solaris) && defined(studio11) )
00321 #include <strings.h>
00322 #include <stdlib.h>
00323 #endif
00324 
00325 #if defined(OSFV5) || defined(linux)
00326 #include <string.h>
00327 #endif
00328 
00329 #if defined(linux)
00330 #include <sys/socket.h>
00331 #include <netinet/in.h>
00332 #include <arpa/inet.h>
00333 #endif
00334 
00335 #ifndef MAP_FAILED
00336 #define MAP_FAILED -1
00337 #endif
00338 
00339 #ifdef generic
00340 typedef long long off64_t;
00341 #endif
00342 
00343 #if defined(__DragonFly__)
00344 #define __off64_t_defined
00345 typedef off_t off64_t;
00346 #endif
00347 
00348 
00349 #ifndef solaris
00350 #ifndef off64_t
00351 #ifndef _OFF64_T
00352 #ifndef __AIX__
00353 #ifndef __off64_t_defined
00354 #ifndef SCO_Unixware_gcc
00355 #ifndef UWIN
00356 #ifndef __DragonFly__
00357 typedef long long off64_t;
00358 #endif
00359 #endif
00360 #endif
00361 #endif
00362 #endif
00363 #endif
00364 #endif
00365 #endif
00366 
00367 #ifdef __AIX__
00368 #include <fcntl.h>
00369 #endif
00370 
00371 #ifdef VXFS
00372 #include <sys/fs/vx_ioctl.h>
00373 #endif
00374 
00375 #ifdef unix
00376 #if defined (__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__) \
00377    || defined(_SUA_)
00378 #include <sys/time.h>
00379 #endif
00380 #include <sys/times.h>
00381 #include <sys/file.h>
00382 #include <sys/resource.h>
00383 #ifndef NULL
00384 #define NULL 0
00385 #endif
00386 
00387 #ifndef nolimits
00388 #include <limits.h>
00389 #endif
00390 #endif
00391 
00392 #ifdef HAVE_ANSIC_C
00393 #define VOLATILE volatile
00394 #else 
00395 #define VOLATILE 
00396 #endif
00397 
00398 #include <sys/time.h>
00399 
00400 #ifdef SHARED_MEM
00401 #include <sys/shm.h>
00402 #endif
00403 
00404 #if defined(bsd4_2) && !defined(MS_SYNC)
00405 #define MS_SYNC 0
00406 #define MS_ASYNC 0
00407 #endif
00408 
00409 #if defined(bsd4_4) || defined(__DragonFly__)
00410 #define MAP_ANONYMOUS MAP_ANON
00411 #endif
00412 
00413 #if defined(SCO_Unixware_gcc) || defined(solaris) || defined(UWIN) || defined(SCO)
00414 #define MAP_FILE (0)
00415 #endif
00416 
00417 #if defined(IRIX) || defined(IRIX64) || defined(Windows) || defined(bsd4_2) || defined(bsd4_4) || defined(SCO) || defined(Solaris) || defined(SCO_Unixware_gcc)
00418 long long page_size = 4096;
00419 #define GOT_PAGESIZE 1
00420 #elif defined(NBPG)
00421 long long page_size = NBPG;
00422 #define GOT_PAGESIZE 1
00423 #elif defined(old_linux)
00424 #include <asm/page.h>
00425 long long page_size = PAGE_SIZE;
00426 #define GOT_PAGESIZE 1
00427 #elif !defined(GOT_PAGESIZE)
00428 long long page_size = 4096; /* Used when all else fails */
00429 #endif
00430 
00431 #ifdef HAVE_PREAD
00432 #ifdef HAVE_PREADV
00433 #define PVECMAX 16
00434 
00435 #ifdef _HPUX_SOURCE
00436 #define PER_VECTOR_OFFSET
00437 #include <sys/puio.h>
00438 struct piovec piov[PVECMAX];
00439 #else
00440 #include <sys/uio.h>
00441 struct iovec piov[PVECMAX];
00442 #define piov_base iov_base
00443 #define piov_len iov_len
00444 #endif
00445 
00446 #endif
00447 #endif
00448 
00449 #define DEDUPSEED 0x2719362
00450 
00451 
00452 /*
00453  * In multi thread/process throughput mode each child keeps track of
00454  * statistics and communicates them through various flavors of
00455  * shared memory, and via messages.
00456  */
00457 struct child_stats {
00458     long long flag;     /* control space */
00459     long long flag1;    /* pad */
00460     float walltime;         /* child elapsed time */
00461     float cputime;      /* child CPU time */
00462     float throughput;   /* Throughput in either kb/sec or ops/sec */
00463     float actual;       /* Either actual kb read or # of ops performed */
00464 } VOLATILE *child_stat;
00465 
00466 /*
00467  * Used for cpu time statistics.
00468  */
00469 struct runtime {
00470     float   walltime;
00471     float   cputime;
00472     float   cpuutil;
00473 };
00474 
00475 #ifdef __convex_spp
00476 #include <sys/cnx_ail.h>
00477 #endif
00478 
00479 #include <sys/socket.h>
00480 #include <netinet/in.h>
00481 #include <netdb.h>
00482 
00483 
00484 /* 
00485  * Messages the controlling process sends to children.
00486  * Internal representation that is arch specific.
00487  * This is used when using the network distributed mode.
00488  */
00489 struct client_command {
00490     char c_host_name[100];
00491     char c_pit_hostname[40];
00492     char c_pit_service[8];
00493     char c_client_name[100];
00494     char c_working_dir[200];
00495     char c_file_name[200];
00496     char c_path_dir[200];
00497     char c_execute_name[200];
00498     char c_write_traj_filename[200];
00499     char c_read_traj_filename[200];
00500     int c_oflag;
00501     int c_mfflag;
00502     int c_unbuffered;
00503     int c_noretest;
00504     int c_notruncate;
00505     int c_read_sync;
00506     int c_jflag;
00507     int c_async_flag;
00508     int c_k_flag;
00509     int c_h_flag;
00510     int c_mflag;
00511     int c_pflag;
00512     int c_stride_flag;
00513     int c_verify;
00514     int c_sverify;
00515     int c_odsync;
00516     int c_diag_v;
00517     int c_dedup;
00518     int c_dedup_interior;
00519     int c_dedup_compress;
00520     int c_dedup_mseed;
00521     int c_hist_summary;
00522     int c_op_rate;
00523     int c_op_rate_flag;
00524     int c_Q_flag;
00525     int c_L_flag;
00526     int c_OPS_flag;
00527     int c_mmapflag;
00528     int c_mmapasflag;
00529     int c_mmapnsflag;
00530     int c_mmapssflag;
00531     int c_no_copy_flag;
00532     int c_include_close;
00533     int c_include_flush;
00534     int c_disrupt_flag;
00535     int c_compute_flag;
00536     int c_xflag;
00537     int c_MS_flag;
00538     int c_mmap_mix;
00539     int c_Kplus_flag;
00540     int c_stop_flag;
00541     int c_w_traj_flag;
00542     int c_r_traj_flag;
00543     int c_direct_flag;
00544     int c_cpuutilflag;
00545     int c_seq_mix;
00546     int c_client_number;
00547     int c_command;
00548     int c_testnum;
00549     int c_no_unlink;
00550     int c_no_write;
00551     int c_file_lock;
00552     int c_rec_lock;
00553     int c_Kplus_readers;
00554     int c_multiplier;
00555     int c_share_file;
00556     int c_pattern;
00557     int c_version;
00558     int c_base_time;
00559     int c_num_child;
00560     int c_pct_read;
00561     int c_advise_op;
00562     int c_advise_flag;
00563     int c_restf;
00564     int c_mygen;
00565     long long c_stride;
00566     long long c_rest_val;
00567     long long c_delay;
00568     long long c_purge;
00569     long long c_fetchon;
00570     long long c_numrecs64;
00571     long long c_reclen;
00572     long long c_child_flag;
00573     long long c_delay_start;
00574     long long c_depth;
00575     float c_compute_time;
00576 };  
00577 
00578 /*
00579  * All data in this is in string format for portability in a 
00580  * hetrogeneous environment.
00581  *
00582  * Messages that the master will send to the clients
00583  * over the socket. This provides neutral format
00584  * so that heterogeneous clusters will work.
00585  * This is used when using the network distributed mode.
00586  * WARNING !!! This data structure MUST not be bigger
00587  * than 1448 bytes or fragmentation will kick your butt.
00588  */
00589 struct client_neutral_command {
00590     char c_host_name[100];
00591     char c_pit_hostname[40];
00592     char c_pit_service[8];
00593     char c_client_name[100];
00594     char c_working_dir[200];
00595     char c_file_name[200];
00596     char c_path_dir[200];
00597     char c_execute_name[200];
00598     char c_write_traj_filename[200];
00599     char c_read_traj_filename[200];
00600     char c_oflag[2];
00601     char c_mfflag[2];
00602     char c_unbuffered[2];
00603     char c_noretest[2];
00604     char c_notruncate[2];
00605     char c_read_sync[2];
00606     char c_jflag[2];
00607     char c_async_flag[2];
00608     char c_k_flag[2];
00609     char c_h_flag[2];
00610     char c_mflag[2];
00611     char c_pflag[2];
00612     char c_stride_flag[2];
00613     char c_verify[2];
00614     char c_sverify[2];
00615     char c_odsync[2];
00616     char c_diag_v[2];
00617     char c_dedup[4];
00618     char c_dedup_interior[4];
00619     char c_dedup_compress[4];
00620     char c_dedup_mseed[4];
00621     char c_hist_summary[4];
00622     char c_op_rate[4];
00623     char c_op_rate_flag[2];
00624     char c_Q_flag[2];
00625     char c_L_flag[2];
00626     char c_OPS_flag[2];
00627     char c_mmapflag[2];
00628     char c_mmapasflag[2];
00629     char c_mmapnsflag[2];
00630     char c_mmapssflag[2];
00631     char c_no_copy_flag[2];
00632     char c_include_close[2];
00633     char c_include_flush[2];
00634     char c_disrupt_flag[2];
00635     char c_compute_flag[2];
00636     char c_stop_flag[2];
00637     char c_xflag[2];
00638     char c_MS_flag[2];
00639     char c_mmap_mix[2];
00640     char c_Kplus_flag[2];
00641     char c_w_traj_flag[2];      /* small int */
00642     char c_r_traj_flag[2];      /* small int */
00643     char c_direct_flag[2];      /* small int */
00644     char c_cpuutilflag[2];      /* small int */
00645     char c_seq_mix[2];      /* small int */
00646     char c_stride[10];      /* small long long */
00647     char c_rest_val[10];        /* small long long */
00648     char c_purge[10];       /* very small long long */
00649     char c_fetchon[10];         /* very small long long */
00650     char c_multiplier[10];      /* small int */
00651     char c_share_file[10];      /* small int */
00652     char c_file_lock[10];       /* small int */
00653     char c_rec_lock[10];        /* small int */
00654     char c_Kplus_readers[10];   /* small int */
00655     char c_client_number[20];   /* int */
00656     char c_command[20];         /* int */
00657     char c_testnum[20];         /* int */
00658     char c_no_unlink[4];        /* int */
00659     char c_no_write[4];         /* int */
00660     char c_pattern[20];         /* int */
00661     char c_version[20];         /* int */
00662     char c_base_time[20];       /* int */
00663     char c_num_child[20];       /* int */
00664     char c_pct_read[6];         /* small int */
00665     char c_advise_op[4];        /* small int */
00666     char c_advise_flag[4];      /* small int */
00667     char c_restf[4];        /* small int */
00668     char c_mygen[20];       /* long */
00669     char c_depth[20];       /* small long long */
00670     char c_child_flag[40];      /* small long long */
00671     char c_delay[80];       /* long long */
00672     char c_numrecs64[80];       /* long long */
00673     char c_reclen[80];      /* long long */
00674     char c_delay_start[80];     /* long long */
00675     char c_compute_time[80];    /* float */
00676 };  
00677 
00678 /* 
00679  * Messages the clients will send to the master.
00680  * Internal representation on each client and the master.
00681  * This is used when using the network distributed mode.
00682  */
00683 struct master_command {
00684     char m_host_name[100];
00685     char m_client_name[100];
00686     char m_stop_flag; 
00687     int m_client_number;
00688     int m_client_error;
00689     int m_child_port;
00690     int m_child_async_port;
00691     int m_command;
00692     int m_testnum;
00693     int m_version;
00694     int m_mygen;
00695     float m_throughput;
00696     float m_cputime;
00697     float m_walltime;
00698     float m_actual;
00699     long long m_child_flag;
00700 };  
00701 
00702 /*
00703  * Messages that the clients will send to the master
00704  * over the socket. This provides neutral format
00705  * so that heterogeneous clusters will work.
00706  * This is used when using the network distributed mode.
00707  */
00708 struct master_neutral_command {
00709     char m_host_name[100];
00710     char m_client_name[100];
00711     char m_client_number[20];   /* int */
00712     char m_client_error[20];    /* int */
00713     char m_stop_flag[4];        /* char +space */
00714     char m_child_port[20];      /* int */
00715     char m_child_async_port[20];    /* int */
00716     char m_command[20];     /* int */
00717     char m_testnum[20];     /* int */
00718     char m_version[20];     /* int */
00719     char m_mygen[20];       /* int */
00720     char m_throughput[80];      /* float */
00721     char m_cputime[80];     /* float */
00722     char m_walltime[80];        /* float */
00723     char m_actual[80];      /* float */
00724     char m_child_flag[80];      /* long long */
00725 };  
00726 
00727 
00728 /*
00729  * Possible values for the commands sent to the master
00730  */
00731 #define R_CHILD_JOIN        1
00732 #define R_STAT_DATA         2
00733 #define R_FLAG_DATA         3
00734 
00735 /*
00736  * Possible values for the master's commands sent to a client
00737  *
00738  * The R_FLAG_DATA is also used by the master to tell the 
00739  * client to update its flags.
00740  */
00741 #define R_JOIN_ACK        4
00742 #define R_STOP_FLAG       5
00743 #define R_TERMINATE       6
00744 #define R_DEATH           7
00745 
00746 
00747 /* These are the defaults for the processor. They can be 
00748  * over written by the command line options.
00749  */
00750 #define CACHE_LINE_SIZE 32
00751 #define CACHE_SIZE ( 1024 * 1024 )
00752 
00753 
00754 #define MEG (1024 * 1024)
00755 
00756 /*
00757  * For stride testing use a prime number to avoid stripe
00758  * wrap hitting the same spindle.
00759  */
00760 #define STRIDE 17
00761 
00762 
00763 
00764 /************************************************************************/
00765 /*                                  */
00766 /*    DEFINED CONSTANTS                         */
00767 /*                                  */
00768 /* Never add a comment to the end of a #define. Some compilers will     */
00769 /* choke and fail the compile.                      */
00770 /************************************************************************/
00771 
00772 /*
00773  * Size of buffer for capturing the machine's name.
00774  */
00775 #define IBUFSIZE 100
00776 /*
00777  * How many I/Os before a non-uniform access.
00778  */
00779 #define DISRUPT 100
00780 
00781 /*
00782  * Set the crossover size. This is where the small transfers
00783  * are skipped to save time. There is an option to 
00784  * disable the skipping.
00785  */
00786 #define LARGE_REC 65536
00787 
00788 /* Default number of kilobytes in file */
00789 #define KILOBYTES 512           
00790 
00791 /* Default number of bytes in a record */
00792 #define RECLEN 1024         
00793 
00794 /* Default size of file in bytes*/
00795 #define FILESIZE (KILOBYTES*1024)   
00796 
00797 /* Default number of records */
00798 #define NUMRECS FILESIZE/RECLEN     
00799 
00800 #ifdef __bsdi__
00801 /* At 8 Meg switch to large records */
00802 #define CROSSOVER (8*1024)      
00803 /*maximum buffer size*/
00804 #define MAXBUFFERSIZE (8*1024*1024)     
00805 #else
00806 /* At 16 Meg switch to large records */
00807 #define CROSSOVER (16*1024)     
00808 /* Maximum buffer size*/
00809 #define MAXBUFFERSIZE (16*1024*1024)        
00810 #endif
00811 
00812 /* Maximum number of children. Threads/procs/clients */
00813 #define MAXSTREAMS  256     
00814 
00815 /* Minimum buffer size */
00816 #define MINBUFFERSIZE 128
00817 /* If things ran way too fast */
00818 #define TOOFAST 10
00819 /* Set the maximum number of types of tests */
00820 #define MAXTESTS 12
00821 /* Default fill pattern for verification */
00822 #define PATTERN get_pattern();
00823 #define PATTERN1 0xBB
00824 /* Used for Excel internal tables */
00825 #define MAX_X 100           
00826 /* Used for Excel internal tables */
00827 #define MAX_Y 512           
00828 
00829 #define USAGE  "\tUsage: For usage information type iozone -h \n\n"
00830 
00831 
00832 /* Maximum number of characters in filename */
00833 #define MAXNAMESIZE 1000                
00834 
00835 /*
00836  * Define the typical output that the user will see on their
00837  * screen.
00838  */
00839 #ifdef NO_PRINT_LLD
00840 #ifdef HAVE_PREAD
00841 #include <sys/times.h>
00842 #if defined(HAVE_PREAD) && defined(HAVE_PREADV)
00843 #define CONTROL_STRING1 "%16ld%8ld%8ld%8ld%8ld%8ld%8ld%8ld%8ld %8ld %8ld%8ld%8ld%9ld%9ld%8ld%10ld%9ld%10ld%9ld%10ld%10ld%9ld\n"
00844 #define CONTROL_STRING2 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s%9s%9s%8s%9s%8s%9s%7s%10s%10s%10s%9s%9s\n"
00845 #define CONTROL_STRING3 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s%9s%9s%8s%9s\n"
00846 #define CONTROL_STRING4 "%16s%8s%8s%8s%8s%10s\n"
00847 #else
00848 #define CONTROL_STRING1 "%16ld%8ld%8ld%8ld%8ld%8ld%8ld%8ld%8ld %8ld %8ld%8ld%8ld%9ld%9ld%8ld%10ld%9ld%10ld\n"
00849 #define CONTROL_STRING2 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s%9s%9s%8s%9s%8s%9s%7s%10s\n"
00850 #define CONTROL_STRING3 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s\n"
00851 #define CONTROL_STRING4 "%16s%8s%8s%8s%8s%10s\n"
00852 #endif
00853 #else
00854 #define CONTROL_STRING1 "%16ld%8ld%8ld%8ld%8ld%8ld%8ld%8ld%8ld %8ld %8ld%8ld%8ld%9ld%9ld\n"
00855 #define CONTROL_STRING2 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s%9s%9s%8s%9s\n"
00856 #define CONTROL_STRING3 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s%9s%9s%8s%9s\n"
00857 #define CONTROL_STRING4 "%16s%8s%8s%8s%8s%10s\n"
00858 #endif
00859 #endif
00860 
00861 #ifndef NO_PRINT_LLD
00862 #ifdef HAVE_PREAD
00863 #include <sys/times.h>
00864 #if defined(HAVE_PREAD) && defined(HAVE_PREADV)
00865 #define CONTROL_STRING1 "%16lld%8ld%8ld%8ld%8ld%8ld%8ld%8ld%8ld %8ld %8ld%8ld%8ld%9ld%9ld%8ld%10ld%9ld%10ld%9ld%10ld%10ld%9ld\n"
00866 #define CONTROL_STRING2 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s%9s%9s%8s%9s%8s%9s%7s%10s%10s%10s%9s%9s\n"
00867 #define CONTROL_STRING3 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s%9s%9s%8s%9s\n"
00868 #define CONTROL_STRING4 "%16s%8s%8s%8s%8s%10s\n"
00869 #else
00870 #define CONTROL_STRING1 "%16lld%8ld%8ld%8ld%8ld%8ld%8ld%8ld%8ld %8ld %8ld%8ld%8ld%9ld%9ld%8ld%10ld%9ld%10ld\n"
00871 #define CONTROL_STRING2 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s%9s%9s%8s%9s%8s%9s%7s%10s\n"
00872 #define CONTROL_STRING3 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s%9s%9s%8s%9s\n"
00873 #define CONTROL_STRING4 "%16s%8s%8s%8s%8s%10s\n"
00874 #endif
00875 #else
00876 #define CONTROL_STRING1 "%16lld%8ld%8ld%8ld%8ld%8ld%8ld%8ld %8ld %8ld%8ld%8ld%8ld%9ld%9ld\n"
00877 #define CONTROL_STRING2 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s%9s%9s%8s%9s\n"
00878 #define CONTROL_STRING3 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s%9s%9s%8s%9s\n"
00879 #define CONTROL_STRING4 "%16s%8s%8s%8s%8s%10s\n"
00880 #endif
00881 #endif
00882 
00883 /* 
00884     For 'auto mode', these defines determine the number of iterations
00885     to perform for both the file size and the record length.
00886 */ 
00887 
00888 /* Start with 64 kbyte minimum file size by default */
00889 #define KILOBYTES_START       64
00890 /* Default maximum file size. This is 512 Mbytes */
00891 #define KILOBYTES_END (1024*512)
00892 /* Default starting record size */
00893 #define RECLEN_START  4096
00894 /* Default maximum record size */
00895 #define RECLEN_END    (MAXBUFFERSIZE)
00896 /* Multiplier for each itteration on file and record size */
00897 #define MULTIPLIER    2
00898 
00899 /*
00900  * Assign numeric values to each of the tests.
00901  */
00902 #define WRITER_TEST     0
00903 #define READER_TEST     1
00904 #define RANDOM_RW_TEST      2
00905 #define REVERSE_TEST        3
00906 #define REWRITE_REC_TEST    4
00907 #define STRIDE_READ_TEST    5
00908 #define FWRITER_TEST        6
00909 #define FREADER_TEST        7
00910 #define RANDOM_MIX_TEST     8
00911 #ifdef HAVE_PREAD
00912 #define PWRITER_TEST        9
00913 #define PREADER_TEST        10  
00914 #endif /* HAVE_PREAD */
00915 #ifdef HAVE_PREADV
00916 #define PWRITEV_TEST        11
00917 #define PREADV_TEST     12
00918 #endif /* HAVE_PREADV */
00919 
00920 #define WRITER_MASK     (1 << WRITER_TEST)
00921 #define READER_MASK     (1 << READER_TEST)
00922 #define RANDOM_RW_MASK      (1 << RANDOM_RW_TEST)
00923 #define RANDOM_MIX_MASK     (1 << RANDOM_MIX_TEST)
00924 #define REVERSE_MASK        (1 << REVERSE_TEST)
00925 #define REWRITE_REC_MASK    (1 << REWRITE_REC_TEST)
00926 #define STRIDE_READ_MASK    (1 << STRIDE_READ_TEST)
00927 #define FWRITER_MASK        (1 << FWRITER_TEST)
00928 #define FREADER_MASK        (1 << FREADER_TEST)
00929 #ifdef HAVE_PREAD
00930 #define PWRITER_MASK        (1 << PWRITER_TEST)
00931 #define PREADER_MASK        (1 << PREADER_TEST)
00932 #endif /* HAVE_PREAD */
00933 #ifdef HAVE_PREADV
00934 #define PWRITEV_MASK        (1 << PWRITEV_TEST)
00935 #define PREADV_MASK     (1 << PREADV_TEST)
00936 #endif /* HAVE_PREADV */
00937 
00938 /*
00939  * child_stat->flag values and transitions
00940  */
00941 /* Parent initializes children to HOLD */
00942 #define CHILD_STATE_HOLD    0   
00943 /* Child tells master when it's READY */
00944 #define CHILD_STATE_READY   1   
00945 /* Parent tells child to BEGIN */
00946 #define CHILD_STATE_BEGIN   2   
00947 /* Child tells parent that it's DONE */
00948 #define CHILD_STATE_DONE    3   
00949 
00950 #define MERSENNE
00951 
00952 /******************************************************************/
00953 /*                                */
00954 /*    FUNCTION DECLARATIONS                   */
00955 /*                                */
00956 /******************************************************************/
00957 char *initfile();
00958 /*int pit_gettimeofday( struct timeval *, struct timezone *, char *, char *);*/
00959 int pit_gettimeofday( );
00960 static int openSckt( const char *, const char *, unsigned int );
00961 static void pit( int, struct timeval *);
00962 void mmap_end();
00963 void alloc_pbuf();
00964 void auto_test();       /* perform automatic test series  */
00965 void show_help();       /* show development help          */
00966 static double time_so_far();    /* time since start of program    */
00967 #ifdef unix
00968 static double utime_so_far();   /* user time              */
00969 static double stime_so_far();   /* system time            */
00970 static double clk_tck();    /* Get clocks/tick        */
00971 static double cputime_so_far();
00972 #else
00973 #define cputime_so_far()    time_so_far()
00974 #endif
00975 static double time_so_far1();   /* time since start of program    */
00976 void get_resolution();
00977 void get_rusage_resolution();
00978 void signal_handler();      /* clean up if user interrupts us */
00979 void begin();           /* The main worker in the app     */
00980 void fetchit();         /* Prime on chip cache        */
00981 void purgeit();         /* Purge on chip cache        */
00982 void throughput_test();     /* Multi process throughput       */
00983 void multi_throughput_test();   /* Multi process throughput       */
00984 void prepage();         /* Pre-fault user buffer      */
00985 void get_date();
00986 int get_pattern();      /* Set pattern based on version   */
00987 #ifdef HAVE_ANSIC_C
00988 float do_compute(float);    /* compute cycle simulation       */
00989 #else
00990 float do_compute();     /* compute cycle simulation       */
00991 #endif
00992 void write_perf_test();     /* write/rewrite test         */
00993 void fwrite_perf_test();    /* fwrite/refwrite test       */
00994 void fread_perf_test();     /* fread/refread test         */
00995 void read_perf_test();      /* read/reread test       */
00996 void mix_perf_test();       /* read/reread test       */
00997 void random_perf_test();    /* random read/write test     */
00998 void reverse_perf_test();   /* reverse read test          */
00999 void rewriterec_perf_test();    /* rewrite record test        */
01000 void read_stride_perf_test();   /* read with stride test      */
01001 #ifdef HAVE_PREAD
01002 void pread_perf_test();     /* pread/re-pread test        */
01003 void pwrite_perf_test();    /* pwrite/re-pwrite test      */
01004 #endif /* HAVE_PREAD */
01005 #ifdef HAVE_PREADV
01006 void preadv_perf_test();    /* preadv/re-preadv test      */
01007 void pwritev_perf_test();   /* pwritev/re-pwritev test    */
01008 #endif /* HAVE_PREADV */
01009 void store_dvalue();        /* Store doubles array        */
01010 void dump_excel();
01011 void dump_throughput();
01012 int sp_start_child_send();
01013 int sp_start_master_listen();
01014 #ifdef HAVE_ANSIC_C
01015 #if defined (HAVE_PREAD) && defined(_LARGEFILE64_SOURCE)
01016 ssize_t pwrite64(); 
01017 ssize_t pread64(); 
01018 #endif
01019 #if !defined(linux)
01020 char *getenv();
01021 char *inet_ntoa();
01022 int system();
01023 #endif
01024 void my_nap();
01025 void my_unap();
01026 int thread_exit();
01027 #ifdef ASYNC_IO
01028 size_t async_write();
01029 void async_release();
01030 int async_read();
01031 int async_read_no_copy();
01032 size_t async_write_no_copy();
01033 void end_async();
01034 void async_init();
01035 #else
01036 size_t async_write();
01037 size_t async_write_no_copy();
01038 void async_release();
01039 #endif
01040 void do_float();
01041 int create_xls();
01042 void close_xls();
01043 void do_label();
01044 int mylockf(int, int, int);
01045 int mylockr(int,int, int, off64_t, off64_t);
01046 int rand(void);
01047 void srand(unsigned int);
01048 int get_client_info(void);
01049 void exit(int);
01050 void find_remote_shell(char *);
01051 void find_external_mon(char *,char *);
01052 void start_monitor(char *);
01053 void stop_monitor(char *);
01054 void takeoff_cache();
01055 void del_cache();
01056 void fill_area(long long *, long long *, long long);
01057 void fill_buffer(char *,long long ,long long ,char, long long );
01058 void store_value(off64_t);
01059 void store_times(double, double);
01060 static double cpu_util(double, double);
01061 void dump_cputimes(void);
01062 void purge_buffer_cache(void);
01063 char *alloc_mem(long long,int);
01064 void *(thread_rwrite_test)(void *);
01065 void *(thread_write_test)(void *);
01066 void *(thread_fwrite_test)(void *);
01067 void *(thread_fread_test)(void *);
01068 void *(thread_read_test)(void*);
01069 #ifdef HAVE_PREAD
01070 void *(thread_pread_test)(void*);
01071 void *(thread_pwrite_test)(void*);
01072 #endif
01073 void *(thread_cleanup_test)(void*);
01074 void *(thread_cleanup_quick)(void*);
01075 void *(thread_ranread_test)(void *);
01076 void *(thread_mix_test)(void *);
01077 void *(thread_ranwrite_test)(void *);
01078 void *(thread_rread_test)(void *);
01079 void *(thread_reverse_read_test)(void *);
01080 void *(thread_stride_read_test)(void *);
01081 void *(thread_set_base)(void *);
01082 void *(thread_join)(long long, void *);
01083 void disrupt(int);
01084 #if defined(Windows)
01085 void disruptw(HANDLE);
01086 #endif
01087 long long get_traj(FILE *, long long *, float *, long);
01088 void create_temp(off64_t, long long );
01089 FILE *open_w_traj(void);
01090 FILE *open_r_traj(void);
01091 void traj_vers(void);
01092 void r_traj_size(void);
01093 long long w_traj_size(void);
01094 void init_file_sizes();
01095 off64_t get_next_file_size(off64_t);
01096 void add_file_size(off64_t);
01097 void init_file_sizes( off64_t,  off64_t);
01098 off64_t get_next_record_size(off64_t);
01099 void add_record_size(off64_t);
01100 void init_record_sizes( off64_t,  off64_t);
01101 void del_record_sizes( void );
01102 void hist_insert(double );
01103 void dump_hist(char *,int );
01104 void do_speed_check(int);
01105 #else
01106 void do_speed_check();
01107 #if !defined(linux)
01108 char *getenv();
01109 char *inet_ntoa();
01110 int system();
01111 #endif
01112 void my_nap();
01113 void my_unap();
01114 int thread_exit();
01115 void close_xls();
01116 void do_label();
01117 int create_xls();
01118 void do_float();
01119 #ifdef ASYNC_IO
01120 void async_release();
01121 size_t async_write();
01122 size_t async_write_no_copy();
01123 int async_read();
01124 int async_read_no_copy();
01125 #endif
01126 int mylockf();
01127 int mylockr();
01128 int rand();
01129 void srand();
01130 int get_client_info();
01131 void exit();
01132 void find_remote_shell();
01133 void traj_vers();
01134 void r_traj_size();
01135 long long w_traj_size();
01136 FILE *open_w_traj();
01137 FILE *open_r_traj();
01138 void create_temp();
01139 void fill_buffer();
01140 char *alloc_mem();
01141 void *(thread_rwrite_test)();
01142 void *(thread_write_test)();
01143 void *(thread_fwrite_test)();
01144 void *(thread_fread_test)();
01145 void *(thread_read_test)();
01146 void *(thread_cleanup_test)();
01147 void *(thread_ranread_test)();
01148 void *(thread_mix_test)();
01149 void *(thread_ranwrite_test)();
01150 void *(thread_rread_test)();
01151 void *(thread_reverse_read_test)();
01152 void *(thread_stride_read_test)();
01153 void *(thread_set_base)();
01154 void *(thread_join)();
01155 void disrupt();
01156 long long get_traj();
01157 void init_file_sizes();
01158 off64_t get_next_file_size();
01159 void add_file_size();
01160 void init_record_sizes();
01161 off64_t get_next_record_size();
01162 void add_record_size();
01163 void dump_cputimes();
01164 static double cpu_util();
01165 void del_record_sizes();
01166 void hist_insert();
01167 void dump_hist();
01168 #endif
01169 
01170 #ifdef _LARGEFILE64_SOURCE
01171 #define I_LSEEK(x,y,z)  lseek64(x,(off64_t)(y),z)
01172 #define I_OPEN(x,y,z)   open64(x,(int)(y),(int)(z))
01173 #define I_CREAT(x,y)    creat64(x,(int)(y))
01174 #define I_FOPEN(x,y)    fopen64(x,y)
01175 #define I_STAT(x,y)     stat64(x,y)
01176 #ifdef HAVE_PREAD
01177 #define I_PREAD(a,b,c,d)    pread64(a,b,(size_t)(c),(off64_t)(d))
01178 #define I_PWRITE(a,b,c,d)   pwrite64(a,b,(size_t)(c),(off64_t)(d))
01179 #endif
01180 #define I_MMAP(a,b,c,d,e,f)     mmap64((void *)(a),(size_t)(b),(int)(c),(int)(d),(int)(e),(off64_t)(f))
01181 #else
01182 #define I_LSEEK(x,y,z)  lseek(x,(off_t)(y),z)
01183 #define I_OPEN(x,y,z)   open(x,(int)(y),(int)(z))
01184 #define I_CREAT(x,y)    creat(x,(int)(y))
01185 #define I_FOPEN(x,y)    fopen(x,y)
01186 #define I_STAT(x,y)     stat(x,y)
01187 #ifdef HAVE_PREAD
01188 #define I_PREAD(a,b,c,d)    pread(a,b,(size_t)(c),(off_t)(d))
01189 #define I_PWRITE(a,b,c,d)   pwrite(a,b,(size_t)(c),(off_t)(d))
01190 #endif
01191 #define I_MMAP(a,b,c,d,e,f)     mmap((void *)(a),(size_t)(b),(int)(c),(int)(d),(int)(e),(off_t)(f))
01192 #endif
01193 
01194 
01195 /************************************************************************/
01196 /* The list of tests to be called.                  */
01197 /************************************************************************/
01198 void (*func[])() = { 
01199             write_perf_test, 
01200             read_perf_test,
01201             random_perf_test,
01202             reverse_perf_test,
01203             rewriterec_perf_test,
01204             read_stride_perf_test,
01205             fwrite_perf_test,
01206             fread_perf_test,
01207             mix_perf_test 
01208 #ifdef HAVE_PREAD
01209             ,
01210             pwrite_perf_test,
01211             pread_perf_test
01212 #ifdef HAVE_PREADV
01213             ,
01214             pwritev_perf_test,
01215             preadv_perf_test
01216 #endif /* HAVE_PREADV */
01217 #endif /* HAVE_PREAD */
01218     };
01219 
01220 /*
01221 char *test_output[] = {"                ",
01222               "                  ",
01223               "                ",
01224               "        ",
01225               "        ",
01226               "        ",
01227               "                  ",
01228               "                ",
01229               "                 ",
01230               "                 ",
01231               "                   ",
01232               "                   \n" };
01233 */
01234 char *test_output[] = {"                ",
01235               "                  ",
01236               "                ",
01237               "        ",
01238               "        ",
01239               "        ",
01240               "                  ",
01241               "                ",
01242               "",
01243               "                 ",
01244               "                   ",
01245               "                   ",
01246               "                   ",
01247               "                   ",
01248               "                   ",
01249               "                   \n" };
01250 long long test_soutput[] = {2,2,2,1,1,1,2,2,2,2,2,2,2,2};
01251 
01252 
01253 /******************************************************************/
01254 /*                                */
01255 /*    GLOBAL VARIABLES                            */
01256 /*                                */
01257 /*******************************************************************/
01258 
01259 /*
01260  * Set the size of the shared memory segment for the children
01261  * to put their results.
01262  */
01263 #define SHMSIZE  ((( sizeof(struct child_stats) * MAXSTREAMS) )+4096 )
01264 /*
01265  * Pointer to the shared memory segment.
01266  */
01267 VOLATILE struct child_stats *shmaddr;
01268 double totaltime,total_time, temp_time ,total_kilos;
01269 off64_t report_array[MAX_X][MAX_Y];
01270 double report_darray[MAX_X][MAXSTREAMS];
01271 double time_res,cputime_res;
01272 long long throughput_array[MAX_X];  /* Filesize & record size are constants */
01273 short current_x, current_y;
01274 long long orig_size;
01275 long long max_x, max_y;
01276 unsigned long long goodkilos;
01277 off64_t kilobytes64 = (off64_t)KILOBYTES;
01278 long long goodrecl;
01279 off64_t offset = 0;               /*offset for random I/O */
01280 off64_t offset64 = 0;               /*offset for random I/O */
01281 off64_t filebytes64;
01282 off64_t r_range[100];
01283 off64_t s_range[100];
01284 int t_range[100];
01285 int t_count = 0;
01286 int r_count,s_count;
01287 char *barray[MAXSTREAMS];
01288 char *haveshm;
01289 extern int optind;
01290 long long onetime, auto_mode, sfd, multi_buffer;
01291 int fd;
01292 int sp_msfd,sp_mrfd,sp_csfd,sp_crfd;
01293 int begin_proc,num_processors,ioz_processor_bind;
01294 long long res_prob,rec_prob;
01295 char silent,read_sync;
01296 char master_iozone, client_iozone,distributed;
01297 int bif_fd,s_count;
01298 int bif_row,bif_column;
01299 int dedup_mseed = 1;
01300 int hist_summary;
01301 int op_rate;
01302 int op_rate_flag;
01303 char aflag, Eflag, hflag, Rflag, rflag, sflag;
01304 char diag_v,sent_stop,dedup,dedup_interior,dedup_compress;
01305 char *dedup_ibuf;
01306 char *dedup_temp;
01307 char bif_flag;
01308 int rlocking;
01309 int share_file;
01310 int ecount;
01311 char gflag,nflag;
01312 char yflag,qflag;
01313 #ifdef Windows
01314 char *build_name = "Windows";
01315 #else
01316 char *build_name = NAME;
01317 #endif
01318 char imon_start[256],imon_stop[256]; 
01319 char imon_sync;
01320 char trflag; 
01321 char cpuutilflag;
01322 char seq_mix;
01323 long base_time;
01324 long long mint, maxt; 
01325 long long w_traj_ops, r_traj_ops, w_traj_fsize,r_traj_fsize;
01326 long long r_traj_ops_completed,r_traj_bytes_completed;
01327 long long w_traj_ops_completed,w_traj_bytes_completed;
01328 int w_traj_items, r_traj_items;
01329 char fflag, Uflag,uflag,lflag,include_tflag; 
01330 struct runtime runtimes [MAX_X] [MAX_Y];    /* in parallel with report_array[][] */
01331 long long include_test[50];
01332 long long include_mask;
01333 char RWONLYflag, NOCROSSflag;       /*auto mode 2 - kcollins 8-21-96*/
01334 char mfflag;
01335 long long status, x, y, childids[MAXSTREAMS+1], myid, num_child;
01336 int pct_read,speed_code;
01337 #ifndef NO_THREADS
01338 pthread_t p_childids[MAXSTREAMS+1];
01339 #endif
01340 off64_t next64;
01341 char wol_opened, rol_opened;
01342 FILE *wqfd,*rwqfd,*rqfd,*rrqfd;
01343 
01344 extern char *optarg;
01345 #ifndef __AIX__
01346 long long ret;
01347 #else
01348 short ret;
01349 #endif
01350 struct size_entry {
01351     struct size_entry *next;
01352     off64_t size;
01353 };
01354 struct size_entry *size_list=0;
01355 struct size_entry *rec_size_list=0;
01356 off64_t maximum_file_size;
01357 off64_t minimum_file_size;
01358 
01359 char bif_filename [MAXNAMESIZE];           /* name of biff file      */
01360 char filename [MAXNAMESIZE];               /* name of temporary file */
01361 char mountname [MAXNAMESIZE];              /* name of device         */
01362 char dummyfile [MAXSTREAMS][MAXNAMESIZE];  /* name of dummy file     */
01363 char dummyfile1 [MAXNAMESIZE];             /* name of dummy file     */
01364 char *filearray[MAXSTREAMS];           /* array of file names    */
01365 char tfile[] = "iozone";
01366 char *buffer,*buffer1, *mbuffer,*mainbuffer;
01367 FILE *pi,*r_traj_fd,*w_traj_fd;
01368 VOLATILE char *pbuffer;
01369 char *default_filename="iozone.tmp"; /*default name of temporary file*/
01370 VOLATILE char stoptime;
01371 char Cflag;
01372 char use_thread = 0;
01373 long long debug1=0;     
01374 long long debug=0;
01375 unsigned long cache_size=CACHE_SIZE;
01376 unsigned long cache_line_size=CACHE_LINE_SIZE;
01377 long long *pstatus;
01378 off64_t min_file_size = KILOBYTES_START;
01379 off64_t max_file_size = KILOBYTES_END;
01380 long long min_rec_size = RECLEN_START;
01381 long long max_rec_size = RECLEN_END;
01382 long long orig_min_rec_size = RECLEN_START;
01383 long long orig_max_rec_size = RECLEN_END;
01384 long long xover = CROSSOVER;
01385 char *throughput_tests[] = {"Initial write","Rewrite","Read","Re-read",
01386     "Reverse Read","Stride read","Random read","Mixed workload","Random write","Pwrite","Pread","Fwrite","Fread"};
01387 char command_line[1024] = "\0";
01388 #ifdef unix
01389 double sc_clk_tck;
01390 #endif
01391 
01392 int argcsave;
01393 char **argvsave;
01394 char splash[80][80];
01395 int splash_line;
01396 char client_filename[256];
01397 char remote_shell[256];
01398 int client_error;
01399 
01400 char pit_hostname[40];
01401 char pit_service[8];
01402 int junk;
01403 
01404 /* 
01405  * Host ports used to listen, and handle errors.
01406  */
01407 #define HOST_LIST_PORT 20000
01408 #define HOST_ESEND_PORT (HOST_LIST_PORT+MAXSTREAMS)
01409 #define HOST_ASEND_PORT (HOST_ESEND_PORT+MAXSTREAMS)
01410 int controlling_host_port = HOST_LIST_PORT;
01411 
01412 /* 
01413  * Childs ports used to listen, and handle errors.
01414  */
01415 #define CHILD_ESEND_PORT (HOST_ASEND_PORT+MAXSTREAMS)
01416 #define CHILD_LIST_PORT (CHILD_ESEND_PORT+MAXSTREAMS)
01417 
01418 /* Childs async message port. Used for stop flag and terminate */
01419 #define CHILD_ALIST_PORT (CHILD_LIST_PORT+MAXSTREAMS)
01420 
01421 /* Ports for the network speed code */
01422 #define SP_CHILD_LISTEN_PORT 31000
01423 #define SP_CHILD_ESEND_PORT (SP_CHILD_LISTEN_PORT+10)
01424 #define SP_MASTER_LISTEN_PORT (SP_CHILD_ESEND_PORT+10)
01425 #define SP_MASTER_ESEND_PORT (SP_MASTER_LISTEN_PORT+10)
01426 #define SP_MASTER_RESULTS_PORT (SP_MASTER_ESEND_PORT+10)
01427 
01428 
01429 #define THREAD_WRITE_TEST 1
01430 #define THREAD_REWRITE_TEST 2
01431 #define THREAD_READ_TEST 3
01432 #define THREAD_REREAD_TEST 4
01433 #define THREAD_STRIDE_TEST 5
01434 #define THREAD_RANDOM_READ_TEST 6
01435 #define THREAD_RANDOM_WRITE_TEST 7
01436 #define THREAD_REVERSE_READ_TEST 8
01437 #define THREAD_RANDOM_MIX_TEST 9
01438 #define THREAD_PWRITE_TEST 10
01439 #define THREAD_PREAD_TEST 11
01440 #define THREAD_FWRITE_TEST 12
01441 #define THREAD_FREAD_TEST 13
01442 #define THREAD_CLEANUP_TEST 14
01443 
01444 /*
01445  * Child states that the master is tracking.
01446  * The master uses these to determine how to shutdown
01447  * the clients when some fool hits control-C.
01448  */
01449 #define C_STATE_ZERO 1
01450 #define C_STATE_WAIT_WHO 2
01451 #define C_STATE_WAIT_BARRIER 3
01452 
01453 
01454 int c_port,a_port; /* port number */
01455 int child_port; /* Virtualized due to fork */
01456 int child_async_port; /* Virtualized due to fork */
01457 int client_listen_pid; /* Virtualized due to fork */
01458 int master_join_count; /* How many children have joined */
01459 int l_sock,l_async_sock; /* Sockets for listening */
01460 char master_rcv_buf[4096]; /* Master's receive buffer */
01461 int master_listen_pid; /* Pid of the master's async listener proc */
01462 char master_send_buf[4096]; /* Master's send buffer */
01463 char child_rcv_buf[4096]; /* Child's receive buffer */
01464 char child_async_rcv_buf[4096]; /* Child's async recieve buffer */
01465 char child_send_buf[4096]; /* Child's send buffer */
01466 int child_send_socket; /* Child's send socket */
01467 int child_listen_socket; /* Child's listener socket */
01468 int child_listen_socket_async; /* Child's async listener socket */
01469 int master_send_socket; /* Needs to be an array. One for each child*/
01470 int master_send_sockets[MAXSTREAMS]; /* Needs to be an array. One for each child*/
01471 int master_send_async_sockets[MAXSTREAMS]; /* Needs to be an array. One for each child*/
01472 int master_listen_port; /* Master's listener port number */
01473 int master_listen_socket; /* Master's listener socket */
01474 int clients_found; /* Number of clients found in the client file */
01475 FILE *newstdin, *newstdout, *newstderr; /* used for debug in cluster mode.*/
01476 char toutput[20][20]; /* Used to help format the output */
01477 int toutputindex; /* Index to the current output line */
01478 int cdebug = 0; /* Use to turn on child/client debugging in cluster mode. */
01479 int mdebug = 0; /* Use to turn on master debug in cluster mode */
01480 int aggflag; /* Used to indicate constant aggregate data set size */
01481 struct sockaddr_in child_sync_sock, child_async_sock;
01482 
01483 /*
01484  * Change this whenever you change the message format of master or client.
01485  */
01486 int proto_version = 25;
01487 
01488 /******************************************************************************/
01489 /* Tele-port zone. These variables are updated on the clients when one is     */
01490 /* using cluster mode. (-+m)                                                  */
01491 /* Do not touch these unless you have become one with the universe !!         */
01492 /******************************************************************************/
01493 char controlling_host_name[100];
01494 struct child_ident {
01495     char child_name[100];
01496     char workdir[200];
01497     char execute_path[200];
01498     char file_name[200];
01499     int state;
01500     int child_number;
01501     int child_port;
01502     int child_async_port;
01503     int master_socket_num;
01504     int master_async_socket_num;
01505 }child_idents[MAXSTREAMS];
01506 int Kplus_readers;
01507 char write_traj_filename [MAXNAMESIZE];     /* name of write telemetry file */
01508 char read_traj_filename [MAXNAMESIZE];    /* name of read telemetry file  */
01509 char oflag,jflag,k_flag,h_flag,mflag,pflag,unbuffered,Kplus_flag;
01510 char noretest;
01511 char notruncate;   /* turn off truncation of files */
01512 char async_flag,stride_flag,mmapflag,mmapasflag,mmapssflag,mmapnsflag,mmap_mix;
01513 char verify = 1;
01514 int restf;
01515 char sverify = 1;
01516 char odsync = 0;
01517 char Q_flag,OPS_flag;
01518 char L_flag=0;
01519 char no_copy_flag,include_close,include_flush;
01520 char disrupt_flag,compute_flag,xflag,Z_flag, X_flag;
01521 int no_unlink = 0;
01522 int no_write = 0;
01523 int r_traj_flag,w_traj_flag;
01524 int mygen;
01525 char MS_flag;
01526 int advise_op,advise_flag;
01527 int direct_flag;
01528 int current_client_number;
01529 long long chid;
01530 int file_lock;
01531 unsigned int pattern;
01532 long long stride = STRIDE;
01533 long long delay,purge,fetchon;
01534 off64_t  numrecs64 = (off64_t)NUMRECS;
01535 long long reclen = RECLEN;
01536 long long delay_start,depth;
01537 VOLATILE char *stop_flag;       /* Used to stop all children */
01538 float compute_time;
01539 int multiplier = MULTIPLIER;
01540 long long rest_val;
01541 #if defined(Windows)
01542     HANDLE hand;
01543 #endif
01544 
01545 /******************************************************************************/
01546 /* End of Tele-port zone.                                                     */
01547 /******************************************************************************/
01548 
01549 
01550 /* 
01551  * Prototypes
01552  * Sort of... Full prototypes break non-ansi C compilers. No protos is 
01553  * a bit sloppy, so the compromise is this.
01554  */
01555 void child_send();
01556 int start_child_listen();
01557 int start_child_listen_async();
01558 void start_child_listen_loop();
01559 void child_listen();
01560 void child_listen_async();
01561 void stop_child_send();
01562 void stop_child_listen();
01563 void cleanup_comm();
01564 void master_send();
01565 int start_master_send();
01566 int start_master_listen();
01567 int check_filename();
01568 void master_listen();
01569 void stop_master_send();
01570 void stop_master_listen();
01571 long long start_child_proc();
01572 int parse_client_line();
01573 void wait_dist_join();
01574 void tell_children_begin();
01575 void start_master_listen_loop();
01576 void wait_for_master_go();
01577 void tell_master_ready();
01578 void stop_master_listen_loop();
01579 void tell_master_stats();
01580 void become_client();
01581 int pick_client();
01582 long long start_child_proc();
01583 int start_master_send();
01584 void child_listen();
01585 int start_child_listen();
01586 void stop_master_send();
01587 void stop_master_listen();
01588 void stop_child_send();
01589 void stop_child_listen();
01590 void master_send();
01591 void child_send();
01592 void master_listen();
01593 int start_master_listen();
01594 void child_remove_files();
01595 void terminate_child_async();
01596 void distribute_stop();
01597 void send_stop();
01598 void cleanup_children();
01599 
01600 
01601 /****************************************************************/
01602 /*                              */
01603 /*   MAIN ()                            */
01604 /*                              */
01605 /****************************************************************/
01606 
01607 int
01608 main(argc,argv) 
01609 int argc;
01610 char **argv;
01611 {
01612 
01613     long long fileindx,i,tval;
01614     long long ind;
01615     int ret;
01616     FILE *pi;
01617     char reply[IBUFSIZE];
01618     unsigned char inp_pat;
01619     time_t time_run;
01620     char *port,*m,*subarg;
01621     int num_child1;
01622     int cret;
01623     int anwser,bind_cpu;
01624     char *evalue;
01625 
01626 
01627     anwser=bind_cpu=0;
01628     /* Used to make fread/fwrite do something better than their defaults */
01629     setvbuf( stdout, NULL, _IONBF, (size_t) NULL );
01630     setvbuf( stderr, NULL, _IONBF, (size_t) NULL );
01631     
01632     /* Save the master's name */
01633     gethostname(controlling_host_name,100);
01634 
01635     /* Let user activate mdebug or cdebug via environmental variables */
01636     evalue = (char *)NULL;
01637     evalue=(char *)getenv("CDEBUG");
01638     if(evalue)
01639         cdebug=atoi(evalue);
01640     evalue = (char *)NULL;
01641     evalue=(char *)getenv("MDEBUG");
01642     if(evalue)
01643         mdebug=atoi(evalue);
01644 
01645     srand(time(0));
01646     mygen=rand(); /* Pick a random generation number */
01647 
01648     /* Try to find the actual VM page size, if possible */
01649 #if defined (solaris) || defined (_HPUX_SOURCE) || defined (linux) || defined(IRIX) || defined (IRIX64)
01650 #ifndef __convex_spp
01651     page_size=getpagesize();
01652 #endif
01653 #endif
01654     /* Try to find the actual number of ticks per second */
01655 #ifdef unix
01656     sc_clk_tck = clk_tck();
01657 #endif
01658     for(ind=0;ind<MAXSTREAMS;ind++)
01659         filearray[ind]=(char *)tfile;
01660 
01661     /* base_time=(long)time_so_far(); */
01662     myid=(long long)getpid();   /* save the master's PID */
01663     /* get_resolution();         Get clock resolution */
01664     time_run = time(0);     /* Start a timer */
01665     (void)find_external_mon(imon_start, imon_stop);
01666 
01667     /*
01668      * Save the splash screen for later display. When in distributed network
01669      * mode this output does not get displayed on the clients.
01670      */
01671     sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n");
01672         sprintf(splash[splash_line++],"\t%s\n\t%s\n", THISVERSION,MODE);
01673         sprintf(splash[splash_line++],"\t\tBuild: %s \n\n",build_name);
01674         sprintf(splash[splash_line++],"\tContributors:William Norcott, Don Capps, Isom Crawford, Kirby Collins\n");
01675     sprintf(splash[splash_line++],"\t             Al Slater, Scott Rhine, Mike Wisner, Ken Goss\n");
01676         sprintf(splash[splash_line++],"\t             Steve Landherr, Brad Smith, Mark Kelly, Dr. Alain CYR,\n");
01677         sprintf(splash[splash_line++],"\t             Randy Dunlap, Mark Montague, Dan Million, Gavin Brebner,\n");
01678         sprintf(splash[splash_line++],"\t             Jean-Marc Zucconi, Jeff Blomberg, Benny Halevy, Dave Boone,\n");
01679         sprintf(splash[splash_line++],"\t             Erik Habbinga, Kris Strecker, Walter Wong, Joshua Root,\n");
01680         sprintf(splash[splash_line++],"\t             Fabrice Bacchella, Zhenghua Xue, Qin Li, Darren Sawyer.\n");
01681         sprintf(splash[splash_line++],"\t             Ben England.\n\n");
01682     sprintf(splash[splash_line++],"\tRun began: %s\n",ctime(&time_run));
01683     argcsave=argc;
01684     argvsave=argv;
01685 
01686         signal(SIGINT, signal_handler);     /* handle user interrupt */
01687         signal(SIGTERM, signal_handler);    /* handle kill from shell */
01688 
01689         /********************************************************/
01690         /* Allocate and align buffer with beginning of the  */
01691         /* on chip data cache.                  */
01692         /********************************************************/
01693 
01694         buffer = (char *) alloc_mem((long long)(MAXBUFFERSIZE + (2 * cache_size)),(int)0);
01695     if(buffer == 0) {
01696             perror("Memory allocation failed:");
01697             exit(1);
01698         }
01699 
01700 #ifdef _64BIT_ARCH_
01701         buffer = (char *) ((long long )(buffer + cache_size ) & 
01702         ~(cache_size-1));
01703 #else
01704         buffer = (char *) ((long)(buffer + cache_size ) & 
01705         ~((long)cache_size-1));
01706 #endif
01707     mainbuffer = buffer;
01708 
01709     /* de-dup input buf */
01710         buffer1 = (char *) alloc_mem((long long)(MAXBUFFERSIZE + (2 * cache_size)),(int)0);
01711     if(buffer1 == 0) {
01712             perror("Memory allocation failed:");
01713             exit(1);
01714         }
01715 
01716 #ifdef _64BIT_ARCH_
01717         buffer1 = (char *) ((long long )(buffer1 + cache_size ) & 
01718         ~(cache_size-1));
01719 #else
01720         buffer1 = (char *) ((long)(buffer1 + cache_size ) & 
01721         ~((long)cache_size-1));
01722 #endif
01723     dedup_ibuf = buffer1;
01724     touch_dedup(buffer1, MAXBUFFERSIZE);
01725 
01726 #ifdef FOOB
01727     /* de-dup temp buf */
01728         buffer1 = (char *) alloc_mem((long long)(MAXBUFFERSIZE + (2 * cache_size)),(int)0);
01729     if(buffer1 == 0) {
01730             perror("Memory allocation failed:");
01731             exit(1);
01732         }
01733 
01734 #ifdef _64BIT_ARCH_
01735         buffer1 = (char *) ((long long )(buffer1 + cache_size ) & 
01736         ~(cache_size-1));
01737 #else
01738         buffer1 = (char *) ((long)(buffer1 + cache_size ) & 
01739         ~((long)cache_size-1));
01740 #endif
01741 #endif
01742     dedup_temp = mainbuffer;
01743 
01744     fetchon++;  /* By default, prefetch the CPU cache lines associated with the buffer */
01745     strcpy(filename,default_filename);  /* Init default filename */
01746     sprintf(dummyfile[0],"%s.DUMMY",default_filename);
01747     if(argc <=1){
01748         printf(USAGE);
01749         exit(255);
01750     }
01751     auto_mode = 0;      /* Default is to disable auto mode */
01752     inp_pat = PATTERN;  /* Init default pattern for verification */
01753     /* Fill the entire pattern variable with the same character */
01754     pattern = ((inp_pat << 24) | (inp_pat << 16) | (inp_pat << 8) | inp_pat);
01755 
01756     /*
01757      * Parse all of the options that the user specified.
01758      */
01759     while((cret = getopt(argc,argv,"ZQNIBDGCTOMREWovAxamwphcezKJ:j:k:V:r:t:s:f:F:d:l:u:U:S:L:H:+:P:i:b:X:Y:g:n:y:q: ")) != EOF){
01760         switch(cret){
01761         case 'k':   /* Async I/O with no bcopys */
01762             depth = (long long)(atoi(optarg));
01763             if(depth <0)
01764                 depth=0;
01765             /*
01766             if(depth > 60)
01767                 depth=60;
01768             */
01769 #ifdef NO_PRINT_LLD
01770             sprintf(splash[splash_line++],"\tPOSIX Async I/O (no bcopy). Depth %ld \n",depth);
01771 #else
01772             sprintf(splash[splash_line++],"\tPOSIX Async I/O (no bcopy). Depth %lld \n",depth);
01773 #endif
01774             no_copy_flag=1;
01775             async_flag++;
01776             k_flag++;
01777             break;
01778         case 'T':   /* Switch to POSIX thread based */
01779 #ifndef NO_THREADS
01780             use_thread++;
01781 #else
01782             printf("\tThreads not supported in this version\n");
01783             exit(2);
01784 #endif
01785             break;
01786         case 'H':   /* Use POSIX async_io */
01787             h_flag++;
01788             depth = (long long)(atoi(optarg));
01789             if(depth <0)
01790                 depth=0;
01791             /*
01792              * Hmmm. many systems fail is strange ways when the maximum
01793              * number of async I/Os per user or proc is exceeded.
01794              */
01795             /*
01796             if(depth > 60)
01797                 depth=60;
01798             */
01799 #ifdef NO_PRINT_LLD
01800             sprintf(splash[splash_line++],"\tPOSIX async I/O (with bcopy). Depth %ld\n",depth);
01801 #else
01802             sprintf(splash[splash_line++],"\tPOSIX async I/O (with bcopy). Depth %lld\n",depth);
01803 #endif
01804             async_flag++;
01805             break;
01806         case 'I':   /* Use VXFS direct advisory or O_DIRECT from Linux or AIX , or O_DIRECTIO for TRU64  or Solaris directio */
01807 #ifdef VXFS
01808             direct_flag++;
01809             sprintf(splash[splash_line++],"\tVxFS advanced feature SET_CACHE, VX_DIRECT enabled\n");
01810             break;
01811 #endif
01812 #if ! defined(DONT_HAVE_O_DIRECT)
01813 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined(__FreeBSD__) || defined(solaris)
01814             direct_flag++;
01815             sprintf(splash[splash_line++],"\tO_DIRECT feature enabled\n");
01816             break;
01817 #endif
01818 #if defined(TRU64)
01819             direct_flag++;
01820             sprintf(splash[splash_line++],"\tO_DIRECTIO feature enabled\n");
01821             break;
01822 #endif
01823 #else
01824             break;
01825 #endif
01826 #if defined(Windows)
01827             sprintf(splash[splash_line++],"\tO_DIRECTIO feature not available in Windows version.\n");
01828             break;
01829 #endif
01830         case 'B':   /* Use mmap file for test file */
01831             sprintf(splash[splash_line++],"\tUsing mmap files\n");
01832             mmapflag++;
01833             mmapnsflag++;
01834             break;
01835         case 'D':   /* Use async msync mmap file */
01836             sprintf(splash[splash_line++],"\tUsing msync(MS_ASYNC) on mmap files\n");
01837             mmapflag++;
01838             mmapasflag++;
01839             mmapnsflag=0;
01840             break;
01841         case 'G':   /* Use msync sync for mmap file */
01842             sprintf(splash[splash_line++],"\tUsing msync(MS_SYNC) on mmap files\n");
01843             mmapssflag++;
01844             mmapnsflag=0;
01845             break;
01846         case 'C':   /* show children xfer counts */
01847             Cflag++;
01848             break;
01849         case 'Q':   /* Enable output offset/latency files */
01850                 sprintf(splash[splash_line++],"\tOffset/latency files enabled.\n");
01851             Q_flag++;
01852             break;
01853         case 'x':   /* Disable stone_wall */
01854                 sprintf(splash[splash_line++],"\tStonewall disabled\n");
01855             xflag++;
01856             break;
01857 
01858         case 'a':   /* auto mode */
01859             fetchon=1;
01860             purge=0;
01861             multi_buffer=0;
01862                 auto_mode = 1;
01863             aflag++;
01864                 sprintf(splash[splash_line++],"\tAuto Mode\n");
01865             break;
01866         case 'c':   /* Include close in timing */
01867             include_close++;
01868                 sprintf(splash[splash_line++],"\tInclude close in write timing\n");
01869             break;
01870         case 'e':   /* Include fsync in timing */
01871             include_flush++;
01872                 sprintf(splash[splash_line++],"\tInclude fsync in write timing\n");
01873             break;
01874         case 'A':   /* auto2 mode. Soon to go away. Please use -az */
01875             fetchon=1;
01876             purge=0;
01877             multi_buffer=0;
01878                 auto_mode = 1;
01879             aflag++;
01880                 sprintf(splash[splash_line++],"\tAuto Mode 2. This option is obsolete. Use -az -i0 -i1 \n");
01881             RWONLYflag++;
01882             NOCROSSflag++;
01883             include_tflag++;    /* automatically set WRITER_TEST and READER_TEST */
01884             include_test[WRITER_TEST]++;
01885             include_test[READER_TEST]++;
01886             break;
01887         case 's':   /* Set file size */
01888 #ifdef NO_PRINT_LLD
01889             sscanf(optarg,"%ld",&kilobytes64);
01890 #else
01891             sscanf(optarg,"%lld",&kilobytes64);
01892 #endif
01893             if(optarg[strlen(optarg)-1]=='k' ||
01894                 optarg[strlen(optarg)-1]=='K'){
01895                 ;
01896             }
01897             if(optarg[strlen(optarg)-1]=='m' ||
01898                 optarg[strlen(optarg)-1]=='M'){
01899                 kilobytes64 = kilobytes64 * 1024;
01900             }
01901             if(optarg[strlen(optarg)-1]=='g' ||
01902                 optarg[strlen(optarg)-1]=='G'){
01903                 kilobytes64 = kilobytes64 *1024 * 1024;
01904             }
01905             if(kilobytes64 <= 0)
01906                 kilobytes64=512;
01907 
01908             s_range[s_count++]=kilobytes64;
01909             max_file_size = (off64_t)s_range[s_count-1];   /* Make visable globally */
01910             min_file_size = (off64_t)s_range[0];   /* Make visable globally */
01911 
01912 #ifdef NO_PRINT_LLD
01913                 sprintf(splash[splash_line++],"\tFile size set to %ld KB\n",kilobytes64);
01914 #else
01915                 sprintf(splash[splash_line++],"\tFile size set to %lld KB\n",kilobytes64);
01916 #endif
01917             sflag++;
01918             break;
01919         case 'l':   /* Set lower thread/proc limit  */
01920             mint = (long long)(atoi(optarg));
01921             if(mint <= 0)
01922             {
01923                 mint=1;
01924                 num_child=1;
01925             }else
01926                 num_child=mint;
01927             if(mint > (unsigned long long)MAXSTREAMS){
01928               printf("Invalid options: maximum streams for ");
01929               printf("throughput is MAXSTREAMS\n");
01930               exit(4);
01931             }
01932             lflag++;
01933             trflag++;
01934             if(Uflag)
01935             {
01936                 printf("Can not run throughput tests with unmount & remounts.\n");
01937                 exit(5);
01938             }
01939             break;
01940         case 'u':   /* Set upper thread/proc limit  */
01941             maxt = (long long)(atoi(optarg));
01942             if(maxt <= 0)
01943                 maxt=1;
01944             if(maxt > MAXSTREAMS){
01945               printf("Invalid options: maximum streams for ");
01946               printf("throughput is MAXSTREAMS\n");
01947               exit(6);
01948             }
01949             uflag++;
01950             trflag++;
01951             if(Uflag)
01952             {
01953                 printf("Can not run throughput tests with unmount & remounts.\n");
01954                 exit(7);
01955             }
01956             break;
01957         case 'm':   /* Use multiple buffers */
01958             fetchon=0;
01959             multi_buffer=1;
01960             mflag++;
01961                 mbuffer = (char *) alloc_mem((long long)MAXBUFFERSIZE,(int)0);
01962             if(mbuffer == 0) {
01963                             perror("Memory allocation failed:");
01964                             exit(8);
01965             }
01966                 sprintf(splash[splash_line++],"\tMulti_buffer. Work area %d bytes\n",
01967                 MAXBUFFERSIZE);
01968             break;
01969                 case 'M':       /* Report machine name and OS */
01970             bzero(reply,sizeof(reply));
01971                         pi=popen("uname -a", "r");
01972             if(pi == (FILE *)0)
01973             {
01974                 sprintf(splash[splash_line++],"\n\tError using popen() on uname\n");
01975                 sprintf(splash[splash_line++],"\t-M option suppressed.\n");
01976             }
01977             else
01978             {
01979                             junk=fread(reply,IBUFSIZE-1,1,pi);
01980                             pclose(pi);
01981                 m=reply;
01982                             while(*m) /* Strip new line */
01983                 {
01984                     if(*m=='\n')
01985                                         *m=0;
01986                     else    
01987                                         m++;
01988                 }
01989                             sprintf(splash[splash_line++],"\n\tMachine = %s\n",reply);
01990             }
01991                         break;
01992 
01993         case 'P':   /* Set beginning processor for binding. */
01994 #ifndef NO_THREADS
01995 #if defined(_HPUX_SOURCE) || defined(linux)
01996 #if defined(_HPUX_SOURCE)
01997             num_processors= pthread_num_processors_np();
01998 #else
01999       num_processors = sysconf(_SC_NPROCESSORS_ONLN);
02000 #endif      
02001             begin_proc = atoi(optarg);
02002             if(begin_proc < 0)
02003                 begin_proc=0;
02004             if(begin_proc > num_processors)
02005                 begin_proc=0;
02006                         sprintf(splash[splash_line++],"\tBinding of processors beginning with %d \n",begin_proc);
02007             ioz_processor_bind++;
02008 #else
02009             sprintf(splash[splash_line++],"\tProcessor binding not available in this version\n");
02010 #endif
02011 #endif
02012                         break;
02013         case 'p':   /* purge the processor cache */
02014                 sprintf(splash[splash_line++],"\tPurge Mode On\n");
02015             fetchon=0;
02016             pflag++;
02017             purge=1;
02018             break;
02019         case 'h':   /* show help */
02020             hflag++;
02021                 show_help();
02022             exit(0);
02023             break;
02024         case 'E':   /* Extended testing for pread/pwrite... */
02025             Eflag++;
02026             break;
02027         case 'R':   /* Generate Excel compatible Report */
02028             Rflag++;
02029                 sprintf(splash[splash_line++],"\tExcel chart generation enabled\n");
02030             break;
02031         case 'o':   /* Open OSYNC */
02032                 sprintf(splash[splash_line++],"\tSYNC Mode. \n");
02033             oflag++;
02034             break;
02035         case 'O':   /* Report in Ops/sec instead of KB/sec */
02036                 sprintf(splash[splash_line++],"\tOPS Mode. Output is in operations per second.\n");
02037             OPS_flag++;
02038             break;
02039         case 'N':   /* Report in usec/op  */
02040                 sprintf(splash[splash_line++],"\tMicroseconds/op Mode. Output is in microseconds per operation.\n");
02041             MS_flag++;
02042             break;
02043         case 'V':   /* Turn on Verify every byte */
02044             sverify=0;
02045             inp_pat = (char)(atoi(optarg));
02046             if(inp_pat == 0)
02047                 inp_pat = PATTERN;
02048             pattern = ((inp_pat << 24) | (inp_pat << 16) | (inp_pat << 8) 
02049                 | inp_pat);
02050             verify=1;
02051                 sprintf(splash[splash_line++],"\tVerify Mode. Pattern %x\n",pattern);
02052                 sprintf(splash[splash_line++],"\tPerformance measurements are invalid in this mode.\n");
02053             break;
02054         case 'S':   /* Set the processor cache size */
02055             cache_size = (long)(atoi(optarg)*1024);
02056             if(cache_size == 0)
02057                 cache_size = CACHE_SIZE;
02058             break;
02059         case 'L':   /* Set processor cache line size */
02060             cache_line_size = (long)(atoi(optarg));
02061             if(cache_line_size == 0)
02062                 cache_line_size = CACHE_LINE_SIZE;
02063             break;
02064         case 'f':   /* Specify the file name */
02065             if(mfflag) {
02066               printf("invalid options: -f and -F are mutually exclusive\n");
02067               exit(10);
02068             }
02069             fflag++;
02070             strcpy(filename,optarg);
02071             sprintf(dummyfile[0],"%s.DUMMY",optarg);
02072             break;
02073         case 'b':   /* Specify the biff file name */
02074             Rflag++;
02075             bif_flag++;
02076             strcpy(bif_filename,optarg);
02077             break;
02078         case 'F':   /* Specify multiple file names for -t */
02079             mfflag++;
02080             if(fflag) {
02081               printf("invalid options: -f and -F are mutually exclusive\n");
02082               exit(11);
02083             }
02084             if(!trflag) {
02085               printf("invalid options: must specify -t N before -F\n");
02086               exit(12);
02087             }
02088             optind--;
02089             for(fileindx=0;fileindx<maxt;fileindx++) {
02090               filearray[fileindx]=argv[optind++];
02091               if(optind > argc) {
02092 #ifdef NO_PRINT_LLD
02093                 printf("invalid options: not enough filenames for %ld streams\n",num_child);
02094 #else
02095                 printf("invalid options: not enough filenames for %lld streams\n",num_child);
02096 #endif
02097                 exit(13);
02098               }
02099             }
02100             break;
02101         case 'r':   /* Specify the record size to use */
02102             rflag++;
02103             reclen = ((long long)(atoi(optarg))*1024);
02104             if(optarg[strlen(optarg)-1]=='k' ||
02105                 optarg[strlen(optarg)-1]=='K'){
02106                 reclen = (long long)(1024 * atoi(optarg));
02107             }
02108             if(optarg[strlen(optarg)-1]=='m' ||
02109                 optarg[strlen(optarg)-1]=='M'){
02110                 reclen = (long long)(1024 * 1024 * atoi(optarg));
02111             }
02112             if(optarg[strlen(optarg)-1]=='g' ||
02113                 optarg[strlen(optarg)-1]=='G'){
02114                 reclen = (long long)(1024 * 1024 * 1024 *(long long)atoi(optarg));
02115             }
02116             if(reclen <= 0)
02117                 reclen=(long long)4096;
02118 
02119             r_range[r_count++]=reclen;
02120             max_rec_size = (off64_t)r_range[r_count-1];   /* Make visable globally */
02121             min_rec_size = (off64_t)r_range[0];   /* Make visable globally */
02122 #ifdef NO_PRINT_LLD
02123                 sprintf(splash[splash_line++],"\tRecord Size %ld KB\n",reclen/1024);
02124 #else
02125                 sprintf(splash[splash_line++],"\tRecord Size %lld KB\n",reclen/1024);
02126 #endif
02127             if(max_rec_size > MAXBUFFERSIZE) {
02128 #ifdef NO_PRINT_LLD
02129                 printf("Error: maximum record size %ld KB is greater than maximum buffer size %ld KB\n ",
02130                     max_rec_size/1024, MAXBUFFERSIZE/1024);
02131 #else
02132                 printf("Error: maximum record size %lld KB is greater than maximum buffer size %lld KB\n ",
02133                     (long long)(max_rec_size/1024LL), (long long)MAXBUFFERSIZE/1024LL);
02134 #endif
02135                 exit(23);
02136             }
02137             break;
02138         case 'J':   /* Specify the compute time in millisecs */
02139             compute_time = (float)(atoi(optarg));
02140             compute_time=compute_time/1000; 
02141             if(compute_time < (float)0)
02142                 compute_time=(float)0;
02143             else
02144                 compute_flag=1;
02145             jflag++;
02146             break;
02147         case 'j':   /* Specify the stride in records */
02148             stride = (long long)(atoi(optarg));
02149             if(stride < 0)
02150                 stride=0;
02151             stride_flag=1;
02152             break;
02153         case 't':   /* Specify the number of children to run */
02154             num_child1=(atoi(optarg));
02155             num_child = (long long)num_child1;
02156             if(num_child > (long long)MAXSTREAMS) {
02157               printf("invalid options: maximum streams for throughput is MAXSTREAMS\n");
02158 #ifdef NO_PRINT_LLD
02159               printf("Numchild %ld %s\n",num_child,optarg);
02160 #else
02161               printf("Numchild %lld %s\n",num_child,optarg);
02162 #endif
02163               exit(14);
02164             }
02165             if(num_child <= 0)
02166                 num_child = 8;
02167             if(num_child == 0)
02168                 num_child=1;
02169                         t_range[t_count++]=num_child;
02170                         maxt = (maxt>num_child?maxt:num_child);
02171             trflag++;
02172             if(Uflag)
02173             {
02174                 printf("Can not run throughput tests with unmount & remounts.\n");
02175                 exit(15);
02176             }
02177             break;
02178         case 'd':   /* Specify the delay of children to run */
02179             delay_start = (long long)(atoi(optarg));
02180             if(delay_start < 0)
02181                 delay_start=0;
02182             break;
02183         case 'i':   /* Specify specific tests */
02184             tval=(long long)(atoi(optarg));
02185             if(tval < 0) tval=0;
02186 #ifndef HAVE_PREAD
02187             if(tval > RANDOM_MIX_TEST)
02188             {
02189                 printf("\tPread tests not available on this operating system.\n");
02190                 exit(183);
02191             }
02192 #endif
02193             if(tval > sizeof(func)/sizeof(char *)) 
02194             {
02195                 tval=0;
02196                 sprintf(splash[splash_line++],"\tSelected test not available on the version.\n");
02197             }
02198             include_test[tval]++;
02199             include_tflag++;
02200             break;
02201         case 'v':   /* Show version information */
02202                 for(ind=0; strlen(head1[ind]); ind++)
02203                 {
02204                 printf("%s\n", head1[ind]);
02205                 }
02206             exit(0);
02207             break;
02208         case 'U':   /* Specify the dev name for umount/mount*/
02209             Uflag++;
02210             strcpy(mountname,optarg);
02211             if(trflag)
02212             {
02213                 printf("Can not run throughput tests with unmount & remounts.\n");
02214                 exit(16);
02215             }
02216             break;
02217         case 'w':   /* Do not unlink files */
02218             sprintf(splash[splash_line++],"\tSetting no_unlink\n");
02219             no_unlink = 1;
02220             break;
02221         case 'Z':   /* Turn on the mmap and file I/O mixing */
02222             sprintf(splash[splash_line++],"\tEnable mmap & file I/O mixing.\n");
02223             mmap_mix = 1;
02224             break;
02225         case 'W':   /* Read/Write with file locked */
02226             file_lock=1;
02227             sprintf(splash[splash_line++],"\tLock file when reading/writing.\n");
02228             break;
02229         case 'K':   /* Cause disrupted read pattern */
02230             disrupt_flag=1;
02231             sprintf(splash[splash_line++],"\tDisrupted read patterns selected.\n");
02232             break;
02233         case 'X':   /* Open write telemetry file */
02234             compute_flag=1;
02235             sverify=2;  /* touch lightly */
02236             w_traj_flag=1;
02237             strcpy(write_traj_filename,optarg);
02238             traj_vers();
02239             w_traj_size();
02240             sprintf(splash[splash_line++],"\tUsing write telemetry file \"%s\"\n",
02241                 write_traj_filename);
02242             w_traj_fd=open_w_traj();
02243             if(w_traj_fd == (FILE *)0)
02244                 exit(200);
02245             break;
02246         case 'Y':   /* Open Read telemetry file */
02247             compute_flag=1;
02248             sverify=2;  /* touch lightly */
02249             r_traj_flag=1;
02250             strcpy(read_traj_filename,optarg);
02251             sprintf(splash[splash_line++],"\tUsing read telemetry file \"%s\"\n",
02252                 read_traj_filename);
02253             traj_vers();
02254             r_traj_size();
02255             r_traj_fd=open_r_traj();
02256             if(r_traj_fd == (FILE*) 0)
02257                 exit(200);
02258             break;
02259         case 'n':   /* Set min file size for auto mode */
02260             nflag=1;
02261             minimum_file_size = (off64_t)atoi(optarg);
02262             if(optarg[strlen(optarg)-1]=='k' ||
02263                 optarg[strlen(optarg)-1]=='K'){
02264                 ;
02265             }
02266             if(optarg[strlen(optarg)-1]=='m' ||
02267                 optarg[strlen(optarg)-1]=='M'){
02268                 minimum_file_size = (long long)(1024 * atoi(optarg));
02269             }
02270             if(optarg[strlen(optarg)-1]=='g' ||
02271                 optarg[strlen(optarg)-1]=='G'){
02272                 minimum_file_size = (long long)(1024 * 1024 * (long long)atoi(optarg));
02273             }
02274             if(minimum_file_size < RECLEN_START/1024)
02275                 minimum_file_size=(off64_t)(RECLEN_START/1024);
02276             if(minimum_file_size < page_size/1024)
02277                 minimum_file_size=(off64_t)(page_size/1024);
02278 #ifdef NO_PRINT_LLD
02279             sprintf(splash[splash_line++],"\tUsing minimum file size of %ld kilobytes.\n",minimum_file_size);
02280 #else
02281             sprintf(splash[splash_line++],"\tUsing minimum file size of %lld kilobytes.\n",minimum_file_size);
02282 #endif
02283             break;
02284         case 'g':   /* Set maximum file size for auto mode */
02285             gflag=1;
02286             maximum_file_size = (off64_t)atoi(optarg);
02287             if(optarg[strlen(optarg)-1]=='k' ||
02288                 optarg[strlen(optarg)-1]=='K'){
02289                 ;
02290             }
02291             if(optarg[strlen(optarg)-1]=='m' ||
02292                 optarg[strlen(optarg)-1]=='M'){
02293                 maximum_file_size = (long long)(1024 * atoi(optarg));
02294             }
02295             if(optarg[strlen(optarg)-1]=='g' ||
02296                 optarg[strlen(optarg)-1]=='G'){
02297                 maximum_file_size = (long long)(1024 * 1024 * (long long)atoi(optarg));
02298             }
02299             if(maximum_file_size < RECLEN_START/1024)
02300                 maximum_file_size=(off64_t)(RECLEN_START/1024);
02301 #ifdef NO_PRINT_LLD
02302             sprintf(splash[splash_line++],"\tUsing maximum file size of %ld kilobytes.\n",maximum_file_size);
02303 #else
02304             sprintf(splash[splash_line++],"\tUsing maximum file size of %lld kilobytes.\n",maximum_file_size);
02305 #endif
02306             break;
02307         case 'z':   /* Set no cross over */
02308             sprintf(splash[splash_line++],"\tCross over of record size disabled.\n");
02309             NOCROSSflag=1;
02310             break;
02311         case 'y':       /* Set min record size for auto mode */
02312             yflag=1;
02313             min_rec_size = ((long long)(atoi(optarg))*1024);
02314             if(optarg[strlen(optarg)-1]=='k' ||
02315                 optarg[strlen(optarg)-1]=='K'){
02316                 min_rec_size = (long long)(1024 * atoi(optarg));
02317             }
02318             if(optarg[strlen(optarg)-1]=='m' ||
02319                 optarg[strlen(optarg)-1]=='M'){
02320                 min_rec_size = (long long)(1024 * 1024 * atoi(optarg));
02321             }
02322             if(optarg[strlen(optarg)-1]=='g' ||
02323                 optarg[strlen(optarg)-1]=='G'){
02324                 min_rec_size = (long long)(1024 * 1024 * 1024 *(long long)atoi(optarg));
02325             }
02326             if(min_rec_size <= 0)
02327                 min_rec_size=(long long)RECLEN_START;
02328 #ifdef NO_PRINT_LLD
02329                 sprintf(splash[splash_line++],"\tUsing Minimum Record Size %ld KB\n", min_rec_size/1024);
02330 #else
02331                 sprintf(splash[splash_line++],"\tUsing Minimum Record Size %lld KB\n", min_rec_size/1024);
02332 #endif
02333             break;
02334         case 'q':       /* Set max record size for auto mode */
02335             qflag=1;
02336             max_rec_size = ((long long)(atoi(optarg))*1024);
02337             if(optarg[strlen(optarg)-1]=='k' ||
02338                 optarg[strlen(optarg)-1]=='K'){
02339                 max_rec_size = (long long)(1024 * atoi(optarg));
02340             }
02341             if(optarg[strlen(optarg)-1]=='m' ||
02342                 optarg[strlen(optarg)-1]=='M'){
02343                 max_rec_size = (long long)(1024 * 1024 * atoi(optarg));
02344             }
02345             if(optarg[strlen(optarg)-1]=='g' ||
02346                 optarg[strlen(optarg)-1]=='G'){
02347                 max_rec_size = (long long)(1024 * 1024 * 1024 *(long long)atoi(optarg));
02348             }
02349             if(max_rec_size <= 0)
02350                 min_rec_size=(long long)RECLEN_END;
02351             if(max_rec_size > MAXBUFFERSIZE) {
02352 #ifdef NO_PRINT_LLD
02353                 printf("Error: maximum record size %ld KB is greater than maximum buffer size %ld KB\n ",
02354                     max_rec_size/1024, MAXBUFFERSIZE/1024);
02355 #else
02356                 printf("Error: maximum record size %lld KB is greater than maximum buffer size %lld KB\n ",
02357                     (long long)(max_rec_size/1024LL), (long long)MAXBUFFERSIZE/1024LL);
02358 #endif
02359                 exit(23);
02360             }
02361 #ifdef NO_PRINT_LLD
02362             sprintf(splash[splash_line++],"\tUsing Maximum Record Size %ld KB\n", max_rec_size/1024);
02363 #else
02364             sprintf(splash[splash_line++],"\tUsing Maximum Record Size %lld KB\n", max_rec_size/1024);
02365 #endif
02366             break;
02367 
02368         /* 
02369          * The + operator is for the new extended options mechanism 
02370          * Syntax is -+ followed by option leter, and if the optino
02371          * takes an operand  then it is implemented below. An example
02372          * -+a arg    is shown below. This is a sub option with an argument.
02373          * -+b  is shown below. This is a sub option with no argument.
02374          */
02375         case '+':
02376             /* printf("Plus option = >%s<\n",optarg);*/
02377             switch (*((char *)optarg))
02378             {
02379                 case 'a':  /* Example: Has argument */
02380                     subarg=argv[optind++];
02381                     /* if(subarg!=(char *)0)   Error checking. */
02382                     /* printf("Plus option argument = >%s<\n",subarg);*/
02383                     break;
02384                 case 'b':  /* Example: Does not have an argument */
02385                     break;
02386                 case 'c':  /* Argument is the controlling host name */
02387                     /* I am a client for distributed Iozone */
02388                     subarg=argv[optind++];
02389                     if(subarg==(char *)0)
02390                     {
02391                          printf("-+c takes an operand !!\n");
02392                          exit(200);
02393                     }
02394                     strcpy(controlling_host_name,subarg);
02395                     distributed=1;
02396                     client_iozone=1;
02397                     master_iozone=0;
02398                     break;
02399                                 case 'h':  /* Argument is the controlling host name */
02400                                         subarg=argv[optind++];
02401                                         if(subarg==(char *)0)
02402                                         {
02403                                              printf("-+h takes an operand !!\n");
02404                                              exit(200);
02405                                         }
02406                                         strcpy(controlling_host_name,subarg);
02407                                         sprintf(splash[splash_line++],"\tHostname = %s\n",controlling_host_name);
02408                                         break;
02409                 case 'm':  /* I am the controlling process for distributed Iozone */
02410                        /* Does not have an argument */
02411                     subarg=argv[optind++];
02412                     if(subarg==(char *)0)
02413                     {
02414                          printf("-+m takes an operand. ( filename )\n");
02415                          exit(201);
02416                     }
02417                     strcpy(client_filename,subarg);
02418                     ret=get_client_info();
02419                     if(ret <= 0)
02420                     {
02421                         printf("Error reading client file\n");
02422                         exit(178);
02423                     }
02424                     clients_found=ret;
02425                     distributed=1;
02426                     master_iozone=1;
02427                     client_iozone=0;
02428                     sprintf(splash[splash_line++],"\tNetwork distribution mode enabled.\n");
02429                     break;
02430                 case 'N':  /* turn off truncating the file before write test */
02431                     notruncate = 1;
02432                     break;
02433                 case 'u':   /* Set CPU utilization output flag */
02434                     cpuutilflag = 1;    /* only used if R(eport) flag is also set */
02435                     get_rusage_resolution();
02436                         sprintf(splash[splash_line++],"\tCPU utilization Resolution = %5.3f seconds.\n",cputime_res);
02437                         sprintf(splash[splash_line++],"\tCPU utilization Excel chart enabled\n");
02438                     break;
02439                 case 's':  /* Clients operate in silent mode. */
02440                        /* Does not have an argument */
02441                     silent=1;
02442                     break;
02443                 case 'd':  /* Diagnostics mode */
02444                     sprintf(splash[splash_line++],"\t>>> I/O Diagnostic mode enabled. <<<\n");
02445                         sprintf(splash[splash_line++],"\tPerformance measurements are invalid in this mode.\n");
02446                     diag_v=1;
02447                     sverify=0;
02448                     break;
02449                 case 'x':  /* Argument is the multiplier for rec size and file size */
02450                     subarg=argv[optind++];
02451                     if(subarg==(char *)0)
02452                     {
02453                          printf("-+c takes an operand !!\n");
02454                          exit(200);
02455                     }
02456                     multiplier = atoi(subarg);
02457                     if(multiplier <=1)
02458                         multiplier = 2;
02459                     break;
02460                 case 'i':  /* Argument is the host port */
02461                     subarg=argv[optind++];
02462                     if(subarg==(char *)0)
02463                     {
02464                          printf("-+i takes an operand !!\n");
02465                          exit(200);
02466                     }
02467                     controlling_host_port = atoi(subarg);
02468                     break;
02469                 case 'p':  /* Argument is the percentage read */
02470                     subarg=argv[optind++];
02471                     if(subarg==(char *)0)
02472                     {
02473                          printf("-+p takes an operand !!\n");
02474                          exit(200);
02475                     }
02476                     pct_read = atoi(subarg);
02477                     if(pct_read < 1)
02478                         pct_read = 1;
02479                     if(pct_read >=100)
02480                         pct_read = 100;
02481                         sprintf(splash[splash_line++],"\tPercent read in mix test is %d\n",pct_read);
02482                     break;
02483                 case 't':  /* Speed code activated */
02484                     speed_code=1;
02485                     break;
02486 #if defined(_HPUX_SOURCE) || defined(linux) || defined(solaris)
02487                 case 'r':  /* Read sync too */
02488                     read_sync=1;
02489                         sprintf(splash[splash_line++],"\tRead & Write sync mode active.\n");
02490                     break;
02491 #endif
02492 #ifndef NO_MADVISE
02493                 case 'A':  /* Argument is madvise selector */
02494                     subarg=argv[optind++];
02495                     if(subarg==(char *)0)
02496                     {
02497                        printf("-+A take an operand !!\n");
02498                        exit(200);
02499                     }
02500                     advise_flag=1;
02501                     advise_op=atoi(subarg);
02502                     sprintf(splash[splash_line++],"\tMadvise enabled: %d\n",advise_op);
02503                     break;
02504 #endif
02505                 case 'n':   /* Set no-retest */
02506                     noretest = 1;   
02507                         sprintf(splash[splash_line++],"\tNo retest option selected\n");
02508                     break;
02509                 case 'k':   /* Constant aggregate data set size */
02510                     aggflag=1;
02511                     break;
02512                 case 'q':  /* Argument is the rest time between tests in seconds */
02513                     subarg=argv[optind++];
02514                     if(subarg==(char *)0)
02515                     {
02516                          printf("-+q takes an operand !!\n");
02517                          exit(200);
02518                     }
02519                     rest_val = (long long)atoi(subarg);
02520                     if(rest_val <=0)
02521                         rest_val = 0;
02522                     restf=1;
02523                     sprintf(splash[splash_line++],"\tDelay %d seconds between tests enabled.\n",atoi(subarg));
02524                     break;
02525 #if defined(O_DSYNC)
02526                 case 'D':  /* O_DSYNC mode */
02527                     sprintf(splash[splash_line++],"\t>>> O_DSYNC mode enabled. <<<\n");
02528                     odsync=1;
02529                     break;
02530 #endif
02531                 case 'l':  /* Record locking mode */
02532                     sprintf(splash[splash_line++],"\t>>> Record locking mode enabled. <<<\n");
02533                     rlocking=1;
02534                     break;
02535                 case 'L':  /* Record locking mode shared files*/
02536                     sprintf(splash[splash_line++],"\t>>> Record locking, shared file mode enabled. <<<\n");
02537                     share_file=1;
02538                     rlocking=1;
02539                     break;
02540                 case 'V':  /* No Record locking shared files*/
02541                     sprintf(splash[splash_line++],"\t>>> Shared file mode enabled. <<<\n");
02542                     share_file=1;
02543                     break;
02544                 case 'B':  /* Sequential mix */
02545                     sprintf(splash[splash_line++],"\t>>> Sequential Mixed workload. <<<\n");
02546                     seq_mix=1;
02547                     break;
02548                         /* Use an existing user file, that does
02549                      not contain Iozone's pattern. Use file
02550                                      for testing, but read only, and no 
02551                                          delete at the end of the test. Also, 
02552                                          no pattern verification, but do touch
02553                                          the pages. */
02554                 case 'E':  
02555                     sprintf(splash[splash_line++],"\t>>> No Verify mode. <<<\n");
02556                     sverify=2;
02557                     no_unlink=1;
02558                     no_write=1;
02559                     break;
02560                 case 'T':  /* Time stamps on */
02561                     L_flag=1;
02562                     break;
02563                 case 'X': /* Short circuit test mode */
02564                     X_flag = 1;
02565                     sverify=1;
02566                     verify=1;
02567                     inp_pat = 0xBB;
02568                     pattern = ((inp_pat << 24) | 
02569                       (inp_pat << 16) | (inp_pat << 8) |
02570                        inp_pat);
02571                         sprintf(splash[splash_line++],"\tShort circuit mode. For\n");
02572                         sprintf(splash[splash_line++],"\t filesystem development testing ONLY !\n");
02573                     break;
02574                 case 'Z': /* Compatibility mode for 0xA5 */ 
02575                     Z_flag = 1;
02576                     sverify=1;
02577                     verify=1;
02578                     inp_pat = 0xA5;
02579                     pattern = ((inp_pat << 24) | 
02580                       (inp_pat << 16) | (inp_pat << 8) |
02581                        inp_pat);
02582                         sprintf(splash[splash_line++],"\tUsing old data sets.\n");
02583                         sprintf(splash[splash_line++],"\t Performance measurements may be invalid in this\n");
02584                         sprintf(splash[splash_line++],"\t mode due to published hack.\n");
02585                     break;
02586 #if defined(Windows)
02587                 case 'U':  /* Windows only Unbufferd I/O */
02588                     unbuffered=1;
02589                     sprintf(splash[splash_line++],"\tUnbuffered Windows API usage. >>> Very Experimental <<<\n");
02590                     break;
02591 #endif
02592                 case 'K':  /* Sony special for manual control of test 8 */
02593                     subarg=argv[optind++];
02594                     if(subarg==(char *)0)
02595                     {
02596                          printf("-+K takes an operand !!\n");
02597                          exit(204);
02598                     }
02599                     Kplus_readers = (int)atoi(subarg);
02600                     if(Kplus_readers <=0)
02601                         Kplus_readers = 1;
02602                     Kplus_flag=1;
02603                     sprintf(splash[splash_line++],"\tManual control of test 8. >>> Very Experimental. Sony special <<<\n");
02604                     break;
02605                 case 'w':  /* Argument is the percent of dedup */
02606                        /* Sets size of dedup region across files */
02607                     subarg=argv[optind++];
02608                     if(subarg==(char *)0)
02609                     {
02610                          printf("-+w takes an operand !!\n");
02611                          exit(200);
02612                     }
02613                     dedup = atoi(subarg);
02614                     if(dedup <=0)
02615                         dedup = 0;
02616                     if(dedup >100)
02617                         dedup = 100;
02618                     sprintf(splash[splash_line++],"\tDedup activated %d percent.\n",dedup);
02619                     break;
02620                 case 'y':  /* Argument is the percent of interior dedup */
02621                        /* Sets size of dedup region within and across files */
02622                     subarg=argv[optind++];
02623                     if(subarg==(char *)0)
02624                     {
02625                          printf("-+y takes an operand !!\n");
02626                          exit(200);
02627                     }
02628                     dedup_interior = atoi(subarg);
02629                     if(dedup_interior <0)
02630                         dedup_interior = 0;
02631                     if(dedup_interior >100)
02632                         dedup_interior = 100;
02633                     sprintf(splash[splash_line++],"\tDedupe within & across %d percent.\n",dedup_interior);
02634                     break;
02635                 case 'C':  /* Argument is the percent of dedupe within & !across */
02636                        /* Sets size of dedup region within and !across files */
02637                     subarg=argv[optind++];
02638                     if(subarg==(char *)0)
02639                     {
02640                          printf("-+C takes an operand !!\n");
02641                          exit(200);
02642                     }
02643                     dedup_compress = atoi(subarg);
02644                     if(dedup_compress <0)
02645                         dedup_compress = 0;
02646                     if(dedup_compress >100)
02647                         dedup_compress = 100;
02648                     sprintf(splash[splash_line++],"\tDedupe within %d percent.\n",dedup_compress);
02649                     break;
02650                 case 'S':  /* Argument is the seed for dedup */
02651                     subarg=argv[optind++];
02652                     if(subarg==(char *)0)
02653                     {
02654                          printf("-+S takes an operand !!\n");
02655                          exit(200);
02656                     }
02657                     dedup_mseed = atoi(subarg);
02658                     if(dedup_mseed ==0)
02659                         dedup_mseed = 1;
02660                     sprintf(splash[splash_line++],"\tDedup manual seed %d .\n",dedup_mseed);
02661                     break;
02662                 case 'H':  /* Argument is hostname of the PIT */
02663                     subarg=argv[optind++];
02664                     if(subarg==(char *)0)
02665                     {
02666                          printf("-+H takes operand !!\n");
02667                          exit(200);
02668                     }
02669                     strcpy(pit_hostname,subarg);
02670                     sprintf(splash[splash_line++],"\tPIT_host %s\n",pit_hostname);
02671                     
02672                     break;
02673                 case 'P':  /* Argument is port of the PIT */
02674                     subarg=argv[optind++];
02675                     if(subarg==(char *)0)
02676                     {
02677                          printf("-+P takes operand !!\n");
02678                          exit(200);
02679                     }
02680                     strcpy(pit_service,subarg);
02681                     sprintf(splash[splash_line++],"\tPIT_port %s\n",pit_service);
02682                     break;
02683                 case 'z':  /* Enable hist summary*/
02684                     hist_summary=1;
02685                     sprintf(splash[splash_line++],"\tHistogram summary enabled.\n");
02686                     break;
02687                 case 'O':  /* Argument is the Op rate */
02688                     subarg=argv[optind++];
02689                     if(subarg==(char *)0)
02690                     {
02691                          printf("-+O takes an operand !!\n");
02692                          exit(200);
02693                     }
02694                     op_rate = atoi(subarg);
02695                     if(op_rate <= 0)
02696                         op_rate = 1;
02697                     op_rate_flag = 1;
02698                     sprintf(splash[splash_line++],"\tRate control active %d Ops/sec .\n",op_rate);
02699                     break;
02700                 default:
02701                     printf("Unsupported Plus option -> %s <-\n",optarg);
02702                     exit(255);
02703                     break;
02704             }   
02705             break;
02706         default:
02707             printf("Unsupported option -> %s <-\n",optarg);
02708             exit(255);
02709         }
02710     }
02711     base_time=(long)time_so_far();
02712     get_resolution();       /* Get clock resolution */
02713     if(speed_code)
02714     {
02715         do_speed_check(client_iozone);
02716         exit(0);
02717     }
02718     if(r_count > 1)
02719     {
02720         aflag=1;
02721         rflag=0;
02722         NOCROSSflag=1;
02723     }
02724     if(s_count > 1)
02725     {
02726         aflag=1;
02727         sflag=0;
02728         NOCROSSflag=1;
02729     }
02730     /*
02731          * If not in silent mode then display the splash screen.
02732      */
02733     for(i=0;i<splash_line;i++)
02734         if(!silent) printf("%s",splash[i]);
02735     /*
02736      * Save the command line for later 
02737      */
02738     record_command_line(argcsave, argvsave);
02739 
02740     if(pflag) /* Allocate after cache_size is set */
02741     {
02742         alloc_pbuf();
02743     }
02744     if(distributed && master_iozone)
02745     {
02746         if(maxt > clients_found)
02747         {
02748             printf("You can not specify more threads/processes than you have in the client file list\n");
02749             exit(202);
02750         }
02751     }
02752     
02753     if(!OPS_flag && !MS_flag)
02754     {
02755         if(!silent) printf("\tOutput is in Kbytes/sec\n");
02756     }
02757     if (min_rec_size > max_rec_size) {
02758 #ifdef NO_PRINT_LLD
02759         printf("Error: minimum record size %ld KB is greater than maximum record size %ld KB\n ",
02760             min_rec_size/1024, max_rec_size/1024);
02761 #else
02762         printf("Error: minimum record size %lld KB is greater than maximum record size %lld KB\n ",
02763             min_rec_size/1024, max_rec_size/1024);
02764 #endif
02765         exit(23);
02766         }
02767     orig_min_rec_size=min_rec_size;
02768     orig_max_rec_size=max_rec_size;
02769     /*
02770      * No telemetry files... just option selected 
02771      */
02772     if(compute_flag && jflag  && !(r_traj_flag || w_traj_flag))
02773         if(!silent) printf("\tCompute time %f seconds for reads and writes.\n",compute_time);
02774     /*
02775      * Read telemetry file and option selected
02776      */
02777     if(compute_flag && r_traj_flag && !w_traj_flag)
02778     {
02779         if(r_traj_items==3)
02780         {
02781             if(!silent) printf("\tCompute time from telemetry files for reads.\n");
02782         }
02783         else
02784         {
02785             if(jflag)
02786                 if(!silent) printf("\tCompute time %f seconds for reads.\n",compute_time);
02787         }
02788         if(jflag)
02789             if(!silent) printf("\tCompute time %f seconds for writes.\n",compute_time);
02790     }
02791     /*
02792      * Write telemetry file and option selected
02793      */
02794     if(compute_flag && !r_traj_flag && w_traj_flag)
02795     {
02796         if(w_traj_items==3)
02797         {
02798             if(!silent) printf("\tCompute time from telemetry files for writes.\n");
02799         }
02800         else
02801         {
02802             if(jflag)
02803                 if(!silent) printf("\tCompute time %f seconds for writes.\n",compute_time);
02804         }
02805         if(jflag)
02806             if(!silent) printf("\tCompute time %f seconds for reads.\n",compute_time);
02807     }
02808     if(compute_flag && r_traj_flag && w_traj_flag && jflag)
02809     {
02810         if(r_traj_items==3)
02811         {
02812             if(!silent) printf("\tCompute time from telemetry files for reads.\n");
02813         }
02814         else
02815         {
02816             if(!silent) printf("\tCompute time %f seconds for reads.\n",compute_time);
02817         }
02818         if(w_traj_items==3) 
02819         {
02820             if(!silent) printf("\tCompute time from telemetry files for writes.\n");
02821         }
02822         else
02823         {
02824             if(!silent) printf("\tCompute time %f seconds for writes.\n",compute_time);
02825         }
02826     }
02827     if(compute_flag && r_traj_flag && w_traj_flag && !jflag)
02828     {
02829         if(r_traj_items==3)
02830         {
02831             if(!silent) printf("\tCompute time from telemetry files for reads.\n");
02832         }
02833         else
02834         {
02835             if(!silent) printf("\tNo compute time for reads.\n");
02836         }
02837 
02838         if(w_traj_items==3) 
02839         {
02840             if(!silent) printf("\tCompute time from telemetry files for writes.\n");
02841         }
02842         else
02843         {
02844             if(!silent) printf("\tNo compute time for writes.\n");
02845         }
02846     }
02847 
02848         /* Enforce only write,rewrite,read,reread */
02849         if(w_traj_flag || r_traj_flag)
02850         {
02851                 for(i=2;i<sizeof(func)/sizeof(char *);i++)
02852                 {
02853                         if(seq_mix && (i==8))
02854                                 ;
02855                         else
02856                                 include_test[i] = 0;
02857                 }
02858         }
02859 
02860     if(r_traj_flag)
02861     {
02862         if(include_test[READER_TEST] == 0) 
02863         {
02864             include_test[WRITER_TEST]=1;
02865             include_test[READER_TEST]=1;
02866             include_tflag=1;
02867         }
02868     }
02869     if(w_traj_flag)
02870     {
02871         if(include_test[WRITER_TEST] == 0) 
02872         {
02873             include_test[WRITER_TEST]=1;
02874             include_tflag=1;
02875         }
02876     }
02877     if(w_traj_flag && w_traj_fsize != 0)
02878         kilobytes64=w_traj_fsize/1024;
02879     if(r_traj_flag && r_traj_fsize != 0)
02880         kilobytes64=r_traj_fsize/1024;
02881 
02882     if( sverify==0 && (w_traj_flag || r_traj_flag))
02883     {
02884         printf("\n\tFull verification not supported in telemetry mode.\n\n");
02885         exit(17);
02886     }
02887     ;
02888     if(disrupt_flag &&(w_traj_flag || r_traj_flag) )
02889     {
02890         printf("\n\tDisrupt not supported in telemetry mode.\n\n");
02891         exit(17);
02892     }
02893     if(aflag &&(w_traj_flag || r_traj_flag) )
02894     {
02895         printf("\n\tAuto mode not supported in telemetry mode.\n");
02896         printf("\tTry:   -i 0 -i 1 \n\n");
02897         exit(17);
02898     }
02899     if(sflag && w_traj_flag )
02900     {
02901         printf("\n\tSize of file is determined by telemetry file.\n\n");
02902         exit(17);
02903     }
02904     if(rflag && w_traj_flag )
02905     {
02906         printf("\n\tRecord size of file is determined by telemetry file.\n\n");
02907         exit(17);
02908     }
02909     if(stride_flag && (w_traj_flag || r_traj_flag))
02910     {
02911         printf("\n\tStride size is determined by telemetry file.\n\n");
02912         exit(17);
02913     }
02914     if(trflag && MS_flag)
02915     {
02916         printf("\n\tMicrosecond mode not supported in throughput mode.\n\n");
02917         exit(17);
02918     }
02919     if (trflag  /* throughput mode, don't allow auto-mode options: */
02920         && (auto_mode || aflag || yflag || qflag || nflag || gflag))
02921     {
02922         printf("\n\tCan not mix throughput mode and auto-mode flags.\n\n");
02923         exit(17);
02924     }
02925     if(fflag && trflag)
02926     {
02927         printf("\n\tYou must use -F when using multiple threads or processes.\n\n");
02928         exit(17);
02929     }
02930     if(aflag && mfflag)
02931     {
02932         printf("\n\tYou must use -f when using auto mode.\n\n");
02933         exit(17);
02934     }
02935     if(async_flag && mmapflag)
02936     {
02937         printf("\n\tSorry ... Only mmap or async but not both\n\n");
02938         exit(18);
02939     }
02940 #ifndef ASYNC_IO
02941     if(async_flag)
02942     {
02943         printf("\n\tSorry ... This version does not support async I/O\n\n");
02944         exit(19);
02945     }
02946 #endif
02947     if(no_write)
02948     {
02949        if(!include_tflag)
02950        {
02951          printf("You must specify which tests ( -i # ) when using -+E\n");
02952          exit(19);
02953        }
02954     }
02955     if(include_tflag)
02956     {
02957         for(i=0;i<sizeof(func)/sizeof(char *);i++)
02958             if(include_test[i])
02959                 include_mask|=(long long)(1<<i);
02960         /* printf(">> %llx",include_mask);  HERE */
02961     }
02962     if(no_write) /* Disable if any writer would disturbe existing file */
02963     {
02964        if(include_test[0] || include_test[4] ||
02965           include_test[6] || include_test[8] || include_test[9] ||
02966               include_test[11])
02967        {
02968           printf("You must disable any test that writes when using -+E\n");
02969           exit(20);
02970        }
02971     }
02972     if(no_write) /* User must specify the existing file name */
02973     {
02974        if(!(fflag | mfflag))
02975        {
02976           printf("You must use -f or -F when using -+E\n");
02977           exit(20);
02978        }
02979     }
02980     if(h_flag && k_flag)
02981     {
02982         printf("\n\tCan not do both -H and -k\n");
02983         exit(20);
02984     }
02985     if((dedup | dedup_interior) && diag_v)
02986     {
02987         printf("\n\tCan not do both -+d and -+w\n");
02988         exit(20);
02989     }
02990         
02991     if(!aflag && !rflag)
02992         max_rec_size=min_rec_size;
02993 
02994     init_record_sizes(min_rec_size,max_rec_size);
02995         if(!silent) printf("\tTime Resolution = %1.6f seconds.\n",time_res);
02996 #ifdef NO_PRINT_LLD
02997         if(!silent) printf("\tProcessor cache size set to %ld Kbytes.\n",cache_size/1024);
02998         if(!silent) printf("\tProcessor cache line size set to %ld bytes.\n",cache_line_size);
02999     if(!silent) printf("\tFile stride size set to %ld * record size.\n",stride);
03000 #else
03001         if(!silent) printf("\tProcessor cache size set to %ld Kbytes.\n",cache_size/1024);
03002         if(!silent) printf("\tProcessor cache line size set to %ld bytes.\n",cache_line_size);
03003     if(!silent) printf("\tFile stride size set to %lld * record size.\n",stride);
03004 #endif
03005     if(!rflag)
03006         reclen=(long long)4096;
03007 
03008     if(uflag && !lflag)
03009         num_child=mint = 1;
03010     if(lflag && !uflag)
03011         maxt = mint;
03012     if(use_thread)
03013         port="thread";
03014     else
03015         port="process";
03016     if(lflag || uflag){
03017 #ifdef NO_PRINT_LLD
03018         if(!silent) printf("\tMin %s = %ld \n",port,mint);
03019         if(!silent) printf("\tMax %s = %ld \n",port,maxt);
03020 #else
03021         if(!silent) printf("\tMin %s = %lld \n",port,mint);
03022         if(!silent) printf("\tMax %s = %lld \n",port,maxt);
03023 #endif
03024     }
03025     if(trflag)
03026     {
03027         if(num_child > 1)
03028         {
03029             if(use_thread)
03030             {
03031                 port="threads";
03032             }
03033             else
03034             {
03035                 port="processes";
03036             }
03037         }
03038 
03039 #ifdef NO_PRINT_LLD
03040         if(!silent) printf("\tThroughput test with %ld %s\n", num_child,port);
03041 #else
03042         if(!silent) printf("\tThroughput test with %lld %s\n", num_child,port);
03043 #endif
03044     }
03045         numrecs64 = (long long)(kilobytes64*1024)/reclen;
03046         if (reclen >  (long long)MAXBUFFERSIZE) {
03047 #ifdef NO_PRINT_LLD
03048                 printf("Error: Maximum record length is %ld bytes\n",
03049                                 MAXBUFFERSIZE);
03050 #else
03051                 printf("Error: Maximum record length is %lld bytes\n",
03052                                 (long long)MAXBUFFERSIZE);
03053 #endif
03054                 exit(21);
03055         }
03056         if (reclen < (long long)MINBUFFERSIZE) {
03057 #ifdef NO_PRINT_LLD
03058                 printf("Error: Minimum record length is %ld bytes\n",
03059                                 MINBUFFERSIZE);
03060 #else
03061                 printf("Error: Minimum record length is %lld bytes\n",
03062                                 (long long)MINBUFFERSIZE);
03063 #endif
03064                 exit(22);
03065         }
03066     /* Only bzero or fill that which you will use. The buffer is very large */
03067     if(verify ) 
03068     {
03069         fill_buffer((char *)buffer,l_min(reclen,(long long)cache_size),(long long)pattern,(char)sverify,(long long)0);
03070         if(pflag)
03071             fill_buffer((char *)pbuffer,l_min(reclen,(long long)cache_size),(long long)pattern,(char)sverify,(long long)0);
03072         if(mflag)
03073             fill_buffer((char *)mbuffer,l_min(reclen,(long long)cache_size),(long long)pattern,(char)sverify,(long long)0);
03074     }
03075     else
03076     {
03077         bzero(buffer,(size_t)l_min(reclen,(long long)cache_size));
03078     }
03079 
03080 #ifndef NO_THREADS
03081 #if defined( _HPUX_SOURCE ) || defined ( linux )
03082     if(ioz_processor_bind)
03083     {
03084          bind_cpu=begin_proc;
03085 #if defined( _HPUX_SOURCE )
03086          pthread_processor_bind_np(PTHREAD_BIND_FORCED_NP,
03087                          (pthread_spu_t *)&anwser, (pthread_spu_t)bind_cpu, pthread_self());
03088 #else
03089      cpu_set_t cpuset;
03090      CPU_ZERO(&cpuset);
03091      CPU_SET(bind_cpu, &cpuset);
03092 
03093      pthread_setaffinity_np(pthread_self(), sizeof(cpuset),&cpuset);
03094 #endif
03095         my_nap(40); /* Switch to new cpu */
03096     }
03097 #endif
03098 #endif
03099     orig_size=kilobytes64;
03100     if(trflag){
03101         (void)multi_throughput_test(mint,maxt);
03102         goto out;
03103     }
03104     if(trflag && (mint == maxt)){
03105         auto_mode=0;
03106         throughput_test();
03107             goto out;
03108     }
03109         if (aflag) {
03110         print_header();
03111         auto_test();
03112         goto out;
03113     } 
03114     print_header();
03115     (void) begin(kilobytes64,reclen);
03116 out:
03117     if(r_traj_flag)
03118         fclose(r_traj_fd);
03119     if(w_traj_flag)
03120         fclose(w_traj_fd);
03121     if (!no_unlink)
03122     {
03123         if(check_filename(dummyfile[0]))
03124                unlink(dummyfile[0]);    /* delete the file */
03125     }
03126     if(!silent) printf("\niozone test complete.\n");
03127     if(res_prob)
03128     {
03129         printf("Timer resolution is poor. Some small transfers may have \n");
03130         printf("reported inaccurate results. Sizes %ld Kbytes and below.\n",
03131             (long)(rec_prob/(long long)1024));
03132     }
03133 
03134     if(Rflag && !trflag){
03135         dump_excel();
03136     }
03137     return(0);  
03138 }
03139 
03140 #ifdef HAVE_ANSIC_C
03141 void
03142 record_command_line(int argc, char **argv)
03143 #else
03144 void
03145 record_command_line(argc, argv)
03146 int argc;
03147 char **argv;
03148 #endif
03149 {
03150     int ix, len = 0;
03151 
03152     /* print and save the entire command line */
03153     if(!silent) printf("\tCommand line used:");
03154     for (ix=0; ix < argc; ix++) {
03155         if(!silent) printf(" %s", argv[ix]);
03156         if ((len + strlen(argv[ix])) < sizeof(command_line)) {
03157             strcat (command_line, argv[ix]);
03158             strcat (command_line, " ");
03159             len += strlen(argv[ix]) + 1;
03160         }
03161         else {
03162             printf ("Command line too long to save completely.\n");
03163             break;
03164         }
03165     }
03166     if(!silent) printf("\n");
03167 }
03168 
03169 /*************************************************************************/
03170 /* BEGIN()                               */
03171 /* This is the main work horse. It is called from main and from      */
03172 /* auto_test. The caller provides the size of file and the record length.*/
03173 /*************************************************************************/
03174 #ifdef HAVE_ANSIC_C
03175 void 
03176 begin(off64_t kilos64,long long reclength)
03177 #else
03178 void
03179 begin(kilos64,reclength)
03180 off64_t kilos64;
03181 long long reclength;
03182 #endif
03183 {
03184     long long num_tests,test_num,i,j;
03185     long long data1[MAXTESTS], data2[MAXTESTS];
03186     num_tests = sizeof(func)/sizeof(char *);
03187 #if defined(HAVE_PREAD) 
03188     if(!Eflag)
03189     {
03190 #if defined(HAVE_PREAD) && defined(HAVE_PREADV)
03191         num_tests -= 4;
03192 #else
03193         num_tests -= 2;
03194 #endif
03195         if(mmapflag || async_flag)
03196         {
03197             num_tests -= 2;
03198         }
03199     }
03200     else
03201     {
03202         if(mmapflag || async_flag)
03203 #if defined(HAVE_PREAD) && defined(HAVE_PREADV)
03204             num_tests -= 6;
03205 #else
03206             num_tests -= 4;
03207 #endif
03208     }
03209 #else
03210     if(mmapflag || async_flag)
03211     {
03212         num_tests -= 2;
03213     }
03214 #endif
03215 
03216     if(RWONLYflag) num_tests = 2;       /* kcollins 8-21-96*/
03217     sync();         /* just in case there were some dirty */
03218     sync();
03219     kilobytes64=kilos64;
03220     reclen=reclength;
03221     numrecs64 = (kilobytes64*1024)/reclen;
03222     store_value(kilobytes64);
03223     if(r_traj_flag || w_traj_flag)
03224         store_value((off64_t)0);
03225     else    
03226         store_value((off64_t)(reclen/1024));
03227 
03228 #ifdef NO_PRINT_LLD
03229     if(!silent) printf("%16ld",kilobytes64);
03230     if(r_traj_flag || w_traj_flag)
03231     {
03232         if(!silent) printf("%8ld",0);
03233     }
03234     else
03235     {
03236         if(!silent) printf("%8ld",reclen/1024);
03237     }
03238 #else
03239     if(!silent) printf("%16lld",kilobytes64);
03240     if(r_traj_flag || w_traj_flag)
03241     {
03242         if(!silent) printf("%8lld",(long long )0);
03243     }
03244     else
03245     {
03246         if(!silent) printf("%8lld",reclen/1024);
03247     }
03248 #endif
03249     if(include_tflag)
03250     {
03251         for(i=0;i<num_tests;i++)
03252         {
03253             if(include_mask & (long long)(1<<i))
03254                func[i](kilobytes64,reclen,&data1[i],&data2[i]);
03255             else
03256             {
03257                     if(!silent) printf("%s",test_output[i]); 
03258                 fflush(stdout);
03259                 for(j=0;j<test_soutput[i];j++)
03260                     store_value((off64_t)0);
03261             }
03262         }
03263     }
03264     else
03265     {
03266         for(test_num=0;test_num < num_tests;test_num++)
03267         {
03268             func[test_num](kilobytes64,reclen,&data1[test_num],&data2[test_num]);
03269         };
03270     }
03271     if(!silent) printf("\n");
03272     if(!OPS_flag && !include_tflag){            /* Report in ops/sec ? */
03273        if(data1[1]!=0 && data2[1] != 0)
03274        {   
03275         totaltime = data1[1] + data1[0];
03276         if (totaltime < TOOFAST) 
03277         {
03278             goodkilos = (TOOFAST/totaltime)*2*kilobytes64;
03279                 printf("\nThe test completed too quickly to give a good result\n");
03280                 printf("You will get a more precise measure of this machine's\n");
03281                 printf("performance by re-running iozone using the command:\n");
03282 #ifdef NO_PRINT_LLD
03283                 printf("\n\tiozone %ld ", goodkilos);
03284                 printf("\t(i.e., file size = %ld kilobytes64)\n", goodkilos);
03285 #else
03286                 printf("\n\tiozone %lld ", goodkilos);
03287                 printf("\t(i.e., file size = %lld kilobytes64)\n", goodkilos);
03288 #endif
03289         }
03290        } else {
03291             goodrecl = reclen/2;
03292             printf("\nI/O error during read.  Try again with the command:\n");
03293 #ifdef NO_PRINT_LLD
03294             printf("\n\tiozone %ld %ld ", kilobytes64,  goodrecl);
03295             printf("\t(i.e. record size = %ld bytes)\n",  goodrecl);
03296 #else
03297             printf("\n\tiozone %lld %lld ", kilobytes64,  goodrecl);
03298             printf("\t(i.e. record size = %lld bytes)\n",  goodrecl);
03299 #endif
03300        }
03301     }
03302     if (!no_unlink)
03303     {
03304         if(check_filename(filename))
03305               unlink(filename); /* delete the file */
03306     }
03307                     /*stop timer*/
03308     return ;
03309 }
03310 /******************************************************************
03311 
03312     SHOW_HELP -- show development help of this program
03313 
03314 ******************************************************************/
03315 #ifdef HAVE_ANSIC_C
03316 void show_help(void)
03317 #else
03318 void show_help()
03319 #endif
03320 {
03321         long long i;
03322         if(!silent) printf("iozone: help mode\n\n");
03323         for(i=0; strlen(help[i]); i++)
03324         {
03325         if(!silent) printf("%s\n", help[i]);
03326         }
03327 }
03328 /******************************************************************
03329 
03330     SIGNAL_HANDLER -- clean up if user interrupts the program
03331 
03332 ******************************************************************/
03333 #ifdef HAVE_ANSIC_C
03334 void signal_handler(void)
03335 #else
03336 void signal_handler()
03337 #endif
03338 {
03339     long long i;
03340     if(distributed)
03341     {
03342         if(master_iozone)
03343             cleanup_children();
03344     }
03345     if((long long)getpid()==myid)
03346     {
03347             if(!silent) printf("\niozone: interrupted\n\n");
03348 #ifndef VMS
03349         if (!no_unlink)
03350         {
03351            if(check_filename(filename))
03352                 unlink(filename);   /* delete the file */
03353         }
03354         for(i=1;i<num_child;i++)
03355         {
03356            if(check_filename(dummyfile[i]))
03357                 unlink(dummyfile[i]);   /* delete the file */
03358         }
03359         if (!no_unlink)
03360         {
03361            if(check_filename(dummyfile[0]))
03362                 unlink(dummyfile[0]);   /* delete the file */
03363         }
03364         
03365 #endif
03366         if(Rflag && !trflag){
03367             dump_excel();
03368         }
03369         if(Rflag && trflag){
03370             dump_throughput();
03371         }
03372 
03373             if(!silent) printf("exiting iozone\n\n");
03374         if(res_prob)
03375         {
03376             printf("Timer resolution is poor. Some small transfers may have \n");
03377             printf("reported inaccurate results. Sizes %ld Kbytes and below.\n",
03378                 (long)rec_prob/1024);
03379         }
03380         if(trflag && !use_thread)
03381            for(i=0;i<num_child;i++)
03382             kill((pid_t)childids[i],SIGTERM);
03383         if(r_traj_flag)
03384             fclose(r_traj_fd);
03385         if(w_traj_flag)
03386             fclose(w_traj_fd);
03387     }
03388     if(sp_msfd)
03389         close(sp_msfd);
03390     if(sp_mrfd)
03391         close(sp_mrfd);
03392         exit(0);
03393 }
03394 
03395 /****************************************************************/
03396 /*                              */
03397 /*   AUTO_TEST -- perform series of tests and tabulate results  */
03398 /*                              */
03399 /****************************************************************/
03400 #ifdef HAVE_ANSIC_C
03401 void 
03402 auto_test(void)
03403 #else
03404 void auto_test()
03405 #endif
03406 {
03407         off64_t kilosi;
03408     long long recszi,count1;
03409     long long mult;
03410     long long xx;
03411 
03412     /****************************************************************/
03413     /* Start with file size of 1 megabyte and repeat the test   */
03414     /* KILOBYTES_ITER_LIMIT                     */
03415     /* times.  Each time we run, the file size is doubled       */
03416     /****************************************************************/
03417 /*
03418         if(sflag) {
03419           min_file_size = kilobytes64;
03420           max_file_size = kilobytes64;
03421         }
03422         if(rflag) {
03423           min_rec_size = reclen;
03424           max_rec_size = reclen;
03425         }
03426 */
03427     if(gflag)
03428         max_file_size = maximum_file_size;
03429     if(nflag)
03430         min_file_size = minimum_file_size;
03431 
03432         if (min_rec_size > (long long)(min_file_size*1024)) {
03433 #ifdef NO_PRINT_LLD
03434             printf("Error: record length %ld is greater than filesize %ld KB\n ",
03435                                 min_rec_size,min_file_size);
03436 #else
03437             printf("Error: record length %lld is greater than filesize %lld KB\n ",
03438                                 min_rec_size,min_file_size);
03439 #endif
03440                 exit(23);
03441         }
03442 
03443     if(NOCROSSflag) xover = max_file_size;
03444 
03445     init_file_sizes(min_file_size, max_file_size);
03446     del_record_sizes();
03447     orig_min_rec_size=min_rec_size;
03448     orig_max_rec_size=max_rec_size;
03449     init_record_sizes(min_rec_size, max_rec_size);
03450 
03451         for(kilosi=get_next_file_size((off64_t)0); kilosi>0; kilosi=get_next_file_size(kilosi))
03452         {
03453     /****************************************************************/
03454     /* Start with record size of min_rec_size bytes and repeat the  */
03455     /* test, multiplying the record size by MULTIPLIER each time,   */
03456     /* until we reach max_rec_size.  At the CROSSOVER we stop doing */
03457     /* small buffers as it takes forever and becomes very       */
03458     /* un-interesting.                      */
03459     /****************************************************************/
03460              if(!rflag && !sflag && !yflag && !qflag)
03461                 if(kilosi > xover){
03462                     min_rec_size = LARGE_REC;
03463             mult = orig_min_rec_size/1024;
03464             del_record_sizes();
03465             init_record_sizes(min_rec_size, max_rec_size);
03466                 /************************************/
03467             /* Generate dummy entries in the    */
03468             /* Excel buffer for skipped         */
03469             /* record sizes          */
03470             /************************************/
03471             for(count1=min_rec_size;
03472                     (count1 != orig_min_rec_size) && (
03473                         mult <= (kilosi*1024)) ;
03474                         count1=(count1>>1))
03475             {
03476                     current_x=0;
03477                     store_value((off64_t)kilosi);
03478                     store_value((off64_t)mult);
03479                     for(xx=0;xx<20;xx++)
03480                         store_value((off64_t)0);
03481                     mult=mult*2;
03482                     current_y++;
03483                     if(current_y>max_y)
03484                         max_y=current_y;
03485                     current_x=0;
03486             }
03487          }
03488 
03489              for (recszi=get_next_record_size((off64_t)0);recszi!=0;recszi=get_next_record_size(recszi))
03490              {
03491                      if(recszi > (kilosi*1024)) 
03492             break;
03493                      begin(kilosi, recszi );
03494              current_x=0;
03495              current_y++;
03496              }
03497     }
03498 }
03499 
03500 
03501 /****************************************************************/
03502 /*                              */
03503 /* THROUGHPUT_TEST () Multi process throughput test     */
03504 /*                              */
03505 /* Note: States for share memory barrier are:           */
03506 /* 0 = Child not running or has finished.           */
03507 /* 1 = Child is ready to begin.                 */
03508 /* 2 = Child is told to begin.                  */
03509 /****************************************************************/
03510 /* Data in shared memory format is:             */
03511 /*                              */
03512 /* struct child_stats {                     */
03513 /*  long long flag;     Used to barrier         */
03514 /*  double walltime;    Child's elapsed time        */
03515 /*  double cputime;     Child's CPU time        */
03516 /*  double throughput;  Child's throughput      */
03517 /*  double actual;      Child's actual read/written */
03518 /* }                                */
03519 /*                              */
03520 /* There is an array of child_stat structures layed out in  */
03521 /* shared memory.                       */
03522 /*                              */
03523 /****************************************************************/
03524 
03525 #ifdef HAVE_ANSIC_C
03526 void 
03527 throughput_test(void)
03528 #else
03529 void 
03530 throughput_test()
03531 #endif
03532 {
03533     char *unit;
03534     double starttime1 = 0;
03535     double jstarttime = 0;
03536     double jtime = 0;
03537     double walltime = 0;
03538     double cputime = 0;
03539     char *port;
03540     char getout;
03541     long long throughsize = KILOBYTES;
03542     long long xx,xy,i;
03543     long long xyz;
03544     double ptotal;
03545     off64_t written_so_far, read_so_far, re_written_so_far,re_read_so_far;
03546     VOLATILE char *temp;
03547     double min_throughput = 0;
03548     double max_throughput = 0;
03549     double avg_throughput = 0;
03550     double min_xfer = 0; 
03551 
03552 
03553     toutputindex=0;
03554     strcpy(&toutput[0][0],throughput_tests[0]);
03555     ptotal=written_so_far=read_so_far=re_written_so_far=re_read_so_far=0 ;
03556 
03557     if(OPS_flag)
03558         unit="ops";
03559     else
03560         unit="KB";
03561 
03562     if(!haveshm)
03563     {
03564         shmaddr=(struct child_stats *)alloc_mem((long long)SHMSIZE,(int)1);
03565 #ifdef _64BIT_ARCH_
03566         if((long long)shmaddr==(long long)-1)
03567 #else
03568         if((long )shmaddr==(long)-1)
03569 #endif
03570         {
03571             printf("\nShared memory not working\n");
03572             exit(24);
03573         }
03574         haveshm=(char*)shmaddr;
03575     }
03576     else
03577         shmaddr=(struct child_stats *)haveshm;
03578 
03579     if(use_thread)
03580         stop_flag = &stoptime;
03581     else
03582     {
03583         temp = (char *)&shmaddr[0];
03584         stop_flag = (char *)&temp[(long long)SHMSIZE]-4;
03585     }
03586     for(xyz=0;xyz<num_child;xyz++){ /* all children to state 0 (HOLD) */
03587         child_stat = (struct child_stats *)&shmaddr[xyz];
03588         child_stat->flag=CHILD_STATE_HOLD;
03589         child_stat->actual=0;
03590         child_stat->throughput=0;
03591         child_stat->cputime=0;
03592         child_stat->walltime=0;
03593     }
03594     *stop_flag = 0;
03595     if(!sflag)
03596         kilobytes64=throughsize;
03597     if(!rflag)
03598             reclen=(long long)4096;
03599     if(aggflag)
03600         kilobytes64=orig_size/num_child;
03601         numrecs64 = (long long)(kilobytes64*1024)/reclen;
03602     buffer=mainbuffer;
03603     if(use_thread)
03604         port="thread";
03605     else
03606         port="process";
03607     if(w_traj_flag)
03608     {
03609 #ifdef NO_PRINT_LLD
03610     if(!silent) printf("\tEach %s writes a %ld Kbyte file in telemetry controlled records\n",
03611         port,kilobytes64);
03612 #else
03613     if(!silent) printf("\tEach %s writes a %lld Kbyte file in telemetry controlled records\n",
03614         port,kilobytes64);
03615 #endif
03616     }
03617     else
03618     {
03619 #ifdef NO_PRINT_LLD
03620     if(!silent) printf("\tEach %s writes a %ld Kbyte file in %ld Kbyte records\n",
03621         port,kilobytes64,reclen/1024);
03622 #else
03623     if(!silent) printf("\tEach %s writes a %lld Kbyte file in %lld Kbyte records\n",
03624         port,kilobytes64,reclen/1024);
03625 #endif
03626     }
03627 
03628     if(fflag)       /* Each child has a file name to write */
03629       for(xx=0;xx<num_child;xx++)
03630         filearray[xx] = filename;
03631     myid = (long long)getpid();
03632 
03633     /* rags: skip writer test */
03634     if(include_tflag)
03635         if(!(include_mask & (long long)WRITER_MASK))
03636         {
03637             store_dvalue( (double)0);
03638             store_dvalue( (double)0);
03639             toutputindex++;
03640             goto next0;
03641         }
03642 
03643     if((!distributed) || (distributed && master_iozone))
03644         start_monitor("Write");
03645     /* Hooks to start the distributed Iozone client/server code */
03646     if(distributed)
03647     {
03648         use_thread=0;  /* Turn of any Posix threads */
03649         if(master_iozone)
03650             master_listen_socket = start_master_listen();
03651         else
03652             become_client();
03653     }
03654     if(!use_thread)
03655     {
03656        for(xx = 0; xx< num_child ; xx++){   /* Create the children */
03657         chid=xx;
03658         childids[xx] = start_child_proc(THREAD_WRITE_TEST,numrecs64,reclen);
03659         if(childids[xx]==-1){
03660             printf("\nFork failed\n");
03661             for(xy = 0; xy< xx ; xy++){
03662                 if(!use_thread)
03663                     kill((pid_t)childids[xy],SIGTERM);
03664             }
03665             exit(25);
03666         }
03667         if(childids[xx]!=0 && debug1)
03668 #ifdef NO_PRINT_LLD
03669             printf("Parent starting slot %ld\n",xx);    
03670 #else
03671             printf("Parent starting slot %lld\n",xx);   
03672 #endif
03673         if( childids[xx] == 0 ){
03674 #ifdef _64BIT_ARCH_
03675           thread_write_test((void *)xx);
03676 #else
03677           thread_write_test((void *)(long)xx);
03678 #endif
03679         }else {
03680 #ifdef NO_PRINT_LLD
03681           sprintf(dummyfile[xx],"%s.DUMMY.%ld",filearray[xx], xx);
03682 #else
03683           sprintf(dummyfile[xx],"%s.DUMMY.%lld",filearray[xx], xx);
03684 #endif
03685         }
03686        }
03687     }
03688 #ifndef NO_THREADS
03689     else
03690     {
03691        for(xx = 0; xx< num_child ; xx++){   /* Create the children */
03692 
03693 #ifdef NO_PRINT_LLD
03694         sprintf(dummyfile[xx],"%s.DUMMY.%ld",filearray[xx], xx);
03695 #else
03696         sprintf(dummyfile[xx],"%s.DUMMY.%lld",filearray[xx], xx);
03697 #endif
03698         if(!barray[xx])
03699         {
03700             barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
03701             if(barray[xx] == 0) {
03702                    perror("Memory allocation failed:");
03703                    exit(26);
03704                 }
03705                 barray[xx] =(char *)(((long)barray[xx] + cache_size ) & 
03706             ~(cache_size-1));
03707         }
03708 
03709 #ifdef _64BIT_ARCH_
03710         childids[xx] = mythread_create(thread_write_test,(void*)xx);
03711 #else
03712         childids[xx] = mythread_create(thread_write_test,(void*)(long)xx);
03713 #endif
03714         if(childids[xx]==-1){
03715             printf("Thread create failed\n");
03716             for(xy = 0; xy< xx ; xy++){
03717                 kill((pid_t)myid,SIGTERM);
03718             }
03719             exit(27);
03720         }
03721        }
03722     }
03723 #endif
03724     if((long long)getpid() == myid)
03725     {
03726         prepage(buffer,reclen);     /* Force copy on write */
03727                 /* wait for children to start */
03728         if(distributed && master_iozone)
03729         {
03730             start_master_listen_loop((int) num_child);
03731         }
03732         for(i=0;i<num_child; i++){
03733             child_stat = (struct child_stats *)&shmaddr[i]; 
03734             while(child_stat->flag==CHILD_STATE_HOLD)
03735                 Poll((long long)1);
03736         }
03737         for(i=0;i<num_child; i++)   /* Start all children going */
03738         {
03739             if(delay_start!=0)
03740                 Poll((long long)delay_start);
03741                         /* State "go" */
03742             child_stat = (struct child_stats *)&shmaddr[i]; 
03743             child_stat->flag=CHILD_STATE_BEGIN;
03744             if(distributed && master_iozone)
03745                 tell_children_begin(i);
03746         }
03747         starttime1 = time_so_far(); /* Start parents timer */
03748         goto waitout;
03749     }
03750 
03751 waitout:
03752     getout=0;
03753     if((long long)getpid() == myid) {   /* Parent only */
03754         starttime1 = time_so_far(); /* Wait for all children */
03755         for( i = 0; i < num_child; i++){
03756             child_stat = (struct child_stats *) &shmaddr[i];
03757             if(distributed && master_iozone)
03758             {
03759                 printf("\n\tTest running:");
03760                 wait_dist_join();
03761                 break;
03762             }
03763             else
03764             {
03765              if(use_thread)
03766              {
03767                 thread_join(childids[i],(void *)&pstatus);
03768              }
03769              else
03770              {
03771                 wait(0);
03772              }
03773             }
03774             if(!jstarttime)
03775                 jstarttime = time_so_far(); 
03776         }
03777         jtime = (time_so_far()-jstarttime)-time_res;
03778         if(jtime < (double).000001) 
03779         {
03780             jtime=time_res; 
03781         }
03782     }
03783     total_time = (time_so_far() - starttime1)-time_res; /* get parents total time */
03784     if(total_time < (double).000001) 
03785     {
03786         total_time=time_res; 
03787         if(rec_prob < reclen)
03788             rec_prob = reclen;
03789         res_prob=1;
03790     }
03791 #ifdef JTIME
03792     total_time=total_time-jtime;/* Remove the join time */
03793     if(!silent) printf("\nJoin time %10.2f\n",jtime);
03794 #endif
03795 
03796     total_kilos=0;
03797     ptotal=0;
03798     walltime = 0.0;
03799     cputime = 0.0;
03800     if(!silent) printf("\n");
03801     for(xyz=0;xyz<num_child;xyz++){
03802         child_stat = (struct child_stats *) &shmaddr[xyz];
03803         total_kilos += child_stat->throughput; /* add up the children */
03804         ptotal += child_stat->actual;
03805         if(!min_xfer)
03806             min_xfer=child_stat->actual;
03807         if(child_stat->actual < min_xfer)
03808             min_xfer=child_stat->actual;
03809         if(!min_throughput)
03810             min_throughput=child_stat->throughput;
03811         if(child_stat->throughput < min_throughput)
03812             min_throughput=child_stat->throughput;
03813         if(child_stat->throughput > max_throughput)
03814             max_throughput=child_stat->throughput;
03815         /* Add up the cpu times of all children */
03816         cputime += child_stat->cputime;
03817 
03818         /* and find the child with the longest wall time */
03819         /* Get the earliest start time and latest fini time to calc. elapsed time. */
03820         if (child_stat->walltime < child_stat->cputime)
03821             child_stat->walltime = child_stat->cputime;
03822         if (child_stat->walltime > walltime)
03823             walltime = child_stat->walltime;
03824     }
03825     avg_throughput=total_kilos/num_child;
03826     if(cpuutilflag)
03827     {
03828         if (cputime < cputime_res)
03829             cputime = 0.0;
03830     }
03831     
03832     for(xyz=0;xyz<num_child;xyz++){
03833         child_stat = (struct child_stats *) &shmaddr[xyz];
03834         child_stat->flag = CHILD_STATE_HOLD; /* Start children at state 0 (HOLD) */
03835     }
03836     if(cpuutilflag)
03837         store_times (walltime, cputime);    /* Must be Before store_dvalue(). */
03838     store_dvalue(total_kilos);
03839 #ifdef NO_PRINT_LLD
03840     if(!silent) printf("\tChildren see throughput for %2ld initial writers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
03841     if(!silent && !distributed) printf("\tParent sees throughput for %2ld initial writers \t= %10.2f %s/sec\n",num_child,((double)(ptotal)/total_time),unit);
03842 #else
03843     if(!silent) printf("\tChildren see throughput for %2lld initial writers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
03844     if(!silent && !distributed) printf("\tParent sees throughput for %2lld initial writers \t= %10.2f %s/sec\n",num_child,((double)(ptotal)/total_time),unit);
03845 #endif
03846     if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
03847     if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
03848     if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
03849     if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
03850     /* CPU% can be > 100.0 for multiple CPUs */
03851     if(cpuutilflag)
03852     {
03853         if(walltime == 0.0)
03854         {
03855             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
03856                 walltime, cputime, 0.0);
03857         }
03858         else
03859         {
03860             if(!silent) printf("\tCPU Utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
03861                 walltime, cputime, 100.0 * cputime / walltime);
03862         }
03863     }
03864     if(Cflag)
03865     {
03866         for(xyz=0;xyz<num_child;xyz++)
03867         {
03868             child_stat = (struct child_stats *) &shmaddr[xyz];
03869             if(cpuutilflag)
03870             {
03871                 if(!silent) 
03872                     printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
03873                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime, 
03874                     child_stat->cputime, cpu_util(child_stat->cputime, child_stat->walltime));
03875             }
03876             else
03877             {
03878                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
03879                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
03880             }
03881         }
03882     }
03883     if((!distributed) || (distributed && master_iozone))
03884         stop_monitor("Write");
03885     /**********************************************************/
03886     /*************** End of intitial writer *******************/
03887     /**********************************************************/
03888     sync();
03889     sleep(2);
03890     if(restf)
03891         sleep((int)rest_val);
03892     *stop_flag=0;
03893     if(distributed && master_iozone)
03894     {
03895         stop_master_listen(master_listen_socket);
03896         cleanup_comm();
03897     }
03898 
03899     /**********************************************************/
03900     /* Re-write throughput performance test. ******************/
03901     /**********************************************************/
03902     walltime = 0.0;
03903     cputime = 0.0;
03904     jstarttime=0;
03905     total_kilos=0;
03906     toutputindex=1;
03907     strcpy(&toutput[1][0],throughput_tests[1]);
03908     if(noretest)
03909     {
03910         store_dvalue( (double)0);
03911         goto next0;
03912     }
03913     if((!distributed) || (distributed && master_iozone))
03914         start_monitor("Rewrite");
03915     /* Hooks to start the distributed Iozone client/server code */
03916     if(distributed)
03917     {
03918         use_thread=0;  /* Turn of any Posix threads */
03919         if(master_iozone)
03920             master_listen_socket = start_master_listen();
03921         else
03922             become_client();
03923     }
03924     if(!use_thread)
03925     {
03926        for(xx = 0; xx< num_child ; xx++){
03927         chid=xx;
03928         childids[xx] = start_child_proc(THREAD_REWRITE_TEST,numrecs64,reclen);
03929         if(childids[xx]==-1){
03930             printf("\nFork failed\n");
03931             for(xy = 0; xy< xx ; xy++){
03932                 Kill((long long)childids[xy],(long long)SIGTERM);
03933             }
03934             exit(28);
03935         }
03936         if(childids[xx] == 0){
03937 #ifdef _64BIT_ARCH_
03938             thread_rwrite_test((void *)xx);
03939 #else
03940             thread_rwrite_test((void *)((long)xx));
03941 #endif
03942         }   
03943        }
03944     }
03945 #ifndef NO_THREADS
03946     else
03947     {
03948        for(xx = 0; xx< num_child ; xx++){   /* Create the children */
03949         if(!barray[xx])
03950         {
03951             barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
03952             if(barray[xx] == 0) {
03953                    perror("Memory allocation failed:");
03954                    exit(26);
03955                 }
03956                 barray[xx] =(char *)(((long)barray[xx] + cache_size ) & 
03957             ~(cache_size-1));
03958         }
03959 #ifdef _64BIT_ARCH_
03960         childids[xx] = mythread_create( thread_rwrite_test,xx);
03961 #else
03962         childids[xx] = mythread_create( thread_rwrite_test,(void *)(long)xx);
03963 #endif
03964         if(childids[xx]==-1){
03965             printf("\nThread create failed\n");
03966             for(xy = 0; xy< xx ; xy++){
03967                 Kill((long long)myid,(long long)SIGTERM);
03968             }
03969             exit(29);
03970         }
03971        }
03972     }
03973 #endif
03974     if((long long)myid == getpid())
03975     {
03976         if(distributed && master_iozone)
03977         {
03978             start_master_listen_loop((int) num_child);
03979         }
03980         for(i=0;i<num_child; i++){
03981             child_stat = (struct child_stats *)&shmaddr[i];
03982                     /* wait for children to start */
03983             while(child_stat->flag==CHILD_STATE_HOLD) 
03984                 Poll((long long)1);
03985         }
03986         for(i=0;i<num_child; i++)
03987         {
03988             child_stat = (struct child_stats *)&shmaddr[i];
03989             child_stat->flag = CHILD_STATE_BEGIN;   /* tell children to go */
03990             if(delay_start!=0)
03991                 Poll((long long)delay_start);
03992             if(distributed && master_iozone)
03993                 tell_children_begin(i);
03994         }
03995         starttime1 = time_so_far();
03996         goto jump3;
03997     }
03998     
03999 jump3:
04000     getout=0;
04001     if((long long)myid == getpid()){    /* Parent only here */
04002         for( i = 0; i < num_child; i++){
04003             child_stat=(struct child_stats *)&shmaddr[i];
04004             if(distributed && master_iozone)
04005             {
04006                 printf("\n\tTest running:");
04007                 wait_dist_join();
04008                 break;
04009             }
04010             else
04011             {
04012                if(use_thread)
04013                {
04014                 thread_join(childids[i],(void *)&pstatus);
04015                }
04016                else
04017                {
04018                 wait(0);
04019                }
04020             }
04021             if(!jstarttime)
04022                 jstarttime = time_so_far(); 
04023         }
04024         jtime = (time_so_far()-jstarttime)-time_res;
04025         if(jtime < (double).000001) 
04026         {
04027             jtime=time_res;
04028         }
04029     }
04030     total_time = (time_so_far() - starttime1)-time_res; /* Parents total time */
04031     if(total_time  < (double).000001) 
04032     {
04033         total_time=time_res;
04034         if(rec_prob < reclen)
04035             rec_prob = reclen;
04036         res_prob=1;
04037     }
04038 #ifdef JTIME
04039     total_time=total_time-jtime;/* Remove the join time */
04040     if(!silent) printf("\nJoin time %10.2f\n",jtime);
04041 #endif
04042     
04043 
04044     total_kilos=0;
04045     ptotal=0;
04046 
04047     min_throughput=max_throughput=min_xfer=0;
04048     if(!silent) printf("\n");
04049     for(xyz=0;xyz<num_child;xyz++){
04050         child_stat=(struct child_stats *)&shmaddr[xyz];
04051         total_kilos+=child_stat->throughput;
04052         ptotal+=child_stat->actual;
04053         if(!min_xfer)
04054             min_xfer=child_stat->actual;
04055         if(child_stat->actual < min_xfer)
04056             min_xfer=child_stat->actual;
04057         if(!min_throughput)
04058             min_throughput=child_stat->throughput;
04059         if(child_stat->throughput < min_throughput)
04060             min_throughput=child_stat->throughput;
04061         if(child_stat->throughput > max_throughput)
04062             max_throughput=child_stat->throughput;
04063         cputime += child_stat->cputime;
04064         /* Get the earliest start time and latest fini time to calc. elapsed time. */
04065         if (child_stat->walltime < child_stat->cputime)
04066             child_stat->walltime = child_stat->cputime;
04067         if (child_stat->walltime > walltime)
04068             walltime = child_stat->walltime;
04069     }
04070     avg_throughput=total_kilos/num_child;
04071     if(cpuutilflag)
04072     {
04073 /*
04074         if (walltime < cputime_res)
04075             walltime = 0.0;
04076 */
04077         if (cputime < cputime_res)
04078             cputime = 0.0;
04079     }
04080 
04081     for(xyz=0;xyz<num_child;xyz++){ /* Reset state to 0 (HOLD) */
04082         child_stat=(struct child_stats *)&shmaddr[xyz];
04083         child_stat->flag = CHILD_STATE_HOLD;
04084     }
04085     if(cpuutilflag)
04086         store_times (walltime, cputime);    /* Must be Before store_dvalue(). */
04087     store_dvalue(total_kilos);
04088 #ifdef NO_PRINT_LLD
04089     if(!silent) printf("\tChildren see throughput for %2ld rewriters \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
04090     if(!silent && !distributed) printf("\tParent sees throughput for %2ld rewriters \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
04091 #else
04092     if(!silent) printf("\tChildren see throughput for %2lld rewriters \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
04093     if(!silent && !distributed) printf("\tParent sees throughput for %2lld rewriters \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
04094 #endif
04095     if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
04096     if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
04097     if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
04098     if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
04099     /* CPU% can be > 100.0 for multiple CPUs */
04100     if(cpuutilflag)
04101     {
04102         if(walltime == 0.0)
04103         {
04104             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
04105                 walltime, cputime, 0.0);
04106         }
04107         else
04108         {
04109             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
04110                 walltime, cputime, 100.0 * cputime / walltime);
04111         }
04112     }
04113     if(Cflag)
04114     {
04115         for(xyz=0;xyz<num_child;xyz++)
04116         {
04117             child_stat = (struct child_stats *) &shmaddr[xyz];
04118             if(cpuutilflag)
04119             {
04120                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
04121                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime, 
04122                     child_stat->cputime, cpu_util(child_stat->cputime, child_stat->walltime));
04123             }
04124             else
04125             {
04126                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
04127                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
04128             }
04129         }
04130     }
04131     *stop_flag=0;
04132     if((!distributed) || (distributed && master_iozone))
04133         stop_monitor("Rewrite");
04134     /**********************************************************/
04135     /*************** End of rewrite throughput ****************/
04136     /**********************************************************/
04137     sync();
04138     sleep(2);
04139     if(restf)
04140         sleep((int)rest_val);
04141     if(distributed && master_iozone)
04142     {
04143         stop_master_listen(master_listen_socket);
04144         cleanup_comm();
04145     }
04146 next0:
04147     if(include_tflag)
04148         if(!(include_mask & (long long)READER_MASK))
04149             goto next1;
04150     /**************************************************************/
04151     /*** Reader throughput tests **********************************/
04152     /**************************************************************/
04153     if((!distributed) || (distributed && master_iozone))
04154         start_monitor("Read");
04155     toutputindex++;
04156     strcpy(&toutput[toutputindex][0],throughput_tests[2]);
04157     walltime = 0.0;
04158     cputime = 0.0;
04159     jstarttime=0;
04160     total_kilos=0;
04161     if(distributed)
04162     {
04163         use_thread=0;
04164         if(master_iozone)
04165             master_listen_socket=start_master_listen();
04166         else
04167             become_client();
04168     }
04169     if(!use_thread)
04170     {
04171        for(xx = 0; xx< num_child ; xx++){
04172         chid=xx;
04173         childids[xx] = start_child_proc(THREAD_READ_TEST,numrecs64,reclen);
04174         if(childids[xx]==-1){
04175             printf("\nFork failed\n");
04176             for(xy = 0; xy< xx ; xy++){
04177                 Kill((long long)childids[xy],(long long)SIGTERM);
04178             }
04179             exit(30);
04180         }
04181         if(childids[xx]==0){
04182 #ifdef _64BIT_ARCH_
04183             thread_read_test((void *)xx);
04184 #else
04185             thread_read_test((void *)((long)xx));
04186 #endif
04187         }   
04188        }
04189     }
04190 #ifndef NO_THREADS
04191     else
04192     {
04193        for(xx = 0; xx< num_child ; xx++){   /* Create the children */
04194         if(!barray[xx])
04195         {
04196             barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
04197             if(barray[xx] == 0) {
04198                    perror("Memory allocation failed:");
04199                    exit(26);
04200                 }
04201                 barray[xx] =(char *)(((long)barray[xx] + cache_size ) & 
04202             ~(cache_size-1));
04203         }
04204 #ifdef _64BIT_ARCH_
04205         childids[xx] = mythread_create( thread_read_test,xx);
04206 #else
04207         childids[xx] = mythread_create( thread_read_test,(void *)(long)xx);
04208 #endif
04209         if(childids[xx]==-1){
04210             printf("\nThread create failed\n");
04211             for(xy = 0; xy< xx ; xy++){
04212                 kill((pid_t)myid,(int)SIGTERM);
04213             }
04214             exit(31);
04215         }
04216        }
04217     }
04218 #endif
04219     if(myid == (long long)getpid()){
04220         if(distributed && master_iozone)
04221         {
04222             start_master_listen_loop((int) num_child);
04223         }
04224         for(i=0;i<num_child; i++){ /* wait for children to start */
04225             child_stat=(struct child_stats *)&shmaddr[i];
04226             while(child_stat->flag==CHILD_STATE_HOLD)
04227                 Poll((long long)1);
04228         }
04229         for(i=0;i<num_child; i++)
04230         {
04231             child_stat=(struct child_stats *)&shmaddr[i];
04232             child_stat->flag = CHILD_STATE_BEGIN; /* tell children to go */
04233             if(delay_start!=0)
04234                 Poll((long long)delay_start);
04235             if(distributed && master_iozone)
04236                 tell_children_begin(i);
04237         }
04238         starttime1 = time_so_far();
04239         goto jumpend4;
04240     }
04241 jumpend4:
04242     getout=0;
04243     if(myid == (long long)getpid()){    /* Parent here */
04244         for( i = 0; i < num_child; i++){
04245             child_stat = (struct child_stats *)&shmaddr[i];
04246             if(distributed && master_iozone)
04247             {
04248                 printf("\n\tTest running:");
04249                 wait_dist_join();
04250                 break;
04251             }
04252             else
04253             {
04254                if(use_thread)
04255                {
04256                 thread_join(childids[i],(void *)&pstatus);
04257                }
04258                else
04259                {
04260                 wait(0);
04261                }
04262             }
04263             if(!jstarttime)
04264                 jstarttime = time_so_far(); 
04265         }
04266         jtime = (time_so_far()-jstarttime)-time_res; 
04267         if(jtime < (double).000001)
04268         {
04269             jtime=time_res; 
04270         }
04271     }
04272     total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
04273     if(total_time < (double).000001) 
04274     {
04275         total_time=time_res; 
04276         if(rec_prob < reclen)
04277             rec_prob = reclen;
04278         res_prob=1;
04279     }
04280 #ifdef JTIME
04281     total_time=total_time-jtime;/* Remove the join time */
04282     if(!silent) printf("\nJoin time %10.2f\n",jtime);
04283 #endif
04284     
04285     total_kilos=0;
04286     ptotal=0;
04287     min_throughput=max_throughput=min_xfer=0;
04288     if(!silent) printf("\n");
04289     for(xyz=0;xyz<num_child;xyz++){
04290         child_stat=(struct child_stats *)&shmaddr[xyz];
04291         total_kilos+=child_stat->throughput;
04292         ptotal+=child_stat->actual;
04293         if(!min_xfer)
04294             min_xfer=child_stat->actual;
04295         if(child_stat->actual < min_xfer)
04296             min_xfer=child_stat->actual;
04297         if(!min_throughput)
04298             min_throughput=child_stat->throughput;
04299         if(child_stat->throughput < min_throughput)
04300             min_throughput=child_stat->throughput;
04301         if(child_stat->throughput > max_throughput)
04302             max_throughput=child_stat->throughput;
04303         cputime += child_stat->cputime;
04304         /* Get the earliest start time and latest fini time to calc. elapsed time. */
04305         if (child_stat->walltime < child_stat->cputime)
04306             child_stat->walltime = child_stat->cputime;
04307         if (child_stat->walltime > walltime)
04308             walltime = child_stat->walltime;
04309     }
04310     avg_throughput=total_kilos/num_child;
04311     if(cpuutilflag)
04312     {
04313         if (cputime < cputime_res)
04314             cputime = 0.0;
04315     }
04316     if(cpuutilflag)
04317         store_times (walltime, cputime);    /* Must be Before store_dvalue(). */
04318     store_dvalue(total_kilos);
04319 #ifdef NO_PRINT_LLD
04320     if(!silent) printf("\tChildren see throughput for %2ld readers \t\t= %10.2f %s/sec\n", num_child, total_kilos,unit);
04321     if(!silent && !distributed) printf("\tParent sees throughput for %2ld readers \t\t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
04322 #else
04323     if(!silent) printf("\tChildren see throughput for %2lld readers \t\t= %10.2f %s/sec\n", num_child, total_kilos,unit);
04324     if(!silent && !distributed) printf("\tParent sees throughput for %2lld readers \t\t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
04325 #endif
04326     if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
04327     if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
04328     if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
04329     if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
04330     /* CPU% can be > 100.0 for multiple CPUs */
04331     if(cpuutilflag)
04332     {
04333         if(walltime == 0.0)
04334         {
04335             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
04336                 walltime, cputime, 0.0);
04337         }
04338         else
04339         {
04340             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
04341                 walltime, cputime, 100.0 * cputime / walltime);
04342         }
04343     }
04344     if(Cflag)
04345     {
04346         for(xyz=0;xyz<num_child;xyz++)
04347         {
04348             child_stat = (struct child_stats *) &shmaddr[xyz];
04349             if(cpuutilflag)
04350             {
04351                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
04352                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime, 
04353                     child_stat->cputime, cpu_util(child_stat->cputime, child_stat->walltime));
04354             }
04355             else
04356             {
04357                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
04358                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
04359             }
04360         }
04361     }
04362     if((!distributed) || (distributed && master_iozone))
04363         stop_monitor("Read");
04364     /**********************************************************/
04365     /*************** End of readers throughput ****************/
04366     /**********************************************************/
04367     sync();
04368     sleep(2);
04369     if(restf)
04370         sleep((int)rest_val);
04371     if(distributed && master_iozone)
04372     {
04373         stop_master_listen(master_listen_socket);
04374         cleanup_comm();
04375     }
04376 
04377     /**************************************************************/
04378     /*** ReReader throughput tests **********************************/
04379     /**************************************************************/
04380     toutputindex++;
04381     strcpy(&toutput[toutputindex][0],throughput_tests[3]);
04382     if(noretest)
04383     {
04384         store_dvalue( (double)0);
04385         goto next1;
04386     }
04387     if((!distributed) || (distributed && master_iozone))
04388         start_monitor("Reread");
04389     walltime = 0.0;
04390     cputime = 0.0;
04391     jstarttime=0;
04392     *stop_flag=0;
04393     total_kilos=0;
04394         /* Hooks to start the distributed Iozone client/server code */
04395         if(distributed)
04396         {
04397                 use_thread=0;  /* Turn of any Posix threads */
04398                 if(master_iozone)
04399                         master_listen_socket = start_master_listen();
04400                 else
04401                         become_client();
04402         }
04403     if(!use_thread)
04404     {
04405        for(xx = 0; xx< num_child ; xx++){
04406         chid=xx;
04407         childids[xx] = start_child_proc(THREAD_REREAD_TEST, numrecs64,reclen);
04408         if(childids[xx]==-1){
04409             printf("\nFork failed\n");
04410             for(xy = 0; xy< xx ; xy++){
04411                 Kill((long long)childids[xy],(long long)SIGTERM);
04412             }
04413             exit(32);
04414         }
04415         if(childids[xx]==0){
04416 #ifdef _64BIT_ARCH_
04417             thread_rread_test((void *)xx);
04418 #else
04419             thread_rread_test((void *)((long)xx));
04420 #endif
04421         }   
04422        }
04423     }
04424 #ifndef NO_THREADS
04425     else
04426     {
04427        for(xx = 0; xx< num_child ; xx++){   /* Create the children */
04428         chid=xx;
04429         if(!barray[xx])
04430         {
04431             barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
04432             if(barray[xx] == 0) {
04433                    perror("Memory allocation failed:");
04434                    exit(26);
04435                 }
04436                 barray[xx] =(char *)(((long)barray[xx] + cache_size ) & 
04437             ~(cache_size-1));
04438         }
04439 #ifdef _64BIT_ARCH_
04440         childids[xx] = mythread_create( thread_rread_test,xx);
04441 #else
04442         childids[xx] = mythread_create( thread_rread_test,(void *)(long)xx);
04443 #endif
04444         if(childids[xx]==-1){
04445             printf("\nThread create failed\n");
04446             for(xy = 0; xy< xx ; xy++){
04447                 kill((pid_t)myid,(int)SIGTERM);
04448             }
04449             exit(33);
04450         }
04451        }
04452     }
04453 #endif
04454     if(myid == (long long)getpid()){
04455                 if(distributed && master_iozone)
04456                 {
04457                         start_master_listen_loop((int) num_child);
04458                 }
04459         for(i=0;i<num_child; i++){ /* wait for children to start */
04460             child_stat = (struct child_stats *)&shmaddr[i];
04461             while(child_stat->flag==CHILD_STATE_HOLD)
04462                 Poll((long long)1);
04463         }
04464         for(i=0;i<num_child; i++){
04465             child_stat = (struct child_stats *)&shmaddr[i];
04466             child_stat->flag = CHILD_STATE_BEGIN;   /* tell children to go */
04467             if(delay_start!=0)
04468                 Poll((long long)delay_start);
04469                        if(distributed && master_iozone)
04470                                 tell_children_begin(i);
04471         }
04472         starttime1 = time_so_far();
04473         goto jumpend2;
04474     }
04475     
04476 jumpend2:
04477     getout=0;
04478     if(myid == (long long)getpid()){     /* Parent here */
04479         for( i = 0; i < num_child; i++){ /* wait for children to stop */
04480             child_stat = (struct child_stats *)&shmaddr[i];
04481                         if(distributed && master_iozone)
04482                         {
04483                 printf("\n\tTest running:");
04484                                 wait_dist_join();
04485                                 break;
04486                         }
04487                         else
04488                         {
04489                if(use_thread)
04490                {
04491                 thread_join(childids[i],(void *)&pstatus);
04492                }
04493                else
04494                {
04495                 wait(0);
04496                }
04497             }
04498             if(!jstarttime)
04499                 jstarttime = time_so_far(); 
04500         }
04501         jtime = (time_so_far()-jstarttime)-time_res; 
04502         if(jtime < (double).000001)
04503         {
04504             jtime=time_res;
04505         }
04506     }
04507     total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
04508     if(total_time < (double).000001) 
04509     {
04510         total_time=time_res;
04511         if(rec_prob < reclen)
04512             rec_prob = reclen;
04513         res_prob=1;
04514     }
04515 #ifdef JTIME
04516     total_time=total_time-jtime;/* Remove the join time */
04517     if(!silent) printf("\nJoin time %10.2f\n",jtime);
04518 #endif
04519     min_throughput=max_throughput=min_xfer=0;
04520     total_kilos=0;
04521     ptotal=0;
04522     if(!silent) printf("\n");
04523     for(xyz=0;xyz<num_child;xyz++){
04524         child_stat = (struct child_stats *)&shmaddr[xyz];
04525         total_kilos+=child_stat->throughput;
04526         ptotal+=child_stat->actual;
04527         if(!min_xfer)
04528             min_xfer=child_stat->actual;
04529         if(child_stat->actual < min_xfer)
04530             min_xfer=child_stat->actual;
04531         if(!min_throughput)
04532             min_throughput=child_stat->throughput;
04533         if(child_stat->throughput < min_throughput)
04534             min_throughput=child_stat->throughput;
04535         if(child_stat->throughput > max_throughput)
04536             max_throughput=child_stat->throughput;
04537         cputime += child_stat->cputime;
04538         /* Get the earliest start time and latest fini time to calc. elapsed time. */
04539         if (child_stat->walltime < child_stat->cputime)
04540             child_stat->walltime = child_stat->cputime;
04541         if (child_stat->walltime > walltime)
04542             walltime = child_stat->walltime;
04543     }
04544     avg_throughput=total_kilos/num_child;
04545     if(cpuutilflag)
04546     {
04547 /*
04548         if (walltime < cputime_res)
04549             walltime = 0.0;
04550 */
04551         if (cputime < cputime_res)
04552             cputime = 0.0;
04553     }
04554     if(cpuutilflag)
04555         store_times (walltime, cputime);    /* Must be Before store_dvalue(). */
04556     store_dvalue(total_kilos);
04557 #ifdef NO_PRINT_LLD
04558     if(!silent) printf("\tChildren see throughput for %ld re-readers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
04559     if(!silent && !distributed) printf("\tParent sees throughput for %ld re-readers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
04560 #else
04561     if(!silent) printf("\tChildren see throughput for %lld re-readers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
04562     if(!silent && !distributed) printf("\tParent sees throughput for %lld re-readers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
04563 #endif
04564     if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
04565     if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
04566     if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
04567     if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
04568     /* CPU% can be > 100.0 for multiple CPUs */
04569     if(cpuutilflag)
04570     {
04571         if(walltime == 0.0)
04572         {
04573             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
04574                 walltime, cputime, 0.0);
04575         }
04576         else
04577         {
04578             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
04579                 walltime, cputime, 100.0 * cputime / walltime);
04580         }
04581     }
04582     if(Cflag)
04583     {
04584         for(xyz=0;xyz<num_child;xyz++)
04585         {
04586             child_stat = (struct child_stats *) &shmaddr[xyz];
04587             if(cpuutilflag)
04588             {
04589                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
04590                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime, 
04591                     child_stat->cputime, cpu_util(child_stat->cputime, child_stat->walltime));
04592             }
04593             else
04594             {
04595                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
04596                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
04597             }
04598         }
04599     }
04600     if((!distributed) || (distributed && master_iozone))
04601         stop_monitor("Reread");
04602     /**********************************************************/
04603     /*************** End of re-readers throughput ****************/
04604     /**********************************************************/
04605     sync();
04606     sleep(2);
04607     if(restf)
04608         sleep((int)rest_val);
04609         if(distributed && master_iozone)
04610     {
04611                 stop_master_listen(master_listen_socket);
04612         cleanup_comm();
04613     }
04614 
04615 next1:
04616     if(include_tflag)
04617         if(!(include_mask & (long long)REVERSE_MASK))
04618             goto next2;
04619     sync();
04620     sleep(2);
04621 
04622     /**************************************************************/
04623     /*** Reverse reader throughput tests **************************/
04624     /**************************************************************/
04625     toutputindex++;
04626     strcpy(&toutput[toutputindex][0],throughput_tests[4]);
04627     if((!distributed) || (distributed && master_iozone))
04628         start_monitor("Revread");
04629     walltime = 0.0;
04630     cputime = 0.0;
04631     jstarttime=0;
04632     *stop_flag=0;
04633     total_kilos=0;
04634         /* Hooks to start the distributed Iozone client/server code */
04635         if(distributed)
04636         {
04637                 use_thread=0;  /* Turn of any Posix threads */
04638                 if(master_iozone)
04639                         master_listen_socket = start_master_listen();
04640                 else
04641                         become_client();
04642         }
04643     if(!use_thread)
04644     {
04645        for(xx = 0; xx< num_child ; xx++){
04646         chid=xx;
04647         childids[xx] = start_child_proc(THREAD_REVERSE_READ_TEST,numrecs64,reclen);
04648         if(childids[xx]==-1){
04649             printf("\nFork failed\n");
04650             for(xy = 0; xy< xx ; xy++){
04651                 Kill((long long)childids[xy],(long long)SIGTERM);
04652             }
04653             exit(34);
04654         }
04655         if(childids[xx]==0){
04656 #ifdef _64BIT_ARCH_
04657             thread_reverse_read_test((void *)xx);
04658 #else
04659             thread_reverse_read_test((void *)((long)xx));
04660 #endif
04661         }   
04662        }
04663     }
04664 #ifndef NO_THREADS
04665     else
04666     {
04667        for(xx = 0; xx< num_child ; xx++){   /* Create the children */
04668         chid=xx;
04669         if(!barray[xx])
04670         {
04671             barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
04672             if(barray[xx] == 0) {
04673                    perror("Memory allocation failed:");
04674                    exit(26);
04675                 }
04676                 barray[xx] =(char *)(((long)barray[xx] + cache_size ) & 
04677             ~(cache_size-1));
04678         }
04679 #ifdef _64BIT_ARCH_
04680         childids[xx] = mythread_create( thread_reverse_read_test,xx);
04681 #else
04682         childids[xx] = mythread_create( thread_reverse_read_test,(void *)(long)xx);
04683 #endif
04684         if(childids[xx]==-1){
04685             printf("\nThread create failed\n");
04686             for(xy = 0; xy< xx ; xy++){
04687                 kill((pid_t)myid,(int)SIGTERM);
04688             }
04689             exit(35);
04690         }
04691        }
04692     }
04693 #endif
04694     if(myid == (long long)getpid()){
04695                 if(distributed && master_iozone)
04696                 {
04697                         start_master_listen_loop((int) num_child);
04698                 }
04699         for(i=0;i<num_child; i++){ /* wait for children to start */
04700             child_stat = (struct child_stats *)&shmaddr[i];
04701             while(child_stat->flag==CHILD_STATE_HOLD)
04702                 Poll((long long)1);
04703         }
04704         for(i=0;i<num_child; i++){
04705             child_stat = (struct child_stats *)&shmaddr[i];
04706             child_stat->flag = CHILD_STATE_BEGIN;   /* tell children to go */
04707             if(delay_start!=0)
04708                 Poll((long long)delay_start);
04709                        if(distributed && master_iozone)
04710                                 tell_children_begin(i);
04711         }
04712         starttime1 = time_so_far();
04713     }
04714     
04715     getout=0;
04716     if(myid == (long long)getpid()){     /* Parent here */
04717         for( i = 0; i < num_child; i++){ /* wait for children to stop */
04718             child_stat = (struct child_stats *)&shmaddr[i];
04719                         if(distributed && master_iozone)
04720                         {
04721                 printf("\n\tTest running:");
04722                                 wait_dist_join();
04723                                 break;
04724                         }
04725                         else
04726                         {
04727                            if(use_thread)
04728                            {
04729                                 thread_join(childids[i],(void *)&pstatus);
04730                            }
04731                            else
04732                            {
04733                                 wait(0);
04734                            }
04735                         }
04736             if(!jstarttime)
04737                 jstarttime = time_so_far(); 
04738         }
04739         jtime = (time_so_far()-jstarttime)-time_res;
04740         if(jtime < (double).000001)
04741         {
04742             jtime=time_res;
04743         }
04744     }
04745     total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
04746     if(total_time < (double).000001) 
04747     {
04748         total_time=time_res;
04749         if(rec_prob < reclen)
04750             rec_prob = reclen;
04751         res_prob=1;
04752     }
04753 #ifdef JTIME
04754     total_time=total_time-jtime;/* Remove the join time */
04755     if(!silent) printf("\nJoin time %10.2f\n",jtime);
04756 #endif
04757     total_kilos=0;
04758     ptotal=0;
04759     min_throughput=max_throughput=min_xfer=0;
04760     if(!silent) printf("\n");
04761     for(xyz=0;xyz<num_child;xyz++){
04762         child_stat = (struct child_stats *)&shmaddr[xyz];
04763         total_kilos+=child_stat->throughput;
04764         ptotal+=child_stat->actual;
04765         if(!min_xfer)
04766             min_xfer=child_stat->actual;
04767         if(child_stat->actual < min_xfer)
04768             min_xfer=child_stat->actual;
04769         if(!min_throughput)
04770             min_throughput=child_stat->throughput;
04771         if(child_stat->throughput < min_throughput)
04772             min_throughput=child_stat->throughput;
04773         if(child_stat->throughput > max_throughput)
04774             max_throughput=child_stat->throughput;
04775         /* walltime += child_stat->walltime; */
04776         cputime += child_stat->cputime;
04777         /* Get the earliest start time and latest fini time to calc. elapsed time. */
04778         if (child_stat->walltime < child_stat->cputime)
04779             child_stat->walltime = child_stat->cputime;
04780         if (child_stat->walltime > walltime)
04781             walltime = child_stat->walltime;
04782     }
04783     avg_throughput=total_kilos/num_child;
04784     if(cpuutilflag)
04785     {
04786 /*
04787         if (walltime < cputime_res)
04788             walltime = 0.0;
04789 */
04790         if (cputime < cputime_res)
04791             cputime = 0.0;
04792     }
04793     if(cpuutilflag)
04794         store_times (walltime, cputime);    /* Must be Before store_dvalue(). */
04795     store_dvalue(total_kilos);
04796 #ifdef NO_PRINT_LLD
04797     if(!silent) printf("\tChildren see throughput for %ld reverse readers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
04798     if(!silent && !distributed) printf("\tParent sees throughput for %ld reverse readers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
04799 #else
04800     if(!silent) printf("\tChildren see throughput for %lld reverse readers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
04801     if(!silent && !distributed) printf("\tParent sees throughput for %lld reverse readers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
04802 #endif
04803     if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
04804     if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
04805     if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
04806     if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
04807     /* CPU% can be > 100.0 for multiple CPUs */
04808     if(cpuutilflag)
04809     {
04810         if(walltime == 0.0)
04811         {
04812             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
04813                 walltime, cputime, 0.0);
04814         }
04815         else
04816         {
04817             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
04818                 walltime, cputime, 100.0 * cputime / walltime);
04819         }
04820     }
04821     if(Cflag)
04822     {
04823         for(xyz=0;xyz<num_child;xyz++)
04824         {
04825             child_stat = (struct child_stats *) &shmaddr[xyz];
04826             if(cpuutilflag)
04827             {
04828                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
04829                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime, 
04830                     child_stat->cputime, cpu_util(child_stat->cputime, child_stat->walltime));
04831             }
04832             else
04833             {
04834                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
04835                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
04836             }
04837         }
04838     }
04839     if((!distributed) || (distributed && master_iozone))
04840         stop_monitor("Revread");
04841     sync();
04842     sleep(2);
04843     if(restf)
04844         sleep((int)rest_val);
04845         if(distributed && master_iozone)
04846     {
04847                 stop_master_listen(master_listen_socket);
04848         cleanup_comm();
04849     }
04850 next2:
04851     if(include_tflag)
04852         if(!(include_mask & (long long)STRIDE_READ_MASK))
04853             goto next3;
04854     /**************************************************************/
04855     /*** stride reader throughput tests **************************/
04856     /**************************************************************/
04857     toutputindex++;
04858     strcpy(&toutput[toutputindex][0],throughput_tests[5]);
04859     if((!distributed) || (distributed && master_iozone))
04860         start_monitor("Strideread");
04861     walltime = 0.0;
04862     cputime = 0.0;
04863     jstarttime=0;
04864     sync();
04865     sleep(2);
04866     *stop_flag=0;
04867     total_kilos=0;
04868         /* Hooks to start the distributed Iozone client/server code */
04869         if(distributed)
04870         {
04871                 use_thread=0;  /* Turn of any Posix threads */
04872                 if(master_iozone)
04873                         master_listen_socket = start_master_listen();
04874                 else
04875                         become_client();
04876         }
04877     if(!use_thread)
04878     {
04879        for(xx = 0; xx< num_child ; xx++){
04880         chid=xx;
04881         childids[xx] = start_child_proc(THREAD_STRIDE_TEST,numrecs64,reclen);
04882         if(childids[xx]==-1){
04883             printf("\nFork failed\n");
04884             for(xy = 0; xy< xx ; xy++){
04885                 Kill((long long)childids[xy],(long long)SIGTERM);
04886             }
04887             exit(36);
04888         }
04889         if(childids[xx]==0){
04890 #ifdef _64BIT_ARCH_
04891             thread_stride_read_test((void *)xx);
04892 #else
04893             thread_stride_read_test((void *)((long)xx));
04894 #endif
04895         }   
04896        }
04897     }
04898 #ifndef NO_THREADS
04899     else
04900     {
04901        for(xx = 0; xx< num_child ; xx++){   /* Create the children */
04902         chid=xx;
04903         if(!barray[xx])
04904         {
04905             barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
04906             if(barray[xx] == 0) {
04907                    perror("Memory allocation failed:");
04908                    exit(26);
04909                 }
04910                 barray[xx] =(char *)(((long)barray[xx] + cache_size ) & 
04911             ~(cache_size-1));
04912         }
04913 #ifdef _64BIT_ARCH_
04914         childids[xx] = mythread_create( thread_stride_read_test,xx);
04915 #else
04916         childids[xx] = mythread_create( thread_stride_read_test,(void *)(long)xx);
04917 #endif
04918         if(childids[xx]==-1){
04919             printf("\nThread create failed\n");
04920             for(xy = 0; xy< xx ; xy++){
04921                 kill((pid_t)myid,(int)SIGTERM);
04922             }
04923             exit(37);
04924         }
04925        }
04926     }
04927 #endif
04928     if(myid == (long long)getpid()){
04929                 if(distributed && master_iozone)
04930                 {
04931                         start_master_listen_loop((int) num_child);
04932                 }
04933         for(i=0;i<num_child; i++){ /* wait for children to start */
04934             child_stat = (struct child_stats *)&shmaddr[i];
04935             while(child_stat->flag==CHILD_STATE_HOLD)
04936                 Poll((long long)1);
04937         }
04938         for(i=0;i<num_child; i++){
04939             child_stat = (struct child_stats *)&shmaddr[i];
04940             child_stat->flag = CHILD_STATE_BEGIN;   /* tell children to go */
04941             if(delay_start!=0)
04942                 Poll((long long)delay_start);
04943                        if(distributed && master_iozone)
04944                                 tell_children_begin(i);
04945         }
04946         starttime1 = time_so_far();
04947     }
04948     
04949     getout=0;
04950     if(myid == (long long)getpid()){     /* Parent here */
04951         for( i = 0; i < num_child; i++){ /* wait for children to stop */
04952             child_stat = (struct child_stats *)&shmaddr[i];
04953                         if(distributed && master_iozone)
04954                         {
04955                 printf("\n\tTest running:");
04956                                 wait_dist_join();
04957                                 break;
04958                         }
04959                         else
04960                         {
04961                            if(use_thread)
04962                            {
04963                                 thread_join(childids[i],(void *)&pstatus);
04964                            }
04965                            else
04966                            {
04967                                 wait(0);
04968                            }
04969                         }
04970             if(!jstarttime)
04971                 jstarttime = time_so_far(); 
04972         }
04973         jtime = (time_so_far()-jstarttime)-time_res;
04974         if(jtime < (double).000001) 
04975         {
04976             jtime=time_res; 
04977         }
04978     }
04979     total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
04980     if(total_time < (double).000001) 
04981     {
04982         total_time=time_res;
04983         if(rec_prob < reclen)
04984             rec_prob = reclen;
04985         res_prob=1;
04986     }
04987 #ifdef JTIME
04988     total_time=total_time-jtime;/* Remove the join time */
04989     if(!silent) printf("\nJoin time %10.2f\n",jtime);
04990 #endif
04991     total_kilos=0;
04992     ptotal=0;
04993     min_throughput=max_throughput=min_xfer=0;
04994     if(!silent) printf("\n");
04995     for(xyz=0;xyz<num_child;xyz++){
04996         child_stat = (struct child_stats *)&shmaddr[xyz];
04997         total_kilos+=child_stat->throughput;
04998         ptotal+=child_stat->actual;
04999         if(!min_xfer)
05000             min_xfer=child_stat->actual;
05001         if(child_stat->actual < min_xfer)
05002             min_xfer=child_stat->actual;
05003         if(!min_throughput)
05004             min_throughput=child_stat->throughput;
05005         if(child_stat->throughput < min_throughput)
05006             min_throughput=child_stat->throughput;
05007         if(child_stat->throughput > max_throughput)
05008             max_throughput=child_stat->throughput;
05009         /* walltime += child_stat->walltime; */
05010         cputime += child_stat->cputime;
05011         /* Get the biggest walltime */
05012         if (child_stat->walltime < child_stat->cputime)
05013             child_stat->walltime = child_stat->cputime;
05014         if (child_stat->walltime > walltime)
05015             walltime = child_stat->walltime;
05016     }
05017     avg_throughput=total_kilos/num_child;
05018     if(cpuutilflag)
05019     {
05020 /*
05021         if (walltime < cputime_res)
05022             walltime = 0.0;
05023 */
05024         if (cputime < cputime_res)
05025             cputime = 0.0;
05026     }
05027     if(cpuutilflag)
05028         store_times (walltime, cputime);    /* Must be Before store_dvalue(). */
05029     store_dvalue(total_kilos);
05030 #ifdef NO_PRINT_LLD
05031     if(!silent) printf("\tChildren see throughput for %ld stride readers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
05032     if(!silent && !distributed) printf("\tParent sees throughput for %ld stride readers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
05033 #else
05034     if(!silent) printf("\tChildren see throughput for %lld stride readers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
05035     if(!silent && !distributed) printf("\tParent sees throughput for %lld stride readers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
05036 #endif
05037     if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
05038     if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
05039     if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
05040     if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
05041     /* CPU% can be > 100.0 for multiple CPUs */
05042     if(cpuutilflag)
05043     {
05044         if(walltime == 0.0)
05045         {
05046             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
05047                 walltime, cputime, 0.0);
05048         }
05049         else
05050         {
05051             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
05052                 walltime, cputime, 100.0 * cputime / walltime);
05053         }
05054     }
05055     if(Cflag)
05056     {
05057         for(xyz=0;xyz<num_child;xyz++)
05058         {
05059             child_stat = (struct child_stats *) &shmaddr[xyz];
05060             if(cpuutilflag)
05061             {
05062                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
05063                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime, 
05064                     child_stat->cputime, cpu_util(child_stat->cputime, child_stat->walltime));
05065             }
05066             else
05067             {
05068                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
05069                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
05070             }
05071         }
05072     }
05073     if((!distributed) || (distributed && master_iozone))
05074         stop_monitor("Strideread");
05075     sync();
05076     sleep(2);
05077     if(restf)
05078         sleep((int)rest_val);
05079         if(distributed && master_iozone)
05080     {
05081                 stop_master_listen(master_listen_socket);
05082         cleanup_comm();
05083     }
05084     /**************************************************************/
05085     /*** random reader throughput tests ***************************/
05086     /**************************************************************/
05087 next3:
05088     if(include_tflag)
05089         if(!(include_mask & (long long)RANDOM_RW_MASK))
05090             goto next4;
05091     
05092     toutputindex++;
05093     strcpy(&toutput[toutputindex][0],throughput_tests[6]);
05094     if((!distributed) || (distributed && master_iozone))
05095         start_monitor("Randread");
05096     walltime = 0.0;
05097     cputime = 0.0;
05098     jstarttime=0;
05099     sync();
05100     sleep(2);
05101     *stop_flag=0;
05102     total_kilos=0;
05103         /* Hooks to start the distributed Iozone client/server code */
05104         if(distributed)
05105         {
05106                 use_thread=0;  /* Turn of any Posix threads */
05107                 if(master_iozone)
05108                         master_listen_socket = start_master_listen();
05109                 else
05110                         become_client();
05111         }
05112     if(!use_thread)
05113     {
05114        for(xx = 0; xx< num_child ; xx++){
05115         chid=xx;
05116         childids[xx] = start_child_proc(THREAD_RANDOM_READ_TEST,numrecs64,reclen);
05117         if(childids[xx]==-1){
05118             printf("\nFork failed\n");
05119             for(xy = 0; xy< xx ; xy++){
05120                 Kill((long long)childids[xy],(long long)SIGTERM);
05121             }
05122             exit(38);
05123         }
05124         if(childids[xx]==0){
05125 #ifdef _64BIT_ARCH_
05126             thread_ranread_test((void *)xx);
05127 #else
05128             thread_ranread_test((void *)((long)xx));
05129 #endif
05130         }   
05131        }
05132     }
05133 #ifndef NO_THREADS
05134     else
05135     {
05136        for(xx = 0; xx< num_child ; xx++){   /* Create the children */
05137         chid=xx;
05138         if(!barray[xx])
05139         {
05140             barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
05141             if(barray[xx] == 0) {
05142                    perror("Memory allocation failed:");
05143                    exit(26);
05144                 }
05145                 barray[xx] =(char *)(((long)barray[xx] + cache_size ) & 
05146             ~(cache_size-1));
05147         }
05148 #ifdef _64BIT_ARCH_
05149         childids[xx] = mythread_create( thread_ranread_test,xx);
05150 #else
05151         childids[xx] = mythread_create( thread_ranread_test,(void *)(long)xx);
05152 #endif
05153         if(childids[xx]==-1){
05154             printf("\nThread create failed\n");
05155             for(xy = 0; xy< xx ; xy++){
05156                 kill((pid_t)myid,(int)SIGTERM);
05157             }
05158             exit(39);
05159         }
05160        }
05161     }
05162 #endif
05163     if(myid == (long long)getpid()){
05164                 if(distributed && master_iozone)
05165                 {
05166                         start_master_listen_loop((int) num_child);
05167                 }
05168         for(i=0;i<num_child; i++){ /* wait for children to start */
05169             child_stat = (struct child_stats *)&shmaddr[i];
05170             while(child_stat->flag==CHILD_STATE_HOLD)
05171                 Poll((long long)1);
05172         }
05173         for(i=0;i<num_child; i++){
05174             child_stat = (struct child_stats *)&shmaddr[i];
05175             child_stat->flag = CHILD_STATE_BEGIN;   /* tell children to go */
05176             if(delay_start!=0)
05177                 Poll((long long)delay_start);
05178                        if(distributed && master_iozone)
05179                                 tell_children_begin(i);
05180         }
05181         starttime1 = time_so_far();
05182     }
05183     
05184     getout=0;
05185     if(myid == (long long)getpid()){     /* Parent here */
05186         for( i = 0; i < num_child; i++){ /* wait for children to stop */
05187             child_stat = (struct child_stats *)&shmaddr[i];
05188                         if(distributed && master_iozone)
05189                         {
05190                 printf("\n\tTest running:");
05191                                 wait_dist_join();
05192                                 break;
05193                         }
05194                         else
05195                         {
05196                            if(use_thread)
05197                            {
05198                                 thread_join(childids[i],(void *)&pstatus);
05199                            }
05200                            else
05201                            {
05202                                 wait(0);
05203                            }
05204                         }
05205             if(!jstarttime)
05206                 jstarttime = time_so_far(); 
05207         }
05208         jtime = (time_so_far()-jstarttime)-time_res;
05209         if(jtime < (double).000001) 
05210         {
05211             jtime=time_res; 
05212         }
05213     }
05214     total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
05215     if(total_time < (double).000001) 
05216     {
05217         total_time=time_res;
05218         if(rec_prob < reclen)
05219             rec_prob = reclen;
05220         res_prob=1;
05221     }
05222 #ifdef JTIME
05223     total_time=total_time-jtime;/* Remove the join time */
05224     if(!silent) printf("\nJoin time %10.2f\n",jtime);
05225 #endif
05226     total_kilos=0;
05227     ptotal=0;
05228     min_throughput=max_throughput=min_xfer=0;
05229     if(!silent) printf("\n");
05230     for(xyz=0;xyz<num_child;xyz++){
05231         child_stat = (struct child_stats *)&shmaddr[xyz];
05232         total_kilos+=child_stat->throughput;
05233         ptotal+=child_stat->actual;
05234         if(!min_xfer)
05235             min_xfer=child_stat->actual;
05236         if(child_stat->actual < min_xfer)
05237             min_xfer=child_stat->actual;
05238         if(!min_throughput)
05239             min_throughput=child_stat->throughput;
05240         if(child_stat->throughput < min_throughput)
05241             min_throughput=child_stat->throughput;
05242         if(child_stat->throughput > max_throughput)
05243             max_throughput=child_stat->throughput;
05244         cputime += child_stat->cputime;
05245         /* Get the biggest walltime */
05246         if (child_stat->walltime < child_stat->cputime)
05247             child_stat->walltime = child_stat->cputime;
05248         if (child_stat->walltime > walltime)
05249             walltime = child_stat->walltime;
05250     }
05251     avg_throughput=total_kilos/num_child;
05252     if(cpuutilflag)
05253     {
05254         if (cputime < cputime_res)
05255             cputime = 0.0;
05256     }
05257     if(cpuutilflag)
05258         store_times (walltime, cputime);    /* Must be Before store_dvalue(). */
05259     store_dvalue(total_kilos);
05260 #ifdef NO_PRINT_LLD
05261     if(!silent) printf("\tChildren see throughput for %ld random readers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
05262     if(!silent && !distributed) printf("\tParent sees throughput for %ld random readers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
05263 #else
05264     if(!silent) printf("\tChildren see throughput for %lld random readers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
05265     if(!silent && !distributed) printf("\tParent sees throughput for %lld random readers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
05266 #endif
05267     if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
05268     if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
05269     if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
05270     if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
05271     /* CPU% can be > 100.0 for multiple CPUs */
05272     if(cpuutilflag)
05273     {
05274         if(walltime == 0.0)
05275         {
05276             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
05277                 walltime, cputime, 0.0);
05278         }
05279         else
05280         {
05281             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
05282                 walltime, cputime, 100.0 * cputime / walltime);
05283         }
05284     }
05285     if(Cflag)
05286     {
05287         for(xyz=0;xyz<num_child;xyz++)
05288         {
05289             child_stat = (struct child_stats *) &shmaddr[xyz];
05290             if(cpuutilflag)
05291             {
05292                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
05293                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime, 
05294                     child_stat->cputime, cpu_util(child_stat->cputime, child_stat->walltime));
05295             }
05296             else
05297             {
05298                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
05299                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
05300             }
05301         }
05302     }
05303     if((!distributed) || (distributed && master_iozone))
05304         stop_monitor("Randread");
05305     sync();
05306     sleep(2);
05307     if(restf)
05308         sleep((int)rest_val);
05309         if(distributed && master_iozone)
05310     {
05311                 stop_master_listen(master_listen_socket);
05312         cleanup_comm();
05313     }
05314     /**************************************************************/
05315     /***  mixed workload throughput tests ***************************/
05316     /**************************************************************/
05317 next4:
05318     if(include_tflag)
05319         if(!(include_mask & (long long)RANDOM_MIX_MASK))
05320             goto next5;
05321     
05322     toutputindex++;
05323     strcpy(&toutput[toutputindex][0],throughput_tests[7]);
05324     if((!distributed) || (distributed && master_iozone))
05325         start_monitor("Mixed");
05326     walltime = 0.0;
05327     cputime = 0.0;
05328     jstarttime=0;
05329     sync();
05330     sleep(2);
05331     *stop_flag=0;
05332     total_kilos=0;
05333         /* Hooks to start the distributed Iozone client/server code */
05334         if(distributed)
05335         {
05336                 use_thread=0;  /* Turn of any Posix threads */
05337                 if(master_iozone)
05338                         master_listen_socket = start_master_listen();
05339                 else
05340                         become_client();
05341         }
05342     if(!use_thread)
05343     {
05344        for(xx = 0; xx< num_child ; xx++){
05345         chid=xx;
05346         childids[xx] = start_child_proc(THREAD_RANDOM_MIX_TEST,numrecs64,reclen);
05347         if(childids[xx]==-1){
05348             printf("\nFork failed\n");
05349             for(xy = 0; xy< xx ; xy++){
05350                 Kill((long long)childids[xy],(long long)SIGTERM);
05351             }
05352             exit(38);
05353         }
05354         if(childids[xx]==0){
05355 #ifdef _64BIT_ARCH_
05356             thread_mix_test((void *)xx);
05357 #else
05358             thread_mix_test((void *)((long)xx));
05359 #endif
05360         }   
05361        }
05362     }
05363 #ifndef NO_THREADS
05364     else
05365     {
05366        for(xx = 0; xx< num_child ; xx++){   /* Create the children */
05367         chid=xx;
05368         if(!barray[xx])
05369         {
05370             barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
05371             if(barray[xx] == 0) {
05372                    perror("Memory allocation failed:");
05373                    exit(26);
05374                 }
05375                 barray[xx] =(char *)(((long)barray[xx] + cache_size ) & 
05376             ~(cache_size-1));
05377         }
05378 #ifdef _64BIT_ARCH_
05379         childids[xx] = mythread_create( thread_mix_test,xx);
05380 #else
05381         childids[xx] = mythread_create( thread_mix_test,(void *)(long)xx);
05382 #endif
05383         if(childids[xx]==-1){
05384             printf("\nThread create failed\n");
05385             for(xy = 0; xy< xx ; xy++){
05386                 kill((pid_t)myid,(int)SIGTERM);
05387             }
05388             exit(39);
05389         }
05390        }
05391     }
05392 #endif
05393     if(myid == (long long)getpid()){
05394                 if(distributed && master_iozone)
05395                 {
05396                         start_master_listen_loop((int) num_child);
05397                 }
05398         for(i=0;i<num_child; i++){ /* wait for children to start */
05399             child_stat = (struct child_stats *)&shmaddr[i];
05400             while(child_stat->flag==CHILD_STATE_HOLD)
05401                 Poll((long long)1);
05402         }
05403         for(i=0;i<num_child; i++){
05404             child_stat = (struct child_stats *)&shmaddr[i];
05405             child_stat->flag = CHILD_STATE_BEGIN;   /* tell children to go */
05406             if(delay_start!=0)
05407                 Poll((long long)delay_start);
05408                        if(distributed && master_iozone)
05409                                 tell_children_begin(i);
05410         }
05411         starttime1 = time_so_far();
05412     }
05413     
05414     getout=0;
05415     if(myid == (long long)getpid()){     /* Parent here */
05416         for( i = 0; i < num_child; i++){ /* wait for children to stop */
05417             child_stat = (struct child_stats *)&shmaddr[i];
05418                         if(distributed && master_iozone)
05419                         {
05420                 printf("\n\tTest running:");
05421                                 wait_dist_join();
05422                                 break;
05423                         }
05424                         else
05425                         {
05426                            if(use_thread)
05427                            {
05428                                 thread_join(childids[i],(void *)&pstatus);
05429                            }
05430                            else
05431                            {
05432                                 wait(0);
05433                            }
05434                         }
05435             if(!jstarttime)
05436                 jstarttime = time_so_far(); 
05437         }
05438         jtime = (time_so_far()-jstarttime)-time_res;
05439         if(jtime < (double).000001) 
05440         {
05441             jtime=time_res; 
05442         }
05443     }
05444     total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
05445     if(total_time < (double).000001) 
05446     {
05447         total_time=time_res;
05448         if(rec_prob < reclen)
05449             rec_prob = reclen;
05450         res_prob=1;
05451     }
05452 #ifdef JTIME
05453     total_time=total_time-jtime;/* Remove the join time */
05454     if(!silent) printf("\nJoin time %10.2f\n",jtime);
05455 #endif
05456     total_kilos=0;
05457     ptotal=0;
05458     min_throughput=max_throughput=min_xfer=0;
05459     if(!silent) printf("\n");
05460     for(xyz=0;xyz<num_child;xyz++){
05461         child_stat = (struct child_stats *)&shmaddr[xyz];
05462         total_kilos+=child_stat->throughput;
05463         ptotal+=child_stat->actual;
05464         if(!min_xfer)
05465             min_xfer=child_stat->actual;
05466         if(child_stat->actual < min_xfer)
05467             min_xfer=child_stat->actual;
05468         if(!min_throughput)
05469             min_throughput=child_stat->throughput;
05470         if(child_stat->throughput < min_throughput)
05471             min_throughput=child_stat->throughput;
05472         if(child_stat->throughput > max_throughput)
05473             max_throughput=child_stat->throughput;
05474         cputime += child_stat->cputime;
05475         /* Get the biggest walltime */
05476         if (child_stat->walltime < child_stat->cputime)
05477             child_stat->walltime = child_stat->cputime;
05478         if (child_stat->walltime > walltime)
05479             walltime = child_stat->walltime;
05480     }
05481     avg_throughput=total_kilos/num_child;
05482     if(cpuutilflag)
05483     {
05484         if (cputime < cputime_res)
05485             cputime = 0.0;
05486     }
05487     if(cpuutilflag)
05488         store_times (walltime, cputime);    /* Must be Before store_dvalue(). */
05489     store_dvalue(total_kilos);
05490 #ifdef NO_PRINT_LLD
05491     if(!silent) printf("\tChildren see throughput for %ld mixed workload \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
05492     if(!silent && !distributed) printf("\tParent sees throughput for %ld mixed workload \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
05493 #else
05494     if(!silent) printf("\tChildren see throughput for %lld mixed workload \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
05495     if(!silent && !distributed) printf("\tParent sees throughput for %lld mixed workload \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
05496 #endif
05497     if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
05498     if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
05499     if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
05500     if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
05501     /* CPU% can be > 100.0 for multiple CPUs */
05502     if(cpuutilflag)
05503     {
05504         if(walltime == 0.0)
05505         {
05506             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
05507                 walltime, cputime, 0.0);
05508         }
05509         else
05510         {
05511             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
05512                 walltime, cputime, 100.0 * cputime / walltime);
05513         }
05514     }
05515     if(Cflag)
05516     {
05517         for(xyz=0;xyz<num_child;xyz++)
05518         {
05519             child_stat = (struct child_stats *) &shmaddr[xyz];
05520             if(cpuutilflag)
05521             {
05522                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
05523                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime, 
05524                     child_stat->cputime, cpu_util(child_stat->cputime, child_stat->walltime));
05525             }
05526             else
05527             {
05528                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
05529                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
05530             }
05531         }
05532     }
05533     if((!distributed) || (distributed && master_iozone))
05534         stop_monitor("Mixed");
05535     sync();
05536     sleep(2);
05537     if(restf)
05538         sleep((int)rest_val);
05539         if(distributed && master_iozone)
05540     {
05541                 stop_master_listen(master_listen_socket);
05542         cleanup_comm();
05543     }
05544 next5:
05545     /**************************************************************/
05546     /*** random writer throughput tests  **************************/
05547     /**************************************************************/
05548     if(include_tflag)
05549         if(!(include_mask & (long long)RANDOM_RW_MASK) || no_write)
05550             goto next6;
05551     
05552     toutputindex++;
05553     strcpy(&toutput[toutputindex][0],throughput_tests[8]);
05554     if((!distributed) || (distributed && master_iozone))
05555         start_monitor("Randwrite");
05556     walltime = 0.0;
05557     cputime = 0.0;
05558     jstarttime=0;
05559     sync();
05560     sleep(2);
05561     *stop_flag=0;
05562     total_kilos=0;
05563         /* Hooks to start the distributed Iozone client/server code */
05564         if(distributed)
05565         {
05566                 use_thread=0;  /* Turn of any Posix threads */
05567                 if(master_iozone)
05568                         master_listen_socket = start_master_listen();
05569                 else
05570                         become_client();
05571         }
05572     if(!use_thread)
05573     {
05574        for(xx = 0; xx< num_child ; xx++){
05575         chid=xx;
05576         childids[xx] = start_child_proc(THREAD_RANDOM_WRITE_TEST,numrecs64,reclen);
05577         if(childids[xx]==-1){
05578             printf("\nFork failed\n");
05579             for(xy = 0; xy< xx ; xy++){
05580                 Kill((long long)childids[xy],(long long)SIGTERM);
05581             }
05582             exit(38);
05583         }
05584         if(childids[xx]==0){
05585 #ifdef _64BIT_ARCH_
05586             thread_ranwrite_test((void *)xx);
05587 #else
05588             thread_ranwrite_test((void *)((long)xx));
05589 #endif
05590         }   
05591        }
05592     }
05593 #ifndef NO_THREADS
05594     else
05595     {
05596        for(xx = 0; xx< num_child ; xx++){   /* Create the children */
05597         chid=xx;
05598         if(!barray[xx])
05599         {
05600             barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
05601             if(barray[xx] == 0) {
05602                    perror("Memory allocation failed:");
05603                    exit(26);
05604                 }
05605                 barray[xx] =(char *)(((long)barray[xx] + cache_size ) & 
05606             ~(cache_size-1));
05607         }
05608 #ifdef _64BIT_ARCH_
05609         childids[xx] = mythread_create( thread_ranwrite_test,xx);
05610 #else
05611         childids[xx] = mythread_create( thread_ranwrite_test,(void *)(long)xx);
05612 #endif
05613         if(childids[xx]==-1){
05614             printf("\nThread create failed\n");
05615             for(xy = 0; xy< xx ; xy++){
05616                 kill((pid_t)myid,(int)SIGTERM);
05617             }
05618             exit(39);
05619         }
05620        }
05621     }
05622 #endif
05623     if(myid == (long long)getpid()){
05624                 if(distributed && master_iozone)
05625                 {
05626                         start_master_listen_loop((int) num_child);
05627                 }
05628         for(i=0;i<num_child; i++){ /* wait for children to start */
05629             child_stat = (struct child_stats *)&shmaddr[i];
05630             while(child_stat->flag==CHILD_STATE_HOLD)
05631                 Poll((long long)1);
05632         }
05633         for(i=0;i<num_child; i++){
05634             child_stat = (struct child_stats *)&shmaddr[i];
05635             child_stat->flag = CHILD_STATE_BEGIN;   /* tell children to go */
05636             if(delay_start!=0)
05637                 Poll((long long)delay_start);
05638                        if(distributed && master_iozone)
05639                                 tell_children_begin(i);
05640         }
05641         starttime1 = time_so_far();
05642     }
05643     
05644     getout=0;
05645     if(myid == (long long)getpid()){     /* Parent here */
05646         for( i = 0; i < num_child; i++){ /* wait for children to stop */
05647             child_stat = (struct child_stats *)&shmaddr[i];
05648                         if(distributed && master_iozone)
05649                         {
05650                 printf("\n\tTest running:");
05651                                 wait_dist_join();
05652                                 break;
05653                         }
05654                         else
05655                         {
05656                            if(use_thread)
05657                            {
05658                                 thread_join(childids[i],(void *)&pstatus);
05659                            }
05660                            else
05661                            {
05662                                 wait(0);
05663                            }
05664                         }
05665             if(!jstarttime)
05666                 jstarttime = time_so_far(); 
05667         }
05668         jtime = (time_so_far()-jstarttime)-time_res;
05669         if(jtime < (double).000001) 
05670         {
05671             jtime=time_res; 
05672         }
05673     }
05674     total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
05675     if(total_time < (double).000001) 
05676     {
05677         total_time=time_res;
05678         if(rec_prob < reclen)
05679             rec_prob = reclen;
05680         res_prob=1;
05681     }
05682 #ifdef JTIME
05683     total_time=total_time-jtime;/* Remove the join time */
05684     if(!silent) printf("\nJoin time %10.2f\n",jtime);
05685 #endif
05686     total_kilos=0;
05687     ptotal=0;
05688     min_throughput=max_throughput=min_xfer=0;
05689     if(!silent) printf("\n");
05690     for(xyz=0;xyz<num_child;xyz++){
05691         child_stat = (struct child_stats *)&shmaddr[xyz];
05692         total_kilos+=child_stat->throughput;
05693         ptotal+=child_stat->actual;
05694         if(!min_xfer)
05695             min_xfer=child_stat->actual;
05696         if(child_stat->actual < min_xfer)
05697             min_xfer=child_stat->actual;
05698         if(!min_throughput)
05699             min_throughput=child_stat->throughput;
05700         if(child_stat->throughput < min_throughput)
05701             min_throughput=child_stat->throughput;
05702         if(child_stat->throughput > max_throughput)
05703             max_throughput=child_stat->throughput;
05704         cputime += child_stat->cputime;
05705         /* Get the biggest walltime */
05706         if (child_stat->walltime < child_stat->cputime)
05707             child_stat->walltime = child_stat->cputime;
05708         if (child_stat->walltime > walltime)
05709             walltime = child_stat->walltime;
05710     }
05711     avg_throughput=total_kilos/num_child;
05712     if(cpuutilflag)
05713     {
05714         if (cputime < cputime_res)
05715             cputime = 0.0;
05716     }
05717     if(cpuutilflag)
05718         store_times (walltime, cputime);    /* Must be Before store_dvalue(). */
05719     store_dvalue(total_kilos);
05720 #ifdef NO_PRINT_LLD
05721     if(!silent) printf("\tChildren see throughput for %ld random writers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
05722     if(!silent && !distributed) printf("\tParent sees throughput for %ld random writers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
05723 #else
05724     if(!silent) printf("\tChildren see throughput for %lld random writers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
05725     if(!silent && !distributed) printf("\tParent sees throughput for %lld random writers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
05726 #endif
05727     if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
05728     if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
05729     if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
05730     if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
05731     /* CPU% can be > 100.0 for multiple CPUs */
05732     if(cpuutilflag)
05733     {
05734         if(walltime == 0.0)
05735         {
05736             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
05737                 walltime, cputime, 0.0);
05738         }
05739         else
05740         {
05741             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
05742                 walltime, cputime, 100.0 * cputime / walltime);
05743         }
05744     }
05745     if(Cflag)
05746     {
05747         for(xyz=0;xyz<num_child;xyz++)
05748         {
05749             child_stat = (struct child_stats *) &shmaddr[xyz];
05750             if(cpuutilflag)
05751             {
05752                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
05753                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime, 
05754                     child_stat->cputime, cpu_util(child_stat->cputime, child_stat->walltime));
05755             }
05756             else
05757             {
05758                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
05759                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
05760             }
05761         }
05762     }
05763     if((!distributed) || (distributed && master_iozone))
05764         stop_monitor("Randwrite");
05765     sync();
05766     sleep(2);
05767     if(restf)
05768         sleep((int)rest_val);
05769         if(distributed && master_iozone)
05770     {
05771                 stop_master_listen(master_listen_socket);
05772         cleanup_comm();
05773     }
05774 next6:
05775     /**************************************************************/
05776     /*** Pwrite writer throughput tests  **************************/
05777     /**************************************************************/
05778 #ifndef HAVE_PREAD
05779         goto next7;
05780 #else
05781     if(include_tflag)
05782         if(!(include_mask & (long long)PWRITER_MASK))
05783             goto next7;
05784     
05785     toutputindex++;
05786     strcpy(&toutput[toutputindex][0],throughput_tests[9]);
05787     if((!distributed) || (distributed && master_iozone))
05788         start_monitor("Pwrite");
05789     walltime = 0.0;
05790     cputime = 0.0;
05791     jstarttime=0;
05792     sync();
05793     sleep(2);
05794     *stop_flag=0;
05795     total_kilos=0;
05796         /* Hooks to start the distributed Iozone client/server code */
05797         if(distributed)
05798         {
05799                 use_thread=0;  /* Turn of any Posix threads */
05800                 if(master_iozone)
05801                         master_listen_socket = start_master_listen();
05802                 else
05803                         become_client();
05804         }
05805     if(!use_thread)
05806     {
05807        for(xx = 0; xx< num_child ; xx++){
05808         chid=xx;
05809         childids[xx] = start_child_proc(THREAD_PWRITE_TEST,numrecs64,reclen);
05810         if(childids[xx]==-1){
05811             printf("\nFork failed\n");
05812             for(xy = 0; xy< xx ; xy++){
05813                 Kill((long long)childids[xy],(long long)SIGTERM);
05814             }
05815             exit(38);
05816         }
05817         if(childids[xx]==0){
05818 #ifdef _64BIT_ARCH_
05819             thread_pwrite_test((void *)xx);
05820 #else
05821             thread_pwrite_test((void *)((long)xx));
05822 #endif
05823         }   
05824        }
05825     }
05826 #ifndef NO_THREADS
05827     else
05828     {
05829        for(xx = 0; xx< num_child ; xx++){   /* Create the children */
05830         chid=xx;
05831         if(!barray[xx])
05832         {
05833             barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
05834             if(barray[xx] == 0) {
05835                    perror("Memory allocation failed:");
05836                    exit(26);
05837                 }
05838                 barray[xx] =(char *)(((long)barray[xx] + cache_size ) & 
05839             ~(cache_size-1));
05840         }
05841 #ifdef _64BIT_ARCH_
05842         childids[xx] = mythread_create( thread_pwrite_test,xx);
05843 #else
05844         childids[xx] = mythread_create( thread_pwrite_test,(void *)(long)xx);
05845 #endif
05846         if(childids[xx]==-1){
05847             printf("\nThread create failed\n");
05848             for(xy = 0; xy< xx ; xy++){
05849                 kill((pid_t)myid,(int)SIGTERM);
05850             }
05851             exit(39);
05852         }
05853        }
05854     }
05855 #endif
05856     if(myid == (long long)getpid()){
05857                 if(distributed && master_iozone)
05858                 {
05859                         start_master_listen_loop((int) num_child);
05860                 }
05861         for(i=0;i<num_child; i++){ /* wait for children to start */
05862             child_stat = (struct child_stats *)&shmaddr[i];
05863             while(child_stat->flag==CHILD_STATE_HOLD)
05864                 Poll((long long)1);
05865         }
05866         for(i=0;i<num_child; i++){
05867             child_stat = (struct child_stats *)&shmaddr[i];
05868             child_stat->flag = CHILD_STATE_BEGIN;   /* tell children to go */
05869             if(delay_start!=0)
05870                 Poll((long long)delay_start);
05871                        if(distributed && master_iozone)
05872                                 tell_children_begin(i);
05873         }
05874         starttime1 = time_so_far();
05875     }
05876     
05877     getout=0;
05878     if(myid == (long long)getpid()){     /* Parent here */
05879         for( i = 0; i < num_child; i++){ /* wait for children to stop */
05880             child_stat = (struct child_stats *)&shmaddr[i];
05881                         if(distributed && master_iozone)
05882                         {
05883                 printf("\n\tTest running:");
05884                                 wait_dist_join();
05885                                 break;
05886                         }
05887                         else
05888                         {
05889                            if(use_thread)
05890                            {
05891                                 thread_join(childids[i],(void *)&pstatus);
05892                            }
05893                            else
05894                            {
05895                                 wait(0);
05896                            }
05897                         }
05898             if(!jstarttime)
05899                 jstarttime = time_so_far(); 
05900         }
05901         jtime = (time_so_far()-jstarttime)-time_res;
05902         if(jtime < (double).000001) 
05903         {
05904             jtime=time_res; 
05905         }
05906     }
05907     total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
05908     if(total_time < (double).000001) 
05909     {
05910         total_time=time_res;
05911         if(rec_prob < reclen)
05912             rec_prob = reclen;
05913         res_prob=1;
05914     }
05915 #ifdef JTIME
05916     total_time=total_time-jtime;/* Remove the join time */
05917     if(!silent) printf("\nJoin time %10.2f\n",jtime);
05918 #endif
05919     total_kilos=0;
05920     ptotal=0;
05921     min_throughput=max_throughput=min_xfer=0;
05922     if(!silent) printf("\n");
05923     for(xyz=0;xyz<num_child;xyz++){
05924         child_stat = (struct child_stats *)&shmaddr[xyz];
05925         total_kilos+=child_stat->throughput;
05926         ptotal+=child_stat->actual;
05927         if(!min_xfer)
05928             min_xfer=child_stat->actual;
05929         if(child_stat->actual < min_xfer)
05930             min_xfer=child_stat->actual;
05931         if(!min_throughput)
05932             min_throughput=child_stat->throughput;
05933         if(child_stat->throughput < min_throughput)
05934             min_throughput=child_stat->throughput;
05935         if(child_stat->throughput > max_throughput)
05936             max_throughput=child_stat->throughput;
05937         cputime += child_stat->cputime;
05938         /* Get the biggest walltime*/
05939         if (child_stat->walltime < child_stat->cputime)
05940             child_stat->walltime = child_stat->cputime;
05941         if (child_stat->walltime > walltime)
05942             walltime = child_stat->walltime;
05943     }
05944     avg_throughput=total_kilos/num_child;
05945     if(cpuutilflag)
05946     {
05947         if (cputime < cputime_res)
05948             cputime = 0.0;
05949     }
05950     if(cpuutilflag)
05951         store_times (walltime, cputime);    /* Must be Before store_dvalue(). */
05952     store_dvalue(total_kilos);
05953 #ifdef NO_PRINT_LLD
05954     if(!silent) printf("\tChildren see throughput for %ld pwrite writers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
05955     if(!silent && !distributed) printf("\tParent sees throughput for %ld pwrite writers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
05956 #else
05957     if(!silent) printf("\tChildren see throughput for %lld pwrite writers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
05958     if(!silent && !distributed) printf("\tParent sees throughput for %lld pwrite writers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
05959 #endif
05960     if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
05961     if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
05962     if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
05963     if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
05964     /* CPU% can be > 100.0 for multiple CPUs */
05965     if(cpuutilflag)
05966     {
05967         if(walltime == 0.0)
05968         {
05969             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
05970                 walltime, cputime, 0.0);
05971         }
05972         else
05973         {
05974             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
05975                 walltime, cputime, 100.0 * cputime / walltime);
05976         }
05977     }
05978     if(Cflag)
05979     {
05980         for(xyz=0;xyz<num_child;xyz++)
05981         {
05982             child_stat = (struct child_stats *) &shmaddr[xyz];
05983             if(cpuutilflag)
05984             {
05985                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
05986                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime, 
05987                     child_stat->cputime, cpu_util(child_stat->cputime, child_stat->walltime));
05988             }
05989             else
05990             {
05991                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
05992                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
05993             }
05994         }
05995     }
05996     if((!distributed) || (distributed && master_iozone))
05997         stop_monitor("Pwrite");
05998     sync();
05999     sleep(2);
06000     if(restf)
06001         sleep((int)rest_val);
06002         if(distributed && master_iozone)
06003     {
06004                 stop_master_listen(master_listen_socket);
06005         cleanup_comm();
06006     }
06007 #endif
06008     /**************************************************************/
06009     /*** Pread reader throughput tests  **************************/
06010     /**************************************************************/
06011 next7:
06012 
06013 #ifndef HAVE_PREAD
06014         goto next8;
06015 #else
06016     if(include_tflag)
06017         if(!(include_mask & (long long)PREADER_MASK))
06018             goto next8;
06019     
06020     toutputindex++;
06021     strcpy(&toutput[toutputindex][0],throughput_tests[10]);
06022     if((!distributed) || (distributed && master_iozone))
06023         start_monitor("Pread");
06024     walltime = 0.0;
06025     cputime = 0.0;
06026     jstarttime=0;
06027     sync();
06028     sleep(2);
06029     *stop_flag=0;
06030     total_kilos=0;
06031         /* Hooks to start the distributed Iozone client/server code */
06032         if(distributed)
06033         {
06034                 use_thread=0;  /* Turn of any Posix threads */
06035                 if(master_iozone)
06036                         master_listen_socket = start_master_listen();
06037                 else
06038                         become_client();
06039         }
06040     if(!use_thread)
06041     {
06042        for(xx = 0; xx< num_child ; xx++){
06043         chid=xx;
06044         childids[xx] = start_child_proc(THREAD_PREAD_TEST,numrecs64,reclen);
06045         if(childids[xx]==-1){
06046             printf("\nFork failed\n");
06047             for(xy = 0; xy< xx ; xy++){
06048                 Kill((long long)childids[xy],(long long)SIGTERM);
06049             }
06050             exit(38);
06051         }
06052         if(childids[xx]==0){
06053 #ifdef _64BIT_ARCH_
06054             thread_pread_test((void *)xx);
06055 #else
06056             thread_pread_test((void *)((long)xx));
06057 #endif
06058         }   
06059        }
06060     }
06061 #ifndef NO_THREADS
06062     else
06063     {
06064        for(xx = 0; xx< num_child ; xx++){   /* Create the children */
06065         chid=xx;
06066         if(!barray[xx])
06067         {
06068             barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
06069             if(barray[xx] == 0) {
06070                    perror("Memory allocation failed:");
06071                    exit(26);
06072                 }
06073                 barray[xx] =(char *)(((long)barray[xx] + cache_size ) & 
06074             ~(cache_size-1));
06075         }
06076 #ifdef _64BIT_ARCH_
06077         childids[xx] = mythread_create( thread_pread_test,xx);
06078 #else
06079         childids[xx] = mythread_create( thread_pread_test,(void *)(long)xx);
06080 #endif
06081         if(childids[xx]==-1){
06082             printf("\nThread create failed\n");
06083             for(xy = 0; xy< xx ; xy++){
06084                 kill((pid_t)myid,(int)SIGTERM);
06085             }
06086             exit(39);
06087         }
06088        }
06089     }
06090 #endif
06091     if(myid == (long long)getpid()){
06092                 if(distributed && master_iozone)
06093                 {
06094                         start_master_listen_loop((int) num_child);
06095                 }
06096         for(i=0;i<num_child; i++){ /* wait for children to start */
06097             child_stat = (struct child_stats *)&shmaddr[i];
06098             while(child_stat->flag==CHILD_STATE_HOLD)
06099                 Poll((long long)1);
06100         }
06101         for(i=0;i<num_child; i++){
06102             child_stat = (struct child_stats *)&shmaddr[i];
06103             child_stat->flag = CHILD_STATE_BEGIN;   /* tell children to go */
06104             if(delay_start!=0)
06105                 Poll((long long)delay_start);
06106                        if(distributed && master_iozone)
06107                                 tell_children_begin(i);
06108         }
06109         starttime1 = time_so_far();
06110     }
06111     
06112     getout=0;
06113     if(myid == (long long)getpid()){     /* Parent here */
06114         for( i = 0; i < num_child; i++){ /* wait for children to stop */
06115             child_stat = (struct child_stats *)&shmaddr[i];
06116                         if(distributed && master_iozone)
06117                         {
06118                 printf("\n\tTest running:");
06119                                 wait_dist_join();
06120                                 break;
06121                         }
06122                         else
06123                         {
06124                            if(use_thread)
06125                            {
06126                                 thread_join(childids[i],(void *)&pstatus);
06127                            }
06128                            else
06129                            {
06130                                 wait(0);
06131                            }
06132                         }
06133             if(!jstarttime)
06134                 jstarttime = time_so_far(); 
06135         }
06136         jtime = (time_so_far()-jstarttime)-time_res;
06137         if(jtime < (double).000001) 
06138         {
06139             jtime=time_res; 
06140         }
06141     }
06142     total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
06143     if(total_time < (double).000001) 
06144     {
06145         total_time=time_res;
06146         if(rec_prob < reclen)
06147             rec_prob = reclen;
06148         res_prob=1;
06149     }
06150 #ifdef JTIME
06151     total_time=total_time-jtime;/* Remove the join time */
06152     if(!silent) printf("\nJoin time %10.2f\n",jtime);
06153 #endif
06154     total_kilos=0;
06155     ptotal=0;
06156     min_throughput=max_throughput=min_xfer=0;
06157     if(!silent) printf("\n");
06158     for(xyz=0;xyz<num_child;xyz++){
06159         child_stat = (struct child_stats *)&shmaddr[xyz];
06160         total_kilos+=child_stat->throughput;
06161         ptotal+=child_stat->actual;
06162         if(!min_xfer)
06163             min_xfer=child_stat->actual;
06164         if(child_stat->actual < min_xfer)
06165             min_xfer=child_stat->actual;
06166         if(!min_throughput)
06167             min_throughput=child_stat->throughput;
06168         if(child_stat->throughput < min_throughput)
06169             min_throughput=child_stat->throughput;
06170         if(child_stat->throughput > max_throughput)
06171             max_throughput=child_stat->throughput;
06172         cputime += child_stat->cputime;
06173         /* Get the biggest walltime*/
06174         if (child_stat->walltime < child_stat->cputime)
06175             child_stat->walltime = child_stat->cputime;
06176         if (child_stat->walltime > walltime)
06177             walltime = child_stat->walltime;
06178     }
06179     avg_throughput=total_kilos/num_child;
06180     if(cpuutilflag)
06181     {
06182         if (cputime < cputime_res)
06183             cputime = 0.0;
06184     }
06185     if(cpuutilflag)
06186         store_times (walltime, cputime);    /* Must be Before store_dvalue(). */
06187     store_dvalue(total_kilos);
06188 #ifdef NO_PRINT_LLD
06189     if(!silent) printf("\tChildren see throughput for %ld pread readers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
06190     if(!silent && !distributed) printf("\tParent sees throughput for %ld pread readers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
06191 #else
06192     if(!silent) printf("\tChildren see throughput for %lld pread readers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
06193     if(!silent && !distributed) printf("\tParent sees throughput for %lld pread readers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
06194 #endif
06195     if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
06196     if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
06197     if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
06198     if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
06199     /* CPU% can be > 100.0 for multiple CPUs */
06200     if(cpuutilflag)
06201     {
06202         if(walltime == 0.0)
06203         {
06204             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
06205                 walltime, cputime, 0.0);
06206         }
06207         else
06208         {
06209             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
06210                 walltime, cputime, 100.0 * cputime / walltime);
06211         }
06212     }
06213     if(Cflag)
06214     {
06215         for(xyz=0;xyz<num_child;xyz++)
06216         {
06217             child_stat = (struct child_stats *) &shmaddr[xyz];
06218             if(cpuutilflag)
06219             {
06220                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
06221                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime, 
06222                     child_stat->cputime, cpu_util(child_stat->cputime, child_stat->walltime));
06223             }
06224             else
06225             {
06226                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
06227                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
06228             }
06229         }
06230     }
06231     if((!distributed) || (distributed && master_iozone))
06232         stop_monitor("Pread");
06233     sync();
06234     sleep(2);
06235     if(restf)
06236         sleep((int)rest_val);
06237         if(distributed && master_iozone)
06238     {
06239                 stop_master_listen(master_listen_socket);
06240         cleanup_comm();
06241     }
06242 #endif
06243 next8:
06244     if(include_tflag)
06245         if(!(include_mask & (long long)FWRITER_MASK))
06246             goto next9;
06247     /**************************************************************/
06248     /*** fwriter throughput tests *********************************/
06249     /**************************************************************/
06250     if((!distributed) || (distributed && master_iozone))
06251         start_monitor("Fwrite");
06252     toutputindex++;
06253     strcpy(&toutput[toutputindex][0],throughput_tests[11]);
06254     walltime = 0.0;
06255     cputime = 0.0;
06256     jstarttime=0;
06257     total_kilos=0;
06258     if(distributed)
06259     {
06260         use_thread=0;
06261         if(master_iozone)
06262             master_listen_socket=start_master_listen();
06263         else
06264             become_client();
06265     }
06266     if(!use_thread)
06267     {
06268        for(xx = 0; xx< num_child ; xx++){
06269         chid=xx;
06270         childids[xx] = start_child_proc(THREAD_FWRITE_TEST,numrecs64,reclen);
06271         if(childids[xx]==-1){
06272             printf("\nFork failed\n");
06273             for(xy = 0; xy< xx ; xy++){
06274                 Kill((long long)childids[xy],(long long)SIGTERM);
06275             }
06276             exit(30);
06277         }
06278         if(childids[xx]==0){
06279 #ifdef _64BIT_ARCH_
06280             thread_fwrite_test((void *)xx);
06281 #else
06282             thread_fwrite_test((void *)((long)xx));
06283 #endif
06284         }   
06285        }
06286     }
06287 #ifndef NO_THREADS
06288     else
06289     {
06290        for(xx = 0; xx< num_child ; xx++){   /* Create the children */
06291         if(!barray[xx])
06292         {
06293             barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
06294             if(barray[xx] == 0) {
06295                    perror("Memory allocation failed:");
06296                    exit(26);
06297                 }
06298                 barray[xx] =(char *)(((long)barray[xx] + cache_size ) & 
06299             ~(cache_size-1));
06300         }
06301 #ifdef _64BIT_ARCH_
06302         childids[xx] = mythread_create( thread_fwrite_test,xx);
06303 #else
06304         childids[xx] = mythread_create( thread_fwrite_test,(void *)(long)xx);
06305 #endif
06306         if(childids[xx]==-1){
06307             printf("\nThread create failed\n");
06308             for(xy = 0; xy< xx ; xy++){
06309                 kill((pid_t)myid,(int)SIGTERM);
06310             }
06311             exit(31);
06312         }
06313        }
06314     }
06315 #endif
06316     if(myid == (long long)getpid()){
06317         if(distributed && master_iozone)
06318         {
06319             start_master_listen_loop((int) num_child);
06320         }
06321         for(i=0;i<num_child; i++){ /* wait for children to start */
06322             child_stat=(struct child_stats *)&shmaddr[i];
06323             while(child_stat->flag==CHILD_STATE_HOLD)
06324                 Poll((long long)1);
06325         }
06326         for(i=0;i<num_child; i++)
06327         {
06328             child_stat=(struct child_stats *)&shmaddr[i];
06329             child_stat->flag = CHILD_STATE_BEGIN; /* tell children to go */
06330             if(delay_start!=0)
06331                 Poll((long long)delay_start);
06332             if(distributed && master_iozone)
06333                 tell_children_begin(i);
06334         }
06335         starttime1 = time_so_far();
06336         goto jumpend1;
06337     }
06338 jumpend1:
06339     getout=0;
06340     if(myid == (long long)getpid()){    /* Parent here */
06341         for( i = 0; i < num_child; i++){
06342             child_stat = (struct child_stats *)&shmaddr[i];
06343             if(distributed && master_iozone)
06344             {
06345                 printf("\n\tTest running:");
06346                 wait_dist_join();
06347                 break;
06348             }
06349             else
06350             {
06351                if(use_thread)
06352                {
06353                 thread_join(childids[i],(void *)&pstatus);
06354                }
06355                else
06356                {
06357                 wait(0);
06358                }
06359             }
06360             if(!jstarttime)
06361                 jstarttime = time_so_far(); 
06362         }
06363         jtime = (time_so_far()-jstarttime)-time_res; 
06364         if(jtime < (double).000001)
06365         {
06366             jtime=time_res; 
06367         }
06368     }
06369     total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
06370     if(total_time < (double).000001) 
06371     {
06372         total_time=time_res; 
06373         if(rec_prob < reclen)
06374             rec_prob = reclen;
06375         res_prob=1;
06376     }
06377 #ifdef JTIME
06378     total_time=total_time-jtime;/* Remove the join time */
06379     if(!silent) printf("\nJoin time %10.2f\n",jtime);
06380 #endif
06381     
06382     total_kilos=0;
06383     ptotal=0;
06384     min_throughput=max_throughput=min_xfer=0;
06385     if(!silent) printf("\n");
06386     for(xyz=0;xyz<num_child;xyz++){
06387         child_stat=(struct child_stats *)&shmaddr[xyz];
06388         total_kilos+=child_stat->throughput;
06389         ptotal+=child_stat->actual;
06390         if(!min_xfer)
06391             min_xfer=child_stat->actual;
06392         if(child_stat->actual < min_xfer)
06393             min_xfer=child_stat->actual;
06394         if(!min_throughput)
06395             min_throughput=child_stat->throughput;
06396         if(child_stat->throughput < min_throughput)
06397             min_throughput=child_stat->throughput;
06398         if(child_stat->throughput > max_throughput)
06399             max_throughput=child_stat->throughput;
06400         cputime += child_stat->cputime;
06401         /* Get the earliest start time and latest fini time to calc. elapsed time. */
06402         if (child_stat->walltime < child_stat->cputime)
06403             child_stat->walltime = child_stat->cputime;
06404         if (child_stat->walltime > walltime)
06405             walltime = child_stat->walltime;
06406     }
06407     avg_throughput=total_kilos/num_child;
06408     if(cpuutilflag)
06409     {
06410         if (cputime < cputime_res)
06411             cputime = 0.0;
06412     }
06413     if(cpuutilflag)
06414         store_times (walltime, cputime);    /* Must be Before store_dvalue(). */
06415     store_dvalue(total_kilos);
06416 #ifdef NO_PRINT_LLD
06417     if(!silent) printf("\tChildren see throughput for %2ld fwriters \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
06418     if(!silent && !distributed) printf("\tParent sees throughput for %2ld fwriters \t\t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
06419 #else
06420     if(!silent) printf("\tChildren see throughput for %2lld fwriters \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
06421     if(!silent && !distributed) printf("\tParent sees throughput for %2lld fwriters \t\t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
06422 #endif
06423     if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
06424     if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
06425     if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
06426     if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
06427     /* CPU% can be > 100.0 for multiple CPUs */
06428     if(cpuutilflag)
06429     {
06430         if(walltime == 0.0)
06431         {
06432             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
06433                 walltime, cputime, 0.0);
06434         }
06435         else
06436         {
06437             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
06438                 walltime, cputime, 100.0 * cputime / walltime);
06439         }
06440     }
06441     if(Cflag)
06442     {
06443         for(xyz=0;xyz<num_child;xyz++)
06444         {
06445             child_stat = (struct child_stats *) &shmaddr[xyz];
06446             if(cpuutilflag)
06447             {
06448                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
06449                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime, 
06450                     child_stat->cputime, cpu_util(child_stat->cputime, child_stat->walltime));
06451             }
06452             else
06453             {
06454                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
06455                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
06456             }
06457         }
06458     }
06459     if((!distributed) || (distributed && master_iozone))
06460         stop_monitor("Fwrite");
06461     /**********************************************************/
06462     /*************** End of fwrite throughput ****************/
06463     /**********************************************************/
06464     sync();
06465     sleep(2);
06466     if(restf)
06467         sleep((int)rest_val);
06468     if(distributed && master_iozone)
06469     {
06470         stop_master_listen(master_listen_socket);
06471         cleanup_comm();
06472     }
06473 next9:
06474     if(include_tflag)
06475         if(!(include_mask & (long long)FREADER_MASK))
06476             goto next10;
06477     /**************************************************************/
06478     /*** freader throughput tests *********************************/
06479     /**************************************************************/
06480     if((!distributed) || (distributed && master_iozone))
06481         start_monitor("Fread");
06482     toutputindex++;
06483     strcpy(&toutput[toutputindex][0],throughput_tests[12]);
06484     walltime = 0.0;
06485     cputime = 0.0;
06486     jstarttime=0;
06487     total_kilos=0;
06488     if(distributed)
06489     {
06490         use_thread=0;
06491         if(master_iozone)
06492             master_listen_socket=start_master_listen();
06493         else
06494             become_client();
06495     }
06496     if(!use_thread)
06497     {
06498        for(xx = 0; xx< num_child ; xx++){
06499         chid=xx;
06500         childids[xx] = start_child_proc(THREAD_FREAD_TEST,numrecs64,reclen);
06501         if(childids[xx]==-1){
06502             printf("\nFork failed\n");
06503             for(xy = 0; xy< xx ; xy++){
06504                 Kill((long long)childids[xy],(long long)SIGTERM);
06505             }
06506             exit(30);
06507         }
06508         if(childids[xx]==0){
06509 #ifdef _64BIT_ARCH_
06510             thread_fread_test((void *)xx);
06511 #else
06512             thread_fread_test((void *)((long)xx));
06513 #endif
06514         }   
06515        }
06516     }
06517 #ifndef NO_THREADS
06518     else
06519     {
06520        for(xx = 0; xx< num_child ; xx++){   /* Create the children */
06521         if(!barray[xx])
06522         {
06523             barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
06524             if(barray[xx] == 0) {
06525                    perror("Memory allocation failed:");
06526                    exit(26);
06527                 }
06528                 barray[xx] =(char *)(((long)barray[xx] + cache_size ) & 
06529             ~(cache_size-1));
06530         }
06531 #ifdef _64BIT_ARCH_
06532         childids[xx] = mythread_create( thread_fread_test,xx);
06533 #else
06534         childids[xx] = mythread_create( thread_fread_test,(void *)(long)xx);
06535 #endif
06536         if(childids[xx]==-1){
06537             printf("\nThread create failed\n");
06538             for(xy = 0; xy< xx ; xy++){
06539                 kill((pid_t)myid,(int)SIGTERM);
06540             }
06541             exit(31);
06542         }
06543        }
06544     }
06545 #endif
06546     if(myid == (long long)getpid()){
06547         if(distributed && master_iozone)
06548         {
06549             start_master_listen_loop((int) num_child);
06550         }
06551         for(i=0;i<num_child; i++){ /* wait for children to start */
06552             child_stat=(struct child_stats *)&shmaddr[i];
06553             while(child_stat->flag==CHILD_STATE_HOLD)
06554                 Poll((long long)1);
06555         }
06556         for(i=0;i<num_child; i++)
06557         {
06558             child_stat=(struct child_stats *)&shmaddr[i];
06559             child_stat->flag = CHILD_STATE_BEGIN; /* tell children to go */
06560             if(delay_start!=0)
06561                 Poll((long long)delay_start);
06562             if(distributed && master_iozone)
06563                 tell_children_begin(i);
06564         }
06565         starttime1 = time_so_far();
06566         goto jumpend3;
06567     }
06568 jumpend3:
06569     getout=0;
06570     if(myid == (long long)getpid()){    /* Parent here */
06571         for( i = 0; i < num_child; i++){
06572             child_stat = (struct child_stats *)&shmaddr[i];
06573             if(distributed && master_iozone)
06574             {
06575                 printf("\n\tTest running:");
06576                 wait_dist_join();
06577                 break;
06578             }
06579             else
06580             {
06581                if(use_thread)
06582                {
06583                 thread_join(childids[i],(void *)&pstatus);
06584                }
06585                else
06586                {
06587                 wait(0);
06588                }
06589             }
06590             if(!jstarttime)
06591                 jstarttime = time_so_far(); 
06592         }
06593         jtime = (time_so_far()-jstarttime)-time_res; 
06594         if(jtime < (double).000001)
06595         {
06596             jtime=time_res; 
06597         }
06598     }
06599     total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
06600     if(total_time < (double).000001) 
06601     {
06602         total_time=time_res; 
06603         if(rec_prob < reclen)
06604             rec_prob = reclen;
06605         res_prob=1;
06606     }
06607 #ifdef JTIME
06608     total_time=total_time-jtime;/* Remove the join time */
06609     if(!silent) printf("\nJoin time %10.2f\n",jtime);
06610 #endif
06611     
06612     total_kilos=0;
06613     ptotal=0;
06614     min_throughput=max_throughput=min_xfer=0;
06615     if(!silent) printf("\n");
06616     for(xyz=0;xyz<num_child;xyz++){
06617         child_stat=(struct child_stats *)&shmaddr[xyz];
06618         total_kilos+=child_stat->throughput;
06619         ptotal+=child_stat->actual;
06620         if(!min_xfer)
06621             min_xfer=child_stat->actual;
06622         if(child_stat->actual < min_xfer)
06623             min_xfer=child_stat->actual;
06624         if(!min_throughput)
06625             min_throughput=child_stat->throughput;
06626         if(child_stat->throughput < min_throughput)
06627             min_throughput=child_stat->throughput;
06628         if(child_stat->throughput > max_throughput)
06629             max_throughput=child_stat->throughput;
06630         cputime += child_stat->cputime;
06631         /* Get the earliest start time and latest fini time to calc. elapsed time. */
06632         if (child_stat->walltime < child_stat->cputime)
06633             child_stat->walltime = child_stat->cputime;
06634         if (child_stat->walltime > walltime)
06635             walltime = child_stat->walltime;
06636     }
06637     avg_throughput=total_kilos/num_child;
06638     if(cpuutilflag)
06639     {
06640         if (cputime < cputime_res)
06641             cputime = 0.0;
06642     }
06643     if(cpuutilflag)
06644         store_times (walltime, cputime);    /* Must be Before store_dvalue(). */
06645     store_dvalue(total_kilos);
06646 #ifdef NO_PRINT_LLD
06647     if(!silent) printf("\tChildren see throughput for %2ld freaders \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
06648     if(!silent && !distributed) printf("\tParent sees throughput for %2ld freaders \t\t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
06649 #else
06650     if(!silent) printf("\tChildren see throughput for %2lld freaders \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
06651     if(!silent && !distributed) printf("\tParent sees throughput for %2lld freaders \t\t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
06652 #endif
06653     if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
06654     if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
06655     if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
06656     if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
06657     /* CPU% can be > 100.0 for multiple CPUs */
06658     if(cpuutilflag)
06659     {
06660         if(walltime == 0.0)
06661         {
06662             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
06663                 walltime, cputime, 0.0);
06664         }
06665         else
06666         {
06667             if(!silent) printf("\tCPU utilization: Wall time %8.3f    CPU time %8.3f    CPU utilization %6.2f %%\n\n",
06668                 walltime, cputime, 100.0 * cputime / walltime);
06669         }
06670     }
06671     if(Cflag)
06672     {
06673         for(xyz=0;xyz<num_child;xyz++)
06674         {
06675             child_stat = (struct child_stats *) &shmaddr[xyz];
06676             if(cpuutilflag)
06677             {
06678                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
06679                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime, 
06680                     child_stat->cputime, cpu_util(child_stat->cputime, child_stat->walltime));
06681             }
06682             else
06683             {
06684                 if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
06685                     (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
06686             }
06687         }
06688     }
06689     if((!distributed) || (distributed && master_iozone))
06690         stop_monitor("Fread");
06691     /**********************************************************/
06692     /*************** End of fread throughput ******************/
06693     /**********************************************************/
06694     sync();
06695     sleep(2);
06696     if(restf)
06697         sleep((int)rest_val);
06698     if(distributed && master_iozone)
06699     {
06700         stop_master_listen(master_listen_socket);
06701         cleanup_comm();
06702     }
06703 next10:
06704     sleep(2); /* You need this. If you stop and restart the 
06705              master_listen it will fail on Linux */
06706     if (!no_unlink) {
06707         /**********************************************************/
06708         /* Cleanup all of the temporary files             */
06709         /* This is not really a test. It behaves like a test so   */
06710         /* it can unlink all of the same files that the other     */
06711         /* tests left hanging around.                 */
06712         /**********************************************************/
06713         /* Hooks to start the distributed Iozone client/server code */
06714         if(distributed)
06715         {
06716             use_thread=0;  /* Turn of any Posix threads */
06717             if(master_iozone)
06718                 master_listen_socket = start_master_listen();
06719             else
06720                 become_client();
06721         }
06722         if(!use_thread)
06723         {
06724            for(xx = 0; xx< num_child ; xx++){
06725             chid=xx;
06726             childids[xx] = start_child_proc(THREAD_CLEANUP_TEST,numrecs64,reclen);
06727             if(childids[xx]==-1){
06728                 printf("\nFork failed\n");
06729                 for(xy = 0; xy< xx ; xy++){
06730                     Kill((long long)childids[xy],(long long)SIGTERM);
06731                 }
06732                 exit(28);
06733             }
06734             if(childids[xx] == 0){
06735 #ifdef _64BIT_ARCH_
06736                 thread_cleanup_test((void *)xx);
06737 #else
06738                 thread_cleanup_test((void *)((long)xx));
06739 #endif
06740             }   
06741            }
06742         }
06743 #ifndef NO_THREADS
06744         else
06745         {
06746            for(xx = 0; xx< num_child ; xx++){   /* Create the children */
06747 #ifdef _64BIT_ARCH_
06748             childids[xx] = mythread_create( thread_cleanup_test,xx);
06749 #else
06750             childids[xx] = mythread_create( thread_cleanup_test,(void *)(long)xx);
06751 #endif
06752             if(childids[xx]==-1){
06753                 printf("\nThread create failed\n");
06754                 for(xy = 0; xy< xx ; xy++){
06755                     Kill((long long)myid,(long long)SIGTERM);
06756                 }
06757                 exit(29);
06758             }
06759            }
06760         }
06761 #endif
06762         if((long long)myid == getpid())
06763         {
06764             if(distributed && master_iozone)
06765             {
06766                 start_master_listen_loop((int) num_child);
06767             }
06768             for(i=0;i<num_child; i++){
06769                 child_stat = (struct child_stats *)&shmaddr[i];
06770                         /* wait for children to start */
06771                 while(child_stat->flag==CHILD_STATE_HOLD) 
06772                     Poll((long long)1);
06773             }
06774             for(i=0;i<num_child; i++)
06775             {
06776                 child_stat = (struct child_stats *)&shmaddr[i];
06777                 child_stat->flag = CHILD_STATE_BEGIN;   /* tell children to go */
06778                 if(delay_start!=0)
06779                     Poll((long long)delay_start);
06780                 if(distributed && master_iozone)
06781                     tell_children_begin(i);
06782             }
06783         }
06784     
06785         getout=0;
06786         if((long long)myid == getpid()){    /* Parent only here */
06787             for( i = 0; i < num_child; i++){
06788                 child_stat=(struct child_stats *)&shmaddr[i];
06789                 if(distributed && master_iozone)
06790                 {
06791                     printf("\n\tTest cleanup:");
06792                     wait_dist_join();
06793                     break;
06794                 }
06795                 else
06796                 {
06797                    if(use_thread)
06798                    {
06799                     thread_join(childids[i],(void *)&pstatus);
06800                    }
06801                    else
06802                    {
06803                     wait(0);
06804                    }
06805                 }
06806             }
06807         }
06808 
06809         for(xyz=0;xyz<num_child;xyz++){ /* Reset state to 0 (HOLD) */
06810             child_stat=(struct child_stats *)&shmaddr[xyz];
06811             child_stat->flag = CHILD_STATE_HOLD;
06812         }
06813         sync();
06814         sleep(2);
06815         if(distributed && master_iozone)
06816         {
06817             stop_master_listen(master_listen_socket);
06818 #ifdef Windows
06819             /* windows needs time before shutting down sockets */
06820             sleep(1);
06821 #endif
06822             cleanup_comm();
06823         }
06824     }
06825     /********************************************************/
06826     /* End of cleanup                   */
06827     /********************************************************/
06828     sync();
06829     if(!silent) printf("\n");
06830     if(!silent) printf("\n");
06831     return;
06832 }
06833 
06834     
06835 /************************************************************************/
06836 /* Time measurement routines.                       */
06837 /************************************************************************/
06838 
06839 #ifdef HAVE_ANSIC_C
06840 static double
06841 time_so_far(void)
06842 #else
06843 static double
06844 time_so_far()
06845 #endif
06846 {
06847 #ifdef Windows
06848    LARGE_INTEGER freq,counter;
06849    double wintime,bigcounter;
06850    struct timeval tp;
06851    /* For Windows the time_of_day() is useless. It increments in 55 milli 
06852     * second increments. By using the Win32api one can get access to the 
06853     * high performance measurement interfaces. With this one can get back 
06854     * into the 8 to 9 microsecond resolution.
06855     */
06856    if(pit_hostname[0]){
06857      if (pit_gettimeofday(&tp, (struct timezone *) NULL, pit_hostname, 
06858         pit_service) == -1)
06859          perror("pit_gettimeofday");
06860      return ((double) (tp.tv_sec)) + (((double) tp.tv_usec) * 0.000001 );
06861    }
06862    else
06863    {
06864         QueryPerformanceFrequency(&freq);
06865         QueryPerformanceCounter(&counter);
06866         bigcounter=(double)counter.HighPart *(double)0xffffffff +
06867                 (double)counter.LowPart;
06868         wintime = (double)(bigcounter/(double)freq.LowPart);
06869         return((double)wintime);
06870    }
06871 #else
06872 #if defined (OSFV4) || defined(OSFV3) || defined(OSFV5)
06873   struct timespec gp;
06874 
06875   if (getclock(TIMEOFDAY, (struct timespec *) &gp) == -1)
06876     perror("getclock");
06877   return (( (double) (gp.tv_sec)) +
06878     ( ((float)(gp.tv_nsec)) * 0.000000001 ));
06879 #else
06880   struct timeval tp;
06881 
06882   if(pit_hostname[0]){
06883      if (pit_gettimeofday(&tp, (struct timezone *) NULL, pit_hostname, pit_service) == -1)
06884          perror("pit_gettimeofday");
06885      return ((double) (tp.tv_sec)) + (((double) tp.tv_usec) * 0.000001 );
06886   }
06887   else
06888   {
06889      if (gettimeofday(&tp, (struct timezone *) NULL) == -1)
06890          perror("gettimeofday");
06891      return ((double) (tp.tv_sec)) + (((double) tp.tv_usec) * 0.000001 );
06892   }
06893 #endif
06894 #endif
06895 }
06896 
06897 /************************************************************************/
06898 /* FETCHIT ()                               */
06899 /*                                  */
06900 /* Routine to make the on chip data cache hot for this buffer. The  */
06901 /* on chip cache may have been blown by other code in the application   */
06902 /* or in the OS.  Remember, on some machines, the data cache is direct  */
06903 /* mapped and virtual indexed.                      */
06904 /************************************************************************/
06905 
06906 #ifdef HAVE_ANSIC_C
06907 void fetchit(char *buffer,long long length)
06908 #else
06909 void fetchit(buffer,length)
06910 char *buffer;
06911 long long length;
06912 #endif
06913 {
06914     char *where;
06915     volatile long long x[4];
06916     long long i;
06917     where=(char *)buffer;
06918     for(i=0;i<(length/cache_line_size);i++)
06919     {
06920         x[(i & 3)]=*(where);
06921         where+=cache_line_size;
06922         
06923     }
06924 }
06925 
06926 /************************************************************************/
06927 /* Verify that the buffer contains expected pattern         */
06928 /************************************************************************/
06929 /* sverify == 0 means full check of pattern for every byte.             */
06930 /* severify == 1 means partial check of pattern for each page.          */
06931 /* sverify == 2 means no check, but partial touch for each page.        */
06932 /************************************************************************/
06933 
06934 #ifdef HAVE_ANSIC_C
06935 long long 
06936 verify_buffer(volatile char *buffer,long long length, off64_t recnum, long long recsize,unsigned long long patt,
06937     char sverify)
06938 #else
06939 long long 
06940 verify_buffer(buffer,length, recnum, recsize,patt,sverify)
06941 char *buffer;
06942 long long length; 
06943 off64_t recnum; 
06944 long long recsize;
06945 unsigned long long patt;
06946 char sverify;
06947 #endif
06948 {
06949     volatile unsigned long long *where;
06950     volatile unsigned long long dummy;
06951     long *de_ibuf, *de_obuf;
06952     long long j,k;
06953     off64_t file_position=0;
06954     off64_t i;
06955     char *where2;
06956     char *pattern_ptr;
06957     long long mpattern,xx2;
06958     unsigned int seed;
06959     unsigned long x;
06960     unsigned long long value,value1;
06961     unsigned long long a= 0x01020304;
06962     unsigned long long b = 0x05060708;
06963     unsigned long long c= 0x01010101;
06964     unsigned long long d = 0x01010101;
06965     unsigned long long pattern_buf;
06966     int lite = 1;   /* Only validate 1 long when running 
06967                de-deup validation */
06968 
06969     value = (a<<32) | b;
06970     value1 = (c<<32) | d;
06971 
06972     /* printf("Verify Sverify %d verify %d diag_v %d\n",sverify,verify,diag_v); */
06973     x=0;
06974     xx2=chid;
06975     if(share_file)
06976         xx2=(long long)0;
06977     mpattern=patt;
06978     pattern_buf=patt;
06979     where=(unsigned long long *)buffer;
06980     if(sverify == 2)
06981     {
06982       for(i=0;i<(length);i+=page_size)
06983       {
06984           dummy = *where;
06985           where+=(page_size/sizeof(long long));
06986       }
06987       return(0);
06988     }
06989     if(dedup)
06990     {
06991         gen_new_buf((char *)dedup_ibuf,(char *)dedup_temp, (long)recnum, (int)length,(int)dedup, (int) dedup_interior, dedup_compress, 0);
06992         de_ibuf = (long *)buffer;
06993         de_obuf = (long *)dedup_temp;
06994         if(lite)    /* short touch to reduce intrusion */
06995             length = (long) sizeof(long);
06996         for(i=0;i<length/sizeof(long);i++)
06997         {
06998             if(de_ibuf[i]!= de_obuf[i])
06999             {
07000                 if(!silent)
07001 #ifdef NO_PRINT_LLD
07002                    printf("\nDedup mis-compare at %ld\n",
07003                     (long long)((recnum*recsize)+(i*sizeof(long))) );
07004 #else
07005                    printf("\nDedup mis-compare at %lld\n",
07006                     (long long)((recnum*recsize)+(i*sizeof(long))) );
07007                    printf("Found %.lx Expecting %.lx \n",de_ibuf[i], de_obuf[i]);
07008 #endif
07009                 return(1);
07010             }
07011         }
07012         return(0);
07013     }
07014     if(diag_v)
07015     {
07016         if(no_unlink)
07017             base_time=0;
07018         seed= (unsigned int)(base_time+xx2+recnum);
07019             srand(seed);
07020             mpattern=(long long)rand();
07021             mpattern=(mpattern<<48) | (mpattern<<32) | (mpattern<<16) | mpattern;
07022         mpattern=mpattern+value;
07023     }
07024 
07025     /* printf("verify patt %llx CHid %d\n",mpattern,chid);*/
07026 
07027     where=(unsigned long long *)buffer;
07028 
07029     if(!verify)
07030         printf("\nOOPS You have entered verify_buffer unexpectedly !!! \n");
07031 
07032     if(sverify == 1)
07033     {
07034       for(i=0;i<(length);i+=page_size)
07035       {
07036           if((unsigned long long)(*where) != (unsigned long long)((pattern_buf<<32) | pattern_buf))
07037           {
07038            file_position = (off64_t)( (recnum * recsize)+ i);
07039     printf("\n\n");
07040 #ifdef NO_PRINT_LLD
07041     printf("Error in file: Found ?%lx? Expecting ?%lx? addr %lx\n",*where, (long long)((pattern_buf<<32)|pattern_buf),where);
07042     printf("Error in file: Position %ld \n",file_position);
07043     printf("Record # %ld Record size %ld kb \n",recnum,recsize/1024);
07044     printf("where %8.8llx loop %ld\n",where,i);
07045 #else
07046     printf("Error in file: Found ?%llx? Expecting ?%llx? addr %lx\n",*where, (long long)((pattern_buf<<32)|pattern_buf),((long)where));
07047     printf("Error in file: Position %lld \n",file_position);
07048     printf("Record # %lld Record size %lld kb \n",recnum,recsize/1024);
07049     printf("where %8.8lx loop %lld\n",(long)where,(long long)i);
07050 #endif
07051            return(1);
07052           }
07053           where+=(page_size/sizeof(long long));
07054       }
07055     }
07056     if(sverify == 0)
07057     {
07058       for(i=0;i<(length/cache_line_size);i++)
07059       {
07060        for(j=0;j<(cache_line_size/sizeof(long long));j++)
07061        {
07062               if(diag_v)
07063           {
07064          pattern_buf=mpattern;
07065           }
07066           else
07067               {
07068         pattern_buf= mpattern<<32 | mpattern;
07069           }
07070 
07071           pattern_ptr =(char *)&pattern_buf;
07072 
07073           if(*where != (unsigned long long)pattern_buf)
07074           {
07075            file_position = (off64_t)( (recnum * recsize))+
07076             ((i*cache_line_size)+(j*sizeof(long long)));
07077            where2=(char *)where;
07078            for(k=0;k<sizeof(long long);k++){
07079             if(*where2 != *pattern_ptr)
07080                 break;
07081             where2++;
07082             pattern_ptr++;
07083            }
07084            file_position+=k;
07085     printf("\n\n");
07086 #ifdef NO_PRINT_LLD
07087     printf("Error in file: Position %ld %ld %ld \n",i,j,k);
07088     printf("Error in file: Position %ld \n",file_position);
07089     printf("Record # %ld Record size %ld kb \n",recnum,recsize/1024);
07090 #else
07091     printf("Error in file: Position %lld %lld %lld \n",i,j,k);
07092     printf("Error in file: Position %lld \n",file_position);
07093     printf("Record # %lld Record size %lld kb \n",recnum,recsize/1024);
07094 #endif
07095     printf("Found pattern: Char >>%c<< Expecting >>%c<<\n", *where2,*pattern_ptr);
07096     printf("Found pattern: Hex >>%x<< Expecting >>%x<<\n", *where2,*pattern_ptr);
07097            return(1);
07098           }
07099           where++;
07100           if(diag_v)
07101              mpattern=mpattern+value1;
07102        }    
07103       }
07104     }
07105     return(0);
07106 }
07107 /************************************************************************/
07108 /* Fill  the buffer                             */
07109 /************************************************************************/
07110 #ifdef HAVE_ANSIC_C
07111 void 
07112 fill_buffer(char *buffer,long long length,long long pattern,char sverify,long long recnum)
07113 #else
07114 void 
07115 fill_buffer(buffer,length,pattern,sverify,recnum)
07116 char *buffer;
07117 long long length;
07118 long long pattern;
07119 long long recnum;
07120 char sverify;
07121 #endif
07122 {
07123     unsigned long long *where;
07124     long long i,j,xx2;
07125     long long mpattern;
07126     unsigned int seed;
07127     unsigned long x;
07128     unsigned long long value,value1;
07129     unsigned long long a = 0x01020304;
07130     unsigned long long b = 0x05060708;
07131     unsigned long long c = 0x01010101;
07132     unsigned long long d = 0x01010101;
07133 
07134     value = (a << 32) | b;
07135     value1 = (c << 32) | d;
07136 
07137     xx2=chid;
07138     if(share_file)
07139         xx2=(long long)0;
07140     x=0;
07141     mpattern=pattern;
07142     /* printf("Fill: Sverify %d verify %d diag_v %d\n",sverify,verify,diag_v);*/
07143     if(dedup)
07144     {
07145         gen_new_buf((char *)dedup_ibuf,(char *)buffer, (long)recnum, (int)length,(int)dedup, (int) dedup_interior, dedup_compress, 1);
07146         return;
07147     }
07148     if(diag_v)
07149     {
07150         /*if(client_iozone)
07151             base_time=0;
07152         */
07153         if(no_unlink)
07154             base_time=0;
07155         seed= (unsigned int)(base_time+xx2+recnum);
07156             srand(seed);
07157         mpattern=(long long)rand();
07158         mpattern=(mpattern<<48) | (mpattern<<32) | (mpattern<<16) | mpattern;
07159         mpattern=mpattern+value;
07160     }
07161     where=(unsigned long long *)buffer;
07162     if(sverify == 1)
07163     {
07164         for(i=0;i<(length);i+=page_size)
07165         {
07166             *where = (long long)((pattern<<32) | pattern);
07167             where+=(page_size/sizeof(long long)); 
07168             /* printf("Filling page %lld \n",i/page_size);*/
07169         }   
07170     }
07171     else
07172     {
07173         for(i=0;i<(length/cache_line_size);i++)
07174         {
07175             for(j=0;j<(cache_line_size/sizeof(long long));j++)
07176             {
07177                 if(diag_v)
07178                 {
07179                     *where = (long long)(mpattern);
07180                     mpattern=mpattern+value1;
07181                 }
07182                 else
07183                     *where = (long long)((pattern<<32) | pattern);
07184                 where++;
07185             }   
07186         }
07187     }
07188 }
07189 
07190 /************************************************************************/
07191 /* PURGEIT()                                */
07192 /*                                  */
07193 /* Routine to make the on chip data cache cold for this buffer.     */
07194 /* Remember, on some machines, the data cache is direct mapped and  */
07195 /* virtual indexed.                         */
07196 /************************************************************************/
07197 
07198 #ifdef HAVE_ANSIC_C
07199 void 
07200 purgeit(char *buffer,long long reclen)
07201 #else
07202 void 
07203 purgeit(buffer,reclen)
07204 char *buffer;
07205 long long reclen;
07206 #endif
07207 {
07208     char *where;
07209     long rsize;
07210     long tsize;
07211     VOLATILE long long x[200];
07212     long i,cache_lines_per_rec;
07213     long cache_lines_per_cache;
07214     tsize = 200;
07215     cache_lines_per_rec = (long)(reclen/cache_line_size);
07216     cache_lines_per_cache = (long)(cache_size/cache_line_size);
07217     rsize = (long)l_min((long long)cache_lines_per_rec,(long long)cache_lines_per_cache);
07218 #ifdef _64BIT_ARCH_
07219     where=(char *)pbuffer + ((unsigned long long)buffer & (cache_size-1));
07220 #else
07221     where=(char *)pbuffer + ((long)buffer & ((long)cache_size-1));
07222 #endif
07223     for(i=0;i<(rsize);i++)
07224     {
07225         x[i%tsize]=*(where);
07226         where+=cache_line_size;
07227 
07228     }
07229 }
07230 
07231 #ifdef HAVE_ANSIC_C
07232 void
07233 prepage(char *buffer,long long reclen)
07234 #else
07235 void
07236 prepage(buffer, reclen)
07237 char *buffer;
07238 long long reclen; 
07239 #endif
07240 {
07241     char *where;
07242     long long i;
07243     where=(char *)buffer;
07244     for(i=0;i<(reclen/cache_line_size);i++)
07245     {
07246         *(where)=PATTERN;
07247         where+=cache_line_size;
07248     }
07249 }
07250 
07251 /************************************************************************/
07252 /* write_perf_test ()                               */
07253 /* Write and re-write test                      */
07254 /************************************************************************/
07255 #ifdef HAVE_ANSIC_C
07256 void write_perf_test(off64_t kilo64,long long reclen ,long long *data1,long long *data2)
07257 #else
07258 void write_perf_test(kilo64,reclen ,data1,data2)
07259 off64_t kilo64;
07260 long long reclen;
07261 long long *data1;
07262 long long *data2;
07263 #endif
07264 {
07265     double starttime1;
07266     double writetime[2];
07267     double walltime[2], cputime[2];
07268     double qtime_start,qtime_stop;
07269     double hist_time;
07270     double compute_val = (double)0;
07271 #ifdef unix
07272     double qtime_u_start,qtime_u_stop;
07273     double qtime_s_start,qtime_s_stop;
07274 #endif
07275     long long i,j;
07276     off64_t numrecs64,traj_offset;
07277     off64_t lock_offset=0;
07278     long long Index = 0;
07279     long long file_flags = 0;
07280     long long traj_size;
07281     unsigned long long writerate[2];
07282     off64_t filebytes64;
07283     int ltest;
07284     char *maddr;
07285     char *wmaddr,*free_addr;
07286     char *pbuff;
07287     char *nbuff;
07288     int fd,wval;
07289 #ifdef ASYNC_IO
07290     struct cache *gc=0;
07291 #else
07292     long long *gc=0;
07293 #endif
07294 
07295     int test_foo;
07296 
07297 #ifdef unix
07298     qtime_u_start=qtime_u_stop=0;
07299     qtime_s_start=qtime_s_stop=0;
07300 #endif
07301     nbuff=wmaddr=free_addr=0;
07302     traj_offset=0;
07303     test_foo=0;
07304     hist_time=qtime_start=qtime_stop=0;
07305     maddr=0;
07306     pbuff=mainbuffer;
07307     if(w_traj_flag)
07308     {
07309         filebytes64 = w_traj_fsize;
07310         numrecs64=w_traj_ops;
07311     }
07312     else
07313     {
07314         numrecs64 = (kilo64*1024)/reclen;
07315         filebytes64 = numrecs64*reclen;
07316     }
07317 
07318     if(Q_flag && (!wol_opened))
07319     {
07320         wol_opened++;
07321         wqfd=fopen("wol.dat","a");
07322         if(wqfd==0)
07323         {
07324             printf("Unable to open wol.dat\n");
07325             exit(40);
07326         }
07327         fprintf(wqfd,"Offset in Kbytes   Latency in microseconds  Transfer size in bytes\n");
07328         rwqfd=fopen("rwol.dat","a");
07329         if(rwqfd==0)
07330         {
07331             printf("Unable to open rwol.dat\n");
07332             exit(41);
07333         }
07334         fprintf(rwqfd,"Offset in Kbytes   Latency in microseconds  Transfer size in bytes\n");
07335     }
07336     fd = 0;
07337     if(oflag)
07338         file_flags = O_RDWR|O_SYNC;
07339     else
07340         file_flags = O_RDWR;
07341 #if defined(O_DSYNC)
07342     if(odsync)
07343         file_flags |= O_DSYNC;
07344 #endif
07345 #if defined(_HPUX_SOURCE) || defined(linux) || defined(__FreeBSD__) || defined(__DragonFly__)
07346     if(read_sync)
07347         file_flags |=O_RSYNC|O_SYNC;
07348 #endif
07349 
07350 #if ! defined(DONT_HAVE_O_DIRECT)
07351 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
07352     if(direct_flag)
07353         file_flags |=O_DIRECT;
07354 #endif
07355 #if defined(TRU64)
07356     if(direct_flag)
07357         file_flags |=O_DIRECTIO;
07358 #endif
07359 #endif
07360 
07361 /* Sanity check */
07362 /* Some filesystems do not behave correctly and fail
07363  * when this sequence is performned. This is a very
07364  * bad thing. It breaks many applications and lurks
07365  * around quietly. This code should never get
07366  * triggered, but in the case of running iozone on
07367  * an NFS client, the filesystem type on the server
07368  * that is being exported can cause this failure.
07369  * If this failure happens, then the NFS client is
07370  * going to going to have problems, but the acutal
07371  * problem is the filesystem on the NFS server.
07372  * It's not NFS, it's the local filesystem on the
07373  * NFS server that is not correctly permitting
07374  * the sequence to function.
07375  */
07376 /* _SUA_ Services for Unix Applications, under Windows
07377     does not have a truncate, so this must be skipped */
07378 #if !defined(_SUA_)
07379         if((fd = I_OPEN(filename, (int)O_CREAT|O_WRONLY,0))<0)
07380         {
07381                 printf("\nCan not open temp file: %s\n",
07382                         filename);
07383                 perror("open");
07384                 exit(44);
07385         }
07386         if(!notruncate)
07387         {
07388             if(check_filename(filename))
07389             {
07390                 wval=ftruncate(fd,0);
07391                 if(wval < 0)
07392                 {
07393                     printf("\n\nSanity check failed. Do not deploy this filesystem in a production environment !\n");
07394                     exit(44);
07395                 }
07396             }
07397             close(fd);
07398 
07399             if(check_filename(filename))
07400                 unlink(filename);
07401         }
07402 /* Sanity check */
07403 
07404 #endif
07405     if(noretest)
07406         ltest=1;
07407     else
07408         ltest=2;
07409 
07410     for( j=0; j<ltest; j++)
07411     {
07412         if(cpuutilflag)
07413         {
07414             walltime[j] = time_so_far();
07415             cputime[j]  = cputime_so_far();
07416         }
07417         if(Uflag) /* Unmount and re-mount the mountpoint */
07418         {
07419             purge_buffer_cache();
07420         }
07421         if(j==0)
07422         {
07423 #if defined(Windows)
07424                 if(unbuffered)
07425                 {
07426                     hand=CreateFile(filename,
07427                   GENERIC_READ|GENERIC_WRITE,
07428                       FILE_SHARE_WRITE|FILE_SHARE_READ,
07429                   NULL,OPEN_ALWAYS,FILE_FLAG_NO_BUFFERING|
07430                   FILE_FLAG_WRITE_THROUGH|FILE_FLAG_POSIX_SEMANTICS,
07431                   NULL);
07432                     }
07433                 else
07434                 {
07435 #endif
07436                 if(!notruncate)
07437                 {
07438                     if((fd = I_CREAT(filename, 0640))<0)
07439                     {
07440                         printf("\nCan not create temp file: %s\n", 
07441                             filename);
07442                         perror("creat");
07443                         exit(42);
07444                     }
07445                 }
07446 #if defined(Windows)
07447             }
07448 #endif
07449         }
07450 #if defined(Windows)
07451         if(unbuffered)
07452             CloseHandle(hand);
07453         else
07454         {
07455 #endif
07456           if(fd) 
07457             close(fd);
07458 #if defined(Windows)
07459         }
07460 #endif
07461 
07462 #if defined(Windows)
07463             if(unbuffered)
07464             {
07465                 hand=CreateFile(filename,
07466               GENERIC_READ|GENERIC_WRITE,
07467                   FILE_SHARE_WRITE|FILE_SHARE_READ,
07468               NULL,OPEN_EXISTING,FILE_FLAG_NO_BUFFERING|
07469               FILE_FLAG_WRITE_THROUGH|FILE_FLAG_POSIX_SEMANTICS,
07470               NULL);
07471                 }
07472             else
07473             {
07474 #endif
07475            if((fd = I_OPEN(filename, (int)file_flags,0))<0)
07476            {
07477             printf("\nCan not open temp file: %s\n", 
07478                 filename);
07479             perror("open");
07480             exit(44);
07481            }
07482 #if defined(Windows)
07483         }
07484 #endif
07485 #ifdef VXFS
07486         if(direct_flag)
07487         {
07488             ioctl(fd,VX_SETCACHE,VX_DIRECT);
07489             ioctl(fd,VX_GETCACHE,&test_foo);
07490             if(test_foo == 0)
07491             {
07492                 if(!client_iozone)
07493                   printf("\nVxFS advanced setcache feature not available.\n");
07494                 exit(3);
07495             }
07496         }
07497 #endif
07498 #if defined(solaris)
07499                if(direct_flag)
07500                {
07501                        test_foo = directio(fd, DIRECTIO_ON);
07502                        if(test_foo != 0)
07503                        {
07504                                if(!client_iozone)
07505                                  printf("\ndirectio not available.\n");
07506                                exit(3);
07507                        }
07508                }
07509 #endif
07510 
07511         if(file_lock)
07512             if(mylockf((int) fd, (int) 1, (int)0)!=0)
07513                 printf("File lock for write failed. %d\n",errno);
07514         if(mmapflag)
07515         {
07516             maddr=(char *)initfile(fd,filebytes64,1,PROT_READ|PROT_WRITE);
07517         }
07518         if(mmap_mix)
07519         {
07520             wval=write(fd, pbuff, (size_t) page_size);
07521             if(wval != page_size)
07522             {
07523 #ifdef NO_PRINT_LLD
07524                     printf("\nError writing block %ld, fd= %d\n", (long long)0, fd);
07525 #else
07526                     printf("\nError writing block %lld, fd= %d\n", (long long)0, fd);
07527 #endif
07528                 if(wval==-1)
07529                     perror("write");
07530                 signal_handler();
07531             }
07532             I_LSEEK(fd,0,SEEK_SET);
07533         };
07534         wval=fsync(fd);
07535         if(wval==-1){
07536             perror("fsync");
07537             signal_handler();
07538         }
07539 #ifdef ASYNC_IO
07540         if(async_flag)
07541             async_init(&gc,fd,direct_flag);
07542 #endif
07543         pbuff=mainbuffer;
07544         if(fetchon)
07545             fetchit(pbuff,reclen);
07546         if(verify || dedup || dedup_interior)
07547             fill_buffer(pbuff,reclen,(long long)pattern,sverify,(long long)0);
07548         starttime1 = time_so_far();
07549 #ifdef unix
07550         if(Q_flag)
07551         {
07552             qtime_u_start=utime_so_far();
07553             qtime_s_start=stime_so_far();
07554         }
07555 #endif
07556         if(w_traj_flag)
07557         {
07558             rewind(w_traj_fd);
07559         }
07560         compute_val=(double)0;
07561         w_traj_ops_completed=0;
07562         w_traj_bytes_completed=0;
07563         for(i=0; i<numrecs64; i++){
07564             if(w_traj_flag)
07565             {
07566                 traj_offset=get_traj(w_traj_fd, (long long *)&traj_size,(float *)&compute_time,(long)1);
07567                 reclen=traj_size;
07568 #if defined(Windows)
07569             if(unbuffered)
07570               SetFilePointer(hand,(LONG)traj_offset,0,FILE_BEGIN);
07571             else
07572 #endif
07573                 I_LSEEK(fd,traj_offset,SEEK_SET);
07574             }
07575             if(Q_flag)
07576             {
07577 #if defined(Windows)
07578             if(unbuffered)
07579               traj_offset=SetFilePointer(hand,(LONG)0,0,FILE_CURRENT);
07580             else
07581 #endif
07582                 traj_offset=I_LSEEK(fd,0,SEEK_CUR);
07583             }
07584             if(rlocking)
07585             {
07586                 lock_offset=I_LSEEK(fd,0,SEEK_CUR);
07587                 mylockr((int) fd, (int) 1, (int)0,
07588                   lock_offset, reclen);
07589             }
07590             if((verify && diag_v) || dedup || dedup_interior)
07591                 fill_buffer(pbuff,reclen,(long long)pattern,sverify,i);
07592             if(compute_flag)
07593                 compute_val+=do_compute(compute_time);
07594             if(multi_buffer)
07595             {
07596                 Index +=reclen;
07597                 if(Index > (MAXBUFFERSIZE-reclen))
07598                     Index=0;
07599                 pbuff = mbuffer + Index;    
07600                 if(verify || dedup || dedup_interior)
07601                     fill_buffer(pbuff,reclen,(long long)pattern,sverify,(long long)0);
07602             }
07603             if(async_flag && no_copy_flag)
07604             {
07605                 free_addr=nbuff=(char *)malloc((size_t)reclen+page_size);
07606                 nbuff=(char *)(((long)nbuff+(long)page_size) & (long)~(page_size-1));
07607                 if(verify || dedup || dedup_interior)
07608                     fill_buffer(nbuff,reclen,(long long)pattern,sverify,i);
07609                 if(purge)
07610                     purgeit(nbuff,reclen);
07611             }
07612             if(purge)
07613                 purgeit(pbuff,reclen);
07614             if(Q_flag || hist_summary)
07615             {
07616                 qtime_start=time_so_far();
07617             }
07618             if(mmapflag)
07619             {
07620                 wmaddr = &maddr[i*reclen];
07621                 fill_area((long long*)pbuff,(long long*)wmaddr,(long long)reclen);
07622                 if(!mmapnsflag)
07623                 {
07624                   if(mmapasflag)
07625                     msync(wmaddr,(size_t)reclen,MS_ASYNC);
07626                   if(mmapssflag)
07627                     msync(wmaddr,(size_t)reclen,MS_SYNC);
07628                 }
07629             }
07630             else
07631             {
07632               if(async_flag)
07633               {
07634                  if(no_copy_flag)
07635                    async_write_no_copy(gc, (long long)fd, nbuff, reclen, (i*reclen), depth,free_addr);
07636                  else
07637                    async_write(gc, (long long)fd, pbuff, reclen, (i*reclen), depth);
07638               }
07639               else
07640               {
07641 #if defined(Windows)
07642                     if(unbuffered)
07643                     {
07644                 WriteFile(hand, pbuff, reclen,(LPDWORD)&wval,
07645                     0);
07646                 }
07647                 else
07648                 {
07649 #endif
07650                 wval=write(fd, pbuff, (size_t ) reclen);
07651                 if(wval != reclen)
07652                 {
07653 #ifdef NO_PRINT_LLD
07654                     printf("\nError writing block %ld, fd= %d\n", i,
07655                      fd);
07656 #else
07657                     printf("\nError writing block %lld, fd= %d\n", i,
07658                      fd);
07659 #endif
07660                     if(wval == -1)
07661                     perror("write");
07662                 signal_handler();
07663                 }
07664 #if defined(Windows)
07665                 }
07666 #endif
07667               }
07668             }
07669             if(hist_summary)
07670             {
07671                 qtime_stop=time_so_far();
07672                 hist_time =(qtime_stop-qtime_start-time_res);
07673                 hist_insert(hist_time);
07674             }
07675             if(Q_flag)
07676             {
07677                 qtime_stop=time_so_far();
07678                 if(j==0)
07679 #ifdef NO_PRINT_LLD
07680                 fprintf(wqfd,"%10.1ld %10.0f %10.1ld\n",(traj_offset)/1024,((qtime_stop-qtime_start-time_res))*1000000,reclen);
07681                 else
07682                 fprintf(rwqfd,"%10.1ld %10.0f %10.1ld\n",(traj_offset)/1024,((qtime_stop-qtime_start-time_res))*1000000,reclen);
07683 #else
07684                 fprintf(wqfd,"%10.1lld %10.0f %10.1lld\n",(traj_offset)/1024,((qtime_stop-qtime_start-time_res))*1000000,reclen);
07685                 else
07686                 fprintf(rwqfd,"%10.1lld %10.0f %10.1lld\n",(traj_offset)/1024,((qtime_stop-qtime_start-time_res))*1000000,reclen);
07687 #endif
07688             }
07689             w_traj_ops_completed++;
07690             w_traj_bytes_completed+=reclen;
07691             if(rlocking)
07692             {
07693                 mylockr((int) fd, (int) 0, (int)0,
07694                   lock_offset, reclen);
07695             }
07696         }
07697 #ifdef unix
07698         if(Q_flag)
07699         {
07700            qtime_u_stop=utime_so_far();
07701            qtime_s_stop=stime_so_far();
07702            if(j==0)
07703              fprintf(wqfd,"\nSystem time %10.3f User time %10.3f Real %10.3f  (seconds)\n",
07704                 (qtime_s_stop-qtime_s_start)/sc_clk_tck,
07705                 (qtime_u_stop-qtime_u_start)/sc_clk_tck,
07706                 time_so_far()-starttime1);
07707            else
07708             fprintf(rwqfd,"\nSystem time %10.3f User time %10.3f Real %10.3f  (seconds)\n",
07709                 (qtime_s_stop-qtime_s_start)/sc_clk_tck,
07710                 (qtime_u_stop-qtime_u_start)/sc_clk_tck,
07711                 time_so_far()-starttime1);
07712         }
07713 #endif
07714 
07715 #ifdef ASYNC_IO
07716         if(async_flag)
07717         {
07718             end_async(gc);
07719             gc=0;
07720         }
07721 #endif
07722         if(include_flush)
07723         {
07724             if(mmapflag){
07725                 msync(maddr,(size_t)filebytes64,MS_SYNC);
07726             }
07727             else
07728             {
07729                 wval=fsync(fd);
07730                 if(wval==-1){
07731                     perror("fsync");
07732                     signal_handler();
07733                 }
07734             }
07735         }
07736         if(file_lock)
07737             if(mylockf((int) fd,(int)0,(int)0))
07738                 printf("Unlock failed %d\n",errno);
07739         if(include_close)
07740         {
07741             if(mmapflag)
07742             {
07743                 mmap_end(maddr,(unsigned long long)filebytes64);
07744             }
07745 #if defined(Windows)
07746             if(unbuffered)
07747                 CloseHandle(hand);
07748             else
07749 #endif
07750                wval=close(fd);
07751                if(wval==-1){
07752                 perror("close");
07753                 signal_handler();
07754                }
07755         }
07756         writetime[j] = ((time_so_far() - starttime1)-time_res)
07757             -compute_val;
07758         if(writetime[j] < (double).000001) 
07759         {
07760             writetime[j]=time_res;
07761             if(rec_prob < reclen)
07762                 rec_prob = reclen;
07763             res_prob=1;
07764         }
07765         if(!include_close)
07766         {
07767             if(mmapflag)
07768                 msync(maddr,(size_t)filebytes64,MS_SYNC);/* Clean up before read starts */
07769             else
07770             {
07771                 wval=fsync(fd);
07772                 if(wval==-1){
07773                     perror("fsync");
07774                     signal_handler();
07775                 }
07776             }
07777             if(mmapflag)
07778             {
07779                 mmap_end(maddr,(unsigned long long)filebytes64);
07780             }
07781 #if defined(Windows)
07782             if(unbuffered)
07783                 CloseHandle(hand);
07784             else
07785 #endif
07786             wval=close(fd);
07787             if(wval==-1){
07788                 perror("close");
07789                 signal_handler();
07790             }
07791         }
07792         if(cpuutilflag)
07793         {
07794             cputime[j]  = cputime_so_far() - cputime[j];
07795             if (cputime[j] < cputime_res)
07796                 cputime[j] = 0.0;
07797             walltime[j] = time_so_far() - walltime[j];
07798             if (walltime[j] < cputime[j])
07799                walltime[j] = cputime[j];
07800         }
07801         if(restf)
07802             sleep((int)rest_val);
07803     }
07804     if(OPS_flag || MS_flag){
07805        filebytes64=w_traj_ops_completed;
07806        /*filebytes64=filebytes64/reclen;*/
07807     }else
07808        filebytes64=w_traj_bytes_completed;
07809         
07810         for(j=0;j<ltest;j++)
07811         {
07812         if(MS_flag)
07813         {
07814             writerate[j]=1000000.0*(writetime[j] / (double)filebytes64);
07815             continue;
07816         }
07817               else
07818             {
07819                   writerate[j] = 
07820                     (unsigned long long) ((double) filebytes64 / writetime[j]);
07821             }
07822         if(!(OPS_flag || MS_flag))
07823            writerate[j] >>= 10;
07824     }
07825     data1[0]=writerate[0];
07826     if(noretest)
07827     {   
07828         writerate[1]=(long long) 0;
07829         if(cpuutilflag)
07830         {
07831             walltime[1]=0.0;
07832             cputime[1]=0.0;
07833         }
07834     }
07835     /* Must save walltime & cputime before calling store_value() for each/any cell.*/
07836     if(cpuutilflag)
07837         store_times(walltime[0], cputime[0]);
07838     store_value((off64_t)writerate[0]);
07839     if(cpuutilflag)
07840         store_times(walltime[1], cputime[1]);
07841     store_value((off64_t)writerate[1]);
07842 #ifdef NO_PRINT_LLD
07843     if(!silent) printf("%8ld",writerate[0]);
07844     if(!silent) printf("%8ld",writerate[1]);
07845     if(!silent) fflush(stdout);
07846 #else
07847     if(!silent) printf("%8lld",writerate[0]);
07848     if(!silent) printf("%8lld",writerate[1]);
07849     if(!silent) fflush(stdout);
07850 #endif
07851 }
07852 /************************************************************************/
07853 /* fwrite_perf_test ()                              */
07854 /* fWrite and fre-write test                        */
07855 /************************************************************************/
07856 #ifdef HAVE_ANSIC_C
07857 void fwrite_perf_test(off64_t kilo64,long long reclen ,long long *data1,long long *data2)
07858 #else
07859 void fwrite_perf_test(kilo64,reclen ,data1,data2)
07860 off64_t kilo64;
07861 long long reclen;
07862 long long *data1;
07863 long long *data2;
07864 #endif
07865 {
07866     double starttime1;
07867     double writetime[2];
07868     double walltime[2], cputime[2];
07869     double compute_val = (double)0;
07870     long long i,j;
07871     off64_t numrecs64;
07872     long long Index = 0;
07873     unsigned long long writerate[2];
07874     off64_t filebytes64;
07875     FILE *stream = NULL;
07876     int fd;
07877     int wval;
07878     int ltest;
07879     char *how;
07880     char *stdio_buf;
07881 
07882     if(mmapflag || async_flag)
07883         return;
07884     numrecs64 = (kilo64*1024)/reclen;
07885     filebytes64 = numrecs64*reclen;
07886     stdio_buf=(char *)malloc((size_t)reclen);
07887     if(noretest)
07888         ltest=1;
07889     else
07890         ltest=2;
07891 
07892     for( j=0; j<ltest; j++)
07893     {
07894         if(cpuutilflag)
07895         {
07896             walltime[j] = time_so_far();
07897             cputime[j]  = cputime_so_far();
07898         }
07899         if(Uflag) /* Unmount and re-mount the mountpoint */
07900         {
07901             purge_buffer_cache();
07902         }
07903         if(j==0)
07904         {
07905             if(check_filename(filename))
07906                 how="r+"; /* file exists, don't create and zero a new one. */
07907             else
07908                 how="w+"; /* file doesn't exist. create it. */
07909         }
07910         else
07911             how="r+"; /* re-tests should error out if file does not exist. */
07912 #ifdef IRIX64
07913         if((stream=(FILE *)fopen(filename,how)) == 0)
07914         {
07915             printf("\nCan not fdopen temp file: %s %lld\n", 
07916                 filename,errno);
07917             perror("fdopen");
07918             exit(48);
07919         }
07920 #else
07921         if((stream=(FILE *)I_FOPEN(filename,how)) == 0)
07922         {
07923 #ifdef NO_PRINT_LLD
07924             printf("\nCan not fdopen temp file: %s %d\n", 
07925                 filename,errno);
07926 #else
07927             printf("\nCan not fdopen temp file: %s %d\n", 
07928                 filename,errno);
07929 #endif
07930             perror("fdopen");
07931             exit(49);
07932         }
07933 #endif
07934         fd=fileno(stream);
07935         fsync(fd);
07936         setvbuf(stream,stdio_buf,_IOFBF,reclen);
07937         buffer=mainbuffer;
07938         if(fetchon)
07939             fetchit(buffer,reclen);
07940         if(verify || dedup || dedup_interior)
07941             fill_buffer(buffer,reclen,(long long)pattern,sverify,(long long)0);
07942         starttime1 = time_so_far();
07943         compute_val=(double)0;
07944         for(i=0; i<numrecs64; i++){
07945             if(compute_flag)
07946                 compute_val+=do_compute(compute_time);
07947             if(multi_buffer)
07948             {
07949                 Index +=reclen;
07950                 if(Index > (MAXBUFFERSIZE-reclen))
07951                     Index=0;
07952                 buffer = mbuffer + Index;   
07953             }
07954             if((verify & diag_v) || dedup || dedup_interior)
07955                 fill_buffer(buffer,reclen,(long long)pattern,sverify,i);
07956             if(purge)
07957                 purgeit(buffer,reclen);
07958             if(fwrite(buffer, (size_t) reclen, 1, stream) != 1)
07959             {
07960 #ifdef NO_PRINT_LLD
07961                     printf("\nError fwriting block %ld, fd= %d\n", i,
07962                      fd);
07963 #else
07964                     printf("\nError fwriting block %lld, fd= %d\n", i,
07965                      fd);
07966 #endif
07967                 perror("fwrite");
07968                 signal_handler();
07969             }
07970         }
07971 
07972         if(include_flush)
07973         {
07974             fflush(stream);
07975             wval=fsync(fd);
07976             if(wval==-1){
07977                 perror("fsync");
07978                 signal_handler();
07979             }
07980         }
07981         if(include_close)
07982         {
07983             wval=fclose(stream);
07984             if(wval==-1){
07985                 perror("fclose");
07986                 signal_handler();
07987             }
07988         }
07989         writetime[j] = ((time_so_far() - starttime1)-time_res)
07990             -compute_val;
07991         if(writetime[j] < (double).000001) 
07992         {
07993             writetime[j]= time_res;
07994             if(rec_prob < reclen)
07995                 rec_prob = reclen;
07996             res_prob=1;
07997         }
07998         if(!include_close)
07999         {
08000             wval=fflush(stream);
08001             if(wval==-1){
08002                 perror("fflush");
08003                 signal_handler();
08004             }
08005             wval=fsync(fd);
08006             if(wval==-1){
08007                 perror("fsync");
08008                 signal_handler();
08009             }
08010             wval=fclose(stream);
08011             if(wval==-1){
08012                 perror("fclose");
08013                 signal_handler();
08014             }
08015         }
08016 
08017         if(cpuutilflag)
08018         {
08019             cputime[j]  = cputime_so_far() - cputime[j];
08020             if (cputime[j] < cputime_res)
08021                 cputime[j] = 0.0;
08022             walltime[j] = time_so_far() - walltime[j];
08023             if (walltime[j] < cputime[j])
08024                walltime[j] = cputime[j];
08025         }
08026         if(restf)
08027             sleep((int)(int)rest_val);
08028     }
08029     free(stdio_buf);
08030     if(OPS_flag || MS_flag){
08031        filebytes64=filebytes64/reclen;
08032     }
08033         for(j=0;j<ltest;j++)
08034         {
08035         if(MS_flag)
08036         {
08037             writerate[j]=1000000.0*(writetime[j] / (double)filebytes64);
08038             continue;
08039         }
08040             else
08041             {
08042                   writerate[j] = 
08043               (unsigned long long) ((double) filebytes64 / writetime[j]);
08044             }
08045         if(!(OPS_flag || MS_flag))
08046             writerate[j] >>= 10;
08047     }
08048     /* Must save walltime & cputime before calling store_value() for each/any cell.*/
08049     if(noretest)
08050     {
08051         writerate[1]=(long long)0;
08052         if(cpuutilflag)
08053         {
08054             walltime[1]=0.0;
08055             cputime[1]=0.0;
08056         }
08057     }
08058     if(cpuutilflag)
08059         store_times(walltime[0], cputime[0]);
08060     store_value((off64_t)writerate[0]);
08061     if(cpuutilflag)
08062         store_times(walltime[1], cputime[1]);
08063     store_value((off64_t)writerate[1]);
08064     data1[0]=writerate[0];
08065 #ifdef NO_PRINT_LLD
08066     if(!silent) printf("%9ld",writerate[0]);
08067     if(!silent) printf("%9ld",writerate[1]);
08068     if(!silent) fflush(stdout);
08069 #else
08070     if(!silent) printf("%9lld",writerate[0]);
08071     if(!silent) printf("%9lld",writerate[1]);
08072     if(!silent) fflush(stdout);
08073 #endif
08074 }
08075 
08076 /************************************************************************/
08077 /* fread_perf_test                              */
08078 /* fRead and fre-read test                      */
08079 /************************************************************************/
08080 #ifdef HAVE_ANSIC_C
08081 void fread_perf_test(off64_t kilo64,long long reclen,long long *data1,long long *data2)
08082 #else
08083 void fread_perf_test(kilo64,reclen,data1,data2)
08084 off64_t kilo64;
08085 long long reclen;
08086 long long *data1,*data2;
08087 #endif
08088 {
08089     double starttime2;
08090     double readtime[2];
08091     double walltime[2], cputime[2];
08092     double compute_val = (double)0;
08093     long long j;
08094     off64_t i,numrecs64;
08095     long long Index = 0;
08096     unsigned long long readrate[2];
08097     off64_t filebytes64;
08098     FILE *stream = 0;
08099     char *stdio_buf;
08100     int fd,ltest;
08101 
08102     if(mmapflag || async_flag)
08103         return;
08104     numrecs64 = (kilo64*1024)/reclen;
08105     filebytes64 = numrecs64*reclen;
08106     stdio_buf=(char *)malloc((size_t)reclen);
08107 
08108     if(noretest)
08109         ltest=1;
08110     else
08111         ltest=2;
08112 
08113     for( j=0; j<ltest; j++ )
08114     {
08115         if(cpuutilflag)
08116         {
08117             walltime[j] = time_so_far();
08118             cputime[j]  = cputime_so_far();
08119         }
08120 
08121         if(Uflag) /* Unmount and re-mount the mountpoint */
08122         {
08123             purge_buffer_cache();
08124         }
08125 #ifdef IRIX64
08126         if((stream=(FILE *)fopen(filename,"r")) == 0)
08127         {
08128             printf("\nCan not fdopen temp file: %s\n", 
08129                 filename);
08130             perror("fdopen");
08131             exit(51);
08132         }
08133 #else
08134         if((stream=(FILE *)I_FOPEN(filename,"r")) == 0)
08135         {
08136             printf("\nCan not fdopen temp file: %s\n", 
08137                 filename);
08138             perror("fdopen");
08139             exit(52);
08140         }
08141 #endif
08142         fd=I_OPEN(filename,O_RDONLY,0);
08143         fsync(fd);
08144         close(fd);
08145         setvbuf(stream,stdio_buf,_IOFBF,reclen);
08146         buffer=mainbuffer;
08147         if(fetchon)
08148             fetchit(buffer,reclen);
08149         compute_val=(double)0;
08150         starttime2 = time_so_far();
08151         for(i=0; i<numrecs64; i++) 
08152         {
08153             if(compute_flag)
08154                 compute_val+=do_compute(compute_time);
08155                         if(multi_buffer)
08156                         {
08157                                 Index +=reclen;
08158                                 if(Index > (MAXBUFFERSIZE-reclen))
08159                                         Index=0;
08160                                 buffer = mbuffer + Index;
08161                         }
08162             if(purge)
08163                 purgeit(buffer,reclen);
08164             if(fread(buffer, (size_t) reclen,1, stream) != 1)
08165             {
08166 #ifdef _64BIT_ARCH_
08167 #ifdef NO_PRINT_LLD
08168                 printf("\nError freading block %lu %lx\n", i,
08169                     (unsigned long long)buffer);
08170 #else
08171                 printf("\nError freading block %llu %llx\n", i,
08172                     (unsigned long long)buffer);
08173 #endif
08174 #else
08175 #ifdef NO_PRINT_LLD
08176                 printf("\nError freading block %lu %lx\n", i,
08177                     (long)buffer);
08178 #else
08179                 printf("\nError freading block %llu %lx\n", i,
08180                     (long)buffer);
08181 #endif
08182 #endif
08183                 perror("read");
08184                 exit(54);
08185             }
08186             if(verify){
08187                 if(verify_buffer(buffer,reclen,(off64_t)i,reclen,(long long)pattern,sverify)){
08188                     exit(55);
08189                 }
08190             }
08191         }
08192         if(include_flush)
08193             fflush(stream);
08194         if(include_close)
08195         {
08196             fclose(stream);
08197         }
08198         readtime[j] = ((time_so_far() - starttime2)-time_res)
08199             -compute_val;
08200         if(readtime[j] < (double).000001) 
08201         {
08202             readtime[j]= time_res;
08203             if(rec_prob < reclen)
08204                 rec_prob = reclen;
08205             res_prob=1;
08206         }
08207         if(!include_close)
08208         {
08209             fflush(stream);
08210             fclose(stream);
08211         }
08212         stream = NULL;
08213         if(cpuutilflag)
08214         {
08215             cputime[j]  = cputime_so_far() - cputime[j];
08216             if (cputime[j] < cputime_res)
08217                 cputime[j] = 0.0;
08218             walltime[j] = time_so_far() - walltime[j];
08219             if (walltime[j] < cputime[j])
08220                walltime[j] = cputime[j];
08221         }
08222         if(restf)
08223             sleep((int)rest_val);
08224         }
08225     free(stdio_buf);
08226     if(OPS_flag || MS_flag){
08227        filebytes64=filebytes64/reclen;
08228     }
08229         for(j=0;j<ltest;j++)
08230         {
08231         if(MS_flag)
08232         {
08233             readrate[j]=1000000.0*(readtime[j] / (double)filebytes64);
08234             continue;
08235         }
08236             else
08237             {
08238                   readrate[j] = 
08239                   (unsigned long long) ((double) filebytes64 / readtime[j]);
08240             }
08241         if(!(OPS_flag || MS_flag))
08242             readrate[j] >>= 10;
08243     }
08244     data1[0]=readrate[0];
08245     data2[0]=1;
08246     if(noretest)
08247     {
08248         readrate[1]=(long long)0;
08249         if(cpuutilflag)
08250         {
08251             walltime[1]=0.0;
08252             cputime[1]=0.0;
08253         }
08254     }
08255     /* Must save walltime & cputime before calling store_value() for each/any cell.*/
08256     if(cpuutilflag)
08257         store_times(walltime[0], cputime[0]);
08258     store_value((off64_t)readrate[0]);
08259     if(cpuutilflag)
08260         store_times(walltime[1], cputime[1]);
08261     store_value((off64_t)readrate[1]);
08262 #ifdef NO_PRINT_LLD
08263     if(!silent) printf("%8ld",readrate[0]);
08264     if(!silent) printf("%9ld",readrate[1]);
08265     if(!silent) fflush(stdout);
08266 #else
08267     if(!silent) printf("%8lld",readrate[0]);
08268     if(!silent) printf("%9lld",readrate[1]);
08269     if(!silent) fflush(stdout);
08270 #endif
08271 }
08272 
08273 /************************************************************************/
08274 /* read_perf_test                               */
08275 /* Read and re-fread test                       */
08276 /************************************************************************/
08277 #ifdef HAVE_ANSIC_C
08278 void 
08279 read_perf_test(off64_t kilo64,long long reclen,long long *data1,long long *data2)
08280 #else
08281 void 
08282 read_perf_test(kilo64,reclen,data1,data2)
08283 off64_t kilo64;
08284 long long reclen;
08285 long long *data1,*data2;
08286 #endif
08287 {
08288     double starttime2;
08289     double compute_val = (double)0;
08290     double readtime[2];
08291     double walltime[2], cputime[2];
08292 #ifdef unix
08293     double qtime_u_start,qtime_u_stop;
08294     double qtime_s_start,qtime_s_stop;
08295 #endif
08296     long long j;
08297     long long traj_size;
08298     off64_t i,numrecs64,traj_offset;
08299     off64_t lock_offset=0;
08300     long long Index = 0;
08301     unsigned long long readrate[2];
08302     off64_t filebytes64;
08303     volatile char *buffer1;
08304     char *nbuff;
08305     char *maddr;
08306     char *wmaddr;
08307     int fd,open_flags;
08308     int test_foo,ltest;
08309     long wval;
08310     double qtime_start,qtime_stop;
08311     double hist_time;
08312 #ifdef ASYNC_IO
08313     struct cache *gc=0;
08314 
08315 #else
08316     long long *gc=0;
08317 #endif
08318 #ifdef unix
08319     qtime_u_start=qtime_u_stop=0;
08320     qtime_s_start=qtime_s_stop=0;
08321 #endif
08322     hist_time=qtime_start=qtime_stop=0;
08323     maddr=0;
08324     traj_offset=0;
08325     test_foo=0;
08326     numrecs64 = (kilo64*1024)/reclen;
08327 
08328     open_flags = O_RDONLY;
08329 #if defined(_HPUX_SOURCE) || defined(linux)
08330     if(read_sync)
08331         open_flags |=O_RSYNC|O_SYNC;
08332 #endif
08333 #if ! defined(DONT_HAVE_O_DIRECT)
08334 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
08335     if(direct_flag)
08336         open_flags |=O_DIRECT;
08337 #endif
08338 #if defined(TRU64)
08339     if(direct_flag)
08340         open_flags |=O_DIRECTIO;
08341 #endif
08342 #endif
08343     if(r_traj_flag)
08344     {
08345         numrecs64=r_traj_ops;
08346         filebytes64 = r_traj_fsize;
08347     } else
08348         filebytes64 = numrecs64*reclen;
08349     fd = 0;
08350     if(Q_flag && (!rol_opened))
08351     {
08352         rol_opened++;
08353         rqfd=fopen("rol.dat","a");
08354         if(rqfd==0)
08355         {
08356             printf("Unable to open rol.dat\n");
08357             exit(56);
08358         }
08359         fprintf(rqfd,"Offset in Kbytes   Latency in microseconds  Transfer size in bytes\n");
08360         rrqfd=fopen("rrol.dat","a");
08361         if(rrqfd==0)
08362         {
08363             printf("Unable to open rrol.dat\n");
08364             exit(57);
08365         }
08366         fprintf(rrqfd,"Offset in Kbytes   Latency in microseconds  Transfer size in bytes\n");
08367     }
08368     /* 
08369      * begin real testing
08370      */
08371     if(noretest)
08372         ltest=1;
08373     else
08374         ltest=2;
08375 
08376     for( j=0; j<ltest; j++ )
08377     {
08378 
08379         if(cpuutilflag)
08380         {
08381             walltime[j] = time_so_far();
08382             cputime[j]  = cputime_so_far();
08383         }
08384 
08385         if(Uflag) /* Unmount and re-mount the mountpoint */
08386         {
08387             purge_buffer_cache();
08388         }
08389 #if defined(Windows)
08390             if(unbuffered)
08391             {
08392                 hand=CreateFile(filename,
08393               GENERIC_READ|GENERIC_WRITE,
08394                   FILE_SHARE_WRITE|FILE_SHARE_READ,
08395               NULL,OPEN_EXISTING,FILE_FLAG_NO_BUFFERING|
08396               FILE_FLAG_WRITE_THROUGH|FILE_FLAG_POSIX_SEMANTICS,
08397               NULL);
08398                 }
08399             else
08400             {
08401 #endif
08402         if((fd = I_OPEN(filename, open_flags,0))<0)
08403         {
08404             printf("\nCan not open temporary file %s for read\n",filename);
08405             perror("open");
08406             exit(58);
08407         }
08408 #if defined(Windows)
08409         }
08410 #endif
08411 #ifdef ASYNC_IO
08412         if(async_flag)
08413             async_init(&gc,fd,direct_flag);
08414 #endif
08415 
08416 #ifdef VXFS
08417         if(direct_flag)
08418         {
08419             ioctl(fd,VX_SETCACHE,VX_DIRECT);
08420             ioctl(fd,VX_GETCACHE,&test_foo);
08421             if(test_foo == 0)
08422             {
08423                 if(!client_iozone)
08424                   printf("\nVxFS advanced setcache feature not available.\n");
08425                 exit(3);
08426             }
08427         }
08428 #endif
08429 #if defined(solaris)
08430                if(direct_flag)
08431                {
08432                        test_foo = directio(fd, DIRECTIO_ON);
08433                        if(test_foo != 0)
08434                        {
08435                                if(!client_iozone)
08436                                  printf("\ndirectio not available.\n");
08437                                exit(3);
08438                        }
08439                }
08440 #endif
08441         if(file_lock)
08442             if(mylockf((int) fd, (int) 1, (int)1) != 0)
08443                 printf("File lock for read failed. %d\n",errno);
08444         if(mmapflag)
08445         {
08446             maddr=(char *)initfile(fd,filebytes64,0,PROT_READ);
08447         }
08448 #if defined(Windows)
08449         if(!unbuffered)
08450 #endif
08451           fsync(fd);
08452         /* 
08453          *  Need to prime the instruction cache & TLB
08454          */
08455         nbuff=mainbuffer;
08456         if(fetchon)
08457             fetchit(nbuff,reclen);
08458 #if defined(Windows)
08459         if(!unbuffered)
08460         {
08461 #endif
08462         if(read(fd, (void *)nbuff, (size_t) reclen) != reclen)
08463         {
08464 #ifdef _64BIT_ARCH_
08465             printf("\nError reading block %d %llx\n", 0,
08466                 (unsigned long long)nbuff);
08467 #else
08468             printf("\nError reading block %d %lx\n", 0,
08469                 (long)nbuff);
08470 #endif
08471             perror("read");
08472             exit(60);
08473         }
08474         I_LSEEK(fd,0,SEEK_SET);
08475 #if defined(Windows)
08476         }
08477         if(unbuffered)
08478             SetFilePointer(hand,(LONG)0,0,FILE_BEGIN);
08479 #endif
08480         nbuff=mainbuffer;
08481 
08482         if(fetchon)
08483             fetchit(nbuff,reclen);
08484         starttime2 = time_so_far();
08485 #ifdef unix
08486         if(Q_flag || hist_summary)
08487         {
08488             qtime_u_start=utime_so_far();
08489             qtime_s_start=stime_so_far();
08490         }
08491 #endif
08492         if(r_traj_flag)
08493         {
08494             rewind(r_traj_fd);
08495         }
08496         compute_val=(double)0;
08497         r_traj_ops_completed=0;
08498         r_traj_bytes_completed=0;
08499         for(i=0; i<numrecs64; i++) 
08500         {
08501             if(disrupt_flag && ((i%DISRUPT)==0))
08502             {
08503 #if defined(Windows)
08504     
08505                 if(unbuffered)
08506                    disruptw(hand);
08507                 else
08508                    disrupt(fd);
08509 #else
08510                 disrupt(fd);
08511 #endif
08512             }
08513             if(r_traj_flag)
08514             {
08515                 traj_offset=get_traj(r_traj_fd, (long long *)&traj_size,(float *)&compute_time, (long)0);
08516                 reclen=traj_size;
08517 #if defined(Windows)
08518             if(unbuffered)
08519               SetFilePointer(hand,(LONG)traj_offset,0,FILE_BEGIN);
08520             else
08521 #endif
08522                 I_LSEEK(fd,traj_offset,SEEK_SET);
08523             }
08524             if(Q_flag)
08525             {
08526 #if defined(Windows)
08527             if(unbuffered)
08528               traj_offset=SetFilePointer(hand,(LONG)0,0,FILE_CURRENT);
08529             else
08530 #endif
08531                 traj_offset=I_LSEEK(fd,0,SEEK_CUR);
08532             }
08533             if(rlocking)
08534             {
08535                 lock_offset=I_LSEEK(fd,0,SEEK_CUR);
08536                 mylockr((int) fd, (int) 1, (int)1,
08537                   lock_offset, reclen);
08538             }
08539             if(compute_flag)
08540                 compute_val+=do_compute(compute_time);
08541                         if(multi_buffer)
08542                         {
08543                                 Index +=reclen;
08544                                 if(Index > (MAXBUFFERSIZE-reclen))
08545                                         Index=0;
08546                                 nbuff = mbuffer + Index;
08547                         }
08548             if(purge)
08549                 purgeit(nbuff,reclen);
08550             if(Q_flag || hist_summary)
08551                 qtime_start=time_so_far();
08552             if(mmapflag)
08553             {
08554                 wmaddr=&maddr[i*reclen];
08555                 fill_area((long long*)wmaddr,(long long*)nbuff,(long long)reclen);
08556             }
08557             else
08558             {
08559               if(async_flag)
08560               {
08561                 if(no_copy_flag)
08562                   async_read_no_copy(gc, (long long)fd, &buffer1, (i*reclen), reclen,
08563                     1LL,(numrecs64*reclen),depth);
08564                 else
08565                   async_read(gc, (long long)fd, nbuff, (i*reclen),reclen,
08566                     1LL,(numrecs64*reclen),depth);
08567               }
08568               else
08569               {
08570 #if defined(Windows)
08571                     if(unbuffered)
08572                     {
08573                 ReadFile(hand, nbuff, reclen,(LPDWORD)&wval,
08574                     0);
08575                 }
08576                 else
08577 #endif
08578                   wval=read((int)fd, (void*)nbuff, (size_t) reclen);
08579                 if(wval != reclen)
08580                 {
08581 #ifdef _64BIT_ARCH_
08582 #ifdef NO_PRINT_LLD
08583                 printf("\nError reading block %ld %lx\n", i,
08584                     (unsigned long long)nbuff);
08585 #else
08586                 printf("\nError reading block %lld %llx\n", i,
08587                     (unsigned long long)nbuff);
08588 #endif
08589 #else
08590 #ifdef NO_PRINT_LLD
08591                 printf("\nError reading block %ld %x\n", i,
08592                     (long)nbuff);
08593 #else
08594                 printf("\nError reading block %lld %lx\n", i,
08595                     (long)nbuff);
08596 #endif
08597 #endif
08598                 perror("read");
08599                 exit(61);
08600                 }
08601               }
08602             }
08603             if(verify) {
08604               if(async_flag && no_copy_flag)
08605               {
08606                 if(verify_buffer(buffer1,reclen,(off64_t)i,reclen,(long long)pattern,sverify)){
08607                     exit(62);
08608                 }
08609               }
08610               else
08611               {
08612                 if(verify_buffer(nbuff,reclen,(off64_t)i,reclen,(long long)pattern,sverify)){
08613                     exit(63);
08614                 }
08615               }
08616             }
08617             if(async_flag && no_copy_flag)
08618                 async_release(gc);
08619             buffer1=0;
08620             if(hist_summary)
08621             {
08622                 qtime_stop=time_so_far();
08623                 hist_time =(qtime_stop-qtime_start-time_res);
08624                 hist_insert(hist_time);
08625             }
08626             if(Q_flag)
08627             {
08628                 qtime_stop=time_so_far();
08629                 if(j==0)
08630 #ifdef NO_PRINT_LLD
08631                 fprintf(rqfd,"%10.1ld %10.0f %10.1ld\n",(traj_offset)/1024,(qtime_stop-qtime_start-time_res)*1000000,reclen);
08632                 else
08633                 fprintf(rrqfd,"%10.1ld %10.0f %10.1ld\n",(traj_offset)/1024,(qtime_stop-qtime_start-time_res)*1000000,reclen);
08634 #else
08635                 fprintf(rqfd,"%10.1lld %10.0f %10.1lld\n",(traj_offset)/1024,(qtime_stop-qtime_start-time_res)*1000000,reclen);
08636                 else
08637                 fprintf(rrqfd,"%10.1lld %10.0f %10.1lld\n",(traj_offset)/1024,(qtime_stop-qtime_start-time_res)*1000000,reclen);
08638 #endif
08639             }
08640             r_traj_ops_completed++;
08641             r_traj_bytes_completed+=reclen;
08642         }
08643         if(rlocking)
08644         {
08645             mylockr((int) fd, (int) 0, (int)1,
08646               lock_offset, reclen);
08647         }
08648         if(file_lock)
08649             if(mylockf((int) fd, (int) 0, (int)1))
08650                 printf("Read unlock failed. %d\n",errno);
08651 #ifdef unix
08652         if(Q_flag)
08653         {
08654            qtime_u_stop=utime_so_far();
08655            qtime_s_stop=stime_so_far();
08656            if(j==0)
08657              fprintf(rqfd,"\nSystem time %10.3f User time %10.3f Real %10.3f  (seconds)\n",
08658                 (qtime_s_stop-qtime_s_start)/sc_clk_tck,
08659                 (qtime_u_stop-qtime_u_start)/sc_clk_tck,
08660                 time_so_far()-starttime2);
08661            else
08662             fprintf(rrqfd,"\nSystem time %10.3f User time %10.3f Real %10.3f  (seconds)\n",
08663                 (qtime_s_stop-qtime_s_start)/sc_clk_tck,
08664                 (qtime_u_stop-qtime_u_start)/sc_clk_tck,
08665                 time_so_far()-starttime2);
08666         }
08667 #endif
08668 #ifdef ASYNC_IO
08669         if(async_flag)
08670         {
08671             end_async(gc);
08672             gc=0;
08673         }
08674 #endif
08675         if(include_flush)
08676         {
08677             if(mmapflag)
08678                 msync(maddr,(size_t)filebytes64,MS_SYNC);
08679             else
08680                 fsync(fd);
08681         }
08682         if(include_close)
08683         {
08684             if(mmapflag)
08685             {
08686                 mmap_end(maddr,(unsigned long long)filebytes64);
08687             }
08688 #if defined(Windows)
08689             if(unbuffered)
08690                 CloseHandle(hand);
08691             else
08692 #endif
08693             close(fd);
08694         }
08695         readtime[j] = ((time_so_far() - starttime2)-time_res)-compute_val;
08696         if(readtime[j] < (double).000001) 
08697         {
08698             readtime[j]= time_res;
08699             if(rec_prob < reclen)
08700                 rec_prob = reclen;
08701             res_prob=1;
08702         }
08703         if(!include_close)
08704         {
08705             if(mmapflag)
08706                 msync(maddr,(size_t)filebytes64,MS_SYNC);
08707             else
08708                 fsync(fd);
08709             if(mmapflag)
08710             {
08711                 mmap_end(maddr,(unsigned long long)filebytes64);
08712             }
08713 #if defined(Windows)
08714             if(unbuffered)
08715                 CloseHandle(hand);
08716             else
08717 #endif
08718             close(fd);
08719         }
08720         if(cpuutilflag)
08721         {
08722             cputime[j]  = cputime_so_far() - cputime[j];
08723             if (cputime[j] < cputime_res)
08724                 cputime[j] = 0.0;
08725             walltime[j] = time_so_far() - walltime[j];
08726             if (walltime[j] < cputime[j])
08727                walltime[j] = cputime[j];
08728         }
08729         if(restf)
08730             sleep((int)rest_val);
08731         }
08732     if(OPS_flag || MS_flag){
08733        filebytes64=r_traj_ops_completed;
08734        /*filebytes64=filebytes64/reclen;*/
08735     } else
08736        filebytes64=r_traj_bytes_completed;
08737 
08738         for(j=0;j<ltest;j++)
08739         {
08740         if(MS_flag)
08741         {
08742             readrate[j]=1000000.0*(readtime[j] / (double)filebytes64);
08743             continue;
08744         }
08745             else
08746             {
08747                   readrate[j] = 
08748                   (unsigned long long) ((double) filebytes64 / readtime[j]);
08749             }
08750         if(!(OPS_flag || MS_flag))
08751             readrate[j] >>= 10;
08752             
08753     }
08754     data1[0]=readrate[0];
08755     data2[0]=1;
08756     if(noretest)
08757     {
08758         readrate[1]=(long long)0;
08759         if(cpuutilflag)
08760         {
08761             walltime[1]=0.0;
08762             cputime[1]=0.0;
08763         }
08764     }
08765     /* Must save walltime & cputime before calling store_value() for each/any cell.*/
08766     if(cpuutilflag)
08767         store_times(walltime[0], cputime[0]);
08768     store_value((off64_t)readrate[0]);
08769     if(cpuutilflag)
08770         store_times(walltime[1], cputime[1]);
08771     store_value((off64_t)readrate[1]);
08772 #ifdef NO_PRINT_LLD
08773     if(!silent) printf("%9ld",readrate[0]);
08774     if(!silent) printf("%9ld",readrate[1]);
08775     if(!silent) fflush(stdout);
08776 #else
08777     if(!silent) printf("%9lld",readrate[0]);
08778     if(!silent) printf("%9lld",readrate[1]);
08779     if(!silent) fflush(stdout);
08780 #endif
08781 }
08782 
08783 
08784 /************************************************************************/
08785 /* random_perf_test                             */
08786 /* Random read and write test                       */
08787 /************************************************************************/
08788 #ifdef HAVE_ANSIC_C
08789 void random_perf_test(off64_t kilo64,long long reclen,long long *data1,long long *data2)
08790 #else
08791 void random_perf_test(kilo64,reclen,data1,data2)
08792 off64_t kilo64;
08793 long long reclen;
08794 long long *data1, *data2;
08795 #endif
08796 {
08797     double randreadtime[2];
08798     double starttime2;
08799     double walltime[2], cputime[2];
08800     double compute_val = (double)0;
08801 #if defined (bsd4_2) || defined(Windows)
08802     long long rand1,rand2,rand3;
08803 #endif
08804     unsigned long long big_rand;
08805     long long j;
08806     off64_t i,numrecs64;
08807     long long Index=0;
08808     int flags;
08809     unsigned long long randreadrate[2];
08810     off64_t filebytes64;
08811     off64_t lock_offset=0;
08812     volatile char *buffer1;
08813     char *wmaddr,*nbuff;
08814     char *maddr,*free_addr;
08815     int fd,wval;
08816     long long *recnum= 0;
08817 #if defined(VXFS) || defined(solaris)
08818     int test_foo=0;
08819 #endif
08820 #ifdef ASYNC_IO
08821     struct cache *gc=0;
08822 #else
08823     long long *gc=0;
08824 #endif
08825 #ifdef MERSENNE
08826     unsigned long long init[4]={0x12345ULL, 0x23456ULL, 0x34567ULL, 0x45678ULL};
08827     unsigned long long length=4;
08828 #endif
08829 
08830     maddr=free_addr=0;
08831     numrecs64 = (kilo64*1024)/reclen;
08832 #ifdef MERSENNE
08833        init_by_array64(init, length);
08834 #else
08835 #ifdef bsd4_2
08836         srand(0);
08837 #else
08838 #ifdef Windows
08839         srand(0);
08840 #else
08841         srand48(0);
08842 #endif
08843 #endif
08844 #endif
08845         recnum = (long long *)malloc(sizeof(*recnum)*numrecs64);
08846         if (recnum){
08847              /* pre-compute random sequence based on 
08848         Fischer-Yates (Knuth) card shuffle */
08849             for(i = 0; i < numrecs64; i++){
08850                 recnum[i] = i;
08851             }
08852             for(i = 0; i < numrecs64; i++) {
08853                 long long tmp;
08854 #ifdef MERSENNE
08855                big_rand=genrand64_int64();
08856 #else
08857 #ifdef bsd4_2
08858                rand1=(long long)rand();
08859                rand2=(long long)rand();
08860                rand3=(long long)rand();
08861                big_rand=(rand1<<32)|(rand2<<16)|(rand3);
08862 #else
08863 #ifdef Windows
08864                rand1=(long long)rand();
08865                rand2=(long long)rand();
08866                rand3=(long long)rand();
08867                big_rand=(rand1<<32)|(rand2<<16)|(rand3);
08868 #else
08869                big_rand = lrand48();
08870 #endif
08871 #endif
08872 #endif
08873                big_rand = big_rand%numrecs64;
08874                tmp = recnum[i];
08875                recnum[i] = recnum[big_rand];
08876                recnum[big_rand] = tmp;
08877             }
08878         }
08879     else
08880     {
08881         fprintf(stderr,"Random uniqueness fallback.\n");
08882     }
08883     flags = O_RDWR;
08884 #if ! defined(DONT_HAVE_O_DIRECT)
08885 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
08886     if(direct_flag)
08887         flags |=O_DIRECT;
08888 #endif
08889 #if defined(TRU64)
08890     if(direct_flag)
08891         flags |=O_DIRECTIO;
08892 #endif
08893 #endif
08894     fd=0;
08895     if(oflag)
08896         flags |= O_SYNC;
08897 #if defined(O_DSYNC)
08898     if(odsync)
08899         flags |= O_DSYNC;
08900 #endif
08901 #if defined(_HPUX_SOURCE) || defined(linux)
08902     if(read_sync)
08903         flags |=O_RSYNC|O_SYNC;
08904 #endif
08905     filebytes64 = numrecs64*reclen;
08906     for( j=0; j<2; j++ )
08907     {
08908         if(j==0)
08909             flags |=O_CREAT;
08910         if (no_write && (j == 1))
08911             continue;
08912         if(cpuutilflag)
08913         {
08914              walltime[j] = time_so_far();
08915              cputime[j]  = cputime_so_far();
08916          }
08917          if(Uflag) /* Unmount and re-mount the mountpoint */
08918          {
08919             purge_buffer_cache();
08920          }
08921          if((fd = I_OPEN(filename, ((int)flags),0640))<0){
08922             printf("\nCan not open temporary file for read/write\n");
08923             perror("open");
08924             exit(66);
08925          }
08926 #ifdef ASYNC_IO
08927         if(async_flag)
08928             async_init(&gc,fd,direct_flag);
08929 #endif
08930 
08931 #ifdef VXFS
08932         if(direct_flag)
08933         {
08934             ioctl(fd,VX_SETCACHE,VX_DIRECT);
08935             ioctl(fd,VX_GETCACHE,&test_foo);
08936             if(test_foo == 0)
08937             {
08938                 if(!client_iozone)
08939                   printf("\nVxFS advanced setcache feature not available.\n");
08940                 exit(3);
08941             }
08942         }
08943 #endif
08944 #if defined(solaris)
08945                if(direct_flag)
08946                {
08947                        test_foo = directio(fd, DIRECTIO_ON);
08948                        if(test_foo != 0)
08949                        {
08950                                if(!client_iozone)
08951                                  printf("\ndirectio not available.\n");
08952                                exit(3);
08953                        }
08954                }
08955 #endif
08956          if(mmapflag)
08957          {
08958             maddr=(char *)initfile(fd,filebytes64,0,PROT_READ|PROT_WRITE);
08959          }
08960          nbuff=mainbuffer;
08961          if(fetchon)
08962            fetchit(nbuff,reclen);
08963 #ifdef MERSENNE
08964             init_by_array64(init, length);
08965 #else
08966 #ifdef bsd4_2
08967          srand(0);
08968 #else
08969 #ifdef Windows
08970              srand(0);
08971 #else
08972              srand48(0);
08973 #endif
08974 #endif
08975 #endif
08976          compute_val=(double)0;
08977          starttime2 = time_so_far();
08978          if ( j==0 ){
08979         for(i=0; i<numrecs64; i++) {
08980             if(compute_flag)
08981                 compute_val+=do_compute(compute_time);
08982                         if(multi_buffer)
08983                         {
08984                                 Index +=reclen;
08985                                 if(Index > (MAXBUFFERSIZE-reclen))
08986                                         Index=0;
08987                                 nbuff = mbuffer + Index;
08988                         }
08989             if(purge)
08990                 purgeit(nbuff,reclen);
08991                         if (recnum) {
08992                 offset64 = reclen * (long long)recnum[i];
08993                         }
08994             else
08995             {
08996 
08997 #ifdef MERSENNE
08998                    big_rand =genrand64_int64();
08999                offset64 = reclen * (big_rand%numrecs64);
09000 #else
09001 #ifdef bsd4_2
09002                rand1=(long long)rand();
09003                rand2=(long long)rand();
09004                rand3=(long long)rand();
09005                big_rand=(rand1<<32)|(rand2<<16)|(rand3);
09006                            offset64 = reclen * (big_rand%numrecs64);
09007 #else
09008 #ifdef Windows
09009                rand1=(long long)rand();
09010                rand2=(long long)rand();
09011                rand3=(long long)rand();
09012                big_rand=(rand1<<32)|(rand2<<16)|(rand3);
09013                            offset64 = reclen * (big_rand%numrecs64);
09014 #else
09015                offset64 = reclen * (lrand48()%numrecs64);
09016 #endif
09017 #endif
09018 #endif
09019             }
09020 
09021             if( !(h_flag || k_flag || mmapflag))
09022             {
09023                if(I_LSEEK( fd, offset64, SEEK_SET )<0)
09024                {
09025                 perror("lseek");
09026                 exit(68);
09027                };
09028             }
09029             if(rlocking)
09030             {
09031                 lock_offset=I_LSEEK(fd,0,SEEK_CUR);
09032                 mylockr((int) fd, (int) 1, (int)1,
09033                   lock_offset, reclen);
09034             }
09035             if(mmapflag)
09036             {
09037                 wmaddr=&maddr[offset64];
09038                 fill_area((long long*)wmaddr,(long long*)nbuff,(long long)reclen);
09039             }
09040             else
09041             {
09042               if(async_flag)
09043               {
09044                  if(no_copy_flag)
09045                     async_read_no_copy(gc, (long long)fd, &buffer1, offset64,reclen,
09046                       0LL,(numrecs64*reclen),depth);
09047                  else
09048                  async_read(gc, (long long)fd, nbuff, (offset64),reclen,
09049                             0LL,(numrecs64*reclen),0LL);
09050               }
09051               else
09052               {
09053                  if(read(fd, (void *)nbuff, (size_t)reclen) != reclen)
09054                  {
09055 #ifdef NO_PRINT_LLD
09056                  printf("\nError reading block at %ld\n",
09057                      offset64); 
09058 #else
09059                  printf("\nError reading block at %lld\n",
09060                      offset64); 
09061 #endif
09062                  perror("read");
09063                  exit(70);
09064                  }
09065               }
09066             }
09067             if(verify){
09068               if(async_flag && no_copy_flag)
09069               {
09070                 if(verify_buffer(buffer1,reclen,(off64_t)offset64/reclen,reclen,(long long)pattern,sverify)){
09071                     exit(71);
09072                 }
09073               }
09074               else
09075               {
09076                 if(verify_buffer(nbuff,reclen,(off64_t)offset64/reclen,reclen,(long long)pattern,sverify)){
09077                     exit(72);
09078                 }
09079               }
09080             }
09081             if(async_flag && no_copy_flag)
09082                 async_release(gc);
09083             if(rlocking)
09084             {
09085                 lock_offset=I_LSEEK(fd,0,SEEK_CUR);
09086                 mylockr((int) fd, (int) 1, (int)1,
09087                   lock_offset, reclen);
09088             }
09089         }
09090          }
09091          else
09092          {
09093             if(verify || dedup || dedup_interior)
09094                 fill_buffer(nbuff,reclen,(long long)pattern,sverify,(long long)0);
09095             for(i=0; i<numrecs64; i++) 
09096             {
09097                 if(compute_flag)
09098                     compute_val+=do_compute(compute_time);
09099                             if(multi_buffer)
09100                             {
09101                                     Index +=reclen;
09102                                     if(Index > (MAXBUFFERSIZE-reclen))
09103                                          Index=0;
09104                                     nbuff = mbuffer + Index;
09105                             }
09106                                 if (recnum) {
09107                   offset64 = reclen * (long long)recnum[i];
09108                                 }
09109                     else
09110                     {
09111 #ifdef bsd4_2
09112                   rand1=(long long)rand();
09113                   rand2=(long long)rand();
09114                   rand3=(long long)rand();
09115                   big_rand=(rand1<<32)|(rand2<<16)|(rand3);
09116                   offset64 = reclen * (big_rand%numrecs64);
09117 #else
09118 #ifdef Windows
09119                   rand1=(long long)rand();
09120                   rand2=(long long)rand();
09121                   rand3=(long long)rand();
09122                   big_rand=(rand1<<32)|(rand2<<16)|(rand3);
09123                   offset64 = reclen * (big_rand%numrecs64);
09124 #else
09125                   offset64 = reclen * (lrand48()%numrecs64);
09126 #endif
09127 #endif
09128                 }
09129                 if(async_flag && no_copy_flag)
09130                 {
09131                     free_addr=nbuff=(char *)malloc((size_t)reclen+page_size);
09132                     nbuff=(char *)(((long)nbuff+(long)page_size) & (long)~(page_size-1));
09133                     if(verify || dedup || dedup_interior)
09134                         fill_buffer(nbuff,reclen,(long long)pattern,sverify,offset64/reclen);
09135                 }
09136                 if(purge)
09137                     purgeit(nbuff,reclen);
09138 
09139                 if((verify & diag_v) || dedup || dedup_interior)
09140                     fill_buffer(nbuff,reclen,(long long)pattern,sverify,offset64/reclen);
09141 
09142                 if (!(h_flag || k_flag || mmapflag))
09143                 {
09144                   I_LSEEK( fd, offset64, SEEK_SET );
09145                 }
09146                 if(rlocking)
09147                 {
09148                     lock_offset=I_LSEEK(fd,0,SEEK_CUR);
09149                     mylockr((int) fd, (int) 1, (int)0,
09150                       lock_offset, reclen);
09151                 }
09152                 if(mmapflag)
09153                 {
09154                     wmaddr=&maddr[offset64];
09155                     fill_area((long long*)nbuff,(long long*)wmaddr,(long long)reclen);
09156                     if(!mmapnsflag)
09157                     {
09158                         if(mmapasflag)
09159                                 msync(wmaddr,(size_t)reclen,MS_ASYNC);
09160                         if(mmapssflag)
09161                                 msync(wmaddr,(size_t)reclen,MS_SYNC);
09162                     }
09163                 }
09164                 else
09165                 {
09166                     if(async_flag)
09167                     {
09168                            if(no_copy_flag)
09169                               async_write_no_copy(gc, (long long)fd, nbuff, reclen, offset64, 
09170                         depth,free_addr);
09171                        else
09172                             async_write(gc, (long long)fd, nbuff, reclen, offset64, depth);
09173                     }
09174                     else
09175                     {
09176                       wval=write(fd, nbuff,(size_t)reclen);
09177                       if(wval != reclen)
09178                       {
09179 #ifdef NO_PRINT_LLD
09180                         printf("\nError writing block at %ld\n",
09181                             offset64); 
09182 #else
09183                         printf("\nError writing block at %lld\n",
09184                             offset64); 
09185 #endif
09186                         if(wval==-1)
09187                             perror("write");
09188                         signal_handler();
09189                       }
09190                     }
09191                 }
09192                 if(rlocking)
09193                 {
09194                     mylockr((int) fd, (int) 0, (int)0,
09195                       lock_offset, reclen);
09196                 }
09197             }
09198          }  /* end of modifications *kcollins:2-5-96 */
09199 #ifdef ASYNC_IO
09200          if(async_flag)
09201          {
09202         end_async(gc);
09203             gc=0;
09204              }  
09205 #endif
09206          if(include_flush)
09207          {
09208         if(mmapflag)
09209             msync(maddr,(size_t)filebytes64,MS_SYNC);/* Clean up before read starts running */
09210         else
09211         {
09212                 wval=fsync(fd);
09213             if(wval==-1){
09214                 perror("fsync");
09215                 signal_handler();
09216             }
09217         }
09218          }
09219          if(include_close)
09220          {
09221         if(mmapflag)
09222         {
09223             mmap_end(maddr,(unsigned long long)filebytes64);
09224         }
09225         wval=close(fd);
09226         if(wval==-1){
09227             perror("close");
09228             signal_handler();
09229         }
09230          }
09231          randreadtime[j] = ((time_so_far() - starttime2)-time_res)-
09232             compute_val;
09233          if(randreadtime[j] < (double).000001) 
09234          {
09235             randreadtime[j]=time_res;
09236             if(rec_prob < reclen)
09237                 rec_prob = reclen;
09238             res_prob=1;
09239          }
09240         if(!include_close)
09241         {
09242         if(mmapflag)
09243         {
09244             msync(maddr,(size_t)filebytes64,MS_SYNC);/* Clean up before read starts running */
09245         }
09246         else
09247         {
09248                 wval=fsync(fd);
09249             if(wval==-1){
09250                 perror("fsync");
09251                 signal_handler();
09252             }
09253         }
09254         if(mmapflag)
09255             mmap_end(maddr,(unsigned long long)filebytes64);
09256         wval=close(fd);
09257         if(wval==-1){
09258             perror("close");
09259             signal_handler();
09260         }
09261         }
09262             if(cpuutilflag)
09263         {
09264             cputime[j]  = cputime_so_far() - cputime[j];
09265             if (cputime[j] < cputime_res)
09266             cputime[j] = 0.0;
09267             walltime[j] = time_so_far() - walltime[j];
09268         if (walltime[j] < cputime[j])
09269            walltime[j] = cputime[j];
09270         }
09271         if(restf)
09272         sleep((int)rest_val);
09273         }
09274     if(OPS_flag || MS_flag){
09275        filebytes64=filebytes64/reclen;
09276     }
09277         for(j=0;j<2;j++)
09278         {
09279         if(no_write && (j==1))
09280         {
09281             randreadrate[1] = 0.0;
09282         continue;
09283         }
09284         if(MS_flag)
09285         {
09286         randreadrate[j]=1000000.0*(randreadtime[j] / (double)filebytes64);
09287         continue;
09288         }
09289             else
09290             {
09291                   randreadrate[j] = 
09292               (unsigned long long) ((double) filebytes64 / randreadtime[j]);
09293             }
09294         if(!(OPS_flag || MS_flag))
09295         randreadrate[j] >>= 10;
09296     }
09297     /* Must save walltime & cputime before calling store_value() for each/any cell.*/
09298         if(cpuutilflag)
09299         store_times(walltime[0], cputime[0]);
09300     store_value((off64_t)randreadrate[0]);
09301         if(cpuutilflag)
09302         store_times(walltime[1], cputime[1]);
09303     store_value((off64_t)randreadrate[1]);
09304 #ifdef NO_PRINT_LLD
09305     if(!silent) printf("%8ld",randreadrate[0]);
09306     if(!silent) printf("%8ld",randreadrate[1]);
09307     if(!silent) fflush(stdout);
09308 #else
09309     if(!silent) printf("%8lld",randreadrate[0]);
09310     if(!silent) printf("%8lld",randreadrate[1]);
09311     if(!silent) fflush(stdout);
09312 #endif
09313     if(recnum)
09314         free(recnum);
09315 }
09316 
09317 /************************************************************************/
09318 /* reverse_perf_test                                */
09319 /* Reverse read test                            */
09320 /************************************************************************/
09321 #ifdef HAVE_ANSIC_C
09322 void reverse_perf_test(off64_t kilo64,long long reclen,long long *data1,long long *data2)
09323 #else
09324 void reverse_perf_test(kilo64,reclen,data1,data2)
09325 off64_t kilo64;
09326 long long reclen;
09327 long long *data1,*data2;
09328 #endif
09329 {
09330     double revreadtime[2];
09331     double starttime2;
09332     double walltime[2], cputime[2];
09333     double compute_val = (double)0;
09334     long long j;
09335     off64_t i,numrecs64;
09336     long long Index = 0;
09337     unsigned long long revreadrate[2];
09338     off64_t filebytes64;
09339     off64_t lock_offset=0;
09340     int fd,open_flags;
09341     char *maddr,*wmaddr;
09342     volatile char *buffer1;
09343     int ltest;
09344     char *nbuff;
09345 #if defined(VXFS) || defined(solaris)
09346     int test_foo=0;
09347 #endif
09348 #ifdef ASYNC_IO
09349     struct cache *gc=0;
09350 #else
09351     long long *gc=0;
09352 #endif
09353 
09354     maddr=wmaddr=0;
09355     open_flags=O_RDONLY;
09356 #if ! defined(DONT_HAVE_O_DIRECT)
09357 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
09358     if(direct_flag)
09359         open_flags |=O_DIRECT;
09360 #endif
09361 #if defined(TRU64)
09362     if(direct_flag)
09363         open_flags |=O_DIRECTIO;
09364 #endif
09365 #endif
09366 #if defined(_HPUX_SOURCE) || defined(linux)
09367     if(read_sync)
09368         open_flags |=O_RSYNC|O_SYNC;
09369 #endif
09370     numrecs64 = (kilo64*1024)/reclen;
09371     filebytes64 = numrecs64*reclen;
09372     fd = 0;
09373     if(noretest)
09374         ltest=1;
09375     else
09376         ltest=2;
09377     for( j=0; j<ltest; j++ )
09378     {
09379         if(cpuutilflag)
09380         {
09381             walltime[j] = time_so_far();
09382             cputime[j]  = cputime_so_far();
09383         }
09384         if(Uflag) /* Unmount and re-mount the mountpoint */
09385         {
09386             purge_buffer_cache();
09387         }
09388         if((fd = I_OPEN(filename, open_flags,0))<0){
09389             printf("\nCan not open temporary file for read\n");
09390             perror("open");
09391             exit(75);
09392         }
09393 #ifdef ASYNC_IO
09394         if(async_flag)
09395             async_init(&gc,fd,direct_flag);
09396 #endif
09397 
09398 #ifdef VXFS
09399         if(direct_flag)
09400         {
09401             ioctl(fd,VX_SETCACHE,VX_DIRECT);
09402             ioctl(fd,VX_GETCACHE,&test_foo);
09403             if(test_foo == 0)
09404             {
09405                 if(!client_iozone)
09406                   printf("\nVxFS advanced setcache feature not available.\n");
09407                 exit(3);
09408             }
09409         }
09410 #endif
09411 #if defined(solaris)
09412                if(direct_flag)
09413                {
09414                        test_foo = directio(fd, DIRECTIO_ON);
09415                        if(test_foo != 0)
09416                        {
09417                                if(!client_iozone)
09418                                  printf("\ndirectio not available.\n");
09419                                exit(3);
09420                        }
09421                }
09422 #endif
09423         if(mmapflag)
09424         {
09425             maddr=(char *)initfile(fd,filebytes64,0,PROT_READ);
09426         }
09427         fsync(fd);
09428         nbuff=mainbuffer;
09429         mbuffer=mainbuffer;
09430         if(fetchon)
09431             fetchit(nbuff,reclen);
09432         starttime2 = time_so_far();
09433         if (!(h_flag || k_flag || mmapflag))
09434         {
09435           if(check_filename(filename))
09436           {
09437             if(I_LSEEK( fd, -reclen, SEEK_END )<0)
09438             {
09439                 perror("lseek");
09440                 exit(77);
09441             };
09442           }
09443           else
09444           {
09445             if(I_LSEEK( fd, filebytes64-reclen, SEEK_SET )<0)
09446             {
09447                 perror("lseek");
09448                 exit(77);
09449             };
09450           }
09451         }
09452             compute_val=(double)0;
09453         for(i=0; i<numrecs64; i++) 
09454         {
09455             if(rlocking)
09456             {
09457                 lock_offset=I_LSEEK(fd,0,SEEK_CUR);
09458                 mylockr((int) fd, (int) 1, (int)1,
09459                   lock_offset, reclen);
09460             }
09461             if(compute_flag)
09462                 compute_val+=do_compute(compute_time);
09463                         if(multi_buffer)
09464                         {
09465                                 Index +=reclen;
09466                                 if(Index > (MAXBUFFERSIZE-reclen))
09467                                         Index=0;
09468                                 nbuff = mbuffer + Index;
09469                         }
09470 
09471             if(purge)
09472                 purgeit(nbuff,reclen);
09473             if(mmapflag)
09474             {
09475                 wmaddr = &maddr[((numrecs64-1)-i)*reclen];
09476                 fill_area((long long*)wmaddr,(long long*)nbuff,(long long)reclen);
09477             }
09478             else
09479             if(async_flag)
09480             {
09481                 if(no_copy_flag)
09482                    async_read_no_copy(gc, (long long)fd, &buffer1, ((((numrecs64-1)-i)*reclen)),
09483                       reclen, -1LL,(numrecs64*reclen),depth);
09484                 else
09485                    async_read(gc, (long long)fd, nbuff, (((numrecs64-1)-i)*reclen),
09486                       reclen,-1LL,(numrecs64*reclen),depth);
09487             }else
09488             {
09489                 if(read((int)fd, (void*)nbuff, (size_t) reclen) != reclen)
09490                 {
09491 #ifdef NO_PRINT_LLD
09492                     printf("\nError reading block %ld\n", i); 
09493 #else
09494                     printf("\nError reading block %lld\n", i); 
09495 #endif
09496                     perror("read");
09497                     exit(79);
09498                 }
09499             }
09500             if(verify){
09501                if(async_flag && no_copy_flag)
09502                {
09503                 if(verify_buffer(buffer1,reclen,(off64_t)(numrecs64-1)-i,reclen,(long long)pattern,sverify)){
09504                     exit(80);
09505                 }
09506                }
09507                else
09508                {
09509                 if(verify_buffer(nbuff,reclen,(off64_t)(numrecs64-1)-i,reclen,(long long)pattern,sverify)){
09510                     exit(81);
09511                 }
09512                }
09513             }
09514             if(async_flag && no_copy_flag)
09515                 async_release(gc);
09516             if(rlocking)
09517             {
09518                 mylockr((int) fd, (int) 0, (int)1,
09519                   lock_offset, reclen);
09520             }
09521             if (!(h_flag || k_flag || mmapflag))
09522             {
09523               I_LSEEK( fd, (off64_t)-2*reclen, SEEK_CUR );
09524             }
09525         }
09526 #ifdef ASYNC_IO
09527         if(async_flag)
09528         {
09529             end_async(gc);
09530             gc=0;
09531         }
09532 #endif
09533         if(include_flush)   
09534         {
09535             if(mmapflag)
09536                 msync(maddr,(size_t)filebytes64,MS_SYNC);
09537             else
09538                 fsync(fd);
09539         }
09540         if(include_close)
09541         {
09542             if(mmapflag)
09543             {
09544                 mmap_end(maddr,(unsigned long long)filebytes64);
09545             }
09546             close(fd);
09547         }
09548         revreadtime[j] = ((time_so_far() - starttime2)-time_res)
09549             -compute_val;
09550         if(revreadtime[j] < (double).000001) 
09551         {
09552             revreadtime[j]= time_res;
09553             if(rec_prob < reclen)
09554                 rec_prob = reclen;
09555             res_prob=1;
09556         }
09557         if(!include_close)
09558         {
09559             if(mmapflag)
09560                 msync(maddr,(size_t)filebytes64,MS_SYNC);
09561             else
09562                 fsync(fd);
09563             if(mmapflag)
09564             {
09565                 mmap_end(maddr,(unsigned long long)filebytes64);
09566             }
09567             close(fd);
09568         }
09569         if(cpuutilflag)
09570         {
09571             cputime[j]  = cputime_so_far() - cputime[j];
09572             if (cputime[j] < cputime_res)
09573                 cputime[j] = 0.0;
09574             walltime[j] = time_so_far() - walltime[j];
09575             if (walltime[j] < cputime[j])
09576                walltime[j] = cputime[j];
09577         }
09578         if(restf)
09579             sleep((int)rest_val);
09580         }
09581     if(OPS_flag || MS_flag){
09582        filebytes64=filebytes64/reclen;
09583     }
09584     for(j=0;j<ltest;j++){
09585         if(MS_flag)
09586         {
09587             revreadrate[j]=1000000.0*(revreadtime[j] / (double)filebytes64);
09588             continue;
09589         }
09590             else
09591             {
09592                   revreadrate[j] = 
09593               (unsigned long long) ((double) filebytes64 / revreadtime[j]);
09594             }
09595         if(!(OPS_flag || MS_flag))
09596             revreadrate[j] >>= 10;
09597     }
09598     /* Must save walltime & cputime before calling store_value() for each/any cell.*/
09599     if(cpuutilflag)
09600         store_times(walltime[0], cputime[0]);
09601     store_value((off64_t)revreadrate[0]);
09602 #ifdef NO_PRINT_LLD
09603     if(!silent) printf("%8ld",revreadrate[0]);
09604 #else
09605     if(!silent) printf("%8lld",revreadrate[0]);
09606 #endif
09607     if(!silent) fflush(stdout);
09608 }
09609 
09610 /************************************************************************/
09611 /* rewriterec_perf_test                             */
09612 /* Re-write the same record                         */
09613 /************************************************************************/
09614 #ifdef HAVE_ANSIC_C
09615 void rewriterec_perf_test(off64_t kilo64 ,long long reclen,long long *data1,long long *data2)
09616 #else
09617 void rewriterec_perf_test(kilo64 ,reclen,data1,data2)
09618 off64_t kilo64;
09619 long long reclen;
09620 long long *data1,*data2;
09621 #endif
09622 {
09623     double writeintime;
09624     double starttime1;
09625     double walltime, cputime;
09626     double compute_val = (double)0;
09627     long long i;
09628     off64_t numrecs64;
09629     long long flags;
09630     long long Index=0;
09631     unsigned long long writeinrate;
09632     off64_t filebytes64;
09633     off64_t lock_offset=0;
09634     int fd,wval;
09635     char *maddr;
09636     char *wmaddr,*free_addr,*nbuff;
09637 #if defined(VXFS) || defined(solaris)
09638     int test_foo=0;
09639 #endif
09640 #ifdef ASYNC_IO
09641     struct cache *gc=0;
09642 #else
09643     long long *gc=0;
09644 #endif
09645 
09646     walltime=cputime=0;
09647     maddr=wmaddr=free_addr=nbuff=0;
09648     numrecs64 = (kilo64*1024)/reclen;
09649     filebytes64 = numrecs64*reclen;
09650 /*  flags = O_RDWR|O_CREAT|O_TRUNC;*/
09651     flags = O_RDWR|O_CREAT;
09652 #if ! defined(DONT_HAVE_O_DIRECT)
09653 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
09654     if(direct_flag)
09655         flags |=O_DIRECT;
09656 #endif
09657 #if defined(TRU64)
09658     if(direct_flag)
09659         flags |=O_DIRECTIO;
09660 #endif
09661 #endif
09662     if(oflag)
09663         flags |= O_SYNC;
09664 #if defined(O_DSYNC)
09665     if(odsync)
09666         flags |= O_DSYNC;
09667 #endif
09668 #if defined(_HPUX_SOURCE) || defined(linux)
09669     if(read_sync)
09670         flags |=O_RSYNC|O_SYNC;
09671 #endif
09672 /*
09673     if (!no_unlink)
09674     {
09675        if(check_filename(filename))
09676         unlink(filename);
09677     }
09678 */
09679     if(Uflag) /* Unmount and re-mount the mountpoint */
09680     {
09681         purge_buffer_cache();
09682     }
09683         if((fd = I_OPEN(filename, (int)flags,0640))<0)
09684         {
09685                     printf("\nCan not open temporary file %s for write.\n",filename);
09686             perror("open");
09687                     exit(84);
09688         }
09689 #ifdef VXFS
09690     if(direct_flag)
09691     {
09692         ioctl(fd,VX_SETCACHE,VX_DIRECT);
09693         ioctl(fd,VX_GETCACHE,&test_foo);
09694         if(test_foo == 0)
09695         {
09696             if(!client_iozone)
09697               printf("\nVxFS advanced setcache feature not available.\n");
09698             exit(3);
09699         }
09700     }
09701 #endif
09702 #if defined(solaris)
09703                if(direct_flag)
09704                {
09705                        test_foo = directio(fd, DIRECTIO_ON);
09706                        if(test_foo != 0)
09707                        {
09708                                if(!client_iozone)
09709                                  printf("\ndirectio not available.\n");
09710                                exit(3);
09711                        }
09712                }
09713 #endif
09714     if(mmapflag)
09715     {
09716         maddr=(char *)initfile(fd,filebytes64,1,PROT_READ|PROT_WRITE);
09717     }
09718 #ifdef ASYNC_IO
09719     if(async_flag)
09720         async_init(&gc,fd,direct_flag);
09721 #endif
09722     wval=fsync(fd);
09723     if(wval==-1){
09724         perror("fsync");
09725         signal_handler();
09726     }
09727     nbuff=mainbuffer;
09728     mbuffer=mainbuffer;
09729     if(fetchon)
09730         fetchit(nbuff,reclen);
09731     /*
09732     wval=write(fd, nbuff, (size_t) reclen);
09733     if(wval != reclen)
09734     {
09735 #ifdef NO_PRINT_LLD
09736             printf("\nError writing block %ld, fd= %d\n", 0, fd);
09737 #else
09738             printf("\nError writing block %lld, fd= %d\n", 0, fd);
09739 #endif
09740         if(wval==-1)
09741             perror("write");
09742         signal_handler();
09743     }
09744     */
09745     if(verify || dedup || dedup_interior)
09746         fill_buffer(nbuff,reclen,(long long)pattern,sverify,(long long)0);
09747     starttime1 = time_so_far();
09748     if(cpuutilflag)
09749     {
09750         walltime = time_so_far();
09751         cputime  = cputime_so_far();
09752     }
09753     for(i=0; i<numrecs64; i++){
09754         if(rlocking)
09755         {
09756             lock_offset=I_LSEEK(fd,0,SEEK_CUR);
09757             mylockr((int) fd, (int) 1, (int)0,
09758               lock_offset, reclen);
09759         }
09760         if(compute_flag)
09761             compute_val+=do_compute(compute_time);
09762             if(multi_buffer)
09763             {
09764                     Index +=reclen;
09765                         if(Index > (MAXBUFFERSIZE-reclen))
09766                                 Index=0;
09767                         nbuff = mbuffer + Index;
09768                 }
09769         if(async_flag && no_copy_flag)
09770         {
09771             free_addr=nbuff=(char *)malloc((size_t)reclen+page_size);
09772             nbuff=(char *)(((long)nbuff+(long)page_size) & (long)~(page_size-1));
09773             if(verify || dedup || dedup_interior)
09774                 fill_buffer(nbuff,reclen,(long long)pattern,sverify,(long long)0);
09775         }
09776         if((verify & diag_v) || dedup || dedup_interior)
09777             fill_buffer(nbuff,reclen,(long long)pattern,sverify,(long long)0);
09778         if(purge)
09779             purgeit(nbuff,reclen);
09780         if(mmapflag)
09781         {
09782             wmaddr = &maddr[i*reclen];
09783             fill_area((long long*)nbuff,(long long*)wmaddr,(long long)reclen);
09784             if(!mmapnsflag)
09785             {
09786               if(mmapasflag)
09787                 msync(wmaddr,(size_t)reclen,MS_ASYNC);
09788               if(mmapssflag)
09789                 msync(wmaddr,(size_t)reclen,MS_SYNC);
09790             }
09791         }
09792         else
09793         {
09794               if(async_flag)
09795               {
09796                  if(no_copy_flag)
09797                    async_write_no_copy(gc, (long long)fd, nbuff, reclen, (i*reclen), depth,free_addr);
09798                  else
09799                    async_write(gc, (long long)fd, nbuff, reclen, (i*reclen), depth);
09800               }
09801               else
09802               {
09803                    wval=write(fd, nbuff, (size_t) reclen);
09804                    if(wval != reclen)
09805                    {
09806 #ifdef NO_PRINT_LLD
09807                        printf("\nError writing block %ld, fd= %d\n", i, fd);
09808 #else
09809                        printf("\nError writing block %lld, fd= %d\n", i, fd);
09810 #endif
09811                    if(wval==-1)
09812                     perror("write");
09813                    signal_handler();
09814                    }
09815               }
09816         }
09817         if(rlocking)
09818         {
09819             mylockr((int) fd, (int) 0, (int)0,
09820               lock_offset, reclen);
09821         }
09822         if (!(h_flag || k_flag || mmapflag))
09823         {
09824           I_LSEEK(fd, (off64_t)0,SEEK_SET);
09825         }
09826     }
09827 
09828 #ifdef ASYNC_IO
09829     if(async_flag)
09830     {
09831         end_async(gc);
09832         gc=0;
09833     }
09834 #endif
09835     if(include_flush)
09836     {
09837         if(mmapflag)
09838             msync(maddr,(size_t)filebytes64,MS_SYNC);/* Clean up before read starts running */
09839         else
09840         {
09841             wval=fsync(fd);
09842             if(wval==-1){
09843                 perror("fsync");
09844                 signal_handler();
09845             }
09846         }
09847     }
09848     if(include_close)
09849     {
09850         if(mmapflag)
09851             mmap_end(maddr,(unsigned long long)filebytes64);
09852         wval=close(fd);
09853         if(wval==-1){
09854             perror("close");
09855             signal_handler();
09856         }
09857     }
09858     writeintime = ((time_so_far() - starttime1)-time_res)-
09859         compute_val;
09860     if(cpuutilflag)
09861     {
09862         cputime  = cputime_so_far() - cputime;
09863         if (cputime < cputime_res)
09864             cputime = 0.0;
09865         walltime = time_so_far() - walltime;
09866         if (walltime < cputime)
09867            walltime = cputime;
09868     }
09869     if(writeintime < (double).000001) 
09870     {
09871         writeintime= time_res;
09872         if(rec_prob < reclen)
09873             rec_prob = reclen;
09874         res_prob=1;
09875     }
09876 
09877     if(!include_close)
09878     {
09879         if(mmapflag)
09880             msync(maddr,(size_t)filebytes64,MS_SYNC);/* Clean up before read starts running */
09881         else
09882         {
09883             wval=fsync(fd);
09884             if(wval==-1){
09885                 perror("fsync");
09886                 signal_handler();
09887             }
09888         }
09889         if(mmapflag)
09890             mmap_end(maddr,(unsigned long long)filebytes64);
09891         wval=close(fd);
09892         if(wval==-1){
09893             perror("close");
09894             signal_handler();
09895         }
09896 
09897     }
09898 
09899     if(OPS_flag || MS_flag){
09900        filebytes64=filebytes64/reclen;
09901     }
09902     if(MS_flag)
09903     {
09904         writeinrate=1000000.0*(writeintime / (double)filebytes64);
09905     }
09906       else
09907       {
09908             writeinrate = (unsigned long long) ((double) filebytes64 / writeintime);
09909       }
09910     if(!(OPS_flag || MS_flag))
09911         writeinrate >>= 10;
09912     /* Must save walltime & cputime before calling store_value() for each/any cell.*/
09913     if(cpuutilflag)
09914         store_times(walltime, cputime);
09915     store_value((off64_t)writeinrate);
09916 #ifdef NO_PRINT_LLD
09917     if(!silent) printf(" %8ld",writeinrate);
09918 #else
09919     if(!silent) printf(" %8lld",writeinrate);
09920 #endif
09921     if(!silent) fflush(stdout);
09922     if(restf)
09923         sleep((int)rest_val);
09924 }
09925 
09926 /************************************************************************/
09927 /* read_stride_perf_test                            */
09928 /* Read with a constant stride test                 */
09929 /************************************************************************/
09930 #ifdef HAVE_ANSIC_C
09931 void read_stride_perf_test(off64_t kilos64,long long reclen,long long *data1,long long *data2)
09932 #else
09933 void read_stride_perf_test(kilos64,reclen,data1,data2)
09934 off64_t kilos64;
09935 long long reclen;
09936 long long *data1, *data2;
09937 #endif
09938 {
09939     double strideintime;
09940     double starttime1;
09941     double compute_val = (double)0;
09942     double walltime, cputime;
09943     off64_t numrecs64,current_position;
09944     long long Index = 0;
09945     off64_t i,savepos64 = 0;
09946     unsigned long long strideinrate;
09947     off64_t filebytes64;
09948     off64_t lock_offset=0;
09949     long long uu;
09950     off64_t stripewrap=0;
09951     int fd,open_flags;
09952     volatile char *buffer1;
09953     char *nbuff;
09954     char *maddr;
09955     char *wmaddr;
09956 #if defined(VXFS) || defined(solaris)
09957     int test_foo=0;
09958 #endif
09959 #ifdef ASYNC_IO
09960     struct cache *gc=0;
09961 #else
09962     long long *gc=0;
09963 #endif
09964 
09965     walltime=cputime=0;
09966     nbuff=maddr=wmaddr=0;
09967     open_flags=O_RDONLY;
09968 #if ! defined(DONT_HAVE_O_DIRECT)
09969 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
09970     if(direct_flag)
09971         open_flags |=O_DIRECT;
09972 #endif
09973 #if defined(TRU64)
09974     if(direct_flag)
09975         open_flags |=O_DIRECTIO;
09976 #endif
09977 #endif
09978 #if defined(_HPUX_SOURCE) || defined(linux)
09979     if(read_sync)
09980         open_flags |=O_RSYNC|O_SYNC;
09981 #endif
09982     next64 = (off64_t)0;
09983     numrecs64 = (kilos64*1024)/reclen;
09984     filebytes64 = numrecs64*reclen;
09985     if(Uflag) /* Unmount and re-mount the mountpoint */
09986     {
09987         purge_buffer_cache();
09988     }
09989         if((fd = I_OPEN(filename, (int)open_flags, 0640))<0)
09990         {
09991                     printf("\nCan not open temporary file for read\n");
09992             perror("open");
09993                     exit(86);
09994         }
09995 #ifdef ASYNC_IO
09996     if(async_flag)
09997         async_init(&gc,fd,direct_flag);
09998 #endif
09999 
10000 #ifdef VXFS
10001     if(direct_flag)
10002     {
10003         ioctl(fd,VX_SETCACHE,VX_DIRECT);
10004         ioctl(fd,VX_GETCACHE,&test_foo);
10005         if(test_foo == 0)
10006         {
10007             if(!client_iozone)
10008               printf("\nVxFS advanced setcache feature not available.\n");
10009             exit(3);
10010         }
10011     }
10012 #endif
10013 #if defined(solaris)
10014                if(direct_flag)
10015                {
10016                        test_foo = directio(fd, DIRECTIO_ON);
10017                        if(test_foo != 0)
10018                        {
10019                                if(!client_iozone)
10020                                  printf("\ndirectio not available.\n");
10021                                exit(3);
10022                        }
10023                }
10024 #endif
10025     if(mmapflag)
10026     {
10027         maddr=(char *)initfile(fd,filebytes64,0,PROT_READ);
10028     }
10029     fsync(fd);
10030     current_position=0;
10031     nbuff=mainbuffer;
10032     mbuffer=mainbuffer;
10033     if(fetchon)
10034         fetchit(nbuff,reclen);
10035     starttime1 = time_so_far();
10036     if(cpuutilflag)
10037     {
10038         walltime = time_so_far();
10039         cputime  = cputime_so_far();
10040     }
10041     for(i=0; i<numrecs64; i++){
10042         if(rlocking)
10043         {
10044             lock_offset=I_LSEEK(fd,0,SEEK_CUR);
10045             mylockr((int) fd, (int) 1, (int)1,
10046               lock_offset, reclen);
10047         }
10048         if(compute_flag)
10049             compute_val+=do_compute(compute_time);
10050             if(multi_buffer)
10051                 {
10052                        Index +=reclen;
10053                        if(Index > (MAXBUFFERSIZE-reclen))
10054                                 Index=0;
10055                        nbuff = mbuffer + Index;
10056                 }
10057         if(purge)
10058             purgeit(nbuff,reclen);
10059         if(verify)
10060         {
10061             savepos64=current_position/reclen;
10062         }
10063         if(mmapflag)
10064         {
10065             wmaddr = &maddr[current_position];
10066             fill_area((long long*)wmaddr,(long long*)nbuff,(long long)reclen);
10067         }
10068         else
10069         {
10070             if(async_flag)
10071             {
10072                 if(no_copy_flag)
10073                   async_read_no_copy(gc, (long long)fd, &buffer1, current_position,
10074                     reclen, stride,(numrecs64*reclen),depth);
10075                 else
10076                    async_read(gc, (long long)fd, nbuff, current_position, reclen,
10077                      stride,(numrecs64*reclen),depth);
10078             }
10079             else
10080             {
10081               if((uu=read((int)fd, (void*)nbuff, (size_t) reclen)) != reclen)
10082               {
10083 #ifdef NO_PRINT_LLD
10084                     printf("\nError reading block %ld, fd= %d Filename %s Read returned %ld\n", i, fd,filename,uu);
10085                     printf("\nSeeked to %ld Reclen = %ld\n", savepos64,reclen);
10086 #else
10087                     printf("\nError reading block %lld, fd= %d Filename %s Read returned %lld\n", i, fd,filename,uu);
10088                     printf("\nSeeked to %lld Reclen = %lld\n", savepos64,reclen);
10089 #endif
10090                 perror("read");
10091                     exit(88);
10092               }
10093             }
10094         }
10095         if(rlocking)
10096         {
10097             mylockr((int) fd, (int) 0, (int)1,
10098               lock_offset, reclen);
10099         }
10100         current_position+=reclen;
10101         if(verify){
10102             if(async_flag && no_copy_flag)
10103             {
10104                if(verify_buffer(buffer1,reclen, (off64_t)savepos64 ,reclen,(long long)pattern,sverify)){
10105                 exit(89);
10106                }
10107             }
10108             else
10109             {
10110                if(verify_buffer(nbuff,reclen, (off64_t)savepos64 ,reclen,(long long)pattern,sverify)){
10111                 exit(90);
10112                }
10113             }
10114         }
10115         if(async_flag && no_copy_flag)
10116             async_release(gc);
10117             
10118         /* This is a bit tricky.  The goal is to read with a stride through
10119            the file. The problem is that you need to touch all of the file
10120            blocks. So.. the first pass through you read with a constant stride.
10121            When you hit eof then add 1 to the beginning offset of the next
10122            time through the file. The rub here is that eventually adding
10123            1 will cause the initial start location plus the STRIDE to be
10124            beyond eof. So... when this happens the initial offset for the
10125            next pass needs to be set back to 0.
10126         */
10127         if(current_position + (stride * reclen) >= (numrecs64 * reclen)-reclen) 
10128         {
10129             current_position=0;
10130 
10131             stripewrap++;
10132               
10133             if(numrecs64 <= stride)
10134             {
10135                 current_position=0;
10136             }
10137             else
10138             {
10139                 current_position = (off64_t)((stripewrap)%numrecs64)*reclen;
10140             }
10141 
10142             if (!(h_flag || k_flag || mmapflag))
10143             {
10144               if(I_LSEEK(fd,current_position,SEEK_SET)<0)
10145               {
10146                 perror("lseek");
10147                 exit(91);
10148               }
10149             }
10150         }
10151         else            
10152         {
10153             current_position+=(stride*reclen)-reclen;
10154             if (!(h_flag || k_flag || mmapflag))
10155             {
10156               if(I_LSEEK(fd,current_position,SEEK_SET)<0)
10157               {
10158                 perror("lseek");
10159                 exit(93);
10160               };
10161             }
10162         }
10163     }
10164     if(cpuutilflag)
10165     {
10166         cputime  = cputime_so_far() - cputime;
10167         if (cputime < cputime_res)
10168             cputime = 0.0;
10169         walltime = time_so_far() - walltime;
10170         if (walltime < cputime)
10171            walltime = cputime;
10172     }
10173 
10174 #ifdef ASYNC_IO
10175     if(async_flag)
10176     {
10177         end_async(gc);
10178         gc=0;
10179     }
10180 #endif
10181     if(include_flush)
10182     {
10183         if(mmapflag)
10184             msync(maddr,(size_t)filebytes64,MS_SYNC);
10185         else
10186             fsync(fd);
10187     }
10188     if(include_close)
10189     {
10190         if(mmapflag)
10191         {
10192             mmap_end(maddr,(unsigned long long)filebytes64);
10193         }
10194         close(fd);
10195     }
10196     strideintime = ((time_so_far() - starttime1)-time_res)
10197         -compute_val;
10198     if(strideintime < (double).000001) 
10199     {
10200         strideintime= time_res;
10201         if(rec_prob < reclen)
10202             rec_prob = reclen;
10203         res_prob=1;
10204     }
10205 
10206     if(!include_close)
10207     {
10208         if(mmapflag)
10209             msync(maddr,(size_t)filebytes64,MS_SYNC);
10210         else
10211             fsync(fd);
10212         if(mmapflag)
10213         {
10214             mmap_end(maddr,(unsigned long long)filebytes64);
10215         }
10216         close(fd);
10217     }
10218 
10219     if(OPS_flag || MS_flag){
10220        filebytes64=filebytes64/reclen;
10221     }
10222     if(MS_flag)
10223     {
10224         strideinrate=1000000.0*(strideintime / (double)filebytes64);
10225     }
10226       else
10227       {
10228             strideinrate = (unsigned long long) ((double) filebytes64 / strideintime);
10229       }
10230     if(!(OPS_flag || MS_flag))
10231         strideinrate >>= 10;
10232     /* Must save walltime & cputime before calling store_value() for each/any cell.*/
10233     if(cpuutilflag)
10234         store_times(walltime, cputime);
10235     store_value((off64_t)strideinrate);
10236 #ifdef NO_PRINT_LLD
10237     if(!silent) printf(" %8ld",strideinrate);
10238 #else
10239     if(!silent) printf(" %8lld",strideinrate);
10240 #endif
10241     if(!silent) fflush(stdout);
10242     if(restf)
10243         sleep((int)rest_val);
10244 }
10245 
10246 #ifdef HAVE_PREAD
10247 /************************************************************************/
10248 /* pwrite_perf_test                             */
10249 /* pwrite and re-write test                     */
10250 /************************************************************************/
10251 #ifdef HAVE_ANSIC_C
10252 void pwrite_perf_test(off64_t kilos64,long long reclen,long long *data1,long long *data2)
10253 #else
10254 void pwrite_perf_test(kilos64,reclen,data1,data2)
10255 off64_t kilos64;
10256 long long reclen;
10257 long long *data1,*data2;
10258 #endif
10259 {
10260     double pwritetime[2];
10261     double starttime1;
10262     double walltime[2], cputime[2];
10263     double compute_val = (double)0;
10264     long long i,j;
10265     long long Index = 0;
10266     unsigned long long pwriterate[2];
10267     off64_t filebytes64;
10268     long long flags_here = 0;
10269     int fd,ltest,wval;
10270     off64_t numrecs64,traj_offset;
10271     off64_t lock_offset=0;
10272     long long traj_size;
10273 #if defined(VXFS) || defined(solaris)
10274     int test_foo=0;
10275 #endif
10276     char *nbuff;
10277 
10278     traj_offset=0;
10279     nbuff=mainbuffer;
10280     if(w_traj_flag)
10281     {
10282         filebytes64 = w_traj_fsize;
10283         numrecs64=w_traj_ops;
10284     }
10285     else
10286     {
10287         numrecs64 = (kilos64*1024)/reclen;
10288         filebytes64 = numrecs64*reclen;
10289     }
10290     fd = 0;
10291     if(oflag){
10292         flags_here = O_SYNC|O_RDWR;
10293     }
10294     else
10295     {
10296         flags_here = O_RDWR;
10297     }
10298 #if defined(O_DSYNC)
10299     if(odsync)
10300         flags_here |= O_DSYNC;
10301 #endif
10302 
10303 #if defined(_HPUX_SOURCE) || defined(linux)
10304     if(read_sync)
10305         flags_here |=O_RSYNC|O_SYNC;
10306 #endif
10307 
10308 #if ! defined(DONT_HAVE_O_DIRECT)
10309 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
10310     if(direct_flag)
10311         flags_here |=O_DIRECT;
10312 #endif
10313 #if defined(TRU64)
10314     if(direct_flag)
10315         flags_here |=O_DIRECTIO;
10316 #endif
10317 #endif
10318     if(noretest)
10319         ltest=1;
10320     else
10321         ltest=2;
10322     for( j=0; j<ltest; j++)
10323     {
10324         if(j==0)
10325             flags_here |=O_CREAT;
10326         if(cpuutilflag)
10327         {
10328             walltime[j] = time_so_far();
10329             cputime[j]  = cputime_so_far();
10330         }
10331         if(Uflag) /* Unmount and re-mount the mountpoint */
10332         {
10333             purge_buffer_cache();
10334         }
10335         if((fd = I_OPEN(filename, (int)flags_here,0640))<0)
10336         {
10337             printf("\nCan not open temp file: %s\n", 
10338                 filename);
10339             perror("open");
10340             exit(97);
10341         }
10342 #ifdef VXFS
10343         if(direct_flag)
10344         {
10345             ioctl(fd,VX_SETCACHE,VX_DIRECT);
10346             ioctl(fd,VX_GETCACHE,&test_foo);
10347             if(test_foo == 0)
10348             {
10349                 if(!client_iozone)
10350                   printf("\nVxFS advanced setcache feature not available.\n");
10351                 exit(3);
10352             }
10353         }
10354 #endif
10355 #if defined(solaris)
10356         if(direct_flag)
10357         {
10358             test_foo = directio(fd, DIRECTIO_ON);
10359             if(test_foo != 0)
10360             {
10361                 if(!client_iozone)
10362                     printf("\ndirectio not available.\n");
10363                 exit(3);
10364             }
10365         }
10366 #endif
10367         fsync(fd);
10368         nbuff=mainbuffer;
10369         mbuffer=mainbuffer;
10370         if(fetchon)
10371             fetchit(nbuff,reclen);
10372         if(verify || dedup || dedup_interior)
10373             fill_buffer(nbuff,reclen,(long long)pattern,sverify,(long long)0);
10374         starttime1 = time_so_far();
10375             compute_val=(double)0;
10376         if(w_traj_flag)
10377         {
10378             rewind(w_traj_fd);
10379         }
10380         for(i=0; i<numrecs64; i++){
10381             if(w_traj_flag)
10382             {
10383                 traj_offset=get_traj(w_traj_fd, (long long *)&traj_size,(float *)&compute_time,(long)1);
10384                 reclen=traj_size;
10385             }
10386             else
10387                 traj_offset=(i * reclen);
10388             if(rlocking)
10389             {
10390                 lock_offset=traj_offset;
10391                 mylockr((int) fd, (int) 1, (int)0,
10392                   lock_offset, reclen);
10393             }
10394             if(compute_flag)
10395                 compute_val+=do_compute(compute_time);
10396                         if(multi_buffer)
10397                         {
10398                                 Index +=reclen;
10399                                 if(Index > (MAXBUFFERSIZE-reclen))
10400                                         Index=0;
10401                                 nbuff = mbuffer + Index;
10402                         }
10403             if((verify && diag_v) || dedup || dedup_interior)
10404                 fill_buffer(nbuff,reclen,(long long)pattern,sverify,i);
10405             if(purge)
10406                 purgeit(nbuff,reclen);
10407             if(I_PWRITE(fd, nbuff, reclen, traj_offset) != reclen)
10408             {
10409 #ifdef NO_PRINT_LLD
10410                     printf("\nError pwriting block %ld, fd= %d\n", i,
10411                      fd);
10412 #else
10413                     printf("\nError pwriting block %lld, fd= %d\n", i,
10414                      fd);
10415 #endif
10416                 perror("pwrite");
10417                 signal_handler();
10418             }
10419             if(rlocking)
10420             {
10421                 mylockr((int) fd, (int) 0, (int)0,
10422                   lock_offset, reclen);
10423             }
10424         }
10425         if(include_flush)
10426         {
10427             wval=fsync(fd);
10428             if(wval==-1){
10429                 perror("fsync");
10430                 signal_handler();
10431             }
10432         }
10433         if(include_close)
10434         {
10435             wval=close(fd);
10436             if(wval==-1){
10437                 perror("close");
10438                 signal_handler();
10439             }
10440         }
10441         pwritetime[j] = ((time_so_far() - starttime1)-time_res)
10442             -compute_val;
10443         if(pwritetime[j] < (double).000001) 
10444         {
10445             pwritetime[j]= time_res;
10446             if(rec_prob < reclen)
10447                 rec_prob = reclen;
10448             res_prob=1;
10449         }
10450         if(!include_close)
10451         {
10452             wval=fsync(fd);
10453             if(wval==-1){
10454                 perror("fsync");
10455                 signal_handler();
10456             }
10457             wval=close(fd);
10458             if(wval==-1){
10459                 perror("close");
10460                 signal_handler();
10461             }
10462         }
10463 
10464         if(cpuutilflag)
10465         {
10466             cputime[j]  = cputime_so_far() - cputime[j];
10467             if (cputime[j] < cputime_res)
10468                 cputime[j] = 0.0;
10469             walltime[j] = time_so_far() - walltime[j];
10470             if (walltime[j] < cputime[j])
10471                walltime[j] = cputime[j];
10472         }
10473         if(restf)
10474             sleep((int)rest_val);
10475     }
10476     if(OPS_flag || MS_flag){
10477        filebytes64=filebytes64/reclen;
10478     }
10479     for(j=0;j<ltest;j++){
10480         if(MS_flag)
10481         {
10482             pwriterate[j]=1000000.0*(pwritetime[j] / (double)filebytes64);
10483             continue;
10484         }
10485             else
10486             {
10487                   pwriterate[j] = 
10488               (unsigned long long) ((double) filebytes64 / pwritetime[j]);
10489             }
10490         if(!(OPS_flag || MS_flag))
10491             pwriterate[j] >>= 10;
10492     }
10493     /* Must save walltime & cputime before calling store_value() for each/any cell.*/
10494     if(noretest)
10495     {
10496         pwriterate[1]=(long long)0;
10497         if(cpuutilflag)
10498         {
10499             walltime[1]=0.0;
10500             cputime[1]=0.0;
10501         }
10502     }
10503     
10504     if(cpuutilflag)
10505         store_times(walltime[0], cputime[0]);
10506     store_value((off64_t)pwriterate[0]);
10507     if(cpuutilflag)
10508         store_times(walltime[1], cputime[1]);
10509     store_value((off64_t)pwriterate[1]);
10510 #ifdef NO_PRINT_LLD
10511     if(!silent) printf("%8ld",pwriterate[0]);
10512     if(!silent) printf("%9ld",pwriterate[1]);
10513     if(!silent) fflush(stdout);
10514 #else
10515     if(!silent) printf("%8lld",pwriterate[0]);
10516     if(!silent) printf("%9lld",pwriterate[1]);
10517     if(!silent) fflush(stdout);
10518 #endif
10519 }
10520 
10521 /************************************************************************/
10522 /* pread_perf_test                              */
10523 /* pread and re-pread test                      */
10524 /************************************************************************/
10525 #ifdef HAVE_PREAD
10526 #ifdef HAVE_ANSIC_C
10527 void pread_perf_test(off64_t kilos64,long long reclen,long long *data1,long long *data2)
10528 #else
10529 void pread_perf_test(kilos64,reclen,data1,data2)
10530 off64_t kilos64;
10531 long long reclen;
10532 long long *data1, *data2;
10533 #endif
10534 {
10535     double starttime2;
10536     double preadtime[2];
10537     double walltime[2], cputime[2];
10538     double compute_val = (double)0;
10539     long long numrecs64,i;
10540     long long j;
10541     long long Index = 0;
10542     unsigned long long preadrate[2];
10543     off64_t filebytes64;
10544     off64_t lock_offset=0;
10545     int fd,open_flags;
10546     int ltest;
10547     off64_t traj_offset;
10548     long long traj_size;
10549 #if defined(VXFS) || defined(solaris)
10550     int test_foo = 0;
10551 #endif
10552     char *nbuff;
10553 
10554     traj_offset=0;
10555     nbuff=mainbuffer;
10556     open_flags=O_RDONLY;
10557 #if ! defined(DONT_HAVE_O_DIRECT)
10558 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
10559     if(direct_flag)
10560         open_flags |=O_DIRECT;
10561 #endif
10562 #if defined(TRU64)
10563     if(direct_flag)
10564         open_flags |=O_DIRECTIO;
10565 #endif
10566 #endif
10567 #if defined(_HPUX_SOURCE) || defined(linux) || defined(__FreeBSD__) || defined(__DragonFly__)
10568     if(read_sync)
10569         open_flags |=O_RSYNC|O_SYNC;
10570 #endif
10571     if(r_traj_flag)
10572     {
10573         filebytes64 = r_traj_fsize;
10574         numrecs64=r_traj_ops;
10575     }
10576     else
10577     {
10578         numrecs64 = (kilos64*1024)/reclen;
10579         filebytes64 = numrecs64*reclen;
10580     }
10581 
10582     fd = 0;
10583     if(noretest)
10584         ltest=1;
10585     else
10586         ltest=2;
10587     for( j=0; j<ltest; j++ )        /* Pread and Re-Pread */
10588     {
10589         if(cpuutilflag)
10590         {
10591             walltime[j] = time_so_far();
10592             cputime[j]  = cputime_so_far();
10593         }
10594         if(Uflag) /* Unmount and re-mount the mountpoint */
10595         {
10596             purge_buffer_cache();
10597         }
10598         if((fd = I_OPEN(filename, (int)open_flags,0))<0)
10599         {
10600             printf("\nCan not open temporary file %s for read\n",filename);
10601             perror("open");
10602             exit(101);
10603         }
10604 #ifdef VXFS
10605         if(direct_flag)
10606         {
10607             ioctl(fd,VX_SETCACHE,VX_DIRECT);
10608             ioctl(fd,VX_GETCACHE,&test_foo);
10609             if(test_foo == 0)
10610             {
10611                 if(!client_iozone)
10612                   printf("\nVxFS advanced setcache feature not available.\n");
10613                 exit(3);
10614             }
10615         }
10616 #endif
10617 #if defined(solaris)
10618                if(direct_flag)
10619                {
10620                        test_foo = directio(fd, DIRECTIO_ON);
10621                        if(test_foo != 0)
10622                        {
10623                                if(!client_iozone)
10624                                  printf("\ndirectio not available.\n");
10625                                exit(3);
10626                        }
10627                }
10628 #endif
10629         nbuff=mainbuffer;
10630         mbuffer=mainbuffer;
10631         if(fetchon)
10632             fetchit(nbuff,reclen);
10633         starttime2 = time_so_far();
10634             compute_val=(double)0;
10635         if(r_traj_flag)
10636         {
10637             rewind(r_traj_fd);
10638         }
10639         for(i=0; i<numrecs64; i++) 
10640         {
10641             if(r_traj_flag)
10642             {
10643                 traj_offset=get_traj(r_traj_fd, (long long *)&traj_size,(float *)&compute_time,(long)1);
10644                 reclen=traj_size;
10645             }
10646             else
10647                 traj_offset=(i * reclen);
10648             if(rlocking)
10649             {
10650                 lock_offset=traj_offset;
10651                 mylockr((int) fd, (int) 1, (int)1,
10652                   lock_offset, reclen);
10653             }
10654             if(compute_flag)
10655                 compute_val+=do_compute(compute_time);
10656                         if(multi_buffer)
10657                         {
10658                                 Index +=reclen;
10659                                 if(Index > (MAXBUFFERSIZE-reclen))
10660                                         Index=0;
10661                                 nbuff = mbuffer + Index;
10662                         }
10663 
10664             if(purge)
10665                 purgeit(nbuff,reclen);
10666             if(I_PREAD(((int)fd), ((void*)nbuff), ((size_t) reclen),traj_offset ) 
10667                     != reclen)
10668             {
10669 #ifdef NO_PRINT_LLD
10670                 printf("\nError reading block %ld %lx\n", i,(unsigned long)nbuff);
10671 #else
10672                 printf("\nError reading block %lld %lx\n", i,(unsigned long)nbuff);
10673 #endif
10674                 perror("pread");
10675                 exit(103);
10676             }
10677             if(verify){
10678                 if(verify_buffer(nbuff,reclen,(off64_t)i,reclen,(long long)pattern,sverify)){
10679                     exit(104);
10680                 }
10681             }
10682             if(rlocking)
10683             {
10684                 lock_offset=I_LSEEK(fd,0,SEEK_CUR);
10685                 mylockr((int) fd, (int) 1, (int)1,
10686                   lock_offset, reclen);
10687             }
10688         }
10689         if(include_flush)
10690             fsync(fd);
10691         if(include_close)
10692             close(fd);
10693         preadtime[j] = ((time_so_far() - starttime2)-time_res)
10694             -compute_val;
10695         if(preadtime[j] < (double).000001) 
10696         {
10697             preadtime[j]= time_res;
10698             if(rec_prob < reclen)
10699                 rec_prob = reclen;
10700             res_prob=1;
10701         }
10702         if(!include_close)
10703         {
10704             fsync(fd);
10705             close(fd);
10706         }
10707 
10708         if(cpuutilflag)
10709         {
10710             cputime[j]  = cputime_so_far() - cputime[j];
10711             if (cputime[j] < cputime_res)
10712                 cputime[j] = 0.0;
10713             walltime[j] = time_so_far() - walltime[j];
10714             if (walltime[j] < cputime[j])
10715                walltime[j] = cputime[j];
10716         }
10717         if(restf)
10718             sleep((int)rest_val);
10719         }
10720 
10721     filebytes64 = numrecs64*reclen;
10722     if(OPS_flag || MS_flag){
10723        filebytes64=filebytes64/reclen;
10724     }
10725     for(j=0;j<ltest;j++){
10726         if(MS_flag)
10727         {
10728             preadrate[j]=1000000.0*(preadtime[j] / (double)filebytes64);
10729             continue;
10730         }
10731             else
10732             {
10733                   preadrate[j] = 
10734             (unsigned long long) ((double) filebytes64 / preadtime[j]);
10735             }
10736         if(!(OPS_flag || MS_flag))
10737             preadrate[j] >>= 10;
10738     }
10739     if(noretest)
10740     {
10741         preadrate[1]=(long long)0;
10742         if(cpuutilflag)
10743         {
10744             walltime[1]=0.0;
10745             cputime[1]=0.0;
10746         }
10747     }
10748 
10749     /* Must save walltime & cputime before calling store_value() for each/any cell.*/
10750     if(cpuutilflag)
10751         store_times(walltime[0], cputime[0]);
10752     store_value((off64_t)preadrate[0]);
10753     if(cpuutilflag)
10754         store_times(walltime[1], cputime[1]);
10755     store_value((off64_t)preadrate[1]);
10756 #ifdef NO_PRINT_LLD
10757     if(!silent) printf("%8ld",preadrate[0]);
10758     if(!silent) printf("%9ld",preadrate[1]);
10759     if(!silent) fflush(stdout);
10760 #else
10761     if(!silent) printf("%8lld",preadrate[0]);
10762     if(!silent) printf("%9lld",preadrate[1]);
10763     if(!silent) fflush(stdout);
10764 #endif
10765 }
10766 #endif
10767 
10768 #ifdef HAVE_PREADV
10769 /************************************************************************/
10770 /* pwritev_perf_test                                */
10771 /* pwritev and re-pwritev test                      */
10772 /************************************************************************/
10773 #ifdef HAVE_ANSIC_C
10774 void pwritev_perf_test(off64_t kilos64,long long reclen,long long *data1,long long *data2)
10775 #else
10776 void pwritev_perf_test(kilos64,reclen,data1,data2)
10777 off64_t kilos64;
10778 long long reclen;
10779 long long *data1,*data2;
10780 #endif
10781 {
10782     int wval;
10783     double starttime1;
10784     double pwritevtime[2];
10785     double walltime[2], cputime[2];
10786     double compute_val = (double)0;
10787     long long list_off[PVECMAX];
10788     long long numvecs,j,xx;
10789     unsigned long long pwritevrate[2];
10790     off64_t filebytes64,i;
10791     off64_t numrecs64;
10792     int fd,ltest;
10793 #if defined(VXFS) || defined(solaris)
10794     int test_foo = 0;
10795 #endif
10796     long long flags_here;
10797     char *nbuff;
10798 #ifdef MERSENNE
10799         unsigned long long init[4]={0x12345ULL, 0x23456ULL, 0x34567ULL, 0x45678ULL}, length=4;
10800 #endif
10801 
10802     numrecs64 = (kilos64*1024)/reclen;
10803     filebytes64 = numrecs64*reclen;
10804     nbuff = mainbuffer;
10805     fd = 0;
10806     if(oflag)
10807         flags_here = O_SYNC|O_RDWR;
10808     else
10809         flags_here = O_RDWR;
10810 #if defined(O_DSYNC)
10811     if(odsync)
10812         flags_here |= O_DSYNC;
10813 #endif
10814 #if defined(_HPUX_SOURCE) || defined(linux)
10815     if(read_sync)
10816         flags_here |=O_RSYNC|O_SYNC;
10817 #endif
10818 
10819 #if ! defined(DONT_HAVE_O_DIRECT)
10820 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
10821     if(direct_flag)
10822         flags_here |=O_DIRECT;
10823 #endif
10824 #if defined(TRU64)
10825     if(direct_flag)
10826         flags_here |=O_DIRECTIO;
10827 #endif
10828 #endif
10829      
10830     if(noretest)
10831         ltest=1;
10832     else
10833         ltest=2;
10834 
10835     for( j=0; j<ltest; j++)
10836     {
10837         if(j==0)
10838             flags_here |=O_CREAT;
10839         if(cpuutilflag)
10840         {
10841             walltime[j] = time_so_far();
10842             cputime[j]  = cputime_so_far();
10843         }
10844         if(Uflag) /* Unmount and re-mount the mountpoint */
10845         {
10846             purge_buffer_cache();
10847         }
10848         if((fd = I_OPEN(filename, (int)flags_here,0640))<0)
10849         {
10850             printf("\nCan not open temp file: %s\n", 
10851                 filename);
10852             perror("open");
10853             exit(109);
10854         }
10855 #ifdef VXFS
10856         if(direct_flag)
10857         {
10858             ioctl(fd,VX_SETCACHE,VX_DIRECT);
10859             ioctl(fd,VX_GETCACHE,&test_foo);
10860             if(test_foo == 0)
10861             {
10862                 if(!client_iozone)
10863                     printf("\nVxFS advanced setcache feature not available.\n");
10864                 exit(3);
10865             }
10866         }
10867 #endif
10868 #if defined(solaris)
10869         if(direct_flag)
10870         {
10871             test_foo = directio(fd, DIRECTIO_ON);
10872             if(test_foo != 0)
10873             {
10874                 if(!client_iozone)
10875                     printf("\ndirectio not available.\n");
10876                 exit(3);
10877             }
10878         }
10879 #endif
10880         nbuff=mainbuffer;
10881         mbuffer=mainbuffer;
10882         if(fetchon)
10883             fetchit(nbuff,reclen);
10884         numvecs=PVECMAX;
10885                 if(numrecs64 < numvecs) numvecs=numrecs64;
10886                 if(MAXBUFFERSIZE/reclen < PVECMAX) numvecs=MAXBUFFERSIZE/reclen;
10887 
10888 #ifdef MERSENNE
10889                 init_by_array64(init, length);
10890 #else
10891 #ifdef bsd4_2
10892             srand(0);
10893 #else
10894 #ifdef Windows
10895                 srand(0);
10896 #else
10897             srand48(0);
10898 #endif
10899 #endif
10900 #endif
10901         starttime1 = time_so_far();
10902             compute_val=(double)0;
10903         for(i=0; i<numrecs64; i+=numvecs){
10904             if(compute_flag)
10905                 compute_val+=do_compute(compute_time);
10906             if((numrecs64-i) < numvecs) 
10907                 numvecs=numrecs64-i;
10908             create_list((long long *)list_off, reclen, numrecs64);
10909             for(xx=0;xx<numvecs;xx++)
10910             {
10911                 piov[xx].piov_base = 
10912                     (caddr_t)(nbuff+(xx * reclen));
10913                 if(verify || dedup || dedup_interior)
10914                     fill_buffer(piov[xx].piov_base,reclen,(long long)pattern,sverify,i);
10915                 piov[xx].piov_len = reclen;
10916 #ifdef PER_VECTOR_OFFSET
10917                 piov[xx].piov_offset = list_off[xx];
10918 #endif
10919                 if(purge)
10920                     purgeit(piov[xx].piov_base,reclen);
10921             }
10922             if(pwritev(fd, piov,numvecs
10923 #ifndef PER_VECTOR_OFFSET
10924                 , list_off[0]
10925 #endif
10926                 ) != (reclen*numvecs))
10927             {
10928 #ifdef NO_PRINT_LLD
10929                     printf("\nError pwriteving block %ld, fd= %d\n", i,
10930                      fd);
10931 #else
10932                     printf("\nError pwriteving block %lld, fd= %d\n", i,
10933                      fd);
10934 #endif
10935                 perror("pwritev");
10936                     exit(113);
10937             }
10938         }
10939 
10940         if(include_flush)
10941         {
10942             wval=fsync(fd);
10943             if(wval==-1){
10944                 perror("fsync");
10945                 signal_handler();
10946             }
10947         }
10948         if(include_close)
10949         {
10950             wval=close(fd);
10951             if(wval==-1){
10952                 perror("close");
10953                 signal_handler();
10954             }
10955         }
10956         pwritevtime[j] = ((time_so_far() - starttime1)-time_res)
10957             -compute_val;
10958         if(pwritevtime[j] < (double).000001) 
10959         {
10960             pwritevtime[j]= time_res;
10961             if(rec_prob < reclen)
10962                 rec_prob = reclen;
10963             res_prob=1;
10964         }
10965         if(!include_close)
10966         {
10967             wval=fsync(fd);
10968             if(wval==-1){
10969                 perror("fsync");
10970                 signal_handler();
10971             }
10972             wval=close(fd);
10973             if(wval==-1){
10974                 perror("close");
10975                 signal_handler();
10976             }
10977         }
10978 
10979         if(cpuutilflag)
10980         {
10981             cputime[j]  = cputime_so_far() - cputime[j];
10982             if (cputime[j] < cputime_res)
10983                 cputime[j] = 0.0;
10984             walltime[j] = time_so_far() - walltime[j];
10985             if (walltime[j] < cputime[j])
10986                walltime[j] = cputime[j];
10987         }
10988         if(restf)
10989             sleep((int)rest_val);
10990     }
10991     if(OPS_flag || MS_flag){
10992        filebytes64=filebytes64/reclen;
10993     }
10994     for(j=0;j<ltest;j++){
10995         if(MS_flag)
10996         {
10997             pwritevrate[j]=1000000.0*(pwritevtime[j] / (double)filebytes64);
10998             continue;
10999         }
11000             else
11001             {
11002                   pwritevrate[j] = 
11003               (unsigned long long) ((double) filebytes64 / pwritevtime[j]);
11004             }
11005         if(!(OPS_flag || MS_flag))
11006             pwritevrate[j] >>= 10;
11007     }
11008     if(noretest)
11009     {
11010         pwritevrate[1]=(long long)0;
11011         if(cpuutilflag)
11012         {
11013             walltime[1]=0.0;
11014             cputime[1]=0.0;
11015         }
11016     }   
11017     /* Must save walltime & cputime before calling store_value() for each/any cell.*/
11018     if(cpuutilflag)
11019         store_times(walltime[0], cputime[0]);
11020     store_value((off64_t)pwritevrate[0]);
11021     if(cpuutilflag)
11022         store_times(walltime[1], cputime[1]);
11023     store_value((off64_t)pwritevrate[1]);
11024 #ifdef NO_PRINT_LLD
11025     if(!silent) printf("%9ld",pwritevrate[0]);
11026     if(!silent) printf("%10ld",pwritevrate[1]);
11027     if(!silent) fflush(stdout);
11028 #else
11029     if(!silent) printf("%9lld",pwritevrate[0]);
11030     if(!silent) printf("%10lld",pwritevrate[1]);
11031     if(!silent) fflush(stdout);
11032 #endif
11033 }
11034 #endif
11035 
11036 
11037 #ifdef HAVE_PREADV
11038 /**************************************************************************/
11039 /* create_list()                              */
11040 /* Creates a list of PVECMAX entries that are unique (non over lapping ). */
11041 /* Each of these offsets are then used in a vector (preadv/pwritev)   */
11042 /**************************************************************************/
11043 #ifdef HAVE_ANSIC_C
11044 void create_list(long long *list_off, long long reclen, off64_t numrecs64)
11045 #else
11046 void create_list(list_off, reclen, numrecs64)
11047 long long *list_off;
11048 long long reclen; 
11049 off64_t numrecs64;
11050 #endif
11051 {
11052     long long found,i,j;
11053     long long numvecs;
11054     unsigned long long big_rand = -1;
11055 #if defined (bsd4_2) || defined(Windows)
11056     long long rand1,rand2,rand3;
11057 #endif
11058 
11059     numvecs = PVECMAX;
11060     if(numrecs64< numvecs)
11061         numvecs = numrecs64;
11062     for(j=0;j<numvecs;j++)
11063         list_off[j]=0;  
11064     for(j=0;j<numvecs;j++)
11065     {
11066 again:
11067         found = 0;
11068 #ifdef MERSENNE
11069                 big_rand = genrand64_int64();
11070         offset64 = reclen * (big_rand%numrecs64);
11071 #else
11072 #ifdef bsd4_2
11073         rand1=(long long)rand();
11074         rand2=(long long)rand();
11075         rand3=(long long)rand();
11076         big_rand=(rand1<<32)|(rand2<<16)|(rand3);
11077         offset64 = reclen * (big_rand%numrecs64);
11078 #else
11079 #ifdef Windows
11080         rand1=(long long)rand();
11081         rand2=(long long)rand();
11082         rand3=(long long)rand();
11083         big_rand=(rand1<<32)|(rand2<<16)|(rand3);
11084         offset64 = reclen * (big_rand%numrecs64);
11085 #else
11086         offset64 = reclen * (lrand48()%numrecs64);
11087 #endif
11088 #endif
11089 #endif
11090 
11091         for(i=0;i<j;i++)
11092         {
11093             if(list_off[i] == offset64)
11094             {
11095                 found++;
11096                 break;
11097             }
11098         }
11099         if(!found)
11100             list_off[j]=offset64;
11101         else
11102         {
11103             goto again;
11104         }
11105     }
11106 }
11107 #endif
11108 
11109 #ifdef HAVE_PREADV
11110 /************************************************************************/
11111 /* preadv_perf_test                             */
11112 /* preadv and re-preadv test                        */
11113 /************************************************************************/
11114 #ifdef HAVE_ANSIC_C
11115 void preadv_perf_test(off64_t kilos64,long long reclen,long long *data1,long long *data2)
11116 #else
11117 void preadv_perf_test(kilos64,reclen,data1,data2)
11118 off64_t kilos64;
11119 long long reclen;
11120 long long *data1,*data2;
11121 #endif
11122 {
11123     double starttime2;
11124     double preadvtime[2];
11125     double walltime[2], cputime[2];
11126     double compute_val = (double)0;
11127     long long list_off[PVECMAX];
11128     long long numvecs,i,j,xx;
11129     off64_t numrecs64;
11130     unsigned long long preadvrate[2];
11131     off64_t filebytes64;
11132     int fd,open_flags,ltest;
11133 #if defined(VXFS) || defined(solaris)
11134     int test_foo = 0;
11135 #endif
11136     char *nbuff;
11137 #ifdef MERSENNE
11138         unsigned long long init[4]={0x12345ULL, 0x23456ULL, 0x34567ULL, 0x45678ULL}, length=4;
11139 #endif
11140 
11141     open_flags=O_RDONLY;
11142 #if ! defined(DONT_HAVE_O_DIRECT)
11143 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
11144     if(direct_flag)
11145         open_flags |=O_DIRECT;
11146 #endif
11147 #if defined(TRU64)
11148     if(direct_flag)
11149         open_flags |=O_DIRECTIO;
11150 #endif
11151 #endif
11152 #if defined(_HPUX_SOURCE) || defined(linux)
11153     if(read_sync)
11154         open_flags |=O_RSYNC|O_SYNC;
11155 #endif
11156     numrecs64 = (kilos64*1024)/reclen;
11157     filebytes64 = numrecs64*reclen;
11158     nbuff = mainbuffer;
11159     fd = 0;
11160     if(noretest)
11161         ltest=1;
11162     else
11163         ltest=2;
11164 
11165     for( j=0; j<ltest; j++ )
11166     {
11167         if(cpuutilflag)
11168         {
11169             walltime[j] = time_so_far();
11170             cputime[j]  = cputime_so_far();
11171         }
11172         if(Uflag) /* Unmount and re-mount the mountpoint */
11173         {
11174             purge_buffer_cache();
11175         }
11176 
11177         if((fd = I_OPEN(filename, (int)open_flags,0))<0)
11178         {
11179             printf("\nCan not open temporary file for preadv\n");
11180             perror("open");
11181             exit(114);
11182         }
11183 #ifdef VXFS
11184         if(direct_flag)
11185         {
11186             ioctl(fd,VX_SETCACHE,VX_DIRECT);
11187             ioctl(fd,VX_GETCACHE,&test_foo);
11188             if(test_foo == 0)
11189             {
11190                 if(!client_iozone)
11191                   printf("\nVxFS advanced setcache feature not available.\n");
11192                 exit(3);
11193             }
11194         }
11195 #endif
11196 #if defined(solaris)
11197                if(direct_flag)
11198                {
11199                        test_foo = directio(fd, DIRECTIO_ON);
11200                        if(test_foo != 0)
11201                        {
11202                                if(!client_iozone)
11203                                  printf("\ndirectio not available.\n");
11204                                exit(3);
11205                        }
11206                }
11207 #endif
11208         nbuff=mainbuffer;
11209         mbuffer=mainbuffer;
11210         if(fetchon)
11211             fetchit(nbuff,reclen);
11212         numvecs=PVECMAX;
11213                 if(numrecs64 < numvecs) numvecs=numrecs64;
11214                 if(MAXBUFFERSIZE/reclen < PVECMAX) numvecs=MAXBUFFERSIZE/reclen;
11215 
11216 #ifdef MERSENNE
11217                init_by_array64(init, length);
11218 #else
11219 #ifdef bsd4_2
11220             srand(0);
11221 #else
11222 #ifdef Windows
11223                 srand(0);
11224 #else
11225             srand48(0);
11226 #endif
11227 #endif
11228 #endif
11229         starttime2 = time_so_far();
11230             compute_val=(double)0;
11231         for(i=0; i<(numrecs64); i+=numvecs) 
11232         {
11233             if(compute_flag)
11234                 compute_val+=do_compute(compute_time);
11235             if((numrecs64-i) < numvecs) 
11236                 numvecs=numrecs64-i;
11237             create_list((long long *)list_off, reclen, numrecs64);
11238             for(xx=0;xx<numvecs;xx++)
11239             {
11240                 piov[xx].piov_base = 
11241                     (caddr_t)(nbuff+(xx * reclen));
11242                 piov[xx].piov_len = reclen;
11243 #ifdef PER_VECTOR_OFFSET
11244                 piov[xx].piov_offset = list_off[xx];
11245 #endif
11246                 if(purge)
11247                    purgeit(piov[xx].piov_base,reclen);
11248             }
11249             if(preadv(fd, piov, numvecs
11250 #ifndef PER_VECTOR_OFFSET
11251                 , list_off[0]
11252 #endif
11253                 ) != (numvecs * reclen))
11254             {
11255 #ifdef NO_PRINT_LLD
11256                 printf("\nError preadving block %ld \n", i);
11257 #else
11258                 printf("\nError preadving block %lld \n", i);
11259 #endif
11260                 perror("preadv");
11261                 exit(116);
11262             }
11263         }
11264         if(include_flush)
11265             fsync(fd);
11266         if(include_close)
11267             close(fd);
11268         preadvtime[j] = ((time_so_far() - starttime2)-time_res)
11269             -compute_val;
11270         if(preadvtime[j] < (double).000001) 
11271         {
11272             preadvtime[j]= time_res;
11273             if(rec_prob < reclen)
11274                 rec_prob = reclen;
11275             res_prob=1;
11276         }
11277         if(!include_close)
11278         {
11279             fsync(fd);
11280             close(fd);
11281         }
11282 
11283         if(cpuutilflag)
11284         {
11285             cputime[j]  = cputime_so_far() - cputime[j];
11286             if (cputime[j] < cputime_res)
11287                 cputime[j] = 0.0;
11288             walltime[j] = time_so_far() - walltime[j];
11289             if (walltime[j] < cputime[j])
11290                walltime[j] = cputime[j];
11291         }
11292         if(restf)
11293             sleep((int)rest_val);
11294         }
11295     if(OPS_flag || MS_flag){
11296        filebytes64=filebytes64/reclen;
11297     }
11298     for(j=0;j<ltest;j++){
11299         if(MS_flag)
11300         {
11301             preadvrate[j]=1000000.0*(preadvtime[j] / (double)filebytes64);
11302             continue;
11303         }
11304             else
11305             {
11306                   preadvrate[j] = 
11307               (unsigned long long) ((double) filebytes64 / preadvtime[j]);
11308             }
11309         if(!(OPS_flag || MS_flag))
11310             preadvrate[j] >>= 10;
11311     }
11312     if(noretest)
11313     {
11314         preadvrate[1]=(long long)0;
11315         if(cpuutilflag)
11316         {
11317             walltime[1]=0.0;
11318             cputime[1]=0.0;
11319         }
11320     }
11321     
11322     /* Must save walltime & cputime before calling store_value() for each/any cell.*/
11323     if(cpuutilflag)
11324         store_times(walltime[0], cputime[0]);
11325     store_value((off64_t)preadvrate[0]);
11326     if(cpuutilflag)
11327         store_times(walltime[1], cputime[1]);
11328     store_value((off64_t)preadvrate[1]);
11329 #ifdef NO_PRINT_LLD
11330     if(!silent) printf("%10ld",preadvrate[0]);
11331     if(!silent) printf("%9ld",preadvrate[1]);
11332     if(!silent) printf("\n");
11333     if(!silent) fflush(stdout);
11334 #else
11335     if(!silent) printf("%10lld",preadvrate[0]);
11336     if(!silent) printf("%9lld",preadvrate[1]);
11337     if(!silent) printf("\n");
11338     if(!silent) fflush(stdout);
11339 #endif
11340 }
11341 #endif
11342 
11343 /************************************************************************/
11344 /* print_header()                           */
11345 /* Prints the header for the output from Iozone.            */
11346 /************************************************************************/
11347 #endif
11348 #ifdef HAVE_ANSIC_C
11349 void print_header(void)
11350 #else
11351 void print_header()
11352 #endif
11353 {
11354     if(Eflag)
11355     {
11356            if(!silent) printf(CONTROL_STRING2,
11357         " ", 
11358         " ",
11359         " ",
11360         " ",
11361         " ",
11362         " ",
11363         "random",           /*kcollins:2-5-96*/
11364         "random",           /*kcollins:2-5-96*/
11365         "bkwd",
11366         "record",
11367         "stride",
11368         " ",
11369         " ",
11370         " ",
11371         " "
11372 #ifdef HAVE_PREAD
11373         ," ",
11374         " ",
11375         " ",
11376         " "
11377 #ifdef HAVE_PREADV
11378         ," ",
11379         " ",
11380         " ",
11381         " "
11382 #endif
11383 #endif
11384         );
11385         if(!silent) printf(CONTROL_STRING2,
11386         "KB", 
11387         "reclen",
11388         "write",
11389         "rewrite",
11390         "read",
11391         "reread",
11392         "read",             /*kcollins:2-5-96*/
11393         "write",            /*kcollins:2-5-96*/
11394         "read",
11395         "rewrite",
11396         "read",
11397         "fwrite",
11398         "frewrite",
11399         "fread",
11400         "freread"
11401 #ifdef HAVE_PREAD
11402         ,"pwrite",
11403         "repwrite",
11404         "pread",
11405         "repread"
11406 #ifdef HAVE_PREADV
11407         ,"pwritev",
11408         "repwritev",
11409         "preadv",
11410         "repreadv"
11411 #endif
11412 #endif
11413         );
11414     }else 
11415     if(RWONLYflag){             /*kcollins 8-21-96*/
11416            if(!silent) printf(CONTROL_STRING4,      /*kcollins 8-21-96*/
11417         " ",                /*kcollins 8-21-96*/
11418         " ",                /*kcollins 8-21-96*/
11419         " ",                /*kcollins 8-21-96*/
11420         " ",                /*kcollins 8-21-96*/
11421         " ",                /*kcollins 8-21-96*/
11422         " "             /*kcollins 8-21-96*/
11423         );              /*kcollins 8-21-96*/
11424         if(!silent) printf(CONTROL_STRING4,         /*kcollins 8-21-96*/
11425         "KB",               /*kcollins 8-21-96*/
11426         "reclen",           /*kcollins 8-21-96*/
11427         "write",            /*kcollins 8-21-96*/
11428         "rewrite",          /*kcollins 8-21-96*/
11429         "read",             /*kcollins 8-21-96*/
11430         "reread"            /*kcollins 8-21-96*/
11431         );              /*kcollins 8-21-96*/
11432     }else{
11433        if(!(mmapflag || async_flag))
11434        {
11435             if(!silent) printf(CONTROL_STRING3,
11436             " ", 
11437             " ",
11438             " ",
11439             " ",
11440             " ",
11441             " ",
11442             "random",           /*kcollins:2-5-96*/
11443             "random",           /*kcollins:2-5-96*/
11444             "bkwd",
11445             "record",
11446             "stride",
11447             "",
11448             "",
11449             "",
11450             ""
11451             );
11452             if(!silent) printf(CONTROL_STRING3,
11453             "KB", 
11454             "reclen",
11455             "write",
11456             "rewrite",
11457             "read",
11458             "reread",
11459             "read",             /*kcollins:2-5-96*/
11460             "write",            /*kcollins:2-5-96*/
11461             "read",
11462             "rewrite",
11463             "read",
11464             "fwrite",
11465             "frewrite",
11466             "fread",
11467             "freread" 
11468             );
11469         }else
11470         {
11471                 if(!silent) printf(CONTROL_STRING3,
11472                 " ", 
11473                 " ",
11474                 " ",
11475                 " ",
11476                 " ",
11477                 " ",
11478                 "random",           /*kcollins:2-5-96*/
11479                 "random",           /*kcollins:2-5-96*/
11480                 "bkwd",
11481                 "record",
11482                 "stride",
11483                 "",
11484                 "",
11485                 "",
11486                 ""
11487                 );
11488                 if(!silent) printf(CONTROL_STRING3,
11489                 "KB", 
11490                 "reclen",
11491                 "write",
11492                 "rewrite",
11493                 "read",
11494                 "reread",
11495                 "read",             /*kcollins:2-5-96*/
11496                 "write",            /*kcollins:2-5-96*/
11497                 "read",
11498                 "rewrite",
11499                 "read",
11500                 "",
11501                 "",
11502                 "",
11503                 "" 
11504                 );
11505         }
11506     }
11507 }
11508 
11509 /************************************************************************/
11510 /* store_value()                            */
11511 /* Stores a value in an in memory array. Used by the report function    */
11512 /* to re-organize the output for Excel                  */
11513 /************************************************************************/
11514 #ifdef HAVE_ANSIC_C
11515 void
11516 store_value(off64_t value)
11517 #else
11518 store_value(value)
11519 off64_t value;
11520 #endif
11521 {
11522     report_array[current_x][current_y]=value;
11523     current_x++;
11524     if(current_x > max_x)
11525         max_x=current_x;
11526     if(current_y > max_y)
11527         max_y=current_y;
11528     if(max_x >= MAX_X)
11529     {
11530         printf("\nMAX_X too small\n");
11531         exit(117);
11532     }
11533     if(max_y >= MAX_Y)
11534     {
11535         printf("\nMAX_Y too small\n");
11536         exit(118);
11537     }
11538 }
11539 
11540 /************************************************************************/
11541 /* store_times()                            */
11542 /* Stores runtime (walltime & cputime) in a memory array.       */
11543 /* Used by the report function to re-organize the output for Excel  */
11544 /* For now, must be called immediately before calling store_value() for */
11545 /* each cell.                               */
11546 /************************************************************************/
11547 #ifdef HAVE_ANSIC_C
11548 void
11549 store_times(double walltime, double cputime)
11550 #else
11551 store_times(walltime, cputime)
11552 double walltime, cputime;
11553 #endif
11554 {
11555     runtimes [current_x][current_y].walltime = walltime;
11556     runtimes [current_x][current_y].cputime  = cputime;
11557     runtimes [current_x][current_y].cpuutil  = cpu_util(cputime, walltime);
11558 }
11559 
11560 /************************************************************************/
11561 /* dump_report()                            */
11562 /* Dumps the Excel report on standard output.               */
11563 /************************************************************************/
11564 #ifdef HAVE_ANSIC_C
11565 void dump_report(long long who)
11566 #else
11567 dump_report(who)
11568 long long who;
11569 #endif
11570 {
11571     long long i;
11572     off64_t current_file_size;
11573     off64_t rec_size;
11574 
11575     if(bif_flag)
11576         bif_column++;
11577     if(!silent) printf("      ");
11578 
11579     /* 
11580      * Need to reconstruct the record size list
11581      * as the crossover in -a changed the list.
11582     */
11583     del_record_sizes();
11584     init_record_sizes(orig_min_rec_size, orig_max_rec_size);
11585 
11586     for(rec_size=get_next_record_size(0); rec_size <= orig_max_rec_size;
11587         rec_size=get_next_record_size(rec_size))
11588     {
11589         if (rec_size == 0) break;
11590         if(bif_flag)
11591             do_float(bif_fd,(double)(rec_size/1024),bif_row,bif_column++);
11592 #ifdef NO_PRINT_LLD
11593         if(!silent) printf("  %c%ld%c",'"',rec_size/1024,'"');
11594 #else
11595         if(!silent) printf("  %c%lld%c",'"',rec_size/1024,'"');
11596 #endif
11597     }
11598     if(!silent) printf("\n");
11599     if(bif_flag)
11600     {
11601         bif_column=0;
11602         bif_row++;
11603     }
11604 
11605     current_file_size = report_array[0][0];
11606     if(bif_flag)
11607     {
11608         do_float(bif_fd,(double)(current_file_size),bif_row,bif_column++);
11609     }
11610 #ifdef NO_PRINT_LLD
11611     if(!silent) printf("%c%ld%c  ",'"',current_file_size,'"');
11612 #else
11613     if(!silent) printf("%c%lld%c  ",'"',current_file_size,'"');
11614 #endif
11615     for(i=0;i<=max_y;i++){
11616         if(report_array[0][i] != current_file_size){
11617             if(!silent) printf("\n");
11618             current_file_size = report_array[0][i];
11619             if(bif_flag)
11620             {
11621                 bif_row++;
11622                 bif_column=0;
11623                 do_float(bif_fd,(double)(current_file_size),bif_row,bif_column++);
11624             }
11625 #ifdef NO_PRINT_LLD
11626             if(!silent) printf("%c%ld%c  ",'"',current_file_size,'"');
11627 #else
11628             if(!silent) printf("%c%lld%c  ",'"',current_file_size,'"');
11629 #endif
11630         }
11631         if(bif_flag)
11632             do_float(bif_fd,(double)(report_array[who][i]),bif_row,bif_column++);
11633 #ifdef NO_PRINT_LLD
11634         if(!silent) printf(" %ld ",report_array[who][i]);
11635 #else
11636         if(!silent) printf(" %lld ",report_array[who][i]);
11637 #endif
11638     }
11639     if(bif_flag)
11640     {
11641         bif_row++;
11642         bif_column=0;
11643     }
11644     if(!silent) printf("\n");
11645 }
11646 
11647 /************************************************************************/
11648 /* Wrapper that dumps each of the collected data sets.          */
11649 /************************************************************************/
11650 #ifdef HAVE_ANSIC_C
11651 void dump_excel(void)
11652 #else
11653 void dump_excel()
11654 #endif
11655 {
11656     if(bif_flag)
11657     {
11658         bif_fd=create_xls(bif_filename);
11659         do_label(bif_fd,command_line,bif_row++,bif_column);
11660         do_label(bif_fd," ",bif_row++,bif_column);
11661                 do_label(bif_fd,"The top row is records sizes, the left column is file sizes",bif_row++,bif_column);
11662     }
11663     if(!silent) printf("Excel output is below:\n");
11664 
11665     if ((!include_tflag) || (include_mask & (long long)WRITER_MASK)) {
11666     if(bif_flag)
11667         do_label(bif_fd,"Writer Report",bif_row++,bif_column);
11668     if(!silent) printf("\n%cWriter report%c\n",'"','"');
11669     dump_report(2); 
11670     if(bif_flag)
11671         do_label(bif_fd,"Re-writer Report",bif_row++,bif_column);
11672     if(!silent) printf("\n%cRe-writer report%c\n",'"','"');
11673     dump_report(3); 
11674     }
11675 
11676     if ((!include_tflag) || (include_mask & (long long)READER_MASK)) {
11677     if(bif_flag)
11678         do_label(bif_fd,"Reader Report",bif_row++,bif_column);
11679     if(!silent) printf("\n%cReader report%c\n",'"','"');
11680     dump_report(4); 
11681     if(bif_flag)
11682         do_label(bif_fd,"Re-reader Report",bif_row++,bif_column);
11683     if(!silent) printf("\n%cRe-Reader report%c\n",'"','"');
11684     dump_report(5); 
11685     }
11686 
11687     if ((!include_tflag) || (include_mask & (long long)RANDOM_RW_MASK)) {
11688         if(bif_flag)
11689             do_label(bif_fd,"Random Read Report",bif_row++,bif_column);
11690         if(!silent) printf("\n%cRandom read report%c\n",'"','"');
11691         dump_report(6); 
11692         if(bif_flag)
11693             do_label(bif_fd,"Random Write Report",bif_row++,bif_column);
11694         if(!silent) printf("\n%cRandom write report%c\n",'"','"');
11695         dump_report(7); 
11696     }
11697 
11698     if ((!include_tflag) || (include_mask & (long long)REVERSE_MASK)) {
11699         if(bif_flag)
11700             do_label(bif_fd,"Backward Read Report",bif_row++,bif_column);
11701         if(!silent) printf("\n%cBackward read report%c\n",'"','"');
11702         dump_report(8); 
11703     }
11704 
11705     if ((!include_tflag) || (include_mask & (long long)REWRITE_REC_MASK)) {
11706         if(bif_flag)
11707             do_label(bif_fd,"Record Rewrite Report",bif_row++,bif_column);
11708         if(!silent) printf("\n%cRecord rewrite report%c\n",'"','"');
11709         dump_report(9); 
11710     }
11711 
11712     if ((!include_tflag) || (include_mask & (long long)STRIDE_READ_MASK)) {
11713         if(bif_flag)
11714             do_label(bif_fd,"Stride Read Report",bif_row++,bif_column);
11715         if(!silent) printf("\n%cStride read report%c\n",'"','"');
11716         dump_report(10); 
11717     }
11718 
11719     if ((!include_tflag) || (include_mask & (long long)FWRITER_MASK)) {
11720         if(bif_flag)
11721             do_label(bif_fd,"Fwrite Report",bif_row++,bif_column);
11722         if(!silent) printf("\n%cFwrite report%c\n",'"','"');
11723         dump_report(11); 
11724         if(bif_flag)
11725             do_label(bif_fd,"Re-fwrite Report",bif_row++,bif_column);
11726         if(!silent) printf("\n%cRe-Fwrite report%c\n",'"','"');
11727         dump_report(12); 
11728     }
11729 
11730     if ((!include_tflag) || (include_mask & (long long)FREADER_MASK)) {
11731         if(bif_flag)
11732             do_label(bif_fd,"Fread Report",bif_row++,bif_column);
11733         if(!silent) printf("\n%cFread report%c\n",'"','"');
11734         dump_report(13); 
11735         if(bif_flag)
11736             do_label(bif_fd,"Re-fread Report",bif_row++,bif_column);
11737         if(!silent) printf("\n%cRe-Fread report%c\n",'"','"');
11738         dump_report(14); 
11739     }
11740 
11741 #ifdef HAVE_PREAD
11742     if(Eflag)
11743     {
11744         if ((!include_tflag) || (include_mask & (long long)PWRITER_MASK)) {
11745             if(bif_flag)
11746                 do_label(bif_fd,"Pwrite Report",bif_row++,bif_column);
11747             if(!silent) printf("\n%cPwrite report%c\n",'"','"');
11748             dump_report(15); 
11749             if(bif_flag)
11750                 do_label(bif_fd,"Re-pwrite Report",bif_row++,bif_column);
11751             if(!silent) printf("\n%cRe-Pwrite report%c\n",'"','"');
11752             dump_report(16); 
11753         }
11754 
11755         if ((!include_tflag) || (include_mask & (long long)PREADER_MASK)) {
11756             if(bif_flag)
11757                 do_label(bif_fd,"Pread Report",bif_row++,bif_column);
11758             if(!silent) printf("\n%cPread report%c\n",'"','"');
11759             dump_report(17); 
11760             if(bif_flag)
11761                 do_label(bif_fd,"Re-pread Report",bif_row++,bif_column);
11762             if(!silent) printf("\n%cRe-Pread report%c\n",'"','"');
11763             dump_report(18); 
11764         }
11765 
11766 #ifdef HAVE_PREADV
11767         if ((!include_tflag) || (include_mask & (long long)PWRITEV_MASK)) {
11768             if(bif_flag)
11769                 do_label(bif_fd,"Pwritev Report",bif_row++,bif_column);
11770             if(!silent) printf("\n%cPwritev report%c\n",'"','"');
11771             dump_report(19); 
11772             if(bif_flag)
11773                 do_label(bif_fd,"Re-pwritev Report",bif_row++,bif_column);
11774             if(!silent) printf("\n%cRe-Pwritev report%c\n",'"','"');
11775             dump_report(20); 
11776         }
11777 
11778         if ((!include_tflag) || (include_mask & (long long)PREADV_MASK)) {
11779             if(bif_flag)
11780                 do_label(bif_fd,"Preadv Report",bif_row++,bif_column);
11781             if(!silent) printf("\n%cPreadv report%c\n",'"','"');
11782             dump_report(21); 
11783             if(bif_flag)
11784                 do_label(bif_fd,"Re-preadv Report",bif_row++,bif_column);
11785             if(!silent) printf("\n%cRe-Preadv report%c\n",'"','"');
11786             dump_report(22); 
11787         }
11788 #endif
11789     }
11790 #endif
11791     if (cpuutilflag)
11792         dump_cputimes();
11793     if(bif_flag)
11794         close_xls(bif_fd);
11795 }
11796 
11797 /************************************************************************/
11798 /* dump_times()                             */
11799 /* Dumps the Excel CPU times report to stdout and to the bif file.  */
11800 /************************************************************************/
11801 #ifdef HAVE_ANSIC_C
11802 void dump_times(long long who)
11803 #else
11804 dump_times(who)
11805 long long who;
11806 #endif
11807 {
11808     long long i;
11809     off64_t current_file_size;
11810     off64_t rec_size;
11811 
11812     if (bif_flag)
11813         bif_column++;
11814     if(!silent) printf("      ");
11815 
11816     for (rec_size = get_next_record_size(0); rec_size <= orig_max_rec_size;
11817         rec_size = get_next_record_size(rec_size))
11818     {
11819         if (rec_size == 0) break;
11820         if (bif_flag)
11821             do_float(bif_fd, (double)(rec_size/1024), bif_row, bif_column++);
11822 #ifdef NO_PRINT_LLD
11823         if(!silent) printf("  %c%ld%c",'"',rec_size/1024,'"');
11824 #else
11825         if(!silent) printf("  %c%lld%c",'"',rec_size/1024,'"');
11826 #endif
11827     }
11828     if(!silent) printf("\n");
11829     if (bif_flag)
11830     {
11831         bif_column=0;
11832         bif_row++;
11833     }
11834 
11835     current_file_size = report_array[0][0];
11836     if (bif_flag)
11837     {
11838         do_float(bif_fd, (double)(current_file_size), bif_row, bif_column++);
11839     }
11840 #ifdef NO_PRINT_LLD
11841     if(!silent) printf("%c%ld%c  ",'"',current_file_size,'"');
11842 #else
11843     if(!silent) printf("%c%lld%c  ",'"',current_file_size,'"');
11844 #endif
11845     for (i = 0; i <= max_y; i++) {
11846         if (report_array[0][i] != current_file_size) {
11847             if(!silent) printf("\n");
11848             current_file_size = report_array[0][i];
11849             if (bif_flag)
11850             {
11851                 bif_row++;
11852                 bif_column=0;
11853                 do_float(bif_fd, (double)(current_file_size), bif_row, bif_column++);
11854             }
11855 #ifdef NO_PRINT_LLD
11856             if(!silent) printf("%c%ld%c  ",'"',current_file_size,'"');
11857 #else
11858             if(!silent) printf("%c%lld%c  ",'"',current_file_size,'"');
11859 #endif
11860         }
11861         if (bif_flag)
11862             do_float(bif_fd, (double)(runtimes [who][i].cpuutil), bif_row, bif_column++);
11863         if(!silent) printf(" %6.2f", runtimes [who][i].cpuutil);
11864     }
11865     if(!silent) printf("\n");
11866     if (bif_flag)
11867     {
11868         bif_row++;
11869         bif_column=0;
11870     }
11871 }
11872 
11873 /************************************************************************/
11874 /* Wrapper that dumps each of the collected data sets.          */
11875 /* This one dumps only the collected CPU times.             */
11876 /************************************************************************/
11877 #ifdef HAVE_ANSIC_C
11878 void dump_cputimes(void)
11879 #else
11880 void dump_cputimes(void)
11881 #endif
11882 {
11883     bif_row++;
11884     bif_column = 0;
11885 
11886     if ((!include_tflag) || (include_mask & (long long)WRITER_MASK)) {
11887     if(bif_flag)
11888         do_label(bif_fd, "Writer CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
11889     if(!silent) printf("\n%cWriter CPU utilization report (Zero values should be ignored)%c\n",'"','"');
11890     dump_times(2); 
11891     if(bif_flag)
11892         do_label(bif_fd, "Re-writer CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
11893     if(!silent) printf("\n%cRe-writer CPU utilization report (Zero values should be ignored)%c\n",'"','"');
11894     dump_times(3); 
11895     }
11896 
11897     if ((!include_tflag) || (include_mask & (long long)READER_MASK)) {
11898     if(bif_flag)
11899         do_label(bif_fd, "Reader CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
11900     if(!silent) printf("\n%cReader CPU utilization report (Zero values should be ignored)%c\n",'"','"');
11901     dump_times(4); 
11902     if(bif_flag)
11903         do_label(bif_fd, "Re-reader CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
11904     if(!silent) printf("\n%cRe-Reader CPU utilization report (Zero values should be ignored)%c\n",'"','"');
11905     dump_times(5); 
11906     }
11907 
11908     if ((!include_tflag) || (include_mask & (long long)RANDOM_RW_MASK)) {
11909         if(bif_flag)
11910             do_label(bif_fd, "Random Read CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
11911         if(!silent) printf("\n%cRandom read CPU utilization report (Zero values should be ignored)%c\n",'"','"');
11912         dump_times(6); 
11913         if(bif_flag)
11914             do_label(bif_fd, "Random Write CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
11915         if(!silent) printf("\n%cRandom write CPU utilization report (Zero values should be ignored)%c\n",'"','"');
11916         dump_times(7); 
11917     }
11918 
11919     if ((!include_tflag) || (include_mask & (long long)REVERSE_MASK)) {
11920         if(bif_flag)
11921             do_label(bif_fd, "Backward Read CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
11922         if(!silent) printf("\n%cBackward read CPU utilization report (Zero values should be ignored)%c\n",'"','"');
11923         dump_times(8); 
11924     }
11925 
11926     if ((!include_tflag) || (include_mask & (long long)REWRITE_REC_MASK)) {
11927         if(bif_flag)
11928             do_label(bif_fd, "Record Rewrite CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
11929         if(!silent) printf("\n%cRecord rewrite CPU utilization report (Zero values should be ignored)%c\n",'"','"');
11930         dump_times(9); 
11931     }
11932 
11933     if ((!include_tflag) || (include_mask & (long long)STRIDE_READ_MASK)) {
11934         if(bif_flag)
11935             do_label(bif_fd, "Stride Read CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
11936         if(!silent) printf("\n%cStride read CPU utilization report (Zero values should be ignored)%c\n",'"','"');
11937         dump_times(10); 
11938     }
11939 
11940     if ((!include_tflag) || (include_mask & (long long)FWRITER_MASK)) {
11941         if(bif_flag)
11942             do_label(bif_fd, "Fwrite CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
11943         if(!silent) printf("\n%cFwrite CPU utilization report (Zero values should be ignored)%c\n",'"','"');
11944         dump_times(11); 
11945         if(bif_flag)
11946             do_label(bif_fd, "Re-fwrite CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
11947         if(!silent) printf("\n%cRe-Fwrite CPU utilization report (Zero values should be ignored)%c\n",'"','"');
11948         dump_times(12); 
11949     }
11950 
11951     if ((!include_tflag) || (include_mask & (long long)FREADER_MASK)) {
11952         if(bif_flag)
11953             do_label(bif_fd, "Fread CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
11954         if(!silent) printf("\n%cFread CPU utilization report (Zero values should be ignored)%c\n",'"','"');
11955         dump_times(13); 
11956         if(bif_flag)
11957             do_label(bif_fd, "Re-fread CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
11958         if(!silent) printf("\n%cRe-Fread CPU utilization report (Zero values should be ignored)%c\n",'"','"');
11959         dump_times(14); 
11960     }
11961 
11962 #ifdef HAVE_PREAD
11963     if(Eflag)
11964     {
11965         if ((!include_tflag) || (include_mask & (long long)PWRITER_MASK)) {
11966             if(bif_flag)
11967                 do_label(bif_fd, "Pwrite CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
11968             if(!silent) printf("\n%cPwrite CPU utilization report (Zero values should be ignored)%c\n",'"','"');
11969             dump_times(15); 
11970             if(bif_flag)
11971                 do_label(bif_fd, "Re-pwrite CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
11972             if(!silent) printf("\n%cRe-Pwrite CPU utilization report (Zero values should be ignored)%c\n",'"','"');
11973             dump_times(16); 
11974         }
11975 
11976         if ((!include_tflag) || (include_mask & (long long)PREADER_MASK)) {
11977             if(bif_flag)
11978                 do_label(bif_fd, "Pread CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
11979             if(!silent) printf("\n%cPread CPU utilization report (Zero values should be ignored)%c\n",'"','"');
11980             dump_times(17); 
11981             if(bif_flag)
11982                 do_label(bif_fd, "Re-pread CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
11983             if(!silent) printf("\n%cRe-Pread CPU utilization report (Zero values should be ignored)%c\n",'"','"');
11984             dump_times(18); 
11985         }
11986 
11987 #ifdef HAVE_PREADV
11988         if ((!include_tflag) || (include_mask & (long long)PWRITEV_MASK)) {
11989             if(bif_flag)
11990                 do_label(bif_fd, "Pwritev CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
11991             if(!silent) printf("\n%cPwritev CPU utilization report (Zero values should be ignored)%c\n",'"','"');
11992             dump_times(19); 
11993             if(bif_flag)
11994                 do_label(bif_fd, "Re-pwritev CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
11995             if(!silent) printf("\n%cRe-Pwritev CPU utilization report (Zero values should be ignored)%c\n",'"','"');
11996             dump_times(20); 
11997         }
11998 
11999         if ((!include_tflag) || (include_mask & (long long)PREADV_MASK)) {
12000             if(bif_flag)
12001                 do_label(bif_fd, "Preadv CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
12002             if(!silent) printf("\n%cPreadv CPU utilization report (Zero values should be ignored)%c\n",'"','"');
12003             dump_times(21); 
12004             if(bif_flag)
12005                 do_label(bif_fd, "Re-preadv CPU utilization report (Zero values should be ignored)", bif_row++, bif_column);
12006             if(!silent) printf("\n%cRe-Preadv CPU utilization report (Zero values should be ignored)%c\n",'"','"');
12007             dump_times(22); 
12008         }
12009 #endif
12010     }
12011 #endif
12012 }
12013 
12014 /************************************************************************/
12015 /* Internal memory allocation mechanism. Uses shared memory or mmap     */
12016 /************************************************************************/
12017 #ifdef HAVE_ANSIC_C
12018 char *
12019 alloc_mem(long long size, int shared_flag)
12020 #else
12021 char *
12022 alloc_mem(size,shared_flag)
12023 long long size;
12024 int shared_flag;
12025 #endif
12026 {
12027     long long size1;
12028     char *addr,*dumb;
12029     int shmid;
12030     int tfd;
12031     long long tmp;
12032 #if defined(solaris) 
12033         char mmapFileName[]="mmap_tmp_XXXXXX";
12034 #endif
12035 
12036     tmp = 0;
12037     dumb = (char *)0;
12038     tfd=0;
12039     size1=l_max(size,page_size);
12040     if(!distributed)
12041     {
12042         if(!trflag)
12043         {
12044             addr=(char *)malloc((size_t)size1);
12045             return(addr);
12046         }
12047         if(use_thread)
12048         {
12049             addr=(char *)malloc((size_t)size1);
12050             return(addr);
12051         }
12052     }
12053     if(!shared_flag)
12054     {
12055         addr=(char *)malloc((size_t)size1);
12056         return(addr);
12057     }
12058 #ifdef SHARED_MEM
12059     size1=l_max(size,page_size);
12060     size1=(size1 +page_size) & ~(page_size-1);
12061     shmid=(int)shmget((key_t)(IPC_PRIVATE), (size_t)size1 , (int)(IPC_CREAT|0666));
12062         if(shmid < (int)0)
12063         {
12064                 printf("\nUnable to get shared memory segment(shmget)\n");
12065 #ifdef NO_PRINT_LLD
12066                 printf("shmid = %d, size = %ld, size1 = %lu, Error %d\n",shmid,size,(size_t)size1,errno);
12067 #else
12068                 printf("shmid = %d, size = %lld, size1 = %lu, Error %d\n",shmid,size,(unsigned long)size1,errno);
12069 #endif
12070                 exit(119);
12071         }
12072         /*addr = (char *)shmat(shmid, 0, SHM_W);*/
12073     /* Some systems will not take the above but
12074      * will default to read/write if no flags
12075      * are provided. (AIX)
12076      * The POSIX standard states that if SHM_RDONLY
12077      * is not specified then it will be read/write.
12078      */
12079         addr = (char *)shmat((int)shmid, 0, 0);
12080 #ifdef _64BIT_ARCH_
12081         if((long long)addr == (long long)-1)
12082 #else
12083         if((long)addr == (long)-1)
12084 #endif
12085         {
12086                 printf("\nUnable to get shared memory segment\n");
12087                 printf("..Error %d\n",errno);
12088                 exit(120);
12089         }
12090     shmctl(shmid, IPC_RMID, 0);
12091     return(addr);
12092 #else
12093 
12094     size1=l_max(size,page_size);
12095     size1=(size1 +page_size) & ~(page_size-1);
12096 #if defined(bsd4_2) && !defined(macosx)
12097     if((tfd = creat("mmap.tmp", 0666))<0)
12098     {
12099         printf("Unable to create tmp file\n");
12100         exit(121);
12101     }
12102     addr=(char *)mmap(0,&size1,PROT_WRITE|PROT_READ,
12103         MAP_ANON|MAP_SHARED, tfd, 0);
12104     unlink("mmap.tmp");
12105 #else
12106 
12107 
12108 #if defined(solaris) 
12109     tfd=mkstemp(mmapFileName);
12110         if(tfd < 0)
12111     {
12112         printf("Unable to create tmp file\n");
12113         exit(121);
12114     }
12115     dumb=(char *)malloc((size_t)size1);
12116     bzero(dumb,size1);
12117     write(tfd,dumb,size1);
12118     free(dumb);
12119     addr=(char *)mmap(0,(size_t)size1,PROT_WRITE|PROT_READ,
12120         MAP_SHARED, tfd, 0);
12121     unlink(mmapFileName);
12122 #else
12123 #if defined(SCO) || defined(SCO_Unixware_gcc) || defined(Windows)
12124         char mmapFileName[]="mmap_tmp_XXXXXX";
12125     tfd=mkstemp(mmapFileName);
12126         if(tfd < 0)
12127         {
12128                 printf("Unable to create tmp file\n");
12129                 exit(121);
12130         }
12131         dumb=(char *)malloc((size_t)size1);
12132     bzero(dumb,size1);
12133         write(tfd,dumb,size1);
12134         free(dumb);
12135         addr=(char *)mmap(0,(size_t)size1,PROT_WRITE|PROT_READ,
12136                 MAP_SHARED, tfd, 0);
12137     unlink(mmapFileName);
12138 #else
12139     addr=(char *)mmap(0,(size_t)size1,PROT_WRITE|PROT_READ,
12140         MAP_ANONYMOUS|MAP_SHARED, -1, 0);
12141 #endif
12142 #endif
12143 #endif
12144     if((char *)addr == (char *)-1)
12145     {
12146         printf("\nUnable to get memory segment\n");
12147         printf("Error %d\n",errno);
12148         exit(122);
12149     }
12150     if(debug1)
12151         printf("Got shared memory for size %d\n",size1);
12152 
12153     return(addr);
12154 #endif
12155 }
12156 
12157 /************************************************************************/
12158 /* Implementation of poll() function.                   */
12159 /************************************************************************/
12160 #ifdef HAVE_ANSIC_C
12161 void Poll(long long time1)
12162 #else
12163 void Poll(time1)
12164 long  long time1;
12165 #endif
12166 {
12167     struct timeval howlong;
12168     howlong.tv_sec=(int)(time1/100000);
12169     howlong.tv_usec=(int)(time1%100000); /* Get into u.s. */
12170     select(0, 0, 0, 0, &howlong);
12171 }
12172 
12173 /************************************************************************/
12174 /* Implementation of max() function.                    */
12175 /************************************************************************/
12176 #ifdef HAVE_ANSIC_C
12177 long long l_max(long long one,long long two)
12178 #else
12179 long long l_max(one,two)
12180 long long one,two;
12181 #endif
12182 {
12183     if(one > two)
12184         return(one);
12185     else
12186         return(two);
12187 }
12188 
12189 /************************************************************************/
12190 /* Internal Kill. With stonewalling disabled, kill does nothing     */
12191 /************************************************************************/
12192 #ifdef HAVE_ANSIC_C
12193 void Kill(long long pid,long long sig)
12194 #else
12195 void Kill(pid,sig)
12196 long long pid,sig;
12197 #endif
12198 {
12199     if(!xflag)
12200     {
12201         /*printf("Killing %d\n",pid);*/
12202         kill((pid_t)pid,(int)sig);
12203     }
12204 }
12205 /************************************************************************/
12206 /* Implementation of min() function.                    */
12207 /************************************************************************/
12208 
12209 #ifdef HAVE_ANSIC_C
12210 long long l_min(long long num1,long long num2)
12211 #else
12212 long long l_min(num1,num2)
12213 long long num1,num2;
12214 #endif
12215 {
12216     if(num1 >= num2)
12217         return num2;
12218     else
12219         return num1;
12220 }
12221 
12222 /************************************************************************/
12223 /* Routine to call throughput tests many times.             */
12224 /************************************************************************/
12225 
12226 #ifdef HAVE_ANSIC_C
12227 void
12228 multi_throughput_test(long long mint,long long maxt)
12229 #else
12230 void multi_throughput_test(mint, maxt)
12231 long long mint, maxt;
12232 #endif
12233 {
12234         int *t_rangeptr, *t_rangecurs;
12235         int *saveptr = (int *)0;
12236         int tofree = 0;
12237     long long i;
12238         if(t_count == 0){
12239             t_count = (int) maxt - mint + 1;
12240             t_rangeptr = (int *) malloc((size_t)sizeof(int)*t_count);
12241         saveptr = t_rangeptr;
12242             tofree = 1;
12243             t_rangecurs = t_rangeptr;
12244             for(i=mint; i<= maxt; i++) {
12245                 *(t_rangecurs++) = i;
12246             }
12247         }
12248         else {
12249             t_rangeptr = &t_range[0];
12250         }
12251     for(i=0; i < t_count; i++){
12252         num_child = *(t_rangeptr++);
12253         current_client_number=0; /* Need to start with 1 */
12254         throughput_test();
12255         current_x=0;
12256         current_y++;
12257     }
12258     if(Rflag)
12259         dump_throughput();
12260         if(tofree)
12261             free(saveptr);
12262 
12263 }
12264 
12265 
12266 
12267 /************************************************************************/
12268 /* Routine to purge the buffer cache by unmounting drive.       */
12269 /************************************************************************/
12270 #ifdef HAVE_ANSIC_C
12271 void
12272 purge_buffer_cache()
12273 #else
12274 purge_buffer_cache()
12275 #endif
12276 {
12277     char command[1024];
12278     int ret,i;
12279     strcpy(command,"umount ");
12280     strcat(command, mountname);
12281         /*
12282            umount might fail if the device is still busy, so
12283            retry unmounting several times with increasing delays
12284         */
12285         for (i = 1; i < 200; ++i) {
12286                ret = system(command);
12287                if (ret == 0)
12288                        break;
12289                sleep(i); /* seconds */
12290         }
12291     strcpy(command,"mount ");
12292     strcat(command, mountname);
12293     /*
12294          mount might fail if the device is still busy, so
12295          retry mounting several times with increasing delays
12296         */
12297         for (i = 1; i < 10; ++i) {
12298               ret = system(command);
12299               if (ret == 0)
12300                    break;
12301                    sleep(i); /* seconds */
12302          }
12303 }
12304 
12305 /************************************************************************/
12306 /* Thread write test                                */
12307 /************************************************************************/
12308 #ifdef HAVE_ANSIC_C
12309 void *
12310 thread_write_test(void *x)
12311 #else
12312 void *
12313 thread_write_test( x)
12314 #endif
12315 {
12316 
12317     struct child_stats *child_stat;
12318     double starttime1 = 0;
12319     double temp_time;
12320     double walltime, cputime;
12321     double compute_val = (double)0;
12322     float delay = (float)0;
12323     double thread_qtime_stop,thread_qtime_start;
12324     double hist_time;
12325     double desired_op_rate_time;
12326     double actual_rate;
12327     off64_t traj_offset;
12328     off64_t lock_offset=0;
12329     off64_t save_offset=0;
12330     long long flags,traj_size;
12331     long long w_traj_bytes_completed;
12332     long long w_traj_ops_completed;
12333     FILE *w_traj_fd;
12334     int fd;
12335     long long recs_per_buffer;
12336     long long stopped,i;
12337     off64_t written_so_far, read_so_far, re_written_so_far,re_read_so_far;
12338     long long xx,xx2;
12339     char *dummyfile [MAXSTREAMS];           /* name of dummy file     */
12340     char *nbuff;
12341     char *maddr;
12342     char *wmaddr,*free_addr;
12343     char now_string[30];
12344     int anwser,bind_cpu,wval;
12345 #if defined(VXFS) || defined(solaris)
12346     int test_foo = 0;
12347 #endif
12348     off64_t filebytes64;
12349     char tmpname[256];
12350     FILE *thread_wqfd;
12351     FILE *thread_Lwqfd;
12352 
12353 #ifdef ASYNC_IO
12354     struct cache *gc=0;
12355 
12356 #else
12357     long long *gc=0;
12358 #endif
12359 
12360     if(compute_flag)
12361         delay=compute_time;
12362     nbuff=maddr=wmaddr=free_addr=0;
12363     hist_time=thread_qtime_stop=thread_qtime_start=0;
12364     thread_wqfd=w_traj_fd=thread_Lwqfd=(FILE *)0;
12365     traj_offset=walltime=cputime=0;
12366     anwser=bind_cpu=0;
12367     if(w_traj_flag)
12368     {
12369         filebytes64 = w_traj_fsize;
12370         numrecs64=w_traj_ops;
12371     }
12372     else
12373     {
12374         filebytes64 = numrecs64*reclen;
12375     }
12376     written_so_far=read_so_far=re_written_so_far=re_read_so_far=0;
12377     w_traj_bytes_completed=w_traj_ops_completed=0;
12378     recs_per_buffer = cache_size/reclen ;
12379 #ifdef NO_THREADS
12380     xx=chid;
12381 #else
12382     if(use_thread)
12383     {
12384         xx = (long long)((long)x);
12385     }
12386     else
12387     {
12388         xx=chid;
12389     }
12390 #endif
12391 #ifndef NO_THREADS
12392 #if defined(_HPUX_SOURCE) || defined(linux)
12393     if(ioz_processor_bind)
12394     {
12395          bind_cpu=(begin_proc+(int)xx)%num_processors;
12396 #if defined(_HPUX_SOURCE)
12397          pthread_processor_bind_np(PTHREAD_BIND_FORCED_NP,
12398                          (pthread_spu_t *)&anwser, (pthread_spu_t)bind_cpu, pthread_self());
12399 #else
12400      cpu_set_t cpuset;
12401 
12402      CPU_ZERO(&cpuset);
12403      CPU_SET(bind_cpu, &cpuset);
12404 
12405      pthread_setaffinity_np(pthread_self(), sizeof(cpuset),&cpuset);
12406 #endif
12407         my_nap(40); /* Switch to new cpu */
12408     }
12409 #endif
12410 #endif
12411     if(use_thread)
12412         nbuff=barray[xx];
12413     else
12414         nbuff=buffer;
12415     if(debug1 )
12416     {
12417        if(use_thread)
12418 #ifdef NO_PRINT_LLD
12419         printf("\nStarting child %ld\n",xx);
12420 #else
12421         printf("\nStarting child %lld\n",xx);
12422 #endif
12423        else
12424 #ifdef NO_PRINT_LLD
12425         printf("\nStarting process %d slot %ld\n",getpid(),xx);
12426 #else
12427         printf("\nStarting process %d slot %lld\n",getpid(),xx);
12428 #endif
12429         
12430     }
12431     dummyfile[xx]=(char *)malloc((size_t)MAXNAMESIZE);
12432     xx2=xx;
12433     if(share_file)
12434         xx2=(long long)0;
12435     if(mfflag)
12436     {
12437 #ifdef NO_PRINT_LLD
12438         sprintf(dummyfile[xx],"%s",filearray[xx2]);
12439 #else
12440         sprintf(dummyfile[xx],"%s",filearray[xx2]);
12441 #endif
12442     }
12443     else
12444     {
12445 #ifdef NO_PRINT_LLD
12446         sprintf(dummyfile[xx],"%s.DUMMY.%ld",filearray[xx2],xx2);
12447 #else
12448         sprintf(dummyfile[xx],"%s.DUMMY.%lld",filearray[xx2],xx2);
12449 #endif
12450     }
12451     /*****************/
12452     /* Children only */
12453     /*******************************************************************/
12454     /* Initial write throughput performance test. **********************/
12455     /*******************************************************************/
12456 #if defined(Windows)
12457     if(unbuffered)
12458     {
12459         hand=CreateFile(dummyfile[xx],
12460             GENERIC_READ|GENERIC_WRITE,
12461             FILE_SHARE_WRITE|FILE_SHARE_READ,
12462             NULL,OPEN_ALWAYS,FILE_FLAG_NO_BUFFERING|
12463             FILE_FLAG_WRITE_THROUGH|FILE_FLAG_POSIX_SEMANTICS,
12464             NULL);
12465         CloseHandle(hand);
12466     }
12467 #endif
12468     if(oflag)
12469         flags=O_RDWR|O_SYNC|O_CREAT;
12470     else
12471         flags=O_RDWR|O_CREAT;
12472 #if defined(O_DSYNC)
12473     if(odsync)
12474         flags |= O_DSYNC;
12475 #endif
12476 #if defined(_HPUX_SOURCE) || defined(linux)
12477     if(read_sync)
12478         flags |=O_RSYNC|O_SYNC;
12479 #endif
12480 
12481 #if ! defined(DONT_HAVE_O_DIRECT)
12482 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
12483     if(direct_flag)
12484         flags |=O_DIRECT;
12485 #endif
12486 #if defined(TRU64)
12487     if(direct_flag)
12488         flags |=O_DIRECTIO;
12489 #endif
12490 #endif
12491 #if defined(Windows)
12492         if(unbuffered)
12493         {
12494             hand=CreateFile(dummyfile[xx],
12495           GENERIC_READ|GENERIC_WRITE,
12496               FILE_SHARE_WRITE|FILE_SHARE_READ,
12497           NULL,OPEN_EXISTING,FILE_FLAG_NO_BUFFERING|
12498           FILE_FLAG_WRITE_THROUGH|FILE_FLAG_POSIX_SEMANTICS,
12499           NULL);
12500         }
12501         else
12502         {
12503 #endif
12504     if((fd = I_OPEN(dummyfile[xx], (int)flags,0640))<0)
12505     {
12506         client_error=errno;
12507         if(distributed && client_iozone)
12508             send_stop();
12509         printf("\nCan not open temp file: %s\n", 
12510             filename);
12511         perror("open");
12512         exit(125);
12513     }
12514 #if defined(Windows)
12515     }
12516 #endif
12517 #ifdef VXFS
12518     if(direct_flag)
12519     {
12520         ioctl(fd,VX_SETCACHE,VX_DIRECT);
12521         ioctl(fd,VX_GETCACHE,&test_foo);
12522         if(test_foo == 0)
12523         {
12524             if(!client_iozone)
12525               printf("\nVxFS advanced setcache feature not available.\n");
12526             exit(3);
12527         }
12528     }
12529 #endif
12530 #if defined(solaris)
12531                if(direct_flag)
12532                {
12533                        test_foo = directio(fd, DIRECTIO_ON);
12534                        if(test_foo != 0)
12535                        {
12536                                if(!client_iozone)
12537                                  printf("\ndirectio not available.\n");
12538                                exit(3);
12539                        }
12540                }
12541 #endif
12542 #ifdef ASYNC_IO
12543     if(async_flag)
12544         async_init(&gc,fd,direct_flag);
12545 #endif
12546     if(mmapflag)
12547     {
12548         maddr=(char *)initfile(fd,(filebytes64),1,PROT_READ|PROT_WRITE);
12549     }
12550     if(reclen < cache_size )
12551     {
12552         recs_per_buffer = cache_size/reclen ;
12553         nbuff=&nbuff[(xx%recs_per_buffer)*reclen];
12554     }
12555     if(fetchon)         /* Prefetch into processor cache */
12556         fetchit(nbuff,reclen);
12557     if((verify && !no_copy_flag) || dedup || dedup_interior)
12558         fill_buffer(nbuff,reclen,(long long)pattern,sverify,(long long)0);
12559 
12560     if(w_traj_flag)
12561         w_traj_fd=open_w_traj();
12562 
12563     child_stat = (struct child_stats *)&shmaddr[xx];    
12564     child_stat->throughput = 0;
12565     child_stat->actual = 0;
12566     child_stat->flag=CHILD_STATE_READY; /* Tell parent child is ready to go */
12567     if(distributed && client_iozone)
12568         tell_master_ready(chid);
12569     if(distributed && client_iozone)
12570     {
12571         if(cdebug)
12572         {
12573             fprintf(newstdout,"Child %d waiting for go from master\n",(int)xx);
12574             fflush(newstdout);
12575         }
12576         wait_for_master_go(chid);
12577         if(cdebug)
12578         {
12579             fprintf(newstdout,"Child %d received go from master\n",(int)xx);
12580             fflush(newstdout);
12581         }
12582     }
12583     else
12584     {
12585         while(child_stat->flag!=CHILD_STATE_BEGIN)   /* Wait for signal from parent */
12586             Poll((long long)1);
12587     }
12588 
12589     written_so_far=0;
12590     child_stat = (struct child_stats *)&shmaddr[xx];
12591     child_stat->actual = 0;
12592     child_stat->throughput = 0;
12593     stopped=0;
12594     if(file_lock)
12595         if(mylockf((int) fd, (int) 1, (int)0) != 0)
12596             printf("File lock for write failed. %d\n",errno);
12597     if(Q_flag)
12598     {
12599         sprintf(tmpname,"Child_%d_wol.dat",(int)xx);
12600         thread_wqfd=fopen(tmpname,"a");
12601         if(thread_wqfd==0)
12602         {
12603             client_error=errno;
12604             if(distributed && client_iozone)
12605                 send_stop();
12606             printf("Unable to open %s\n",tmpname);
12607             exit(40);
12608         }
12609         fprintf(thread_wqfd,"Offset in Kbytes   Latency in microseconds Transfer size in bytes\n");
12610     }
12611     if(L_flag)
12612     {
12613         sprintf(tmpname,"Child_%d.log",(int)xx);
12614         thread_Lwqfd=fopen(tmpname,"a");
12615         if(thread_Lwqfd==0)
12616         {
12617             client_error=errno;
12618             if(distributed && client_iozone)
12619                 send_stop();
12620             printf("Unable to open %s\n",tmpname);
12621             exit(40);
12622         }
12623         get_date(now_string);
12624         fprintf(thread_Lwqfd,"%-25s %s","Write test start: ",now_string);
12625     }
12626     starttime1 = time_so_far();
12627     if(cpuutilflag)
12628     {
12629         walltime = starttime1;
12630         cputime = cputime_so_far();
12631     }
12632     if(w_traj_flag)
12633         rewind(w_traj_fd);
12634     for(i=0; i<numrecs64; i++){
12635         if(w_traj_flag)
12636         {
12637             traj_offset=get_traj(w_traj_fd, (long long *)&traj_size,(float *)&delay, (long)1);
12638             reclen=traj_size;
12639 #if defined(Windows)
12640             if(unbuffered)
12641               SetFilePointer(hand,(LONG)traj_offset,0,FILE_BEGIN);
12642             else
12643 #endif
12644             I_LSEEK(fd,traj_offset,SEEK_SET);
12645         }
12646         if(Q_flag)
12647         {
12648 #if defined(Windows)
12649             if(unbuffered)
12650               traj_offset=SetFilePointer(hand,0,0,FILE_CURRENT);
12651             else
12652 #endif
12653             traj_offset=I_LSEEK(fd,0,SEEK_CUR);
12654         }
12655         if(rlocking)
12656         {
12657             lock_offset=I_LSEEK(fd,0,SEEK_CUR);
12658             mylockr((int) fd, (int) 1, (int)0,
12659               lock_offset, reclen);
12660         }
12661         if((verify && !no_copy_flag) || dedup || dedup_interior)
12662             fill_buffer(nbuff,reclen,(long long)pattern,sverify,i);
12663         if(compute_flag)
12664             compute_val+=do_compute(delay);
12665         if(*stop_flag && !stopped){
12666             if(include_flush)
12667             {
12668                 if(mmapflag)
12669                     msync(maddr,(size_t)filebytes64,MS_SYNC);
12670                 else
12671                     fsync(fd);
12672             }
12673             /* Close and re-open to get close in measurment */
12674             if(include_close)
12675             {
12676               save_offset=I_LSEEK(fd,0,SEEK_CUR);
12677               close(fd);
12678             }
12679             child_stat->throughput = 
12680                 (time_so_far() - starttime1)-time_res;
12681             if(include_close)
12682             {
12683               if((fd = I_OPEN(dummyfile[xx], (int)flags,0))<0)
12684               {
12685                 client_error=errno;
12686                 if(distributed && client_iozone)
12687                     send_stop();
12688                 printf("\nCan not open temp file: %s\n", 
12689                     filename);
12690                 perror("open");
12691                 exit(125);
12692               }
12693               I_LSEEK(fd,save_offset,SEEK_SET);
12694             }
12695             if(child_stat->throughput < (double).000001) 
12696             {
12697                 child_stat->throughput = time_res;
12698                 if(rec_prob < reclen)
12699                     rec_prob = reclen;
12700                 res_prob=1;
12701             }
12702 
12703             if(OPS_flag){
12704                /*written_so_far=(written_so_far*1024)/reclen;*/
12705                written_so_far=w_traj_ops_completed;
12706             }
12707             child_stat->throughput = 
12708               (double)written_so_far/child_stat->throughput;
12709             child_stat->actual = (double)written_so_far;
12710             if(debug1)
12711             {
12712                 printf("\n(%ld) Stopped by another\n", (long)xx);
12713             }
12714             stopped=1;
12715         }
12716         if(purge)
12717             purgeit(nbuff,reclen);
12718         if(Q_flag || hist_summary || op_rate_flag)
12719         {
12720             thread_qtime_start=time_so_far();
12721         }
12722 again:      
12723         if(mmapflag)
12724         {
12725             wmaddr = &maddr[i*reclen];
12726             fill_area((long long*)nbuff,(long long*)wmaddr,(long long)reclen);
12727             /*printf("CHid: %lld  Writing offset %lld for length of %lld\n",chid,i*reclen,reclen);*/
12728             if(!mmapnsflag)
12729             {
12730               if(mmapasflag)
12731                 msync(wmaddr,(size_t)reclen,MS_ASYNC);
12732               if(mmapssflag)
12733                 msync(wmaddr,(size_t)reclen,MS_SYNC);
12734             }
12735         }
12736         else
12737         {
12738            if(async_flag)
12739            {
12740                  if(no_copy_flag)
12741                  {
12742                 free_addr=nbuff=(char *)malloc((size_t)reclen+page_size);
12743                 nbuff=(char *)(((long)nbuff+(long)page_size) & (long)~(page_size-1));
12744                 if(verify || dedup || dedup_interior)
12745                     fill_buffer(nbuff,reclen,(long long)pattern,sverify,i);
12746                     async_write_no_copy(gc, (long long)fd, nbuff, reclen, (i*reclen), depth,free_addr);
12747                  }
12748                  else
12749                 async_write(gc, (long long)fd, nbuff, reclen, (i*reclen), depth);
12750            }
12751            else
12752            {
12753 #if defined(Windows)
12754               if(unbuffered)
12755               {
12756             WriteFile(hand,nbuff,reclen, (LPDWORD)&wval,0);
12757               }
12758               else
12759               {
12760 #endif
12761               wval=write(fd, nbuff, (size_t) reclen);
12762 #if defined(Windows)
12763               }
12764 #endif
12765               if(wval != reclen)
12766               {
12767             if(*stop_flag && !stopped){
12768                 if(include_flush)
12769                 {
12770                     if(mmapflag)
12771                         msync(maddr,(size_t)filebytes64,MS_SYNC);
12772                     else
12773                         fsync(fd);
12774                 }
12775                 temp_time = time_so_far();
12776                 child_stat->throughput = 
12777                     (temp_time - starttime1)-time_res;
12778                 if(child_stat->throughput < (double).000001) 
12779                 {
12780                     child_stat->throughput= time_res;
12781                     if(rec_prob < reclen)
12782                         rec_prob = reclen;
12783                     res_prob=1;
12784                 }
12785 
12786                 if(OPS_flag){
12787                    /*written_so_far=(written_so_far*1024)/reclen;*/
12788                    written_so_far=w_traj_ops_completed;
12789                 }
12790                 child_stat->throughput = 
12791                   (double)written_so_far/child_stat->throughput;
12792                 child_stat->actual = (double)written_so_far;
12793                 if(debug1)
12794                 {
12795                     printf("\n(%ld) Stopped by another\n", (long)xx);
12796                 }
12797                 stopped=1;
12798                 goto again;
12799             }
12800             /* Note: Writer must finish even though told
12801                to stop. Otherwise the readers will fail.
12802                The code will capture bytes transfered
12803                before told to stop but let the writer
12804                complete.
12805             */
12806 #ifdef NO_PRINT_LLD
12807                 printf("\nError writing block %ld, fd= %d\n", i,
12808                  fd);
12809 #else
12810                 printf("\nError writing block %lld, fd= %d\n", i,
12811                  fd);
12812 #endif
12813             if(wval==-1)
12814                 perror("write");
12815             if (!no_unlink)
12816             {
12817                if(check_filename(dummyfile[xx]))
12818                 unlink(dummyfile[xx]);
12819             }
12820             child_stat->flag = CHILD_STATE_HOLD;
12821                 exit(127);
12822               }
12823             }
12824         }
12825         if(hist_summary)
12826         {
12827             thread_qtime_stop=time_so_far();
12828             hist_time =(thread_qtime_stop-thread_qtime_start);
12829             hist_insert(hist_time);
12830         }
12831         if(op_rate_flag)
12832         {
12833             thread_qtime_stop=time_so_far();
12834             desired_op_rate_time = ((double)1.0/(double)op_rate);
12835             actual_rate = (double)(thread_qtime_stop-thread_qtime_start);
12836 /*
12837 printf("Desired rate %g  Actual rate %g Nap %g microseconds\n",desired_op_rate_time,
12838     actual_rate, (desired_op_rate_time-actual_rate));
12839 */
12840             if( actual_rate < desired_op_rate_time)
12841                   my_unap((unsigned long long)((desired_op_rate_time-actual_rate)*1000000.0 ));
12842         }
12843         if(Q_flag)
12844         {
12845             thread_qtime_stop=time_so_far();
12846 #ifdef NO_PRINT_LLD
12847             fprintf(thread_wqfd,"%10.1ld %10.0f %10.1ld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
12848 #else
12849             fprintf(thread_wqfd,"%10.1lld %10.0f %10.1lld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
12850 #endif
12851         }
12852         w_traj_ops_completed++;
12853         w_traj_bytes_completed+=reclen;
12854         written_so_far+=reclen/1024;
12855         if(*stop_flag)
12856         {
12857             written_so_far-=reclen/1024;
12858             w_traj_bytes_completed-=reclen;
12859         }
12860         if(rlocking)
12861         {
12862             mylockr((int) fd, (int) 0, (int)0,
12863               lock_offset, reclen);
12864         }
12865     }
12866     
12867 
12868     if(file_lock)
12869         if(mylockf((int) fd, (int) 0, (int)0))
12870             printf("Write unlock failed. %d\n",errno);
12871     
12872 #ifdef ASYNC_IO
12873     if(async_flag)
12874     {
12875         end_async(gc);
12876         gc=0;
12877     }
12878 #endif
12879     if(!xflag)
12880     {
12881         *stop_flag=1;
12882         if(distributed && client_iozone)
12883             send_stop();
12884     }
12885     
12886     if(include_flush)
12887     {
12888         if(mmapflag)
12889             msync(maddr,(size_t)filebytes64,MS_SYNC);
12890         else
12891             fsync(fd);
12892     }
12893     if(include_close)
12894     {
12895         if(mmapflag)
12896             mmap_end(maddr,(unsigned long long)filebytes64);
12897 #if defined(Windows)
12898         if(unbuffered)
12899             CloseHandle(hand);
12900         else
12901 #endif
12902         close(fd);
12903     }
12904     if(!stopped){
12905         temp_time = time_so_far();
12906         child_stat->throughput = ((temp_time - starttime1)-time_res)
12907             -compute_val;
12908         if(child_stat->throughput < (double).000001) 
12909         {
12910             child_stat->throughput= time_res;
12911             if(rec_prob < reclen)
12912                 rec_prob = reclen;
12913             res_prob=1;
12914         }
12915 
12916         if(OPS_flag){
12917            /*written_so_far=(written_so_far*1024)/reclen;*/
12918            written_so_far=w_traj_ops_completed;
12919         }
12920         child_stat->throughput =
12921             (double)written_so_far/child_stat->throughput;
12922         child_stat->actual = (double)written_so_far;
12923     }
12924     if(cdebug)
12925     {
12926         fprintf(newstdout,"Child %d: throughput %f actual %f \n",(int)chid, child_stat->throughput,
12927             child_stat->actual);
12928         fflush(newstdout);
12929     }
12930     if(cpuutilflag)
12931     {
12932         cputime = cputime_so_far() - cputime;
12933         if (cputime < cputime_res)
12934             cputime = 0.0;
12935         child_stat->cputime = cputime;
12936         walltime = time_so_far() - walltime;
12937         child_stat->walltime = walltime;
12938     }
12939     if(distributed && client_iozone)
12940         tell_master_stats(THREAD_WRITE_TEST, chid, child_stat->throughput, 
12941             child_stat->actual, 
12942             child_stat->cputime, child_stat->walltime,
12943             (char)*stop_flag,
12944             (long long)CHILD_STATE_HOLD);
12945             
12946     if (debug1) {
12947         printf(" child/slot: %lld, wall-cpu: %8.3f %8.3fC" " -> %6.2f%%\n",
12948             xx, walltime, cputime,
12949             cpu_util(cputime, walltime));
12950     }
12951     child_stat->flag = CHILD_STATE_HOLD; /* Tell parent I'm done */
12952     stopped=0;
12953     /*******************************************************************/
12954     /* End write performance test. *************************************/
12955     /*******************************************************************/
12956     if(debug1)
12957 #ifdef NO_PRINT_LLD
12958         printf("\nChild finished %ld\n",xx);
12959 #else
12960         printf("\nChild finished %lld\n",xx);
12961 #endif
12962     if(!include_close)
12963     {
12964         if(mmapflag)
12965         {
12966             msync(maddr,(size_t)numrecs64*reclen,MS_SYNC); /*Clean up before read starts running*/ 
12967             mmap_end(maddr,(unsigned long long)numrecs64*reclen);
12968         }else
12969             fsync(fd);
12970             
12971 #if defined(Windows)
12972         if(unbuffered)
12973             CloseHandle(hand);
12974         else
12975 #endif
12976         close(fd);
12977     }
12978     if(Q_flag && (thread_wqfd !=0) )
12979         fclose(thread_wqfd);
12980     free(dummyfile[xx]);
12981     if(w_traj_flag)
12982         fclose(w_traj_fd);
12983 
12984     if(L_flag)
12985     {
12986         get_date(now_string);
12987         fprintf(thread_Lwqfd,"%-25s %s","Write test finished: ",now_string);
12988         fclose(thread_Lwqfd);
12989     }
12990     if(hist_summary)
12991        dump_hist("write",(int)xx);
12992     if(distributed && client_iozone)
12993         return(0);
12994 #ifdef NO_THREADS
12995     exit(0);
12996 #else
12997     if(use_thread)
12998         thread_exit();
12999     else
13000         exit(0);
13001 #endif
13002 return(0);
13003 }
13004 
13005 #ifdef HAVE_PREAD
13006 /************************************************************************/
13007 /* Thread pwrite test                               */
13008 /************************************************************************/
13009 #ifdef HAVE_ANSIC_C
13010 void *
13011 thread_pwrite_test(void *x)
13012 #else
13013 void *
13014 thread_pwrite_test( x)
13015 #endif
13016 {
13017 
13018     struct child_stats *child_stat;
13019     double starttime1 = 0;
13020     double temp_time;
13021     double walltime, cputime;
13022     double compute_val = (double)0;
13023     float delay = (float)0;
13024     double thread_qtime_stop,thread_qtime_start;
13025     double hist_time;
13026     double desired_op_rate_time;
13027     double actual_rate;
13028     off64_t traj_offset;
13029     off64_t lock_offset=0;
13030     long long flags,traj_size;
13031     long long w_traj_bytes_completed;
13032     long long w_traj_ops_completed;
13033     FILE *w_traj_fd;
13034     int fd;
13035     long long recs_per_buffer;
13036     long long stopped,i;
13037     off64_t written_so_far, read_so_far, re_written_so_far,re_read_so_far;
13038     long long xx,xx2;
13039     char *dummyfile [MAXSTREAMS];           /* name of dummy file     */
13040     char *nbuff;
13041     char *maddr;
13042     char *wmaddr,*free_addr;
13043     char now_string[30];
13044     int anwser,bind_cpu,wval;
13045 #if defined(VXFS) || defined(solaris)
13046     int test_foo = 0;
13047 #endif
13048     off64_t filebytes64;
13049     char tmpname[256];
13050     FILE *thread_wqfd;
13051     FILE *thread_Lwqfd;
13052 
13053 #ifdef ASYNC_IO
13054     struct cache *gc=0;
13055 
13056 #else
13057     long long *gc=0;
13058 #endif
13059 
13060     if(compute_flag)
13061         delay=compute_time;
13062     nbuff=maddr=wmaddr=free_addr=0;
13063     hist_time=thread_qtime_stop=thread_qtime_start=0;
13064     thread_wqfd=w_traj_fd=thread_Lwqfd=(FILE *)0;
13065     traj_offset=walltime=cputime=0;
13066     anwser=bind_cpu=0;
13067     if(w_traj_flag)
13068     {
13069         filebytes64 = w_traj_fsize;
13070         numrecs64=w_traj_ops;
13071     }
13072     else
13073     {
13074         filebytes64 = numrecs64*reclen;
13075     }
13076     written_so_far=read_so_far=re_written_so_far=re_read_so_far=0;
13077     w_traj_bytes_completed=w_traj_ops_completed=0;
13078     recs_per_buffer = cache_size/reclen ;
13079 #ifdef NO_THREADS
13080     xx=chid;
13081 #else
13082     if(use_thread)
13083     {
13084         xx = (long long)((long)x);
13085     }
13086     else
13087     {
13088         xx=chid;
13089     }
13090 #endif
13091 #ifndef NO_THREADS
13092 #if defined( _HPUX_SOURCE ) || defined ( linux )
13093     if(ioz_processor_bind)
13094     {
13095          bind_cpu=(begin_proc+(int)xx)%num_processors;
13096 #if defined( _HPUX_SOURCE )
13097          pthread_processor_bind_np(PTHREAD_BIND_FORCED_NP,
13098                          (pthread_spu_t *)&anwser, (pthread_spu_t)bind_cpu, pthread_self());
13099 #else
13100      cpu_set_t cpuset;
13101      CPU_ZERO(&cpuset);
13102      CPU_SET(bind_cpu, &cpuset);
13103 
13104      pthread_setaffinity_np(pthread_self(), sizeof(cpuset),&cpuset);
13105 #endif
13106         my_nap(40); /* Switch to new cpu */
13107     }
13108 #endif
13109 #endif
13110     if(use_thread)
13111         nbuff=barray[xx];
13112     else
13113         nbuff=buffer;
13114     if(debug1 )
13115     {
13116        if(use_thread)
13117 #ifdef NO_PRINT_LLD
13118         printf("\nStarting child %ld\n",xx);
13119 #else
13120         printf("\nStarting child %lld\n",xx);
13121 #endif
13122        else
13123 #ifdef NO_PRINT_LLD
13124         printf("\nStarting process %d slot %ld\n",getpid(),xx);
13125 #else
13126         printf("\nStarting process %d slot %lld\n",getpid(),xx);
13127 #endif
13128         
13129     }
13130     dummyfile[xx]=(char *)malloc((size_t)MAXNAMESIZE);
13131     xx2=xx;
13132     if(share_file)
13133         xx2=(long long)0;
13134     if(mfflag)
13135     {
13136 #ifdef NO_PRINT_LLD
13137        sprintf(dummyfile[xx],"%s",filearray[xx2]);
13138 #else
13139        sprintf(dummyfile[xx],"%s",filearray[xx2]);
13140 #endif
13141     }
13142     else
13143     {
13144 #ifdef NO_PRINT_LLD
13145        sprintf(dummyfile[xx],"%s.DUMMY.%ld",filearray[xx2],xx2);
13146 #else
13147        sprintf(dummyfile[xx],"%s.DUMMY.%lld",filearray[xx2],xx2);
13148 #endif
13149     }
13150     /*****************/
13151     /* Children only */
13152     /*******************************************************************/
13153     /* Initial pwrite throughput performance test. *********************/
13154     /*******************************************************************/
13155     if(!notruncate)
13156     {
13157         if((fd = I_CREAT(dummyfile[xx], 0640))<0)
13158         {
13159             client_error=errno;
13160             if(distributed && client_iozone)
13161                 send_stop();
13162             perror(dummyfile[xx]);
13163             exit(123);
13164         }
13165         close(fd);
13166     }
13167     if(oflag)
13168         flags=O_RDWR|O_SYNC|O_CREAT;
13169     else
13170         flags=O_RDWR|O_CREAT;
13171 #if defined(O_DSYNC)
13172     if(odsync)
13173         flags |= O_DSYNC;
13174 #endif
13175 #if defined(_HPUX_SOURCE) || defined(linux)
13176     if(read_sync)
13177         flags |=O_RSYNC|O_SYNC;
13178 #endif
13179 
13180 #if ! defined(DONT_HAVE_O_DIRECT)
13181 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
13182     if(direct_flag)
13183         flags |=O_DIRECT;
13184 #endif
13185 #if defined(TRU64)
13186     if(direct_flag)
13187         flags |=O_DIRECTIO;
13188 #endif
13189 #endif
13190     if((fd = I_OPEN(dummyfile[xx], (int)flags,0640))<0)
13191     {
13192         client_error=errno;
13193         if(distributed && client_iozone)
13194             send_stop();
13195         printf("\nCan not open temp file: %s\n", 
13196             filename);
13197         perror("open");
13198         exit(125);
13199     }
13200 #ifdef VXFS
13201     if(direct_flag)
13202     {
13203         ioctl(fd,VX_SETCACHE,VX_DIRECT);
13204         ioctl(fd,VX_GETCACHE,&test_foo);
13205         if(test_foo == 0)
13206         {
13207             if(!client_iozone)
13208               printf("\nVxFS advanced setcache feature not available.\n");
13209             exit(3);
13210         }
13211     }
13212 #endif
13213 #if defined(solaris)
13214         if(direct_flag)
13215         {
13216                 test_foo = directio(fd, DIRECTIO_ON);
13217                 if(test_foo != 0)
13218                 {
13219                         if(!client_iozone)
13220                           printf("\ndirectio not available.\n");
13221                         exit(3);
13222                 }
13223         }
13224 #endif
13225 #ifdef ASYNC_IO
13226     if(async_flag)
13227         async_init(&gc,fd,direct_flag);
13228 #endif
13229     if(mmapflag)
13230     {
13231         maddr=(char *)initfile(fd,(filebytes64),1,PROT_READ|PROT_WRITE);
13232     }
13233     if(reclen < cache_size )
13234     {
13235         recs_per_buffer = cache_size/reclen ;
13236         nbuff=&nbuff[(xx%recs_per_buffer)*reclen];
13237     }
13238     if(fetchon)         /* Prefetch into processor cache */
13239         fetchit(nbuff,reclen);
13240     if((verify && !no_copy_flag) || dedup || dedup_interior)
13241         fill_buffer(nbuff,reclen,(long long)pattern,sverify,(long long)0);
13242 
13243     if(w_traj_flag)
13244         w_traj_fd=open_w_traj();
13245 
13246     child_stat = (struct child_stats *)&shmaddr[xx];    
13247     child_stat->throughput = 0;
13248     child_stat->actual = 0;
13249     child_stat->flag=CHILD_STATE_READY; /* Tell parent child is ready to go */
13250     if(distributed && client_iozone)
13251         tell_master_ready(chid);
13252     if(distributed && client_iozone)
13253     {
13254         if(cdebug)
13255         {
13256             fprintf(newstdout,"Child %d waiting for go from master\n",(int)xx);
13257             fflush(newstdout);
13258         }
13259         wait_for_master_go(chid);
13260         if(cdebug)
13261         {
13262             fprintf(newstdout,"Child %d received go from master\n",(int)xx);
13263             fflush(newstdout);
13264         }
13265     }
13266     else
13267     {
13268         while(child_stat->flag!=CHILD_STATE_BEGIN)   /* Wait for signal from parent */
13269             Poll((long long)1);
13270     }
13271 
13272     written_so_far=0;
13273     child_stat = (struct child_stats *)&shmaddr[xx];
13274     child_stat->actual = 0;
13275     child_stat->throughput = 0;
13276     stopped=0;
13277     if(file_lock)
13278         if(mylockf((int) fd, (int) 1, (int)0) != 0)
13279             printf("File lock for write failed. %d\n",errno);
13280     if(Q_flag)
13281     {
13282         sprintf(tmpname,"Child_%d_pwol.dat",(int)xx);
13283         thread_wqfd=fopen(tmpname,"a");
13284         if(thread_wqfd==0)
13285         {
13286             client_error=errno;
13287             if(distributed && client_iozone)
13288                 send_stop();
13289             printf("Unable to open %s\n",tmpname);
13290             exit(40);
13291         }
13292         fprintf(thread_wqfd,"Offset in Kbytes   Latency in microseconds  Transfer size in bytes\n");
13293     }
13294     if(L_flag)
13295     {
13296         sprintf(tmpname,"Child_%d.log",(int)xx);
13297         thread_Lwqfd=fopen(tmpname,"a");
13298         if(thread_Lwqfd==0)
13299         {
13300             client_error=errno;
13301             if(distributed && client_iozone)
13302                 send_stop();
13303             printf("Unable to open %s\n",tmpname);
13304             exit(40);
13305         }
13306         get_date(now_string);
13307         fprintf(thread_Lwqfd,"%-25s %s","Pwrite test start: ",now_string);
13308     }
13309     starttime1 = time_so_far();
13310     if(cpuutilflag)
13311     {
13312         walltime = starttime1;
13313         cputime = cputime_so_far();
13314     }
13315     if(w_traj_flag)
13316         rewind(w_traj_fd);
13317     for(i=0; i<numrecs64; i++){
13318         traj_offset= ( i * reclen );
13319         if(w_traj_flag)
13320         {
13321             traj_offset=get_traj(w_traj_fd, (long long *)&traj_size,(float *)&delay, (long)1);
13322             reclen=traj_size;
13323         }
13324         if(rlocking)
13325         {
13326             lock_offset=I_LSEEK(fd,0,SEEK_CUR);
13327             mylockr((int) fd, (int) 1, (int)0,
13328               lock_offset, reclen);
13329         }
13330         if((verify && !no_copy_flag) || dedup || dedup_interior)
13331             fill_buffer(nbuff,reclen,(long long)pattern,sverify,i);
13332         if(compute_flag)
13333             compute_val+=do_compute(delay);
13334         if(*stop_flag && !stopped){
13335             if(include_flush)
13336             {
13337                 if(mmapflag)
13338                     msync(maddr,(size_t)filebytes64,MS_SYNC);
13339                 else
13340                     fsync(fd);
13341             }
13342             child_stat->throughput = 
13343                 (time_so_far() - starttime1)-time_res;
13344             if(child_stat->throughput < (double).000001) 
13345             {
13346                 child_stat->throughput = time_res;
13347                 if(rec_prob < reclen)
13348                     rec_prob = reclen;
13349                 res_prob=1;
13350             }
13351 
13352             if(OPS_flag){
13353                /*written_so_far=(written_so_far*1024)/reclen;*/
13354                written_so_far=w_traj_ops_completed;
13355             }
13356             child_stat->throughput = 
13357               (double)written_so_far/child_stat->throughput;
13358             child_stat->actual = (double)written_so_far;
13359             if(debug1)
13360             {
13361                 printf("\n(%ld) Stopped by another\n", (long)xx);
13362             }
13363             stopped=1;
13364         }
13365         if(purge)
13366             purgeit(nbuff,reclen);
13367         if(Q_flag || hist_summary || op_rate_flag)
13368         {
13369             thread_qtime_start=time_so_far();
13370         }
13371 again:      
13372         if(mmapflag)
13373         {
13374             wmaddr = &maddr[traj_offset];
13375             fill_area((long long*)nbuff,(long long*)wmaddr,(long long)reclen);
13376             /*printf("CHid: %lld  Writing offset %lld for length of %lld\n",chid,i*reclen,reclen);*/
13377             if(!mmapnsflag)
13378             {
13379               if(mmapasflag)
13380                 msync(wmaddr,(size_t)reclen,MS_ASYNC);
13381               if(mmapssflag)
13382                 msync(wmaddr,(size_t)reclen,MS_SYNC);
13383             }
13384         }
13385         else
13386         {
13387            if(async_flag)
13388            {
13389                  if(no_copy_flag)
13390                  {
13391                 free_addr=nbuff=(char *)malloc((size_t)reclen+page_size);
13392                 nbuff=(char *)(((long)nbuff+(long)page_size) & (long)~(page_size-1));
13393                 if(verify || dedup || dedup_interior)
13394                     fill_buffer(nbuff,reclen,(long long)pattern,sverify,i);
13395                     async_write_no_copy(gc, (long long)fd, nbuff, reclen, (traj_offset), depth,free_addr);
13396                  }
13397                  else
13398                 async_write(gc, (long long)fd, nbuff, reclen, (traj_offset), depth);
13399            }
13400            else
13401            {
13402               wval=I_PWRITE(fd, nbuff, reclen, traj_offset);
13403               if(wval != reclen)
13404               {
13405             if(*stop_flag && !stopped){
13406                 if(include_flush)
13407                 {
13408                     if(mmapflag)
13409                         msync(maddr,(size_t)filebytes64,MS_SYNC);
13410                     else
13411                         fsync(fd);
13412                 }
13413                 temp_time = time_so_far();
13414                 child_stat->throughput = 
13415                     (temp_time - starttime1)-time_res;
13416                 if(child_stat->throughput < (double).000001) 
13417                 {
13418                     child_stat->throughput= time_res;
13419                     if(rec_prob < reclen)
13420                         rec_prob = reclen;
13421                     res_prob=1;
13422                 }
13423 
13424                 if(OPS_flag){
13425                    /*written_so_far=(written_so_far*1024)/reclen;*/
13426                    written_so_far=w_traj_ops_completed;
13427                 }
13428                 child_stat->throughput = 
13429                   (double)written_so_far/child_stat->throughput;
13430                 child_stat->actual = (double)written_so_far;
13431                 if(debug1)
13432                 {
13433                     printf("\n(%ld) Stopped by another\n", (long)xx);
13434                 }
13435                 stopped=1;
13436                 goto again;
13437             }
13438             /* Note: Writer must finish even though told
13439                to stop. Otherwise the readers will fail.
13440                The code will capture bytes transfered
13441                before told to stop but let the writer
13442                complete.
13443             */
13444 #ifdef NO_PRINT_LLD
13445                 printf("\nError pwriting block %ld, fd= %d\n", i,
13446                  fd);
13447 #else
13448                 printf("\nError pwriting block %lld, fd= %d\n", i,
13449                  fd);
13450 #endif
13451             if(wval==-1)
13452                 perror("pwrite");
13453             if (!no_unlink)
13454             {
13455                if(check_filename(dummyfile[xx]))
13456                 unlink(dummyfile[xx]);
13457             }
13458             child_stat->flag = CHILD_STATE_HOLD;
13459                 exit(127);
13460               }
13461             }
13462         }
13463         if(rlocking)
13464         {
13465             mylockr((int) fd, (int) 0, (int)0,
13466               lock_offset, reclen);
13467         }
13468         if(hist_summary)
13469         {
13470             thread_qtime_stop=time_so_far();
13471             hist_time =(thread_qtime_stop-thread_qtime_start-time_res);
13472             hist_insert(hist_time);
13473         }
13474         if(op_rate_flag)
13475         {
13476             thread_qtime_stop=time_so_far();
13477             desired_op_rate_time = ((double)1.0/(double)op_rate);
13478             actual_rate = (double)(thread_qtime_stop-thread_qtime_start);
13479 /*
13480 printf("Desired rate %g  Actual rate %g Nap %g microseconds\n",desired_op_rate_time,
13481     actual_rate, (desired_op_rate_time-actual_rate));
13482 */
13483             if( actual_rate < desired_op_rate_time)
13484                 my_unap((unsigned long long) ((desired_op_rate_time-actual_rate)*1000000.0 ));
13485         }
13486         if(Q_flag)
13487         {
13488             thread_qtime_stop=time_so_far();
13489 #ifdef NO_PRINT_LLD
13490             fprintf(thread_wqfd,"%10.1ld %10.0f %10.1ld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
13491 #else
13492             fprintf(thread_wqfd,"%10.1lld %10.0f %10.1lld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
13493 #endif
13494         }
13495         w_traj_ops_completed++;
13496         w_traj_bytes_completed+=reclen;
13497         written_so_far+=reclen/1024;
13498         if(*stop_flag)
13499         {
13500             written_so_far-=reclen/1024;
13501             w_traj_bytes_completed-=reclen;
13502         }
13503     }
13504     
13505 
13506     if(file_lock)
13507         if(mylockf((int) fd, (int) 0, (int)0))
13508             printf("Write unlock failed. %d\n",errno);
13509     
13510 #ifdef ASYNC_IO
13511     if(async_flag)
13512     {
13513         end_async(gc);
13514         gc=0;
13515     }
13516 #endif
13517     if(!xflag)
13518     {
13519         *stop_flag=1;
13520         if(distributed && client_iozone)
13521             send_stop();
13522     }
13523     
13524     if(include_flush)
13525     {
13526         if(mmapflag)
13527             msync(maddr,(size_t)filebytes64,MS_SYNC);
13528         else
13529             fsync(fd);
13530     }
13531     if(include_close)
13532     {
13533         if(mmapflag)
13534             mmap_end(maddr,(unsigned long long)filebytes64);
13535         close(fd);
13536     }
13537     if(!stopped){
13538         temp_time = time_so_far();
13539         child_stat->throughput = ((temp_time - starttime1)-time_res)
13540             -compute_val;
13541         if(child_stat->throughput < (double).000001) 
13542         {
13543             child_stat->throughput= time_res;
13544             if(rec_prob < reclen)
13545                 rec_prob = reclen;
13546             res_prob=1;
13547         }
13548 
13549         if(OPS_flag){
13550            /*written_so_far=(written_so_far*1024)/reclen;*/
13551            written_so_far=w_traj_ops_completed;
13552         }
13553         child_stat->throughput =
13554             (double)written_so_far/child_stat->throughput;
13555         child_stat->actual = (double)written_so_far;
13556     }
13557     if(cdebug)
13558     {
13559         fprintf(newstdout,"Child %d: throughput %f actual %f \n",(int)chid, child_stat->throughput,
13560             child_stat->actual);
13561         fflush(newstdout);
13562     }
13563     if(cpuutilflag)
13564     {
13565         cputime = cputime_so_far() - cputime;
13566         if (cputime < cputime_res)
13567             cputime = 0.0;
13568         child_stat->cputime = cputime;
13569         walltime = time_so_far() - walltime;
13570         child_stat->walltime = walltime;
13571     }
13572     if(distributed && client_iozone)
13573         tell_master_stats(THREAD_PWRITE_TEST, chid, child_stat->throughput, 
13574             child_stat->actual, 
13575             child_stat->cputime, child_stat->walltime,
13576             (char)*stop_flag,
13577             (long long)CHILD_STATE_HOLD);
13578             
13579     if (debug1) {
13580         printf(" child/slot: %lld, wall-cpu: %8.3f %8.3fC" " -> %6.2f%%\n",
13581             xx, walltime, cputime,
13582             cpu_util(cputime, walltime));
13583     }
13584     child_stat->flag = CHILD_STATE_HOLD; /* Tell parent I'm done */
13585     stopped=0;
13586     /*******************************************************************/
13587     /* End pwrite performance test. *************************************/
13588     /*******************************************************************/
13589     if(debug1)
13590 #ifdef NO_PRINT_LLD
13591         printf("\nChild finished %ld\n",xx);
13592 #else
13593         printf("\nChild finished %lld\n",xx);
13594 #endif
13595     if(!include_close)
13596     {
13597         if(mmapflag)
13598         {
13599             msync(maddr,(size_t)numrecs64*reclen,MS_SYNC); /*Clean up before read starts running*/ 
13600             mmap_end(maddr,(unsigned long long)numrecs64*reclen);
13601         }else
13602             fsync(fd);
13603             
13604         close(fd);
13605     }
13606     if(Q_flag && (thread_wqfd !=0) )
13607         fclose(thread_wqfd);
13608     free(dummyfile[xx]);
13609     if(w_traj_flag)
13610         fclose(w_traj_fd);
13611 
13612     if(L_flag)
13613     {
13614         get_date(now_string);
13615         fprintf(thread_Lwqfd,"%-25s %s","Pwrite test finished: ",now_string);
13616         fclose(thread_Lwqfd);
13617     }
13618     if(hist_summary)
13619        dump_hist("Pwrite",(int)xx);
13620     if(distributed && client_iozone)
13621         return(0);
13622 #ifdef NO_THREADS
13623     exit(0);
13624 #else
13625     if(use_thread)
13626         thread_exit();
13627     else
13628         exit(0);
13629 #endif
13630 return(0);
13631 }
13632 #endif
13633 
13634 /************************************************************************/
13635 /* Thread re-write test                             */
13636 /************************************************************************/
13637 #ifdef HAVE_ANSIC_C
13638 void *
13639 thread_rwrite_test(void *x)
13640 #else
13641 void *
13642 thread_rwrite_test(x)
13643 #endif
13644 {
13645     /************************/
13646     /* Children only here   */
13647     /************************/
13648     struct child_stats *child_stat;
13649     long long xx,xx2;
13650     double compute_val = (double)0;
13651     double walltime, cputime;
13652     float delay = (float)0;
13653     double thread_qtime_stop,thread_qtime_start;
13654     double hist_time;
13655     double desired_op_rate_time;
13656     double actual_rate;
13657     off64_t traj_offset;
13658     off64_t lock_offset=0;
13659     long long w_traj_bytes_completed;
13660     long long w_traj_ops_completed;
13661     int fd;
13662     FILE *w_traj_fd;
13663     long long flags = 0;
13664     double starttime1 = 0;
13665     double temp_time;
13666     long long recs_per_buffer,traj_size;
13667     long long i;
13668     off64_t written_so_far, read_so_far, re_written_so_far,re_read_so_far=0;
13669     char *dummyfile [MAXSTREAMS];           /* name of dummy file     */
13670     char *nbuff;
13671     char *maddr,*free_addr;
13672     char *wmaddr;
13673     char now_string[30];
13674     int anwser,bind_cpu,wval;
13675     FILE *thread_rwqfd,*thread_Lwqfd;
13676     char tmpname[256];
13677 #if defined(VXFS) || defined(solaris)
13678     int test_foo = 0;
13679 #endif
13680 #ifdef ASYNC_IO
13681     struct cache *gc=0;
13682 
13683 #else
13684     long long *gc=0;
13685 #endif
13686 
13687     if(compute_flag)
13688         delay=compute_time;
13689     wmaddr=nbuff=maddr=free_addr=0;
13690     thread_rwqfd=w_traj_fd=thread_Lwqfd=(FILE *)0;
13691     hist_time=traj_offset=thread_qtime_stop=thread_qtime_start=0;
13692     walltime=cputime=0;
13693     anwser=bind_cpu=0;
13694     w_traj_bytes_completed=w_traj_ops_completed=0;
13695     written_so_far=read_so_far=re_written_so_far=re_read_so_far=0;
13696     recs_per_buffer = cache_size/reclen ;
13697     if(w_traj_flag)
13698     {
13699         filebytes64 = w_traj_fsize;
13700         numrecs64=w_traj_ops;
13701     }
13702     else
13703     {
13704         filebytes64 = numrecs64*reclen;
13705     }
13706 #ifdef NO_THREADS
13707     xx=chid;
13708 #else
13709     if(use_thread)
13710         xx=(long long)((long)x);
13711     else
13712     {
13713         xx=chid;
13714     }
13715 #endif
13716 #ifndef NO_THREADS
13717 #if defined( _HPUX_SOURCE ) || defined ( linux )
13718     if(ioz_processor_bind)
13719     {
13720          bind_cpu=(begin_proc+(int)xx)%num_processors;
13721 #if defined( _HPUX_SOURCE )
13722          pthread_processor_bind_np(PTHREAD_BIND_FORCED_NP,
13723                          (pthread_spu_t *)&anwser, (pthread_spu_t)bind_cpu, pthread_self());
13724 #else
13725      cpu_set_t cpuset;
13726      CPU_ZERO(&cpuset);
13727      CPU_SET(bind_cpu, &cpuset);
13728 
13729      pthread_setaffinity_np(pthread_self(), sizeof(cpuset),&cpuset);
13730 #endif
13731         my_nap(40); /* Switch to new cpu */
13732     }
13733 #endif
13734 #endif
13735     if(use_thread)
13736         nbuff=barray[xx];
13737     else
13738         nbuff=buffer;
13739     child_stat = (struct child_stats *)&shmaddr[xx];
13740     child_stat->throughput = 0;
13741     child_stat->actual = 0;
13742     if(debug1)
13743     {
13744        if(use_thread)
13745 #ifdef NO_PRINT_LLD
13746         printf("\nStarting child %ld\n",xx);
13747 #else
13748         printf("\nStarting child %lld\n",xx);
13749 #endif
13750        else
13751 #ifdef NO_PRINT_LLD
13752         printf("\nStarting process %d slot %ld\n",getpid(),xx);
13753 #else
13754         printf("\nStarting process %d slot %lld\n",getpid(),xx);
13755 #endif
13756         
13757     }
13758     dummyfile[xx]=(char *)malloc((size_t)MAXNAMESIZE);
13759     xx2=xx;
13760     if(share_file)
13761         xx2=(long long)0;
13762     if(mfflag)
13763     {
13764 #ifdef NO_PRINT_LLD
13765         sprintf(dummyfile[xx],"%s",filearray[xx2]);
13766 #else
13767         sprintf(dummyfile[xx],"%s",filearray[xx2]);
13768 #endif
13769     }
13770     else
13771     {
13772 #ifdef NO_PRINT_LLD
13773         sprintf(dummyfile[xx],"%s.DUMMY.%ld",filearray[xx2],xx2);
13774 #else
13775         sprintf(dummyfile[xx],"%s.DUMMY.%lld",filearray[xx2],xx2);
13776 #endif
13777     }
13778     flags = O_RDWR;
13779     if(oflag)
13780         flags|= O_SYNC;
13781 #if defined(O_DSYNC)
13782     if(odsync)
13783         flags|= O_DSYNC;
13784 #endif
13785 #if defined(_HPUX_SOURCE) || defined(linux)
13786     if(read_sync)
13787         flags |=O_RSYNC|O_SYNC;
13788 #endif
13789 
13790 #if ! defined(DONT_HAVE_O_DIRECT)
13791 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
13792     if(direct_flag)
13793         flags |=O_DIRECT;
13794 #endif
13795 #if defined(TRU64)
13796     if(direct_flag)
13797         flags |=O_DIRECTIO;
13798 #endif
13799 #endif
13800 
13801 #if defined(Windows)
13802         if(unbuffered)
13803         {
13804             hand=CreateFile(dummyfile[xx],
13805           GENERIC_READ|GENERIC_WRITE,
13806               FILE_SHARE_WRITE|FILE_SHARE_READ,
13807           NULL,OPEN_ALWAYS,FILE_FLAG_NO_BUFFERING|
13808           FILE_FLAG_WRITE_THROUGH|FILE_FLAG_POSIX_SEMANTICS,
13809           NULL);
13810         }
13811         else
13812         {
13813 #endif
13814     if((fd = I_OPEN(dummyfile[xx], (int)flags,0))<0)
13815     {
13816         client_error=errno;
13817         if(distributed && client_iozone)
13818             send_stop();
13819 #ifdef NO_PRINT_LLD
13820         printf("\nChild %ld\n",xx);
13821 #else
13822         printf("\nChild %lld\n",xx);
13823 #endif
13824         child_stat->flag = CHILD_STATE_HOLD;
13825         perror(dummyfile[xx]);
13826         exit(128);
13827     }
13828 #if defined(Windows)
13829     }
13830 #endif
13831 #ifdef VXFS
13832     if(direct_flag)
13833     {
13834         ioctl(fd,VX_SETCACHE,VX_DIRECT);
13835         ioctl(fd,VX_GETCACHE,&test_foo);
13836         if(test_foo == 0)
13837         {
13838             if(!client_iozone)
13839               printf("\nVxFS advanced setcache feature not available.\n");
13840             exit(3);
13841         }
13842     }
13843 #endif
13844 #if defined(solaris)
13845         if(direct_flag)
13846         {
13847                 test_foo = directio(fd, DIRECTIO_ON);
13848                 if(test_foo != 0)
13849                 {
13850                         if(!client_iozone)
13851                           printf("\ndirectio not available.\n");
13852                         exit(3);
13853                 }
13854         }
13855 #endif
13856 #ifdef ASYNC_IO
13857     if(async_flag)
13858         async_init(&gc,fd,direct_flag);
13859 #endif
13860     if(mmapflag)
13861     {
13862         maddr=(char *)initfile(fd,(numrecs64*reclen),1,PROT_READ|PROT_WRITE);
13863     }
13864     if(fetchon)
13865         fetchit(nbuff,reclen);
13866     if(w_traj_flag)
13867         w_traj_fd=open_w_traj();
13868     if(Q_flag)
13869     {
13870         sprintf(tmpname,"Child_%d_rwol.dat",(int)xx);
13871         thread_rwqfd=fopen(tmpname,"a");
13872         if(thread_rwqfd==0)
13873         {
13874             printf("Unable to open %s\n",tmpname);
13875             client_error=errno;
13876             if(distributed && client_iozone)
13877                 send_stop();
13878             exit(40);
13879         }
13880         fprintf(thread_rwqfd,"Offset in Kbytes   Latency in microseconds  Transfer size in bytes\n");
13881     }
13882     if(L_flag)
13883     {
13884         sprintf(tmpname,"Child_%d.log",(int)xx);
13885         thread_Lwqfd=fopen(tmpname,"a");
13886         if(thread_Lwqfd==0)
13887         {
13888             client_error=errno;
13889             if(distributed && client_iozone)
13890                 send_stop();
13891             printf("Unable to open %s\n",tmpname);
13892             exit(40);
13893         }
13894         get_date(now_string);
13895         fprintf(thread_Lwqfd,"%-25s %s","Rewrite test start: ",now_string);
13896     }
13897     child_stat->flag = CHILD_STATE_READY;
13898     if(distributed && client_iozone)
13899         tell_master_ready(chid);
13900     if(distributed && client_iozone)
13901     {
13902         if(cdebug)
13903         {
13904             fprintf(newstdout,"Child %d waiting for go from master\n",(int)xx);
13905             fflush(newstdout);
13906         }
13907         wait_for_master_go(chid);
13908         if(cdebug)
13909         {
13910             fprintf(newstdout,"Child %d received go from master\n",(int)xx);
13911             fflush(newstdout);
13912         }
13913     }
13914     else
13915     {
13916         while(child_stat->flag!=CHILD_STATE_BEGIN)   /* Wait for signal from parent */
13917             Poll((long long)1);
13918     }
13919     starttime1 = time_so_far();
13920     if(cpuutilflag)
13921     {
13922         walltime = starttime1;
13923         cputime = cputime_so_far();
13924     }
13925     if(file_lock)
13926         if(mylockf((int) fd, (int) 1, (int)0) != 0)
13927             printf("File lock for write failed. %d\n",errno);
13928     if(cpuutilflag)
13929     {
13930         walltime = starttime1;
13931         cputime = cputime_so_far();
13932     }
13933     if(w_traj_flag)
13934         rewind(w_traj_fd);
13935     if((verify && !no_copy_flag) || dedup || dedup_interior)
13936         fill_buffer(nbuff,reclen,(long long)pattern,sverify,(long long)0);
13937     for(i=0; i<numrecs64; i++){
13938         traj_offset= i*reclen ;
13939         if(w_traj_flag)
13940         {
13941             traj_offset=get_traj(w_traj_fd, (long long *)&traj_size,(float *)&delay,(long)1);
13942             reclen=traj_size;
13943 #if defined(Windows)
13944             if(unbuffered)
13945               SetFilePointer(hand,(LONG)traj_offset,0,FILE_BEGIN);
13946             else
13947 #endif
13948             I_LSEEK(fd,traj_offset,SEEK_SET);
13949         }
13950         if(Q_flag)
13951         {
13952 #if defined(Windows)
13953             if(unbuffered)
13954               traj_offset=SetFilePointer(hand,(LONG)0,0,FILE_CURRENT);
13955             else
13956 #endif
13957             traj_offset=I_LSEEK(fd,0,SEEK_CUR);
13958         }
13959         if(rlocking)
13960         {
13961             lock_offset=I_LSEEK(fd,0,SEEK_CUR);
13962             mylockr((int) fd, (int) 1, (int)0,
13963               lock_offset, reclen);
13964         }
13965         if(compute_flag)
13966             compute_val+=do_compute(delay);
13967         if(*stop_flag && !mmapflag)
13968         {
13969             if(debug1)
13970                 printf("\nStop_flag 1\n");
13971             break;
13972         }
13973         if((verify && !no_copy_flag) || dedup || dedup_interior)
13974         {
13975             fill_buffer(nbuff,reclen,(long long)pattern,sverify,i);
13976         }
13977         if(purge)
13978             purgeit(nbuff,reclen);
13979         if(Q_flag || hist_summary || op_rate_flag)
13980         {
13981             thread_qtime_start=time_so_far();
13982         }
13983         if(mmapflag)
13984         {
13985             wmaddr = &maddr[i*reclen];
13986             if(cdebug)
13987             {
13988 fprintf(newstdout,"Chid: %lld Rewriting offset %lld for length of %lld\n",chid, i*reclen,reclen);
13989               fflush(newstdout);
13990             }
13991             fill_area((long long*)nbuff,(long long*)wmaddr,(long long)reclen);
13992             if(!mmapnsflag)
13993             {
13994               if(mmapasflag)
13995                 msync(wmaddr,(size_t)reclen,MS_ASYNC);
13996               if(mmapssflag)
13997                 msync(wmaddr,(size_t)reclen,MS_SYNC);
13998             }
13999         }
14000         else
14001         {
14002             if(async_flag)
14003             {
14004                  if(no_copy_flag)
14005                  {
14006                 free_addr=nbuff=(char *)malloc((size_t)reclen+page_size);
14007                 nbuff=(char *)(((long)nbuff+(long)page_size) & (long)~(page_size-1));
14008                 if(verify || dedup || dedup_interior)
14009                     fill_buffer(nbuff,reclen,(long long)pattern,sverify,i);
14010                     async_write_no_copy(gc, (long long)fd, nbuff, reclen, (i*reclen), depth,free_addr);
14011                  }
14012                  else
14013                 async_write(gc, (long long)fd, nbuff, reclen, (i*reclen), depth);
14014             }
14015             else
14016             {
14017 #if defined(Windows)
14018                if(unbuffered)
14019                {
14020                 WriteFile(hand,nbuff,reclen,(LPDWORD)&wval,0);
14021                }
14022                else
14023 #endif
14024                wval=write(fd, nbuff, (size_t) reclen);
14025                if(wval != reclen)
14026                {
14027                 if(*stop_flag)
14028                 {
14029                     if(debug1)
14030                         printf("\nStop_flag 2\n");
14031                     break;
14032                 }
14033 #ifdef NO_PRINT_LLD
14034                     printf("\nError writing block %ld, fd= %d\n", i,
14035                      fd);
14036 #else
14037                     printf("\nError writing block %lld, fd= %d\n", i,
14038                      fd);
14039 #endif
14040                 if(wval==-1)
14041                     perror("write");
14042                 if (!no_unlink)
14043                 {
14044                    if(check_filename(dummyfile[xx]))
14045                     unlink(dummyfile[xx]);
14046                 }
14047                 child_stat->flag = CHILD_STATE_HOLD;
14048                 signal_handler();
14049                }
14050             }
14051         }
14052         re_written_so_far+=reclen/1024;
14053         w_traj_ops_completed++;
14054         w_traj_bytes_completed+=reclen;
14055         if(*stop_flag)
14056         {
14057             re_written_so_far-=reclen/1024;
14058             w_traj_bytes_completed-=reclen;
14059         }
14060         if(hist_summary)
14061         {
14062             thread_qtime_stop=time_so_far();
14063             hist_time =(thread_qtime_stop-thread_qtime_start-time_res);
14064             hist_insert(hist_time);
14065         }
14066         if(op_rate_flag)
14067         {
14068             thread_qtime_stop=time_so_far();
14069             desired_op_rate_time = ((double)1.0/(double)op_rate);
14070             actual_rate = (double)(thread_qtime_stop-thread_qtime_start);
14071 /*
14072 printf("Desired rate %g  Actual rate %g Nap %g microseconds\n",desired_op_rate_time,
14073     actual_rate, (desired_op_rate_time-actual_rate));
14074 */
14075             if( actual_rate < desired_op_rate_time)
14076                 my_unap((unsigned long long) ((desired_op_rate_time-actual_rate)*1000000.0 ));
14077         }
14078         if(Q_flag)
14079         {
14080             thread_qtime_stop=time_so_far();
14081 #ifdef NO_PRINT_LLD
14082             fprintf(thread_rwqfd,"%10.1ld %10.0f %10.1ld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
14083 #else
14084             fprintf(thread_rwqfd,"%10.1lld %10.0f %10.1lld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
14085 #endif
14086         }
14087         if(rlocking)
14088         {
14089             mylockr((int) fd, (int) 0, (int)0,
14090               lock_offset, reclen);
14091         }
14092     }
14093     if(file_lock)
14094         if(mylockf((int) fd, (int) 0, (int)0))
14095             printf("Write unlock failed. %d\n",errno);
14096 #ifdef ASYNC_IO
14097     if(async_flag)
14098     {
14099         end_async(gc);
14100         gc=0;
14101     }
14102 #endif
14103     if(include_flush)
14104     {
14105         if(mmapflag)
14106         {
14107             msync(maddr,(size_t)(filebytes64),MS_SYNC);
14108         }else
14109             fsync(fd);
14110     }
14111     if(include_close)
14112     {
14113         if(mmapflag)
14114         {
14115             mmap_end(maddr,(unsigned long long)filebytes64);
14116         }
14117 #if defined(Windows)
14118         if(unbuffered)
14119             CloseHandle(hand);
14120         else
14121 #endif
14122         close(fd);
14123     }
14124     temp_time=time_so_far();
14125     child_stat=(struct child_stats *)&shmaddr[xx];
14126     child_stat->throughput = ((temp_time - starttime1)-time_res)
14127         -compute_val;
14128     if(child_stat->throughput < (double).000001) 
14129     {
14130         child_stat->throughput= time_res;
14131         if(rec_prob < reclen)
14132             rec_prob = reclen;
14133         res_prob=1;
14134     }
14135 
14136     if(OPS_flag){
14137        /*re_written_so_far=(re_written_so_far*1024)/reclen;*/
14138        re_written_so_far=w_traj_ops_completed;
14139     }
14140     child_stat->throughput = 
14141         (double)re_written_so_far/child_stat->throughput;
14142     child_stat->actual = (double)re_written_so_far;
14143     if(!xflag)
14144     {
14145         *stop_flag=1;
14146         if(distributed && client_iozone)
14147             send_stop();
14148     }
14149     if(cdebug)
14150     {
14151         fprintf(newstdout,"Child %d: throughput %f actual %f \n",(int)chid, child_stat->throughput,
14152             child_stat->actual);
14153         fflush(newstdout);
14154     }
14155     if(cpuutilflag)
14156     {
14157         cputime = cputime_so_far() - cputime;
14158         if (cputime < cputime_res)
14159             cputime = 0.0;
14160         child_stat->cputime = cputime;
14161         walltime = time_so_far() - walltime;
14162         child_stat->walltime = walltime;
14163     }
14164     if(distributed && client_iozone)
14165         tell_master_stats(THREAD_REWRITE_TEST, chid, child_stat->throughput, 
14166             child_stat->actual,
14167             child_stat->cputime, child_stat->walltime,
14168             (char)*stop_flag,
14169             (long long)CHILD_STATE_HOLD);
14170     child_stat->flag = CHILD_STATE_HOLD;    /* Tell parent I'm done */
14171     if(!include_close)
14172     {
14173         if(mmapflag)
14174         {
14175             msync(maddr,(size_t)(filebytes64),MS_SYNC);
14176             mmap_end(maddr,(unsigned long long)filebytes64);
14177         }
14178         else
14179             fsync(fd);
14180 #if defined(Windows)
14181         if(unbuffered)
14182             CloseHandle(hand);
14183         else
14184 #endif
14185         close(fd);
14186     }
14187     free(dummyfile[xx]);
14188 
14189     if(Q_flag && (thread_rwqfd !=0) )
14190         fclose(thread_rwqfd);
14191 
14192     if(w_traj_flag)
14193         fclose(w_traj_fd);
14194     if(debug1)
14195 #ifdef NO_PRINT_LLD
14196         printf("\nChild Stopping  %ld\n",xx);
14197 #else
14198         printf("\nChild Stopping  %lld\n",xx);
14199 #endif
14200 
14201     if(L_flag)
14202     {
14203         get_date(now_string);
14204         fprintf(thread_Lwqfd,"%-25s %s","Rewrite test finished: ",now_string);
14205         fclose(thread_Lwqfd);
14206     }
14207     if(hist_summary)
14208        dump_hist("Rewrite",(int)xx);
14209     if(distributed && client_iozone)
14210         return(0);
14211 #ifdef NO_THREADS
14212     exit(0);
14213 #else
14214     if(use_thread)
14215         thread_exit();
14216     else
14217         exit(0);
14218 #endif
14219 return(0);
14220 }
14221 
14222 /************************************************************************/
14223 /* Thread read test                             */
14224 /************************************************************************/
14225 #ifdef HAVE_ANSIC_C
14226 void *
14227 thread_read_test(void *x)
14228 #else
14229 void *
14230 thread_read_test(x)
14231 #endif
14232 {
14233     long long xx,xx2;
14234     struct child_stats *child_stat;
14235     double walltime, cputime;
14236     long long r_traj_bytes_completed;
14237     long long r_traj_ops_completed;
14238     int fd;
14239     FILE *r_traj_fd,*thread_rqfd;
14240     FILE *thread_Lwqfd;
14241     long long flags = 0;
14242     off64_t traj_offset;
14243     off64_t lock_offset=0;
14244     double starttime1 = 0;
14245     float delay = 0;
14246     double temp_time;
14247     double thread_qtime_start,thread_qtime_stop;
14248     double hist_time;
14249     double desired_op_rate_time;
14250     double actual_rate;
14251     double compute_val = (double)0;
14252     off64_t written_so_far, read_so_far, re_written_so_far,re_read_so_far;
14253     long long recs_per_buffer,traj_size;
14254     off64_t i;
14255     char *dummyfile[MAXSTREAMS];           /* name of dummy file     */
14256     char *nbuff=0;
14257     char *maddr=0;
14258     char *wmaddr=0;
14259     char tmpname[256];
14260     volatile char *buffer1;
14261     char now_string[30];
14262     int anwser,bind_cpu;
14263     long wval;
14264 #if defined(VXFS) || defined(solaris)
14265     int test_foo = 0;
14266 #endif
14267 #ifdef ASYNC_IO
14268     struct cache *gc=0;
14269 #else
14270     long long *gc=0;
14271 #endif
14272 
14273     if(compute_flag)
14274         delay=compute_time;
14275     thread_rqfd=thread_Lwqfd=r_traj_fd=(FILE *)0;
14276     hist_time=traj_offset=thread_qtime_stop=thread_qtime_start=0;
14277     walltime=cputime=0;
14278     anwser=bind_cpu=0;
14279     r_traj_bytes_completed=r_traj_ops_completed=0;
14280     written_so_far=read_so_far=re_written_so_far=re_read_so_far=0;
14281     recs_per_buffer = cache_size/reclen ;
14282     if(r_traj_flag)
14283     {
14284         filebytes64 = r_traj_fsize;
14285         numrecs64=r_traj_ops;
14286     }
14287     else
14288     {
14289         filebytes64 = numrecs64*reclen;
14290     }
14291     
14292 #ifdef NO_THREADS
14293     xx=chid;
14294 #else
14295     if(use_thread)
14296         xx = (long long)((long)x);
14297     else
14298     {
14299         xx=chid;
14300     }
14301 #endif
14302 #ifndef NO_THREADS
14303 #if defined( _HPUX_SOURCE ) || defined ( linux )
14304     if(ioz_processor_bind)
14305     {
14306          bind_cpu=(begin_proc+(int)xx)%num_processors;
14307 #if defined(_HPUX_SOURCE)
14308          pthread_processor_bind_np(PTHREAD_BIND_FORCED_NP,
14309                          (pthread_spu_t *)&anwser, (pthread_spu_t)bind_cpu, pthread_self());
14310 #else
14311      cpu_set_t cpuset;
14312 
14313      CPU_ZERO(&cpuset);
14314      CPU_SET(bind_cpu, &cpuset);
14315 
14316      pthread_setaffinity_np(pthread_self(), sizeof(cpuset),&cpuset);
14317 #endif
14318         my_nap(40); /* Switch to new cpu */
14319     }
14320 #endif
14321 #endif
14322     if(use_thread)
14323         nbuff=barray[xx];
14324     else
14325         nbuff=buffer;
14326     dummyfile[xx]=(char *)malloc((size_t)MAXNAMESIZE);
14327     xx2=xx;
14328     if(share_file)
14329         xx2=(long long)0;
14330     if(mfflag)
14331     {
14332 #ifdef NO_PRINT_LLD
14333         sprintf(dummyfile[xx],"%s",filearray[xx2]);
14334 #else
14335         sprintf(dummyfile[xx],"%s",filearray[xx2]);
14336 #endif
14337     }
14338     else
14339     {
14340 #ifdef NO_PRINT_LLD
14341         sprintf(dummyfile[xx],"%s.DUMMY.%ld",filearray[xx2],xx2);
14342 #else
14343         sprintf(dummyfile[xx],"%s.DUMMY.%lld",filearray[xx2],xx2);
14344 #endif
14345     }
14346     if(oflag)
14347         flags=O_RDONLY|O_SYNC;
14348     else
14349         flags=O_RDONLY;
14350 #if defined(_HPUX_SOURCE) || defined(linux)
14351     if(read_sync)
14352         flags |=O_RSYNC|O_SYNC;
14353 #endif
14354 
14355 #if ! defined(DONT_HAVE_O_DIRECT)
14356 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
14357     if(direct_flag)
14358         flags |=O_DIRECT;
14359 #endif
14360 #if defined(TRU64)
14361     if(direct_flag)
14362         flags |=O_DIRECTIO;
14363 #endif
14364 #endif
14365 #if defined(Windows)
14366         if(unbuffered)
14367         {
14368             hand=CreateFile(dummyfile[xx],
14369           GENERIC_READ|GENERIC_WRITE,
14370               FILE_SHARE_WRITE|FILE_SHARE_READ,
14371           NULL,OPEN_EXISTING,FILE_FLAG_NO_BUFFERING|
14372           FILE_FLAG_WRITE_THROUGH|FILE_FLAG_POSIX_SEMANTICS,
14373           NULL);
14374         SetFilePointer(hand,(LONG)0,0,FILE_BEGIN);
14375         }
14376     else
14377     {
14378 #endif
14379     if((fd = I_OPEN(dummyfile[xx], (int)flags,0))<0)
14380     {
14381         client_error=errno;
14382         if(distributed && client_iozone)
14383             send_stop();
14384         perror(dummyfile[xx]);
14385         exit(130);
14386     }
14387 #if defined(Windows)
14388     }
14389 #endif
14390 #ifdef ASYNC_IO
14391     if(async_flag)
14392         async_init(&gc,fd,direct_flag);
14393 #endif
14394 #ifdef VXFS
14395     if(direct_flag)
14396     {
14397         ioctl(fd,VX_SETCACHE,VX_DIRECT);
14398         ioctl(fd,VX_GETCACHE,&test_foo);
14399         if(test_foo == 0)
14400         {
14401             if(!client_iozone)
14402               printf("\nVxFS advanced setcache feature not available.\n");
14403             exit(3);
14404         }
14405     }
14406 #endif
14407 #if defined(solaris)
14408         if(direct_flag)
14409         {
14410                 test_foo = directio(fd, DIRECTIO_ON);
14411                 if(test_foo != 0)
14412                 {
14413                         if(!client_iozone)
14414                           printf("\ndirectio not available.\n");
14415                         exit(3);
14416                 }
14417         }
14418 #endif
14419     if(mmapflag)
14420     {
14421         maddr=(char *)initfile(fd,(numrecs64*reclen),0,PROT_READ);
14422     }
14423     child_stat = (struct child_stats *)&shmaddr[xx];
14424     child_stat->throughput = 0;
14425     child_stat->actual = 0;
14426     if(debug1)
14427     {
14428        if(use_thread)
14429 #ifdef NO_PRINT_LLD
14430         printf("\nStarting child %ld\n",xx);
14431 #else
14432         printf("\nStarting child %lld\n",xx);
14433 #endif
14434        else
14435 #ifdef NO_PRINT_LLD
14436         printf("\nStarting process %d slot %ld\n",getpid(),xx);
14437 #else
14438         printf("\nStarting process %d slot %lld\n",getpid(),xx);
14439 #endif
14440         
14441     }
14442     /*****************/
14443     /* Children only */
14444     /*****************/
14445     if(Q_flag)
14446     {
14447         sprintf(tmpname,"Child_%d_rol.dat",(int)xx);
14448         thread_rqfd=fopen(tmpname,"a");
14449         if(thread_rqfd==0)
14450         {
14451             client_error=errno;
14452             if(distributed && client_iozone)
14453                 send_stop();
14454             printf("Unable to open %s\n",tmpname);
14455             exit(40);
14456         }
14457         fprintf(thread_rqfd,"Offset in Kbytes   Latency in microseconds  Transfer size in bytes\n");
14458     }
14459     if(L_flag)
14460     {
14461         sprintf(tmpname,"Child_%d.log",(int)xx);
14462         thread_Lwqfd=fopen(tmpname,"a");
14463         if(thread_Lwqfd==0)
14464         {
14465             client_error=errno;
14466             if(distributed && client_iozone)
14467                 send_stop();
14468             printf("Unable to open %s\n",tmpname);
14469             exit(40);
14470         }
14471         get_date(now_string);
14472         fprintf(thread_Lwqfd,"%-25s %s","Read test start: ",now_string);
14473     }
14474 
14475     if(r_traj_flag)
14476         r_traj_fd=open_r_traj();
14477     if(fetchon)
14478         fetchit(nbuff,reclen);
14479     child_stat=(struct child_stats *)&shmaddr[xx];
14480     child_stat->flag = CHILD_STATE_READY;
14481     if(distributed && client_iozone)
14482         {
14483         tell_master_ready(chid);
14484                 wait_for_master_go(chid);
14485         }
14486         else
14487         {
14488         /* Wait for signal from parent */
14489                 while(child_stat->flag!=CHILD_STATE_BEGIN)   
14490                         Poll((long long)1);
14491         }
14492     if(file_lock)
14493         if(mylockf((int) fd, (int) 1, (int)1) != 0)
14494             printf("File lock for read failed. %d\n",errno);
14495     starttime1 = time_so_far();
14496     if(cpuutilflag)
14497     {
14498         walltime = starttime1;
14499         cputime = cputime_so_far();
14500     }
14501 
14502     if(r_traj_flag)
14503         rewind(r_traj_fd);
14504     for(i=0; i<numrecs64; i++){
14505         traj_offset= i*reclen;
14506         if(disrupt_flag && ((i%DISRUPT)==0))
14507         {
14508 #if defined(Windows)
14509     
14510             if(unbuffered)
14511                disruptw(hand);
14512             else
14513                disrupt(fd);
14514 #else
14515             disrupt(fd);
14516 #endif
14517         }
14518         if(r_traj_flag)
14519         {
14520             traj_offset=get_traj(r_traj_fd, (long long *)&traj_size,(float *)&delay,(long)0);
14521             reclen=traj_size;
14522 #if defined(Windows)
14523             if(unbuffered)
14524               SetFilePointer(hand,(LONG)traj_offset,0,FILE_BEGIN);
14525             else
14526 #endif
14527             I_LSEEK(fd,traj_offset,SEEK_SET);
14528         }
14529         if(Q_flag)
14530         {
14531 #if defined(Windows)
14532             if(unbuffered)
14533               traj_offset=SetFilePointer(hand,0,0,FILE_CURRENT);
14534             else
14535 #endif
14536             traj_offset=I_LSEEK(fd,0,SEEK_CUR);
14537         }
14538         if(rlocking)
14539         {
14540             lock_offset=I_LSEEK(fd,0,SEEK_CUR);
14541             mylockr((int) fd, (int) 1, (int)1,
14542               lock_offset, reclen);
14543         }
14544         if(compute_flag)
14545             compute_val+=do_compute(delay);
14546         if(*stop_flag)
14547         {
14548             if(debug1)
14549                 printf("\n(%ld) Stopped by another 2\n", (long)xx);
14550             break;
14551         }
14552         if(purge)
14553             purgeit(nbuff,reclen);
14554         if(Q_flag || hist_summary || op_rate_flag)
14555                 {
14556                         thread_qtime_start=time_so_far();
14557                 }
14558         if(mmapflag)
14559         {
14560             wmaddr = &maddr[i*reclen];
14561             fill_area((long long*)wmaddr,(long long*)nbuff,(long long)reclen);
14562         }
14563         else
14564         {
14565               if(async_flag)
14566               {
14567                 if(no_copy_flag)
14568                   async_read_no_copy(gc, (long long)fd, &buffer1, (i*reclen), reclen,
14569                     1LL,(numrecs64*reclen),depth);
14570                 else
14571                   async_read(gc, (long long)fd, nbuff, (i*reclen), reclen,
14572                     1LL,(numrecs64*reclen),depth);
14573               }
14574               else
14575               {
14576 #if defined(Windows)
14577                   if(unbuffered)
14578                   {
14579                 ReadFile(hand,nbuff,reclen,(LPDWORD)&wval,0);
14580                   }
14581                   else
14582 #endif
14583                   wval=read((int)fd, (void*)nbuff, (size_t) reclen);
14584                   if(wval != reclen)
14585                   {
14586                 if(*stop_flag)
14587                 {
14588                     if(debug1)
14589                         printf("\n(%ld) Stopped by another 2\n", (long)xx);
14590                     break;
14591                 }
14592 #ifdef NO_PRINT_LLD
14593                     printf("\nError reading block %ld, fd= %d\n", i,
14594                      fd);
14595 #else
14596                     printf("\nError reading block %lld, fd= %d\n", i,
14597                      fd);
14598 #endif
14599                 perror("read");
14600                 if (!no_unlink)
14601                 {
14602                    if(check_filename(dummyfile[xx]))
14603                     unlink(dummyfile[xx]);
14604                 }
14605                 child_stat->flag = CHILD_STATE_HOLD;
14606                     exit(132);
14607                   }
14608               }
14609         }
14610         if(verify){
14611            if(async_flag && no_copy_flag)
14612            {
14613                if(verify_buffer(buffer1,reclen,(off64_t)i,reclen,(long long)pattern,sverify)){
14614                 if (!no_unlink)
14615                 {
14616                    if(check_filename(dummyfile[xx]))
14617                     unlink(dummyfile[xx]);
14618                 }
14619                 child_stat->flag = CHILD_STATE_HOLD;
14620                 exit(133);
14621                }
14622            }
14623            else
14624            {
14625                if(verify_buffer(nbuff,reclen,(off64_t)i,reclen,(long long)pattern,sverify)){
14626                 if (!no_unlink)
14627                 {
14628                    if(check_filename(dummyfile[xx]))
14629                     unlink(dummyfile[xx]);
14630                 }
14631                 child_stat->flag = CHILD_STATE_HOLD;
14632                 exit(134);
14633                }
14634            }
14635         }
14636         if(async_flag && no_copy_flag)
14637             async_release(gc);
14638         read_so_far+=reclen/1024;
14639         r_traj_bytes_completed+=reclen;
14640         r_traj_ops_completed++;
14641         if(*stop_flag)
14642         {
14643             read_so_far-=reclen/1024;
14644             r_traj_bytes_completed-=reclen;
14645         }
14646         if(hist_summary)
14647         {
14648             thread_qtime_stop=time_so_far();
14649             hist_time =(thread_qtime_stop-thread_qtime_start-time_res);
14650             hist_insert(hist_time);
14651         }
14652         if(op_rate_flag)
14653         {
14654             thread_qtime_stop=time_so_far();
14655             desired_op_rate_time = ((double)1.0/(double)op_rate);
14656             actual_rate = (double)(thread_qtime_stop-thread_qtime_start);
14657 /*
14658 printf("Desired rate %g  Actual rate %g Nap %g microseconds\n",desired_op_rate_time,
14659     actual_rate, (desired_op_rate_time-actual_rate));
14660 */
14661             if( actual_rate < desired_op_rate_time)
14662                 my_unap((unsigned long long) ((desired_op_rate_time-actual_rate)*1000000.0 ));
14663         }
14664                 if(Q_flag)
14665                 {
14666                         thread_qtime_stop=time_so_far();
14667 #ifdef NO_PRINT_LLD
14668                         fprintf(thread_rqfd,"%10.1ld %10.0f %10.1ld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
14669 #else
14670                         fprintf(thread_rqfd,"%10.1lld %10.0f %10.1lld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
14671 #endif
14672                 }
14673 
14674         if(rlocking)
14675         {
14676             mylockr((int) fd, (int) 0, (int)1,
14677               lock_offset, reclen);
14678         }
14679     }
14680     if(file_lock)
14681         if(mylockf((int) fd, (int) 0, (int)1))
14682             printf("Read unlock failed. %d\n",errno);
14683 #ifdef ASYNC_IO
14684     if(async_flag)
14685     {
14686         end_async(gc);
14687         gc=0;
14688     }
14689 #endif
14690     if(include_flush)
14691     {
14692         if(mmapflag)
14693         {
14694             msync(maddr,(size_t)(filebytes64),MS_SYNC);
14695         }else
14696             fsync(fd);
14697     }
14698     if(include_close)
14699     {   
14700         if(mmapflag)
14701         {
14702             mmap_end(maddr,(unsigned long long)filebytes64);
14703         }
14704 #if defined(Windows)
14705         if(unbuffered)
14706           CloseHandle(hand);
14707         else
14708 #endif
14709         close(fd);
14710     }
14711     temp_time = time_so_far();
14712     child_stat=(struct child_stats *)&shmaddr[xx];
14713     child_stat->throughput = ((temp_time - starttime1)-time_res)
14714         -compute_val;
14715     if(child_stat->throughput < (double).000001) 
14716     {
14717         child_stat->throughput= time_res;
14718         if(rec_prob < reclen)
14719             rec_prob = reclen;
14720         res_prob=1;
14721     }
14722 
14723     if(OPS_flag){
14724        /*read_so_far=(read_so_far*1024)/reclen;*/
14725        read_so_far=r_traj_ops_completed;
14726     }
14727     child_stat->throughput = read_so_far/child_stat->throughput;
14728     child_stat->actual = read_so_far;
14729     if(!xflag)
14730     {
14731         *stop_flag=1;
14732         if(distributed && client_iozone)
14733             send_stop();
14734     }
14735         if(cdebug)
14736     {
14737                 fprintf(newstdout,"Child %d: throughput %f actual %f \n",(int)chid,child_stat->throughput,
14738                         child_stat->actual);
14739         fflush(newstdout);
14740     }
14741     if(cpuutilflag)
14742     {
14743         cputime = cputime_so_far() - cputime;
14744         if (cputime < cputime_res)
14745             cputime = 0.0;
14746         child_stat->cputime = cputime;
14747         walltime = time_so_far() - walltime;
14748         child_stat->walltime = walltime;
14749     }
14750         if(distributed && client_iozone)
14751                 tell_master_stats(THREAD_READ_TEST, chid, child_stat->throughput,
14752                         child_stat->actual, 
14753             child_stat->cputime, child_stat->walltime,
14754             (char)*stop_flag,
14755                         (long long)CHILD_STATE_HOLD);
14756     child_stat->flag = CHILD_STATE_HOLD;    /* Tell parent I'm done */
14757     /*fsync(fd);*/
14758     if(!include_close)
14759     {
14760         if(mmapflag)
14761         {
14762             msync(maddr,(size_t)(filebytes64),MS_SYNC);
14763             mmap_end(maddr,(unsigned long long)filebytes64);
14764         }else
14765             fsync(fd);
14766 #if defined(Windows)
14767         if(unbuffered)
14768           CloseHandle(hand);
14769         else
14770 #endif
14771         close(fd);
14772     }
14773         if(Q_flag && (thread_rqfd !=0) )
14774                 fclose(thread_rqfd);
14775     free(dummyfile[xx]);
14776     if(r_traj_flag)
14777         fclose(r_traj_fd);
14778     if(debug1)
14779 #ifdef NO_PRINT_LLD
14780         printf("\nChild finished %ld\n",xx);
14781 #else
14782         printf("\nChild finished %lld\n",xx);
14783 #endif
14784 
14785     if(L_flag)
14786     {
14787         get_date(now_string);
14788         fprintf(thread_Lwqfd,"%-25s %s","Read test finished: ",now_string);
14789         fclose(thread_Lwqfd);
14790     }
14791     if(hist_summary)
14792        dump_hist("Read",(int)xx);
14793     if(distributed && client_iozone)
14794         return(0);
14795 #ifdef NO_THREADS
14796     exit(0);
14797 #else
14798     if(use_thread)
14799         thread_exit();
14800     else
14801         exit(0);
14802 #endif
14803 return(0);
14804 }
14805 
14806 #ifdef HAVE_PREAD
14807 /************************************************************************/
14808 /* Thread pread test                                */
14809 /************************************************************************/
14810 #ifdef HAVE_ANSIC_C
14811 void *
14812 thread_pread_test(void *x)
14813 #else
14814 void *
14815 thread_pread_test(x)
14816 #endif
14817 {
14818     long long xx,xx2;
14819     struct child_stats *child_stat;
14820     double walltime, cputime;
14821     long long r_traj_bytes_completed;
14822     long long r_traj_ops_completed;
14823     int fd;
14824     FILE *r_traj_fd,*thread_rqfd;
14825     FILE *thread_Lwqfd;
14826     long long flags = 0;
14827     off64_t traj_offset;
14828     off64_t lock_offset=0;
14829     double starttime1 = 0;
14830     float delay = 0;
14831     double temp_time;
14832     double thread_qtime_start,thread_qtime_stop;
14833     double hist_time;
14834     double desired_op_rate_time;
14835     double actual_rate;
14836     double compute_val = (double)0;
14837     off64_t written_so_far, read_so_far, re_written_so_far,re_read_so_far;
14838     long long recs_per_buffer,traj_size;
14839     off64_t i;
14840     char *dummyfile[MAXSTREAMS];           /* name of dummy file     */
14841     char *nbuff=0;
14842     char *maddr=0;
14843     char *wmaddr=0;
14844     char tmpname[256];
14845     char now_string[30];
14846     volatile char *buffer1;
14847     int anwser,bind_cpu;
14848 #if defined(VXFS) || defined(solaris)
14849     int test_foo = 0;
14850 #endif
14851 #ifdef ASYNC_IO
14852     struct cache *gc=0;
14853 #else
14854     long long *gc=0;
14855 #endif
14856 
14857     if(compute_flag)
14858         delay=compute_time;
14859     thread_rqfd=thread_Lwqfd=r_traj_fd=(FILE *)0;
14860     hist_time=traj_offset=thread_qtime_stop=thread_qtime_start=0;
14861     walltime=cputime=0;
14862     anwser=bind_cpu=0;
14863     r_traj_bytes_completed=r_traj_ops_completed=0;
14864     written_so_far=read_so_far=re_written_so_far=re_read_so_far=0;
14865     recs_per_buffer = cache_size/reclen ;
14866     if(r_traj_flag)
14867     {
14868         filebytes64 = r_traj_fsize;
14869         numrecs64=r_traj_ops;
14870     }
14871     else
14872     {
14873         filebytes64 = numrecs64*reclen;
14874     }
14875     
14876 #ifdef NO_THREADS
14877     xx=chid;
14878 #else
14879     if(use_thread)
14880         xx = (long long)((long)x);
14881     else
14882     {
14883         xx=chid;
14884     }
14885 #endif
14886 #ifndef NO_THREADS
14887 #ifdef _HPUX_SOURCE
14888     if(ioz_processor_bind)
14889     {
14890          bind_cpu=(begin_proc+(int)xx)%num_processors;
14891          pthread_processor_bind_np(PTHREAD_BIND_FORCED_NP,
14892                          (pthread_spu_t *)&anwser, (pthread_spu_t)bind_cpu, pthread_self());
14893         my_nap(40); /* Switch to new cpu */
14894     }
14895 #endif
14896 #endif
14897     if(use_thread)
14898         nbuff=barray[xx];
14899     else
14900         nbuff=buffer;
14901     dummyfile[xx]=(char *)malloc((size_t)MAXNAMESIZE);
14902     xx2=xx;
14903     if(share_file)
14904         xx2=(long long)0;
14905     if(mfflag)
14906     {
14907 #ifdef NO_PRINT_LLD
14908         sprintf(dummyfile[xx],"%s",filearray[xx2]);
14909 #else
14910         sprintf(dummyfile[xx],"%s",filearray[xx2]);
14911 #endif
14912     }
14913     else
14914     {
14915 #ifdef NO_PRINT_LLD
14916         sprintf(dummyfile[xx],"%s.DUMMY.%ld",filearray[xx2],xx2);
14917 #else
14918         sprintf(dummyfile[xx],"%s.DUMMY.%lld",filearray[xx2],xx2);
14919 #endif
14920     }
14921     if(oflag)
14922         flags=O_RDONLY|O_SYNC;
14923     else
14924         flags=O_RDONLY;
14925 #if defined(_HPUX_SOURCE) || defined(linux)
14926     if(read_sync)
14927         flags |=O_RSYNC|O_SYNC;
14928 #endif
14929 
14930 #if ! defined(DONT_HAVE_O_DIRECT)
14931 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
14932     if(direct_flag)
14933         flags |=O_DIRECT;
14934 #endif
14935 #if defined(TRU64)
14936     if(direct_flag)
14937         flags |=O_DIRECTIO;
14938 #endif
14939 #endif
14940     if((fd = I_OPEN(dummyfile[xx], (int)flags,0))<0)
14941     {
14942         client_error=errno;
14943         if(distributed && client_iozone)
14944             send_stop();
14945         perror(dummyfile[xx]);
14946         exit(130);
14947     }
14948 #ifdef ASYNC_IO
14949     if(async_flag)
14950         async_init(&gc,fd,direct_flag);
14951 #endif
14952 #ifdef VXFS
14953     if(direct_flag)
14954     {
14955         ioctl(fd,VX_SETCACHE,VX_DIRECT);
14956         ioctl(fd,VX_GETCACHE,&test_foo);
14957         if(test_foo == 0)
14958         {
14959             if(!client_iozone)
14960               printf("\nVxFS advanced setcache feature not available.\n");
14961             exit(3);
14962         }
14963     }
14964 #endif
14965 #if defined(solaris)
14966         if(direct_flag)
14967         {
14968                 test_foo = directio(fd, DIRECTIO_ON);
14969                 if(test_foo != 0)
14970                 {
14971                         if(!client_iozone)
14972                           printf("\ndirectio not available.\n");
14973                         exit(3);
14974                 }
14975         }
14976 #endif
14977     if(mmapflag)
14978     {
14979         maddr=(char *)initfile(fd,(numrecs64*reclen),0,PROT_READ);
14980     }
14981     child_stat = (struct child_stats *)&shmaddr[xx];
14982     child_stat->throughput = 0;
14983     child_stat->actual = 0;
14984     if(debug1)
14985     {
14986        if(use_thread)
14987 #ifdef NO_PRINT_LLD
14988         printf("\nStarting child %ld\n",xx);
14989 #else
14990         printf("\nStarting child %lld\n",xx);
14991 #endif
14992        else
14993 #ifdef NO_PRINT_LLD
14994         printf("\nStarting process %d slot %ld\n",getpid(),xx);
14995 #else
14996         printf("\nStarting process %d slot %lld\n",getpid(),xx);
14997 #endif
14998         
14999     }
15000     /*****************/
15001     /* Children only */
15002     /*****************/
15003     if(Q_flag)
15004     {
15005         sprintf(tmpname,"Child_%d_prol.dat",(int)xx);
15006         thread_rqfd=fopen(tmpname,"a");
15007         if(thread_rqfd==0)
15008         {
15009             client_error=errno;
15010             if(distributed && client_iozone)
15011                 send_stop();
15012             printf("Unable to open %s\n",tmpname);
15013             exit(40);
15014         }
15015         fprintf(thread_rqfd,"Offset in Kbytes   Latency in microseconds  Transfer size in bytes\n");
15016     }
15017     if(L_flag)
15018     {
15019         sprintf(tmpname,"Child_%d.log",(int)xx);
15020         thread_Lwqfd=fopen(tmpname,"a");
15021         if(thread_Lwqfd==0)
15022         {
15023             client_error=errno;
15024             if(distributed && client_iozone)
15025                 send_stop();
15026             printf("Unable to open %s\n",tmpname);
15027             exit(40);
15028         }
15029         get_date(now_string);
15030         fprintf(thread_Lwqfd,"%-25s %s","Pread test start: ",now_string);
15031     }
15032 
15033     if(r_traj_flag)
15034         r_traj_fd=open_r_traj();
15035     if(fetchon)
15036         fetchit(nbuff,reclen);
15037     child_stat=(struct child_stats *)&shmaddr[xx];
15038     child_stat->flag = CHILD_STATE_READY;
15039     if(distributed && client_iozone)
15040         {
15041         tell_master_ready(chid);
15042                 wait_for_master_go(chid);
15043         }
15044         else
15045         {
15046         /* Wait for signal from parent */
15047                 while(child_stat->flag!=CHILD_STATE_BEGIN)   
15048                         Poll((long long)1);
15049         }
15050     if(file_lock)
15051         if(mylockf((int) fd, (int) 1, (int)1) != 0)
15052             printf("File lock for read failed. %d\n",errno);
15053     starttime1 = time_so_far();
15054     if(cpuutilflag)
15055     {
15056         walltime = starttime1;
15057         cputime = cputime_so_far();
15058     }
15059 
15060     if(r_traj_flag)
15061         rewind(r_traj_fd);
15062     for(i=0; i<numrecs64; i++){
15063         traj_offset = i*reclen;
15064         if(disrupt_flag && ((i%DISRUPT)==0))
15065         {
15066             disrupt(fd);
15067         }
15068         if(r_traj_flag)
15069         {
15070             traj_offset=get_traj(r_traj_fd, (long long *)&traj_size,(float *)&delay,(long)0);
15071             reclen=traj_size;
15072             I_LSEEK(fd,traj_offset,SEEK_SET);
15073         }
15074         if(Q_flag)
15075         {
15076             traj_offset=I_LSEEK(fd,0,SEEK_CUR);
15077         }
15078         if(rlocking)
15079         {
15080             lock_offset=I_LSEEK(fd,0,SEEK_CUR);
15081             mylockr((int) fd, (int) 1, (int)0,
15082               lock_offset, reclen);
15083         }
15084         if(compute_flag)
15085             compute_val+=do_compute(delay);
15086         if(*stop_flag)
15087         {
15088             if(debug1)
15089                 printf("\n(%ld) Stopped by another 2\n", (long)xx);
15090             break;
15091         }
15092         if(purge)
15093             purgeit(nbuff,reclen);
15094         if(Q_flag || hist_summary || op_rate_flag)
15095                 {
15096                         thread_qtime_start=time_so_far();
15097                 }
15098         if(mmapflag)
15099         {
15100             wmaddr = &maddr[traj_offset];
15101             fill_area((long long*)wmaddr,(long long*)nbuff,(long long)reclen);
15102         }
15103         else
15104         {
15105               if(async_flag)
15106               {
15107                 if(no_copy_flag)
15108                   async_read_no_copy(gc, (long long)fd, &buffer1, (i*reclen), reclen,
15109                     1LL,(numrecs64*reclen),depth);
15110                 else
15111                   async_read(gc, (long long)fd, nbuff, (traj_offset), reclen,
15112                     1LL,(numrecs64*reclen),depth);
15113               }
15114               else
15115               {
15116                 if(I_PREAD((int)fd, (void*)nbuff, (size_t) reclen,(traj_offset) ) != reclen)
15117                   {
15118                 if(*stop_flag)
15119                 {
15120                     if(debug1)
15121                         printf("\n(%ld) Stopped by another 2\n", (long)xx);
15122                     break;
15123                 }
15124 #ifdef NO_PRINT_LLD
15125                     printf("\nError preading block %ld, fd= %d\n", i,
15126                      fd);
15127 #else
15128                     printf("\nError preading block %lld, fd= %d\n", i,
15129                      fd);
15130 #endif
15131                 perror("pread");
15132                 if (!no_unlink)
15133                 {
15134                    if(check_filename(dummyfile[xx]))
15135                     unlink(dummyfile[xx]);
15136                 }
15137                 child_stat->flag = CHILD_STATE_HOLD;
15138                     exit(132);
15139                   }
15140               }
15141         }
15142         if(verify){
15143            if(async_flag && no_copy_flag)
15144            {
15145                if(verify_buffer(buffer1,reclen,(off64_t)i,reclen,(long long)pattern,sverify)){
15146                 if (!no_unlink)
15147                 {
15148                    if(check_filename(dummyfile[xx]))
15149                     unlink(dummyfile[xx]);
15150                 }
15151                 child_stat->flag = CHILD_STATE_HOLD;
15152                 exit(133);
15153                }
15154            }
15155            else
15156            {
15157                if(verify_buffer(nbuff,reclen,(off64_t)i,reclen,(long long)pattern,sverify)){
15158                 if (!no_unlink)
15159                 {
15160                    if(check_filename(dummyfile[xx]))
15161                     unlink(dummyfile[xx]);
15162                 }
15163                 child_stat->flag = CHILD_STATE_HOLD;
15164                 exit(134);
15165                }
15166            }
15167         }
15168         if(async_flag && no_copy_flag)
15169             async_release(gc);
15170         read_so_far+=reclen/1024;
15171         r_traj_bytes_completed+=reclen;
15172         r_traj_ops_completed++;
15173         if(*stop_flag)
15174         {
15175             read_so_far-=reclen/1024;
15176             r_traj_bytes_completed-=reclen;
15177         }
15178         if(hist_summary)
15179         {
15180             thread_qtime_stop=time_so_far();
15181             hist_time =(thread_qtime_stop-thread_qtime_start-time_res);
15182             hist_insert(hist_time);
15183         }
15184         if(op_rate_flag)
15185         {
15186             thread_qtime_stop=time_so_far();
15187             desired_op_rate_time = ((double)1.0/(double)op_rate);
15188             actual_rate = (double)(thread_qtime_stop-thread_qtime_start);
15189 /*
15190 printf("Desired rate %g  Actual rate %g Nap %g microseconds\n",desired_op_rate_time,
15191     actual_rate, (desired_op_rate_time-actual_rate));
15192 */
15193             if( actual_rate < desired_op_rate_time)
15194                 my_unap((unsigned long long) ((desired_op_rate_time-actual_rate)*1000000.0 ));
15195         }
15196                 if(Q_flag)
15197                 {
15198                         thread_qtime_stop=time_so_far();
15199 #ifdef NO_PRINT_LLD
15200                         fprintf(thread_rqfd,"%10.1ld %10.0f %10.1ld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
15201 #else
15202                         fprintf(thread_rqfd,"%10.1lld %10.0f %10.1lld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
15203 #endif
15204                 }
15205 
15206         if(rlocking)
15207         {
15208             mylockr((int) fd, (int) 0, (int)1,
15209               lock_offset, reclen);
15210         }
15211     }
15212     if(file_lock)
15213         if(mylockf((int) fd, (int) 0, (int)1))
15214             printf("Read unlock failed. %d\n",errno);
15215 #ifdef ASYNC_IO
15216     if(async_flag)
15217     {
15218         end_async(gc);
15219         gc=0;
15220     }
15221 #endif
15222     if(include_flush)
15223     {
15224         if(mmapflag)
15225         {
15226             msync(maddr,(size_t)(filebytes64),MS_SYNC);
15227         }else
15228             fsync(fd);
15229     }
15230     if(include_close)
15231     {   
15232         if(mmapflag)
15233         {
15234             mmap_end(maddr,(unsigned long long)filebytes64);
15235         }
15236         close(fd);
15237     }
15238     temp_time = time_so_far();
15239     child_stat=(struct child_stats *)&shmaddr[xx];
15240     child_stat->throughput = ((temp_time - starttime1)-time_res)
15241         -compute_val;
15242     if(child_stat->throughput < (double).000001) 
15243     {
15244         child_stat->throughput= time_res;
15245         if(rec_prob < reclen)
15246             rec_prob = reclen;
15247         res_prob=1;
15248     }
15249 
15250     if(OPS_flag){
15251        /*read_so_far=(read_so_far*1024)/reclen;*/
15252        read_so_far=r_traj_ops_completed;
15253     }
15254     child_stat->throughput = read_so_far/child_stat->throughput;
15255     child_stat->actual = read_so_far;
15256     if(!xflag)
15257     {
15258         *stop_flag=1;
15259         if(distributed && client_iozone)
15260             send_stop();
15261     }
15262         if(cdebug)
15263     {
15264                 fprintf(newstdout,"Child %d: throughput %f actual %f \n",(int)chid,child_stat->throughput,
15265                         child_stat->actual);
15266         fflush(newstdout);
15267     }
15268     if(cpuutilflag)
15269     {
15270         cputime = cputime_so_far() - cputime;
15271         if (cputime < cputime_res)
15272             cputime = 0.0;
15273         child_stat->cputime = cputime;
15274         walltime = time_so_far() - walltime;
15275         child_stat->walltime = walltime;
15276     }
15277         if(distributed && client_iozone)
15278                 tell_master_stats(THREAD_READ_TEST, chid, child_stat->throughput,
15279                         child_stat->actual,
15280             child_stat->cputime, child_stat->walltime,
15281             (char)*stop_flag,
15282                         (long long)CHILD_STATE_HOLD);
15283     child_stat->flag = CHILD_STATE_HOLD;    /* Tell parent I'm done */
15284     /*fsync(fd);*/
15285     if(!include_close)
15286     {
15287         if(mmapflag)
15288         {
15289             msync(maddr,(size_t)(filebytes64),MS_SYNC);
15290             mmap_end(maddr,(unsigned long long)filebytes64);
15291         }else
15292             fsync(fd);
15293         close(fd);
15294     }
15295         if(Q_flag && (thread_rqfd !=0) )
15296                 fclose(thread_rqfd);
15297     free(dummyfile[xx]);
15298     if(r_traj_flag)
15299         fclose(r_traj_fd);
15300     if(debug1)
15301 #ifdef NO_PRINT_LLD
15302         printf("\nChild finished %ld\n",xx);
15303 #else
15304         printf("\nChild finished %lld\n",xx);
15305 #endif
15306 
15307     if(L_flag)
15308     {
15309         get_date(now_string);
15310         fprintf(thread_Lwqfd,"%-25s %s","Pread test finished: ",
15311             now_string);
15312         fclose(thread_Lwqfd);
15313     }
15314     if(hist_summary)
15315        dump_hist("Pread",(int)xx);
15316     if(distributed && client_iozone)
15317         return(0);
15318 #ifdef NO_THREADS
15319     exit(0);
15320 #else
15321     if(use_thread)
15322         thread_exit();
15323     else
15324         exit(0);
15325 #endif
15326 return(0);
15327 }
15328 #endif
15329 
15330 /************************************************************************/
15331 /* Thread re-read test                              */
15332 /************************************************************************/
15333 #ifdef HAVE_ANSIC_C
15334 void *
15335 thread_rread_test(void *x)
15336 #else
15337 void *
15338 thread_rread_test(x)
15339 #endif
15340 {
15341     long long xx,xx2;
15342     char *nbuff;
15343     struct child_stats *child_stat;
15344     int fd;
15345     FILE *r_traj_fd,*thread_rrqfd;
15346     FILE *thread_Lwqfd;
15347     long long r_traj_bytes_completed;
15348     double walltime, cputime;
15349     long long r_traj_ops_completed;
15350     off64_t traj_offset;
15351     off64_t lock_offset=0;
15352     long long flags = 0;
15353     double starttime1 = 0;
15354     float delay = 0;
15355     double temp_time;
15356     double thread_qtime_start,thread_qtime_stop;
15357     double hist_time;
15358     double desired_op_rate_time;
15359     double actual_rate;
15360     double compute_val = (double)0;
15361     long long recs_per_buffer,traj_size;
15362     off64_t i;
15363     off64_t written_so_far, read_so_far, re_written_so_far,
15364         re_read_so_far;
15365     char *dummyfile[MAXSTREAMS];           /* name of dummy file     */
15366     char *maddr=0;
15367     char *wmaddr=0;
15368     char now_string[30];
15369     volatile char *buffer1;
15370     int anwser,bind_cpu;
15371     long wval;
15372     char tmpname[256];
15373 #if defined(VXFS) || defined(solaris)
15374     int test_foo = 0;
15375 #endif
15376 #ifdef ASYNC_IO
15377     struct cache *gc=0;
15378 #else
15379     long long *gc=0;
15380 #endif
15381     /*****************/
15382     /* Children only */
15383     /*****************/
15384     if(compute_flag)
15385         delay=compute_time;
15386     hist_time=thread_qtime_stop=thread_qtime_start=0;
15387     thread_rrqfd=r_traj_fd=thread_Lwqfd=(FILE *)0;
15388     traj_offset=walltime=cputime=0;
15389     anwser=bind_cpu=0;
15390     r_traj_bytes_completed=r_traj_ops_completed=0;
15391     written_so_far=read_so_far=re_written_so_far=re_read_so_far=0;
15392     recs_per_buffer = cache_size/reclen ;
15393 #ifdef NO_THREADS
15394     xx=chid;
15395 #else
15396     if(r_traj_flag)
15397     {
15398         filebytes64 = r_traj_fsize;
15399         numrecs64=r_traj_ops;
15400     }
15401     else
15402     {
15403         filebytes64 = numrecs64*reclen;
15404     }
15405     if(use_thread)
15406         xx = (long long)((long)x);
15407     else
15408     {
15409         xx=chid;
15410     }
15411 #endif
15412 #ifndef NO_THREADS
15413 #if defined( _HPUX_SOURCE ) || defined ( linux )
15414     if(ioz_processor_bind)
15415     {
15416          bind_cpu=(begin_proc+(int)xx)%num_processors;
15417 #if defined(_HPUX_SOURCE)
15418          pthread_processor_bind_np(PTHREAD_BIND_FORCED_NP,
15419                          (pthread_spu_t *)&anwser, (pthread_spu_t)bind_cpu, pthread_self());
15420 #else
15421      cpu_set_t cpuset;
15422 
15423      CPU_ZERO(&cpuset);
15424      CPU_SET(bind_cpu, &cpuset);
15425 
15426      pthread_setaffinity_np(pthread_self(), sizeof(cpuset),&cpuset);
15427 #endif
15428         my_nap(40); /* Switch to new cpu */
15429     }
15430 #endif
15431 #endif
15432     if(use_thread)
15433         nbuff=barray[xx];
15434     else
15435         nbuff=buffer;
15436     if(debug1)
15437     {
15438        if(use_thread)
15439 #ifdef NO_PRINT_LLD
15440         printf("\nStarting child %ld\n",xx);
15441 #else
15442         printf("\nStarting child %lld\n",xx);
15443 #endif
15444        else
15445 #ifdef NO_PRINT_LLD
15446         printf("\nStarting process %d slot %ld\n",getpid(),xx);
15447 #else
15448         printf("\nStarting process %d slot %lld\n",getpid(),xx);
15449 #endif
15450         
15451     }
15452     dummyfile[xx]=(char *)malloc((size_t)MAXNAMESIZE);
15453     xx2=xx;
15454     if(share_file)
15455         xx2=(long long)0;
15456     if(mfflag)
15457     {
15458 #ifdef NO_PRINT_LLD
15459         sprintf(dummyfile[xx],"%s",filearray[xx2]);
15460 #else
15461         sprintf(dummyfile[xx],"%s",filearray[xx2]);
15462 #endif
15463     }
15464     else
15465     {
15466 #ifdef NO_PRINT_LLD
15467         sprintf(dummyfile[xx],"%s.DUMMY.%ld",filearray[xx2],xx2);
15468 #else
15469         sprintf(dummyfile[xx],"%s.DUMMY.%lld",filearray[xx2],xx2);
15470 #endif
15471     }
15472     if(oflag)
15473         flags=O_RDONLY|O_SYNC;
15474     else
15475         flags=O_RDONLY;
15476 #if defined(_HPUX_SOURCE) || defined(linux)
15477     if(read_sync)
15478         flags |=O_RSYNC|O_SYNC;
15479 #endif
15480 
15481 #if ! defined(DONT_HAVE_O_DIRECT)
15482 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
15483     if(direct_flag)
15484         flags |=O_DIRECT;
15485 #endif
15486 #if defined(TRU64)
15487     if(direct_flag)
15488         flags |=O_DIRECTIO;
15489 #endif
15490 #endif
15491 
15492 #if defined(Windows)
15493         if(unbuffered)
15494         {
15495             hand=CreateFile(dummyfile[xx],
15496           GENERIC_READ|GENERIC_WRITE,
15497               FILE_SHARE_WRITE|FILE_SHARE_READ,
15498           NULL,OPEN_EXISTING,FILE_FLAG_NO_BUFFERING|
15499           FILE_FLAG_WRITE_THROUGH|FILE_FLAG_POSIX_SEMANTICS,
15500           NULL);
15501         SetFilePointer(hand,(LONG)0,0,FILE_BEGIN);
15502         }
15503     else
15504     {
15505 #endif
15506     if((fd = I_OPEN(dummyfile[xx], ((int)flags),0))<0)
15507     {
15508         client_error=errno;
15509         if(distributed && client_iozone)
15510             send_stop();
15511         perror(dummyfile[xx]);
15512         exit(135);
15513     }
15514 #if defined(Windows)
15515     }
15516 #endif
15517 #ifdef ASYNC_IO
15518     if(async_flag)
15519         async_init(&gc,fd,direct_flag);
15520 #endif
15521 #ifdef VXFS
15522     if(direct_flag)
15523     {
15524         ioctl(fd,VX_SETCACHE,VX_DIRECT);
15525         ioctl(fd,VX_GETCACHE,&test_foo);
15526         if(test_foo == 0)
15527         {
15528             if(!client_iozone)
15529               printf("\nVxFS advanced setcache feature not available.\n");
15530             exit(3);
15531         }
15532     }
15533 #endif
15534 #if defined(solaris)
15535         if(direct_flag)
15536         {
15537                 test_foo = directio(fd, DIRECTIO_ON);
15538                 if(test_foo != 0)
15539                 {
15540                         if(!client_iozone)
15541                           printf("\ndirectio not available.\n");
15542                         exit(3);
15543                 }
15544         }
15545 #endif
15546     if(mmapflag)
15547     {
15548         maddr=(char *)initfile(fd,(filebytes64),0,PROT_READ);
15549     }
15550     if(r_traj_flag)
15551         r_traj_fd=open_r_traj();
15552     if(fetchon)
15553         fetchit(nbuff,reclen);
15554         if(Q_flag)
15555         {
15556                 sprintf(tmpname,"Child_%d_rrol.dat",(int)xx);
15557                 thread_rrqfd=fopen(tmpname,"a");
15558                 if(thread_rrqfd==0)
15559                 {
15560             client_error=errno;
15561             if(distributed && client_iozone)
15562                 send_stop();
15563                         printf("Unable to open %s\n",tmpname);
15564                         exit(40);
15565                 }
15566         fprintf(thread_rrqfd,"Offset in Kbytes   Latency in microseconds  Transfer size in bytes\n");
15567         }
15568     if(L_flag)
15569     {
15570         sprintf(tmpname,"Child_%d.log",(int)xx);
15571         thread_Lwqfd=fopen(tmpname,"a");
15572         if(thread_Lwqfd==0)
15573         {
15574             client_error=errno;
15575             if(distributed && client_iozone)
15576                 send_stop();
15577             printf("Unable to open %s\n",tmpname);
15578             exit(40);
15579         }
15580         get_date(now_string);
15581         fprintf(thread_Lwqfd,"%-25s %s","Reread test start: ",now_string);
15582     }
15583 
15584     child_stat = (struct child_stats *)&shmaddr[xx];
15585     child_stat->throughput = 0;
15586     child_stat->actual = 0;
15587     child_stat->flag = CHILD_STATE_READY;
15588 
15589     if(distributed && client_iozone)
15590     {
15591         tell_master_ready(chid);
15592         wait_for_master_go(chid);
15593     }
15594     else
15595     
15596         /* Wait for signal from parent */
15597                 while(child_stat->flag!=CHILD_STATE_BEGIN)   
15598                         Poll((long long)1);
15599     if(file_lock)
15600         if(mylockf((int) fd, (int) 1, (int)1) != 0)
15601             printf("File lock for read failed. %d\n",errno);
15602     starttime1 = time_so_far();
15603     if(cpuutilflag)
15604     {
15605         walltime = starttime1;
15606         cputime = cputime_so_far();
15607     }
15608 
15609     if(r_traj_flag)
15610         rewind(r_traj_fd);
15611     for(i=0; i<numrecs64; i++){
15612         traj_offset=i*reclen;
15613         if(disrupt_flag && ((i%DISRUPT)==0))
15614         {
15615 #if defined(Windows)
15616     
15617             if(unbuffered)
15618                disruptw(hand);
15619             else
15620                disrupt(fd);
15621 #else
15622             disrupt(fd);
15623 #endif
15624         }
15625         if(r_traj_flag)
15626         {
15627             traj_offset=get_traj(r_traj_fd, (long long *)&traj_size,(float *)&delay,(long)0);
15628             reclen=traj_size;
15629 #if defined(Windows)
15630             if(unbuffered)
15631               SetFilePointer(hand,(LONG)traj_offset,0,FILE_BEGIN);
15632             else
15633 #endif
15634             I_LSEEK(fd,traj_offset,SEEK_SET);
15635         }
15636         if(Q_flag)
15637         {
15638 #if defined(Windows)
15639             if(unbuffered)
15640               traj_offset=SetFilePointer(hand,(LONG)0,0,FILE_CURRENT);
15641             else
15642 #endif
15643             traj_offset=I_LSEEK(fd,0,SEEK_CUR);
15644         }
15645         if(rlocking)
15646         {
15647             lock_offset=I_LSEEK(fd,0,SEEK_CUR);
15648             mylockr((int) fd, (int) 1, (int)1,
15649               lock_offset, reclen);
15650         }
15651         if(compute_flag)
15652             compute_val+=do_compute(delay);
15653         if(*stop_flag)
15654         {
15655             if(debug1)
15656                 printf("\n(%ld) Stopped by another 3\n", (long)xx);
15657             break;
15658         }
15659         if(purge)
15660             purgeit(nbuff,reclen);
15661                 if(Q_flag || hist_summary || op_rate_flag)
15662                 {
15663                         thread_qtime_start=time_so_far();
15664                 }
15665         if(mmapflag)
15666         {
15667             wmaddr = &maddr[i*reclen];
15668             fill_area((long long*)wmaddr,(long long*)nbuff,(long long)reclen);
15669         }
15670         else
15671         {
15672               if(async_flag)
15673               {
15674                 if(no_copy_flag)
15675                   async_read_no_copy(gc, (long long)fd, &buffer1, (i*reclen),reclen,
15676                     1LL,(filebytes64),depth);
15677                 else
15678                   async_read(gc, (long long)fd, nbuff, (i*reclen),reclen,
15679                     1LL,(filebytes64),depth);
15680               }
15681               else
15682               {
15683 #if defined(Windows)
15684                   if(unbuffered)
15685                   {
15686                 ReadFile(hand,nbuff,reclen,(LPDWORD)&wval,0);
15687                   }
15688                   else
15689 #endif
15690                   wval=read((int)fd, (void*)nbuff, (size_t) reclen);
15691                   if(wval != reclen)
15692                   {
15693                 if(*stop_flag)
15694                 {
15695                     if(debug1)
15696                         printf("\n(%ld) Stopped by another 4\n", (long)xx);
15697                     break;
15698                 }
15699 #ifdef NO_PRINT_LLD
15700                     printf("\nError writing block %ld, fd= %d\n", i,
15701                      fd);
15702 #else
15703                     printf("\nError writing block %lld, fd= %d\n", i,
15704                      fd);
15705 #endif
15706                 perror("read");
15707                 if (!no_unlink)
15708                 {
15709                    if(check_filename(dummyfile[xx]))
15710                     unlink(dummyfile[xx]);
15711                 }
15712                 child_stat->flag = CHILD_STATE_HOLD;
15713                     exit(137);
15714                   }
15715                }
15716         }
15717         if(verify){
15718            if(async_flag && no_copy_flag)
15719            {
15720             if(verify_buffer(buffer1,reclen,(off64_t)i,reclen,(long long)pattern,sverify)){
15721                 if (!no_unlink)
15722                 {
15723                    if(check_filename(dummyfile[xx]))
15724                     unlink(dummyfile[xx]);
15725                 }
15726                 child_stat->flag = CHILD_STATE_HOLD;
15727                 exit(138);
15728             }
15729            }
15730            else
15731            {
15732             if(verify_buffer(nbuff,reclen,(off64_t)i,reclen,(long long)pattern,sverify)){
15733                 if (!no_unlink)
15734                 {
15735                    if(check_filename(dummyfile[xx]))
15736                     unlink(dummyfile[xx]);
15737                 }
15738                 child_stat->flag = CHILD_STATE_HOLD;
15739                 exit(139);
15740             }
15741            }
15742         }
15743         if(async_flag && no_copy_flag)
15744             async_release(gc);
15745         re_read_so_far+=reclen/1024;
15746         r_traj_bytes_completed+=reclen;
15747         r_traj_ops_completed++;
15748         if(*stop_flag)
15749         {
15750             re_read_so_far-=reclen/1024;
15751             r_traj_bytes_completed-=reclen;
15752         }
15753         if(hist_summary)
15754         {
15755             thread_qtime_stop=time_so_far();
15756             hist_time =(thread_qtime_stop-thread_qtime_start-time_res);
15757             hist_insert(hist_time);
15758         }
15759         if(op_rate_flag)
15760         {
15761             thread_qtime_stop=time_so_far();
15762             desired_op_rate_time = ((double)1.0/(double)op_rate);
15763             actual_rate = (double)(thread_qtime_stop-thread_qtime_start);
15764 /*
15765 printf("Desired rate %g  Actual rate %g Nap %g microseconds\n",desired_op_rate_time,
15766     actual_rate, (desired_op_rate_time-actual_rate));
15767 */
15768             if( actual_rate < desired_op_rate_time)
15769                 my_unap((unsigned long long) ((desired_op_rate_time-actual_rate)*1000000.0 ));
15770         }
15771                 if(Q_flag)
15772                 {
15773                         thread_qtime_stop=time_so_far();
15774 #ifdef NO_PRINT_LLD
15775                         fprintf(thread_rrqfd,"%10.1ld %10.0f %10.1ld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
15776 #else
15777                         fprintf(thread_rrqfd,"%10.1lld %10.0f %10.1lld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
15778 #endif
15779                 }
15780 
15781         if(rlocking)
15782         {
15783             mylockr((int) fd, (int) 0, (int)1,
15784               lock_offset, reclen);
15785         }
15786     }
15787     if(file_lock)
15788         if(mylockf((int) fd, (int) 0, (int)1))
15789             printf("Read unlock failed. %d\n",errno);
15790     /*fsync(fd);*/
15791 #ifdef ASYNC_IO
15792     if(async_flag)
15793     {
15794         end_async(gc);
15795         gc=0;
15796     }
15797 #endif
15798     if(include_flush)
15799     {
15800         if(mmapflag)
15801         {
15802             msync(maddr,(size_t)(filebytes64),MS_SYNC);
15803         }else
15804             fsync(fd);
15805     }
15806     if(include_close)
15807     {   
15808         if(mmapflag)
15809         {
15810             mmap_end(maddr,(unsigned long long)filebytes64);
15811         }
15812 #if defined(Windows)
15813         if(unbuffered)
15814             CloseHandle(hand);
15815         else
15816 #endif
15817         close(fd);
15818     }
15819     temp_time = time_so_far();
15820     child_stat->throughput = ((temp_time - starttime1)-time_res)
15821         -compute_val;
15822     if(child_stat->throughput < (double).000001) 
15823     {
15824         child_stat->throughput= time_res;
15825         if(rec_prob < reclen)
15826             rec_prob = reclen;
15827         res_prob=1;
15828     }
15829 
15830     if(OPS_flag){
15831        /*re_read_so_far=(re_read_so_far*1024)/reclen;*/
15832        re_read_so_far=r_traj_ops_completed;
15833     }
15834     child_stat->throughput = re_read_so_far/child_stat->throughput;
15835     child_stat->actual = re_read_so_far;
15836     if(!xflag)
15837     {
15838         *stop_flag=1;
15839         if(distributed && client_iozone)
15840             send_stop();
15841     }
15842     if(cpuutilflag)
15843     {
15844         cputime = cputime_so_far() - cputime;
15845         if (cputime < cputime_res)
15846             cputime = 0.0;
15847         child_stat->cputime = cputime;
15848         walltime = time_so_far() - walltime;
15849         child_stat->walltime = walltime;
15850     }
15851     if(distributed && client_iozone)
15852     {
15853         tell_master_stats(THREAD_REREAD_TEST,chid, child_stat->throughput,
15854             child_stat->actual, 
15855             child_stat->cputime, child_stat->walltime,
15856             (char)*stop_flag,
15857             (long long)CHILD_STATE_HOLD);
15858     }
15859     child_stat->flag = CHILD_STATE_HOLD;    /* Tell parent I'm done */
15860     if(!include_close)
15861     {
15862         if(mmapflag)
15863         {
15864             msync(maddr,(size_t)(filebytes64),MS_SYNC);
15865             mmap_end(maddr,(unsigned long long)filebytes64);
15866         }else
15867             fsync(fd);
15868 #if defined(Windows)
15869         if(unbuffered)
15870             CloseHandle(hand);
15871         else
15872 #endif
15873         close(fd);
15874     }
15875         if(Q_flag && (thread_rrqfd !=0) )
15876                 fclose(thread_rrqfd);
15877     free(dummyfile[xx]);
15878     if(r_traj_flag)
15879         fclose(r_traj_fd);
15880     if(debug1)
15881 #ifdef NO_PRINT_LLD
15882         printf("\nChild finished %ld\n",xx);
15883 #else
15884         printf("\nChild finished %lld\n",xx);
15885 #endif
15886 
15887     if(L_flag)
15888     {
15889         get_date(now_string);
15890         fprintf(thread_Lwqfd,"%-25s %s","Reread test finished: ",now_string);
15891         fclose(thread_Lwqfd);
15892     }
15893     if(hist_summary)
15894        dump_hist("Reread",(int)xx);
15895     if(distributed && client_iozone)
15896         return(0);
15897 #ifdef NO_THREADS
15898     exit(0);
15899 #else
15900     if(use_thread)
15901         thread_exit();
15902     else
15903         exit(0);
15904 #endif
15905 return(0);
15906 }
15907 
15908 /************************************************************************/
15909 /* Thread_reverse_perf_test                         */
15910 /* Reverse read test                            */
15911 /************************************************************************/
15912 #ifdef HAVE_ANSIC_C
15913 void *
15914 thread_reverse_read_test(void *x)
15915 #else
15916 void *
15917 thread_reverse_read_test(x)
15918 #endif
15919 {
15920     long long xx,xx2;
15921     char *nbuff;
15922     struct child_stats *child_stat;
15923     int fd;
15924     long long flags = 0;
15925     double walltime, cputime;
15926     double thread_qtime_stop,thread_qtime_start;
15927     double hist_time;
15928     double desired_op_rate_time;
15929     double actual_rate;
15930     double starttime2 = 0;
15931     float delay = 0;
15932     double temp_time;
15933     double compute_val = (double)0;
15934     long long recs_per_buffer;
15935     off64_t i,t_offset;
15936     off64_t lock_offset=0;
15937     off64_t current_position=0;
15938     off64_t written_so_far, reverse_read, re_read_so_far,read_so_far;
15939     char *dummyfile[MAXSTREAMS];           /* name of dummy file     */
15940     char *maddr=0;
15941     char *wmaddr=0;
15942     char now_string[30];
15943     volatile char *buffer1;
15944     int anwser,bind_cpu;
15945     off64_t traj_offset;
15946     char tmpname[256];
15947     FILE *thread_revqfd=0;
15948     FILE *thread_Lwqfd=0;
15949 #if defined(VXFS) || defined(solaris)
15950     int test_foo = 0;
15951 #endif
15952 #ifdef ASYNC_IO
15953     struct cache *gc=0;
15954 #else
15955     long long *gc=0;
15956 #endif
15957     /*****************/
15958     /* Children only */
15959     /*****************/
15960     if(compute_flag)
15961         delay=compute_time;
15962     hist_time=thread_qtime_stop=thread_qtime_start=0;
15963     traj_offset=walltime=cputime=0;
15964     anwser=bind_cpu=0;
15965     written_so_far=read_so_far=reverse_read=re_read_so_far=0;
15966     recs_per_buffer = cache_size/reclen ;
15967 #ifdef NO_THREADS
15968     xx=chid;
15969 #else
15970     if(use_thread)
15971         xx = (long long)((long)x);
15972     else
15973     {
15974         xx=chid;
15975     }
15976 #endif
15977 #ifndef NO_THREADS
15978 #if defined( _HPUX_SOURCE ) || defined ( linux )
15979     if(ioz_processor_bind)
15980     {
15981          bind_cpu=(begin_proc+(int)xx)%num_processors;
15982 #if defined(_HPUX_SOURCE)
15983          pthread_processor_bind_np(PTHREAD_BIND_FORCED_NP,
15984                          (pthread_spu_t *)&anwser, (pthread_spu_t)bind_cpu, pthread_self());
15985 #else
15986      cpu_set_t cpuset;
15987 
15988      CPU_ZERO(&cpuset);
15989      CPU_SET(bind_cpu, &cpuset);
15990 
15991      pthread_setaffinity_np(pthread_self(), sizeof(cpuset),&cpuset);
15992 #endif
15993         my_nap(40); /* Switch to new cpu */
15994     }
15995 #endif
15996 #endif
15997     if(use_thread)
15998         nbuff=barray[xx];
15999     else
16000         nbuff=buffer;
16001     if(debug1)
16002     {
16003        if(use_thread)
16004 #ifdef NO_PRINT_LLD
16005         printf("\nStarting child %ld\n",xx);
16006 #else
16007         printf("\nStarting child %lld\n",xx);
16008 #endif
16009        else
16010 #ifdef NO_PRINT_LLD
16011         printf("\nStarting process %d slot %ld\n",getpid(),xx);
16012 #else
16013         printf("\nStarting process %d slot %lld\n",getpid(),xx);
16014 #endif
16015         
16016     }
16017     dummyfile[xx]=(char *)malloc((size_t)MAXNAMESIZE);
16018     xx2=xx;
16019     if(share_file)
16020         xx2=(long long)0;
16021     if(mfflag)
16022     {
16023 #ifdef NO_PRINT_LLD
16024         sprintf(dummyfile[xx],"%s",filearray[xx2]);
16025 #else
16026         sprintf(dummyfile[xx],"%s",filearray[xx2]);
16027 #endif
16028     }
16029     else
16030     {
16031 #ifdef NO_PRINT_LLD
16032         sprintf(dummyfile[xx],"%s.DUMMY.%ld",filearray[xx2],xx2);
16033 #else
16034         sprintf(dummyfile[xx],"%s.DUMMY.%lld",filearray[xx2],xx2);
16035 #endif
16036     }
16037     if(oflag)
16038         flags=O_RDONLY|O_SYNC;
16039     else
16040         flags=O_RDONLY;
16041 #if defined(_HPUX_SOURCE) || defined(linux)
16042     if(read_sync)
16043         flags |=O_RSYNC|O_SYNC;
16044 #endif
16045 
16046 #if ! defined(DONT_HAVE_O_DIRECT)
16047 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
16048     if(direct_flag)
16049         flags |=O_DIRECT;
16050 #endif
16051 #if defined(TRU64)
16052     if(direct_flag)
16053         flags |=O_DIRECTIO;
16054 #endif
16055 #endif
16056 #if defined(Windows)
16057         if(unbuffered)
16058         {
16059             hand=CreateFile(dummyfile[xx],
16060           GENERIC_READ|GENERIC_WRITE,
16061               FILE_SHARE_WRITE|FILE_SHARE_READ,
16062           NULL,OPEN_EXISTING,FILE_FLAG_NO_BUFFERING|
16063           FILE_FLAG_WRITE_THROUGH|FILE_FLAG_POSIX_SEMANTICS,
16064           NULL);
16065         }
16066 #endif
16067 
16068     if((fd = I_OPEN(dummyfile[xx], ((int)flags),0))<0)
16069     {
16070         client_error=errno;
16071         if(distributed && client_iozone)
16072             send_stop();
16073         perror(dummyfile[xx]);
16074         exit(140);
16075     }
16076 #ifdef ASYNC_IO
16077     if(async_flag)
16078         async_init(&gc,fd,direct_flag);
16079 #endif
16080 #ifdef VXFS
16081     if(direct_flag)
16082     {
16083         ioctl(fd,VX_SETCACHE,VX_DIRECT);
16084         ioctl(fd,VX_GETCACHE,&test_foo);
16085         if(test_foo == 0)
16086         {
16087             if(!client_iozone)
16088               printf("\nVxFS advanced setcache feature not available.\n");
16089             exit(3);
16090         }
16091     }
16092 #endif
16093 #if defined(solaris)
16094         if(direct_flag)
16095         {
16096                 test_foo = directio(fd, DIRECTIO_ON);
16097                 if(test_foo != 0)
16098                 {
16099                         if(!client_iozone)
16100                           printf("\ndirectio not available.\n");
16101                         exit(3);
16102                 }
16103         }
16104 #endif
16105     if(mmapflag)
16106     {
16107         maddr=(char *)initfile(fd,(numrecs64*reclen),0,PROT_READ);
16108     }
16109     if(fetchon)
16110         fetchit(nbuff,reclen);
16111         if(Q_flag)
16112         {
16113                 sprintf(tmpname,"Child_%d_revol.dat",(int)xx);
16114                 thread_revqfd=fopen(tmpname,"a");
16115                 if(thread_revqfd==0)
16116                 {
16117             client_error=errno;
16118             if(distributed && client_iozone)
16119                 send_stop();
16120                         printf("Unable to open %s\n",tmpname);
16121                         exit(40);
16122                 }
16123         fprintf(thread_revqfd,"Offset in Kbytes   Latency in microseconds  Transfer size in bytes\n");
16124         }
16125     if(L_flag)
16126     {
16127         sprintf(tmpname,"Child_%d.log",(int)xx);
16128         thread_Lwqfd=fopen(tmpname,"a");
16129         if(thread_Lwqfd==0)
16130         {
16131             client_error=errno;
16132             if(distributed && client_iozone)
16133                 send_stop();
16134             printf("Unable to open %s\n",tmpname);
16135             exit(40);
16136         }
16137         get_date(now_string);
16138         fprintf(thread_Lwqfd,"%-25s %s","Reverse read start: ",now_string);
16139     }
16140     child_stat = (struct child_stats *)&shmaddr[xx];
16141     child_stat->throughput = 0;
16142     child_stat->actual = 0;
16143     child_stat->flag = CHILD_STATE_READY;
16144         if(distributed && client_iozone)
16145         {
16146                 tell_master_ready(chid);
16147                 wait_for_master_go(chid);
16148         }
16149         else
16150         {
16151                 while(child_stat->flag!=CHILD_STATE_BEGIN)   /* Wait for signal from parent */
16152                         Poll((long long)1);
16153         }
16154     starttime2 = time_so_far();
16155     if(cpuutilflag)
16156     {
16157         walltime = starttime2;
16158         cputime = cputime_so_far();
16159     }
16160 
16161     t_offset = (off64_t)reclen;
16162     if (!(h_flag || k_flag || mmapflag))
16163     {
16164       if(check_filename(dummyfile[xx]))
16165       {
16166         if((I_LSEEK( fd, -t_offset, SEEK_END ))<0)
16167         {
16168             client_error=errno;
16169             if(distributed && client_iozone)
16170                 send_stop();
16171             perror("lseek");
16172             exit(142);
16173         }
16174       }
16175       else
16176       {
16177         if(I_LSEEK( fd, (numrecs64*reclen)-t_offset, SEEK_SET )<0)
16178         {
16179             client_error=errno;
16180             if(distributed && client_iozone)
16181                 send_stop();
16182             perror("lseek");
16183             exit(77);
16184         }
16185       }
16186     }
16187     current_position=(reclen*numrecs64)-reclen;
16188     if(file_lock)
16189         if(mylockf((int) fd, (int) 1, (int)1)!=0)
16190             printf("File lock for read failed. %d\n",errno);
16191     for(i=0; i<numrecs64; i++) 
16192     {
16193         if(rlocking)
16194         {
16195             lock_offset=I_LSEEK(fd,0,SEEK_CUR);
16196             mylockr((int) fd, (int) 1, (int)1,
16197               lock_offset, reclen);
16198         }
16199         if(disrupt_flag && ((i%DISRUPT)==0))
16200         {
16201             disrupt(fd);
16202         }
16203         if(compute_flag)
16204             compute_val+=do_compute(delay);
16205         if(Q_flag)
16206         {
16207             traj_offset=I_LSEEK(fd,0,SEEK_CUR);
16208         }
16209         if(*stop_flag)
16210         {
16211             if(debug1)
16212                 printf("\n(%ld) Stopped by another 3\n", (long)xx);
16213             break;
16214         }
16215         if(purge)
16216             purgeit(nbuff,reclen);
16217                 if(Q_flag || hist_summary || op_rate_flag)
16218                 {
16219                         thread_qtime_start=time_so_far();
16220                 }
16221         if(mmapflag)
16222         {
16223             wmaddr = &maddr[current_position];
16224             fill_area((long long*)wmaddr,(long long*)nbuff,(long long)reclen);
16225         }
16226         else
16227         {
16228               if(async_flag)
16229               {
16230                 if(no_copy_flag)
16231                   async_read_no_copy(gc, (long long)fd, &buffer1, (current_position),
16232                     reclen, -1LL,(numrecs64*reclen),depth);
16233                 else
16234                   async_read(gc, (long long)fd, nbuff, (current_position),reclen,
16235                     -1LL,(numrecs64*reclen),depth);
16236               }
16237               else
16238               {
16239                   if(read((int)fd, (void*)nbuff, (size_t) reclen) != reclen)
16240                   {
16241                 if(*stop_flag)
16242                 {
16243                     if(debug1)
16244                         printf("\n(%ld) Stopped by another 4\n", (long)xx);
16245                     break;
16246                 }
16247 #ifdef NO_PRINT_LLD
16248                 printf("\nError reading block %ld\n", i); 
16249 #else
16250                 printf("\nError reading block %lld\n", i); 
16251 #endif
16252                 perror("read");
16253                 if (!no_unlink)
16254                 {
16255                    if(check_filename(dummyfile[xx]))
16256                     unlink(dummyfile[xx]);
16257                 }
16258                 child_stat->flag = CHILD_STATE_HOLD;
16259                 exit(144);
16260                   }
16261               }
16262         }
16263         if(verify){
16264            if(async_flag && no_copy_flag)
16265            {
16266             if(verify_buffer(buffer1,reclen,(off64_t)(current_position/reclen),reclen,(long long)pattern,sverify)){
16267                 if (!no_unlink)
16268                 {
16269                    if(check_filename(dummyfile[xx]))
16270                     unlink(dummyfile[xx]);
16271                 }
16272                 child_stat->flag = CHILD_STATE_HOLD;
16273                 exit(145);
16274             }
16275            }
16276            else
16277            {
16278             if(verify_buffer(nbuff,reclen,(off64_t)(current_position/reclen),reclen,(long long)pattern,sverify)){
16279                 if (!no_unlink)
16280                 {
16281                    if(check_filename(dummyfile[xx]))
16282                     unlink(dummyfile[xx]);
16283                 }
16284                 child_stat->flag = CHILD_STATE_HOLD;
16285                 exit(146);
16286             }
16287            }
16288         }
16289         if(rlocking)
16290         {
16291             mylockr((int) fd, (int) 0, (int)1,
16292               lock_offset, reclen);
16293         }
16294         current_position+=reclen;
16295         if(async_flag && no_copy_flag)
16296             async_release(gc);
16297         t_offset = (off64_t)reclen*2;
16298         if (!(h_flag || k_flag || mmapflag))
16299         {
16300           I_LSEEK( fd, -t_offset, SEEK_CUR );
16301         }
16302         current_position-=(2 *reclen);
16303         reverse_read +=reclen/1024;
16304         if(*stop_flag)
16305         {
16306             reverse_read -=reclen/1024;
16307         }
16308         if(hist_summary)
16309         {
16310             thread_qtime_stop=time_so_far();
16311             hist_time =(thread_qtime_stop-thread_qtime_start-time_res);
16312             hist_insert(hist_time);
16313         }
16314         if(op_rate_flag)
16315         {
16316             thread_qtime_stop=time_so_far();
16317             desired_op_rate_time = ((double)1.0/(double)op_rate);
16318             actual_rate = (double)(thread_qtime_stop-thread_qtime_start);
16319 /*
16320 printf("Desired rate %g  Actual rate %g Nap %g microseconds\n",desired_op_rate_time,
16321     actual_rate, (desired_op_rate_time-actual_rate));
16322 */
16323             if( actual_rate < desired_op_rate_time)
16324                 my_unap((unsigned long long) ((desired_op_rate_time-actual_rate)*1000000.0 ));
16325         }
16326                 if(Q_flag)
16327                 {
16328                         thread_qtime_stop=time_so_far();
16329 #ifdef NO_PRINT_LLD
16330                         fprintf(thread_revqfd,"%10.1ld %10.0f %10.1ld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
16331 #else
16332                         fprintf(thread_revqfd,"%10.1lld %10.0f %10.1lld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
16333 #endif
16334                 }
16335     }
16336     if(file_lock)
16337         if(mylockf((int) fd,(int)0, (int)1))
16338             printf("Read unlock failed %d\n",errno);
16339 #ifdef ASYNC_IO
16340     if(async_flag)
16341     {
16342         end_async(gc);
16343         gc=0;
16344     }
16345 #endif
16346     if(include_flush)
16347     {
16348         if(mmapflag)
16349         {
16350             msync(maddr,(size_t)(numrecs64*reclen),MS_SYNC);
16351         }else
16352             fsync(fd);
16353     }
16354     if(include_close)
16355     {   
16356         if(mmapflag)
16357         {
16358             mmap_end(maddr,(unsigned long long)numrecs64*reclen);
16359         }
16360         close(fd);
16361     }
16362     temp_time = time_so_far();
16363     child_stat->throughput = ((temp_time - starttime2)-time_res)
16364         -compute_val;
16365     if(child_stat->throughput < (double).000001) 
16366     {
16367         child_stat->throughput= time_res;
16368         if(rec_prob < reclen)
16369             rec_prob = reclen;
16370         res_prob=1;
16371     }
16372     if(OPS_flag){
16373        reverse_read=(reverse_read*1024)/reclen;
16374     }
16375     child_stat->throughput = reverse_read/child_stat->throughput;
16376     child_stat->actual = reverse_read;
16377     if(!xflag)
16378     {
16379         *stop_flag=1;
16380         if(distributed && client_iozone)
16381             send_stop();
16382     }
16383     if(cpuutilflag)
16384     {
16385         cputime = cputime_so_far() - cputime;
16386         if (cputime < cputime_res)
16387             cputime = 0.0;
16388         child_stat->cputime = cputime;
16389         walltime = time_so_far() - walltime;
16390         child_stat->walltime = walltime;
16391     }
16392         if(distributed && client_iozone)
16393                 tell_master_stats(THREAD_REVERSE_READ_TEST, chid, child_stat->throughput,
16394                         child_stat->actual,
16395             child_stat->cputime, child_stat->walltime,
16396             (char)*stop_flag,
16397             (long long)CHILD_STATE_HOLD);
16398     child_stat->flag = CHILD_STATE_HOLD;    /* Tell parent I'm done */
16399     if(!include_close)
16400     {
16401         if(mmapflag)
16402         {
16403             msync(maddr,(size_t)(numrecs64*reclen),MS_SYNC);
16404             mmap_end(maddr,(unsigned long long)numrecs64*reclen);
16405         }else
16406             fsync(fd);
16407         close(fd);
16408     }
16409     free(dummyfile[xx]);
16410         if(Q_flag && (thread_revqfd !=0) )
16411                 fclose(thread_revqfd);
16412     if(debug1)
16413 #ifdef NO_PRINT_LLD
16414         printf("\nChild finished %ld\n",xx);
16415 #else
16416         printf("\nChild finished %lld\n",xx);
16417 #endif
16418 
16419     if(L_flag)
16420     {
16421         get_date(now_string);
16422         fprintf(thread_Lwqfd,"%-25s %s","Reverse read finished: ",
16423             now_string);
16424         fclose(thread_Lwqfd);
16425     }
16426     if(hist_summary)
16427        dump_hist("Read Backwards",(int)xx);
16428     if(distributed && client_iozone)
16429         return(0);
16430 #ifdef NO_THREADS
16431     exit(0);
16432 #else
16433     if(use_thread)
16434         thread_exit();
16435     else
16436         exit(0);
16437 #endif
16438 return(0);
16439 }
16440 /************************************************************************/
16441 /* Thread_stride_read_test                          */
16442 /************************************************************************/
16443 #ifdef HAVE_ANSIC_C
16444 void *
16445 thread_stride_read_test(void *x)
16446 #else
16447 void *
16448 thread_stride_read_test(x)
16449 #endif
16450 {
16451     long long xx,xx2;
16452     char *nbuff=0;
16453     struct child_stats *child_stat;
16454     double walltime, cputime;
16455     int fd;
16456     long long flags = 0;
16457     double thread_qtime_stop,thread_qtime_start;
16458     double hist_time;
16459     double desired_op_rate_time;
16460     double actual_rate;
16461     double starttime2 = 0;
16462     float delay = 0;
16463     double compute_val = (double)0;
16464     double temp_time;
16465     long long recs_per_buffer;
16466     off64_t i;
16467     off64_t lock_offset=0;
16468     off64_t savepos64=0;
16469     off64_t written_so_far, stride_read,re_read_so_far,read_so_far;
16470     off64_t stripewrap = 0;
16471     off64_t current_position = 0;
16472     char *dummyfile[MAXSTREAMS];           /* name of dummy file     */
16473     char *maddr=0;
16474     char *wmaddr=0;
16475     volatile char *buffer1;
16476     int anwser,bind_cpu;
16477     off64_t traj_offset;
16478     char tmpname[256];
16479     char now_string[30];
16480     FILE *thread_strqfd=0;
16481     FILE *thread_Lwqfd=0;
16482 #if defined(VXFS) || defined(solaris)
16483     int test_foo = 0;
16484 #endif
16485 #ifdef ASYNC_IO
16486     struct cache *gc=0;
16487 #else
16488     long long *gc=0;
16489 #endif
16490     /*****************/
16491     /* Children only */
16492     /*****************/
16493     if(compute_flag)
16494         delay=compute_time;
16495     hist_time=thread_qtime_stop=thread_qtime_start=0;
16496     traj_offset=walltime=cputime=0;
16497     anwser=bind_cpu=0;
16498     written_so_far=read_so_far=stride_read=re_read_so_far=0;
16499     recs_per_buffer = cache_size/reclen ;
16500 #ifdef NO_THREADS
16501     xx=chid;
16502 #else
16503     if(use_thread)
16504         xx = (long long)((long)x);
16505     else
16506     {
16507         xx=chid;
16508     }
16509 #endif
16510 #ifndef NO_THREADS
16511 #if defined( _HPUX_SOURCE ) || defined ( linux )
16512     if(ioz_processor_bind)
16513     {
16514          bind_cpu=(begin_proc+(int)xx)%num_processors;
16515 #if defined(_HPUX_SOURCE)
16516          pthread_processor_bind_np(PTHREAD_BIND_FORCED_NP,
16517                          (pthread_spu_t *)&anwser, (pthread_spu_t)bind_cpu, pthread_self());
16518 #else
16519      cpu_set_t cpuset;
16520 
16521      CPU_ZERO(&cpuset);
16522      CPU_SET(bind_cpu, &cpuset);
16523 
16524      pthread_setaffinity_np(pthread_self(), sizeof(cpuset),&cpuset);
16525 #endif
16526         my_nap(40); /* Switch to new cpu */
16527     }
16528 #endif
16529 #endif
16530     if(use_thread)
16531         nbuff=barray[xx];
16532     else
16533         nbuff=buffer;
16534     if(debug1)
16535     {
16536        if(use_thread)
16537 #ifdef NO_PRINT_LLD
16538         printf("\nStarting child %ld\n",xx);
16539 #else
16540         printf("\nStarting child %lld\n",xx);
16541 #endif
16542        else
16543 #ifdef NO_PRINT_LLD
16544         printf("\nStarting process %d slot %ld\n",getpid(),xx);
16545 #else
16546         printf("\nStarting process %d slot %lld\n",getpid(),xx);
16547 #endif
16548         
16549     }
16550     dummyfile[xx]=(char *)malloc((size_t)MAXNAMESIZE);
16551     xx2=xx;
16552     if(share_file)
16553         xx2=(long long)0;
16554     if(mfflag)
16555     {
16556 #ifdef NO_PRINT_LLD
16557         sprintf(dummyfile[xx],"%s",filearray[xx2]);
16558 #else
16559         sprintf(dummyfile[xx],"%s",filearray[xx2]);
16560 #endif
16561     }
16562     else
16563     {
16564 #ifdef NO_PRINT_LLD
16565         sprintf(dummyfile[xx],"%s.DUMMY.%ld",filearray[xx2],xx2);
16566 #else
16567         sprintf(dummyfile[xx],"%s.DUMMY.%lld",filearray[xx2],xx2);
16568 #endif
16569     }
16570     if(oflag)
16571         flags=O_RDONLY|O_SYNC;
16572     else
16573         flags=O_RDONLY;
16574 #if defined(_HPUX_SOURCE) || defined(linux)
16575     if(read_sync)
16576         flags |=O_RSYNC|O_SYNC;
16577 #endif
16578 #if ! defined(DONT_HAVE_O_DIRECT)
16579 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
16580     if(direct_flag)
16581         flags |=O_DIRECT;
16582 #endif
16583 #if defined(TRU64)
16584     if(direct_flag)
16585         flags |=O_DIRECTIO;
16586 #endif
16587 #endif
16588 
16589 #if defined(Windows)
16590         if(unbuffered)
16591         {
16592             hand=CreateFile(dummyfile[xx],
16593           GENERIC_READ|GENERIC_WRITE,
16594               FILE_SHARE_WRITE|FILE_SHARE_READ,
16595           NULL,OPEN_EXISTING,FILE_FLAG_NO_BUFFERING|
16596           FILE_FLAG_WRITE_THROUGH|FILE_FLAG_POSIX_SEMANTICS,
16597           NULL);
16598         }
16599 #endif
16600     if((fd = I_OPEN(dummyfile[xx], ((int)flags),0))<0)
16601     {
16602         client_error=errno;
16603         if(distributed && client_iozone)
16604             send_stop();
16605         perror(dummyfile[xx]);
16606         exit(147);
16607     }
16608 #ifdef ASYNC_IO
16609     if(async_flag)
16610         async_init(&gc,fd,direct_flag);
16611 #endif
16612 #ifdef VXFS
16613     if(direct_flag)
16614     {
16615         ioctl(fd,VX_SETCACHE,VX_DIRECT);
16616         ioctl(fd,VX_GETCACHE,&test_foo);
16617         if(test_foo == 0)
16618         {
16619             if(!client_iozone)
16620               printf("\nVxFS advanced setcache feature not available.\n");
16621             exit(3);
16622         }
16623     }
16624 #endif
16625 #if defined(solaris)
16626         if(direct_flag)
16627         {
16628                 test_foo = directio(fd, DIRECTIO_ON);
16629                 if(test_foo != 0)
16630                 {
16631                         if(!client_iozone)
16632                           printf("\ndirectio not available.\n");
16633                         exit(3);
16634                 }
16635         }
16636 #endif
16637 
16638     if(mmapflag)
16639     {
16640         maddr=(char *)initfile(fd,(numrecs64*reclen),0,PROT_READ);
16641     }
16642     if(fetchon)
16643         fetchit(nbuff,reclen);
16644         if(Q_flag)
16645         {
16646                 sprintf(tmpname,"Child_%d_strol.dat",(int)xx);
16647                 thread_strqfd=fopen(tmpname,"a");
16648                 if(thread_strqfd==0)
16649                 {
16650             client_error=errno;
16651             if(distributed && client_iozone)
16652                 send_stop();
16653                         printf("Unable to open %s\n",tmpname);
16654                         exit(40);
16655                 }
16656         fprintf(thread_strqfd,"Offset in Kbytes   Latency in microseconds  Transfer size in bytes\n");
16657         }
16658     if(L_flag)
16659     {
16660         sprintf(tmpname,"Child_%d.log",(int)xx);
16661         thread_Lwqfd=fopen(tmpname,"a");
16662         if(thread_Lwqfd==0)
16663         {
16664             client_error=errno;
16665             if(distributed && client_iozone)
16666                 send_stop();
16667             printf("Unable to open %s\n",tmpname);
16668             exit(40);
16669         }
16670         get_date(now_string);
16671         fprintf(thread_Lwqfd,"%-25s %s","Stride test start: ",
16672             now_string);
16673     }
16674     child_stat = (struct child_stats *)&shmaddr[xx];
16675     child_stat->throughput = 0;
16676     child_stat->actual = 0;
16677     child_stat->flag = CHILD_STATE_READY;
16678         if(distributed && client_iozone)
16679         {
16680                 tell_master_ready(chid);
16681                 wait_for_master_go(chid);
16682         }
16683         else
16684 
16685         /* wait for parent to say go */
16686                 while(child_stat->flag!=CHILD_STATE_BEGIN)      
16687                         Poll((long long)1);
16688     if(file_lock)
16689         if(mylockf((int) fd, (int) 1,  (int)1)!=0)
16690             printf("File lock for write failed. %d\n",errno);
16691     starttime2 = time_so_far();
16692     if(cpuutilflag)
16693     {
16694         walltime = starttime2;
16695         cputime = cputime_so_far();
16696     }
16697     for(i=0; i<numrecs64; i++){
16698         if(disrupt_flag && ((i%DISRUPT)==0))
16699         {
16700             disrupt(fd);
16701         }
16702         if(compute_flag)
16703             compute_val+=do_compute(delay);
16704         if(Q_flag)
16705         {
16706             traj_offset=I_LSEEK(fd,0,SEEK_CUR);
16707         }
16708         if(rlocking)
16709         {
16710             lock_offset=I_LSEEK(fd,0,SEEK_CUR);
16711             mylockr((int) fd, (int) 1, (int)1,
16712               lock_offset, reclen);
16713         }
16714         if(*stop_flag)
16715         {
16716             if(debug1)
16717                 printf("\n(%ld) Stopped by another 3\n", (long)xx);
16718             break;
16719         }
16720         if(purge)
16721             purgeit(nbuff,reclen);
16722                 if(Q_flag || hist_summary || op_rate_flag)
16723                 {
16724                         thread_qtime_start=time_so_far();
16725                 }
16726         if(verify)
16727             savepos64=current_position/(off64_t)reclen;
16728         if(mmapflag)
16729         {
16730             wmaddr = &maddr[current_position];
16731             fill_area((long long*)wmaddr,(long long*)nbuff,(long long)reclen);
16732         }
16733         else
16734         {
16735             if(async_flag)
16736             {
16737                 if(no_copy_flag)
16738                   async_read_no_copy(gc, (long long)fd, &buffer1, (current_position),
16739                     reclen, stride,(numrecs64*reclen),depth);
16740                 else
16741                   async_read(gc, (long long)fd, nbuff, (current_position),reclen,
16742                     stride,(numrecs64*reclen),depth);
16743             }
16744             else
16745             {
16746               if(read((int)fd, (void*)nbuff, (size_t) reclen) != reclen)
16747               {
16748                 if(*stop_flag)
16749                 {
16750                     if(debug1)
16751                         printf("\n(%ld) Stopped by another 4\n", (long)xx);
16752                     break;
16753                 }
16754 #ifdef NO_PRINT_LLD
16755                     printf("\nError reading block %ld, fd= %d\n", i, fd);
16756 #else
16757                     printf("\nError reading block %lld, fd= %d\n", i, fd);
16758 #endif
16759                 perror("read");
16760                 if (!no_unlink)
16761                 {
16762                    if(check_filename(dummyfile[xx]))
16763                     unlink(dummyfile[xx]);
16764                 }
16765                 child_stat->flag = CHILD_STATE_HOLD;
16766                     exit(149);
16767               }
16768             }
16769         }
16770         if(rlocking)
16771         {
16772             mylockr((int) fd, (int) 0, (int)1,
16773               lock_offset, reclen);
16774         }
16775         current_position+=reclen;
16776         if(verify){
16777            if(async_flag && no_copy_flag)
16778            {
16779             if(verify_buffer(buffer1,reclen,(off64_t)savepos64,reclen,(long long)pattern,sverify)){
16780                 if (!no_unlink)
16781                 {
16782                    if(check_filename(dummyfile[xx]))
16783                     unlink(dummyfile[xx]);
16784                 }
16785                 child_stat->flag = CHILD_STATE_HOLD;
16786                 exit(150);
16787             }
16788            }
16789            else
16790            {
16791             if(verify_buffer(nbuff,reclen,(off64_t)savepos64,reclen,(long long)pattern,sverify)){
16792                 if (!no_unlink)
16793                 {
16794                    if(check_filename(dummyfile[xx]))
16795                     unlink(dummyfile[xx]);
16796                 }
16797                 child_stat->flag = CHILD_STATE_HOLD;
16798                 exit(151);
16799             }
16800            }
16801         }
16802         if(async_flag && no_copy_flag)
16803             async_release(gc);
16804         if(current_position + (stride * reclen) >= (numrecs64 * reclen)-reclen) 
16805         {
16806             current_position=0;
16807 
16808             stripewrap++;
16809               
16810             if(numrecs64 <= stride)
16811             {
16812                 current_position=0;
16813             }
16814             else
16815             {
16816                 current_position = (off64_t)((stripewrap)%numrecs64)*reclen;
16817             }
16818             if (!(h_flag || k_flag || mmapflag))
16819             {
16820               if(I_LSEEK(fd,current_position,SEEK_SET)<0)
16821               {
16822                 client_error=errno;
16823                 if(distributed && client_iozone)
16824                     send_stop();
16825                 perror("lseek");
16826                 exit(152);
16827               }
16828             }
16829         }
16830         else            
16831         {
16832             current_position+=(stride*reclen)-reclen;
16833             if (!(h_flag || k_flag || mmapflag))
16834             {
16835               if(I_LSEEK(fd,current_position,SEEK_SET)<0)
16836               {
16837                 client_error=errno;
16838                 if(distributed && client_iozone)
16839                     send_stop();
16840                 perror("lseek");
16841                 exit(154);
16842               };
16843             }
16844         }
16845         stride_read +=reclen/1024;
16846         if(*stop_flag)
16847         {
16848             stride_read -=reclen/1024;
16849         }
16850         if(hist_summary)
16851         {
16852             thread_qtime_stop=time_so_far();
16853             hist_time =(thread_qtime_stop-thread_qtime_start-time_res);
16854             hist_insert(hist_time);
16855         }
16856         if(op_rate_flag)
16857         {
16858             thread_qtime_stop=time_so_far();
16859             desired_op_rate_time = ((double)1.0/(double)op_rate);
16860             actual_rate = (double)(thread_qtime_stop-thread_qtime_start);
16861 /*
16862 printf("Desired rate %g  Actual rate %g Nap %g microseconds\n",desired_op_rate_time,
16863     actual_rate, (desired_op_rate_time-actual_rate));
16864 */
16865             if( actual_rate < desired_op_rate_time)
16866                 my_unap((unsigned long long) ((desired_op_rate_time-actual_rate)*1000000.0 ));
16867         }
16868                 if(Q_flag)
16869                 {
16870                         thread_qtime_stop=time_so_far();
16871 #ifdef NO_PRINT_LLD
16872                         fprintf(thread_strqfd,"%10.1ld %10.0f %10.1ld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
16873 #else
16874                         fprintf(thread_strqfd,"%10.1lld %10.0f %10.1lld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
16875 #endif
16876                 }
16877     }
16878     if(file_lock)
16879         if(mylockf((int) fd,(int)0,(int)1))
16880             printf("Read unlock failed %d\n",errno);
16881 #ifdef ASYNC_IO
16882     if(async_flag)
16883     {
16884         end_async(gc);
16885         gc=0;
16886     }
16887 #endif
16888     if(include_flush)
16889     {
16890         if(mmapflag)
16891         {
16892             msync(maddr,(size_t)(numrecs64*reclen),MS_SYNC);
16893         }else
16894             fsync(fd);
16895     }
16896     if(include_close)
16897     {   
16898         if(mmapflag)
16899         {
16900             mmap_end(maddr,(unsigned long long)numrecs64*reclen);
16901         }
16902         close(fd);
16903     }
16904     temp_time = time_so_far();
16905     child_stat->throughput = ((temp_time - starttime2)-time_res)
16906         -compute_val;
16907     if(child_stat->throughput < (double).000001) 
16908     {
16909         child_stat->throughput= time_res;
16910         if(rec_prob < reclen)
16911             rec_prob = reclen;
16912         res_prob=1;
16913     }
16914     if(OPS_flag){
16915        stride_read=(stride_read*1024)/reclen;
16916     }
16917     child_stat->throughput = stride_read/child_stat->throughput;
16918     child_stat->actual = stride_read;
16919     if(!xflag)
16920     {
16921         *stop_flag=1;
16922         if(distributed && client_iozone)
16923             send_stop();
16924     }
16925     if(cpuutilflag)
16926     {
16927         cputime = cputime_so_far() - cputime;
16928         if (cputime < cputime_res)
16929             cputime = 0.0;
16930         child_stat->cputime = cputime;
16931         walltime = time_so_far() - walltime;
16932         child_stat->walltime = walltime;
16933     }
16934         if(distributed && client_iozone)
16935         {
16936                 tell_master_stats(THREAD_STRIDE_TEST,chid, child_stat->throughput,
16937                         child_stat->actual,
16938             child_stat->cputime, child_stat->walltime,
16939             (char)*stop_flag,
16940                         (long long)CHILD_STATE_HOLD);
16941         }
16942     child_stat->flag = CHILD_STATE_HOLD;    /* Tell parent I'm done */
16943     if(!include_close)
16944     {
16945         if(mmapflag)
16946         {
16947             msync(maddr,(size_t)(numrecs64*reclen),MS_SYNC);
16948             mmap_end(maddr,(unsigned long long)numrecs64*reclen);
16949         }else
16950             fsync(fd);
16951         close(fd);
16952     }
16953         if(Q_flag && (thread_strqfd !=0) )
16954                 fclose(thread_strqfd);
16955     free(dummyfile[xx]);
16956     if(debug1)
16957 #ifdef NO_PRINT_LLD
16958         printf("\nChild finished %ld\n",xx);
16959 #else
16960         printf("\nChild finished %lld\n",xx);
16961 #endif
16962 
16963     if(L_flag)
16964     {
16965         get_date(now_string);
16966         fprintf(thread_Lwqfd,"%-25s %s","Stride test finished: ",
16967             now_string);
16968         fclose(thread_Lwqfd);
16969     }
16970     if(hist_summary)
16971        dump_hist("Stride Read",(int)xx);
16972     if(distributed && client_iozone)
16973         return(0);
16974 #ifdef NO_THREADS
16975     exit(0);
16976 #else
16977     if(use_thread)
16978         thread_exit();
16979     else
16980         exit(0);
16981 #endif
16982 return(0);
16983 }
16984 
16985 /************************************************************************/
16986 /* Thread random test                               */
16987 /************************************************************************/
16988 #ifdef HAVE_ANSIC_C
16989 void *
16990 thread_mix_test(void *x)
16991 #else
16992 void *
16993 thread_mix_test(x)
16994 #endif
16995 {
16996     int selector;
16997     int num_readers;
16998     long xx;
16999 
17000 #ifdef NO_THREADS
17001     xx=chid;
17002 #else
17003     if(use_thread)
17004     {
17005         xx = (long)x;
17006     }
17007     else
17008     {
17009         xx=(long)chid;
17010     }
17011 #endif
17012     if(pct_read!=0)
17013     {
17014         num_readers = (pct_read * num_child)/100;
17015                 if(xx < num_readers)
17016                         selector=0;
17017                 else
17018                         selector=1;
17019     }
17020     else
17021     {
17022        if(Kplus_flag)
17023        {
17024         if(xx+1 <= Kplus_readers)
17025             selector=0;
17026         else
17027             selector=1;
17028        }
17029        else
17030        {
17031         /* Simple round robin */
17032         selector= ((int)xx) % 2;
17033        }        
17034     }
17035     if(selector==0)
17036     {
17037         if(seq_mix)
17038             thread_read_test(x);
17039         else
17040             thread_ranread_test(x);
17041     }
17042     else
17043     {
17044         if(seq_mix)
17045             thread_write_test(x);
17046         else
17047             thread_ranwrite_test(x);
17048     }
17049     return(0);
17050 }
17051 /************************************************************************/
17052 /* Thread random read test                          */
17053 /************************************************************************/
17054 #ifdef HAVE_ANSIC_C
17055 void *
17056 thread_ranread_test(void *x)
17057 #else
17058 void *
17059 thread_ranread_test(x)
17060 #endif
17061 {
17062     long long xx,xx2;
17063     struct child_stats *child_stat;
17064     double walltime, cputime;
17065     int fd;
17066     long long flags = 0;
17067     double thread_qtime_stop,thread_qtime_start;
17068     double hist_time;
17069     double desired_op_rate_time;
17070     double actual_rate;
17071     double starttime1 = 0;
17072     float delay = 0;
17073     double temp_time;
17074     double compute_val = (double)0;
17075     off64_t written_so_far, ranread_so_far, re_written_so_far,re_read_so_far;
17076     long long recs_per_buffer;
17077     off64_t current_offset=0;
17078     off64_t i;
17079     char *dummyfile[MAXSTREAMS];           /* name of dummy file     */
17080     char *nbuff=0;
17081     char *maddr=0;
17082     char *wmaddr=0;
17083     volatile char *buffer1;
17084     int anwser,bind_cpu;
17085     off64_t traj_offset;
17086     off64_t lock_offset=0;
17087     char tmpname[256];
17088     char now_string[30];
17089     FILE *thread_randrfd=0;
17090     FILE *thread_Lwqfd=0;
17091     long long *recnum=0;
17092 #if defined(VXFS) || defined(solaris)
17093     int test_foo = 0;
17094 #endif
17095     long long save_pos;
17096 #if defined (bsd4_2) || defined(Windows)
17097     long long rand1,rand2,rand3;
17098 #endif
17099     unsigned long long big_rand;
17100 #ifdef ASYNC_IO
17101     struct cache *gc=0;
17102 #else
17103     long long *gc=0;
17104 #endif
17105 #ifdef MERSENNE
17106         unsigned long long init[4]={0x12345ULL, 0x23456ULL, 0x34567ULL, 0x45678ULL}, length=4;
17107 #endif
17108 
17109 #ifdef MERSENNE
17110         init_by_array64(init, length);
17111 #else
17112 #ifdef bsd4_2
17113         srand(0);
17114 #else
17115 #ifdef Windows
17116         srand(0);
17117 #else
17118         srand48(0);
17119 #endif
17120 #endif
17121 #endif
17122         recnum = (long long *)malloc(sizeof(*recnum)*numrecs64);
17123         if (recnum){
17124              /* pre-compute random sequence based on 
17125         Fischer-Yates (Knuth) card shuffle */
17126             for(i = 0; i < numrecs64; i++){
17127                 recnum[i] = i;
17128             }
17129             for(i = 0; i < numrecs64; i++) {
17130                 long long tmp = recnum[i];
17131 #ifdef MERSENNE
17132                big_rand = genrand64_int64();
17133 #else
17134 #ifdef bsd4_2
17135                rand1=(long long)rand();
17136                rand2=(long long)rand();
17137                rand3=(long long)rand();
17138                big_rand=(rand1<<32)|(rand2<<16)|(rand3);
17139 #else
17140 #ifdef Windows
17141                rand1=(long long)rand();
17142                rand2=(long long)rand();
17143                rand3=(long long)rand();
17144                big_rand=(rand1<<32)|(rand2<<16)|(rand3);
17145 #else
17146                big_rand = lrand48();
17147 #endif
17148 #endif
17149 #endif
17150                big_rand = big_rand%numrecs64;
17151                tmp = recnum[i];
17152                recnum[i] = recnum[big_rand];
17153                recnum[big_rand] = tmp;
17154             }
17155         }
17156     else
17157     {
17158         fprintf(stderr,"Random uniqueness fallback.\n");
17159     }
17160     if(compute_flag)
17161         delay=compute_time;
17162     hist_time=thread_qtime_stop=thread_qtime_start=0;
17163     traj_offset=walltime=cputime=0;
17164     anwser=bind_cpu=0;
17165     written_so_far=ranread_so_far=re_written_so_far=re_read_so_far=0;
17166     recs_per_buffer = cache_size/reclen ;
17167 #ifdef NO_THREADS
17168     xx=chid;
17169 #else
17170     if(use_thread)
17171         xx = (long long)((long)x);
17172     else
17173     {
17174         xx=chid;
17175     }
17176 #endif
17177 #ifndef NO_THREADS
17178 #if defined( _HPUX_SOURCE ) || defined ( linux )
17179     if(ioz_processor_bind)
17180     {
17181          bind_cpu=(begin_proc+(int)xx)%num_processors;
17182 #if defined(_HPUX_SOURCE)
17183          pthread_processor_bind_np(PTHREAD_BIND_FORCED_NP,
17184                          (pthread_spu_t *)&anwser, (pthread_spu_t)bind_cpu, pthread_self());
17185 #else
17186      cpu_set_t cpuset;
17187 
17188      CPU_ZERO(&cpuset);
17189      CPU_SET(bind_cpu, &cpuset);
17190 
17191      pthread_setaffinity_np(pthread_self(), sizeof(cpuset),&cpuset);
17192 #endif
17193         my_nap(40); /* Switch to new cpu */
17194     }
17195 #endif
17196 #endif
17197     if(use_thread)
17198         nbuff=barray[xx];
17199     else
17200         nbuff=buffer;
17201     dummyfile[xx]=(char *)malloc((size_t)MAXNAMESIZE);
17202     xx2=xx;
17203     if(share_file)
17204         xx2=(long long)0;
17205     if(mfflag)
17206     {
17207 #ifdef NO_PRINT_LLD
17208         sprintf(dummyfile[xx],"%s",filearray[xx2]);
17209 #else
17210         sprintf(dummyfile[xx],"%s",filearray[xx2]);
17211 #endif
17212     }
17213     else
17214     {
17215 #ifdef NO_PRINT_LLD
17216         sprintf(dummyfile[xx],"%s.DUMMY.%ld",filearray[xx2],xx2);
17217 #else
17218         sprintf(dummyfile[xx],"%s.DUMMY.%lld",filearray[xx2],xx2);
17219 #endif
17220     }
17221     if(oflag)
17222     {
17223         flags=O_RDONLY|O_SYNC;
17224     }
17225     else
17226         flags=O_RDONLY;
17227 #if defined(_HPUX_SOURCE) || defined(linux)
17228     if(read_sync)
17229         flags |=O_RSYNC|O_SYNC;
17230 #endif
17231 
17232 #if ! defined(DONT_HAVE_O_DIRECT)
17233 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
17234     if(direct_flag)
17235         flags |=O_DIRECT;
17236 #endif
17237 #if defined(TRU64)
17238     if(direct_flag)
17239         flags |=O_DIRECTIO;
17240 #endif
17241 #endif
17242 
17243 #if defined(Windows)
17244         if(unbuffered)
17245         {
17246             hand=CreateFile(dummyfile[xx],
17247           GENERIC_READ|GENERIC_WRITE,
17248               FILE_SHARE_WRITE|FILE_SHARE_READ,
17249           NULL,OPEN_EXISTING,FILE_FLAG_NO_BUFFERING|
17250           FILE_FLAG_WRITE_THROUGH|FILE_FLAG_POSIX_SEMANTICS,
17251           NULL);
17252         }
17253 #endif
17254     if((fd = I_OPEN(dummyfile[xx], ((int)flags),0))<0)
17255     {
17256         client_error=errno;
17257         if(distributed && client_iozone)
17258             send_stop();
17259         perror(dummyfile[xx]);
17260         exit(156);
17261     }
17262 #ifdef ASYNC_IO
17263     if(async_flag)
17264         async_init(&gc,fd,direct_flag);
17265 #endif
17266 
17267 #ifdef VXFS
17268     if(direct_flag)
17269     {
17270         ioctl(fd,VX_SETCACHE,VX_DIRECT);
17271         ioctl(fd,VX_GETCACHE,&test_foo);
17272         if(test_foo == 0)
17273         {
17274             if(!client_iozone)
17275               printf("\nVxFS advanced setcache feature not available.\n");
17276             exit(3);
17277         }
17278     }
17279 #endif
17280 #if defined(solaris)
17281         if(direct_flag)
17282         {
17283                 test_foo = directio(fd, DIRECTIO_ON);
17284                 if(test_foo != 0)
17285                 {
17286                         if(!client_iozone)
17287                           printf("\ndirectio not available.\n");
17288                         exit(3);
17289                 }
17290         }
17291 #endif
17292 
17293     if(mmapflag)
17294     {
17295         maddr=(char *)initfile(fd,(numrecs64*reclen),0,PROT_READ);
17296     }
17297     child_stat = (struct child_stats *)&shmaddr[xx];
17298     child_stat->throughput = 0;
17299     child_stat->actual = 0;
17300     if(debug1)
17301     {
17302        if(use_thread)
17303 #ifdef NO_PRINT_LLD
17304         printf("\nStarting child %ld\n",xx);
17305 #else
17306         printf("\nStarting child %lld\n",xx);
17307 #endif
17308        else
17309 #ifdef NO_PRINT_LLD
17310         printf("\nStarting process %d slot %ld\n",getpid(),xx);
17311 #else
17312         printf("\nStarting process %d slot %lld\n",getpid(),xx);
17313 #endif
17314         
17315     }
17316     /*****************/
17317     /* Children only */
17318     /*****************/
17319     if(fetchon)
17320         fetchit(nbuff,reclen);
17321         if(Q_flag)
17322         {
17323                 sprintf(tmpname,"Child_%d_randrol.dat",(int)xx);
17324                 thread_randrfd=fopen(tmpname,"a");
17325                 if(thread_randrfd==0)
17326                 {
17327             client_error=errno;
17328             if(distributed && client_iozone)
17329                 send_stop();
17330                         printf("Unable to open %s\n",tmpname);
17331                         exit(40);
17332                 }
17333         fprintf(thread_randrfd,"Offset in Kbytes   Latency in microseconds  Transfer size in bytes\n");
17334         }
17335     if(L_flag)
17336     {
17337         sprintf(tmpname,"Child_%d.log",(int)xx);
17338         thread_Lwqfd=fopen(tmpname,"a");
17339         if(thread_Lwqfd==0)
17340         {
17341             client_error=errno;
17342             if(distributed && client_iozone)
17343                 send_stop();
17344             printf("Unable to open %s\n",tmpname);
17345             exit(40);
17346         }
17347         get_date(now_string);
17348         fprintf(thread_Lwqfd,"%-25s %s","Random read start: ",
17349             now_string);
17350     }
17351     child_stat=(struct child_stats *)&shmaddr[xx];
17352     child_stat->flag = CHILD_STATE_READY;
17353         if(distributed && client_iozone)
17354         {
17355                 tell_master_ready(chid);
17356                 wait_for_master_go(chid);
17357         }
17358         else
17359         {
17360                 while(child_stat->flag!=CHILD_STATE_BEGIN)   /* Wait for signal from parent */
17361                         Poll((long long)1);
17362         }
17363     starttime1 = time_so_far();
17364     if(cpuutilflag)
17365     {
17366         walltime = starttime1;
17367         cputime = cputime_so_far();
17368     }
17369 
17370 #ifdef MERSENNE
17371         init_by_array64(init, length);
17372 #else
17373 #ifdef bsd4_2
17374         srand(0);
17375 #else
17376 #ifdef Windows
17377         srand(0);
17378 #else
17379     srand48(0);
17380 #endif
17381 #endif
17382 #endif
17383     if(file_lock)
17384         if(mylockf((int) fd, (int) 1, (int)1)!=0)
17385             printf("File lock for read failed. %d\n",errno);
17386     for(i=0; i<numrecs64; i++) {
17387         if(compute_flag)
17388             compute_val+=do_compute(delay);
17389         if(*stop_flag)
17390         {
17391             if(debug1)
17392                 printf("\n(%ld) Stopped by another 2\n", (long)xx);
17393             break;
17394         }
17395         if(purge)
17396             purgeit(nbuff,reclen);
17397         if (recnum) {
17398             current_offset = reclen * (long long)recnum[i];
17399                 } else {
17400 #ifdef MERSENNE
17401                    big_rand = genrand64_int64();
17402            current_offset = (off64_t)reclen * (big_rand%numrecs64);
17403 #else
17404 #ifdef bsd4_2
17405            rand1=(long long)rand();
17406            rand2=(long long)rand();
17407            rand3=(long long)rand();
17408            big_rand=(rand1<<32)|(rand2<<16)|(rand3);
17409            current_offset = (off64_t)reclen * (big_rand%numrecs64);
17410 #else
17411 #ifdef Windows
17412            rand1=(long long)rand();
17413            rand2=(long long)rand();
17414            rand3=(long long)rand();
17415            big_rand=(rand1<<32)|(rand2<<16)|(rand3);
17416            current_offset = (off64_t)reclen * (big_rand%numrecs64);
17417 #else
17418            current_offset = reclen * (lrand48()%numrecs64);
17419 #endif
17420 #endif
17421 #endif
17422         }
17423 
17424         if (!(h_flag || k_flag || mmapflag))
17425         {
17426           if(I_LSEEK( fd, current_offset, SEEK_SET )<0)
17427           {
17428             client_error=errno;
17429             if(distributed && client_iozone)
17430                 send_stop();
17431             perror("lseek");
17432             exit(158);
17433           };
17434         }
17435         if(rlocking)
17436         {
17437             lock_offset=I_LSEEK(fd,0,SEEK_CUR);
17438             mylockr((int) fd, (int) 1, (int)1,
17439               lock_offset, reclen);
17440         }
17441         if(Q_flag || hist_summary || op_rate_flag)
17442         {
17443             traj_offset=I_LSEEK(fd,0,SEEK_CUR);
17444                         thread_qtime_start=time_so_far();
17445         }
17446         if(mmapflag)
17447         {
17448             wmaddr = &maddr[current_offset];
17449             fill_area((long long*)wmaddr,(long long*)nbuff,(long long)reclen);
17450         }
17451         else
17452         {
17453             if(async_flag)
17454             {
17455                 if(no_copy_flag)
17456                   async_read_no_copy(gc, (long long)fd, &buffer1, (current_offset),
17457                      reclen, 0LL,(numrecs64*reclen),depth);
17458                 else
17459                   async_read(gc, (long long)fd, nbuff, (current_offset), reclen,
17460                     0LL,(numrecs64*reclen),depth);
17461             }
17462             else
17463             {
17464               if(read((int)fd, (void*)nbuff, (size_t)reclen) != reclen)
17465               {
17466                 if(*stop_flag)
17467                 {
17468                     if(debug1)
17469                         printf("\n(%ld) Stopped by another 2\n", (long)xx);
17470                     break;
17471                 }
17472 #ifdef NO_PRINT_LLD
17473                 printf("\nError reading block at %ld\n",
17474                      offset); 
17475 #else
17476                 printf("\nError reading block at %lld\n",
17477                      offset); 
17478 #endif
17479                 perror("ranread");
17480                 if (!no_unlink)
17481                 {
17482                    if(check_filename(dummyfile[xx]))
17483                     unlink(dummyfile[xx]);
17484                 }
17485                 child_stat->flag = CHILD_STATE_HOLD;
17486                 exit(160);
17487               }
17488             }
17489         }
17490         if(rlocking)
17491         {
17492             mylockr((int) fd, (int) 0, (int)1,
17493               lock_offset, reclen);
17494         }
17495         save_pos=current_offset/reclen;
17496         current_offset+=reclen;
17497         if(verify){
17498            if(async_flag && no_copy_flag)
17499            {
17500             if(verify_buffer(buffer1,reclen,(off64_t)save_pos,reclen,(long long)pattern,sverify)){
17501                 if (!no_unlink)
17502                 {
17503                    if(check_filename(dummyfile[xx]))
17504                     unlink(dummyfile[xx]);
17505                 }
17506                 child_stat->flag = CHILD_STATE_HOLD;
17507                 exit(161);
17508             }
17509            }
17510            else
17511            {
17512             if(verify_buffer(nbuff,reclen,(off64_t)save_pos,reclen,(long long)pattern,sverify)){
17513                 if (!no_unlink)
17514                 {
17515                    if(check_filename(dummyfile[xx]))
17516                     unlink(dummyfile[xx]);
17517                 }
17518                 child_stat->flag = CHILD_STATE_HOLD;
17519                 exit(162);
17520             }
17521            }
17522         }
17523         if(async_flag && no_copy_flag)
17524             async_release(gc);
17525         ranread_so_far+=reclen/1024;
17526         if(*stop_flag)
17527         {
17528             ranread_so_far-=reclen/1024;
17529         }
17530         if(hist_summary)
17531         {
17532             thread_qtime_stop=time_so_far();
17533             hist_time =(thread_qtime_stop-thread_qtime_start-time_res);
17534             hist_insert(hist_time);
17535         }
17536         if(op_rate_flag)
17537         {
17538             thread_qtime_stop=time_so_far();
17539             desired_op_rate_time = ((double)1.0/(double)op_rate);
17540             actual_rate = (double)(thread_qtime_stop-thread_qtime_start);
17541 /*
17542 printf("Desired rate %g  Actual rate %g Nap %g microseconds\n",desired_op_rate_time,
17543     actual_rate, (desired_op_rate_time-actual_rate));
17544 */
17545             if( actual_rate < desired_op_rate_time)
17546                 my_unap((unsigned long long) ((desired_op_rate_time-actual_rate)*1000000.0 ));
17547         }
17548                 if(Q_flag)
17549                 {
17550                         thread_qtime_stop=time_so_far();
17551 #ifdef NO_PRINT_LLD
17552                         fprintf(thread_randrfd,"%10.1ld %10.0f %10.1ld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
17553 #else
17554                         fprintf(thread_randrfd,"%10.1lld %10.0f %10.1lld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
17555 #endif
17556                 }
17557     }
17558     if(file_lock)
17559         if(mylockf((int) fd,(int)0,(int)1))
17560             printf("Read unlock failed %d\n",errno);
17561 #ifdef ASYNC_IO
17562     if(async_flag)
17563     {
17564         end_async(gc);
17565         gc=0;
17566     }
17567 #endif
17568     if(include_flush)
17569     {
17570         if(mmapflag)
17571         {
17572             msync(maddr,(size_t)(numrecs64*reclen),MS_SYNC);
17573         }else
17574             fsync(fd);
17575     }
17576     if(include_close)
17577     {   
17578         if(mmapflag)
17579         {
17580             mmap_end(maddr,(unsigned long long)numrecs64*reclen);
17581         }
17582         close(fd);
17583     }
17584     temp_time = time_so_far();
17585     child_stat=(struct child_stats *)&shmaddr[xx];
17586     child_stat->throughput = ((temp_time - starttime1)-time_res)
17587         -compute_val;
17588     if(child_stat->throughput < (double).000001) 
17589     {
17590         child_stat->throughput= time_res;
17591         if(rec_prob < reclen)
17592             rec_prob = reclen;
17593         res_prob=1;
17594     }
17595     if(OPS_flag){
17596        ranread_so_far=(ranread_so_far*1024)/reclen;
17597     }
17598     child_stat->throughput = ranread_so_far/child_stat->throughput;
17599     child_stat->actual = ranread_so_far;
17600     if(!xflag)
17601     {
17602         *stop_flag=1;
17603         if(distributed && client_iozone)
17604             send_stop();
17605     }
17606         if(cdebug)
17607     {
17608                 fprintf(newstdout,"Child %d: throughput %f actual %f \n",(int)chid,child_stat->throughput,
17609                         child_stat->actual);
17610         fflush(newstdout);
17611     }
17612     if(cpuutilflag)
17613     {
17614         cputime = cputime_so_far() - cputime;
17615         if (cputime < cputime_res)
17616             cputime = 0.0;
17617         child_stat->cputime = cputime;
17618         walltime = time_so_far() - walltime;
17619         child_stat->walltime = walltime;
17620     }
17621         if(distributed && client_iozone)
17622                 tell_master_stats(THREAD_RANDOM_READ_TEST, chid, child_stat->throughput,
17623                         child_stat->actual,
17624             child_stat->cputime, child_stat->walltime,
17625             (char)*stop_flag,
17626                         (long long)CHILD_STATE_HOLD);
17627     child_stat->flag = CHILD_STATE_HOLD;    /* Tell parent I'm done */
17628     if(!include_close)
17629     {
17630         if(mmapflag)
17631         {
17632             msync(maddr,(size_t)(numrecs64*reclen),MS_SYNC);
17633             mmap_end(maddr,(unsigned long long)numrecs64*reclen);
17634         }else
17635             fsync(fd);
17636         close(fd);
17637     }
17638         if(Q_flag && (thread_randrfd !=0) )
17639                 fclose(thread_randrfd);
17640     free(dummyfile[xx]);
17641     if(debug1)
17642 #ifdef NO_PRINT_LLD
17643         printf("\nChild finished %ld\n",xx);
17644 #else
17645         printf("\nChild finished %lld\n",xx);
17646 #endif
17647 
17648     if(L_flag)
17649     {
17650         get_date(now_string);
17651         fprintf(thread_Lwqfd,"%-25s %s","Random read finished: ",now_string);
17652         fclose(thread_Lwqfd);
17653     }
17654     if(recnum)
17655         free(recnum);
17656     if(hist_summary)
17657        dump_hist("Random Read",(int)xx);
17658     if(distributed && client_iozone)
17659         return(0);
17660 #ifdef NO_THREADS
17661     exit(0);
17662 #else
17663     if(use_thread)
17664         thread_exit();
17665     else
17666         exit(0);
17667 #endif
17668 return(0);
17669 }
17670 
17671 /************************************************************************/
17672 /* Thread random write test                         */
17673 /************************************************************************/
17674 #ifdef HAVE_ANSIC_C
17675 void *
17676 thread_ranwrite_test(void *x)
17677 #else
17678 void *
17679 thread_ranwrite_test( x)
17680 #endif
17681 {
17682 
17683     struct child_stats *child_stat;
17684     double starttime1 = 0;
17685     double temp_time;
17686     double walltime, cputime;
17687     double compute_val = (double)0;
17688     float delay = (double)0;
17689     double thread_qtime_stop,thread_qtime_start;
17690     double hist_time;
17691     double desired_op_rate_time;
17692     double actual_rate;
17693     off64_t traj_offset;
17694     off64_t current_offset=0;
17695     long long flags;
17696     long long w_traj_bytes_completed;
17697     long long w_traj_ops_completed;
17698     int fd;
17699     long long recs_per_buffer;
17700     long long stopped,i;
17701     off64_t written_so_far, read_so_far, re_written_so_far,re_read_so_far;
17702     long long xx,xx2;
17703     char *dummyfile [MAXSTREAMS];           /* name of dummy file     */
17704     char *nbuff=0;
17705     char *maddr=0;
17706     char *wmaddr=0;
17707     char *free_addr=0;
17708     int anwser,bind_cpu,wval;
17709     off64_t filebytes64;
17710     off64_t lock_offset=0;
17711     char tmpname[256];
17712     char now_string[30];
17713     FILE *thread_randwqfd=0;
17714     FILE *thread_Lwqfd=0;
17715     long long *recnum = 0;
17716 #if defined(VXFS) || defined(solaris)
17717     int test_foo = 0;
17718 #endif
17719 #if defined (bsd4_2) || defined(Windows)
17720     long long rand1,rand2,rand3;
17721 #endif
17722     unsigned long long big_rand;
17723 
17724 #ifdef ASYNC_IO
17725     struct cache *gc=0;
17726 
17727 #else
17728     long long *gc=0;
17729 #endif
17730 #ifdef MERSENNE
17731         unsigned long long init[4]={0x12345ULL, 0x23456ULL, 0x34567ULL, 0x45678ULL}, length=4;
17732 #endif
17733 
17734     if(compute_flag)
17735         delay=compute_time;
17736     hist_time=thread_qtime_stop=thread_qtime_start=0;
17737     traj_offset=walltime=cputime=0;
17738     anwser=bind_cpu=0;
17739     filebytes64 = numrecs64*reclen;
17740     written_so_far=read_so_far=re_written_so_far=re_read_so_far=0;
17741     w_traj_bytes_completed=w_traj_ops_completed=0;
17742     recs_per_buffer = cache_size/reclen ;
17743 #ifdef MERSENNE
17744         init_by_array64(init, length);
17745 #else
17746 #ifdef bsd4_2
17747         srand(0);
17748 #else
17749 #ifdef Windows
17750         srand(0);
17751 #else
17752         srand48(0);
17753 #endif
17754 #endif
17755 #endif
17756         recnum = (long long *) malloc(sizeof(*recnum)*numrecs64);
17757         if (recnum){
17758              /* pre-compute random sequence based on 
17759         Fischer-Yates (Knuth) card shuffle */
17760             for(i = 0; i < numrecs64; i++){
17761                 recnum[i] = i;
17762             }
17763             for(i = 0; i < numrecs64; i++) {
17764                 long long tmp = recnum[i];
17765 #ifdef MERSENNE
17766                big_rand = genrand64_int64();
17767 #else
17768 #ifdef bsd4_2
17769                rand1=(long long)rand();
17770                rand2=(long long)rand();
17771                rand3=(long long)rand();
17772                big_rand=(rand1<<32)|(rand2<<16)|(rand3);
17773 #else
17774 #ifdef Windows
17775                rand1=(long long)rand();
17776                rand2=(long long)rand();
17777                rand3=(long long)rand();
17778                big_rand=(rand1<<32)|(rand2<<16)|(rand3);
17779 #else
17780                big_rand = lrand48();
17781 #endif
17782 #endif
17783 #endif
17784                big_rand = big_rand%numrecs64;
17785                tmp = recnum[i];
17786                recnum[i] = recnum[big_rand];
17787                recnum[big_rand] = tmp;
17788             }
17789         }
17790     else
17791     {
17792         fprintf(stderr,"Random uniqueness fallback.\n");
17793     }
17794 #ifdef NO_THREADS
17795     xx=chid;
17796 #else
17797     if(use_thread)
17798     {
17799         xx = (long long)((long)x);
17800     }
17801     else
17802     {
17803         xx=chid;
17804     }
17805 #endif
17806 #ifndef NO_THREADS
17807 #if defined( _HPUX_SOURCE ) || defined ( linux )
17808     if(ioz_processor_bind)
17809     {
17810          bind_cpu=(begin_proc+(int)xx)%num_processors;
17811 #if defined(_HPUX_SOURCE)
17812          pthread_processor_bind_np(PTHREAD_BIND_FORCED_NP,
17813                          (pthread_spu_t *)&anwser, (pthread_spu_t)bind_cpu, pthread_self());
17814 #else
17815      cpu_set_t cpuset;
17816 
17817      CPU_ZERO(&cpuset);
17818      CPU_SET(bind_cpu, &cpuset);
17819 
17820      pthread_setaffinity_np(pthread_self(), sizeof(cpuset),&cpuset);
17821 #endif
17822         my_nap(40); /* Switch to new cpu */
17823     }
17824 #endif
17825 #endif
17826     if(use_thread)
17827         nbuff=barray[xx];
17828     else
17829         nbuff=buffer;
17830     if(debug1 )
17831     {
17832        if(use_thread)
17833 #ifdef NO_PRINT_LLD
17834         printf("\nStarting child %ld\n",xx);
17835 #else
17836         printf("\nStarting child %lld\n",xx);
17837 #endif
17838        else
17839 #ifdef NO_PRINT_LLD
17840         printf("\nStarting process %d slot %ld\n",getpid(),xx);
17841 #else
17842         printf("\nStarting process %d slot %lld\n",getpid(),xx);
17843 #endif
17844         
17845     }
17846     dummyfile[xx]=(char *)malloc((size_t)MAXNAMESIZE);
17847     xx2=xx;
17848     if(share_file)
17849         xx2=(long long)0;
17850     if(mfflag)
17851     {
17852 #ifdef NO_PRINT_LLD
17853         sprintf(dummyfile[xx],"%s",filearray[xx2]);
17854 #else
17855         sprintf(dummyfile[xx],"%s",filearray[xx2]);
17856 #endif
17857     }
17858     else
17859     {
17860 #ifdef NO_PRINT_LLD
17861         sprintf(dummyfile[xx],"%s.DUMMY.%ld",filearray[xx2],xx2);
17862 #else
17863         sprintf(dummyfile[xx],"%s.DUMMY.%lld",filearray[xx2],xx2);
17864 #endif
17865     }
17866     /*****************/
17867     /* Children only */
17868     /*******************************************************************/
17869     /* Random write throughput performance test. **********************/
17870     /*******************************************************************/
17871     if(oflag)
17872         flags=O_RDWR|O_SYNC|O_CREAT;
17873     else
17874         flags=O_RDWR|O_CREAT;
17875 #if defined(O_DSYNC)
17876     if(odsync)
17877         flags |= O_DSYNC;
17878 #endif
17879 #if defined(_HPUX_SOURCE) || defined(linux)
17880     if(read_sync)
17881         flags |=O_RSYNC|O_SYNC;
17882 #endif
17883 
17884 #if ! defined(DONT_HAVE_O_DIRECT)
17885 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
17886     if(direct_flag)
17887         flags |=O_DIRECT;
17888 #endif
17889 #if defined(TRU64)
17890     if(direct_flag)
17891         flags |=O_DIRECTIO;
17892 #endif
17893 #endif
17894 #if defined(Windows)
17895         if(unbuffered)
17896         {
17897             hand=CreateFile(dummyfile[xx],
17898           GENERIC_READ|GENERIC_WRITE,
17899               FILE_SHARE_WRITE|FILE_SHARE_READ,
17900           NULL,OPEN_EXISTING,FILE_FLAG_NO_BUFFERING|
17901           FILE_FLAG_WRITE_THROUGH|FILE_FLAG_POSIX_SEMANTICS,
17902           NULL);
17903         }
17904 #endif
17905     if((fd = I_OPEN(dummyfile[xx], ((int)flags),0640))<0)
17906     {
17907         client_error=errno;
17908         if(distributed && client_iozone)
17909             send_stop();
17910         printf("\nCan not open temp file: %s\n", 
17911             filename);
17912         perror("open");
17913         exit(125);
17914     }
17915 #ifdef VXFS
17916     if(direct_flag)
17917     {
17918         ioctl(fd,VX_SETCACHE,VX_DIRECT);
17919         ioctl(fd,VX_GETCACHE,&test_foo);
17920         if(test_foo == 0)
17921         {
17922             if(!client_iozone)
17923               printf("\nVxFS advanced setcache feature not available.\n");
17924             exit(3);
17925         }
17926     }
17927 #endif
17928 #if defined(solaris)
17929         if(direct_flag)
17930         {
17931                 test_foo = directio(fd, DIRECTIO_ON);
17932                 if(test_foo != 0)
17933                 {
17934                         if(!client_iozone)
17935                           printf("\ndirectio not available.\n");
17936                         exit(3);
17937                 }
17938         }
17939 #endif
17940 #ifdef ASYNC_IO
17941     if(async_flag)
17942         async_init(&gc,fd,direct_flag);
17943 #endif
17944     if(mmapflag)
17945     {
17946         maddr=(char *)initfile(fd,(filebytes64),1,PROT_READ|PROT_WRITE);
17947     }
17948     if(reclen < cache_size )
17949     {
17950         recs_per_buffer = cache_size/reclen ;
17951         nbuff=&nbuff[(xx%recs_per_buffer)*reclen];
17952     }
17953     if(fetchon)         /* Prefetch into processor cache */
17954         fetchit(nbuff,reclen);
17955 
17956     child_stat = (struct child_stats *)&shmaddr[xx];    
17957     child_stat->throughput = 0;
17958     child_stat->actual = 0;
17959     child_stat->flag=CHILD_STATE_READY; /* Tell parent child is ready to go */
17960     if(distributed && client_iozone)
17961     {
17962         tell_master_ready(chid);
17963         wait_for_master_go(chid);
17964     }
17965     else
17966     {
17967         while(child_stat->flag!=CHILD_STATE_BEGIN)   /* Wait for signal from parent */
17968             Poll((long long)1);
17969     }
17970     written_so_far=0;
17971     child_stat = (struct child_stats *)&shmaddr[xx];
17972     child_stat->actual = 0;
17973     child_stat->throughput = 0;
17974     stopped=0;
17975     if(file_lock)
17976         if(mylockf((int) fd, (int) 1, (int)0) != 0)
17977             printf("File lock for write failed. %d\n",errno);
17978     if(Q_flag)
17979     {
17980         sprintf(tmpname,"Child_%d_randwol.dat",(int)xx);
17981         thread_randwqfd=fopen(tmpname,"a");
17982         if(thread_randwqfd==0)
17983         {
17984             client_error=errno;
17985             if(distributed && client_iozone)
17986                 send_stop();
17987             printf("Unable to open %s\n",tmpname);
17988             exit(40);
17989         }
17990         fprintf(thread_randwqfd,"Offset in Kbytes   Latency in microseconds  Transfer size in bytes\n");
17991     }
17992     if(L_flag)
17993     {
17994         sprintf(tmpname,"Child_%d.log",(int)xx);
17995         thread_Lwqfd=fopen(tmpname,"a");
17996         if(thread_Lwqfd==0)
17997         {
17998             client_error=errno;
17999             if(distributed && client_iozone)
18000                 send_stop();
18001             printf("Unable to open %s\n",tmpname);
18002             exit(40);
18003         }
18004         get_date(now_string);
18005         fprintf(thread_Lwqfd,"%-25s %s","Random write start: ",
18006             now_string);
18007     }
18008     if((verify && !no_copy_flag) || dedup || dedup_interior)
18009         fill_buffer(nbuff,reclen,(long long)pattern,sverify,(long long)0);
18010     starttime1 = time_so_far();
18011     if(cpuutilflag)
18012     {
18013         walltime = starttime1;
18014         cputime = cputime_so_far();
18015     }
18016     for(i=0; i<numrecs64; i++){
18017         if(compute_flag)
18018             compute_val+=do_compute(delay);
18019         if (recnum) {
18020             current_offset = reclen * (long long)recnum[i];
18021                 } else {
18022 #ifdef bsd4_2
18023            rand1=rand();
18024            rand2=rand();
18025            rand3=rand();
18026            big_rand=(rand1<<32)|(rand2<<16)|(rand3);
18027            current_offset = (off64_t)reclen * (big_rand%numrecs64);
18028 #else
18029 #ifdef Windows
18030            rand1=rand();
18031            rand2=rand();
18032            rand3=rand();
18033            big_rand=(rand1<<32)|(rand2<<16)|(rand3);
18034            current_offset = (off64_t)reclen * (big_rand%numrecs64);
18035 #else
18036            current_offset = reclen * (lrand48()%numrecs64);
18037 #endif
18038 #endif
18039         }
18040 
18041         if (!(h_flag || k_flag || mmapflag))
18042         {
18043           if(I_LSEEK( fd, current_offset, SEEK_SET )<0)
18044           {
18045             client_error=errno;
18046             if(distributed && client_iozone)
18047                 send_stop();
18048             perror("lseek");
18049             exit(158);
18050           };
18051         }
18052         if(Q_flag || hist_summary || op_rate_flag)
18053         {
18054             traj_offset=I_LSEEK(fd,0,SEEK_CUR);
18055                         thread_qtime_start=time_so_far();
18056         }
18057         if(rlocking)
18058         {
18059             lock_offset=I_LSEEK(fd,0,SEEK_CUR);
18060             mylockr((int) fd, (int) 1, (int)0,
18061               lock_offset, reclen);
18062         }
18063         if((verify && !no_copy_flag) || dedup || dedup_interior)
18064             fill_buffer(nbuff,reclen,(long long)pattern,sverify,(long long)(current_offset/reclen));
18065         if(*stop_flag && !stopped){
18066             if(include_flush)
18067             {
18068                 if(mmapflag)
18069                     msync(maddr,(size_t)filebytes64,MS_SYNC);
18070                 else
18071                     fsync(fd);
18072             }
18073             child_stat->throughput = 
18074                 (time_so_far() - starttime1)-time_res;
18075             if(child_stat->throughput < (double).000001) 
18076             {
18077                 child_stat->throughput = time_res;
18078                 if(rec_prob < reclen)
18079                     rec_prob = reclen;
18080                 res_prob=1;
18081             }
18082 
18083             if(OPS_flag){
18084                /*written_so_far=(written_so_far*1024)/reclen;*/
18085                written_so_far=w_traj_ops_completed;
18086             }
18087             child_stat->throughput = 
18088               (double)written_so_far/child_stat->throughput;
18089             child_stat->actual = (double)written_so_far;
18090             if(debug1)
18091             {
18092                 printf("\n(%ld) Stopped by another\n", (long)xx);
18093             }
18094             stopped=1;
18095         }
18096         if(purge)
18097             purgeit(nbuff,reclen);
18098         if(Q_flag || hist_summary)
18099         {
18100             thread_qtime_start=time_so_far();
18101         }
18102 again:      
18103         if(mmapflag)
18104         {
18105             wmaddr = &maddr[current_offset];
18106             fill_area((long long*)nbuff,(long long*)wmaddr,(long long)reclen);
18107             if(!mmapnsflag)
18108             {
18109               if(mmapasflag)
18110                 msync(wmaddr,(size_t)reclen,MS_ASYNC);
18111               if(mmapssflag)
18112                 msync(wmaddr,(size_t)reclen,MS_SYNC);
18113             }
18114         }
18115         else
18116         {
18117            if(async_flag)
18118            {
18119                  if(no_copy_flag)
18120                  {
18121                 free_addr=nbuff=(char *)malloc((size_t)reclen+page_size);
18122                 nbuff=(char *)(((long)nbuff+(long)page_size) & (long)~(page_size-1));
18123                 if(verify || dedup || dedup_interior)
18124                     fill_buffer(nbuff,reclen,(long long)pattern,sverify,(long long)(current_offset/reclen));
18125                     async_write_no_copy(gc, (long long)fd, nbuff, reclen, (current_offset), depth,free_addr);
18126                  }
18127                  else
18128                 async_write(gc, (long long)fd, nbuff, reclen, current_offset, depth);
18129            }
18130            else
18131            {
18132               wval = write(fd, nbuff, (size_t) reclen);
18133               if(wval != reclen)
18134               {
18135             if(*stop_flag && !stopped){
18136                 if(include_flush)
18137                 {
18138                     if(mmapflag)
18139                         msync(maddr,(size_t)filebytes64,MS_SYNC);
18140                     else
18141                         fsync(fd);
18142                 }
18143                 temp_time = time_so_far();
18144                 child_stat->throughput = 
18145                     (temp_time - starttime1)-time_res;
18146                 if(child_stat->throughput < (double).000001) 
18147                 {
18148                     child_stat->throughput= time_res;
18149                     if(rec_prob < reclen)
18150                         rec_prob = reclen;
18151                     res_prob=1;
18152                 }
18153 
18154                 if(OPS_flag){
18155                    /*written_so_far=(written_so_far*1024)/reclen;*/
18156                    written_so_far=w_traj_ops_completed;
18157                 }
18158                 child_stat->throughput = 
18159                   (double)written_so_far/child_stat->throughput;
18160                 child_stat->actual = (double)written_so_far;
18161                 if(debug1)
18162                 {
18163                     printf("\n(%ld) Stopped by another\n", (long)xx);
18164                 }
18165                 stopped=1;
18166                 goto again;
18167             }
18168             /* Note: Writer must finish even though told
18169                to stop. Otherwise the readers will fail.
18170                The code will capture bytes transfered
18171                before told to stop but let the writer
18172                complete.
18173             */
18174 #ifdef NO_PRINT_LLD
18175                 printf("\nError writing block %ld, fd= %d\n", i,
18176                  fd);
18177 #else
18178                 printf("\nError writing block %lld, fd= %d\n", i,
18179                  fd);
18180 #endif
18181             if(wval==-1)
18182                 perror("write");
18183             if (!no_unlink)
18184             {
18185                     if(check_filename(dummyfile[xx]))
18186                 unlink(dummyfile[xx]);
18187             }
18188             child_stat->flag = CHILD_STATE_HOLD;
18189                 exit(127);
18190               }
18191             }
18192         }
18193         if(rlocking)
18194         {
18195             mylockr((int) fd, (int) 0, (int)0,
18196               lock_offset, reclen);
18197         }
18198         if(hist_summary)
18199         {
18200             thread_qtime_stop=time_so_far();
18201             hist_time =(thread_qtime_stop-thread_qtime_start-time_res);
18202             hist_insert(hist_time);
18203         }
18204         if(op_rate_flag)
18205         {
18206             thread_qtime_stop=time_so_far();
18207             desired_op_rate_time = ((double)1.0/(double)op_rate);
18208             actual_rate = (double)(thread_qtime_stop-thread_qtime_start);
18209 /*
18210 printf("Desired rate %g  Actual rate %g Nap %g microseconds\n",desired_op_rate_time,
18211     actual_rate, (desired_op_rate_time-actual_rate));
18212 */
18213             if( actual_rate < desired_op_rate_time)
18214                 my_unap((unsigned long long) ((desired_op_rate_time-actual_rate)*1000000.0 ));
18215         }
18216         if(Q_flag)
18217         {
18218             thread_qtime_stop=time_so_far();
18219 #ifdef NO_PRINT_LLD
18220             fprintf(thread_randwqfd,"%10.1ld %10.0f %10.1ld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
18221 #else
18222             fprintf(thread_randwqfd,"%10.1lld %10.0f %10.1lld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
18223 #endif
18224         }
18225         w_traj_ops_completed++;
18226         w_traj_bytes_completed+=reclen;
18227         written_so_far+=reclen/1024;
18228         if(*stop_flag)
18229         {
18230             written_so_far-=reclen/1024;
18231             w_traj_bytes_completed-=reclen;
18232         }
18233     }
18234     
18235 
18236     if(file_lock)
18237         if(mylockf((int) fd, (int) 0, (int)0))
18238             printf("Write unlock failed. %d\n",errno);
18239     
18240 #ifdef ASYNC_IO
18241     if(async_flag)
18242     {
18243         end_async(gc);
18244         gc=0;
18245     }
18246 #endif
18247     if(!xflag)
18248     {
18249         *stop_flag=1;
18250         if(distributed && client_iozone)
18251             send_stop();
18252     }
18253     
18254     if(include_flush)
18255     {
18256         if(mmapflag)
18257             msync(maddr,(size_t)filebytes64,MS_SYNC);
18258         else
18259             fsync(fd);
18260     }
18261     if(include_close)
18262     {
18263         if(mmapflag)
18264             mmap_end(maddr,(unsigned long long)filebytes64);
18265         close(fd);
18266     }
18267     if(!stopped){
18268         temp_time = time_so_far();
18269         child_stat->throughput = ((temp_time - starttime1)-time_res)
18270             -compute_val;
18271         if(child_stat->throughput < (double).000001) 
18272         {
18273             child_stat->throughput= time_res;
18274             if(rec_prob < reclen)
18275                 rec_prob = reclen;
18276             res_prob=1;
18277         }
18278 
18279         if(OPS_flag){
18280            /*written_so_far=(written_so_far*1024)/reclen;*/
18281            written_so_far=w_traj_ops_completed;
18282         }
18283         child_stat->throughput =
18284             (double)written_so_far/child_stat->throughput;
18285         child_stat->actual = (double)written_so_far;
18286     }
18287     child_stat->flag = CHILD_STATE_HOLD; /* Tell parent I'm done */
18288         if(cdebug)
18289     {
18290                 fprintf(newstdout,"Child %d: throughput %f actual %f \n",(int)chid,child_stat->throughput,
18291                         child_stat->actual);
18292         fflush(newstdout);
18293     }
18294     if(cpuutilflag)
18295     {
18296         cputime = cputime_so_far() - cputime;
18297         if (cputime < cputime_res)
18298             cputime = 0.0;
18299         child_stat->cputime = cputime;
18300         walltime = time_so_far() - walltime;
18301         child_stat->walltime = walltime;
18302     }
18303         if(distributed && client_iozone)
18304                 tell_master_stats(THREAD_RANDOM_WRITE_TEST, chid, child_stat->throughput,
18305                         child_stat->actual,
18306             child_stat->cputime, child_stat->walltime,
18307             (char)*stop_flag,
18308                         (long long)CHILD_STATE_HOLD);
18309     stopped=0;
18310     /*******************************************************************/
18311     /* End random write performance test. ******************************/
18312     /*******************************************************************/
18313     if(debug1)
18314 #ifdef NO_PRINT_LLD
18315         printf("\nChild finished %ld\n",xx);
18316 #else
18317         printf("\nChild finished %lld\n",xx);
18318 #endif
18319     if(!include_close)
18320     {
18321         if(mmapflag)
18322         {
18323             msync(maddr,(size_t)numrecs64*reclen,MS_SYNC); /*Clean up before read starts running*/ 
18324             mmap_end(maddr,(unsigned long long)numrecs64*reclen);
18325         }else
18326             fsync(fd);
18327             
18328         close(fd);
18329     }
18330     if(Q_flag && (thread_randwqfd !=0) )
18331         fclose(thread_randwqfd);
18332     free(dummyfile[xx]);
18333 
18334     if(L_flag)
18335     {
18336         get_date(now_string);
18337         fprintf(thread_Lwqfd,"%-25s %s","Random write finished: ",
18338             now_string);
18339         fclose(thread_Lwqfd);
18340     }
18341     if(recnum)
18342         free(recnum);
18343     if(hist_summary)
18344        dump_hist("Random Write",(int)xx);
18345     if(distributed && client_iozone)
18346         return(0);
18347 #ifdef NO_THREADS
18348     exit(0);
18349 #else
18350     if(use_thread)
18351         thread_exit();
18352     else
18353         exit(0);
18354 #endif
18355 return(0);
18356 }
18357 
18358 /************************************************************************/
18359 /* Thread cleanup test                              */
18360 /* This is not a measurement. It is a mechanism to cleanup all of the   */
18361 /* temporary files that were being used. This becomes very important    */
18362 /* when testing multiple clients over a network :-)                     */
18363 /************************************************************************/
18364 #ifdef HAVE_ANSIC_C
18365 void *
18366 thread_cleanup_test(void *x)
18367 #else
18368 void *
18369 thread_cleanup_test(x)
18370 #endif
18371 {
18372     long long xx;
18373     struct child_stats *child_stat;
18374     char *dummyfile[MAXSTREAMS];           /* name of dummy file     */
18375 
18376     
18377 #ifdef NO_THREADS
18378     xx=chid;
18379 #else
18380     if(use_thread)
18381         xx = (long long)((long)x);
18382     else
18383     {
18384         xx=chid;
18385     }
18386 #endif
18387     dummyfile[xx]=(char *)malloc((size_t)MAXNAMESIZE);
18388     if(mfflag)
18389     {
18390 #ifdef NO_PRINT_LLD
18391         sprintf(dummyfile[xx],"%s",filearray[xx]);
18392 #else
18393         sprintf(dummyfile[xx],"%s",filearray[xx]);
18394 #endif
18395     }
18396     else
18397     {
18398 #ifdef NO_PRINT_LLD
18399         sprintf(dummyfile[xx],"%s.DUMMY.%ld",filearray[xx],xx);
18400 #else
18401         sprintf(dummyfile[xx],"%s.DUMMY.%lld",filearray[xx],xx);
18402 #endif
18403     }
18404     if(!no_unlink)
18405     {
18406         if(check_filename(dummyfile[xx]))
18407         unlink(dummyfile[xx]);
18408     }
18409 
18410     child_stat = (struct child_stats *)&shmaddr[xx];
18411     /*****************/
18412     /* Children only */
18413     /*****************/
18414     child_stat=(struct child_stats *)&shmaddr[xx];
18415     child_stat->flag = CHILD_STATE_READY;
18416     if(distributed && client_iozone)
18417         {
18418         tell_master_ready(chid);
18419                 wait_for_master_go(chid);
18420         }
18421         else
18422         {
18423                 while(child_stat->flag!=CHILD_STATE_BEGIN)   /* Wait for signal from parent */
18424                         Poll((long long)1);
18425         }
18426 
18427     *stop_flag=1;
18428     if(distributed && client_iozone)
18429         send_stop();
18430         if(distributed && client_iozone)
18431                 tell_master_stats(THREAD_CLEANUP_TEST, chid, child_stat->throughput,
18432                         child_stat->actual,
18433             child_stat->cputime, child_stat->walltime,
18434             (char)*stop_flag,
18435                         (long long)CHILD_STATE_HOLD);
18436     child_stat->flag = CHILD_STATE_HOLD;    /* Tell parent I'm done */
18437     free(dummyfile[xx]);
18438 
18439     if(distributed && client_iozone)
18440         return(0);
18441 #ifdef NO_THREADS
18442     exit(0);
18443 #else
18444     if(use_thread)
18445         thread_exit();
18446     else
18447         exit(0);
18448 #endif
18449 return(0);
18450 }
18451 
18452 
18453 /************************************************************************/
18454 /* mythread_create() Internal routine that calls pthread_create()   */
18455 /************************************************************************/
18456 #ifndef NO_THREADS
18457 #ifdef HAVE_ANSIC_C
18458 long long 
18459 mythread_create( void *(*func)(void *),void *x)
18460 #else
18461 long long 
18462 mythread_create( func,x)
18463 void *(*func)(void *);
18464 void *x;
18465 #endif
18466 {
18467     pthread_t ts;
18468     pthread_attr_t attr;
18469     int xx;
18470     int *yy;
18471 #ifdef _64BIT_ARCH_
18472     long long meme;
18473     meme = (long long)x;
18474 #else
18475     long meme;
18476     meme = (long)x;
18477 #endif
18478     yy=(int *)x;
18479 
18480 
18481 #ifdef OSFV3
18482     
18483     xx=(int )pthread_create(&ts, pthread_attr_default,
18484         func, (void *)yy);
18485 
18486 #else
18487     pthread_attr_init(&attr);
18488     xx=(int )pthread_create((pthread_t *)&ts, (pthread_attr_t *) &attr,
18489         func, (void *)yy);
18490 #endif
18491     bcopy(&ts,&p_childids[meme],sizeof(pthread_t));
18492     if(xx < (int)0)
18493         printf("Thread create failed. Returned %d Errno = %d\n",xx,errno);
18494     if(debug1 )
18495     {
18496         printf("\nthread created has an id of %lx\n",ts);
18497         printf("meme %ld\n",meme);
18498     }
18499     return((long long)meme);
18500 }
18501 #else
18502 #ifdef HAVE_ANSIC_C
18503 long long 
18504 mythread_create( void *(*func)(void *),void *x)
18505 #else
18506 long long 
18507 mythread_create( func,x)
18508 void *(*func)(void *);
18509 void *x;
18510 #endif
18511 {
18512     printf("This version does not support threads\n");
18513     return(-1);
18514 }
18515 #endif
18516 
18517 /************************************************************************/
18518 /* thread_exit() Internal routine that calls pthread_exit()     */
18519 /************************************************************************/
18520 #ifndef NO_THREADS
18521 #ifdef HAVE_ANSIC_C
18522 int
18523 thread_exit(void)
18524 #else
18525 int
18526 thread_exit()
18527 #endif
18528 {
18529     pthread_exit((void *)NULL);
18530 return(0);
18531 }
18532 #else
18533 #ifdef HAVE_ANSIC_C
18534 int
18535 thread_exit(void)
18536 #else
18537 int
18538 thread_exit()
18539 #endif
18540 {
18541     printf("This version does not support threads\n");
18542     return(-1);
18543 }
18544 #endif
18545 
18546 /************************************************************************/
18547 /* mythread_self() Internal function that calls pthread_self()      */
18548 /************************************************************************/
18549 #ifndef NO_THREADS
18550 #ifdef HAVE_ANSIC_C
18551 pthread_t
18552 mythread_self(void)
18553 #else
18554 pthread_t
18555 mythread_self()
18556 #endif
18557 {
18558     pthread_t xx;
18559     xx = pthread_self();
18560     return(xx);
18561 }
18562 #else
18563 #ifdef HAVE_ANSIC_C
18564 int
18565 mythread_self(void)
18566 #else
18567 int
18568 mythread_self()
18569 #endif
18570 {
18571     printf("This version does not support threads\n");
18572     return(-1);
18573 }
18574 #endif
18575 
18576 /************************************************************************/
18577 /* Internal thread_join routine... calls pthread_join           */
18578 /************************************************************************/
18579 #ifndef NO_THREADS
18580 #ifdef HAVE_ANSIC_C
18581 void *
18582 thread_join( long long tid, void *status) 
18583 #else
18584 void *
18585 thread_join( tid, status) 
18586 long long tid;
18587 void *status;
18588 #endif
18589 {
18590     int xx;
18591     pthread_t eek;
18592     pthread_attr_t foo;
18593 
18594     bcopy(&p_childids[tid],&eek,sizeof(pthread_t));
18595     xx=pthread_join(eek,(void **)&foo);
18596     if(xx<0)
18597         printf("Thread join returned error %d\n",errno);
18598     return(0);
18599 }
18600 #else
18601 #ifdef HAVE_ANSIC_C
18602 void *
18603 thread_join( long long tid, void *status) 
18604 #else
18605 void *
18606 thread_join( tid, status) 
18607 long long tid;
18608 void *status;
18609 #endif
18610 {
18611     printf("This version does not support threads\n");
18612     return((void *)-1);
18613 }
18614 #endif
18615 
18616 
18617 /************************************************************************/
18618 /* Dump the CPU utilization data.                   */
18619 /************************************************************************/
18620 #ifdef HAVE_ANSIC_C
18621 void
18622 dump_throughput_cpu(void)
18623 #else
18624 void
18625 dump_throughput_cpu()
18626 #endif
18627 {
18628     long long x,y,i,j;
18629     char *port;
18630     char *label;
18631     char print_str[300];
18632     x=max_x;
18633     y=max_y;
18634 
18635     port = use_thread ? "threads" : "processes";
18636     printf("\n\"CPU utilization report Y-axis is type of test X-axis is number of %s\"\n",port);
18637     if (bif_flag)
18638     {
18639         sprintf(print_str, "CPU utilization report Y-axis is type of test X-axis is number of %s", port);
18640         do_label(bif_fd, print_str, bif_row++, bif_column);
18641     }
18642     label = OPS_flag ?  "ops/sec" :
18643         MS_flag ? "microseconds/op" : "Kbytes/sec";
18644 #ifdef NO_PRINT_LLD
18645     if(!silent) printf("\"Record size = %ld Kbytes \"\n", reclen/1024);
18646 #else
18647     if(!silent) printf("\"Record size = %lld Kbytes \"\n", reclen/1024);
18648 #endif
18649     if(!silent) printf("\"Output is in CPU%%\"\n\n");
18650     if (bif_flag)
18651     {
18652 #ifdef NO_PRINT_LLD
18653         sprintf(print_str, "Record size = %ld Kbytes", reclen/1024);
18654 #else
18655         sprintf(print_str, "Record size = %lld Kbytes", reclen/1024);
18656 #endif
18657         do_label(bif_fd, print_str, bif_row++, bif_column);
18658         sprintf(print_str, "Output is in CPU%%");
18659         do_label(bif_fd, print_str, bif_row++, bif_column);
18660     }
18661     for (i = 0; i < x; i++)
18662     {
18663         if(!silent) printf("\"%15s \"", throughput_tests[i]);
18664         if (bif_flag)
18665         {
18666             sprintf(print_str, "%15s ", throughput_tests[i]);
18667             do_label(bif_fd, print_str, bif_row, bif_column++);
18668             bif_column++;
18669         }
18670         for (j = 0; j <= y; j++)
18671         {
18672             if (bif_flag)
18673                 do_float(bif_fd, runtimes[i][j].cpuutil, bif_row, bif_column++);
18674             if(!silent) printf(" %10.2f ", runtimes[i][j].cpuutil);
18675         }
18676         if(!silent) printf("\n\n");
18677         if (bif_flag)
18678         {
18679             bif_column=0;
18680             bif_row++;
18681         }
18682     }
18683 }
18684 
18685 
18686 /************************************************************************/
18687 /* Dump the throughput graphs                       */
18688 /************************************************************************/
18689 #ifdef HAVE_ANSIC_C
18690 void
18691 dump_throughput(void)
18692 #else
18693 void
18694 dump_throughput()
18695 #endif
18696 {
18697     long long x,y,i,j;
18698     char *port;
18699     char *label;
18700     char print_str[300];
18701     x=max_x;
18702     y=max_y;
18703 
18704     if(use_thread)
18705         port="threads";
18706     else
18707         port="processes";
18708     if(!silent) printf("\n\"Throughput report Y-axis is type of test X-axis is number of %s\"\n",port);
18709     if(bif_flag)
18710     {
18711         bif_fd=create_xls(bif_filename);
18712         do_label(bif_fd,command_line,bif_row++,bif_column);
18713         sprintf(print_str,"Throughput report Y-axis is type of test X-axis is number of %s",port);
18714         do_label(bif_fd,print_str,bif_row++,bif_column);
18715     }
18716     if(OPS_flag)
18717         label="ops/sec";
18718     else
18719     if(MS_flag)
18720         label="microseconds/op";
18721     else
18722         label="Kbytes/sec";
18723 #ifdef NO_PRINT_LLD
18724     if(!silent) printf("\"Record size = %ld Kbytes \"\n",reclen/1024);
18725 #else
18726     if(!silent) printf("\"Record size = %lld Kbytes \"\n",reclen/1024);
18727 #endif
18728     if(!silent) printf("\"Output is in %s\"\n\n",label);
18729     if(bif_flag)
18730     {
18731 #ifdef NO_PRINT_LLD
18732         sprintf(print_str,"Record size = %ld Kbytes",reclen/1024);
18733 #else
18734         sprintf(print_str,"Record size = %lld Kbytes",reclen/1024);
18735 #endif
18736         do_label(bif_fd,print_str,bif_row++,bif_column);
18737         sprintf(print_str,"Output is in %s",label);
18738         do_label(bif_fd,print_str,bif_row++,bif_column);
18739     }
18740     for(i=0;i<=toutputindex;i++)
18741     {
18742            if(!silent) printf("\"%15s \"",toutput[i]);
18743            if(bif_flag)
18744            {
18745                sprintf(print_str,"%15s ",toutput[i]);
18746                do_label(bif_fd,print_str,bif_row,bif_column++);
18747                bif_column++;
18748            }
18749            for(j=0;j<=y;j++)
18750            {
18751                if(bif_flag)
18752                {
18753                    do_float(bif_fd,(double)report_darray[i][j],bif_row,bif_column++);
18754                }
18755                if(!silent) printf(" %10.2f ",report_darray[i][j]);
18756            }
18757            if(!silent) printf("\n\n");
18758            if(bif_flag)
18759            {
18760                bif_column=0;
18761                bif_row++;
18762            }
18763     }
18764     if (cpuutilflag)
18765         dump_throughput_cpu();
18766     if(bif_flag)
18767         close_xls(bif_fd);
18768 }
18769 
18770 /************************************************************************/
18771 /* store_dvalue()                           */
18772 /* Stores a value in an in memory array. Used by the report function    */
18773 /* to re-organize the output for Excel                  */
18774 /************************************************************************/
18775 #ifdef HAVE_ANSIC_C
18776 void 
18777 store_dvalue(double value)
18778 #else
18779 void
18780 store_dvalue(value)
18781 double value;
18782 #endif
18783 {
18784     report_darray[current_x][current_y]=value;
18785     current_x++;
18786     if(current_x > max_x)
18787         max_x=current_x;
18788     if(current_y > max_y)
18789         max_y=current_y;
18790     if(max_x >= MAX_X)
18791     {
18792         printf("\nMAX_X too small\n");
18793         exit(163);
18794     }
18795     if(max_y >= MAXSTREAMS)
18796     {
18797         printf("\nMAXSTREAMS too small\n");
18798         exit(164);
18799     }
18800 }
18801 
18802 /************************************************************************/
18803 /* Initialize a file that will be used by mmap.             */
18804 /************************************************************************/
18805 #ifdef HAVE_ANSIC_C
18806 char *
18807 initfile(int fd, off64_t filebytes,int flag,int prot)
18808 #else
18809 char *
18810 initfile(fd, filebytes,flag, prot)
18811 int fd;
18812 off64_t filebytes;
18813 int flag, prot;
18814 #endif
18815 {
18816      char *pa;
18817      int mflags=0;
18818      long long x;
18819      char *tmp,*stmp;
18820      int file_flags;
18821      long long recs;
18822      long long i;
18823      int dflag = 0;
18824 
18825      if(flag)
18826      {
18827 
18828 #ifdef _HPUX_SOURCE
18829         /* 
18830          * Save time, just have the operating system prealloc 
18831          * the file 
18832          */
18833         prealloc(fd,filebytes);
18834 #else
18835         /* 
18836           * Allocate a temporary buffer to meet any alignment 
18837           * contraints of any method.
18838           */
18839          tmp=(char *)malloc((size_t)reclen * 2);
18840          stmp=tmp;
18841          /* 
18842           * Align to a reclen boundary.
18843           */
18844          tmp = (char *)((((long)tmp + (long)reclen))& ~(((long)reclen-1)));
18845         /* 
18846          * Special case.. Open O_DIRECT, and going to be mmap() 
18847          * Under Linux, one can not create a sparse file using 
18848          * a file that is opened with O_DIRECT 
18849          */
18850         file_flags=fcntl(fd,F_GETFL);
18851 
18852 #if ! defined(DONT_HAVE_O_DIRECT)
18853 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
18854         dflag = O_DIRECT;
18855 #endif
18856 #if defined(TRU64)
18857     if(direct_flag)
18858         dflag = O_DIRECTIO;
18859 #endif
18860 #endif
18861         if((file_flags & dflag) !=0)
18862         {
18863             recs=filebytes/reclen;
18864             for (i =0; i<recs ;i++)
18865             {
18866                 x=write(fd,tmp,(size_t)reclen);
18867                 if(x < 1)
18868                 {
18869                     printf("Unable to write file\n");
18870                     exit(182);
18871                 }
18872             }
18873         }
18874         else
18875         {
18876             /* Save time, just seek out and touch at the end */
18877             I_LSEEK(fd,(filebytes-reclen),SEEK_SET);
18878             x=write(fd,tmp,(size_t)reclen);
18879             if(x < 1)
18880             {
18881                 printf("Unable to write file\n");
18882                 exit(181);
18883             }
18884         }
18885         free(stmp);
18886         I_LSEEK(fd,0,SEEK_SET);
18887 #endif
18888      }
18889 
18890 #ifdef IRIX64
18891     if((prot & PROT_WRITE)==PROT_WRITE)
18892         mflags=MAP_SHARED;
18893     else
18894         mflags=MAP_PRIVATE;
18895 #else
18896 #ifdef IRIX
18897     if((prot & PROT_WRITE)==PROT_WRITE)
18898         mflags=MAP_SHARED;
18899     else
18900         mflags=MAP_PRIVATE;
18901 #else
18902     if((prot & PROT_WRITE)==PROT_WRITE)
18903         mflags=MAP_FILE|MAP_SHARED;
18904     else
18905         mflags=MAP_FILE|MAP_PRIVATE;
18906 #endif
18907 #endif
18908 
18909 #if defined(bsd4_2) && !defined(macosx)
18910      pa = (char *)mmap( 0,&filebytes, (int)prot, 
18911             (int)mflags, (int)fd, 0);
18912 #else
18913      pa = (char *)I_MMAP( ((char *)0),filebytes, prot, 
18914             mflags, fd, 0);
18915 #endif
18916 #ifdef __convex_spp
18917     if(pa == (char *)-1)
18918     {
18919         printf("\nMmap failed, errno %d Flags %x\n",errno,(int)mflags);
18920         exit(165);
18921     }
18922 #else
18923 #ifdef linux
18924     if(pa == (char *)-1)
18925     {
18926         printf("Mapping failed, errno %d\n",errno);
18927         exit(166);
18928     }
18929 #else
18930 #ifdef bsd4_2
18931     if(pa == (char *)-1)
18932     {
18933         printf("Mapping failed, errno %d\n",errno);
18934         exit(167);
18935     }
18936 #else
18937     if(pa == (char *)MAP_FAILED)
18938     {
18939         printf("\nMapping failed, errno %d Flags = %x\n",errno,mflags);
18940         exit(168);
18941     }
18942 #endif
18943 #endif
18944 #endif
18945 #ifndef NO_MADVISE
18946     if(advise_flag)
18947     {
18948         switch(advise_op){
18949         case 0:
18950             madvise( (char *)pa, (size_t) filebytes, MADV_NORMAL);
18951             break;
18952         case 1: 
18953             madvise( (char *)pa, (size_t) filebytes, MADV_RANDOM);
18954             break;
18955         case 2: 
18956             madvise( (char *)pa, (size_t) filebytes, MADV_SEQUENTIAL);
18957             break;
18958         case 3: 
18959             madvise( (char *)pa, (size_t) filebytes, MADV_DONTNEED);
18960             break;
18961         case 4: 
18962             madvise( (char *)pa, (size_t) filebytes, MADV_WILLNEED);
18963             break;
18964         default: 
18965             break;
18966         };
18967     }
18968     
18969 #endif
18970     return(pa);
18971 
18972 }
18973 
18974 
18975 /************************************************************************/
18976 /* Release the mmap area.                       */
18977 /************************************************************************/
18978 #ifdef HAVE_ANSIC_C
18979 void
18980 mmap_end( char *buffer, long long size)
18981 #else
18982 void
18983 mmap_end( buffer, size)
18984 char *buffer;
18985 long long size;
18986 #endif
18987 {
18988     if(munmap(buffer,(size_t)size)<0)
18989 #ifdef NO_PRINT_LLD
18990         printf("munmap buffer %lx, size %ld failed.\n",(long)buffer,size);
18991 #else
18992         printf("munmap buffer %lx, size %lld failed.\n",(long)buffer,size);
18993 #endif
18994     
18995 }
18996 
18997 /************************************************************************/
18998 /*  This is an interesting function. How much data to       */
18999 /*  copy is a very good question. Here we are using mmap to     */
19000 /*  perform I/O. If the benchmark touches every byte then       */
19001 /*  this will include a bcopy of the mmap area into the     */
19002 /*  users buffer. This is represenative of an application       */
19003 /*  that reads and touches every byte that it read. If      */
19004 /*  the benchmark reduces the work to touching only         */
19005 /*  a long per page then the numbers go up but it           */
19006 /*  does not reflect the application to well. For now       */
19007 /*  the best assumption is to believe that the application      */
19008 /*  will indeed touch every byte.                   */
19009 /************************************************************************/
19010 #ifdef HAVE_ANSIC_C
19011 void 
19012 fill_area(long long *src_buffer, long long *dest_buffer, long long length)
19013 #else
19014 fill_area( src_buffer, dest_buffer, length)
19015 long long *src_buffer;
19016 long long *dest_buffer;
19017 long long length;
19018 #endif
19019 {
19020     /*printf("Fill area %d\n",(size_t)length);*/
19021     bcopy((void *)src_buffer,(void *)dest_buffer,(size_t)length);
19022 }
19023 
19024 #ifndef ASYNC_IO
19025 int
19026 async_read()
19027 {
19028     printf("Your system does not support async I/O\n");
19029     exit(169);
19030 }
19031 size_t
19032 async_write_no_copy()
19033 {
19034     printf("Your system does not support async I/O\n");
19035     exit(170);
19036 }
19037 size_t
19038 async_write()
19039 {
19040     printf("Your system does not support async I/O\n");
19041     exit(171);
19042 }
19043 void
19044 async_init()
19045 {
19046     printf("Your system does not support async I/O\n");
19047     exit(172);
19048 }
19049 int
19050 async_read_no_copy()
19051 {
19052     printf("Your system does not support async I/O\n");
19053     exit(172);
19054 }
19055 void
19056 async_release()
19057 {
19058     printf("Your system does not support async I/O\n");
19059     exit(173);
19060 }
19061 #endif
19062 
19063 /************************************************************************/
19064 /* Nap in microseconds.                         */
19065 /************************************************************************/
19066 #ifdef HAVE_ANSIC_C
19067 void
19068 my_nap( int ntime )
19069 #else
19070 void
19071 my_nap( ntime )
19072 int ntime;
19073 #endif
19074 {
19075     struct timeval nap_time;
19076     int seconds, microsecs;
19077     seconds = ntime/1000; /* Now in seconds */
19078     microsecs = (ntime*1000)%1000000;  /* Remaining microsecs */
19079     nap_time.tv_sec=seconds;
19080         nap_time.tv_usec=microsecs;
19081         select(0,0,0,0,&nap_time);
19082 }
19083 /************************************************************************/
19084 /* Nap in microseconds.                         */
19085 /************************************************************************/
19086 int nap_once;
19087 double nap_res;
19088 #ifdef HAVE_ANSIC_C
19089 void
19090 my_unap( unsigned long long microsecs )
19091 #else
19092 void
19093 my_unap( microsecs )
19094 unsigned long long microsecs;
19095 #endif
19096 {
19097     struct timeval nap_time;
19098     int seconds;
19099     double timein, timeout;
19100 
19101     seconds = (int)(microsecs/1000000.0); /* Now in seconds */
19102     nap_time.tv_sec=seconds;
19103         nap_time.tv_usec=(int)microsecs;
19104 
19105     timein=time_so_far1();
19106     while(1)
19107     {
19108         timeout=time_so_far1();
19109         /*printf("Sleep for %lld Curtime %g\n",microsecs,timeout-timein);*/
19110         if(timeout-timein > microsecs)
19111            break;
19112     }
19113 
19114 /*
19115         select(0,0,0,0,&nap_time);
19116 */
19117 
19118 
19119 }
19120 
19121 /************************************************************************/
19122 /* Function that establishes the resolution                 */
19123 /* of the gettimeofday() function.                  */
19124 /************************************************************************/
19125 
19126 #ifdef HAVE_ANSIC_C
19127 void
19128 get_resolution(void)
19129 #else
19130 void
19131 get_resolution()
19132 #endif
19133 {
19134         double starttime, finishtime, besttime = 0;
19135         long  j,delay;
19136     int k;
19137 
19138         finishtime=time_so_far1(); /* Warm up the instruction cache */
19139         starttime=time_so_far1();  /* Warm up the instruction cache */
19140         delay=j=0;                 /* Warm up the data cache */
19141     for(k=0;k<10;k++)
19142     {
19143             while(1)
19144             {
19145                     starttime=time_so_far1();
19146                     for(j=0;j< delay;j++)
19147                         ;
19148                     finishtime=time_so_far1();
19149                     if(starttime==finishtime)
19150                             delay++;
19151                     else
19152             {
19153                 if(k==0)
19154                     besttime=(finishtime-starttime);
19155                 if((finishtime-starttime) < besttime)
19156                     besttime=(finishtime-starttime);
19157                             break;
19158             }
19159         }
19160         }
19161     time_res=besttime/1000000.0;    
19162 }
19163 
19164 /************************************************************************/
19165 /* Function that establishes the resolution                 */
19166 /* of the getrusage() function.                     */
19167 /************************************************************************/
19168 
19169 #ifdef HAVE_ANSIC_C
19170 void
19171 get_rusage_resolution(void)
19172 #else
19173 void
19174 get_rusage_resolution()
19175 #endif
19176 {
19177     double starttime, finishtime;
19178     long  j;
19179 
19180     finishtime=cputime_so_far(); /* Warm up the instruction cache */
19181     starttime=cputime_so_far();  /* Warm up the instruction cache */
19182     delay=j=0;         /* Warm up the data cache */
19183     while(1)
19184     {
19185         starttime=cputime_so_far();
19186         for(j=0;j< delay;j++)
19187             ;
19188         finishtime=cputime_so_far();
19189         if(starttime==finishtime)
19190             
19191             delay++;
19192         else
19193             break;
19194     }
19195     cputime_res = (finishtime-starttime);    /* in seconds */
19196 }
19197 /************************************************************************/
19198 /* Time measurement routines.                       */
19199 /* Return time in microseconds                      */
19200 /************************************************************************/
19201 
19202 #ifdef HAVE_ANSIC_C
19203 static double
19204 time_so_far1(void)
19205 #else
19206 static double
19207 time_so_far1()
19208 #endif
19209 {
19210      /* For Windows the time_of_day() is useless. It increments in 
19211         55 milli second  increments. By using the Win32api one can 
19212     get access to the high performance measurement interfaces. 
19213     With this one can get back into the 8 to 9 microsecond resolution
19214       */
19215 #ifdef Windows
19216     LARGE_INTEGER freq,counter;
19217     double wintime;
19218     double bigcounter;
19219     struct timeval tp;
19220 
19221     if(pit_hostname[0]){
19222        pit_gettimeofday(&tp, (struct timezone *) NULL, pit_hostname, 
19223         pit_service);
19224        return ((double) (tp.tv_sec)*1000000.0)+(((double)tp.tv_usec));
19225     }
19226     else
19227     {   
19228 
19229            QueryPerformanceFrequency(&freq);
19230            QueryPerformanceCounter(&counter);
19231            bigcounter=(double)counter.HighPart *(double)0xffffffff +
19232                    (double)counter.LowPart;
19233            wintime = (double)(bigcounter/(double)freq.LowPart);
19234            return((double)wintime*1000000.0);
19235     }
19236 #else
19237 #if defined (OSFV4) || defined(OSFV3) || defined(OSFV5)
19238   struct timespec gp;
19239 
19240   if (getclock(TIMEOFDAY, (struct timespec *) &gp) == -1)
19241     perror("getclock");
19242   return (( (double) (gp.tv_sec)*1000000.0) +
19243     ( ((float)(gp.tv_nsec)) * 0.001 ));
19244 #else
19245   struct timeval tp;
19246 
19247   if(pit_hostname[0]){
19248      if (pit_gettimeofday(&tp, (struct timezone *) NULL, pit_hostname, 
19249         pit_service) == -1)
19250         perror("pit_gettimeofday");
19251      return ((double) (tp.tv_sec)*1000000.0) + (((double) tp.tv_usec) );
19252   }
19253   else
19254   {
19255      if (gettimeofday(&tp, (struct timezone *) NULL) == -1)
19256         perror("gettimeofday");
19257      return ((double) (tp.tv_sec)*1000000.0) + (((double) tp.tv_usec) );
19258   }
19259 #endif
19260 #endif
19261 }
19262 
19263 /************************************************************************/
19264 /* Return the clocks per tick for the times() call.         */
19265 /************************************************************************/
19266 #ifdef unix
19267 #ifdef HAVE_ANSIC_C
19268 static double
19269 clk_tck(void)       /* Get the clocks per tick for times */
19270 #else
19271 static double
19272 clk_tck()       /* Get the clocks per tick for times */
19273 #endif
19274 {
19275     return((double)sysconf(_SC_CLK_TCK));
19276 }
19277 
19278 /************************************************************************/
19279 /* Return the user time in tics as a double.                */
19280 /************************************************************************/
19281 #ifdef HAVE_ANSIC_C
19282 static double
19283 utime_so_far(void)   /* Return user time in ticks as double */
19284 #else
19285 static double
19286 utime_so_far()
19287 #endif
19288 {
19289     struct tms tp;
19290 
19291     times(&tp);
19292     return ((double) (tp.tms_utime));
19293 }
19294 
19295 /************************************************************************/
19296 /* Return the system time in tics as a double.              */
19297 /************************************************************************/
19298 #ifdef HAVE_ANSIC_C
19299 static double
19300 stime_so_far(void)      /* Return system time in ticks as double */
19301 #else
19302 static double
19303 stime_so_far()
19304 #endif
19305 {
19306     struct tms tp;
19307 
19308     times(&tp);
19309     return ((double) (tp.tms_stime));
19310 }
19311 
19312 /************************************************************************/
19313 /* Return the CPU (user + system) time in seconds as a double.      */
19314 /************************************************************************/
19315 #ifdef HAVE_ANSIC_C
19316 static double
19317 cputime_so_far(void)    /* Return CPU time in seconds as double */
19318 #else
19319 static double
19320 cputime_so_far()
19321 #endif
19322 {
19323 #if 0
19324     struct tms tp;
19325 
19326     times(&tp);
19327     return ((double) (tp.tms_utime + tp.tms_stime) / sc_clk_tck);
19328 #else
19329     struct rusage ru;
19330 
19331     if (getrusage (RUSAGE_SELF, &ru))
19332         perror ("getrusage");
19333     return ((double)(ru.ru_utime.tv_sec + ru.ru_stime.tv_sec) +
19334         .000001 *(ru.ru_utime.tv_usec + ru.ru_stime.tv_usec));
19335 #endif
19336 }
19337 #endif
19338 
19339 /************************************************************************/
19340 /* Return the CPU utilization ((user + system) / walltime) as a percentage. */
19341 /************************************************************************/
19342 #ifdef HAVE_ANSIC_C
19343 static double
19344 cpu_util(double cputime, double walltime)
19345 #else
19346 static double
19347 cpu_util(cputime, walltime)
19348 double cputime, walltime;
19349 #endif
19350 {
19351     double cpu;
19352 
19353     if (walltime <= (double)0.0)
19354     {
19355         cpu = (double)0.0;
19356         return cpu;
19357     }
19358     if (cputime <= (double)0.0)
19359         cputime = 0.0;
19360     if (walltime <= (double)0.0)
19361         cpu = (double)100.0;
19362     else {
19363         cpu = (((double)100.0 * cputime) / walltime);
19364         /*
19365         if (cpu > (double)100.0)
19366             cpu = (double)99.99;
19367         */
19368     }
19369     return cpu;
19370 }
19371 
19372 /************************************************************************/
19373 /* This is a locking function that permits the writes and       */
19374 /* reads during the test to hold a file lock. Since each        */
19375 /* tmp file that Iozone creates is a private file, this seems       */
19376 /* like a no-op but it turns out that when using Iozone         */
19377 /* over NFS,  life is very, very different. Some vendors        */
19378 /* read and write performance goes to zip when locks are held       */
19379 /* even if there is only one process using the file and having      */
19380 /* it locked. Some implementations of NFS transition from async     */
19381 /* to fully sync reads and writes if any locks are used. Euck...    */
19382 /************************************************************************/
19383 #ifdef HAVE_ANSIC_C
19384 int
19385 mylockf(int fd, int op, int rdwr)
19386 #else
19387 int
19388 mylockf(fd, op, rdwr)
19389 int fd, op, rdwr;
19390 #endif
19391 {
19392     struct flock myflock;
19393     int ret;
19394     if(op==0) /* Generic unlock the whole file */
19395     {
19396         myflock.l_type=F_UNLCK;
19397         myflock.l_whence=SEEK_SET;
19398         myflock.l_start=0;
19399         myflock.l_len=0; /* The whole file */
19400         myflock.l_pid=getpid();
19401         ret=fcntl(fd,F_SETLKW, &myflock);
19402     }
19403     else
19404           /* Generic lock the whole file */
19405     {
19406         if(rdwr==0)
19407             myflock.l_type=F_WRLCK; /* Apply write lock */
19408         else
19409             myflock.l_type=F_RDLCK; /* Apply read lock */
19410         myflock.l_whence=SEEK_SET;
19411         myflock.l_start=0;
19412         myflock.l_len=0; /* The whole file */
19413         myflock.l_pid=getpid();
19414         ret=fcntl(fd,F_SETLKW, &myflock);
19415     }
19416     return(ret);
19417 }
19418 
19419 #ifdef HAVE_ANSIC_C
19420 int
19421 mylockr(int fd, int op, int rdwr, off64_t offset, off64_t size)
19422 #else
19423 int
19424 mylockr(fd, op, rdwr, offset, size)
19425 int fd, op, rdwr;
19426 off64_t offset;
19427 off64_t size;
19428 #endif
19429 {
19430     struct flock myflock;
19431     int ret;
19432     if(op==0) /* Generic unlock the whole file */
19433     {
19434         /*printf("Child: %lld Unlock offset %lld size %lld\n",chid,offset,size);*/
19435         myflock.l_type=F_UNLCK;
19436         myflock.l_whence=SEEK_SET;
19437         myflock.l_start=offset;
19438         myflock.l_len=size; /* The whole file */
19439         myflock.l_pid=getpid();
19440         ret=fcntl(fd,F_SETLKW, &myflock);
19441     }
19442     else
19443           /* Generic lock the range  */
19444     {
19445         if(rdwr==0)
19446         {
19447             myflock.l_type=F_WRLCK; /* Apply write lock */
19448             /* printf("Write ");*/
19449         }
19450         else
19451         {
19452             myflock.l_type=F_RDLCK; /* Apply read lock */
19453             /* printf("Read ");*/
19454         }
19455         /*printf("Child: %lld Lock offset %lld size %lld\n",chid, offset,size);*/
19456         myflock.l_whence=SEEK_SET;
19457         myflock.l_start=offset;
19458         myflock.l_len=size; /* The whole file */
19459         myflock.l_pid=getpid();
19460         ret=fcntl(fd,F_SETLKW, &myflock);
19461     }
19462     return(ret);
19463 }
19464 /************************************************************************/
19465 /* This function is used to simulate compute time that does     */
19466 /* not involve the I/O subsystem.                   */
19467 /************************************************************************/
19468 
19469 #ifdef HAVE_ANSIC_C
19470 float
19471 do_compute(float comp_delay)
19472 #else
19473 float
19474 do_compute(comp_delay)
19475 float comp_delay;
19476 #endif
19477 {
19478     double starttime,tmptime;
19479     if(comp_delay == (float)0.0)
19480         return(0.0);
19481     starttime=time_so_far();
19482     while(1)
19483     {   
19484         tmptime=time_so_far()-starttime;
19485         if(tmptime >= (double)comp_delay)
19486             return(tmptime);
19487     }
19488     return(0.0);
19489 }
19490 
19491 /************************************************************************/
19492 /* This function is intended to cause an interruption           */
19493 /* in the read pattern. It will make a reader have          */
19494 /* jitter in its access behavior.                   */
19495 /* When using direct I/O one must use a pagesize transfer.      */
19496 /************************************************************************/
19497 #ifdef HAVE_ANSIC_C
19498 void
19499 disrupt(int fd)
19500 #else
19501 void
19502 disrupt(fd)
19503 int fd;
19504 #endif
19505 {
19506     char *nbuff,*free_addr;
19507     off64_t current;
19508 
19509     free_addr=nbuff=(char *)malloc((size_t)page_size+page_size);
19510     nbuff=(char *)(((long)nbuff+(long)page_size) & (long)~(page_size-1));
19511 
19512     /* Save current position */
19513     current = I_LSEEK(fd,0,SEEK_CUR);
19514 
19515     /* Move to beginning of file */
19516     I_LSEEK(fd,0,SEEK_SET);
19517 
19518     /* Read a little of the file */
19519     if(direct_flag)
19520         junk=read(fd,nbuff,page_size);
19521     else
19522         junk=read(fd,nbuff,1);
19523 
19524     /* Skip into the file */
19525     I_LSEEK(fd,page_size,SEEK_SET);
19526 
19527     /* Read a little of the file */
19528     if(direct_flag)
19529         junk=read(fd,nbuff,page_size);
19530     else
19531         junk=read(fd,nbuff,1);
19532 
19533     /* Restore current position in file, before disruption */
19534     I_LSEEK(fd,current,SEEK_SET);
19535     free(free_addr);
19536     
19537 }
19538 
19539 #if defined(Windows)
19540 /************************************************************************/
19541 /* This function is intended to cause an interruption           */
19542 /* in the read pattern. It will make a reader have          */
19543 /* jitter in its access behavior.                   */
19544 /* When using direct I/O one must use a pagesize transfer.      */
19545 /************************************************************************/
19546 #ifdef HAVE_ANSIC_C
19547 void
19548 disruptw(HANDLE hand)
19549 #else
19550 void
19551 disruptw(HANDLE)
19552 int hand;
19553 #endif
19554 {
19555     char *nbuff,*free_addr;
19556     off64_t current;
19557     long retval;
19558 
19559     free_addr=nbuff=(char *)malloc((size_t)page_size+page_size);
19560     nbuff=(char *)(((long)nbuff+(long)page_size) & (long)~(page_size-1));
19561 
19562     /* Save current position */
19563     current=SetFilePointer(hand,(LONG)0,0,FILE_CURRENT);
19564 
19565     /* Move to beginning of file */
19566     SetFilePointer(hand,(LONG)0,0,FILE_BEGIN);
19567 
19568     /* Read a little of the file */
19569     ReadFile(hand, nbuff, reclen,(LPDWORD)&retval,0);
19570 
19571     /* Skip into the file */
19572     SetFilePointer(hand,(LONG)page_size,0,FILE_BEGIN);
19573 
19574     /* Read a little of the file */
19575     ReadFile(hand, nbuff, reclen,(LPDWORD)&retval,0);
19576 
19577     /* Restore current position in file, before disruption */
19578     SetFilePointer(hand,(LONG)current,0,FILE_BEGIN);
19579     free(free_addr);
19580     
19581 }
19582 #endif
19583 
19584 /************************************************************************/
19585 /* Read a telemetry file and return the the offset          */
19586 /* for the next operaton. Also, set the size                */
19587 /* in the variable given in the param list.             */
19588 /* which == 0 ... reader calling                    */
19589 /* which == 1 ... writer calling                    */
19590 /************************************************************************/
19591 #ifdef HAVE_ANSIC_C
19592 long long
19593 get_traj(FILE *traj_fd, long long *traj_size, float *delay, long which)
19594 #else
19595 long long
19596 get_traj(traj_fd, traj_size, delay, which)
19597 FILE *traj_fd;
19598 long long *traj_size;
19599 float *delay;
19600 long which;
19601 #endif
19602 {
19603     long long traj_offset = 0;
19604     long long tmp2 = 0;
19605     int tmp = 0;
19606     int tokens;
19607     int ret=0;
19608     char *ret1,*where;
19609     char buf[200];
19610     char sbuf[200];
19611     int got_line;
19612     
19613     got_line=0;
19614 
19615     while(got_line==0)
19616     {
19617         tokens=0;
19618         ret1=fgets(buf,200,traj_fd);
19619         if(ret1==(char *)0)
19620         {
19621             printf("\n\n\tEarly end of telemetry file. Results not accurate.\n");
19622             signal_handler();
19623         }
19624         where=(char *)&buf[0];
19625         strcpy(sbuf,buf);
19626         if((*where=='#') || (*where=='\n'))
19627             continue;
19628         tokens++;
19629         strtok(where," ");
19630         while( (char *)(strtok( (char *)0," ")) != (char *)0)
19631         {
19632             tokens++;
19633         }
19634         got_line=1;
19635     }
19636     if(tokens == 3)
19637     {
19638 #ifdef NO_PRINT_LLD
19639         ret=sscanf(sbuf,"%ld %ld %d\n",&traj_offset,&tmp2,&tmp);
19640 #else
19641         ret=sscanf(sbuf,"%lld %lld %d\n",&traj_offset,&tmp2,&tmp);
19642 #endif
19643     /*printf("\nReading %s trajectory with %d items\n",which?"write":"read",tokens);*/
19644         *traj_size=tmp2;
19645         *delay= ((float)tmp/1000);
19646     }
19647     if(tokens == 2)
19648     { 
19649 #ifdef NO_PRINT_LLD
19650         ret=sscanf(sbuf,"%ld %ld\n",&traj_offset,traj_size);
19651 #else
19652         ret=sscanf(sbuf,"%lld %lld\n",&traj_offset,traj_size);
19653 #endif
19654         *delay=compute_time;
19655     /*printf("\nReading %s trajectory with %d items\n",which?"write":"read",tokens);*/
19656     }
19657     if((tokens != 2) && (tokens !=3))
19658     {
19659         printf("\n\tInvalid entry in telemetry file. > %s <\n",sbuf);
19660         exit(178);
19661     }
19662     if(ret==EOF)
19663     {
19664         printf("\n\n\tEarly end of telemetry file. Results not accurate.\n");
19665         signal_handler();
19666     }
19667 #ifdef DEBUG
19668 #ifdef NO_PRINT_LLD
19669     if(!silent) printf("\nOffset %lld  Size %ld Compute delay %f\n",traj_offset, *traj_size,*delay);
19670 #else
19671     if(!silent) printf("\nOffset %lld  Size %lld Compute delay %f\n",traj_offset, *traj_size,*delay);
19672 #endif
19673 #endif
19674     return(traj_offset);
19675 }
19676 
19677 /************************************************************************/
19678 /* Open the read telemetry file and return file pointer.        */
19679 /************************************************************************/
19680 #ifdef HAVE_ANSIC_C
19681 FILE *
19682 open_r_traj(void)
19683 #else
19684 FILE *
19685 open_r_traj()
19686 #endif
19687 {
19688     FILE *fd;
19689     fd=fopen(read_traj_filename,"r");
19690     if(fd == (FILE *)0)
19691     {
19692         printf("Unable to open read telemetry file \"%s\"\n",
19693             read_traj_filename);
19694         exit(174);
19695     }
19696     return(fd);
19697 }
19698 
19699 /************************************************************************/
19700 /* Open the write telemetry file and return file pointer.       */
19701 /************************************************************************/
19702 #ifdef HAVE_ANSIC_C
19703 FILE *
19704 open_w_traj(void)
19705 #else
19706 FILE *
19707 open_w_traj()
19708 #endif
19709 {
19710     FILE *fd;
19711     fd=fopen(write_traj_filename,"r");
19712     if(fd == (FILE *)0)
19713     {
19714         printf("Unable to open write telemetry file \"%s\"\n",
19715             write_traj_filename);
19716         exit(175);
19717     }
19718     return(fd);
19719 }
19720 
19721 /************************************************************************/
19722 /* r_traj_size(void)                            */
19723 /* This function scans the read telemetry file              */
19724 /* and establishes the number of entries                */
19725 /* and the maximum file offset.                     */
19726 /************************************************************************/
19727 #ifdef HAVE_ANSIC_C
19728 void 
19729 r_traj_size(void)
19730 #else
19731 void
19732 r_traj_size()
19733 #endif
19734 {
19735     FILE *fd;
19736     int ret;
19737     long long traj_offset = 0;
19738     long long traj_size = 0;
19739     long long max_offset = 0;
19740     int tokens;
19741     int dummy;
19742     int lines;
19743     char buf[200];
19744     char sbuf[200];
19745     char *ret1,*where;
19746 
19747     lines=0;
19748     fd=fopen(read_traj_filename,"r");
19749     if(fd == (FILE *)0)
19750     {
19751         printf("Unable to open read telemetry file \"%s\"\n",
19752             read_traj_filename);
19753         exit(174);
19754     }
19755     while(1)
19756     {
19757         tokens=0;
19758         ret1=fgets(buf,200,fd);
19759         if(ret1==(char *)0)
19760             break;
19761         where=(char *)&buf[0];
19762         strcpy(sbuf,buf);
19763         lines++;
19764         if((*where=='#') || (*where=='\n'))
19765             continue;
19766         tokens++;
19767         strtok(where," ");
19768         while( (char *)(strtok( (char *)0," ")) != (char *)0)
19769         {
19770             tokens++;
19771         }
19772         if(tokens==1)
19773         {
19774             printf("\n\tInvalid read telemetry file entry. Line %d",
19775                 lines);
19776             signal_handler();
19777         }
19778 #ifdef DEBUG
19779     printf("Tokens = %d\n",tokens);
19780 #endif
19781         if(tokens==3)
19782         {
19783 #ifdef NO_PRINT_LLD
19784             ret=sscanf(sbuf,"%ld %ld %d\n",&traj_offset,&traj_size,&dummy);
19785 #else
19786             ret=sscanf(sbuf,"%lld %lld %d\n",&traj_offset,&traj_size,&dummy);
19787 #endif
19788         }
19789         if(tokens==2)
19790         {
19791 #ifdef NO_PRINT_LLD
19792             ret=sscanf(sbuf,"%ld %ld\n",&traj_offset,&traj_size);
19793 #else
19794             ret=sscanf(sbuf,"%lld %lld\n",&traj_offset,&traj_size);
19795 #endif
19796         }
19797         if((tokens != 2) && (tokens !=3))
19798         {
19799             printf("\n\tInvalid read telemetry file. Line %d\n",lines);
19800             exit(178);
19801         }
19802         if(traj_offset + traj_size > max_offset)
19803             max_offset=traj_offset + traj_size;
19804         
19805         r_traj_ops++;
19806     }   
19807     r_traj_fsize=max_offset;
19808 #ifdef DEBUG
19809     printf("File size of read %lld Item count %lld\n",r_traj_fsize,r_traj_ops);
19810 #endif
19811     fclose(fd);
19812 }
19813 
19814 /************************************************************************/
19815 /* w_traj_size(void)                            */
19816 /* This function scans the write telemetry file             */
19817 /* and establishes the number of entries                */
19818 /* and the maximum file offset.                     */
19819 /************************************************************************/
19820 #ifdef HAVE_ANSIC_C
19821 long long
19822 w_traj_size(void)
19823 #else
19824 long long
19825 w_traj_size()
19826 #endif
19827 {
19828     FILE *fd;
19829     int ret;
19830     long long traj_offset = 0;
19831     long long traj_size = 0;
19832     long long max_offset = 0;
19833     int dummy;
19834     int tokens,lines;
19835     char *ret1;
19836     char buf[200];
19837     char sbuf[200];
19838     char *where;
19839 
19840     lines=0;
19841 
19842     fd=fopen(write_traj_filename,"r");
19843     if(fd == (FILE *)0)
19844     {
19845         printf("Unable to open write telemetry file \"%s\"\n",
19846             write_traj_filename);
19847         exit(174);
19848     }
19849     while(1)
19850     {
19851         tokens=0;
19852         ret1=fgets(buf,200,fd);
19853         if(ret1==(char *)0)
19854             break;
19855         lines++;
19856         where=(char *)&buf[0];
19857         strcpy(sbuf,buf);
19858         if((*where=='#') || (*where=='\n'))
19859             continue;
19860         tokens++;
19861         strtok(where," ");
19862         while( (char *)(strtok( (char *)0," ")) != (char *)0)
19863         {
19864             tokens++;
19865         }
19866         if(tokens==1)
19867         {
19868             printf("\n\tInvalid write telemetry file entry. Line %d\n",
19869                 lines);
19870             signal_handler();
19871         }
19872         if(tokens==3)
19873         {
19874 #ifdef NO_PRINT_LLD
19875             ret=sscanf(sbuf,"%ld %ld %d\n",&traj_offset,&traj_size,&dummy);
19876 #else
19877             ret=sscanf(sbuf,"%lld %lld %d",&traj_offset,&traj_size,&dummy);
19878 #endif
19879         }
19880         if(tokens==2)
19881         {
19882 #ifdef NO_PRINT_LLD
19883             ret=sscanf(sbuf,"%ld %ld\n",&traj_offset,&traj_size);
19884 #else
19885             ret=sscanf(sbuf,"%lld %lld\n",&traj_offset,&traj_size);
19886 #endif
19887         }
19888         if(tokens > 3)
19889         {
19890             printf("\n\tInvalid write telemetry file entry. Line %d\n",
19891                 lines);
19892             exit(174);
19893         }
19894         if(traj_offset + traj_size > max_offset)
19895             max_offset=traj_offset + traj_size;
19896         
19897         w_traj_ops++;
19898     }   
19899     w_traj_fsize=max_offset;
19900 #ifdef DEBUG
19901     printf("File size of write %lld Item count %lld\n",w_traj_fsize,w_traj_ops);
19902 #endif
19903     fclose(fd);
19904     return(max_offset);
19905 }
19906 
19907 /************************************************************************/
19908 /* Find which version of the telemetry file format is in use.       */
19909 /************************************************************************/
19910 
19911 #ifdef HAVE_ANSIC_C
19912 void
19913 traj_vers(void)
19914 #else
19915 void
19916 traj_vers()
19917 #endif
19918 {
19919     FILE *fd;
19920     char *where;
19921     char buf[200];
19922     int things;
19923     char *ret1;
19924     
19925     if(r_traj_flag)
19926     {
19927         things=0;
19928         fd=fopen(read_traj_filename,"r");
19929         if(fd == (FILE *)0)
19930         {   
19931             printf("Unable to open read telemetry file \"%s\"\n", read_traj_filename);
19932             exit(174);
19933         }
19934 loop1:
19935         ret1=fgets(buf,200,fd);
19936         if(ret1==(char *)0)
19937         {
19938             fclose(fd);
19939             return;
19940         }
19941         where=(char *)&buf[0];
19942         if((*where=='#') || (*where=='\n'))
19943             goto loop1;
19944         things++;
19945         strtok(where," ");
19946         while( (char *)(strtok( (char *)0," ")) != (char *)0)
19947         {
19948             things++;
19949         }
19950         r_traj_items=things;
19951 #ifdef DEBUG
19952         printf("Found %d items in the read telemetry file\n",things);
19953 #endif
19954     }
19955     if(w_traj_flag)
19956     {
19957         things=0;
19958         fd=fopen(write_traj_filename,"r");
19959         if(fd == (FILE *)0)
19960         {   
19961             printf("Unable to open write telemetry file \"%s\"\n", write_traj_filename);
19962             exit(174);
19963         }
19964 loop2:
19965         ret1=fgets(buf,200,fd);
19966         if(ret1==(char *)0)
19967         {
19968             fclose(fd);
19969             return;
19970         }
19971         where=(char *)&buf[0];
19972         if((*where=='#') || (*where=='\n'))
19973             goto loop2;
19974         things++;
19975         strtok(where," ");
19976         while( (char *)(strtok( (char *)0," ")) != (char *)0)
19977         {
19978             things++;
19979         }
19980         fclose(fd);
19981         w_traj_items=things;
19982 #ifdef DEBUG
19983         printf("Found %d items in the write telemetry file\n",things);
19984 #endif
19985     }
19986 }
19987 
19988 /********************************************************************/
19989 /*                                      */
19990 /* Today this initializes the default set of file sizes for Iozone. */
19991 /* in the future it may take input from the command line or     */
19992 /* from a file.                             */
19993 /*                                  */
19994 /********************************************************************/
19995 #ifdef HAVE_ANSIC_C
19996 void
19997 init_file_sizes( off64_t min_f_size,  off64_t max_f_size)
19998 #else
19999 void
20000 init_file_sizes(min_f_size, max_f_size)
20001 off64_t min_f_size;
20002 off64_t max_f_size;
20003 #endif
20004 {
20005         off64_t kilosi;
20006     int x;
20007     if(s_count > 1)
20008     {
20009             for(x=0; x < s_count; x++)
20010         {
20011             kilosi=s_range[x];
20012             add_file_size((off64_t)kilosi);
20013         }
20014     }
20015     else
20016     {
20017             for(kilosi=min_f_size;kilosi<=max_f_size;kilosi*=multiplier)
20018         {
20019             add_file_size((off64_t)kilosi);
20020         }
20021     }
20022 }
20023 
20024 /********************************************************************/
20025 /* Used to constuct the list of file sizes to test.         */
20026 /********************************************************************/
20027 #ifdef HAVE_ANSIC_C
20028 void
20029 add_file_size(off64_t size)
20030 #else
20031 void
20032 add_file_size(size)
20033 off64_t size;
20034 #endif
20035 {
20036     struct size_entry *size_listp;
20037     struct size_entry *nsize_list;
20038     
20039     size_listp=size_list;
20040     
20041     if(size_list)
20042     {
20043         if(size_listp->next)
20044             while(size_listp->next!=0)
20045                 size_listp=size_listp->next;
20046     }
20047     nsize_list=(struct size_entry *)malloc(sizeof(struct size_entry));
20048     if(nsize_list==0)
20049     {
20050         printf("Malloc failed in add_file_size\n");
20051         exit(180);
20052     }   
20053     nsize_list->next=0;
20054     nsize_list->size=size;
20055     if(size_list == 0)
20056         size_list=nsize_list;
20057     else
20058         size_listp->next=nsize_list;
20059     size_listp=size_list;
20060 }
20061 
20062 /********************************************************************/
20063 /* Return the next file size to test.                   */
20064 /********************************************************************/
20065 #ifdef HAVE_ANSIC_C
20066 off64_t
20067 get_next_file_size(off64_t size)
20068 #else
20069 off64_t
20070 get_next_file_size(size)
20071 off64_t size;
20072 #endif
20073 {
20074     struct size_entry *size_listp;
20075     
20076     size_listp=size_list;
20077     
20078     for( ; size_listp ; size_listp=size_listp->next )
20079     {
20080         if(size_listp->size > size)
20081             return(size_listp->size);
20082     }
20083     return((off64_t)0);
20084 }
20085 
20086 
20087 /**********************************************************************/
20088 /*                                        */
20089 /* Today this initializes the default set of record sizes for Iozone. */
20090 /* in the future it may take input from the command line or       */
20091 /* from a file.                               */
20092 /*                                    */
20093 /**********************************************************************/
20094 #ifdef HAVE_ANSIC_C
20095 void
20096 init_record_sizes( off64_t min_r_size,  off64_t max_r_size)
20097 #else
20098 void
20099 init_record_sizes(min_r_size, max_r_size)
20100 off64_t min_r_size;
20101 off64_t max_r_size;
20102 #endif
20103 {
20104     int x;
20105         off64_t size;
20106     if(r_count > 1)
20107     {
20108             for(x=0; x < r_count; x++)
20109         {
20110             size=r_range[x];
20111             add_record_size((off64_t)size);
20112         }
20113     }
20114     else
20115     {
20116             for(size=min_r_size;size<=max_r_size;size*=multiplier)
20117         {
20118             add_record_size((off64_t)size);
20119         }
20120     }
20121 }
20122 
20123 #ifdef HAVE_ANSIC_C
20124 void
20125 del_record_sizes(void)
20126 #else
20127 void
20128 del_record_sizes()
20129 #endif
20130 {
20131         struct size_entry *size_listp;
20132         struct size_entry *save_item;
20133 
20134         size_listp=rec_size_list;
20135         if(rec_size_list)
20136         {
20137                 while(size_listp!=0)
20138                 {
20139                         save_item=size_listp->next;
20140                         free(size_listp);
20141                         size_listp=save_item;
20142                 }
20143         }
20144         rec_size_list=0;
20145 }
20146 
20147 /********************************************************************/
20148 /* Used to constuct the list of record sizes to test.           */
20149 /********************************************************************/
20150 #ifdef HAVE_ANSIC_C
20151 void
20152 add_record_size(off64_t size)
20153 #else
20154 void
20155 add_record_size(size)
20156 off64_t size;
20157 #endif
20158 {
20159     struct size_entry *size_listp;
20160     struct size_entry *nsize_list;
20161     
20162     size_listp=rec_size_list;
20163     
20164     if(rec_size_list)
20165     {
20166         if(size_listp->next)
20167             while(size_listp->next!=0)
20168                 size_listp=size_listp->next;
20169     }
20170     nsize_list=(struct size_entry *)malloc(sizeof(struct size_entry));
20171     if(nsize_list==0)
20172     {
20173         printf("Malloc failed in add_file_size\n");
20174         exit(180);
20175     }   
20176     nsize_list->next=0;
20177     nsize_list->size=size;
20178     if(rec_size_list == 0)
20179         rec_size_list=nsize_list;
20180     else
20181         size_listp->next=nsize_list;
20182     size_listp=rec_size_list;
20183 }
20184 
20185 /********************************************************************/
20186 /* Return the next record size to test.                 */
20187 /********************************************************************/
20188 #ifdef HAVE_ANSIC_C
20189 off64_t
20190 get_next_record_size(off64_t size)
20191 #else
20192 off64_t
20193 get_next_record_size(size)
20194 off64_t size;
20195 #endif
20196 {
20197     struct size_entry *size_listp;
20198     
20199     size_listp=rec_size_list;
20200     
20201     for( ; size_listp ; size_listp=size_listp->next )
20202     {
20203         if(size_listp->size > size)
20204             return(size_listp->size);
20205     }
20206     return((off64_t)0);
20207 }
20208 
20209 
20210 /*
20211  * Socket based communication mechanism.
20212  * It's intended use is to be the communication mechanism
20213  * that will be used to get Iozone to run across
20214  * multiple clients. 1/11/2002  Don Capps
20215  * The communication model permits a master to send and receive
20216  * messages to and from clients, and for clients to be able to 
20217  * send and receive messages to and from the master.
20218  */
20219 /* 
20220  * Interfaces are:
20221     Master:
20222       int start_master_listen(void)
20223         Called to create masters listening port.
20224 
20225       void master_listen(int sock, int size_of_message)
20226         Call when master wants to block and read
20227         a message.
20228 
20229       int start_master_send(char *child_host_name, int port)
20230         Call to start a send channel to a client.
20231 
20232       void master_send(int child_socket_val, char *host_name, 
20233             char *send_buffer, int send_size)
20234         Call to send message to a client.
20235 
20236       void stop_master_listen(int master_socket_val)
20237         Call to release the masters listening port.
20238 
20239       void stop_master_send(int child_socket_val)
20240         Call to release the masters send port to a client.
20241 
20242     Clients:
20243       int start_child_listen(int size_of_message)
20244         Called to create clients listening port.
20245 
20246       void child_listen(int sock, int size_of_message)
20247         Call when client wants to block and read
20248         a message from the master.
20249 
20250       void child_send(int child_socket_val, char *controlling_host_name, 
20251            char *send_buffer, int send_size)
20252         Call to send message to the master.
20253 
20254       void stop_child_listen(int child_socket_val)
20255         Call to release the clients listening port.
20256 
20257       void stop_child_send(int child_socket_val)
20258         Call to release the clients send port to the master.
20259 
20260 
20261     Messages are sent in command blocks. The structure is
20262     client_command for messages from the master to the 
20263     client, and master_command for messages sent from
20264     a client to the master.
20265 */
20266 
20267 
20268 /*
20269  * Allocate the master listening port that 
20270  * all children will use to send messages to the master.
20271  */
20272 #ifdef HAVE_ANSIC_C
20273 int
20274 start_master_listen(void)
20275 #else
20276 int
20277 start_master_listen()
20278 #endif
20279 {
20280     int s;
20281     int rc;
20282     int tmp_port;
20283     int sockerr;
20284     struct sockaddr_in addr;
20285     int recv_buf_size=65536*4;
20286     int optval=1;
20287     struct linger dummy={1,0};
20288 
20289         s = socket(AF_INET, SOCK_STREAM, 0);
20290         if (s < 0)
20291         {
20292                 perror("socket failed:");
20293                 exit(19);
20294         }
20295     sockerr = setsockopt (s, SOL_SOCKET, SO_RCVBUF, (char *)
20296         &recv_buf_size, sizeof(int));
20297     if ( sockerr == -1 ) {
20298         perror("Error in setsockopt 1\n");
20299     }
20300     sockerr = setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (char *)
20301         &optval, sizeof(int));
20302     if ( sockerr == -1 ) {
20303         perror("Error in setsockopt 2\n");
20304     }
20305     sockerr = setsockopt (s, SOL_SOCKET, SO_LINGER, (char *)
20306         &dummy, sizeof(struct linger));
20307     if ( sockerr == -1 ) {
20308         perror("Error in setsockopt 2\n");
20309     }
20310     tmp_port=HOST_LIST_PORT;
20311         bzero(&addr, sizeof(struct sockaddr_in));
20312         addr.sin_port = htons(tmp_port);
20313         addr.sin_family = AF_INET;
20314         addr.sin_addr.s_addr = INADDR_ANY;
20315         rc = -1;
20316         while (rc < 0)
20317         {
20318                 rc = bind(s, (struct sockaddr *)&addr,
20319                                 sizeof(struct sockaddr_in));
20320         if(rc < 0)
20321         {
20322             tmp_port++;
20323                     addr.sin_port=htons(tmp_port);
20324             continue;
20325         }
20326         master_listen_port = ntohs(addr.sin_port);
20327         }
20328     if(rc < 0)
20329     {
20330         perror("bind failed\n");
20331         exit(20);
20332     }
20333 
20334     if(mdebug)
20335        printf("Master listening on socket %d Port %d\n",s,tmp_port);
20336     return(s);
20337 }
20338 
20339 /*
20340  * Master listens for messages and blocks until
20341  * something arrives.
20342  */
20343 struct sockaddr_in listener_sync_sock;
20344 
20345 #ifdef HAVE_ANSIC_C
20346 void
20347 master_listen(int sock, int size_of_message)
20348 #else
20349 void
20350 master_listen(sock, size_of_message)
20351 int sock, size_of_message;
20352 #endif
20353 {
20354         int tsize;
20355         int s;
20356         struct sockaddr_in *addr;
20357         unsigned int me;
20358         int ns,ret;
20359     struct master_neutral_command *mnc;
20360 
20361     mnc=(struct master_neutral_command *)&master_rcv_buf[0];
20362         tsize = size_of_message;
20363     addr=&listener_sync_sock;
20364         s = sock;
20365     me=sizeof(struct sockaddr_in);
20366 
20367         if(mdebug)
20368           printf("Master in listening mode on socket %d\n",s);
20369 again:
20370         ret=listen(s,MAXSTREAMS);
20371         if(ret != 0)
20372         {
20373                 perror("Master: listen returned error\n");
20374         }
20375         if(mdebug)
20376           printf("Master in accepting connection\n");
20377         ns=accept(s,(void *)addr,&me);
20378         if(ns < 0)
20379         {
20380                 printf("Master socket %d\n",s);
20381                 perror("Master: ***** accept returned error *****\n");
20382         sleep(1);
20383         goto again;
20384         }
20385         if(mdebug)
20386           printf("Master in reading from connection\n");
20387 
20388         ret=read(ns,mnc,tsize);
20389     if(ret < tsize)
20390     {
20391             printf("Master read failed. Ret %d Errno %d\n",ret,errno);
20392     }
20393 
20394         close(ns);
20395 }
20396 
20397 /*
20398  * Child sends message to master.
20399  */
20400 
20401 #ifdef HAVE_ANSIC_C
20402 void
20403 child_send(char *controlling_host_name, struct master_command *send_buffer, int send_size)
20404 #else
20405 void
20406 child_send(controlling_host_name, send_buffer, send_size)
20407 char *controlling_host_name; 
20408 struct master_command *send_buffer; 
20409 int send_size;
20410 #endif
20411 {
20412 
20413         int rc,child_socket_val;
20414         struct hostent *he;
20415         int tmp_port;
20416         struct in_addr *ip;
20417         struct sockaddr_in cs_addr,cs_raddr;
20418     struct master_neutral_command outbuf;
20419     struct timespec req,rem;
20420 
20421     req.tv_sec = 0;
20422     req.tv_nsec = 10000000;
20423     rem.tv_sec = 0;
20424     rem.tv_nsec = 10000000;
20425 
20426         if(cdebug)
20427     {
20428            fprintf(newstdout,"Start_child_send: %s  Size %d\n",controlling_host_name,send_size);
20429        fflush(newstdout);
20430     }
20431         he = gethostbyname(controlling_host_name);
20432         if (he == NULL)
20433         {
20434                 exit(22);
20435         }
20436         ip = (struct in_addr *)he->h_addr_list[0];
20437 
20438 over:
20439         cs_raddr.sin_family = AF_INET;
20440         cs_raddr.sin_port = htons(controlling_host_port);
20441         cs_raddr.sin_addr.s_addr = ip->s_addr;
20442         child_socket_val = socket(AF_INET, SOCK_STREAM, 0);
20443         if (child_socket_val < 0)
20444         {
20445                 perror("Child: socket failed:");
20446                 exit(23);
20447         }
20448         bzero(&cs_addr, sizeof(struct sockaddr_in));
20449         tmp_port= CHILD_ESEND_PORT;
20450         cs_addr.sin_port = htons(tmp_port);
20451         cs_addr.sin_family = AF_INET;
20452         cs_addr.sin_addr.s_addr = INADDR_ANY;
20453         rc = -1;
20454         while (rc < 0)
20455         {
20456                 rc = bind(child_socket_val, (struct sockaddr *)&cs_addr,
20457                                                 sizeof(struct sockaddr_in));
20458                 if(rc < 0)
20459                 {
20460                         tmp_port++;
20461                         cs_addr.sin_port=htons(tmp_port);
20462                         continue;
20463                 }
20464         }
20465         if (rc < 0)
20466         {
20467                 perror("Child: bind failed\n");
20468                 exit(24);
20469         }
20470         if(cdebug)
20471     {
20472           fprintf(newstdout,"Child sender bound to port %d Master port %d \n",tmp_port,HOST_LIST_PORT);
20473       fflush(newstdout);
20474     }
20475 again:
20476     nanosleep(&req,&rem);
20477         rc = connect(child_socket_val, (struct sockaddr *)&cs_raddr,
20478                         sizeof(struct sockaddr_in));
20479         if (rc < 0)
20480         {
20481                 if((ecount++ < 200) && (errno != EISCONN))
20482                 {
20483             nanosleep(&req,&rem);
20484                         /*sleep(1);*/
20485                         goto again;
20486                 }
20487                 if(cdebug)
20488                 {
20489                fprintf(newstdout,"Child: connect failed. Errno %d \n",errno);
20490            fflush(newstdout);
20491                 }
20492                 close(child_socket_val);
20493         nanosleep(&req,&rem);
20494                 /*sleep(1);*/
20495                 ecount=0;
20496                 goto over;
20497         }
20498         ecount=0;
20499         if(cdebug)
20500     {
20501           fprintf(newstdout,"Child connected\n");
20502       fflush(newstdout);
20503     }
20504 
20505     /* NOW send */
20506 
20507     bzero(&outbuf, sizeof(struct master_neutral_command));
20508     if(cdebug>=1)
20509     {
20510         fprintf(newstdout,"Child %d sending message to %s \n",(int)chid, controlling_host_name);
20511         fflush(newstdout);
20512     }
20513     /* 
20514      * Convert internal commands to string format to neutral format for portability
20515      */
20516     strcpy(outbuf.m_host_name,send_buffer->m_host_name);
20517     strcpy(outbuf.m_client_name,send_buffer->m_client_name);
20518     sprintf(outbuf.m_client_number,"%d",send_buffer->m_client_number);
20519     sprintf(outbuf.m_client_error,"%d",send_buffer->m_client_error);
20520     sprintf(outbuf.m_child_port,"%d",send_buffer->m_child_port);
20521     sprintf(outbuf.m_child_async_port,"%d",send_buffer->m_child_async_port);
20522     sprintf(outbuf.m_command,"%d",send_buffer->m_command);
20523     sprintf(outbuf.m_testnum,"%d",send_buffer->m_testnum);
20524     sprintf(outbuf.m_version,"%d",send_buffer->m_version);
20525     sprintf(outbuf.m_mygen,"%d",send_buffer->m_mygen);
20526     sprintf(outbuf.m_throughput,"%f",send_buffer->m_throughput);
20527     sprintf(outbuf.m_cputime,"%f", send_buffer->m_cputime);
20528     sprintf(outbuf.m_walltime,"%f",send_buffer->m_walltime);
20529     sprintf(outbuf.m_stop_flag,"%d",send_buffer->m_stop_flag);
20530     sprintf(outbuf.m_actual,"%f",send_buffer->m_actual);
20531 #ifdef NO_PRINT_LLD
20532     sprintf(outbuf.m_child_flag,"%ld",send_buffer->m_child_flag);
20533 #else
20534     sprintf(outbuf.m_child_flag,"%lld",send_buffer->m_child_flag);
20535 #endif
20536     rc=write(child_socket_val,&outbuf,sizeof(struct master_neutral_command));
20537         if (rc < 0) {
20538                 perror("write failed\n");
20539                 exit(26);
20540         }
20541     close(child_socket_val);
20542 }
20543 
20544 
20545 /*
20546  * Master sending message to a child
20547  * There should be a unique child_socket_val for each
20548  * child.
20549  */
20550 #ifdef HAVE_ANSIC_C
20551 void
20552 master_send(int child_socket_val, char *host_name, struct client_command *send_buffer, int send_size)
20553 #else
20554 void
20555 master_send(child_socket_val, host_name, send_buffer, send_size)
20556 int child_socket_val;
20557 char *host_name; 
20558 struct client_command *send_buffer; 
20559 int send_size;
20560 #endif
20561 {
20562     int rc;
20563     struct client_neutral_command outbuf;
20564 
20565     bzero(&outbuf,sizeof(struct client_neutral_command));
20566     if(mdebug)
20567     {
20568         printf("Master_neutral_command size = %lu\n",(unsigned long)sizeof(struct master_neutral_command));
20569         printf("Client_neutral_command size = %lu\n",(unsigned long)sizeof(struct client_neutral_command));
20570     }
20571     /* 
20572      * Convert internal commands to string format for neutral format/portability
20573      */
20574     strcpy(outbuf.c_host_name,send_buffer->c_host_name);
20575     strcpy(outbuf.c_pit_hostname,send_buffer->c_pit_hostname);
20576     strcpy(outbuf.c_pit_service,send_buffer->c_pit_service);
20577     strcpy(outbuf.c_client_name,send_buffer->c_client_name);
20578     strcpy(outbuf.c_working_dir,send_buffer->c_working_dir);
20579     strcpy(outbuf.c_file_name,send_buffer->c_file_name);
20580     strcpy(outbuf.c_path_dir,send_buffer->c_path_dir);
20581     strcpy(outbuf.c_execute_name,send_buffer->c_execute_name);
20582     strcpy(outbuf.c_write_traj_filename,send_buffer->c_write_traj_filename);
20583     strcpy(outbuf.c_read_traj_filename,send_buffer->c_read_traj_filename);
20584     sprintf(outbuf.c_oflag,"%d",send_buffer->c_oflag);
20585     sprintf(outbuf.c_mfflag,"%d",send_buffer->c_mfflag);
20586     sprintf(outbuf.c_unbuffered,"%d",send_buffer->c_unbuffered);
20587     sprintf(outbuf.c_noretest,"%d",send_buffer->c_noretest);
20588     sprintf(outbuf.c_notruncate,"%d",send_buffer->c_notruncate);
20589     sprintf(outbuf.c_read_sync,"%d",send_buffer->c_read_sync);
20590     sprintf(outbuf.c_jflag,"%d",send_buffer->c_jflag);
20591     sprintf(outbuf.c_async_flag,"%d",send_buffer->c_async_flag);
20592     sprintf(outbuf.c_mmapflag,"%d",send_buffer->c_mmapflag);
20593     sprintf(outbuf.c_k_flag,"%d",send_buffer->c_k_flag);
20594     sprintf(outbuf.c_h_flag,"%d",send_buffer->c_h_flag);
20595     sprintf(outbuf.c_mflag,"%d",send_buffer->c_mflag);
20596     sprintf(outbuf.c_pflag,"%d",send_buffer->c_pflag);
20597     sprintf(outbuf.c_stride_flag,"%d",send_buffer->c_stride_flag);
20598     sprintf(outbuf.c_verify,"%d",send_buffer->c_verify);
20599     sprintf(outbuf.c_sverify,"%d",send_buffer->c_sverify);
20600     sprintf(outbuf.c_odsync,"%d",send_buffer->c_odsync);
20601     sprintf(outbuf.c_diag_v,"%d",send_buffer->c_diag_v);
20602     sprintf(outbuf.c_dedup,"%d",send_buffer->c_dedup);
20603     sprintf(outbuf.c_dedup_interior,"%d",send_buffer->c_dedup_interior);
20604     sprintf(outbuf.c_dedup_compress,"%d",send_buffer->c_dedup_compress);
20605     sprintf(outbuf.c_dedup_mseed,"%d",send_buffer->c_dedup_mseed);
20606     sprintf(outbuf.c_hist_summary,"%d",send_buffer->c_hist_summary);
20607     sprintf(outbuf.c_op_rate,"%d",send_buffer->c_op_rate);
20608     sprintf(outbuf.c_op_rate_flag,"%d",send_buffer->c_op_rate_flag);
20609     sprintf(outbuf.c_Q_flag,"%d",send_buffer->c_Q_flag);
20610     sprintf(outbuf.c_L_flag,"%d",send_buffer->c_L_flag);
20611     sprintf(outbuf.c_include_flush,"%d",send_buffer->c_include_flush);
20612     sprintf(outbuf.c_OPS_flag,"%d",send_buffer->c_OPS_flag);
20613     sprintf(outbuf.c_mmapnsflag,"%d",send_buffer->c_mmapnsflag);
20614     sprintf(outbuf.c_mmapssflag,"%d",send_buffer->c_mmapssflag);
20615     sprintf(outbuf.c_mmapasflag,"%d",send_buffer->c_mmapasflag);
20616     sprintf(outbuf.c_no_copy_flag,"%d",send_buffer->c_no_copy_flag);
20617     sprintf(outbuf.c_include_close,"%d",send_buffer->c_include_close);
20618     sprintf(outbuf.c_disrupt_flag,"%d",send_buffer->c_disrupt_flag);
20619     sprintf(outbuf.c_compute_flag,"%d",send_buffer->c_compute_flag);
20620     sprintf(outbuf.c_xflag,"%d",send_buffer->c_xflag);
20621     sprintf(outbuf.c_MS_flag,"%d",send_buffer->c_MS_flag);
20622     sprintf(outbuf.c_mmap_mix,"%d",send_buffer->c_mmap_mix);
20623     sprintf(outbuf.c_Kplus_flag,"%d",send_buffer->c_Kplus_flag);
20624     sprintf(outbuf.c_w_traj_flag,"%d",send_buffer->c_w_traj_flag);
20625     sprintf(outbuf.c_r_traj_flag,"%d",send_buffer->c_r_traj_flag);
20626     sprintf(outbuf.c_direct_flag,"%d",send_buffer->c_direct_flag);
20627     sprintf(outbuf.c_cpuutilflag,"%d",send_buffer->c_cpuutilflag);
20628     sprintf(outbuf.c_seq_mix,"%d",send_buffer->c_seq_mix);
20629     sprintf(outbuf.c_client_number,"%d",send_buffer->c_client_number);
20630     sprintf(outbuf.c_command,"%d",send_buffer->c_command);
20631     sprintf(outbuf.c_testnum,"%d",send_buffer->c_testnum);
20632     sprintf(outbuf.c_no_unlink,"%d",send_buffer->c_no_unlink);
20633     sprintf(outbuf.c_no_write,"%d",send_buffer->c_no_write);
20634     sprintf(outbuf.c_file_lock,"%d",send_buffer->c_file_lock);
20635     sprintf(outbuf.c_rec_lock,"%d",send_buffer->c_rec_lock);
20636     sprintf(outbuf.c_Kplus_readers,"%d",send_buffer->c_Kplus_readers);
20637     sprintf(outbuf.c_multiplier,"%d",send_buffer->c_multiplier);
20638     sprintf(outbuf.c_share_file,"%d",send_buffer->c_share_file);
20639     sprintf(outbuf.c_pattern,"%d",send_buffer->c_pattern);
20640     sprintf(outbuf.c_version,"%d",send_buffer->c_version);
20641     sprintf(outbuf.c_base_time,"%d",send_buffer->c_base_time);
20642     sprintf(outbuf.c_num_child,"%d",send_buffer->c_num_child);
20643     sprintf(outbuf.c_pct_read,"%d",send_buffer->c_pct_read);
20644     sprintf(outbuf.c_advise_op,"%d",send_buffer->c_advise_op);
20645     sprintf(outbuf.c_advise_flag,"%d",send_buffer->c_advise_flag);
20646     sprintf(outbuf.c_restf,"%d",send_buffer->c_restf);
20647     sprintf(outbuf.c_mygen,"%d",send_buffer->c_mygen);
20648 #ifdef NO_PRINT_LLD
20649     sprintf(outbuf.c_stride,"%ld",send_buffer->c_stride);
20650     sprintf(outbuf.c_rest_val,"%ld",send_buffer->c_rest_val);
20651     sprintf(outbuf.c_delay,"%ld",send_buffer->c_delay);
20652     sprintf(outbuf.c_purge,"%ld",send_buffer->c_purge);
20653     sprintf(outbuf.c_fetchon,"%ld",send_buffer->c_fetchon);
20654     sprintf(outbuf.c_numrecs64,"%ld",send_buffer->c_numrecs64);
20655     sprintf(outbuf.c_reclen,"%ld",send_buffer->c_reclen);
20656     sprintf(outbuf.c_child_flag,"%ld",send_buffer->c_child_flag);
20657     sprintf(outbuf.c_delay_start,"%ld",send_buffer->c_delay_start);
20658     sprintf(outbuf.c_depth,"%ld",send_buffer->c_depth);
20659 #else
20660     sprintf(outbuf.c_delay,"%lld",send_buffer->c_delay);
20661     sprintf(outbuf.c_stride,"%lld",send_buffer->c_stride);
20662     sprintf(outbuf.c_rest_val,"%lld",send_buffer->c_rest_val);
20663     sprintf(outbuf.c_purge,"%lld",send_buffer->c_purge);
20664     sprintf(outbuf.c_fetchon,"%lld",send_buffer->c_fetchon);
20665     sprintf(outbuf.c_numrecs64,"%lld",send_buffer->c_numrecs64);
20666     sprintf(outbuf.c_reclen,"%lld",send_buffer->c_reclen);
20667     sprintf(outbuf.c_child_flag,"%lld",send_buffer->c_child_flag);
20668     sprintf(outbuf.c_delay_start,"%lld",send_buffer->c_delay_start);
20669     sprintf(outbuf.c_depth,"%lld",send_buffer->c_depth);
20670 #endif
20671     sprintf(outbuf.c_stop_flag,"%d",send_buffer->c_stop_flag);
20672     sprintf(outbuf.c_compute_time,"%f",send_buffer->c_compute_time);
20673 
20674     if(mdebug >= 1)
20675         printf("Master sending message to %s \n",host_name);
20676         /*rc = send(child_socket_val, (char *)&outbuf, sizeof(struct client_neutral_command), 0);*/
20677         rc = write(child_socket_val, (char *)&outbuf, sizeof(struct client_neutral_command));
20678         if (rc < 0)
20679         {
20680                 perror("write failed\n");
20681                 exit(26);
20682         }
20683 }
20684 
20685 /*
20686  * Close the childs listening port for messages from the master.
20687  */
20688 #ifdef HAVE_ANSIC_C
20689 void
20690 stop_child_listen(int child_socket_val)
20691 #else
20692 void
20693 stop_child_listen(child_socket_val)
20694 int child_socket_val;
20695 #endif
20696 {
20697     close(child_socket_val);
20698 }
20699 
20700 /*
20701  * Close the childs channel for sending messages to the master.
20702  */
20703 #ifdef HAVE_ANSIC_C
20704 void
20705 O_stop_child_send(int child_socket_val)
20706 #else
20707 void
20708 O_stop_child_send(child_socket_val)
20709 int child_socket_val;
20710 #endif
20711 {
20712     close(child_socket_val);
20713 }
20714 
20715 /*
20716  * Close the masters listening channel for all clients messages.
20717  */
20718 #ifdef HAVE_ANSIC_C
20719 void
20720 stop_master_listen(int master_socket_val)
20721 #else
20722 void
20723 stop_master_listen(master_socket_val)
20724 int master_socket_val;
20725 #endif
20726 {
20727     if(mdebug)
20728        printf("Stop master listen\n");
20729 /*
20730     shutdown(master_socket_val,SHUT_RDWR);
20731 */
20732     close(master_socket_val);
20733     master_socket_val = 0;
20734 }
20735 
20736 /*
20737  * Close the masters send channel a particular child.
20738  */
20739 #ifdef HAVE_ANSIC_C
20740 void
20741 stop_master_send(int child_socket_val)
20742 #else
20743 void
20744 stop_master_send(child_socket_val)
20745 int child_socket_val;
20746 #endif
20747 {
20748     close(child_socket_val);
20749 }
20750 
20751 /*
20752  * Start the childs listening service for messages from the master.
20753  */
20754 #ifdef HAVE_ANSIC_C
20755 int
20756 start_child_listen(int size_of_message)
20757 #else
20758 int
20759 start_child_listen(size_of_message)
20760 int size_of_message;
20761 #endif
20762 {
20763     int tsize;
20764     int s;
20765     int rc;
20766     int xx;
20767     int tmp_port;
20768     int sockerr;
20769     int recv_buf_size=65536;
20770     int optval=1;
20771     struct linger dummy={1,0};
20772     xx = 0;
20773     tsize=size_of_message; /* Number of messages to receive */
20774         s = socket(AF_INET, SOCK_STREAM, 0);
20775         if (s < 0)
20776         {
20777                 perror("socket failed:");
20778                 exit(19);
20779         }
20780     sockerr = setsockopt (s, SOL_SOCKET, SO_RCVBUF, (char *)
20781         &recv_buf_size, sizeof(int));
20782     if ( sockerr == -1 ) {
20783         perror("Error in setsockopt 3\n");
20784     }
20785     sockerr = setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (char *)
20786         &optval, sizeof(int));
20787     if ( sockerr == -1 ) {
20788         perror("Error in setsockopt 4\n");
20789     }
20790     sockerr = setsockopt (s, SOL_SOCKET, SO_LINGER, (char *)
20791         &dummy, sizeof(struct linger));
20792     if ( sockerr == -1 ) {
20793         perror("Error in setsockopt 4\n");
20794     }
20795         bzero(&child_sync_sock, sizeof(struct sockaddr_in));
20796     tmp_port=CHILD_LIST_PORT+chid;
20797         child_sync_sock.sin_port = htons(tmp_port);
20798         child_sync_sock.sin_family = AF_INET;
20799         child_sync_sock.sin_addr.s_addr = INADDR_ANY;
20800         rc = -1;
20801         while (rc < 0)
20802         {
20803                 rc = bind(s, (struct sockaddr *)&child_sync_sock,
20804                                 sizeof(struct sockaddr_in));
20805         if(rc < 0)
20806         {
20807             tmp_port++;
20808                     child_sync_sock.sin_port=htons(tmp_port);
20809             continue;
20810         }
20811         }
20812     child_port = ntohs(child_sync_sock.sin_port);
20813     if(cdebug ==1)
20814     {
20815         fprintf(newstdout,"Child %d: Listen: Bound at port %d\n",(int)chid, tmp_port);
20816         fflush(newstdout);
20817     }
20818     if(rc < 0)
20819     {
20820         fprintf(newstdout,"Child bind failed. Errno %d\n",errno);
20821         fflush(newstdout);
20822         exit(20);
20823     }
20824     return(s);
20825 }
20826 #ifdef HAVE_ANSIC_C
20827 int
20828 child_attach(int s, int flag)
20829 #else
20830 int
20831 child_attach(s, flag)
20832 int s,flag;
20833 #endif
20834 {
20835     unsigned int me;
20836     int ns;
20837     struct sockaddr_in *addr;
20838     if(flag)
20839     {
20840         addr=&child_async_sock;
20841         if(cdebug)
20842         {
20843             fprintf(newstdout,"Child %d attach async\n",(int)chid);
20844             fflush(newstdout);
20845         }
20846     }
20847     else
20848     {
20849         addr=&child_sync_sock;
20850         if(cdebug)
20851         {
20852             fprintf(newstdout,"Child %d attach sync\n",(int)chid);
20853             fflush(newstdout);
20854         }
20855     }
20856     me=sizeof(struct sockaddr_in);
20857     if(cdebug)
20858     {
20859         printf("Child %d enters listen\n",(int)chid);
20860         fflush(stdout);
20861     }
20862     listen(s,10);
20863     if(cdebug)
20864     {
20865         fprintf(newstdout,"Child %d enters accept\n",(int)chid);
20866         fflush(newstdout);
20867     }
20868     ns=accept(s,(void *)addr,&me);
20869     if(cdebug)
20870     {
20871         fprintf(newstdout,"Child %d attached for receive. Sock %d  %d\n",
20872             (int)chid, ns,errno);
20873         fflush(newstdout);
20874     }
20875     return(ns);
20876 }
20877     
20878 
20879 /*
20880  * The clients use this to block waiting for a message from
20881  * the master.
20882  */
20883 #ifdef HAVE_ANSIC_C
20884 void
20885 child_listen(int sock, int size_of_message)
20886 #else
20887 void
20888 child_listen(sock, size_of_message)
20889 int sock, size_of_message;
20890 #endif
20891 {
20892     int tsize;
20893     int rcvd;
20894     int s;
20895     int rc;
20896     char *cnc;
20897 
20898     cnc = (char *)&child_rcv_buf[0];
20899     bzero(cnc, sizeof(child_rcv_buf));
20900     s = sock;
20901     tsize=size_of_message; /* Number of messages to receive */
20902     rcvd = 0;
20903     while(rcvd < tsize)
20904     {
20905         if(cdebug ==1)
20906         {
20907             fprintf(newstdout,"Child %d In recieve \n",(int)chid);
20908             fflush(newstdout);
20909         }
20910         rc=read(s,cnc,size_of_message);
20911         if(rc < 0)
20912         {
20913             fprintf(newstdout,"Read failed. Errno %d \n",errno);
20914             fflush(newstdout);
20915             exit(21);
20916         }
20917         if(cdebug >= 1)
20918         {
20919             fprintf(newstdout,"Child %d: Got %d bytes\n",(int)chid, rc);
20920             fflush(newstdout);
20921         }
20922         rcvd+=rc;
20923         cnc+=rc;
20924     }
20925     if(cdebug >= 1)
20926     {
20927         fprintf(newstdout,"Child %d: return from listen\n",(int)chid);
20928         fflush(newstdout);
20929     }
20930 }
20931 /*
20932  * Start the childs async listening service for messages from the master.
20933  */
20934 #ifdef HAVE_ANSIC_C
20935 int
20936 start_child_listen_async(int size_of_message)
20937 #else
20938 int
20939 start_child_listen_async(size_of_message)
20940 int size_of_message;
20941 #endif
20942 {
20943     int tsize;
20944     int s;
20945     int rc;
20946     int xx;
20947     int tmp_port;
20948     int sockerr;
20949     int recv_buf_size=65536;
20950     int optval=1;
20951     xx = 0;
20952     tsize=size_of_message; /* Number of messages to receive */
20953         s = socket(AF_INET, SOCK_STREAM, 0);
20954         if (s < 0)
20955         {
20956                 perror("socket failed:");
20957                 exit(19);
20958         }
20959     sockerr = setsockopt (s, SOL_SOCKET, SO_RCVBUF, (char *)
20960         &recv_buf_size, sizeof(int));
20961     if ( sockerr == -1 ) {
20962         perror("Error in setsockopt 5\n");
20963     }
20964     sockerr = setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (char *)
20965         &optval, sizeof(int));
20966     if ( sockerr == -1 ) {
20967         perror("Error in setsockopt 6\n");
20968     }
20969         bzero(&child_async_sock, sizeof(struct sockaddr_in));
20970     tmp_port=CHILD_ALIST_PORT;
20971         child_async_sock.sin_port = htons(tmp_port);
20972         child_async_sock.sin_family = AF_INET;
20973         child_async_sock.sin_addr.s_addr = INADDR_ANY;
20974         rc = -1;
20975         while (rc < 0)
20976         {
20977                 rc = bind(s, (struct sockaddr *)&child_async_sock,
20978                                 sizeof(struct sockaddr_in));
20979         if(rc < 0)
20980         {
20981             tmp_port++;
20982                     child_async_sock.sin_port=htons(tmp_port);
20983             continue;
20984         }
20985         }
20986     child_async_port = ntohs(child_async_sock.sin_port);
20987     if(cdebug ==1)
20988     {
20989         fprintf(newstdout,"Child %d: Async Listen: Bound at port %d\n",
20990             (int)chid,tmp_port);
20991         fflush(newstdout);
20992     }
20993     if(rc < 0)
20994     {
20995         fprintf(newstdout,"bind failed. Errno %d \n",errno);
20996         fflush(newstdout);
20997         exit(20);
20998     }
20999     return(s);
21000 }
21001 /*
21002  * The clients use this to block waiting for an async message from
21003  * the master.
21004  */
21005 #ifdef HAVE_ANSIC_C
21006 void
21007 child_listen_async(int sock, int size_of_message)
21008 #else
21009 void
21010 child_listen_async(sock, size_of_message)
21011 int sock, size_of_message;
21012 #endif
21013 {
21014     int tsize;
21015     int rcvd;
21016     int s;
21017     int rc;
21018     char *cnc;
21019 
21020     cnc = &child_async_rcv_buf[0];
21021     s = sock;
21022     tsize=size_of_message; /* Number of messages to receive */
21023     rcvd = 0;
21024     while(rcvd < tsize)
21025     {
21026         if(cdebug ==1)
21027         {
21028             fprintf(newstdout,"Child %d In async recieve \n",(int)chid);
21029             fflush(newstdout);
21030         }
21031         rc=read(s,cnc,size_of_message);
21032         if(rc < 0)
21033         {
21034             fprintf(newstdout,"Read failed. Errno %d \n",errno);
21035             fflush(newstdout);
21036             exit(21);
21037         }
21038         /* Special case. If master gets final results, it can 
21039                    exit, and close the connection to the async child
21040                    too quickly. When this happens the child gets a 
21041            read() that returns 0. It just needs to exit here.
21042         */
21043         if(rc==0)
21044             exit(0);
21045         if(cdebug >= 1)
21046         {
21047             fprintf(newstdout,"Child %d: Got %d bytes (async) \n",(int)chid,rc);
21048             fflush(newstdout);
21049         }
21050         rcvd+=rc;
21051         cnc+=rc;
21052     }
21053     if(cdebug >= 1)
21054     {
21055         fprintf(newstdout,"Child %d: return from async listen\n",(int)chid);
21056         fflush(newstdout);
21057     }
21058 }
21059 
21060 /*
21061  * Start the channel for the master to send a message to 
21062  * a particular child on a particular port that the child
21063  * has created for the parent to use to communicate.
21064  */
21065 #ifdef HAVE_ANSIC_C
21066 int
21067 start_master_send(char *child_host_name, int child_port, struct in_addr *my_s_addr)
21068 #else
21069 int
21070 start_master_send(child_host_name, child_port, my_s_addr)
21071 char *child_host_name; 
21072 int child_port;
21073 struct in_addr *my_s_addr;
21074 #endif
21075 {
21076     int rc,master_socket_val;
21077     struct sockaddr_in addr,raddr;
21078     struct hostent *he;
21079     int port,tmp_port;
21080     int ecount = 0;
21081     struct in_addr *ip;
21082     struct timespec req,rem;
21083 
21084     req.tv_sec = 0;
21085     req.tv_nsec = 10000000;
21086     rem.tv_sec = 0;
21087     rem.tv_nsec = 10000000;
21088 
21089         he = gethostbyname(child_host_name);
21090         if (he == NULL)
21091         {
21092                 printf("Master: Bad hostname >%s<\n",child_host_name);
21093         fflush(stdout);
21094                 exit(22);
21095         }
21096     if(mdebug ==1)
21097     {
21098             printf("Master: start master send: %s\n", he->h_name);
21099         fflush(stdout);
21100     }
21101         ip = (struct in_addr *)he->h_addr_list[0];
21102 #ifndef UWIN
21103     if(mdebug ==1)
21104     {
21105             printf("Master: child name: %s\n", (char *)inet_ntoa(*ip));
21106             printf("Master: child Port: %d\n", child_port);
21107         fflush(stdout);
21108     }
21109 #endif
21110 
21111     port=child_port;
21112     my_s_addr->s_addr = ip->s_addr;
21113     /*port=CHILD_LIST_PORT;*/
21114 
21115         raddr.sin_family = AF_INET;
21116         raddr.sin_port = htons(port);
21117         raddr.sin_addr.s_addr = ip->s_addr;
21118         master_socket_val = socket(AF_INET, SOCK_STREAM, 0);
21119         if (master_socket_val < 0)
21120         {
21121                 perror("Master: socket failed:");
21122                 exit(23);
21123         }
21124         bzero(&addr, sizeof(struct sockaddr_in));
21125     tmp_port=HOST_ESEND_PORT;
21126         addr.sin_port = htons(tmp_port);
21127         addr.sin_family = AF_INET;
21128         addr.sin_addr.s_addr = INADDR_ANY;
21129         rc = -1;
21130         while (rc < 0)
21131         {
21132                 rc = bind(master_socket_val, (struct sockaddr *)&addr,
21133                                                 sizeof(struct sockaddr_in));
21134         if(rc < 0)
21135         {
21136             tmp_port++;
21137                     addr.sin_port=htons(tmp_port);
21138             continue;
21139         }
21140         }
21141     if(mdebug ==1)
21142     {
21143         printf("Master: Bound port\n");
21144         fflush(stdout);
21145     }
21146         if (rc < 0)
21147         {
21148                 perror("Master: bind failed for sync channel to child.\n");
21149                 exit(24);
21150         }
21151     nanosleep(&req,&rem);
21152 again:
21153         rc = connect(master_socket_val, (struct sockaddr *)&raddr, 
21154             sizeof(struct sockaddr_in));
21155     if (rc < 0)
21156         {
21157         if(ecount++ < 300)
21158         {
21159             nanosleep(&req,&rem);
21160             /*sleep(1);*/
21161             goto again;
21162         }
21163                 perror("Master: connect failed\n");
21164         printf("Error %d\n",errno);
21165                 exit(25);
21166         }
21167     if(mdebug ==1)
21168     {
21169         printf("Master Connected\n");
21170         fflush(stdout);
21171     }
21172     return (master_socket_val);
21173 }
21174 /*
21175  * Start the channel for the master to send a message to 
21176  * a particular child on a particular port that the child
21177  * has created for the parent to use to communicate.
21178  */
21179 #ifdef HAVE_ANSIC_C
21180 int
21181 start_master_send_async(char *child_host_name, int child_port, struct in_addr my_s_addr)
21182 #else
21183 int
21184 start_master_send_async(child_host_name, child_port, my_s_addr)
21185 char *child_host_name; 
21186 int child_port;
21187 struct in_addr my_s_addr;
21188 #endif
21189 {
21190     int rc,master_socket_val;
21191     struct sockaddr_in addr,raddr;
21192     int port,tmp_port;
21193     int ecount = 0;
21194     struct timespec req,rem;
21195 
21196     req.tv_sec = 0;
21197     req.tv_nsec = 10000000;
21198     rem.tv_sec = 0;
21199     rem.tv_nsec = 10000000;
21200 
21201 
21202     port=child_port;
21203     nanosleep(&req,&rem);
21204 
21205 over:
21206         raddr.sin_family = AF_INET;
21207         raddr.sin_port = htons(port);
21208         raddr.sin_addr.s_addr = my_s_addr.s_addr;
21209         master_socket_val = socket(AF_INET, SOCK_STREAM, 0);
21210         if (master_socket_val < 0)
21211         {
21212                 perror("Master: async socket failed:");
21213                 exit(23);
21214         }
21215         bzero(&addr, sizeof(struct sockaddr_in));
21216     tmp_port=HOST_ASEND_PORT;
21217         addr.sin_port = htons(tmp_port);
21218         addr.sin_family = AF_INET;
21219         addr.sin_addr.s_addr = INADDR_ANY;
21220         rc = -1;
21221         while (rc < 0)
21222         {
21223                 rc = bind(master_socket_val, (struct sockaddr *)&addr,
21224                                                 sizeof(struct sockaddr_in));
21225         if(rc < 0)
21226         {
21227             tmp_port++;
21228                     addr.sin_port=htons(tmp_port);
21229             continue;
21230         }
21231         }
21232     if(mdebug ==1)
21233     {
21234         printf("Master: Bound async port\n");
21235         fflush(stdout);
21236     }
21237         if (rc < 0)
21238         {
21239                 perror("Master: bind async failed\n");
21240                 exit(24);
21241         }
21242 again:
21243 
21244         rc = connect(master_socket_val, (struct sockaddr *)&raddr, 
21245             sizeof(struct sockaddr_in));
21246     if (rc < 0)
21247         {
21248         if(ecount++ < 300)
21249         {
21250         /* Really need this sleep for Windows */
21251 #if defined (Windows)
21252             sleep(1);
21253 #else
21254             nanosleep(&req,&rem);
21255 #endif
21256             goto again;
21257         }
21258                 perror("Master: async connect failed\n");
21259                 close(master_socket_val);
21260 #if defined (Windows)
21261         sleep(1);
21262 #else
21263         nanosleep(&req,&rem);
21264 #endif
21265                 /*sleep(1);*/
21266                 ecount=0;
21267                 goto over;
21268         }
21269     if(mdebug ==1)
21270     {
21271         printf("Master async Connected\n");
21272         fflush(stdout);
21273     }
21274     return (master_socket_val);
21275 }
21276 
21277 /*
21278  * If not "distributed" then call fork. The "distributed"
21279  * will start iozone on a remote node.
21280  */
21281 #ifdef HAVE_ANSIC_C
21282 long long
21283 start_child_proc(int testnum,long long numrecs64, long long reclen)
21284 #else
21285 long long
21286 start_child_proc(testnum, numrecs64, reclen)
21287 int testnum;
21288 long long numrecs64, reclen;
21289 #endif
21290 {
21291     long long x;
21292     if(distributed && master_iozone)
21293     {
21294         x=(long long)pick_client(testnum,numrecs64, reclen);
21295     }
21296     else
21297     {
21298         x=(long long)fork();
21299     }
21300     if(mdebug)
21301         printf("Starting proc %d\n",(int)x);    
21302     return(x);
21303 }   
21304 
21305 /*
21306  * This function picks a client from the list of clients and
21307  * starts it running on the remote machine. It also waits for
21308  * the remote process to join and then sends the client
21309  * the state information it needs to begin to run the 
21310  * test. The client will initialize its state space, 
21311  * begin the test and block as the barrier waiting
21312  * for the master to say go.
21313  */
21314 #ifdef HAVE_ANSIC_C
21315 int
21316 pick_client(int testnum,long long numrecs64, long long reclen)
21317 #else
21318 int
21319 pick_client(testnum, numrecs64, reclen)
21320 int testnum;
21321 long long numrecs64, reclen;
21322 #endif
21323 {
21324     int x;
21325     int c_command,child_index;
21326     struct client_command cc;
21327     struct master_command mc;
21328     struct master_neutral_command *mnc;
21329     char command[512];
21330     struct in_addr my_s_addr;
21331     char my_port_num[10];
21332 
21333 
21334     bzero(&cc,sizeof(struct client_command));
21335     for(x=0;x<512;x++)
21336         command[x]=0;
21337 
21338     current_client_number++; /* Need to start with 1 */
21339     x=current_client_number;
21340 
21341     child_idents[x-1].state = C_STATE_ZERO;
21342     /* Step 1. Now start client going on remote node.   */
21343 
21344     find_remote_shell(remote_shell);
21345     sprintf(command,"%s ",remote_shell);
21346     strcat(command,child_idents[x-1].child_name);
21347     strcat(command," -n '");
21348     strcat(command,child_idents[x-1].execute_path);
21349     strcat(command," -+s -t 1 -r 4 -s 4 -+c ");
21350     strcat(command,controlling_host_name);
21351         if (master_listen_port != HOST_LIST_PORT)
21352         {
21353           sprintf(my_port_num," -+i %d",master_listen_port);
21354           strcat(command,my_port_num);
21355         }
21356     strcat(command," '");
21357     junk=system(command);
21358 /*
21359     system("remsh rsnperf '/home/capps/niozone/iozone -+s -t 1 -r 4 -s 8 -+c rsnperf'");
21360 
21361 */
21362     if(mdebug)
21363         printf("%s",command);
21364     /* Format example:                  */
21365     /*                          */
21366     /* system("remsh rsnperf '/home/capps/niozone/iozone    */
21367     /*       -+s -t 1 -r 4 -s 8 -+c rsnperf'");     */
21368     /*                          */
21369 
21370     /* Step 2. Wait for join from new client.       */
21371 
21372     child_idents[x-1].state = C_STATE_WAIT_WHO;
21373 
21374     if(mdebug>=1)
21375         printf("\nMaster listening for child to send join message.\n");
21376     master_listen(master_listen_socket,sizeof(struct master_neutral_command));
21377     mnc = (struct master_neutral_command *)&master_rcv_buf[0];
21378 
21379     /* 
21380      * Convert from string format back to internal representation
21381      */
21382     sscanf(mnc->m_child_port,"%d",&mc.m_child_port);    
21383     sscanf(mnc->m_child_async_port,"%d",&mc.m_child_async_port);    
21384     sscanf(mnc->m_command,"%d",&mc.m_command);  
21385     sscanf(mnc->m_version,"%d",&mc.m_version);  
21386     if(mc.m_version != proto_version)
21387     {
21388         printf("Client > %s < is not running the same version of Iozone !! C%d M%d\n", child_idents[x-1].child_name, mc.m_version, proto_version);
21389     }
21390 
21391     c_port = mc.m_child_port; 
21392     a_port = mc.m_child_async_port; 
21393     c_command = mc.m_command;
21394     if(mdebug>=1)
21395     {
21396         printf("Master back from listen child Joined.\n");
21397         printf("Master: Command %d\n",c_command);
21398     }
21399     /* Step 3. Then start_master_send() for this client.    */
21400     
21401     if(mdebug>=1)
21402         printf("Starting master send channel\n");
21403         master_send_sockets[x-1]= start_master_send(child_idents[x-1].child_name,c_port,
21404         &my_s_addr); 
21405     if(mdebug>=1)
21406         printf("Starting master send async channel\n");
21407         master_send_async_sockets[x-1]= start_master_send_async(child_idents[x-1].child_name,a_port,
21408         my_s_addr); 
21409 
21410     child_idents[x-1].master_socket_num = master_send_sockets[x-1];
21411     child_idents[x-1].master_async_socket_num = master_send_async_sockets[x-1];
21412     child_idents[x-1].child_number = x-1;
21413     child_idents[x-1].child_port = c_port;
21414     child_idents[x-1].child_async_port = a_port;
21415 
21416     /*                              */
21417     /* Step 4. Send message to client telling him his name, number, */
21418     /*             rsize, fsize, and test to run.           */
21419     strcpy(cc.c_host_name ,controlling_host_name);
21420     strcpy(cc.c_pit_hostname ,pit_hostname);
21421     strcpy(cc.c_pit_service ,pit_service);
21422     strcpy(cc.c_client_name ,child_idents[x-1].child_name);
21423     strcpy(cc.c_working_dir ,child_idents[x-1].workdir);
21424     strcpy(cc.c_file_name ,child_idents[x-1].file_name);
21425     strcpy(cc.c_write_traj_filename ,write_traj_filename);
21426     strcpy(cc.c_read_traj_filename ,read_traj_filename);
21427     cc.c_command = R_JOIN_ACK;
21428     cc.c_client_number = x-1;
21429     cc.c_testnum = testnum;
21430     cc.c_numrecs64 = numrecs64;
21431     cc.c_reclen = reclen;
21432     cc.c_oflag = oflag;
21433     cc.c_mfflag = mfflag;
21434     cc.c_unbuffered = unbuffered;
21435     cc.c_noretest = noretest;
21436     cc.c_notruncate = notruncate;
21437     cc.c_read_sync = read_sync;
21438     cc.c_jflag = jflag;
21439     cc.c_direct_flag = direct_flag;
21440     cc.c_cpuutilflag = cpuutilflag;
21441     cc.c_seq_mix = seq_mix;
21442     cc.c_async_flag = async_flag;
21443     cc.c_k_flag = k_flag;
21444     cc.c_h_flag = h_flag;
21445     cc.c_mflag = mflag;
21446     cc.c_pflag = pflag;
21447     cc.c_stride_flag = stride_flag;
21448     cc.c_fetchon = fetchon;
21449     cc.c_verify = verify;
21450     cc.c_sverify = sverify;
21451     cc.c_odsync = odsync;
21452     cc.c_diag_v = diag_v;
21453     cc.c_dedup = dedup;
21454     cc.c_dedup_interior = dedup_interior;
21455     cc.c_dedup_compress = dedup_compress;
21456     cc.c_dedup_mseed = dedup_mseed;
21457     cc.c_hist_summary = hist_summary;
21458     cc.c_op_rate = op_rate;
21459     cc.c_op_rate_flag = op_rate_flag;
21460     cc.c_file_lock = file_lock;
21461     cc.c_rec_lock = rlocking;
21462     cc.c_Kplus_readers = Kplus_readers;
21463     cc.c_multiplier = multiplier;
21464     cc.c_share_file = share_file;
21465     cc.c_pattern = pattern;
21466     cc.c_version = proto_version;
21467     cc.c_base_time = base_time;
21468     cc.c_num_child = (int)num_child;
21469     cc.c_pct_read = pct_read;
21470     cc.c_advise_op = advise_op;
21471     cc.c_advise_flag = advise_flag;
21472     cc.c_restf = restf;
21473     cc.c_mygen = mygen;
21474     cc.c_Q_flag = Q_flag;
21475     cc.c_L_flag = L_flag;
21476     cc.c_xflag = xflag;
21477     cc.c_w_traj_flag = w_traj_flag;
21478     cc.c_r_traj_flag = r_traj_flag;
21479     cc.c_include_flush = include_flush;
21480     cc.c_OPS_flag = OPS_flag;
21481     cc.c_purge = purge;
21482     cc.c_mmapflag = mmapflag;
21483     cc.c_mmapasflag = mmapasflag;
21484     cc.c_mmapnsflag = mmapnsflag;
21485     cc.c_mmapssflag = mmapssflag;
21486     cc.c_no_copy_flag = no_copy_flag;
21487     cc.c_no_unlink = no_unlink;
21488     cc.c_no_write = no_write;
21489     cc.c_include_close = include_close;
21490     cc.c_disrupt_flag = disrupt_flag;
21491     cc.c_compute_flag = compute_flag;
21492     cc.c_delay = delay;
21493     cc.c_stride = stride;
21494     cc.c_rest_val = rest_val;
21495     cc.c_delay_start = delay_start;
21496     cc.c_compute_time = compute_time;
21497     cc.c_depth = depth;
21498     cc.c_MS_flag = MS_flag;
21499     cc.c_mmap_mix = mmap_mix;
21500     cc.c_Kplus_flag = Kplus_flag;
21501 
21502 
21503     if(mdebug)
21504         printf("Master sending client who he is\n");
21505     master_send(master_send_sockets[x-1],cc.c_client_name, &cc,sizeof(struct client_command));
21506 
21507     child_idents[x-1].state = C_STATE_WAIT_BARRIER;
21508     
21509     /*                              */
21510     /* Step 5. Wait until you receive message that the chile is at  */
21511     /*             the barrier.                     */
21512     if(mdebug>=1)
21513        printf("Master listening for child to send at barrier message.\n");
21514     master_listen(master_listen_socket,sizeof(struct master_neutral_command));
21515     mnc = (struct master_neutral_command *)&master_rcv_buf[0];
21516     /*
21517      * Convert from string back to arch specific 
21518      */
21519     sscanf(mnc->m_client_number,"%d",&mc.m_client_number);  
21520 #ifdef NO_PRINT_LLD
21521     sscanf(mnc->m_child_flag,"%ld",&mc.m_child_flag);   
21522 #else
21523     sscanf(mnc->m_child_flag,"%lld",&mc.m_child_flag);  
21524 #endif
21525 
21526     child_index = mc.m_client_number;
21527     child_stat = (struct child_stats *)&shmaddr[child_index];   
21528     child_stat->flag = (long long)(mc.m_child_flag);
21529     if(mdebug>=1)
21530        printf("Master sees child %d at barrier message.\n",child_index);
21531 
21532     return(x); /* Tell code above that it is the parent returning */
21533 }
21534 
21535 /****************************************************************************************/
21536 /* This is the code that the client will use when it                    */
21537 /* gets started via remote shell. It is activated by the -+c controller_name option.    */
21538 /*                                          */
21539 /* The steps to this process are:                           */
21540 /* 1. Start client receive channel                          */
21541 /* 2. Start client send channel                             */
21542 /* 3. Send message to controller saying I'm joining.                    */
21543 /* 4. Go into a loop and get all instructions from                  */
21544 /* 5. Get state information from the master                         */
21545 /* 6. Change to the working directory                           */
21546 /* 7. Run the test                                  */
21547 /* 8. Release the listen and send sockets to the master                 */
21548 /*                                          */
21549 /****************************************************************************************/
21550 #ifdef HAVE_ANSIC_C
21551 void
21552 become_client(void)
21553 #else
21554 void
21555 become_client()
21556 #endif
21557 {
21558     int x,testnum;
21559     struct master_command mc;
21560     struct client_command cc;
21561     struct client_neutral_command *cnc;
21562     char client_name[100];
21563     char *workdir;
21564 
21565     bzero(&mc,sizeof(struct master_command));
21566     x=fork(); /* Become a daemon so that remote shell will return. */
21567     if(x != 0)
21568         exit(0);
21569     /*
21570      * I am the child 
21571      */
21572     (void)gethostname(client_name,100);
21573 
21574     fflush(stdout);
21575     fflush(stderr);
21576     if(cdebug)
21577     {
21578         newstdin=freopen("/tmp/don_in","r+",stdin);
21579         newstdout=freopen("/tmp/don_out","a+",stdout);
21580         newstderr=freopen("/tmp/don_err","a+",stderr);
21581     }
21582     else
21583     {
21584         fclose(stdin);
21585         fclose(stdout);
21586         fclose(stderr);
21587     }
21588     if(cdebug>=1)
21589     {
21590         fprintf(newstdout,"My name = %s, Controller's name = %s\n",client_name, controlling_host_name);
21591         fflush(newstdout);
21592     }
21593 
21594     /* 1. Start client receive channel              */
21595 
21596     l_sock = start_child_listen(sizeof(struct client_neutral_command));
21597     l_async_sock = start_child_listen_async(sizeof(struct client_neutral_command));
21598 
21599     /* 2. Send message to controller saying I'm joining.        */
21600 
21601     strcpy(mc.m_host_name,controlling_host_name);
21602     strcpy(mc.m_client_name,client_name);
21603     mc.m_child_port = child_port;
21604     mc.m_child_async_port = child_async_port;
21605     mc.m_command = R_CHILD_JOIN;
21606     mc.m_version = proto_version;
21607     
21608     if(cdebug)
21609     {
21610         fprintf(newstdout,"Child %s sends JOIN to master %s Host Port %d\n",
21611             client_name,controlling_host_name,controlling_host_port);
21612         fflush(newstdout);
21613     }
21614     child_send(controlling_host_name,(struct master_command *)&mc, sizeof(struct master_command));
21615 
21616     l_sock=child_attach(l_sock,0);
21617     l_async_sock=child_attach(l_async_sock,1);
21618     
21619     /* 4. Go into a loop and get all instructions from      */
21620         /*    the controlling process.                  */
21621 
21622     if(cdebug>=1)
21623     {
21624         fprintf(newstdout,"Child %s waiting for who am I\n",client_name);
21625         fflush(newstdout);
21626     }
21627     child_listen(l_sock,sizeof(struct client_neutral_command));
21628     cnc = (struct client_neutral_command *)&child_rcv_buf;
21629     bzero(&cc, sizeof(struct client_command));
21630     
21631     /* Convert from string format to arch format */
21632     sscanf(cnc->c_command,"%d",&cc.c_command);
21633     sscanf(cnc->c_client_name,"%s",cc.c_client_name);
21634     sscanf(cnc->c_client_number,"%d",&cc.c_client_number);
21635     sscanf(cnc->c_host_name,"%s",cc.c_host_name);
21636     sscanf(cnc->c_pit_hostname,"%s",cc.c_pit_hostname);
21637 
21638     if(cc.c_command == R_TERMINATE || cc.c_command==R_DEATH)
21639     {
21640         if(cdebug)
21641         {
21642             fprintf(newstdout,"Child %d received terminate on sync channel !!\n",(int)chid);
21643             fflush(newstdout);
21644         }
21645         exit(1);
21646     }
21647     
21648     if(cdebug)
21649     {
21650          fprintf(newstdout,"Child sees: \n Client name %s \n Client_num # %d \n Host_name %s\n"
21651             ,cc.c_client_name,cc.c_client_number,cc.c_host_name);
21652      fflush(newstdout);
21653     }
21654 
21655     /*
21656      * Now import all of the values of the flags that the child on this 
21657      * machine needs to be able to run the test requested.
21658      */
21659 
21660     /* 5. Get state information from the master */
21661 
21662 #ifdef NO_PRINT_LLD
21663     sscanf(cnc->c_numrecs64,"%ld",&cc.c_numrecs64);
21664     sscanf(cnc->c_reclen,"%ld",&cc.c_reclen);
21665     sscanf(cnc->c_fetchon,"%ld",&cc.c_fetchon);
21666     sscanf(cnc->c_purge,"%ld",&cc.c_purge);
21667     sscanf(cnc->c_delay,"%ld",&cc.c_delay);
21668     sscanf(cnc->c_stride,"%ld",&cc.c_stride);
21669     sscanf(cnc->c_rest_val,"%ld",&cc.c_rest_val);
21670     sscanf(cnc->c_delay_start,"%ld",&cc.c_delay_start);
21671     sscanf(cnc->c_depth,"%ld",&cc.c_depth);
21672 #else
21673     sscanf(cnc->c_numrecs64,"%lld",&cc.c_numrecs64);
21674     sscanf(cnc->c_reclen,"%lld",&cc.c_reclen);
21675     sscanf(cnc->c_fetchon,"%lld",&cc.c_fetchon);
21676     sscanf(cnc->c_purge,"%lld",&cc.c_purge);
21677     sscanf(cnc->c_delay,"%lld",&cc.c_delay);
21678     sscanf(cnc->c_stride,"%lld",&cc.c_stride);
21679     sscanf(cnc->c_rest_val,"%lld",&cc.c_rest_val);
21680     sscanf(cnc->c_delay_start,"%lld",&cc.c_delay_start);
21681     sscanf(cnc->c_depth,"%lld",&cc.c_depth);
21682 #endif
21683     sscanf(cnc->c_pit_hostname,"%s",cc.c_pit_hostname);
21684     sscanf(cnc->c_pit_service,"%s",cc.c_pit_service);
21685     sscanf(cnc->c_testnum,"%d",&cc.c_testnum);
21686     sscanf(cnc->c_client_number,"%d",&cc.c_client_number);
21687     sscanf(cnc->c_working_dir,"%s",cc.c_working_dir);
21688     sscanf(cnc->c_file_name,"%s",cc.c_file_name);
21689     sscanf(cnc->c_write_traj_filename,"%s",cc.c_write_traj_filename);
21690     sscanf(cnc->c_read_traj_filename,"%s",cc.c_read_traj_filename);
21691     sscanf(cnc->c_noretest,"%d",&cc.c_noretest);
21692     sscanf(cnc->c_notruncate,"%d",&cc.c_notruncate);
21693     sscanf(cnc->c_read_sync,"%d",&cc.c_read_sync);
21694     sscanf(cnc->c_jflag,"%d",&cc.c_jflag);
21695     sscanf(cnc->c_direct_flag,"%d",&cc.c_direct_flag);
21696     sscanf(cnc->c_cpuutilflag,"%d",&cc.c_cpuutilflag);
21697     sscanf(cnc->c_seq_mix,"%d",&cc.c_seq_mix);
21698     sscanf(cnc->c_async_flag,"%d",&cc.c_async_flag);
21699     sscanf(cnc->c_k_flag,"%d",&cc.c_k_flag);
21700     sscanf(cnc->c_h_flag,"%d",&cc.c_h_flag);
21701     sscanf(cnc->c_mflag,"%d",&cc.c_mflag);
21702     sscanf(cnc->c_pflag,"%d",&cc.c_pflag);
21703     sscanf(cnc->c_stride_flag,"%d",&cc.c_stride_flag);
21704     sscanf(cnc->c_verify,"%d",&cc.c_verify);
21705     sscanf(cnc->c_sverify,"%d",&cc.c_sverify);
21706     sscanf(cnc->c_odsync,"%d",&cc.c_odsync);
21707     sscanf(cnc->c_diag_v,"%d",&cc.c_diag_v);
21708     sscanf(cnc->c_dedup,"%d",&cc.c_dedup);
21709     sscanf(cnc->c_dedup_interior,"%d",&cc.c_dedup_interior);
21710     sscanf(cnc->c_dedup_compress,"%d",&cc.c_dedup_compress);
21711     sscanf(cnc->c_dedup_mseed,"%d",&cc.c_dedup_mseed);
21712     sscanf(cnc->c_hist_summary,"%d",&cc.c_hist_summary);
21713     sscanf(cnc->c_op_rate,"%d",&cc.c_op_rate);
21714     sscanf(cnc->c_op_rate_flag,"%d",&cc.c_op_rate_flag);
21715     sscanf(cnc->c_file_lock,"%d",&cc.c_file_lock);
21716     sscanf(cnc->c_rec_lock,"%d",&cc.c_rec_lock);
21717     sscanf(cnc->c_Kplus_readers,"%d",&cc.c_Kplus_readers);
21718     sscanf(cnc->c_multiplier,"%d",&cc.c_multiplier);
21719     sscanf(cnc->c_share_file,"%d",&cc.c_share_file);
21720     sscanf(cnc->c_pattern,"%d",&cc.c_pattern);
21721     sscanf(cnc->c_version,"%d",&cc.c_version);
21722     sscanf(cnc->c_base_time,"%d",&cc.c_base_time);
21723     sscanf(cnc->c_num_child,"%d",&cc.c_num_child);
21724     sscanf(cnc->c_pct_read,"%d",&cc.c_pct_read);
21725     sscanf(cnc->c_advise_op,"%d",&cc.c_advise_op);
21726     sscanf(cnc->c_advise_flag,"%d",&cc.c_advise_flag);
21727     sscanf(cnc->c_restf,"%d",&cc.c_restf);
21728     sscanf(cnc->c_mygen,"%d",&cc.c_mygen);
21729     sscanf(cnc->c_oflag,"%d",&cc.c_oflag);
21730     sscanf(cnc->c_mfflag,"%d",&cc.c_mfflag);
21731     sscanf(cnc->c_unbuffered,"%d",&cc.c_unbuffered);
21732     sscanf(cnc->c_Q_flag,"%d",&cc.c_Q_flag);
21733     sscanf(cnc->c_L_flag,"%d",&cc.c_L_flag);
21734     sscanf(cnc->c_xflag,"%d",&cc.c_xflag);
21735     sscanf(cnc->c_include_flush,"%d",&cc.c_include_flush);
21736     sscanf(cnc->c_OPS_flag,"%d",&cc.c_OPS_flag);
21737     sscanf(cnc->c_mmapflag,"%d",&cc.c_mmapflag);
21738     sscanf(cnc->c_mmapasflag,"%d",&cc.c_mmapasflag);
21739     sscanf(cnc->c_mmapnsflag,"%d",&cc.c_mmapnsflag);
21740     sscanf(cnc->c_mmapssflag,"%d",&cc.c_mmapssflag);
21741     sscanf(cnc->c_no_copy_flag,"%d",&cc.c_no_copy_flag);
21742     sscanf(cnc->c_w_traj_flag,"%d",&cc.c_w_traj_flag);
21743     sscanf(cnc->c_r_traj_flag,"%d",&cc.c_r_traj_flag);
21744     sscanf(cnc->c_no_unlink,"%d",&cc.c_no_unlink);
21745     sscanf(cnc->c_no_write,"%d",&cc.c_no_write);
21746     sscanf(cnc->c_include_close,"%d",&cc.c_include_close);
21747     sscanf(cnc->c_disrupt_flag,"%d",&cc.c_disrupt_flag);
21748     sscanf(cnc->c_compute_flag,"%d",&cc.c_compute_flag);
21749     sscanf(cnc->c_MS_flag,"%d",&cc.c_MS_flag);
21750     sscanf(cnc->c_mmap_mix,"%d",&cc.c_mmap_mix);
21751     sscanf(cnc->c_Kplus_flag,"%d",&cc.c_Kplus_flag);
21752     sscanf(cnc->c_compute_time,"%f",&cc.c_compute_time);
21753 
21754     strcpy(write_traj_filename,cc.c_write_traj_filename);
21755     strcpy(read_traj_filename,cc.c_read_traj_filename);
21756     numrecs64 = cc.c_numrecs64;
21757     strcpy(pit_hostname,cc.c_pit_hostname);
21758     strcpy(pit_service,cc.c_pit_service);
21759     reclen = cc.c_reclen;
21760     testnum = cc.c_testnum;
21761     chid = cc.c_client_number;
21762     workdir=cc.c_working_dir;
21763     oflag = cc.c_oflag;
21764     /* Child's absolute filename to use is provided */
21765     mfflag = cc.c_mfflag;
21766     if(mfflag)
21767         strcpy(filearray[chid],cc.c_file_name);
21768     if(cdebug)
21769     {
21770         fprintf(newstdout,"File name given %s\n",cc.c_file_name);
21771         fflush(newstdout);
21772     }
21773     unbuffered = cc.c_unbuffered;
21774     noretest = cc.c_noretest;
21775     notruncate = cc.c_notruncate;
21776     read_sync = cc.c_read_sync;
21777     jflag = cc.c_jflag;
21778     direct_flag = cc.c_direct_flag;
21779     cpuutilflag = cc.c_cpuutilflag;
21780     seq_mix = cc.c_seq_mix;
21781     async_flag = cc.c_async_flag;
21782     k_flag = cc.c_k_flag;
21783     h_flag = cc.c_h_flag;
21784     mflag = cc.c_mflag;
21785     pflag = cc.c_pflag;
21786     stride_flag = cc.c_stride_flag;
21787     fetchon = cc.c_fetchon;
21788     verify = cc.c_verify;
21789     diag_v = cc.c_diag_v;
21790     dedup = cc.c_dedup;
21791     dedup_interior = cc.c_dedup_interior;
21792     dedup_compress = cc.c_dedup_compress;
21793     dedup_mseed = cc.c_dedup_mseed;
21794     hist_summary = cc.c_hist_summary;
21795     op_rate = cc.c_op_rate;
21796     op_rate_flag = cc.c_op_rate_flag;
21797     if(diag_v)
21798         sverify = 0;
21799     else
21800         sverify = cc.c_sverify;
21801     file_lock = cc.c_file_lock;
21802     rlocking = cc.c_rec_lock;
21803     Kplus_readers = cc.c_Kplus_readers;
21804     multiplier = cc.c_multiplier;
21805     share_file = cc.c_share_file;
21806     pattern = cc.c_pattern;
21807     /* proto_version = cc.c_version; Don't copy it back. */
21808     base_time=cc.c_base_time;
21809     num_child=(long long)cc.c_num_child;
21810     pct_read=cc.c_pct_read;
21811     advise_op=cc.c_advise_op;
21812     advise_flag=cc.c_advise_flag;
21813     restf=cc.c_restf;
21814     mygen=cc.c_mygen;
21815     Q_flag = cc.c_Q_flag;
21816     L_flag = cc.c_L_flag;
21817     xflag = cc.c_xflag;
21818     w_traj_flag = cc.c_w_traj_flag;
21819     r_traj_flag = cc.c_r_traj_flag;
21820     include_flush = cc.c_include_flush;
21821     OPS_flag = cc.c_OPS_flag;
21822     purge = cc.c_purge;
21823     mmapflag = cc.c_mmapflag;
21824     mmapasflag = cc.c_mmapasflag;
21825     mmapnsflag = cc.c_mmapnsflag;
21826     mmapssflag = cc.c_mmapssflag; 
21827     no_copy_flag = cc.c_no_copy_flag;
21828     no_unlink = cc.c_no_unlink;
21829     no_write = cc.c_no_write;
21830     include_close = cc.c_include_close;
21831     disrupt_flag = cc.c_disrupt_flag;
21832     compute_flag = cc.c_compute_flag;
21833     MS_flag = cc.c_MS_flag;
21834     mmap_mix = cc.c_mmap_mix;
21835     Kplus_flag = cc.c_Kplus_flag;
21836     delay = cc.c_delay;
21837     stride = cc.c_stride;
21838     rest_val = cc.c_rest_val;
21839     depth = cc.c_depth;
21840     delay_start = cc.c_delay_start;
21841     compute_time = cc.c_compute_time;
21842     if(cdebug)
21843     {
21844         fprintf(newstdout,"Child %d change directory to %s\n",(int)chid,workdir);
21845         fflush(newstdout);
21846     }
21847     if(purge)
21848         alloc_pbuf();
21849 
21850     /* 6. Change to the working directory */
21851 
21852     if(chdir(workdir)<0)
21853         client_error=errno;
21854     start_child_listen_loop(); /* The async channel listener */
21855 
21856     /* Need to start this after getting into the correct directory */
21857     if(w_traj_flag)
21858         w_traj_size();
21859     if(r_traj_flag)
21860         r_traj_size();
21861 
21862     get_resolution();       /* Get my clock resolution */
21863     if(hist_summary)
21864     {
21865         printf("Child got HISTORY flag\n");
21866     }
21867 
21868     /* 7. Run the test */
21869     switch(testnum) {
21870 
21871     case THREAD_WRITE_TEST : 
21872         if(cdebug>=1)
21873         {
21874             fprintf(newstdout,"Child %d running thread_write_test\n",(int)chid);
21875             fflush(newstdout);
21876         }
21877         thread_write_test((long)0);
21878         break;
21879 #ifdef HAVE_PREAD
21880     case THREAD_PWRITE_TEST : 
21881         if(cdebug>=1)
21882         {
21883             fprintf(newstdout,"Child %d running thread_pwrite_test\n",(int)chid);
21884             fflush(newstdout);
21885         }
21886         thread_pwrite_test((long)0);
21887         break;
21888 #endif
21889     case THREAD_REWRITE_TEST : 
21890         if(cdebug>=1)
21891         {
21892             fprintf(newstdout,"Child %d running thread_rewrite_test\n",(int)chid);
21893             fflush(newstdout);
21894         }
21895         thread_rwrite_test((long)0);
21896         break;
21897     case THREAD_READ_TEST : 
21898         if(cdebug>=1)
21899         {
21900             fprintf(newstdout,"Child %d running thread_read_test\n",(int)chid);
21901             fflush(newstdout);
21902         }
21903         thread_read_test((long)0);
21904         break;
21905 #ifdef HAVE_PREAD
21906     case THREAD_PREAD_TEST : 
21907         if(cdebug>=1)
21908         {
21909             fprintf(newstdout,"Child %d running thread_read_test\n",(int)chid);
21910             fflush(newstdout);
21911         }
21912         thread_pread_test((long)0);
21913         break;
21914 #endif
21915     case THREAD_REREAD_TEST : 
21916         if(cdebug>=1)
21917         {
21918             fprintf(newstdout,"Child %d running thread_reread_test\n",(int)chid);
21919             fflush(newstdout);
21920         }
21921         thread_rread_test((long)0);
21922         break;
21923     case THREAD_STRIDE_TEST : 
21924         if(cdebug>=1)
21925         {
21926             fprintf(newstdout,"Child %d running thread_stride_read_test\n",(int)chid);
21927             fflush(newstdout);
21928         }
21929         thread_stride_read_test((long)0);
21930         break;
21931     case THREAD_RANDOM_READ_TEST : 
21932         if(cdebug>=1)
21933         {
21934             fprintf(newstdout,"Child %d running random read test\n",(int)chid);
21935             fflush(newstdout);
21936         }
21937         thread_ranread_test((long)0);
21938         break;
21939     case THREAD_RANDOM_WRITE_TEST : 
21940         if(cdebug>=1)
21941         {
21942             fprintf(newstdout,"Child %d running random write test\n",(int)chid);
21943             fflush(newstdout);
21944         }
21945         thread_ranwrite_test((long)0);
21946         break;
21947     case THREAD_REVERSE_READ_TEST : 
21948         if(cdebug>=1)
21949         {
21950             fprintf(newstdout,"Child %d running reverse read test\n",(int)chid);
21951             fflush(newstdout);
21952         }
21953         thread_reverse_read_test((long)0);
21954         break;
21955     case THREAD_RANDOM_MIX_TEST : 
21956         if(cdebug>=1)
21957         {
21958             fprintf(newstdout,"Child %d running mixed workload test\n",(int)chid);
21959             fflush(newstdout);
21960         }
21961         thread_mix_test((long)0);
21962         break;
21963     case THREAD_FWRITE_TEST : 
21964         if(cdebug>=1)
21965         {
21966             fprintf(newstdout,"Child %d running thread_fwrite_test\n",(int)chid);
21967             fflush(newstdout);
21968         }
21969         thread_fwrite_test((long)0);
21970         break;
21971     case THREAD_FREAD_TEST : 
21972         if(cdebug>=1)
21973         {
21974             fprintf(newstdout,"Child %d running thread_fread_test\n",(int)chid);
21975             fflush(newstdout);
21976         }
21977         thread_fread_test((long)0);
21978         break;
21979     case THREAD_CLEANUP_TEST : 
21980         if(cdebug>=1)
21981         {
21982             fprintf(newstdout,"Child %d running cleanup\n",(int)chid);
21983             fflush(newstdout);
21984         }
21985         thread_cleanup_test((long)0);
21986         break;
21987     };
21988     if(cdebug>=1)
21989     {
21990         fprintf(newstdout,"Child %d finished running test.\n",(int)chid);
21991         fflush(newstdout);
21992     }
21993     
21994     /* 8. Release the listen and send sockets to the master */
21995     stop_child_listen(l_sock);
21996 
21997     exit(0);
21998 }
21999 
22000 /*
22001  * Clients tell the master their statistics, set the stopped flag, and set shared memory
22002  * child_flag to tell the master they are finished. Also each client report all statistics.
22003  */
22004 #ifdef HAVE_ANSIC_C
22005 void
22006 tell_master_stats(testnum , chid, throughput, actual, 
22007          cpu_time, wall_time, stop_flag, child_flag)
22008 int testnum; 
22009 long long chid; 
22010 double throughput, actual, wall_time;
22011 float cpu_time;
22012 char stop_flag;
22013 long long child_flag;
22014 /*
22015 void
22016 tell_master_stats(int testnum , long long chid, double tthroughput, 
22017         double actual, float cpu_time, float wall_time, 
22018         char stop_flag, long long child_flag)
22019 */
22020 #else
22021 void
22022 tell_master_stats(testnum , chid, throughput, actual, cpu_time, 
22023     wall_time, stop_flag, child_flag)
22024 int testnum; 
22025 long long chid; 
22026 double throughput, actual, wall_time;
22027 char stop_flag;
22028 float cpu_time;
22029 long long child_flag;
22030 #endif
22031 {
22032     struct master_command mc;
22033     bzero(&mc,sizeof(struct master_command));
22034     mc.m_client_number = (int) chid;
22035     mc.m_client_error = (int) client_error;
22036     mc.m_throughput= throughput;
22037     mc.m_testnum = testnum;
22038     mc.m_actual = actual;
22039     mc.m_cputime = cpu_time;
22040     mc.m_walltime = wall_time;
22041     mc.m_stop_flag = stop_flag;
22042     mc.m_child_flag = child_flag;
22043     mc.m_command = R_STAT_DATA;
22044     mc.m_mygen = mygen;
22045     mc.m_version = proto_version;
22046     if(cdebug>=1)
22047     {
22048         fprintf(newstdout,"Child %d: Tell master stats and terminate\n",(int)chid);
22049         fflush(newstdout);
22050     }
22051     child_send(controlling_host_name,(struct master_command *)&mc, sizeof(struct master_command));
22052 }
22053     
22054 /*
22055  * Stop the master listener loop service.
22056  * Currently this is not used. The master_join_count
22057  * variable is used to terminate the loop service.
22058  */
22059 #ifdef HAVE_ANSIC_C
22060 void
22061 stop_master_listen_loop(void)
22062 #else
22063 void
22064 stop_master_listen_loop()
22065 #endif
22066 {
22067     if(mdebug>=1)
22068         printf("Stopping Master listen loop");
22069     kill(master_listen_pid,SIGKILL);
22070 }
22071 
22072 
22073 /*
22074  * Clients tell the master that I am at the barrier and ready
22075  * for the message to start work.
22076  */
22077 #ifdef HAVE_ANSIC_C
22078 void
22079 tell_master_ready(long long chid)
22080 #else
22081 void
22082 tell_master_ready(chid)
22083 long long chid;
22084 #endif
22085 {
22086     struct master_command mc;
22087     bzero(&mc,sizeof(struct master_command));
22088     if(cdebug>=1)
22089     {
22090         fprintf(newstdout,"Child %d: Tell master to go\n",(int)chid);
22091         fflush(newstdout);
22092     }
22093     mc.m_command = R_FLAG_DATA;
22094     mc.m_mygen = mygen;
22095     mc.m_version = proto_version;
22096     mc.m_child_flag = CHILD_STATE_READY; 
22097     mc.m_client_number = (int)chid; 
22098     mc.m_client_error = client_error;
22099     child_send(controlling_host_name,(struct master_command *)&mc, sizeof(struct master_command));
22100 }
22101 
22102 /*
22103  * Clients wait at a barrier for the master to tell them
22104  * to begin work. This is the function where they wait.
22105  */
22106 #ifdef HAVE_ANSIC_C
22107 void
22108 wait_for_master_go(long long chid)
22109 #else
22110 void
22111 wait_for_master_go(chid)
22112 long long chid;
22113 #endif
22114 {
22115     struct client_neutral_command *cnc;
22116     struct client_command cc;
22117     bzero(&cc,sizeof(struct client_command));
22118     child_listen(l_sock,sizeof(struct client_neutral_command));
22119     cnc = (struct client_neutral_command *)child_rcv_buf;
22120     sscanf(cnc->c_command,"%d",&cc.c_command);
22121     if(cc.c_command == R_TERMINATE || cc.c_command==R_DEATH)
22122     {
22123         if(cdebug)
22124         {
22125             fprintf(newstdout,"Child %d received terminate on sync channel at barrier !!\n",(int)chid);
22126             fflush(newstdout);
22127         }
22128         exit(1);
22129     }
22130     if(cdebug>=1)
22131     {
22132         fprintf(newstdout,"Child %d return from wait_for_master_go\n",(int)chid);
22133         fflush(newstdout);
22134     }
22135 }
22136 
22137 /*
22138  * Create a master listener for receiving data from the
22139  * many children. As the children finish they will send
22140  * their statistics and terminate. When the master_join_count 
22141  * goes to zero then it is time to stop this service.
22142  * When this service exits then the parent will know
22143  * that all of the children are done.
22144  */
22145 #ifdef HAVE_ANSIC_C
22146 void
22147 start_master_listen_loop(int num)
22148 #else
22149 void
22150 start_master_listen_loop(num)
22151 int num;
22152 #endif
22153 {
22154     int i;
22155     struct child_stats *child_stat;
22156     struct master_neutral_command *mnc;
22157     struct master_command mc;
22158     int temp;
22159     struct timespec req,rem;
22160 
22161     req.tv_sec = 0;
22162     req.tv_nsec = 10000000;
22163     rem.tv_sec = 0;
22164     rem.tv_nsec = 10000000;
22165 
22166 
22167     master_join_count=num;
22168     master_listen_pid=fork();
22169     if(master_listen_pid!=0)
22170         return;
22171     if(mdebug>=1)
22172         printf("Starting Master listen loop m %d c %d count %d\n",master_iozone, 
22173             client_iozone,num);
22174 
22175     while(master_join_count)
22176     {
22177         master_listen(master_listen_socket,sizeof(struct master_neutral_command));
22178         mnc=(struct master_neutral_command *)&master_rcv_buf[0];
22179         
22180         /*
22181          * Convert from string format to arch format
22182          */
22183         sscanf(mnc->m_command,"%d",&mc.m_command);
22184         sscanf(mnc->m_client_number,"%d",&mc.m_client_number);
22185         sscanf(mnc->m_client_error,"%d",&mc.m_client_error);
22186         sscanf(mnc->m_mygen,"%d",&mc.m_mygen);
22187         sscanf(mnc->m_version,"%d",&mc.m_version);
22188         if(mc.m_version != proto_version)
22189         {
22190             printf("Client # %d is not running the same version of Iozone !\n",
22191                 mc.m_client_number);
22192         }       
22193         if(mc.m_client_error != 0)
22194         {
22195             printf("\nClient # %d reporting an error %s !\n",
22196                 mc.m_client_number,strerror(mc.m_client_error));
22197         }       
22198 #ifdef NO_PRINT_LLD
22199         sscanf(mnc->m_child_flag,"%ld",&mc.m_child_flag);
22200 #else
22201         sscanf(mnc->m_child_flag,"%lld",&mc.m_child_flag);
22202 #endif
22203         sscanf(mnc->m_actual,"%f",&mc.m_actual);
22204         sscanf(mnc->m_throughput,"%f",&mc.m_throughput);
22205         sscanf(mnc->m_cputime,"%f",&mc.m_cputime);
22206         sscanf(mnc->m_walltime,"%f",&mc.m_walltime);
22207         sscanf(mnc->m_stop_flag,"%d",&temp);
22208         mc.m_stop_flag = temp;
22209 
22210         switch(mc.m_command) {
22211         case R_STAT_DATA:
22212             if(mc.m_mygen != mygen)
22213             {
22214                 /* 
22215                  * >>> You are NOT one of my children !!!  <<<
22216                  * Probably children left behind from another run !!!
22217                  * Ignore their messages, and go on without them.
22218                  */
22219                 printf("*** Unknown Iozone children responding !!! ***\n");
22220                 continue;
22221             }
22222             i = mc.m_client_number;
22223             if(mdebug)
22224                 printf("loop: R_STAT_DATA for client %d\n",i);
22225             child_stat = (struct child_stats *)&shmaddr[i]; 
22226             child_stat->flag = mc.m_child_flag;
22227             child_stat->actual = mc.m_actual;
22228             child_stat->throughput = mc.m_throughput;
22229             child_stat->cputime = mc.m_cputime;
22230             child_stat->walltime = mc.m_walltime;
22231             *stop_flag = mc.m_stop_flag;
22232             master_join_count--;
22233             break;
22234         case R_FLAG_DATA:
22235             if(mc.m_mygen != mygen)
22236             {
22237                 /* You are NOT one of my children !!! */
22238                 printf("*** Unknown Iozone children responding !!! ***\n");
22239                 continue;
22240             }
22241             if(mdebug)
22242                 printf("loop: R_FLAG_DATA: Client %d flag %d \n",
22243                   (int)mc.m_client_number,
22244                   (int)mc.m_child_flag);
22245             i = mc.m_client_number;
22246             child_stat = (struct child_stats *)&shmaddr[i]; 
22247             child_stat->flag = (long long)(mc.m_child_flag);
22248             break;
22249         case R_STOP_FLAG:
22250             if(mc.m_mygen != mygen)
22251             {
22252                 /* You are NOT one of my children !!! */
22253                 printf("*** Unknown Iozone children responding !!! ***\n");
22254                 continue;
22255             }
22256             if(mdebug)
22257               printf("Master loop: R_STOP_FLAG: Client %d STOP_FLAG \n",
22258                   (int)mc.m_client_number);
22259             *stop_flag=1;
22260             distribute_stop();
22261             break;
22262         }
22263             
22264     }
22265     /* Let the clients report results before exiting.
22266            Also, exiting too quickly can close the async
22267            socket to the child, and cause it to become ill.
22268            On Solaris, it gets stuck in a 0=read() loop. */
22269 
22270 #if defined(Windows)
22271     sleep(1);
22272 #else
22273     nanosleep(&req,&rem);
22274 #endif
22275 
22276     exit(0);
22277 }
22278 /*
22279  * Create a client listener for receiving async data from the
22280  * the master. 
22281  */
22282 #ifdef HAVE_ANSIC_C
22283 void
22284 start_child_listen_loop(void)
22285 #else
22286 void
22287 start_child_listen_loop()
22288 #endif
22289 {
22290     int i;
22291     struct child_stats *child_stat;
22292     struct client_command cc;
22293     struct client_neutral_command *cnc;
22294 
22295     client_listen_pid=fork();
22296     if(client_listen_pid!=0)
22297         return;
22298     if(cdebug>=1)
22299     {
22300         fprintf(newstdout,"Child %d starting client listen loop\n",(int)chid);
22301         fflush(newstdout);
22302     }
22303     while(1)
22304     {
22305         bzero(&cc,sizeof(struct client_command));
22306         child_listen_async(l_async_sock,sizeof(struct client_neutral_command));
22307         cnc=(struct client_neutral_command *)&child_async_rcv_buf;
22308         /*
22309          * Convert from string format to arch format
22310          */
22311         sscanf(cnc->c_command,"%d",&cc.c_command);
22312         sscanf(cnc->c_client_number,"%d",&cc.c_client_number);
22313         sscanf(cnc->c_stop_flag,"%d",&cc.c_stop_flag);
22314 
22315         switch(cc.c_command) {
22316         case R_STOP_FLAG:
22317             i = cc.c_client_number;
22318             if(cdebug)
22319             {
22320                 fprintf(newstdout,"child loop: R_STOP_FLAG for client %d\n",i);
22321                 fflush(newstdout);
22322             }
22323             child_stat = (struct child_stats *)&shmaddr[i]; 
22324             *stop_flag = cc.c_stop_flag; /* In shared memory with other copy */
22325             sent_stop=1;
22326             break;
22327         case R_TERMINATE:
22328             if(cdebug)
22329             {
22330                 fprintf(newstdout,"Child loop: R_TERMINATE: Client %d \n",
22331                   (int)cc.c_client_number);
22332                 fflush(newstdout);
22333             }
22334             sleep(2);
22335             /* Aync listener goes away */
22336             stop_child_listen(l_async_sock);
22337             exit(0);
22338         case R_DEATH:
22339             if(cdebug)
22340             {
22341                 fprintf(newstdout,"Child loop: R_DEATH: Client %d \n",
22342                   (int)cc.c_client_number);
22343                 fflush(newstdout);
22344             }
22345             i = cc.c_client_number;
22346             child_remove_files(i);
22347             sleep(2);
22348             /* Aync listener goes away */
22349             stop_child_listen(l_async_sock);
22350             exit(0);
22351         }
22352             
22353     }
22354 }
22355 
22356 /*
22357  * The controlling process "master" tells the children to begin.
22358  */
22359 
22360 #ifdef HAVE_ANSIC_C
22361 void
22362 tell_children_begin(long long childnum)
22363 #else
22364 void
22365 tell_children_begin(childnum)
22366 long long childnum;
22367 #endif
22368 {
22369     struct client_command cc;
22370     int x;
22371     bzero(&cc,sizeof(struct client_command));
22372     x = (int) childnum;
22373     if(mdebug>=1)
22374         printf("Master: Tell child %d to begin\n",x);
22375     cc.c_command = R_FLAG_DATA;
22376     cc.c_child_flag = CHILD_STATE_BEGIN; 
22377     cc.c_client_number = (int)childnum; 
22378     master_send(master_send_sockets[x],child_idents[x].child_name, &cc,sizeof(struct client_command));
22379 }
22380 
22381 /*
22382  * The master waits here for all of the the children to terminate.
22383  * When the children are done the the master_join_count will be at zero
22384  * and the master_listen_loop will exit. This function waits for this to happen.
22385  */
22386 #ifdef HAVE_ANSIC_C
22387 void
22388 wait_dist_join(void)
22389 #else
22390 void
22391 wait_dist_join()
22392 #endif
22393 {
22394     wait(0);
22395     if(mdebug)
22396         printf("Master: All children have finished. Sending terminate\n");
22397     terminate_child_async(); /* All children are done, so terminate their async channel */
22398     current_client_number=0; /* start again */
22399 }
22400 
22401 
22402 /* 
22403  * This function reads a file that contains client information. 
22404  * The information is:
22405  *  client name (DNS usable name)
22406  *  client working directory (where to run the test)
22407  *  client directory that contains the Iozone executable.
22408  *
22409  * If the first character in a line is a # then it is a comment.
22410  * The maximum number of clients is MAXSTREAMS.
22411  */
22412 #ifdef HAVE_ANSIC_C
22413 int
22414 get_client_info(void)
22415 #else
22416 int
22417 get_client_info()
22418 #endif
22419 {
22420     FILE *fd;
22421     char *ret1;
22422     int count;
22423     char buffer[200];
22424     count=0;
22425     fd=fopen(client_filename,"r");
22426     if(fd == (FILE *)NULL)
22427     {
22428         printf("Unable to open client file \"%s\"\n",
22429             client_filename);
22430         exit(176);
22431     }
22432     while(1)
22433     {
22434             if (count > MAXSTREAMS) {                                                                           
22435                   printf("Too many lines in client file - max of %d supported\n",
22436             MAXSTREAMS);
22437                   exit(7);
22438             }
22439         ret1=fgets(buffer,200,fd);
22440         if(ret1== (char *)NULL)
22441             break;
22442         count+=parse_client_line(buffer,count);
22443     }
22444     fclose(fd);
22445     return(count);
22446 }
22447 
22448 
22449 /*
22450  * This function parses a line from the client file. It is
22451  * looking for:
22452  *  Client name  (DNS usable)
22453  *  Client working directory (where to run the test )
22454  *  Client path to Iozone executable.
22455  *
22456  * Lines that start with # are comments.
22457  */
22458 
22459 #ifdef HAVE_ANSIC_C
22460 int 
22461 parse_client_line(char *buffer,int line_num)
22462 #else
22463 int
22464 parse_client_line(buffer, line_num)
22465 char *buffer;
22466 int line_num;
22467 #endif
22468 {
22469     int num;
22470     /* Format is clientname, workdir, execute_path */
22471     /* If column #1 contains a # symbol then skip this line */
22472 
22473     if(buffer[0]=='#')
22474         return(0);
22475     num=sscanf(buffer,"%s %s %s %s\n",
22476         child_idents[line_num].child_name,
22477         child_idents[line_num].workdir,
22478         child_idents[line_num].execute_path,
22479         child_idents[line_num].file_name);
22480     if((num > 0) && (num !=3) && (num !=4))
22481     {
22482         printf("Bad Client Identity at entry %d\n",line_num);
22483         printf("Client: -> %s  Workdir: -> %s  Execute_path: -> %s \n",
22484         child_idents[line_num].child_name,
22485         child_idents[line_num].workdir,
22486         child_idents[line_num].execute_path);
22487         exit(203);
22488     }
22489     if(num == 4)
22490         mfflag++;
22491 
22492     return(1);
22493 }
22494 
22495 /* 
22496  * This is a mechanism that the child uses to remove all
22497  * of its temporary files. Only used at terminate time.
22498  */
22499 #ifdef HAVE_ANSIC_C
22500 void
22501 child_remove_files(int i)
22502 #else
22503 void
22504 child_remove_files(i)
22505 int i;
22506 #endif
22507 {
22508 
22509     char *dummyfile[MAXSTREAMS];           /* name of dummy file     */
22510     dummyfile[i]=(char *)malloc((size_t)MAXNAMESIZE);
22511     if(mfflag)
22512     {
22513         sprintf(dummyfile[i],"%s",filearray[i]);
22514     }
22515     else
22516     {
22517         sprintf(dummyfile[i],"%s.DUMMY.%d",filearray[i],i);
22518     }
22519     if(cdebug)
22520     {
22521         fprintf(newstdout,"Child %d remove: %s \n",(int)chid, dummyfile[i]);
22522         fflush(newstdout);
22523     }
22524     if(check_filename(dummyfile[i]))
22525         unlink(dummyfile[i]);
22526 }
22527 
22528     
22529 /*
22530  * The master tells the child async listener that it is time
22531  * to terminate its services.
22532  */
22533 #ifdef HAVE_ANSIC_C
22534 void
22535 terminate_child_async(void)
22536 #else
22537 void
22538 terminate_child_async()
22539 #endif
22540 {
22541     int i;
22542     struct client_command cc;
22543     bzero(&cc,sizeof(struct client_command));
22544     cc.c_command = R_TERMINATE;
22545     for(i=0;i<num_child;i++)
22546     {
22547         child_idents[i].state = C_STATE_ZERO;
22548         cc.c_client_number = (int)i; 
22549         if(mdebug)
22550             printf("Master terminating async channels to children.\n");
22551         master_send(master_send_async_sockets[i],child_idents[i].child_name, &cc,sizeof(struct client_command));
22552     }
22553 }
22554 
22555 /*
22556  * The master has received an update to the stop flag and is
22557  * now distributing this to all of the clients.
22558  */
22559 #ifdef HAVE_ANSIC_C
22560 void
22561 distribute_stop(void)
22562 #else
22563 void
22564 distribute_stop()
22565 #endif
22566 {
22567     int i;
22568     struct client_command cc;
22569 
22570     /*
22571      * Only send one stop to the clients. Each client will
22572      * send stop to the master, but the master only needs
22573      * to distribute the first stop. Without this, the 
22574      * master may distribute too many stops and overflow
22575      * the socket buffer on the client.
22576      */
22577     if(sent_stop)
22578     {
22579         if(mdebug)
22580         {
22581           s_count++;
22582           printf("Master not send stop %d\n",s_count);
22583         }
22584         return;
22585     }
22586     bzero(&cc,sizeof(struct client_command));
22587     cc.c_command = R_STOP_FLAG;
22588     cc.c_stop_flag = 1;
22589     for(i=0;i<num_child;i++)
22590     {
22591         cc.c_client_number = (int)i; 
22592         if(mdebug)
22593             printf("Master distributing stop flag to child %d\n",i);
22594         master_send(master_send_async_sockets[i],child_idents[i].child_name, &cc,sizeof(struct client_command));
22595     }
22596     sent_stop=1;
22597 }
22598 
22599 /*
22600  * Child is sending its stop flag to the master.
22601  */
22602 #ifdef HAVE_ANSIC_C
22603 void
22604 send_stop(void)
22605 #else
22606 void
22607 send_stop()
22608 #endif
22609 {
22610     struct master_command mc;
22611 
22612     bzero(&mc, sizeof(struct master_command));
22613     mc.m_command = R_STOP_FLAG;
22614     mc.m_mygen = mygen;
22615     mc.m_version = proto_version;
22616     mc.m_client_number = chid;
22617     mc.m_client_error = client_error;
22618     if(cdebug)
22619     {
22620         fprintf(newstdout,"Child %d sending stop flag to master\n",(int)chid);
22621         fflush(newstdout);
22622     }
22623         child_send(controlling_host_name,(struct master_command *)&mc, sizeof(struct master_command));
22624     client_error=0;  /* clear error, it has been delivered */
22625 }
22626 
22627 /*
22628  * This is very tricky stuff. There are points in time when 
22629  * someone can hit control-c and cause the master to want to die.
22630  * Ok..now how does the master contact all the clients and tell
22631  * them to stop ?  The clients may be in 3 different states.
22632  * Not started yet, Joined and waiting for the WHO information, 
22633  * or at the barrier.  If the client is not started... cool.
22634  * ignore it. If the client has joined and is waiting at WHO
22635  * then the client does not have an async listener yet. So 
22636  * the master only needs to tell the client (sync) channel
22637  * to terminate. If the client is at the barrier then the 
22638  * client has two processes. One at the barrier and another
22639  * that is providing the async services. So... the master
22640  * needs to terminate both of these processes.
22641  */
22642 #ifdef HAVE_ANSIC_C
22643 void
22644 cleanup_children(void)
22645 #else
22646 void
22647 cleanup_children()
22648 #endif
22649 {
22650     int i;
22651     struct client_command cc;
22652     bzero(&cc,sizeof(struct client_command));
22653     cc.c_command = R_DEATH;
22654     for(i=0;i<num_child;i++)
22655     {
22656         cc.c_client_number = (int)i; 
22657         /* Child not started yet */
22658         if(child_idents[i].state == C_STATE_ZERO)
22659             ;
22660         /* Child is waiting for who info */
22661         if(child_idents[i].state == C_STATE_WAIT_WHO)
22662         {
22663             if(mdebug)
22664                 printf("Master sending signaled death to child !!\n");
22665             master_send(master_send_sockets[i],child_idents[i].child_name, &cc,sizeof(struct client_command));
22666         }
22667         /* Child is waiting at the barrier */
22668         if(child_idents[i].state == C_STATE_WAIT_BARRIER)
22669         {
22670             if(mdebug)
22671                 printf("Master sending signaled death to child !!\n");
22672             master_send(master_send_sockets[i],child_idents[i].child_name, &cc,sizeof(struct client_command));
22673             if(mdebug)
22674                 printf("Master sending signaled death to child async !!\n");
22675             master_send(master_send_async_sockets[i],child_idents[i].child_name, &cc,sizeof(struct client_command));
22676         }
22677             
22678     }
22679 }
22680 
22681 /*
22682  * This closes the file descriptors that were created for the master send and async send
22683  * at the end of each phase of the throughput testing.
22684  */
22685 #ifdef HAVE_ANSIC_C
22686 void
22687 cleanup_comm(void)
22688 #else
22689 void
22690 cleanup_comm()
22691 #endif
22692 {
22693     int i;
22694     for(i=0;i<num_child;i++)
22695     {
22696             close(master_send_sockets[i]);
22697             close(master_send_async_sockets[i]);
22698     }
22699 }
22700 
22701 #ifdef HAVE_ANSIC_C
22702 void
22703 find_remote_shell(char *shell)
22704 #else
22705 void
22706 find_remote_shell(shell)
22707 char *shell;
22708 #endif
22709 {
22710     char *value;
22711     value=(char *)getenv("RSH");
22712     if(value)
22713     {
22714         strcpy(shell,value);
22715         return;
22716     }
22717 #ifdef _HPUX_SOURCE
22718     strcpy(shell,"remsh");
22719 #else
22720     strcpy(shell,"rsh");
22721 #endif
22722     return;
22723 }   
22724 #ifdef HAVE_ANSIC_C
22725 void
22726 find_external_mon(char * imon_start, char * imon_stop)
22727 #else
22728 void
22729 find_external_mon(imon_start,imon_stop)
22730 char *imon_start,*imon_stop;
22731 #endif
22732 {
22733     char *start,*stop,*sync;
22734     imon_start[0]=(char)0;
22735     imon_stop[0]=(char)0;
22736     start=(char *)getenv("IMON_START");
22737     if(start)
22738     {
22739         strcpy(imon_start,start);
22740     }
22741     stop=(char *)getenv("IMON_STOP");
22742     if(stop)
22743     {
22744         strcpy(imon_stop,stop);
22745     }
22746     sync=(char *)getenv("IMON_SYNC");
22747     if(sync)
22748     {
22749         imon_sync=1;
22750     }
22751 
22752     return;
22753 }   
22754 
22755 /*
22756  * This test is only valid in throughput mode.
22757  */
22758 
22759 #ifdef HAVE_ANSIC_C
22760 void 
22761 mix_perf_test(off64_t kilo64,long long reclen,long long *data1,long long *data2)
22762 #else
22763 void 
22764 mix_perf_test(kilo64,reclen,data1,data2)
22765 off64_t kilo64;
22766 long long reclen;
22767 long long *data1,*data2;
22768 #endif
22769 {
22770     return;
22771 /*
22772     printf("\nMix mode test only valid in throughput mode.\n");
22773     signal_handler();
22774     exit(180);
22775 */
22776 }
22777 
22778 /*
22779  * Speed check code 
22780  */
22781 char *sp_dest; /* Name of destination for messages */
22782 
22783 int sp_child_listen_port = SP_CHILD_LISTEN_PORT;
22784 int sp_child_esend_port  = SP_CHILD_ESEND_PORT;
22785 
22786 int sp_master_listen_port = SP_MASTER_LISTEN_PORT;
22787 int sp_master_esend_port  = SP_MASTER_ESEND_PORT;
22788 
22789 int sp_master_results_port = SP_MASTER_RESULTS_PORT;
22790 
22791 struct in_addr sp_my_cs_addr;
22792 struct in_addr sp_my_ms_addr;
22793 struct sockaddr_in sp_child_sync_sock, sp_child_async_sock;
22794 struct sockaddr_in sp_master_sync_sock, sp_master_async_sock;
22795 char *sp_buf;
22796 char sp_command[1024];
22797 char sp_remote_shell[100];
22798 int sp_child_mode;
22799 int sp_count,sp_msize,sp_once;
22800 int sp_tcount;
22801 double sp_start_time,sp_finish_time;
22802 void sp_send_result(int, int, float );
22803 void sp_get_result(int , int );
22804 void sp_do_child_t(void);
22805 void sp_do_master_t(void);
22806 void speed_main(char *, char *, long long ,long long , int);
22807 int sp_cret;
22808 char sp_remote_host[256];
22809 char sp_master_host[256];
22810 char sp_location[256];
22811 
22812 
22813 /*
22814  * This is the front end for the speed check code
22815  */
22816 #ifdef HAVE_ANSIC_C
22817 void
22818 speed_main(char *client_name, char *e_path, long long reclen,
22819     long long kilos, int client_flag)
22820 #else
22821 void
22822 speed_main(client_name, e_path, reclen, kilos, client_flag)
22823 char *client_name;
22824 char *e_path;
22825 long long reclen;
22826 long long kilos;
22827 int client_flag;
22828 #endif
22829 {
22830     int x;
22831 
22832 
22833     strcpy(sp_master_host,controlling_host_name);
22834     sp_msize=(int)reclen;
22835     sp_count=((int)kilos*1024)/(int)reclen;
22836     if(!client_flag)
22837     {
22838         printf("\n");
22839         strcpy(sp_remote_host,client_name);
22840         strcpy(sp_location,e_path);
22841     }
22842 
22843     if(client_flag)
22844         sp_child_mode=1;
22845     sp_buf=(char *)malloc(sp_msize);
22846     bzero(sp_buf,sp_msize); /* get page faults out of the way */
22847 
22848     if(sp_child_mode)
22849     {
22850         close(0);
22851         close(1);
22852         close(2);
22853         if(cdebug)
22854         {
22855             newstdin=freopen("/tmp/don_in","r+",stdin);
22856             newstdout=freopen("/tmp/don_out","a+",stdout);
22857             newstderr=freopen("/tmp/don_err","a+",stderr);
22858         }
22859         sp_dest=sp_master_host;
22860         sp_do_child_t();
22861         free(sp_buf);
22862         exit(0);
22863     }
22864     x=fork();
22865     if(x==0)
22866     {
22867         find_remote_shell(sp_remote_shell);
22868      sprintf(sp_command,"%s %s %s -+s -t 1 -r %d -s %d -+c %s -+t ",
22869             sp_remote_shell, sp_remote_host, 
22870             sp_location, (int)reclen/1024, 
22871             (int)kilos,sp_master_host);
22872         /*printf("%s\n",sp_command);*/
22873         junk=system(sp_command);
22874         exit(0);
22875     }
22876     else
22877     {
22878         if(!sp_once)
22879         {
22880         printf("***************************************************\n");
22881         printf("* >>>>>     Client Network Speed check      <<<<< *\n");
22882         printf("***************************************************\n\n");
22883             printf("Master: %s\n",sp_master_host);
22884             printf("Transfer size %d bytes  \n",sp_msize);
22885             printf("Count %d\n",sp_count);
22886             printf("Total size %d kbytes  \n\n",
22887                 (sp_msize*sp_count)/1024);
22888             sp_once=1;
22889         }
22890         sp_dest=sp_remote_host;
22891         sleep(1);
22892         sp_do_master_t();
22893         free(sp_buf);
22894     }
22895 }
22896 
22897 /*
22898  * Get results back from the client.
22899  */
22900 #ifdef HAVE_ANSIC_C
22901 void
22902 sp_get_result(int port,int flag)
22903 #else
22904 void
22905 sp_get_result(port,flag)
22906 int port,flag;
22907 #endif
22908 {
22909     int tcfd;
22910     float throughput;
22911     int count;
22912     char mybuf[1024];
22913     int sp_offset,xx;
22914 
22915     tcfd=sp_start_master_listen(port, 1024);
22916     sp_offset=0;
22917     while(sp_offset < 1024)
22918     {
22919         xx=read(tcfd,&mybuf[sp_offset],1024);
22920         sp_offset+=xx;
22921     }
22922     sscanf(mybuf,"%d %f",&count,&throughput);
22923     if(!flag)
22924         printf("%-20s received  %10d Kbytes @ %10.2f Kbytes/sec \n",
22925             sp_remote_host,count,throughput);
22926     else
22927         printf("%-20s  sent     %10d Kbytes @ %10.2f Kbytes/sec \n",
22928             sp_remote_host,count,throughput);
22929     close(tcfd);
22930 }
22931 
22932 /*
22933  * Send results to the master.
22934  */
22935 #ifdef HAVE_ANSIC_C
22936 void
22937 sp_send_result(int port, int count, float throughput)
22938 #else
22939 void
22940 sp_send_result(port, count, throughput)
22941 int port,count; 
22942 float throughput;
22943 #endif
22944 {
22945     int msfd;
22946     char mybuf[1024];
22947     sprintf(mybuf,"%d %f",count, throughput);
22948     msfd=sp_start_child_send(sp_dest, port, &sp_my_cs_addr);
22949     junk=write(msfd,mybuf,1024);
22950     if(cdebug)
22951     {
22952         fprintf(newstdout,"Sending result\n");
22953         fflush(newstdout);
22954     }
22955     close(msfd);
22956 }
22957 
22958 /*
22959  * Start the channel for the master to send a message to 
22960  * a child on a port that the child
22961  * has created for the parent to use to communicate.
22962  */
22963 #ifdef HAVE_ANSIC_C
22964 int
22965 sp_start_master_send(char *sp_child_host_name, int sp_child_listen_port, struct in_addr *sp_my_ms_addr)
22966 #else
22967 int
22968 sp_start_master_send(sp_child_host_name, sp_child_listen_port, sp_my_ms_addr)
22969 char *sp_child_host_name; 
22970 int sp_child_listen_port;
22971 struct in_addr *sp_my_ms_addr;
22972 #endif
22973 {
22974     int rc,master_socket_val;
22975     struct sockaddr_in addr,raddr;
22976     struct hostent *he;
22977     int port,tmp_port;
22978     int ecount=0;
22979     struct in_addr *ip;
22980     struct timespec req,rem;
22981 
22982     req.tv_sec = 0;
22983     req.tv_nsec = 10000000;
22984     rem.tv_sec = 0;
22985     rem.tv_nsec = 10000000;
22986 
22987         he = gethostbyname(sp_child_host_name);
22988         if (he == NULL)
22989         {
22990                 printf("Master: Bad hostname >%s<\n",sp_child_host_name);
22991         fflush(stdout);
22992                 exit(22);
22993         }
22994     if(mdebug ==1)
22995     {
22996             printf("Master: start master send: %s\n", he->h_name);
22997         fflush(stdout);
22998     }
22999         ip = (struct in_addr *)he->h_addr_list[0];
23000 #ifndef UWIN
23001     if(mdebug ==1)
23002     {
23003             printf("Master: child name: %s\n", (char *)inet_ntoa(*ip));
23004             printf("Master: child Port: %d\n", sp_child_listen_port);
23005         fflush(stdout);
23006     }
23007 #endif
23008 
23009     port=sp_child_listen_port;
23010     sp_my_ms_addr->s_addr = ip->s_addr;
23011     /*port=CHILD_LIST_PORT;*/
23012 
23013         raddr.sin_family = AF_INET;
23014         raddr.sin_port = htons(port);
23015         raddr.sin_addr.s_addr = ip->s_addr;
23016         master_socket_val = socket(AF_INET, SOCK_STREAM, 0);
23017         if (master_socket_val < 0)
23018         {
23019                 perror("Master: socket failed:");
23020                 exit(23);
23021         }
23022         bzero(&addr, sizeof(struct sockaddr_in));
23023     tmp_port=sp_master_esend_port;
23024         addr.sin_port = htons(tmp_port);
23025         addr.sin_family = AF_INET;
23026         addr.sin_addr.s_addr = INADDR_ANY;
23027         rc = -1;
23028         while (rc < 0)
23029         {
23030                 rc = bind(master_socket_val, (struct sockaddr *)&addr,
23031                                                 sizeof(struct sockaddr_in));
23032         if(rc < 0)
23033         {
23034             tmp_port++;
23035                     addr.sin_port=htons(tmp_port);
23036             continue;
23037         }
23038         }
23039     if(mdebug ==1)
23040     {
23041         printf("Master: Bound port\n");
23042         fflush(stdout);
23043     }
23044         if (rc < 0)
23045         {
23046                 perror("Master: bind failed for sync channel to child.\n");
23047                 exit(24);
23048         }
23049 #if defined(Windows)
23050     sleep(1);
23051 #else
23052     nanosleep(&req,&rem);
23053 #endif
23054 
23055 again:
23056         rc = connect(master_socket_val, (struct sockaddr *)&raddr, 
23057             sizeof(struct sockaddr_in));
23058     if (rc < 0)
23059         {
23060         if(ecount++ < 300)
23061         {
23062 #if defined(Windows)
23063             sleep(1);
23064 #else
23065             nanosleep(&req,&rem);
23066 #endif
23067             /*sleep(1);*/
23068             goto again;
23069         }
23070                 perror("Master: connect failed\n");
23071         printf("Error %d\n",errno);
23072                 exit(25);
23073         }
23074     if(mdebug ==1)
23075     {
23076         printf("Master Connected\n");
23077         fflush(stdout);
23078     }
23079     return (master_socket_val);
23080 }
23081 
23082 /*
23083  * Start the childs listening service for messages from the master.
23084  */
23085 #ifdef HAVE_ANSIC_C
23086 int
23087 sp_start_child_listen(int listen_port, int size_of_message)
23088 #else
23089 int
23090 sp_start_child_listen(listen_port, size_of_message)
23091 int listen_port;
23092 int size_of_message;
23093 #endif
23094 {
23095     int tsize;
23096     int s,ns;
23097     unsigned int me;
23098     int rc;
23099     int xx;
23100     int tmp_port;
23101     struct sockaddr_in *addr;
23102     int sockerr;
23103     int recv_buf_size=65536;
23104     int optval=1;
23105     xx = 0;
23106     me=sizeof(struct sockaddr_in);
23107     tsize=size_of_message; /* Number of messages to receive */
23108         s = socket(AF_INET, SOCK_STREAM, 0);
23109         if (s < 0)
23110         {
23111                 perror("socket failed:");
23112                 exit(19);
23113         }
23114     sockerr = setsockopt (s, SOL_SOCKET, SO_RCVBUF, (char *)
23115         &recv_buf_size, sizeof(int));
23116     if ( sockerr == -1 ) {
23117         perror("Error in setsockopt 7\n");
23118     }
23119     sockerr = setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (char *)
23120         &optval, sizeof(int));
23121     if ( sockerr == -1 ) {
23122         perror("Error in setsockopt 8\n");
23123     }
23124         bzero(&sp_child_sync_sock, sizeof(struct sockaddr_in));
23125     tmp_port=sp_child_listen_port;
23126         sp_child_sync_sock.sin_port = htons(tmp_port);
23127         sp_child_sync_sock.sin_family = AF_INET;
23128         sp_child_sync_sock.sin_addr.s_addr = INADDR_ANY;
23129         rc = -1;
23130         while (rc < 0)
23131         {
23132                 rc = bind(s, (struct sockaddr *)&sp_child_sync_sock,
23133                                 sizeof(struct sockaddr_in));
23134         if(rc < 0)
23135         {
23136             tmp_port++;
23137                     sp_child_sync_sock.sin_port=htons(tmp_port);
23138             continue;
23139         }
23140         }
23141     sp_child_listen_port = ntohs(sp_child_sync_sock.sin_port);
23142     if(cdebug ==1)
23143     {
23144         fprintf(newstdout,"Child: Listen: Bound at port %d\n", tmp_port);
23145         fflush(newstdout);
23146     }
23147     if(rc < 0)
23148     {
23149         if(cdebug ==1)
23150         {
23151            fprintf(newstdout,"bind failed. Errno %d\n", errno);
23152            fflush(newstdout);
23153         }
23154         exit(20);
23155     }
23156 
23157     addr=&sp_child_async_sock;
23158     listen(s,10);
23159     if(cdebug)
23160     {
23161         fprintf(newstdout,"Child enters accept\n");
23162         fflush(newstdout);
23163     }
23164     ns=accept(s,(void *)addr,&me);
23165     if(cdebug)
23166     {
23167         fprintf(newstdout,"Child attached for receive. Sock %d  %d\n", ns,errno);
23168         fflush(newstdout);
23169     }
23170     close(s);
23171     return(ns);
23172 }
23173 
23174 
23175 /*
23176  * The client runs this code
23177  */
23178 #ifdef HAVE_ANSIC_C
23179 void
23180 sp_do_child_t(void)
23181 #else
23182 void
23183 sp_do_child_t()
23184 #endif
23185 {
23186     int i,y;
23187     int offset;
23188     int sp_tcount=0;
23189     /* child */
23190     /*
23191      * Child reads from master 
23192      */
23193     sp_crfd=sp_start_child_listen(sp_child_listen_port, sp_msize);
23194     sp_start_time=time_so_far();
23195     for(i=0;i<sp_count;i++)
23196     {
23197         offset=0;
23198         while(offset<sp_msize)
23199         {
23200             y=read(sp_crfd,&sp_buf[offset],sp_msize-offset);
23201             if(y < 0)
23202             {
23203                     if(cdebug)
23204                 {
23205                     fprintf(newstdout,"Child error %d offset %d\n",
23206                         errno,offset);
23207                     fflush(newstdout);
23208                 }
23209                 exit(1);
23210             }
23211             offset+=y;
23212             if(cdebug)
23213             {
23214                 fprintf(newstdout,"Child offset %d read %d\n",offset,y);
23215                 fflush(newstdout);
23216             }
23217         }
23218         sp_tcount+=offset;
23219     }
23220     sp_finish_time=time_so_far();
23221 
23222     close(sp_crfd);
23223     sleep(1); /* Wait for master to get into sp_get_result */
23224     sp_send_result(sp_master_results_port, sp_tcount/1024, 
23225         (float)(sp_tcount/1024)/(sp_finish_time-sp_start_time));
23226 
23227     sleep(1);
23228     /*
23229      * Child writes to master 
23230      */
23231     sp_csfd=sp_start_child_send(sp_dest, sp_master_listen_port,
23232         &sp_my_cs_addr);
23233     sp_tcount=0;
23234     offset=0;
23235     sp_start_time=time_so_far();
23236     for(i=0;i<sp_count;i++)
23237     {
23238         y=write(sp_csfd,sp_buf,sp_msize);
23239         sp_tcount+=y;
23240     }
23241     sp_finish_time=time_so_far();
23242     close(sp_csfd);
23243     sleep(1);
23244     sp_send_result(sp_master_results_port, sp_tcount/1024, 
23245         (float)(sp_tcount/1024)/(sp_finish_time-sp_start_time));
23246     if(cdebug)
23247     {
23248         fprintf(newstdout,"child exits\n");
23249         fflush(newstdout);
23250     }
23251 }
23252 
23253 /*
23254  * The master runs this code.
23255  */
23256 #ifdef HAVE_ANSIC_C
23257 void
23258 sp_do_master_t(void)
23259 #else
23260 void
23261 sp_do_master_t()
23262 #endif
23263 {
23264     int i,y,sp_offset;
23265     int sp_tcount = 0;
23266 
23267 
23268     /*
23269      * Master writes to child 
23270      */
23271     sp_msfd=sp_start_master_send(sp_dest, sp_child_listen_port,
23272         &sp_my_ms_addr);
23273     sp_start_time=time_so_far();
23274     for(i=0;i<sp_count;i++)
23275     {
23276         y=write(sp_msfd,sp_buf,sp_msize);
23277         sp_tcount+=y;
23278     }
23279     sp_finish_time=time_so_far();
23280     close(sp_msfd);
23281     sp_msfd=0;
23282     sp_get_result(sp_master_results_port,0);
23283     printf("%-20s  sent     %10d kbytes @ %10.2f Kbytes/sec \n",
23284         sp_master_host,sp_tcount/1024, 
23285         (float)(sp_tcount/1024)/(sp_finish_time-sp_start_time));
23286 
23287     /* printf("\n"); */
23288     /*
23289      * Master reads from child 
23290      */
23291     sp_mrfd=sp_start_master_listen(sp_master_listen_port, sp_msize);
23292     sp_offset=0;
23293     sp_start_time=time_so_far();
23294     sp_tcount=0;
23295     for(i=0;i<sp_count;i++)
23296     {
23297         sp_offset=0;
23298         while(sp_offset<sp_msize)
23299         {
23300             y=read(sp_mrfd,&sp_buf[sp_offset],sp_msize-sp_offset);
23301             if(y < 0)
23302             {
23303                     printf("Master error %d offset %d\n",errno,
23304                     sp_offset);
23305                 exit(1);
23306             }
23307             sp_offset+=y;
23308             /* printf("Master offset %d read %d\n",offset,y);*/
23309         }
23310         sp_tcount+=sp_offset;
23311     }
23312     sp_finish_time=time_so_far();
23313     sp_get_result(sp_master_results_port,1);
23314     printf("%-20s received  %10d kbytes @ %10.2f Kbytes/sec \n",
23315         sp_master_host,sp_tcount/1024,
23316         (float)(sp_tcount/1024)/(sp_finish_time-sp_start_time));
23317     printf("\n");
23318     wait(NULL);
23319     close(sp_mrfd);
23320     sp_mrfd=0;
23321 }
23322 
23323 /*
23324  * Start the master listening service for messages from the child.
23325  */
23326 #ifdef HAVE_ANSIC_C
23327 int
23328 sp_start_master_listen(int sp_master_listen_port, int sp_size_of_message)
23329 #else
23330 int
23331 sp_start_master_listen(sp_master_listen_port, sp_size_of_message)
23332 int sp_size_of_message;
23333 int sp_master_listen_port;
23334 #endif
23335 {
23336     int tsize;
23337     int s,ns;
23338     unsigned int me;
23339     int rc;
23340     int xx;
23341     int tmp_port;
23342     struct sockaddr_in *addr;
23343     int sockerr;
23344     int recv_buf_size=65536;
23345     int optval=1;
23346     xx = 0;
23347     me=sizeof(struct sockaddr_in);
23348     tsize=sp_size_of_message; /* Number of messages to receive */
23349         s = socket(AF_INET, SOCK_STREAM, 0);
23350         if (s < 0)
23351         {
23352                 perror("socket failed:");
23353                 exit(19);
23354         }
23355     sockerr = setsockopt (s, SOL_SOCKET, SO_RCVBUF, (char *)
23356         &recv_buf_size, sizeof(int));
23357     if ( sockerr == -1 ) {
23358         perror("Error in setsockopt 9\n");
23359     }
23360     sockerr = setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (char *)
23361         &optval, sizeof(int));
23362     if ( sockerr == -1 ) {
23363         perror("Error in setsockopt 10\n");
23364     }
23365         bzero(&sp_master_sync_sock, sizeof(struct sockaddr_in));
23366     tmp_port=sp_master_listen_port;
23367         sp_master_sync_sock.sin_port = htons(tmp_port);
23368         sp_master_sync_sock.sin_family = AF_INET;
23369         sp_master_sync_sock.sin_addr.s_addr = INADDR_ANY;
23370         rc = -1;
23371         while (rc < 0)
23372         {
23373                 rc = bind(s, (struct sockaddr *)&sp_master_sync_sock,
23374                                 sizeof(struct sockaddr_in));
23375         if(rc < 0)
23376         {
23377             tmp_port++;
23378                     sp_master_sync_sock.sin_port=htons(tmp_port);
23379             continue;
23380         }
23381         }
23382     sp_master_listen_port = ntohs(sp_master_sync_sock.sin_port);
23383     if(mdebug ==1)
23384     {
23385         printf("Master: Listen: Bound at port %d\n", tmp_port);
23386         fflush(stdout);
23387     }
23388     if(rc < 0)
23389     {
23390         perror("bind failed\n");
23391         exit(20);
23392     }
23393 
23394     addr=&sp_master_async_sock;
23395     listen(s,10);
23396     if(mdebug)
23397     {
23398         printf("Master enters accept\n");
23399         fflush(stdout);
23400     }
23401     ns=accept(s,(void *)addr,&me);
23402     if(mdebug)
23403     {
23404         printf("Master attached for receive. Sock %d  %d\n", ns,errno);
23405         fflush(stdout);
23406     }
23407     close(s);
23408     return(ns);
23409 }
23410 
23411 /*
23412  * Start the channel for the child to send a message to 
23413  * the master.
23414  */
23415 #ifdef HAVE_ANSIC_C
23416 int
23417 sp_start_child_send(char *sp_master_host_name, int sp_master_listen_port, struct in_addr *sp_my_cs_addr)
23418 #else
23419 int
23420 sp_start_child_send(sp_master_host_name, sp_master_listen_port, sp_my_cs_addr)
23421 char *sp_master_host_name; 
23422 int sp_master_listen_port;
23423 struct in_addr *sp_my_cs_addr;
23424 #endif
23425 {
23426     int rc,sp_child_socket_val;
23427     struct sockaddr_in addr,raddr;
23428     struct hostent *he;
23429     int port,tmp_port;
23430     struct in_addr *ip;
23431     int ecount=0;
23432     struct timespec req,rem;
23433 
23434     req.tv_sec = 0;
23435     req.tv_nsec = 10000000;
23436     rem.tv_sec = 0;
23437     rem.tv_nsec = 10000000;
23438 
23439         he = gethostbyname(sp_master_host_name);
23440         if (he == NULL)
23441         {
23442                 printf("Child: Bad hostname >%s<\n",sp_master_host_name);
23443         fflush(stdout);
23444                 exit(22);
23445         }
23446     if(cdebug ==1)
23447     {
23448             fprintf(newstdout,"Child: start child send: %s\n", he->h_name);
23449             fprintf(newstdout,"To: %s at port %d\n",sp_master_host_name,
23450             sp_master_listen_port);
23451         fflush(newstdout);
23452     }
23453         ip = (struct in_addr *)he->h_addr_list[0];
23454 
23455     port=sp_master_listen_port;
23456     sp_my_cs_addr->s_addr = ip->s_addr;
23457 
23458         raddr.sin_family = AF_INET;
23459         raddr.sin_port = htons(port);
23460         raddr.sin_addr.s_addr = ip->s_addr;
23461         sp_child_socket_val = socket(AF_INET, SOCK_STREAM, 0);
23462         if (sp_child_socket_val < 0)
23463         {
23464                 perror("child: socket failed:");
23465                 exit(23);
23466         }
23467         bzero(&addr, sizeof(struct sockaddr_in));
23468     tmp_port=sp_child_esend_port;
23469         addr.sin_port = htons(tmp_port);
23470         addr.sin_family = AF_INET;
23471         addr.sin_addr.s_addr = INADDR_ANY;
23472         rc = -1;
23473         while (rc < 0)
23474         {
23475                 rc = bind(sp_child_socket_val, (struct sockaddr *)&addr,
23476                                                 sizeof(struct sockaddr_in));
23477         if(rc < 0)
23478         {
23479             tmp_port++;
23480                     addr.sin_port=htons(tmp_port);
23481             continue;
23482         }
23483         }
23484     if(cdebug ==1)
23485     {
23486         fprintf(newstdout,"Child: Bound port %d\n",tmp_port);
23487         fflush(newstdout);
23488     }
23489         if (rc < 0)
23490         {
23491                 perror("Child: bind failed for sync channel to child.\n");
23492                 exit(24);
23493         }
23494 #if defined(Windows)
23495     sleep(1);
23496 #else
23497     nanosleep(&req,&rem);
23498 #endif
23499 again:
23500         rc = connect(sp_child_socket_val, (struct sockaddr *)&raddr, 
23501             sizeof(struct sockaddr_in));
23502     if (rc < 0)
23503         {
23504         if(ecount++<300)
23505         {
23506 #if defined(Windows)
23507             sleep(1);
23508 #else
23509             nanosleep(&req,&rem);
23510 #endif
23511             goto again;
23512         }
23513 
23514         fprintf(newstdout,"child: connect failed. Errno %d \n",errno);
23515         fflush(newstdout);
23516         exit(25);
23517         }
23518     if(cdebug ==1)
23519     {
23520         fprintf(newstdout,"child Connected\n");
23521         fflush(newstdout);
23522     }
23523     return (sp_child_socket_val);
23524 }
23525 
23526 #ifdef HAVE_ANSIC_C
23527 void
23528 do_speed_check(int client_flag)
23529 #else
23530 void
23531 do_speed_check(client_flag)
23532 int client_flag;
23533 #endif
23534 {
23535     int i;
23536     if(client_flag)
23537     {
23538         speed_main(" "," ",reclen,kilobytes64,client_flag);
23539     }
23540     else
23541     {
23542         printf("Checking %d clients\n",clients_found);
23543         for(i=0;i<clients_found;i++)
23544         {
23545             speed_main(child_idents[i].child_name,
23546                 child_idents[i].execute_path,
23547                 reclen, kilobytes64,client_flag);
23548         }
23549     }
23550 }
23551 
23552 #ifdef HAVE_ANSIC_C
23553 void
23554 get_date(char *where)
23555 #else
23556 get_date(where)
23557 char *where;
23558 #endif
23559 {
23560     time_t t;
23561     char *value;
23562     t=time(0);
23563     value=(char *)ctime(&t);
23564     strcpy(where,value);
23565 }
23566 
23567 /* Richard Sharpe decided to hack up Samba and
23568  * have it detect Iozone running, and then
23569  * produce the data without doing any actual
23570  * I/O. This was a HIGHLY questionable thing to
23571  * be doing (my opinion). It may have been a lab
23572  * experiment that was accidentally released into 
23573  * the wild, but now that it is, no choice but
23574  * to prevent its use. So... the pattern
23575  * that he was locking on to, is now random,
23576  * and will change with every release of Iozone.
23577  * See: http://lists.samba.org/archive/samba-technical/2005-April/040541.html
23578  */
23579 
23580 #ifdef HAVE_ANSIC_C
23581 int
23582 get_pattern(void)
23583 #else
23584 get_pattern(void)
23585 #endif
23586 {
23587         int i,x,y;
23588         char cp[100],*ptr;
23589         int pat;
23590     unsigned char inp_pat;
23591     unsigned int temp;
23592 
23593         y=0;
23594         ptr=&cp[0];
23595         strcpy(cp,THISVERSION);
23596         x=strlen(THISVERSION);
23597         for(i=0;i<x;i++)
23598                 y+=*ptr++;
23599         srand(y);
23600         pat=(rand()& 0xff);
23601     /* For compatibility with old 0xa5 data sets. */
23602     if(Z_flag)
23603         pat=0xa5;
23604     /* Lock pattern to 0xBB, for filesystem short circuit debug */
23605     if(X_flag)
23606         pat=PATTERN1;
23607     /* Set global pattern */
23608     inp_pat = pat;
23609     temp =((inp_pat << 24) | (inp_pat << 16) | (inp_pat << 8) | inp_pat);
23610         return(pat);
23611 }
23612 
23613 /* 
23614  * Allocate the buffer for purge. 
23615 */
23616 #ifdef HAVE_ANSIC_C
23617 void
23618 alloc_pbuf(void)
23619 #else
23620 alloc_pbuf(void)
23621 #endif
23622 {
23623     pbuffer = (char *) alloc_mem((long long)(3 * cache_size),(int)0);
23624     if(pbuffer == 0) {
23625                 perror("Memory allocation failed:");
23626                 exit(9);
23627     }
23628 #ifdef _64BIT_ARCH_
23629     pbuffer = (char *) 
23630         (((unsigned long long)pbuffer + cache_size ) 
23631         & ~(cache_size-1));
23632 #else
23633     pbuffer = (char *) 
23634         (((long)pbuffer + (long)cache_size ) 
23635         & ~((long)cache_size-1));
23636 #endif
23637 }
23638 
23639 /* 
23640  * Check to see if the file descriptor points at a file
23641  * or a device.
23642  */
23643 #ifdef HAVE_ANSIC_C
23644 int
23645 check_filename(char *name)
23646 #else
23647 check_filename(name)
23648 char *name;
23649 #endif
23650 {
23651 #ifdef _LARGEFILE64_SOURCE
23652     struct stat64 mystat;
23653 #else
23654     struct stat mystat;
23655 #endif
23656     int x;
23657     if(strlen(name)==0)
23658         return(0);
23659     /* Lets try stat first.. may get an error if file is too big */
23660     x=I_STAT(name,&mystat);
23661     if(x<0)
23662     {
23663         return(0);
23664         /* printf("Stat failed %d\n",x); */
23665     }
23666     if(mystat.st_mode & S_IFREG)
23667     {
23668         /*printf("Is a regular file\n");*/
23669         return(1);
23670     }
23671     return(0);
23672 }
23673 
23674 #ifdef HAVE_ANSIC_C
23675 void
23676 start_monitor(char *test)
23677 #else
23678 start_monitor(test)
23679 char *test;
23680 #endif
23681 {
23682     char command_line[256];
23683     if(strlen(imon_start)!=0)
23684     {
23685         if(imon_sync)
23686            sprintf(command_line,"%s %s",imon_start,test);
23687         else
23688            sprintf(command_line,"%s %s&",imon_start,test);
23689         junk=system(command_line);
23690     }
23691 }
23692 #ifdef HAVE_ANSIC_C
23693 void
23694 stop_monitor(char *test)
23695 #else
23696 stop_monitor(test)
23697 char *test;
23698 #endif
23699 {
23700     char command_line[256];
23701     if(strlen(imon_stop)!=0)
23702     {
23703         if(imon_sync)
23704            sprintf(command_line,"%s %s",imon_stop,test);
23705         else
23706            sprintf(command_line,"%s %s &",imon_stop,test);
23707         junk=system(command_line);
23708     }
23709 }
23710 
23711 /* 
23712  * As quickly as possible, generate a new buffer that
23713  * can not be easily compressed, or de-duped. Also
23714  * permit specified percentage of buffer to be updated.
23715  *
23716  * ibuf ... input buffer
23717  * obuf ... output buffer
23718  * seed ... Seed to use for srand, rand -> xor ops
23719  *          Seed composed from: blocknumber
23720         (do not include childnum as you want duplicates)
23721  * size ... size of buffers. (in bytes)
23722  * percent. Percent of buffer to modify.
23723  * percent_interior. Percent of buffer that is dedupable within 
23724  *                   and across files 
23725  * percent_compress. Percent of buffer that is dedupable within 
23726  *                   but not across files 
23727  *
23728  * Returns 0 (zero) for success, and -1 (minus one) for failure.
23729  */
23730 int
23731 gen_new_buf(char *ibuf, char *obuf, long seed, int size, int percent,
23732     int percent_interior, int percent_compress, int all)
23733 {
23734     register long *ip, *op; /* Register for speed   */
23735     register long iseed;    /* Register for speed   */
23736     register long isize;    /* Register for speed   */
23737     register long cseed;    /* seed for dedupable for within & ! across */
23738     register int x,w;   /* Register for speed   */
23739     register int value;     /* Register for speed   */
23740     register int interior_size;     /* size of interior dedup region */
23741     register int compress_size;     /* size of compression dedup region */
23742     if(ibuf == NULL)    /* no input buf     */
23743         return(-1);
23744     if(obuf == NULL)    /* no output buf    */
23745         return(-1);
23746     if((percent > 100) || (percent < 0)) /* percent check */
23747         return(-1);
23748     if(size == 0)       /* size check       */
23749         return(-1);
23750     srand(seed+1+(((int)numrecs64)*dedup_mseed)); /* set random seed */
23751     iseed = rand();     /* generate random value */
23752     isize = (size * percent)/100; /* percent that is dedupable */
23753     interior_size = ((isize * percent_interior)/100);/* /sizeof(long) */
23754     compress_size =((interior_size * percent_compress)/100);
23755     ip = (long *)ibuf;  /* pointer to input buf */
23756     op = (long *)obuf;  /* pointer to output buf */
23757     if(all == 0)        /* Special case for verify only */
23758         isize = sizeof(long);
23759     /* interior_size = dedup_within + dedup_across */
23760     for(w=0;w<interior_size;w+=sizeof(long))    
23761     {
23762         *op=0xdeadbeef+dedup_mseed;
23763         *ip=0xdeadbeef+dedup_mseed;
23764         op++;
23765         ip++;
23766     }   
23767     /* Prepare for dedup within but not across */
23768     w=interior_size - compress_size;
23769     op=(long *)&obuf[w];
23770     ip=(long *)&ibuf[w];
23771     srand(chid+1+dedup_mseed);            /* set randdom seed   */
23772     cseed = rand();     /* generate random value */
23773     for(w=(interior_size-compress_size);w<interior_size;w+=sizeof(long))    
23774     {
23775         *op=*ip ^ cseed; /* do the xor op */
23776         op++;
23777         ip++;
23778     }   
23779     /* isize = dedup across only */
23780     for(x=interior_size;x<isize;x+=sizeof(long))    /* tight loop for transformation */
23781     {
23782         *op=*ip ^ iseed; /* do the xor op */
23783         op++;
23784         ip++;
23785     }   
23786     if(all == 0)        /* Special case for verify only */
23787         return(0);
23788     /* make the rest of the buffer non-dedupable */
23789     if(100-percent > 0)
23790     {
23791         srand(1+seed+((chid+1)*(int)numrecs64)*dedup_mseed);
23792         value=rand();
23793 /* printf("Non-dedup value %x seed %x\n",value,seed);*/
23794         for( ; x<size;x+=sizeof(long))
23795             *op++=(*ip++)^value; /* randomize the remainder */
23796     }
23797     return(0);
23798 }
23799 /* 
23800  * Used to touch all of the buffers so that the CPU data
23801  * cache is hot, and not part of the measurement.
23802  */
23803 void
23804 touch_dedup(char *i, int size)
23805 {
23806     register int x;
23807     register long *ip;
23808     ip = (long *)i;
23809     srand(DEDUPSEED);
23810     for(x=0;x<size/sizeof(long);x++)
23811     {
23812         *ip=rand(); /* fill initial buffer */
23813         ip++;
23814     }
23815 }
23816 
23817 /* 
23818    A C-program for MT19937-64 (2004/9/29 version).
23819    Coded by Takuji Nishimura and Makoto Matsumoto.
23820 
23821    This is a 64-bit version of Mersenne Twister pseudorandom number
23822    generator.
23823 
23824    Before using, initialize the state by using init_genrand64(seed)  
23825    or init_by_array64(init_key, key_length).
23826 
23827    Copyright (C) 2004, Makoto Matsumoto and Takuji Nishimura,
23828    All rights reserved.                          
23829 
23830    Redistribution and use in source and binary forms, with or without
23831    modification, are permitted provided that the following conditions
23832    are met:
23833 
23834      1. Redistributions of source code must retain the above copyright
23835         notice, this list of conditions and the following disclaimer.
23836 
23837      2. Redistributions in binary form must reproduce the above copyright
23838         notice, this list of conditions and the following disclaimer in the
23839         documentation and/or other materials provided with the distribution.
23840 
23841      3. The names of its contributors may not be used to endorse or promote 
23842         products derived from this software without specific prior written 
23843         permission.
23844 
23845    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23846    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23847    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23848    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23849    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23850    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23851    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23852    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23853    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23854    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23855    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23856 
23857    References:
23858    T. Nishimura, ``Tables of 64-bit Mersenne Twisters''
23859      ACM Transactions on Modeling and 
23860      Computer Simulation 10. (2000) 348--357.
23861    M. Matsumoto and T. Nishimura,
23862      ``Mersenne Twister: a 623-dimensionally equidistributed
23863        uniform pseudorandom number generator''
23864      ACM Transactions on Modeling and 
23865      Computer Simulation 8. (Jan. 1998) 3--30.
23866 
23867    Any feedback is very welcome.
23868    http://www.math.hiroshima-u.ac.jp/~m-mat/MT/emt.html
23869    email: m-mat @ math.sci.hiroshima-u.ac.jp (remove spaces)
23870 */
23871 
23872 
23873 
23874 #define NN 312
23875 #define MM 156
23876 #define MATRIX_A 0xB5026F5AA96619E9ULL
23877 #define UM 0xFFFFFFFF80000000ULL /* Most significant 33 bits */
23878 #define LM 0x7FFFFFFFULL /* Least significant 31 bits */
23879 
23880 
23881 /* The array for the state vector */
23882 static unsigned long long mt[NN]; 
23883 /* mti==NN+1 means mt[NN] is not initialized */
23884 static int mti=NN+1; 
23885 
23886 /* initializes mt[NN] with a seed */
23887 void init_genrand64(unsigned long long seed)
23888 {
23889     mt[0] = seed;
23890     for (mti=1; mti<NN; mti++) 
23891         mt[mti] =  (6364136223846793005ULL * (mt[mti-1] ^ (mt[mti-1] >> 62)) + mti);
23892 }
23893 
23894 /* initialize by an array with array-length */
23895 /* init_key is the array for initializing keys */
23896 /* key_length is its length */
23897 void init_by_array64(unsigned long long init_key[],
23898              unsigned long long key_length)
23899 {
23900     unsigned long long i, j, k;
23901     init_genrand64(19650218ULL);
23902     i=1; j=0;
23903     k = (NN>key_length ? NN : key_length);
23904     for (; k; k--) {
23905         mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 62)) * 3935559000370003845ULL))
23906           + init_key[j] + j; /* non linear */
23907         i++; j++;
23908         if (i>=NN) { mt[0] = mt[NN-1]; i=1; }
23909         if (j>=key_length) j=0;
23910     }
23911     for (k=NN-1; k; k--) {
23912         mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 62)) * 2862933555777941757ULL))
23913           - i; /* non linear */
23914         i++;
23915         if (i>=NN) { mt[0] = mt[NN-1]; i=1; }
23916     }
23917 
23918     mt[0] = 1ULL << 63; /* MSB is 1; assuring non-zero initial array */ 
23919 }
23920 
23921 /* generates a random number on [0, 2^64-1]-interval */
23922 unsigned long long genrand64_int64(void)
23923 {
23924     int i;
23925     unsigned long long x;
23926     static unsigned long long mag01[2]={0ULL, MATRIX_A};
23927 
23928     if (mti >= NN) { /* generate NN words at one time */
23929 
23930         /* if init_genrand64() has not been called, */
23931         /* a default initial seed is used     */
23932         if (mti == NN+1) 
23933             init_genrand64(5489ULL); 
23934 
23935         for (i=0;i<NN-MM;i++) {
23936             x = (mt[i]&UM)|(mt[i+1]&LM);
23937             mt[i] = mt[i+MM] ^ (x>>1) ^ mag01[(int)(x&1ULL)];
23938         }
23939         for (;i<NN-1;i++) {
23940             x = (mt[i]&UM)|(mt[i+1]&LM);
23941             mt[i] = mt[i+(MM-NN)] ^ (x>>1) ^ mag01[(int)(x&1ULL)];
23942         }
23943         x = (mt[NN-1]&UM)|(mt[0]&LM);
23944         mt[NN-1] = mt[MM-1] ^ (x>>1) ^ mag01[(int)(x&1ULL)];
23945 
23946         mti = 0;
23947     }
23948   
23949     x = mt[mti++];
23950 
23951     x ^= (x >> 29) & 0x5555555555555555ULL;
23952     x ^= (x << 17) & 0x71D67FFFEDA60000ULL;
23953     x ^= (x << 37) & 0xFFF7EEE000000000ULL;
23954     x ^= (x >> 43);
23955 
23956     return x;
23957 }
23958 
23959 /* generates a random number on [0, 2^63-1]-interval */
23960 long long genrand64_int63(void)
23961 {
23962     return (long long)(genrand64_int64() >> 1);
23963 }
23964 
23965 /* generates a random number on [0,1]-real-interval */
23966 double genrand64_real1(void)
23967 {
23968     return (genrand64_int64() >> 11) * (1.0/9007199254740991.0);
23969 }
23970 
23971 /* generates a random number on [0,1)-real-interval */
23972 double genrand64_real2(void)
23973 {
23974     return (genrand64_int64() >> 11) * (1.0/9007199254740992.0);
23975 }
23976 
23977 /* generates a random number on (0,1)-real-interval */
23978 double genrand64_real3(void)
23979 {
23980     return ((genrand64_int64() >> 12) + 0.5) * (1.0/4503599627370496.0);
23981 }
23982 
23983 #ifdef MT_TEST
23984 
23985 int main(void)
23986 {
23987     int i;
23988     unsigned long long init[4]={0x12345ULL, 0x23456ULL, 0x34567ULL, 0x45678ULL}, length=4;
23989     init_by_array64(init, length);
23990     printf("1000 outputs of genrand64_int64()\n");
23991     for (i=0; i<1000; i++) {
23992       printf("%20llu ", genrand64_int64());
23993       if (i%5==4) printf("\n");
23994     }
23995     printf("\n1000 outputs of genrand64_real2()\n");
23996     for (i=0; i<1000; i++) {
23997       printf("%10.8f ", genrand64_real2());
23998       if (i%5==4) printf("\n");
23999     }
24000     return 0;
24001 }
24002 #endif
24003 
24004 /*----------------------------------------------------------------------*/
24005 /*                                  */
24006 /* The PIT Programmable Interdimensional Timer              */
24007 /*                                  */
24008 /* This is used to measure time, when you know something odd is going   */
24009 /* to be happening with your wrist watch. For example, you have entered */
24010 /* a temporal distortion field where time its-self is not moving        */
24011 /* as it does in your normal universe. ( thing either intense       */
24012 /* gravitational fields bending space-time, or virtual machines playing */
24013 /* with time )                              */
24014 /* So.. you need to measure time, but with respect to a normal      */
24015 /* space-time.  So.. we deal with this by calling for time from another */
24016 /* machine, but do so with a very similar interface to that of      */
24017 /* gettimeofday().                          */
24018 /* To activate this, one only needs to set an environmental variable.   */
24019 /*      Example:   setenv IOZ_PIT hostname_of_PIT_server        */
24020 /* The environmental variable tells this client where to go to get  */
24021 /* correct timeofday time stamps, with the usual gettimeofday()     */
24022 /* resolution. (microsecond resolution)                 */
24023 /*----------------------------------------------------------------------*/
24024 
24025 /*----------------------------------------------------------------------*/
24026 /* The PIT client: Adapted from source found on the web for someone's   */
24027 /* daytime client code. (Used in many examples for network programming  */
24028 /* Reads PIT info over a socket from a PIT server.          */
24029 /* The PIT server sends its raw microsecond version of gettimeofday     */
24030 /* The PIT client converts this back into timeval structure format.     */
24031 /* Written by: Don Capps. [ capps@iozone.org ]              */
24032 /*----------------------------------------------------------------------*/
24033 
24034 /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<      */
24035 /* >>>> DON'T forget, you must put a definition for PIT <<<<<<<<<<      */
24036 /* >>>> in /etc/services  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<      */
24037 /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<      */
24038 #define DFLT_SERVICE   "PIT"     /* Default service name.               */
24039 #define INVALID_DESC   -1        /* Invalid file (socket) descriptor.   */
24040 #define MAXBFRSIZE     256       /* Max bfr sz to read remote TOD.      */
24041 
24042 /*
24043 ** Type definitions (for convenience).
24044 */
24045 #if defined(Windows)
24046 int false = 0;
24047 int true = 1;
24048 #else
24049 typedef enum { false = 0, true } boolean;
24050 #endif
24051 typedef struct sockaddr_in       sockaddr_in_t;
24052 typedef struct sockaddr_in6      sockaddr_in6_t;
24053 
24054 /*
24055  * Routine to mimic gettimeofday() using a remote PIT server 
24056  */
24057 #if defined(_SUA_)
24058 struct timezone {
24059     int                 tz_minuteswest;             
24060     int                 tz_dsttime;                         
24061 };
24062 #endif
24063 
24064 int 
24065 pit_gettimeofday( struct timeval *tp, struct timezone *foo,
24066     char *pit_hostname, char *pit_service)
24067 {
24068     int             sckt;          /* socket descriptor */
24069     unsigned scopeId = 0;
24070 
24071     /* See if the interdimensional rift is active */
24072     
24073     if(pit_hostname[0] == 0)
24074     {
24075         return gettimeofday(tp,foo);
24076     }
24077 
24078     if ( ( sckt = openSckt( pit_hostname,
24079                            pit_service,
24080                            scopeId ) ) == INVALID_DESC )
24081     {
24082             fprintf( stderr,
24083                   "Sorry... a connectionless socket could "
24084                   "not be set up.\n");
24085                 return -1;
24086     }
24087     /*
24088     ** Get the remote PIT.
24089     */
24090     pit( sckt ,tp );
24091     close(sckt);
24092         return 0;
24093 }
24094 
24095 /*
24096  * Opens a socket for the PIT to use to get the time
24097  * from a remote time server ( A PIT server ) 
24098  */
24099 static int openSckt( const char   *host,
24100                      const char   *service,
24101                      unsigned int  scopeId )
24102 {
24103    struct addrinfo *ai;
24104    int              aiErr;
24105    struct addrinfo *aiHead;
24106    struct addrinfo  hints;
24107    sockaddr_in6_t  *pSadrIn6;
24108    int              sckt;
24109    /*
24110     * Initialize the 'hints' structure for getaddrinfo(3).
24111    */
24112    memset( &hints, 0, sizeof( hints ) );
24113    hints.ai_family   = PF_UNSPEC;     /* IPv4 or IPv6 records */
24114    hints.ai_socktype = SOCK_STREAM;    /* Connection oriented communication.*/
24115    hints.ai_protocol = IPPROTO_TCP;   /* TCP transport layer protocol only. */
24116    /*
24117    ** Look up the host/service information.
24118    */
24119    if ( ( aiErr = getaddrinfo( host,
24120                                service,
24121                                &hints,
24122                                &aiHead ) ) != 0 )
24123    {
24124       fprintf( stderr, "(line %d): ERROR - %s.\n", __LINE__, 
24125      gai_strerror( aiErr ) );
24126       return INVALID_DESC;
24127    }
24128    /*
24129    ** Go through the list and try to open a connection.  Continue until either
24130    ** a connection is established or the entire list is exhausted.
24131    */
24132    for ( ai = aiHead,   sckt = INVALID_DESC;
24133          ( ai != NULL ) && ( sckt == INVALID_DESC );
24134          ai = ai->ai_next )
24135    {
24136       /*
24137       ** IPv6 kluge.  Make sure the scope ID is set.
24138       */
24139       if ( ai->ai_family == PF_INET6 )
24140       {
24141          pSadrIn6 = (sockaddr_in6_t*) ai->ai_addr;
24142          if ( pSadrIn6->sin6_scope_id == 0 )
24143          {
24144             pSadrIn6->sin6_scope_id = scopeId;
24145          }  /* End IF the scope ID wasn't set. */
24146       }  /* End IPv6 kluge. */
24147       /*
24148       ** Create a socket.
24149       */
24150       sckt = socket( ai->ai_family, ai->ai_socktype, ai->ai_protocol );
24151       if(sckt == -1)
24152       {
24153          sckt = INVALID_DESC;
24154          continue;   /* Try the next address record in the list. */
24155       }
24156       /*
24157       ** Set the target destination for the remote host on this socket.  That
24158       ** is, this socket only communicates with the specified host.
24159       */
24160       if (connect( sckt, ai->ai_addr, ai->ai_addrlen ) )
24161       {
24162          (void) close( sckt );   /* Could use system call again here, 
24163                     but why? */
24164          sckt = INVALID_DESC;
24165          continue;   /* Try the next address record in the list. */
24166       }
24167    }  /* End FOR each address record returned by getaddrinfo(3). */
24168    /*
24169    ** Clean up & return.
24170    */
24171    freeaddrinfo( aiHead );
24172    return sckt;
24173 }  /* End openSckt() */
24174 
24175 /*
24176  * Read the PIT, and convert this back into timeval 
24177  * info, and store it in the timeval structure that was
24178  * passed in.
24179  */
24180 static void pit( int sckt, struct timeval *tp)
24181 {
24182    char bfr[ MAXBFRSIZE+1 ];
24183    int  inBytes;
24184    long long value;
24185    /*
24186    ** Send a datagram to the server to wake it up.  The content isn't
24187    ** important, but something must be sent to let it know we want the TOD.
24188    */
24189    junk=write( sckt, "Are you there?", 14 );
24190    /*
24191    ** Read the PIT from the remote host.
24192    */
24193    inBytes = read( sckt, bfr, MAXBFRSIZE );
24194    bfr[ inBytes ] = '\0';   /* Null-terminate the received string. */
24195    /* 
24196     * Convert result to timeval structure format 
24197     */
24198    sscanf(bfr,"%llu\n",&value);
24199    tp->tv_sec = (long)(value / 1000000);
24200    tp->tv_usec = (long)(value % 1000000);
24201 }  
24202 
24203 /* sync does not exist in SUA */
24204 #if defined(_SUA_)
24205 sync()
24206 {
24207 }
24208 #endif
24209 
24210 
24211 #define BUCKETS 40
24212 long long buckets[BUCKETS];
24213 long long bucket_val[BUCKETS] =
24214     { 20,40,60,80,100,
24215     200,400,600,800,1000,
24216     2000,4000,6000,8000,10000,
24217     12000,14000,16000,18000,20000,
24218     40000,60000,80000,100000,
24219     200000,400000,600000,800000,1000000,
24220     2000000,4000000,6000000,8000000,10000000,
24221     20000000,30000000,60000000,90000000,120000000,120000001};
24222 /*
24223  * Buckets: (Based on a Netapp internal consensus)
24224  *     0       1       2       3      4 
24225  *  <=20us  <=40us  <=60us  <=80us  <=100us
24226  * 
24227  *    5        6       7       8       9
24228  * <=200us  <=400us <=600us <=88us  <=1ms
24229  * 
24230  *   10       11      12      13      14
24231  * <=2ms    <=4ms   <=6ms   <=8ms   <=10ms
24232  * 
24233  *   15       16      17      18      19
24234  * <=12ms   <=14ms  <=16ms  <=18ms  <=20ms
24235  *
24236  *   20       21      22      23      24
24237  * <=20ms   <=40ms  <=60ms  <=80ms  <=100ms
24238  * 
24239  *   25       26      27      28      29
24240  * <=200ms  <=400ms <=600ms <=800ms <=1s
24241  * 
24242  *   30       31      32      33      34
24243  * <=2s     <=4s    <=6s    <=8s    <=10s
24244  *
24245  *   35       36      37      38      39
24246  * <=20s    <=30s   <=60    <=90s    >90
24247  */
24248     
24249 /*
24250     fp=fopen("/tmp/iozone_latency_summary.txt","a");
24251     dump_hist(fp);
24252 */
24253 
24254 void
24255 hist_insert(double my_value)
24256 {
24257     int k;
24258     long long value;
24259     
24260     /* Convert to micro-seconds */
24261     value = (long long)(my_value * 1000000);
24262     for(k=0;k<BUCKETS;k++)
24263     {
24264        if(k < (BUCKETS-1)) 
24265        {
24266          if(value <= bucket_val[k])
24267          {
24268         buckets[k]++;
24269         break;
24270          }
24271        }
24272        else
24273        {
24274          if(value > bucket_val[k])
24275          {
24276         buckets[k]++;
24277         break;
24278          }
24279        }
24280     }
24281 }
24282 
24283 void
24284 dump_hist(char *what,int id)
24285 {
24286    FILE *fp;
24287 
24288    char name[256];
24289  
24290    sprintf(name,"%s_child_%d.txt","Iozone_histogram",id);
24291 
24292    fp = fopen(name,"a");
24293 
24294 #ifndef NO_PRINT_LLD
24295    fprintf(fp,"Child: %d Op: %s\n",id,what);
24296    fprintf(fp,"Band 1:   ");
24297    fprintf(fp," 20us:%-7.1lld ",buckets[0]);
24298    fprintf(fp," 40us:%-7.1lld ",buckets[1]);
24299    fprintf(fp," 60us:%-7.1lld ",buckets[2]);
24300    fprintf(fp," 80us:%-7.1lld ",buckets[3]);
24301    fprintf(fp,"100us:%-7.1lld \n",buckets[4]);
24302 
24303    fprintf(fp,"Band 2:   ");
24304    fprintf(fp,"200us:%-7.1lld ",buckets[5]);
24305    fprintf(fp,"400us:%-7.1lld ",buckets[6]);
24306    fprintf(fp,"600us:%-7.1lld ",buckets[7]);
24307    fprintf(fp,"800us:%-7.1lld ",buckets[8]);
24308    fprintf(fp,"  1ms:%-7.1lld \n",buckets[9]);
24309 
24310    fprintf(fp,"Band 3:   ");
24311    fprintf(fp,"  2ms:%-7.1lld ",buckets[10]);
24312    fprintf(fp,"  4ms:%-7.1lld ",buckets[11]);
24313    fprintf(fp,"  6ms:%-7.1lld ",buckets[12]);
24314    fprintf(fp,"  8ms:%-7.1lld ",buckets[13]);
24315    fprintf(fp," 10ms:%-7.1lld \n",buckets[14]);
24316 
24317    fprintf(fp,"Band 4:   ");
24318    fprintf(fp," 12ms:%-7.1lld ",buckets[15]);
24319    fprintf(fp," 14ms:%-7.1lld ",buckets[16]);
24320    fprintf(fp," 16ms:%-7.1lld ",buckets[17]);
24321    fprintf(fp," 18ms:%-7.1lld ",buckets[18]);
24322    fprintf(fp," 20ms:%-7.1lld \n",buckets[19]);
24323 
24324    fprintf(fp,"Band 5:   ");
24325    fprintf(fp," 40ms:%-7.1lld ",buckets[20]);
24326    fprintf(fp," 60ms:%-7.1lld ",buckets[21]);
24327    fprintf(fp," 80ms:%-7.1lld ",buckets[22]);
24328    fprintf(fp,"100ms:%-7.1lld \n",buckets[23]);
24329 
24330    fprintf(fp,"Band 6:   ");
24331    fprintf(fp,"200ms:%-7.1lld ",buckets[24]);
24332    fprintf(fp,"400ms:%-7.1lld ",buckets[25]);
24333    fprintf(fp,"600ms:%-7.1lld ",buckets[26]);
24334    fprintf(fp,"800ms:%-7.1lld ",buckets[27]);
24335    fprintf(fp,"   1s:%-7.1lld \n",buckets[28]);
24336 
24337    fprintf(fp,"Band 7:   ");
24338    fprintf(fp,"   2s:%-7.1lld ",buckets[29]);
24339    fprintf(fp,"   4s:%-7.1lld ",buckets[30]);
24340    fprintf(fp,"   6s:%-7.1lld ",buckets[31]);
24341    fprintf(fp,"   8s:%-7.1lld ",buckets[32]);
24342    fprintf(fp,"  10s:%-7.1lld \n",buckets[33]);
24343 
24344    fprintf(fp,"Band 8:   ");
24345    fprintf(fp,"  20s:%-7.1lld ",buckets[34]);
24346    fprintf(fp,"  40s:%-7.1lld ",buckets[35]);
24347    fprintf(fp,"  60s:%-7.1lld ",buckets[36]);
24348    fprintf(fp,"  80s:%-7.1lld ",buckets[37]);
24349    fprintf(fp," 120s:%-7.1lld \n",buckets[38]);
24350 
24351    fprintf(fp,"Band 9:   ");
24352    fprintf(fp,"120+s:%-7.1lld \n\n",buckets[39]);
24353 #else
24354    fprintf(fp,"Child: %d Op: %s\n",id,what);
24355    fprintf(fp,"Band 1:   ");
24356    fprintf(fp," 20us:%-7.1ld ",buckets[0]);
24357    fprintf(fp," 40us:%-7.1ld ",buckets[1]);
24358    fprintf(fp," 60us:%-7.1ld ",buckets[2]);
24359    fprintf(fp," 80us:%-7.1ld ",buckets[3]);
24360    fprintf(fp,"100us:%-7.1ld \n",buckets[4]);
24361 
24362    fprintf(fp,"Band 2:   ");
24363    fprintf(fp,"200us:%-7.1ld ",buckets[5]);
24364    fprintf(fp,"400us:%-7.1ld ",buckets[6]);
24365    fprintf(fp,"600us:%-7.1ld ",buckets[7]);
24366    fprintf(fp,"800us:%-7.1ld ",buckets[8]);
24367    fprintf(fp,"  1ms:%-7.1ld \n",buckets[9]);
24368 
24369    fprintf(fp,"Band 3:   ");
24370    fprintf(fp,"  2ms:%-7.1ld ",buckets[10]);
24371    fprintf(fp,"  4ms:%-7.1ld ",buckets[11]);
24372    fprintf(fp,"  6ms:%-7.1ld ",buckets[12]);
24373    fprintf(fp,"  8ms:%-7.1ld ",buckets[13]);
24374    fprintf(fp," 10ms:%-7.1ld \n",buckets[14]);
24375 
24376    fprintf(fp,"Band 4:   ");
24377    fprintf(fp," 12ms:%-7.1ld ",buckets[15]);
24378    fprintf(fp," 14ms:%-7.1ld ",buckets[16]);
24379    fprintf(fp," 16ms:%-7.1ld ",buckets[17]);
24380    fprintf(fp," 18ms:%-7.1ld ",buckets[18]);
24381    fprintf(fp," 20ms:%-7.1ld \n",buckets[19]);
24382 
24383    fprintf(fp,"Band 5:   ");
24384    fprintf(fp," 40ms:%-7.1ld ",buckets[20]);
24385    fprintf(fp," 60ms:%-7.1ld ",buckets[21]);
24386    fprintf(fp," 80ms:%-7.1ld ",buckets[22]);
24387    fprintf(fp,"100ms:%-7.1ld \n",buckets[23]);
24388 
24389    fprintf(fp,"Band 6:   ");
24390    fprintf(fp,"200ms:%-7.1ld ",buckets[24]);
24391    fprintf(fp,"400ms:%-7.1ld ",buckets[25]);
24392    fprintf(fp,"600ms:%-7.1ld ",buckets[26]);
24393    fprintf(fp,"800ms:%-7.1ld ",buckets[27]);
24394    fprintf(fp,"   1s:%-7.1ld \n",buckets[28]);
24395 
24396    fprintf(fp,"Band 7:   ");
24397    fprintf(fp,"   2s:%-7.1ld ",buckets[29]);
24398    fprintf(fp,"   4s:%-7.1ld ",buckets[30]);
24399    fprintf(fp,"   6s:%-7.1ld ",buckets[31]);
24400    fprintf(fp,"   8s:%-7.1ld ",buckets[32]);
24401    fprintf(fp,"  10s:%-7.1ld \n",buckets[33]);
24402 
24403    fprintf(fp,"Band 8:   ");
24404    fprintf(fp,"  20s:%-7.1ld ",buckets[34]);
24405    fprintf(fp,"  40s:%-7.1ld ",buckets[35]);
24406    fprintf(fp,"  60s:%-7.1ld ",buckets[36]);
24407    fprintf(fp,"  80s:%-7.1ld ",buckets[37]);
24408    fprintf(fp," 120s:%-7.1ld \n",buckets[38]);
24409 
24410    fprintf(fp,"Band 9:   ");
24411    fprintf(fp,"120+s:%-7.1ld \n\n",buckets[39]);
24412 #endif
24413    fclose(fp);
24414 }
24415 
24416 #ifdef HAVE_ANSIC_C
24417 void * thread_fwrite_test(void *x)
24418 #else
24419 void * thread_fwrite_test( x)
24420 #endif
24421 {
24422 
24423         struct child_stats *child_stat;
24424         double starttime1 = 0;
24425         double temp_time;
24426         double hist_time;
24427     double desired_op_rate_time;
24428     double actual_rate;
24429         double walltime, cputime;
24430         double compute_val = (double)0;
24431         float delay = (float)0;
24432         double thread_qtime_stop,thread_qtime_start;
24433         off64_t traj_offset;
24434         long long w_traj_bytes_completed;
24435         long long w_traj_ops_completed;
24436         FILE *w_traj_fd;
24437         int fd;
24438         long long recs_per_buffer;
24439         long long stopped,i;
24440         off64_t written_so_far, read_so_far, re_written_so_far,re_read_so_far;
24441         long long xx,xx2;
24442         char *dummyfile [MAXSTREAMS];           /* name of dummy file     */
24443         char *nbuff;
24444         char *maddr;
24445         char *wmaddr,*free_addr;
24446         char now_string[30];
24447         int anwser,bind_cpu,wval;
24448 #if defined(VXFS) || defined(solaris)
24449         int test_foo = 0;
24450 #endif
24451         off64_t filebytes64;
24452         char tmpname[256];
24453         FILE *thread_wqfd;
24454         FILE *thread_Lwqfd;
24455         char *filename;
24456 
24457         char *stdio_buf;
24458         char *how;
24459         long long Index = 0;
24460         FILE *stream = NULL;
24461         static int First_Run = 1;
24462 
24463         if(compute_flag)
24464                 delay=compute_time;
24465         nbuff=maddr=wmaddr=free_addr=0;
24466         thread_qtime_stop=thread_qtime_start=0;
24467         thread_wqfd=w_traj_fd=thread_Lwqfd=(FILE *)0;
24468         traj_offset=walltime=cputime=0;
24469         anwser=bind_cpu=0;
24470 
24471         if(w_traj_flag)
24472         {
24473                 filebytes64 = w_traj_fsize;
24474                 numrecs64=w_traj_ops;
24475         }
24476         else
24477         {
24478                 filebytes64 = numrecs64*reclen;
24479         }
24480         written_so_far=read_so_far=re_written_so_far=re_read_so_far=0;
24481         w_traj_bytes_completed=w_traj_ops_completed=0;
24482         recs_per_buffer = cache_size/reclen ;
24483 #ifdef NO_THREADS
24484         xx=chid;
24485 #else
24486         if(use_thread)
24487         {
24488                 xx = (long long)((long)x);
24489         }
24490         else
24491         {
24492                 xx=chid;
24493         }
24494 #endif
24495 #ifndef NO_THREADS
24496 #ifdef _HPUX_SOURCE
24497         if(ioz_processor_bind)
24498         {
24499                  bind_cpu=(begin_proc+(int)xx)%num_processors;
24500                  pthread_processor_bind_np(PTHREAD_BIND_FORCED_NP,
24501                          (pthread_spu_t *)&anwser, (pthread_spu_t)bind_cpu, pthread_self());
24502                 my_nap(40);     /* Switch to new cpu */
24503         }
24504 #endif
24505 #endif
24506         if(use_thread)
24507                 nbuff=barray[xx];
24508         else
24509                 nbuff=buffer;
24510         if(debug1 )
24511         {
24512            if(use_thread)
24513 #ifdef NO_PRINT_LLD
24514                 printf("\nStarting child %ld\n",xx);
24515 #else
24516                 printf("\nStarting child %lld\n",xx);
24517 #endif
24518            else
24519 #ifdef NO_PRINT_LLD
24520                 printf("\nStarting process %d slot %ld\n",getpid(),xx);
24521 #else
24522                 printf("\nStarting process %d slot %lld\n",getpid(),xx);
24523 #endif
24524 
24525         }
24526         dummyfile[xx]=(char *)malloc((size_t)MAXNAMESIZE);
24527         xx2=xx;
24528         if(share_file)
24529                 xx2=(long long)0;
24530         if(mfflag)
24531         {
24532 #ifdef NO_PRINT_LLD
24533            sprintf(dummyfile[xx],"%s",filearray[xx2]);
24534 #else
24535            sprintf(dummyfile[xx],"%s",filearray[xx2]);
24536 #endif
24537         }
24538         else
24539         {
24540 #ifdef NO_PRINT_LLD
24541            sprintf(dummyfile[xx],"%s.DUMMY.%ld",filearray[xx2],xx2);
24542 #else
24543            sprintf(dummyfile[xx],"%s.DUMMY.%lld",filearray[xx2],xx2);
24544 #endif
24545         }
24546         filename=dummyfile[xx];
24547 
24548         if(mmapflag || async_flag)
24549                 return(0);
24550 
24551         stdio_buf=(char *)malloc((size_t)reclen);
24552 
24553         if(Uflag) /* Unmount and re-mount the mountpoint */
24554         {
24555                 purge_buffer_cache();
24556         }
24557 
24558         if(First_Run==1)
24559         {
24560         First_Run=0;
24561                 if(check_filename(filename))
24562                         how="r+"; /* file exists, don't create and zero a new one. */
24563                 else
24564                         how="w+"; /* file doesn't exist. create it. */
24565         }
24566         else
24567                 how="r+"; /* re-tests should error out if file does not exist. */
24568 
24569 #ifdef IRIX64
24570         if((stream=(FILE *)fopen(filename,how)) == 0)
24571         {
24572                 printf("\nCan not fdopen temp file: %s %lld\n",
24573                         filename,errno);
24574                 perror("fdopen");
24575                 exit(48);
24576         }
24577 #else
24578        if((stream=(FILE *)I_FOPEN(filename,how)) == 0)
24579         {
24580 #ifdef NO_PRINT_LLD
24581                 printf("\nCan not fdopen temp file: %s %d\n",
24582                         filename,errno);
24583 #else
24584                 printf("\nCan not fdopen temp file: %s %d\n",
24585                         filename,errno);
24586 #endif
24587                 perror("fdopen");
24588                 exit(49);
24589         }
24590 #endif
24591         fd=fileno(stream);
24592         fsync(fd);
24593         if(direct_flag)
24594           setvbuf(stream,stdio_buf,_IONBF,reclen);
24595         else
24596           setvbuf(stream,stdio_buf,_IOFBF,reclen);
24597 
24598         buffer=mainbuffer;
24599         if(fetchon)
24600                 fetchit(buffer,reclen);
24601         if(verify || dedup || dedup_interior)
24602                 fill_buffer(buffer,reclen,(long long)pattern,sverify,(long long)0);
24603 
24604         compute_val=(double)0;
24605 
24606        /*******************************************************************/
24607 
24608         child_stat = (struct child_stats *)&shmaddr[xx];
24609         child_stat->throughput = 0;
24610         child_stat->actual = 0;
24611         child_stat->flag=CHILD_STATE_READY; /* Tell parent child is ready to go */
24612 
24613         if(distributed && client_iozone)
24614                 tell_master_ready(chid);
24615         if(distributed && client_iozone)
24616         {
24617                 if(cdebug)
24618                 {
24619                         printf("Child %d waiting for go from master\n",(int)xx);
24620                         fflush(stdout);
24621                 }
24622                 wait_for_master_go(chid);
24623                 if(cdebug)
24624                 {
24625                         printf("Child %d received go from master\n",(int)xx);
24626                         fflush(stdout);
24627                 }
24628         }
24629         else
24630         {
24631                 while(child_stat->flag!=CHILD_STATE_BEGIN)   /* Wait for signal from parent */
24632                         Poll((long long)1);
24633         }
24634 
24635         written_so_far=0;
24636         child_stat = (struct child_stats *)&shmaddr[xx];
24637         child_stat->actual = 0;
24638         child_stat->throughput = 0;
24639         stopped=0;
24640         if(Q_flag)
24641         {
24642                 sprintf(tmpname,"Child_%d_fwol.dat",(int)xx);
24643                 thread_wqfd=fopen(tmpname,"a");
24644                 if(thread_wqfd==0)
24645                 {
24646                         client_error=errno;
24647                         if(distributed && client_iozone)
24648                                 send_stop();
24649                         printf("Unable to open %s\n",tmpname);
24650                         exit(40);
24651                 }
24652                 fprintf(thread_wqfd,"Offset in Kbytes   Latency in microseconds  Transfer size in bytes\n");
24653         }
24654         if(L_flag)
24655         {
24656                 sprintf(tmpname,"Child_%d.log",(int)xx);
24657                 thread_Lwqfd=fopen(tmpname,"a");
24658                 if(thread_Lwqfd==0)
24659                 {
24660                         client_error=errno;
24661                         if(distributed && client_iozone)
24662                                 send_stop();
24663                         printf("Unable to open %s\n",tmpname);
24664                         exit(40);
24665                 }
24666                 get_date(now_string);
24667                 fprintf(thread_Lwqfd,"%-25s %s","fwrite test start: ",now_string);
24668         }
24669         starttime1 = time_so_far();
24670         if(cpuutilflag)
24671         {
24672                 walltime = starttime1;
24673                 cputime = cputime_so_far();
24674         }
24675        /*******************************************************************/
24676         for(i=0; i<numrecs64; i++){
24677                 if(compute_flag)
24678                         compute_val+=do_compute(compute_time);
24679                 if(multi_buffer)
24680                 {
24681                         Index +=reclen;
24682                         if(Index > (MAXBUFFERSIZE-reclen))
24683                                 Index=0;
24684                         buffer = mbuffer + Index;
24685                 }
24686                 if((verify & diag_v) || dedup || dedup_interior)
24687                         fill_buffer(buffer,reclen,(long long)pattern,sverify,i);
24688                 if(purge)
24689                         purgeit(buffer,reclen);
24690         if(Q_flag || hist_summary || op_rate_flag)
24691         {
24692             thread_qtime_start=time_so_far();
24693         }
24694                 if(fwrite(buffer, (size_t) reclen, 1, stream) != 1)
24695                 {
24696 #ifdef NO_PRINT_LLD
24697                         printf("\nError fwriting block %ld, fd= %d\n", i,
24698                                  fd);
24699 #else
24700                         printf("\nError fwriting block %lld, fd= %d\n", i,
24701                                  fd);
24702 #endif
24703                         perror("fwrite");
24704                         signal_handler();
24705                 }
24706         if(hist_summary)
24707         {
24708             thread_qtime_stop=time_so_far();
24709             hist_time =(thread_qtime_stop-thread_qtime_start);
24710             hist_insert(hist_time);
24711         }
24712         if(op_rate_flag)
24713         {
24714             thread_qtime_stop=time_so_far();
24715             desired_op_rate_time = ((double)1.0/(double)op_rate);
24716             actual_rate = (double)(thread_qtime_stop-thread_qtime_start);
24717             if( actual_rate < desired_op_rate_time)
24718                   my_unap((unsigned long long)((desired_op_rate_time-actual_rate)*1000000.0 ));
24719         }
24720         if(Q_flag)
24721         {
24722             thread_qtime_stop=time_so_far();
24723 #ifdef NO_PRINT_LLD
24724             fprintf(thread_wqfd,"%10.1ld %10.0f %10.1ld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
24725 #else
24726             fprintf(thread_wqfd,"%10.1lld %10.0f %10.1lld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
24727 #endif
24728         }
24729                 w_traj_ops_completed++;
24730                 w_traj_bytes_completed+=reclen;
24731                 written_so_far+=reclen/1024;
24732         }
24733         if(include_flush)
24734         {
24735                 fflush(stream);
24736                 wval=fsync(fd);
24737                 if(wval==-1){
24738                         perror("fsync");
24739                         signal_handler();
24740                 }
24741         }
24742         if(include_close)
24743         {
24744                 wval=fclose(stream);
24745                 if(wval==-1){
24746                         perror("fclose");
24747                         signal_handler();
24748                 }
24749         }
24750         /*******************************************************************/
24751         if(!stopped){
24752                 temp_time = time_so_far();
24753                 child_stat->throughput = ((temp_time - starttime1)-time_res)
24754                         -compute_val;
24755                 if(child_stat->throughput < (double).000001)
24756                 {
24757                         child_stat->throughput= time_res;
24758                         if(rec_prob < reclen)
24759                                 rec_prob = reclen;
24760                         res_prob=1;
24761                 }
24762 
24763                 if(OPS_flag){
24764                    /*written_so_far=(written_so_far*1024)/reclen;*/
24765                    written_so_far=w_traj_ops_completed;
24766                 }
24767                 child_stat->throughput =
24768                         (double)written_so_far/child_stat->throughput;
24769                 child_stat->actual = (double)written_so_far;
24770         }
24771         if(cdebug)
24772         {
24773                 printf("Child %d: throughput %f actual %f \n",(int)chid, child_stat->throughput,
24774                         child_stat->actual);
24775                 fflush(stdout);
24776         }
24777         if(cpuutilflag)
24778         {
24779                 cputime = cputime_so_far() - cputime;
24780                 if (cputime < cputime_res)
24781                         cputime = 0.0;
24782                 child_stat->cputime = cputime;
24783                 walltime = time_so_far() - walltime;
24784                 child_stat->walltime = walltime;
24785         }
24786         if(distributed && client_iozone)
24787                 tell_master_stats(THREAD_FWRITE_TEST, chid, child_stat->throughput,
24788                         child_stat->actual,
24789                         child_stat->cputime, child_stat->walltime,
24790                         (char)*stop_flag,
24791                         (long long)CHILD_STATE_HOLD);
24792 
24793         if (debug1) {
24794                 printf(" child/slot: %lld, wall-cpu: %8.3f %8.3fC" " -> %6.2f%%\n",
24795                         xx, walltime, cputime,
24796                         cpu_util(cputime, walltime));
24797         }
24798         child_stat->flag = CHILD_STATE_HOLD; /* Tell parent I'm done */
24799         stopped=0;
24800 
24801         /*******************************************************************/
24802         /* End fwrite performance test. *************************************/
24803         /*******************************************************************/
24804 
24805         if(debug1)
24806 #ifdef NO_PRINT_LLD
24807                 printf("\nChild finished %ld\n",xx);
24808 #else
24809                 printf("\nChild finished %lld\n",xx);
24810 #endif
24811         if(Q_flag && (thread_wqfd !=0) )
24812                 fclose(thread_wqfd);
24813         free(dummyfile[xx]);
24814         if(w_traj_flag)
24815                 fclose(w_traj_fd);
24816 
24817         if(L_flag)
24818         {
24819                 get_date(now_string);
24820                 fprintf(thread_Lwqfd,"%-25s %s","Fwrite test finished: ",now_string);
24821                 fclose(thread_Lwqfd);
24822         }
24823         /*******************************************************************/
24824         if(!include_close)
24825         {
24826                 wval=fflush(stream);
24827                 if(wval==-1){
24828                         perror("fflush");
24829                         signal_handler();
24830                 }
24831                 wval=fsync(fd);
24832                 if(wval==-1){
24833                         perror("fsync");
24834                         signal_handler();
24835                 }
24836                 wval=fclose(stream);
24837                 if(wval==-1){
24838                         perror("fclose");
24839                         signal_handler();
24840                 }
24841         }
24842 
24843         if(restf)
24844                 sleep((int)(int)rest_val);
24845 
24846         free(stdio_buf);
24847         if(OPS_flag || MS_flag){
24848            filebytes64=filebytes64/reclen;
24849         }
24850         /*******************************************************************/
24851     if(hist_summary)
24852        dump_hist("Fwrite",(int)xx);
24853         if(distributed && client_iozone)
24854                 return(0);
24855 #ifdef NO_THREADS
24856         exit(0);
24857 #else
24858         if(use_thread)
24859                 thread_exit();
24860         else
24861                 exit(0);
24862 #endif
24863 
24864 return(0);
24865 }
24866 
24867 
24868 #ifdef HAVE_ANSIC_C
24869 void * thread_fread_test(void *x)
24870 #else
24871 void * thread_fread_test( x)
24872 #endif
24873 {
24874         struct child_stats *child_stat;
24875         double starttime1 = 0;
24876         double temp_time;
24877         double hist_time;
24878     double desired_op_rate_time;
24879     double actual_rate;
24880         double walltime, cputime;
24881         double compute_val = (double)0;
24882         float delay = (float)0;
24883         double thread_qtime_stop,thread_qtime_start;
24884         off64_t traj_offset;
24885         long long w_traj_bytes_completed;
24886         long long w_traj_ops_completed;
24887         FILE *w_traj_fd;
24888         int fd;
24889         long long recs_per_buffer;
24890         long long stopped,i;
24891         off64_t written_so_far, read_so_far, re_written_so_far,re_read_so_far;
24892         long long xx,xx2;
24893         char *dummyfile [MAXSTREAMS];           /* name of dummy file     */
24894         char *nbuff;
24895         char *maddr;
24896         char *wmaddr,*free_addr;
24897         char now_string[30];
24898         int anwser,bind_cpu;
24899 #if defined(VXFS) || defined(solaris)
24900         int test_foo = 0;
24901 #endif
24902         off64_t filebytes64;
24903         char tmpname[256];
24904         FILE *thread_wqfd;
24905         FILE *thread_Lwqfd;
24906 
24907         if(compute_flag)
24908                 delay=compute_time;
24909         nbuff=maddr=wmaddr=free_addr=0;
24910         thread_qtime_stop=thread_qtime_start=0;
24911         thread_wqfd=w_traj_fd=thread_Lwqfd=(FILE *)0;
24912         traj_offset=walltime=cputime=0;
24913         anwser=bind_cpu=0;
24914         char *stdio_buf;
24915         long long Index = 0;
24916         FILE *stream = NULL;
24917         char *filename;
24918 
24919         if(w_traj_flag)
24920         {
24921                 filebytes64 = w_traj_fsize;
24922                 numrecs64=w_traj_ops;
24923         }
24924         else
24925         {
24926                 filebytes64 = numrecs64*reclen;
24927         }
24928         written_so_far=read_so_far=re_written_so_far=re_read_so_far=0;
24929         w_traj_bytes_completed=w_traj_ops_completed=0;
24930         recs_per_buffer = cache_size/reclen ;
24931 #ifdef NO_THREADS
24932         xx=chid;
24933 #else
24934         if(use_thread)
24935         {
24936                 xx = (long long)((long)x);
24937         }
24938         else
24939         {
24940                 xx=chid;
24941         }
24942 #endif
24943 #ifndef NO_THREADS
24944 #ifdef _HPUX_SOURCE
24945         if(ioz_processor_bind)
24946         {
24947                  bind_cpu=(begin_proc+(int)xx)%num_processors;
24948                  pthread_processor_bind_np(PTHREAD_BIND_FORCED_NP,
24949                          (pthread_spu_t *)&anwser, (pthread_spu_t)bind_cpu, pthread_self());
24950                 my_nap(40);     /* Switch to new cpu */
24951         }
24952 #endif
24953 #endif
24954         if(use_thread)
24955                 nbuff=barray[xx];
24956         else
24957                 nbuff=buffer;
24958         if(debug1 )
24959         {
24960            if(use_thread)
24961 #ifdef NO_PRINT_LLD
24962                 printf("\nStarting child %ld\n",xx);
24963 #else
24964                 printf("\nStarting child %lld\n",xx);
24965 #endif
24966            else
24967 #ifdef NO_PRINT_LLD
24968                 printf("\nStarting process %d slot %ld\n",getpid(),xx);
24969 #else
24970                 printf("\nStarting process %d slot %lld\n",getpid(),xx);
24971 #endif
24972 
24973         }
24974         dummyfile[xx]=(char *)malloc((size_t)MAXNAMESIZE);
24975         xx2=xx;
24976         if(share_file)
24977                 xx2=(long long)0;
24978         if(mfflag)
24979         {
24980 #ifdef NO_PRINT_LLD
24981            sprintf(dummyfile[xx],"%s",filearray[xx2]);
24982 #else
24983            sprintf(dummyfile[xx],"%s",filearray[xx2]);
24984 #endif
24985         }
24986         else
24987         {
24988 #ifdef NO_PRINT_LLD
24989            sprintf(dummyfile[xx],"%s.DUMMY.%ld",filearray[xx2],xx2);
24990 #else
24991            sprintf(dummyfile[xx],"%s.DUMMY.%lld",filearray[xx2],xx2);
24992 #endif
24993         }
24994 
24995         filename=dummyfile[xx];
24996 
24997         if(mmapflag || async_flag)
24998                 return(0);
24999 
25000         stdio_buf=(char *)malloc((size_t)reclen);
25001 
25002     if(Uflag) /* Unmount and re-mount the mountpoint */
25003     {
25004         purge_buffer_cache();
25005     }
25006 #ifdef IRIX64
25007     if((stream=(FILE *)fopen(filename,"r")) == 0)
25008     {
25009         printf("\nCan not fdopen temp file: %s\n",
25010             filename);
25011         perror("fdopen");
25012         exit(51);
25013     }
25014 #else
25015     if((stream=(FILE *)I_FOPEN(filename,"r")) == 0)
25016     {
25017         printf("\nCan not fdopen temp file: %s\n",
25018             filename);
25019         perror("fdopen");
25020         exit(52);
25021     }
25022 #endif
25023     fd=I_OPEN(filename,O_RDONLY,0);
25024     fsync(fd);
25025     close(fd);
25026         if(direct_flag)
25027           setvbuf(stream,stdio_buf,_IONBF,reclen);
25028         else
25029           setvbuf(stream,stdio_buf,_IOFBF,reclen);
25030 
25031     buffer=mainbuffer;
25032     if(fetchon)
25033         fetchit(buffer,reclen);
25034     compute_val=(double)0;
25035 
25036        /*******************************************************************/
25037        /*******************************************************************/
25038 
25039         child_stat = (struct child_stats *)&shmaddr[xx];
25040         child_stat->throughput = 0;
25041         child_stat->actual = 0;
25042         child_stat->flag=CHILD_STATE_READY; /* Tell parent child is ready to go */
25043 
25044         if(distributed && client_iozone)
25045                 tell_master_ready(chid);
25046         if(distributed && client_iozone)
25047         {
25048                 if(cdebug)
25049                 {
25050                         printf("Child %d waiting for go from master\n",(int)xx);
25051                         fflush(stdout);
25052                 }
25053                 wait_for_master_go(chid);
25054                 if(cdebug)
25055                 {
25056                         printf("Child %d received go from master\n",(int)xx);
25057                         fflush(stdout);
25058                 }
25059         }
25060         else
25061         {
25062                 while(child_stat->flag!=CHILD_STATE_BEGIN)   /* Wait for signal from parent */
25063                         Poll((long long)1);
25064         }
25065 
25066         written_so_far=0;
25067         child_stat = (struct child_stats *)&shmaddr[xx];
25068         child_stat->actual = 0;
25069         child_stat->throughput = 0;
25070         stopped=0;
25071         if(Q_flag)
25072         {
25073                 sprintf(tmpname,"Child_%d_frol.dat",(int)xx);
25074                 thread_wqfd=fopen(tmpname,"a");
25075                 if(thread_wqfd==0)
25076                 {
25077                         client_error=errno;
25078                         if(distributed && client_iozone)
25079                                 send_stop();
25080                         printf("Unable to open %s\n",tmpname);
25081                         exit(40);
25082                 }
25083                 fprintf(thread_wqfd,"Offset in Kbytes   Latency in microseconds  Transfer size in bytes\n");
25084         }
25085         if(L_flag)
25086         {
25087                 sprintf(tmpname,"Child_%d.log",(int)xx);
25088                 thread_Lwqfd=fopen(tmpname,"a");
25089                 if(thread_Lwqfd==0)
25090                 {
25091                         client_error=errno;
25092                         if(distributed && client_iozone)
25093                                 send_stop();
25094                         printf("Unable to open %s\n",tmpname);
25095                         exit(40);
25096                 }
25097                 get_date(now_string);
25098                 fprintf(thread_Lwqfd,"%-25s %s","fread test start: ",now_string);
25099         }
25100         starttime1 = time_so_far();
25101         if(cpuutilflag)
25102         {
25103                 walltime = starttime1;
25104                 cputime = cputime_so_far();
25105         }
25106 
25107 
25108 
25109        /*******************************************************************/
25110 
25111     for(i=0; i<numrecs64; i++)
25112     {
25113         if(compute_flag)
25114             compute_val+=do_compute(compute_time);
25115         if(multi_buffer)
25116         {
25117             Index +=reclen;
25118             if(Index > (MAXBUFFERSIZE-reclen))
25119                 Index=0;
25120             buffer = mbuffer + Index;
25121         }
25122         if(purge)
25123             purgeit(buffer,reclen);
25124         if(Q_flag || hist_summary || op_rate_flag)
25125         {
25126             thread_qtime_start=time_so_far();
25127         }
25128         if(fread(buffer, (size_t) reclen,1, stream) != 1)
25129         {
25130 #ifdef _64BIT_ARCH_
25131 #ifdef NO_PRINT_LLD
25132             printf("\nError freading block %ld %x\n", i,
25133                 (unsigned long)buffer);
25134 #else
25135             printf("\nError freading block %lld %llx\n", i,
25136                 (unsigned long long)buffer);
25137 #endif
25138 #else
25139 #ifdef NO_PRINT_LLD
25140             printf("\nError freading block %ld %lx\n", i,
25141                 (long)buffer);
25142 #else
25143             printf("\nError freading block %lld %lx\n", i,
25144                 (long)buffer);
25145 #endif
25146 #endif
25147             perror("read");
25148             exit(54);
25149         }
25150         if(verify){
25151             if(verify_buffer(buffer,reclen,(off64_t)i,reclen,(long long)pattern,sverify)){
25152                 exit(55);
25153             }
25154         }
25155         if(hist_summary)
25156         {
25157             thread_qtime_stop=time_so_far();
25158             hist_time =(thread_qtime_stop-thread_qtime_start);
25159             hist_insert(hist_time);
25160         }
25161         if(op_rate_flag)
25162         {
25163             thread_qtime_stop=time_so_far();
25164             desired_op_rate_time = ((double)1.0/(double)op_rate);
25165             actual_rate = (double)(thread_qtime_stop-thread_qtime_start);
25166             if( actual_rate < desired_op_rate_time)
25167                   my_unap((unsigned long long)((desired_op_rate_time-actual_rate)*1000000.0 ));
25168         }
25169         if(Q_flag)
25170         {
25171             thread_qtime_stop=time_so_far();
25172 #ifdef NO_PRINT_LLD
25173             fprintf(thread_wqfd,"%10.1ld %10.0f %10.1ld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
25174 #else
25175             fprintf(thread_wqfd,"%10.1lld %10.0f %10.1lld\n",(traj_offset)/1024,((thread_qtime_stop-thread_qtime_start-time_res))*1000000,reclen);
25176 #endif
25177         }
25178                 w_traj_ops_completed++;
25179                 w_traj_bytes_completed+=reclen;
25180                 written_so_far+=reclen/1024;
25181 
25182     }
25183     if(include_flush)
25184         fflush(stream);
25185     if(include_close)
25186     {
25187         fclose(stream);
25188     }
25189 
25190         /*******************************************************************/
25191 
25192         if(!stopped){
25193                 temp_time = time_so_far();
25194                 child_stat->throughput = ((temp_time - starttime1)-time_res)
25195                         -compute_val;
25196                 if(child_stat->throughput < (double).000001)
25197                 {
25198                         child_stat->throughput= time_res;
25199                         if(rec_prob < reclen)
25200                                 rec_prob = reclen;
25201                         res_prob=1;
25202                 }
25203 
25204                 if(OPS_flag){
25205                    /*written_so_far=(written_so_far*1024)/reclen;*/
25206                    written_so_far=w_traj_ops_completed;
25207                 }
25208                 child_stat->throughput =
25209                         (double)written_so_far/child_stat->throughput;
25210                 child_stat->actual = (double)written_so_far;
25211         }
25212         if(cdebug)
25213         {
25214                 printf("Child %d: throughput %f actual %f \n",(int)chid, child_stat->throughput,
25215                         child_stat->actual);
25216                 fflush(stdout);
25217         }
25218         if(cpuutilflag)
25219         {
25220                 cputime = cputime_so_far() - cputime;
25221                 if (cputime < cputime_res)
25222                         cputime = 0.0;
25223                 child_stat->cputime = cputime;
25224                 walltime = time_so_far() - walltime;
25225                 child_stat->walltime = walltime;
25226         }
25227         if(distributed && client_iozone)
25228                 tell_master_stats(THREAD_FREAD_TEST, chid, child_stat->throughput,
25229                         child_stat->actual,
25230                         child_stat->cputime, child_stat->walltime,
25231                         (char)*stop_flag,
25232                         (long long)CHILD_STATE_HOLD);
25233 
25234         if (debug1) {
25235                 printf(" child/slot: %lld, wall-cpu: %8.3f %8.3fC" " -> %6.2f%%\n",
25236                         xx, walltime, cputime,
25237                         cpu_util(cputime, walltime));
25238         }
25239         child_stat->flag = CHILD_STATE_HOLD; /* Tell parent I'm done */
25240         stopped=0;
25241 
25242         /*******************************************************************/
25243         /* End fead performance test.  *************************************/
25244         /*******************************************************************/
25245 
25246         if(debug1)
25247 #ifdef NO_PRINT_LLD
25248                 printf("\nChild finished %ld\n",xx);
25249 #else
25250                 printf("\nChild finished %lld\n",xx);
25251 #endif
25252         if(Q_flag && (thread_wqfd !=0) )
25253                 fclose(thread_wqfd);
25254         free(dummyfile[xx]);
25255         if(w_traj_flag)
25256                 fclose(w_traj_fd);
25257 
25258         if(L_flag)
25259         {
25260                 get_date(now_string);
25261                 fprintf(thread_Lwqfd,"%-25s %s","Fread test finished: ",now_string);
25262                 fclose(thread_Lwqfd);
25263         }
25264 
25265         /*******************************************************************/
25266 
25267         if(!include_close)
25268     {
25269         fflush(stream);
25270         fclose(stream);
25271     }
25272         stream = NULL;
25273 
25274         if(restf)
25275                 sleep((int)(int)rest_val);
25276 
25277         free(stdio_buf);
25278         if(OPS_flag || MS_flag){
25279            filebytes64=filebytes64/reclen;
25280         }
25281 
25282         /*******************************************************************/
25283     if(hist_summary)
25284        dump_hist("Fread",(int)xx);
25285         if(distributed && client_iozone)
25286                 return(0);
25287 #ifdef NO_THREADS
25288         exit(0);
25289 #else
25290         if(use_thread)
25291                 thread_exit();
25292         else
25293                 exit(0);
25294 #endif
25295 
25296 return(0);
25297 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines