PAPI  5.7.0.0
iozone.c
Go to the documentation of this file.
1 /************************************************************************/
2 /* Original Author: */
3 /* William Norcott (wnorcott@us.oracle.com) */
4 /* 4 Dunlap Drive */
5 /* Nashua, NH 03060 */
6 /* */
7 /************************************************************************/
8 /* Enhancements by: */
9 /* Don Capps (capps@iozone.org) */
10 /* 7417 Crenshaw */
11 /* Plano, TX 75025 */
12 /* */
13 /************************************************************************/
14 /* Copyright 1991, 1992, 1994, 1998, 2000, 2001 William D. Norcott */
15 /************************************************************************/
16 /* */
17 /* Iozone is based on the original work done by William Norrcot. It has */
18 /* been enhanced so that it provides a more complete filesystem */
19 /* characterization. */
20 /* Its purpose is to provide automated filesystem characterization. */
21 /* Enhancements have been made by: */
22 /* */
23 /* Don Capps capps@iozone.org */
24 /* */
25 /* Iozone can perform single stream and multi stream I/O */
26 /* also it now performs read, write, re-read, re-write, */
27 /* read backwards, read/write random, re-read record, */
28 /* pread, re-pread, re-pwrite, preadv, re-preadv, pwritev, */
29 /* stride read, and re-pwritev,mmap, POSIX async I/O, NFS */
30 /* cluster testing and much more. */
31 /* */
32 /* The frontend now uses getopt() and the user can control many more */
33 /* of the actions. */
34 /* */
35 /* */
36 /************************************************************************/
37 /* THIS SOFTWARE IS PROVIDED BY DON CAPPS AND THE IOZONE CREW "AS IS */
38 /* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED */
39 /* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A */
40 /* PARTICULAR PURPOSE ARE DISCLAIMED. */
41 /* */
42 /* IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY */
43 /* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL */
44 /* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
45 /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS */
46 /* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER */
47 /* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR */
48 /* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE. */
49 /************************************************************************/
50 
51 /************************************************************************/
52 /* For the beginner... */
53 /* */
54 /* 1. make linux (linux, hpux, convex, hpux_no_ansi) */
55 /* 2. type ./iozone -Ra */
56 /* */
57 /* Hint: Type make (it will give you a list of valid targets) */
58 /* */
59 /************************************************************************/
60 
61 
62 /* The version number */
63 #define THISVERSION " Version $Revision$"
64 
65 #if defined(linux)
66  #define _GNU_SOURCE
67 #endif
68 /* Include for Cygnus development environment for Windows */
69 #if defined (Windows)
70 #include <windows.h>
71 #include <errno.h>
72 #else
73 #if defined(linux) || defined(solaris) || defined(macosx) || defined(__AIX__) || defined(FreeBSD) || defined(_HPUX_SOURCE)
74 #include <errno.h>
75 #else
76 extern int errno; /* imported for errors */
77 extern int h_errno; /* imported for errors */
78 #endif
79 #endif
80 
81 
82 #include <sys/types.h>
83 #include <sys/stat.h>
84 #if defined (__LP64__) || defined(OSF_64) || defined(__alpha__) || defined(__arch64__) || defined(_LP64) || defined(__s390x__) || defined(__AMD64__)
85 #define MODE "\tCompiled for 64 bit mode."
86 #define _64BIT_ARCH_
87 #else
88 #define MODE "\tCompiled for 32 bit mode."
89 #endif
90 
91 #ifndef NO_THREADS
92 #include <pthread.h>
93 #endif
94 
95 #if defined(HAVE_ANSIC_C) && defined(linux)
96 #include <stdlib.h>
97 #include <sys/wait.h>
98 #endif
99 
100 #ifdef HAVE_PROTO
101 #include "proto.h"
102 #else
103 int atoi();
104 int close();
105 int unlink();
106 int main();
107 void record_command_line();
108 #if !defined(linux)
109 int wait();
110 #endif
111 int fsync();
112 void srand48();
113 long lrand48();
114 void create_list();
115 void Poll();
116 void print_header();
117 void Kill();
118 long long l_min();
119 long long l_max();
120 long long mythread_create();
121 int gen_new_buf();
122 void touch_dedup();
123 void init_by_array64(unsigned long long *, unsigned long long );
124 unsigned long long genrand64_int64(void);
125 #endif
126 
127 #include <fcntl.h>
128 
129 char *help[] = {
130 " Usage: iozone [-s filesize_Kb] [-r record_size_Kb] [-f [path]filename] [-h]",
131 " [-i test] [-E] [-p] [-a] [-A] [-z] [-Z] [-m] [-M] [-t children]",
132 " [-l min_number_procs] [-u max_number_procs] [-v] [-R] [-x] [-o]",
133 " [-d microseconds] [-F path1 path2...] [-V pattern] [-j stride]",
134 " [-T] [-C] [-B] [-D] [-G] [-I] [-H depth] [-k depth] [-U mount_point]",
135 " [-S cache_size] [-O] [-L cacheline_size] [-K] [-g maxfilesize_Kb]",
136 " [-n minfilesize_Kb] [-N] [-Q] [-P start_cpu] [-e] [-c] [-b Excel.xls]",
137 " [-J milliseconds] [-X write_telemetry_filename] [-w] [-W]",
138 " [-Y read_telemetry_filename] [-y minrecsize_Kb] [-q maxrecsize_Kb]",
139 " [-+u] [-+m cluster_filename] [-+d] [-+x multiplier] [-+p # ]",
140 " [-+r] [-+t] [-+X] [-+Z] [-+w percent dedupable] [-+y percent_interior_dedup]",
141 " [-+C percent_dedup_within]",
142 " ",
143 " -a Auto mode",
144 " -A Auto2 mode",
145 " -b Filename Create Excel worksheet file",
146 " -B Use mmap() files",
147 " -c Include close in the timing calculations",
148 " -C Show bytes transferred by each child in throughput testing",
149 " -d # Microsecond delay out of barrier",
150 " -D Use msync(MS_ASYNC) on mmap files",
151 " -e Include flush (fsync,fflush) in the timing calculations",
152 " -E Run extension tests",
153 " -f filename to use",
154 " -F filenames for each process/thread in throughput test",
155 " -g # Set maximum file size (in Kbytes) for auto mode (or #m or #g)",
156 " -G Use msync(MS_SYNC) on mmap files",
157 " -h help",
158 " -H # Use POSIX async I/O with # async operations",
159 " -i # Test to run (0=write/rewrite, 1=read/re-read, 2=random-read/write",
160 " 3=Read-backwards, 4=Re-write-record, 5=stride-read, 6=fwrite/re-fwrite",
161 " 7=fread/Re-fread, 8=random_mix, 9=pwrite/Re-pwrite, 10=pread/Re-pread",
162 " 11=pwritev/Re-pwritev, 12=preadv/Re-preadv)",
163 " -I Use VxFS VX_DIRECT, O_DIRECT,or O_DIRECTIO for all file operations",
164 " -j # Set stride of file accesses to (# * record size)",
165 " -J # milliseconds of compute cycle before each I/O operation",
166 " -k # Use POSIX async I/O (no bcopy) with # async operations",
167 " -K Create jitter in the access pattern for readers",
168 " -l # Lower limit on number of processes to run",
169 " -L # Set processor cache line size to value (in bytes)",
170 " -m Use multiple buffers",
171 " -M Report uname -a output",
172 " -n # Set minimum file size (in Kbytes) for auto mode (or #m or #g)",
173 " -N Report results in microseconds per operation",
174 " -o Writes are synch (O_SYNC)",
175 " -O Give results in ops/sec.",
176 " -p Purge on",
177 " -P # Bind processes/threads to processors, starting with this cpu",
178 " -q # Set maximum record size (in Kbytes) for auto mode (or #m or #g)",
179 " -Q Create offset/latency files",
180 " -r # record size in Kb",
181 " or -r #k .. size in Kb",
182 " or -r #m .. size in Mb",
183 " or -r #g .. size in Gb",
184 " -R Generate Excel report",
185 " -s # file size in Kb",
186 " or -s #k .. size in Kb",
187 " or -s #m .. size in Mb",
188 " or -s #g .. size in Gb",
189 " -S # Set processor cache size to value (in Kbytes)",
190 " -t # Number of threads or processes to use in throughput test",
191 " -T Use POSIX pthreads for throughput tests",
192 " -u # Upper limit on number of processes to run",
193 " -U Mount point to remount between tests",
194 " -v version information",
195 " -V # Verify data pattern write/read",
196 " -w Do not unlink temporary file",
197 " -W Lock file when reading or writing",
198 " -x Turn off stone-walling",
199 " -X filename Write telemetry file. Contains lines with (offset reclen compute_time) in ascii",
200 " -y # Set minimum record size (in Kbytes) for auto mode (or #m or #g)",
201 " -Y filename Read telemetry file. Contains lines with (offset reclen compute_time) in ascii",
202 " -z Used in conjunction with -a to test all possible record sizes",
203 " -Z Enable mixing of mmap I/O and file I/O",
204 " -+E Use existing non-Iozone file for read-only testing",
205 " -+K Sony special. Manual control of test 8.",
206 " -+m Cluster_filename Enable Cluster testing",
207 " -+d File I/O diagnostic mode. (To troubleshoot a broken file I/O subsystem)",
208 " -+u Enable CPU utilization output (Experimental)",
209 " -+x # Multiplier to use for incrementing file and record sizes",
210 " -+p # Percentage of mix to be reads",
211 " -+r Enable O_RSYNC|O_SYNC for all testing.",
212 " -+t Enable network performance test. Requires -+m ",
213 " -+n No retests selected.",
214 " -+k Use constant aggregate data set size.",
215 " -+q Delay in seconds between tests.",
216 " -+l Enable record locking mode.",
217 " -+L Enable record locking mode, with shared file.",
218 " -+B Sequential mixed workload.",
219 #if defined(O_DSYNC)
220 " -+D Enable O_DSYNC mode.",
221 #endif
222 #ifndef NO_MADVISE
223 " -+A # Enable madvise. 0 = normal, 1=random, 2=sequential",
224 " 3=dontneed, 4=willneed",
225 #endif
226 " -+N Do not truncate existing files on sequential writes.",
227 " -+S # Dedup-able data is limited to sharing within each numerically",
228 " identified file set",
229 " -+V Enable shared file. No locking.",
230 #if defined(Windows)
231 " -+U Windows Unbufferd I/O API (Very Experimental)",
232 #endif
233 " -+X Enable short circuit mode for filesystem testing ONLY",
234 " ALL Results are NOT valid in this mode.",
235 " -+Z Enable old data set compatibility mode. WARNING.. Published",
236 " hacks may invalidate these results and generate bogus, high",
237 " values for results.",
238 " -+w ## Percent of dedup-able data in buffers.",
239 " -+y ## Percent of dedup-able within & across files in buffers.",
240 " -+C ## Percent of dedup-able within & not across files in buffers.",
241 " -+H Hostname Hostname of the PIT server.",
242 " -+P Service Service of the PIT server.",
243 " -+z Enable latency histogram logging.",
244 "" };
245 
246 char *head1[] = {
247  " 'Iozone' Filesystem Benchmark Program",
248  " ",
250  MODE,
251  " ",
252  " Original Author: William Norcott (wnorcott@us.oracle.com)",
253  " 4 Dunlap Drive",
254  " Nashua, NH 03060",
255  " ",
256  " Enhancements: Don Capps (capps@iozone.org)",
257  " 7417 Crenshaw",
258  " Plano, TX 75025",
259  " ",
260  " Copyright 1991, 1992, 1994, 1998, 1999, 2002 William D. Norcott",
261  " ",
262  " License to freely use and distribute this software is hereby granted ",
263  " by the author, subject to the condition that this copyright notice ",
264  " remains intact. The author retains the exclusive right to publish ",
265  " derivative works based on this work, including, but not limited to, ",
266  " revised versions of this work",
267  " ",
268  " Other contributors:",
269  " ",
270  " Don Capps (Network Appliance) capps@iozone.org",
271  " ",
272  ""};
273 
274 /******************************************************************
275 
276  INCLUDE FILES (system-dependent)
277 
278 ******************************************************************/
279 #include <sys/mman.h>
280 #include <stdio.h>
281 #include <signal.h>
282 #include <unistd.h>
283 
284 #include <fcntl.h>
285 #if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__APPLE__) && !defined(__DragonFly__)
286 #include <malloc.h>
287 #endif
288 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__DragonFly__)
289 #include <stdlib.h>
290 #include <string.h>
291 #endif
292 
293 #if defined (__FreeBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__APPLE__) || defined(__DragonFly__)
294 #ifndef O_SYNC
295 #define O_SYNC O_FSYNC
296 #endif
297 #endif
298 
299 #if defined (__FreeBSD__)
300 #ifndef O_RSYNC
301 #define O_RSYNC O_FSYNC
302 #endif
303 #endif
304 
305 #if ((defined(solaris) && defined(__LP64__)) || defined(__s390x__))
306 /* If we are building for 64-bit Solaris, all functions that return pointers
307  * must be declared before they are used; otherwise the compiler will assume
308  * that they return ints and the top 32 bits of the pointer will be lost,
309  * causing segmentation faults. The following includes take care of this.
310  * It should be safe to add these for all other OSs too, but we're only
311  * doing it for Solaris now in case another OS turns out to be a special case.
312  */
313 #include <strings.h>
314 #include <stdlib.h>
315 #include <sys/socket.h>
316 #include <netinet/in.h>
317 #include <arpa/inet.h>
318 
319 #endif
320 #if ( defined(solaris) && defined(studio11) )
321 #include <strings.h>
322 #include <stdlib.h>
323 #endif
324 
325 #if defined(OSFV5) || defined(linux)
326 #include <string.h>
327 #endif
328 
329 #if defined(linux)
330 #include <sys/socket.h>
331 #include <netinet/in.h>
332 #include <arpa/inet.h>
333 #endif
334 
335 #ifndef MAP_FAILED
336 #define MAP_FAILED -1
337 #endif
338 
339 #ifdef generic
340 typedef long long off64_t;
341 #endif
342 
343 #if defined(__DragonFly__)
344 #define __off64_t_defined
345 typedef off_t off64_t;
346 #endif
347 
348 
349 #ifndef solaris
350 #ifndef off64_t
351 #ifndef _OFF64_T
352 #ifndef __AIX__
353 #ifndef __off64_t_defined
354 #ifndef SCO_Unixware_gcc
355 #ifndef UWIN
356 #ifndef __DragonFly__
357 typedef long long off64_t;
358 #endif
359 #endif
360 #endif
361 #endif
362 #endif
363 #endif
364 #endif
365 #endif
366 
367 #ifdef __AIX__
368 #include <fcntl.h>
369 #endif
370 
371 #ifdef VXFS
372 #include <sys/fs/vx_ioctl.h>
373 #endif
374 
375 #ifdef unix
376 #if defined (__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__) \
377  || defined(_SUA_)
378 #include <sys/time.h>
379 #endif
380 #include <sys/times.h>
381 #include <sys/file.h>
382 #include <sys/resource.h>
383 #ifndef NULL
384 #define NULL 0
385 #endif
386 
387 #ifndef nolimits
388 #include <limits.h>
389 #endif
390 #endif
391 
392 #ifdef HAVE_ANSIC_C
393 #define VOLATILE volatile
394 #else
395 #define VOLATILE
396 #endif
397 
398 #include <sys/time.h>
399 
400 #ifdef SHARED_MEM
401 #include <sys/shm.h>
402 #endif
403 
404 #if defined(bsd4_2) && !defined(MS_SYNC)
405 #define MS_SYNC 0
406 #define MS_ASYNC 0
407 #endif
408 
409 #if defined(bsd4_4) || defined(__DragonFly__)
410 #define MAP_ANONYMOUS MAP_ANON
411 #endif
412 
413 #if defined(SCO_Unixware_gcc) || defined(solaris) || defined(UWIN) || defined(SCO)
414 #define MAP_FILE (0)
415 #endif
416 
417 #if defined(IRIX) || defined(IRIX64) || defined(Windows) || defined(bsd4_2) || defined(bsd4_4) || defined(SCO) || defined(Solaris) || defined(SCO_Unixware_gcc)
418 long long page_size = 4096;
419 #define GOT_PAGESIZE 1
420 #elif defined(NBPG)
421 long long page_size = NBPG;
422 #define GOT_PAGESIZE 1
423 #elif defined(old_linux)
424 #include <asm/page.h>
425 long long page_size = PAGE_SIZE;
426 #define GOT_PAGESIZE 1
427 #elif !defined(GOT_PAGESIZE)
428 long long page_size = 4096; /* Used when all else fails */
429 #endif
430 
431 #ifdef HAVE_PREAD
432 #ifdef HAVE_PREADV
433 #define PVECMAX 16
434 
435 #ifdef _HPUX_SOURCE
436 #define PER_VECTOR_OFFSET
437 #include <sys/puio.h>
438 struct piovec piov[PVECMAX];
439 #else
440 #include <sys/uio.h>
441 struct iovec piov[PVECMAX];
442 #define piov_base iov_base
443 #define piov_len iov_len
444 #endif
445 
446 #endif
447 #endif
448 
449 #define DEDUPSEED 0x2719362
450 
451 
452 /*
453  * In multi thread/process throughput mode each child keeps track of
454  * statistics and communicates them through various flavors of
455  * shared memory, and via messages.
456  */
457 struct child_stats {
458  long long flag; /* control space */
459  long long flag1; /* pad */
460  float walltime; /* child elapsed time */
461  float cputime; /* child CPU time */
462  float throughput; /* Throughput in either kb/sec or ops/sec */
463  float actual; /* Either actual kb read or # of ops performed */
465 
466 /*
467  * Used for cpu time statistics.
468  */
469 struct runtime {
470  float walltime;
471  float cputime;
472  float cpuutil;
473 };
474 
475 #ifdef __convex_spp
476 #include <sys/cnx_ail.h>
477 #endif
478 
479 #include <sys/socket.h>
480 #include <netinet/in.h>
481 #include <netdb.h>
482 
483 
484 /*
485  * Messages the controlling process sends to children.
486  * Internal representation that is arch specific.
487  * This is used when using the network distributed mode.
488  */
490  char c_host_name[100];
491  char c_pit_hostname[40];
492  char c_pit_service[8];
493  char c_client_name[100];
494  char c_working_dir[200];
495  char c_file_name[200];
496  char c_path_dir[200];
497  char c_execute_name[200];
500  int c_oflag;
501  int c_mfflag;
506  int c_jflag;
508  int c_k_flag;
509  int c_h_flag;
510  int c_mflag;
511  int c_pflag;
513  int c_verify;
515  int c_odsync;
516  int c_diag_v;
517  int c_dedup;
524  int c_Q_flag;
525  int c_L_flag;
536  int c_xflag;
563  int c_restf;
564  int c_mygen;
565  long long c_stride;
566  long long c_rest_val;
567  long long c_delay;
568  long long c_purge;
569  long long c_fetchon;
570  long long c_numrecs64;
571  long long c_reclen;
572  long long c_child_flag;
573  long long c_delay_start;
574  long long c_depth;
576 };
577 
578 /*
579  * All data in this is in string format for portability in a
580  * hetrogeneous environment.
581  *
582  * Messages that the master will send to the clients
583  * over the socket. This provides neutral format
584  * so that heterogeneous clusters will work.
585  * This is used when using the network distributed mode.
586  * WARNING !!! This data structure MUST not be bigger
587  * than 1448 bytes or fragmentation will kick your butt.
588  */
590  char c_host_name[100];
591  char c_pit_hostname[40];
592  char c_pit_service[8];
593  char c_client_name[100];
594  char c_working_dir[200];
595  char c_file_name[200];
596  char c_path_dir[200];
597  char c_execute_name[200];
600  char c_oflag[2];
601  char c_mfflag[2];
602  char c_unbuffered[2];
603  char c_noretest[2];
604  char c_notruncate[2];
605  char c_read_sync[2];
606  char c_jflag[2];
607  char c_async_flag[2];
608  char c_k_flag[2];
609  char c_h_flag[2];
610  char c_mflag[2];
611  char c_pflag[2];
612  char c_stride_flag[2];
613  char c_verify[2];
614  char c_sverify[2];
615  char c_odsync[2];
616  char c_diag_v[2];
617  char c_dedup[4];
620  char c_dedup_mseed[4];
621  char c_hist_summary[4];
622  char c_op_rate[4];
623  char c_op_rate_flag[2];
624  char c_Q_flag[2];
625  char c_L_flag[2];
626  char c_OPS_flag[2];
627  char c_mmapflag[2];
628  char c_mmapasflag[2];
629  char c_mmapnsflag[2];
630  char c_mmapssflag[2];
631  char c_no_copy_flag[2];
634  char c_disrupt_flag[2];
635  char c_compute_flag[2];
636  char c_stop_flag[2];
637  char c_xflag[2];
638  char c_MS_flag[2];
639  char c_mmap_mix[2];
640  char c_Kplus_flag[2];
641  char c_w_traj_flag[2]; /* small int */
642  char c_r_traj_flag[2]; /* small int */
643  char c_direct_flag[2]; /* small int */
644  char c_cpuutilflag[2]; /* small int */
645  char c_seq_mix[2]; /* small int */
646  char c_stride[10]; /* small long long */
647  char c_rest_val[10]; /* small long long */
648  char c_purge[10]; /* very small long long */
649  char c_fetchon[10]; /* very small long long */
650  char c_multiplier[10]; /* small int */
651  char c_share_file[10]; /* small int */
652  char c_file_lock[10]; /* small int */
653  char c_rec_lock[10]; /* small int */
654  char c_Kplus_readers[10]; /* small int */
655  char c_client_number[20]; /* int */
656  char c_command[20]; /* int */
657  char c_testnum[20]; /* int */
658  char c_no_unlink[4]; /* int */
659  char c_no_write[4]; /* int */
660  char c_pattern[20]; /* int */
661  char c_version[20]; /* int */
662  char c_base_time[20]; /* int */
663  char c_num_child[20]; /* int */
664  char c_pct_read[6]; /* small int */
665  char c_advise_op[4]; /* small int */
666  char c_advise_flag[4]; /* small int */
667  char c_restf[4]; /* small int */
668  char c_mygen[20]; /* long */
669  char c_depth[20]; /* small long long */
670  char c_child_flag[40]; /* small long long */
671  char c_delay[80]; /* long long */
672  char c_numrecs64[80]; /* long long */
673  char c_reclen[80]; /* long long */
674  char c_delay_start[80]; /* long long */
675  char c_compute_time[80]; /* float */
676 };
677 
678 /*
679  * Messages the clients will send to the master.
680  * Internal representation on each client and the master.
681  * This is used when using the network distributed mode.
682  */
684  char m_host_name[100];
685  char m_client_name[100];
686  char m_stop_flag;
694  int m_mygen;
696  float m_cputime;
697  float m_walltime;
698  float m_actual;
699  long long m_child_flag;
700 };
701 
702 /*
703  * Messages that the clients will send to the master
704  * over the socket. This provides neutral format
705  * so that heterogeneous clusters will work.
706  * This is used when using the network distributed mode.
707  */
709  char m_host_name[100];
710  char m_client_name[100];
711  char m_client_number[20]; /* int */
712  char m_client_error[20]; /* int */
713  char m_stop_flag[4]; /* char +space */
714  char m_child_port[20]; /* int */
715  char m_child_async_port[20]; /* int */
716  char m_command[20]; /* int */
717  char m_testnum[20]; /* int */
718  char m_version[20]; /* int */
719  char m_mygen[20]; /* int */
720  char m_throughput[80]; /* float */
721  char m_cputime[80]; /* float */
722  char m_walltime[80]; /* float */
723  char m_actual[80]; /* float */
724  char m_child_flag[80]; /* long long */
725 };
726 
727 
728 /*
729  * Possible values for the commands sent to the master
730  */
731 #define R_CHILD_JOIN 1
732 #define R_STAT_DATA 2
733 #define R_FLAG_DATA 3
734 
735 /*
736  * Possible values for the master's commands sent to a client
737  *
738  * The R_FLAG_DATA is also used by the master to tell the
739  * client to update its flags.
740  */
741 #define R_JOIN_ACK 4
742 #define R_STOP_FLAG 5
743 #define R_TERMINATE 6
744 #define R_DEATH 7
745 
746 
747 /* These are the defaults for the processor. They can be
748  * over written by the command line options.
749  */
750 #define CACHE_LINE_SIZE 32
751 #define CACHE_SIZE ( 1024 * 1024 )
752 
753 
754 #define MEG (1024 * 1024)
755 
756 /*
757  * For stride testing use a prime number to avoid stripe
758  * wrap hitting the same spindle.
759  */
760 #define STRIDE 17
761 
762 
763 
764 /************************************************************************/
765 /* */
766 /* DEFINED CONSTANTS */
767 /* */
768 /* Never add a comment to the end of a #define. Some compilers will */
769 /* choke and fail the compile. */
770 /************************************************************************/
771 
772 /*
773  * Size of buffer for capturing the machine's name.
774  */
775 #define IBUFSIZE 100
776 /*
777  * How many I/Os before a non-uniform access.
778  */
779 #define DISRUPT 100
780 
781 /*
782  * Set the crossover size. This is where the small transfers
783  * are skipped to save time. There is an option to
784  * disable the skipping.
785  */
786 #define LARGE_REC 65536
787 
788 /* Default number of kilobytes in file */
789 #define KILOBYTES 512
790 
791 /* Default number of bytes in a record */
792 #define RECLEN 1024
793 
794 /* Default size of file in bytes*/
795 #define FILESIZE (KILOBYTES*1024)
796 
797 /* Default number of records */
798 #define NUMRECS FILESIZE/RECLEN
799 
800 #ifdef __bsdi__
801 /* At 8 Meg switch to large records */
802 #define CROSSOVER (8*1024)
803 /*maximum buffer size*/
804 #define MAXBUFFERSIZE (8*1024*1024)
805 #else
806 /* At 16 Meg switch to large records */
807 #define CROSSOVER (16*1024)
808 /* Maximum buffer size*/
809 #define MAXBUFFERSIZE (16*1024*1024)
810 #endif
811 
812 /* Maximum number of children. Threads/procs/clients */
813 #define MAXSTREAMS 256
814 
815 /* Minimum buffer size */
816 #define MINBUFFERSIZE 128
817 /* If things ran way too fast */
818 #define TOOFAST 10
819 /* Set the maximum number of types of tests */
820 #define MAXTESTS 12
821 /* Default fill pattern for verification */
822 #define PATTERN get_pattern();
823 #define PATTERN1 0xBB
824 /* Used for Excel internal tables */
825 #define MAX_X 100
826 /* Used for Excel internal tables */
827 #define MAX_Y 512
828 
829 #define USAGE "\tUsage: For usage information type iozone -h \n\n"
830 
831 
832 /* Maximum number of characters in filename */
833 #define MAXNAMESIZE 1000
834 
835 /*
836  * Define the typical output that the user will see on their
837  * screen.
838  */
839 #ifdef NO_PRINT_LLD
840 #ifdef HAVE_PREAD
841 #include <sys/times.h>
842 #if defined(HAVE_PREAD) && defined(HAVE_PREADV)
843 #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"
844 #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"
845 #define CONTROL_STRING3 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s%9s%9s%8s%9s\n"
846 #define CONTROL_STRING4 "%16s%8s%8s%8s%8s%10s\n"
847 #else
848 #define CONTROL_STRING1 "%16ld%8ld%8ld%8ld%8ld%8ld%8ld%8ld%8ld %8ld %8ld%8ld%8ld%9ld%9ld%8ld%10ld%9ld%10ld\n"
849 #define CONTROL_STRING2 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s%9s%9s%8s%9s%8s%9s%7s%10s\n"
850 #define CONTROL_STRING3 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s\n"
851 #define CONTROL_STRING4 "%16s%8s%8s%8s%8s%10s\n"
852 #endif
853 #else
854 #define CONTROL_STRING1 "%16ld%8ld%8ld%8ld%8ld%8ld%8ld%8ld%8ld %8ld %8ld%8ld%8ld%9ld%9ld\n"
855 #define CONTROL_STRING2 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s%9s%9s%8s%9s\n"
856 #define CONTROL_STRING3 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s%9s%9s%8s%9s\n"
857 #define CONTROL_STRING4 "%16s%8s%8s%8s%8s%10s\n"
858 #endif
859 #endif
860 
861 #ifndef NO_PRINT_LLD
862 #ifdef HAVE_PREAD
863 #include <sys/times.h>
864 #if defined(HAVE_PREAD) && defined(HAVE_PREADV)
865 #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"
866 #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"
867 #define CONTROL_STRING3 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s%9s%9s%8s%9s\n"
868 #define CONTROL_STRING4 "%16s%8s%8s%8s%8s%10s\n"
869 #else
870 #define CONTROL_STRING1 "%16lld%8ld%8ld%8ld%8ld%8ld%8ld%8ld%8ld %8ld %8ld%8ld%8ld%9ld%9ld%8ld%10ld%9ld%10ld\n"
871 #define CONTROL_STRING2 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s%9s%9s%8s%9s%8s%9s%7s%10s\n"
872 #define CONTROL_STRING3 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s%9s%9s%8s%9s\n"
873 #define CONTROL_STRING4 "%16s%8s%8s%8s%8s%10s\n"
874 #endif
875 #else
876 #define CONTROL_STRING1 "%16lld%8ld%8ld%8ld%8ld%8ld%8ld%8ld %8ld %8ld%8ld%8ld%8ld%9ld%9ld\n"
877 #define CONTROL_STRING2 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s%9s%9s%8s%9s\n"
878 #define CONTROL_STRING3 "%16s%8s%8s%8s%8s%10s%8s%8s%8s %8s %8s%9s%9s%8s%9s\n"
879 #define CONTROL_STRING4 "%16s%8s%8s%8s%8s%10s\n"
880 #endif
881 #endif
882 
883 /*
884  For 'auto mode', these defines determine the number of iterations
885  to perform for both the file size and the record length.
886 */
887 
888 /* Start with 64 kbyte minimum file size by default */
889 #define KILOBYTES_START 64
890 /* Default maximum file size. This is 512 Mbytes */
891 #define KILOBYTES_END (1024*512)
892 /* Default starting record size */
893 #define RECLEN_START 4096
894 /* Default maximum record size */
895 #define RECLEN_END (MAXBUFFERSIZE)
896 /* Multiplier for each itteration on file and record size */
897 #define MULTIPLIER 2
898 
899 /*
900  * Assign numeric values to each of the tests.
901  */
902 #define WRITER_TEST 0
903 #define READER_TEST 1
904 #define RANDOM_RW_TEST 2
905 #define REVERSE_TEST 3
906 #define REWRITE_REC_TEST 4
907 #define STRIDE_READ_TEST 5
908 #define FWRITER_TEST 6
909 #define FREADER_TEST 7
910 #define RANDOM_MIX_TEST 8
911 #ifdef HAVE_PREAD
912 #define PWRITER_TEST 9
913 #define PREADER_TEST 10
914 #endif /* HAVE_PREAD */
915 #ifdef HAVE_PREADV
916 #define PWRITEV_TEST 11
917 #define PREADV_TEST 12
918 #endif /* HAVE_PREADV */
919 
920 #define WRITER_MASK (1 << WRITER_TEST)
921 #define READER_MASK (1 << READER_TEST)
922 #define RANDOM_RW_MASK (1 << RANDOM_RW_TEST)
923 #define RANDOM_MIX_MASK (1 << RANDOM_MIX_TEST)
924 #define REVERSE_MASK (1 << REVERSE_TEST)
925 #define REWRITE_REC_MASK (1 << REWRITE_REC_TEST)
926 #define STRIDE_READ_MASK (1 << STRIDE_READ_TEST)
927 #define FWRITER_MASK (1 << FWRITER_TEST)
928 #define FREADER_MASK (1 << FREADER_TEST)
929 #ifdef HAVE_PREAD
930 #define PWRITER_MASK (1 << PWRITER_TEST)
931 #define PREADER_MASK (1 << PREADER_TEST)
932 #endif /* HAVE_PREAD */
933 #ifdef HAVE_PREADV
934 #define PWRITEV_MASK (1 << PWRITEV_TEST)
935 #define PREADV_MASK (1 << PREADV_TEST)
936 #endif /* HAVE_PREADV */
937 
938 /*
939  * child_stat->flag values and transitions
940  */
941 /* Parent initializes children to HOLD */
942 #define CHILD_STATE_HOLD 0
943 /* Child tells master when it's READY */
944 #define CHILD_STATE_READY 1
945 /* Parent tells child to BEGIN */
946 #define CHILD_STATE_BEGIN 2
947 /* Child tells parent that it's DONE */
948 #define CHILD_STATE_DONE 3
949 
950 #define MERSENNE
951 
952 /******************************************************************/
953 /* */
954 /* FUNCTION DECLARATIONS */
955 /* */
956 /******************************************************************/
957 char *initfile();
958 /*int pit_gettimeofday( struct timeval *, struct timezone *, char *, char *);*/
959 int pit_gettimeofday( );
960 static int openSckt( const char *, const char *, unsigned int );
961 static void pit( int, struct timeval *);
962 void mmap_end();
963 void alloc_pbuf();
964 void auto_test(); /* perform automatic test series */
965 void show_help(); /* show development help */
966 static double time_so_far(); /* time since start of program */
967 #ifdef unix
968 static double utime_so_far(); /* user time */
969 static double stime_so_far(); /* system time */
970 static double clk_tck(); /* Get clocks/tick */
971 static double cputime_so_far();
972 #else
973 #define cputime_so_far() time_so_far()
974 #endif
975 static double time_so_far1(); /* time since start of program */
976 void get_resolution();
977 void get_rusage_resolution();
978 void signal_handler(); /* clean up if user interrupts us */
979 void begin(); /* The main worker in the app */
980 void fetchit(); /* Prime on chip cache */
981 void purgeit(); /* Purge on chip cache */
982 void throughput_test(); /* Multi process throughput */
983 void multi_throughput_test(); /* Multi process throughput */
984 void prepage(); /* Pre-fault user buffer */
985 void get_date();
986 int get_pattern(); /* Set pattern based on version */
987 #ifdef HAVE_ANSIC_C
988 float do_compute(float); /* compute cycle simulation */
989 #else
990 float do_compute(); /* compute cycle simulation */
991 #endif
992 void write_perf_test(); /* write/rewrite test */
993 void fwrite_perf_test(); /* fwrite/refwrite test */
994 void fread_perf_test(); /* fread/refread test */
995 void read_perf_test(); /* read/reread test */
996 void mix_perf_test(); /* read/reread test */
997 void random_perf_test(); /* random read/write test */
998 void reverse_perf_test(); /* reverse read test */
999 void rewriterec_perf_test(); /* rewrite record test */
1000 void read_stride_perf_test(); /* read with stride test */
1001 #ifdef HAVE_PREAD
1002 void pread_perf_test(); /* pread/re-pread test */
1003 void pwrite_perf_test(); /* pwrite/re-pwrite test */
1004 #endif /* HAVE_PREAD */
1005 #ifdef HAVE_PREADV
1006 void preadv_perf_test(); /* preadv/re-preadv test */
1007 void pwritev_perf_test(); /* pwritev/re-pwritev test */
1008 #endif /* HAVE_PREADV */
1009 void store_dvalue(); /* Store doubles array */
1010 void dump_excel();
1011 void dump_throughput();
1012 int sp_start_child_send();
1014 #ifdef HAVE_ANSIC_C
1015 #if defined (HAVE_PREAD) && defined(_LARGEFILE64_SOURCE)
1016 ssize_t pwrite64();
1017 ssize_t pread64();
1018 #endif
1019 #if !defined(linux)
1020 char *getenv();
1021 char *inet_ntoa();
1022 int system();
1023 #endif
1024 void my_nap();
1025 void my_unap();
1026 int thread_exit();
1027 #ifdef ASYNC_IO
1028 size_t async_write();
1029 void async_release();
1030 int async_read();
1031 int async_read_no_copy();
1032 size_t async_write_no_copy();
1033 void end_async();
1034 void async_init();
1035 #else
1036 size_t async_write();
1037 size_t async_write_no_copy();
1038 void async_release();
1039 #endif
1040 void do_float();
1041 int create_xls();
1042 void close_xls();
1043 void do_label();
1044 int mylockf(int, int, int);
1045 int mylockr(int,int, int, off64_t, off64_t);
1046 int rand(void);
1047 void srand(unsigned int);
1048 int get_client_info(void);
1049 void exit(int);
1050 void find_remote_shell(char *);
1051 void find_external_mon(char *,char *);
1052 void start_monitor(char *);
1053 void stop_monitor(char *);
1054 void takeoff_cache();
1055 void del_cache();
1056 void fill_area(long long *, long long *, long long);
1057 void fill_buffer(char *,long long ,long long ,char, long long );
1058 void store_value(off64_t);
1059 void store_times(double, double);
1060 static double cpu_util(double, double);
1061 void dump_cputimes(void);
1062 void purge_buffer_cache(void);
1063 char *alloc_mem(long long,int);
1064 void *(thread_rwrite_test)(void *);
1065 void *(thread_write_test)(void *);
1066 void *(thread_fwrite_test)(void *);
1067 void *(thread_fread_test)(void *);
1068 void *(thread_read_test)(void*);
1069 #ifdef HAVE_PREAD
1070 void *(thread_pread_test)(void*);
1071 void *(thread_pwrite_test)(void*);
1072 #endif
1073 void *(thread_cleanup_test)(void*);
1074 void *(thread_cleanup_quick)(void*);
1075 void *(thread_ranread_test)(void *);
1076 void *(thread_mix_test)(void *);
1077 void *(thread_ranwrite_test)(void *);
1078 void *(thread_rread_test)(void *);
1079 void *(thread_reverse_read_test)(void *);
1080 void *(thread_stride_read_test)(void *);
1081 void *(thread_set_base)(void *);
1082 void *(thread_join)(long long, void *);
1083 void disrupt(int);
1084 #if defined(Windows)
1085 void disruptw(HANDLE);
1086 #endif
1087 long long get_traj(FILE *, long long *, float *, long);
1088 void create_temp(off64_t, long long );
1089 FILE *open_w_traj(void);
1090 FILE *open_r_traj(void);
1091 void traj_vers(void);
1092 void r_traj_size(void);
1093 long long w_traj_size(void);
1094 void init_file_sizes();
1096 void add_file_size(off64_t);
1099 void add_record_size(off64_t);
1101 void del_record_sizes( void );
1102 void hist_insert(double );
1103 void dump_hist(char *,int );
1104 void do_speed_check(int);
1105 #else
1106 void do_speed_check();
1107 #if !defined(linux)
1108 char *getenv();
1109 char *inet_ntoa();
1110 int system();
1111 #endif
1112 void my_nap();
1113 void my_unap();
1114 int thread_exit();
1115 void close_xls();
1116 void do_label();
1117 int create_xls();
1118 void do_float();
1119 #ifdef ASYNC_IO
1120 void async_release();
1121 size_t async_write();
1122 size_t async_write_no_copy();
1123 int async_read();
1124 int async_read_no_copy();
1125 #endif
1126 int mylockf();
1127 int mylockr();
1128 int rand();
1129 void srand();
1130 int get_client_info();
1131 void exit();
1132 void find_remote_shell();
1133 void traj_vers();
1134 void r_traj_size();
1135 long long w_traj_size();
1136 FILE *open_w_traj();
1137 FILE *open_r_traj();
1138 void create_temp();
1139 void fill_buffer();
1140 char *alloc_mem();
1141 void *(thread_rwrite_test)();
1142 void *(thread_write_test)();
1143 void *(thread_fwrite_test)();
1144 void *(thread_fread_test)();
1145 void *(thread_read_test)();
1146 void *(thread_cleanup_test)();
1147 void *(thread_ranread_test)();
1148 void *(thread_mix_test)();
1149 void *(thread_ranwrite_test)();
1150 void *(thread_rread_test)();
1151 void *(thread_reverse_read_test)();
1152 void *(thread_stride_read_test)();
1153 void *(thread_set_base)();
1154 void *(thread_join)();
1155 void disrupt();
1156 long long get_traj();
1157 void init_file_sizes();
1159 void add_file_size();
1160 void init_record_sizes();
1162 void add_record_size();
1163 void dump_cputimes();
1164 static double cpu_util();
1165 void del_record_sizes();
1166 void hist_insert();
1167 void dump_hist();
1168 #endif
1169 
1170 #ifdef _LARGEFILE64_SOURCE
1171 #define I_LSEEK(x,y,z) lseek64(x,(off64_t)(y),z)
1172 #define I_OPEN(x,y,z) open64(x,(int)(y),(int)(z))
1173 #define I_CREAT(x,y) creat64(x,(int)(y))
1174 #define I_FOPEN(x,y) fopen64(x,y)
1175 #define I_STAT(x,y) stat64(x,y)
1176 #ifdef HAVE_PREAD
1177 #define I_PREAD(a,b,c,d) pread64(a,b,(size_t)(c),(off64_t)(d))
1178 #define I_PWRITE(a,b,c,d) pwrite64(a,b,(size_t)(c),(off64_t)(d))
1179 #endif
1180 #define I_MMAP(a,b,c,d,e,f) mmap64((void *)(a),(size_t)(b),(int)(c),(int)(d),(int)(e),(off64_t)(f))
1181 #else
1182 #define I_LSEEK(x,y,z) lseek(x,(off_t)(y),z)
1183 #define I_OPEN(x,y,z) open(x,(int)(y),(int)(z))
1184 #define I_CREAT(x,y) creat(x,(int)(y))
1185 #define I_FOPEN(x,y) fopen(x,y)
1186 #define I_STAT(x,y) stat(x,y)
1187 #ifdef HAVE_PREAD
1188 #define I_PREAD(a,b,c,d) pread(a,b,(size_t)(c),(off_t)(d))
1189 #define I_PWRITE(a,b,c,d) pwrite(a,b,(size_t)(c),(off_t)(d))
1190 #endif
1191 #define I_MMAP(a,b,c,d,e,f) mmap((void *)(a),(size_t)(b),(int)(c),(int)(d),(int)(e),(off_t)(f))
1192 #endif
1193 
1194 
1195 /************************************************************************/
1196 /* The list of tests to be called. */
1197 /************************************************************************/
1198 void (*func[])() = {
1199  write_perf_test,
1207  mix_perf_test
1208 #ifdef HAVE_PREAD
1209  ,
1210  pwrite_perf_test,
1211  pread_perf_test
1212 #ifdef HAVE_PREADV
1213  ,
1214  pwritev_perf_test,
1215  preadv_perf_test
1216 #endif /* HAVE_PREADV */
1217 #endif /* HAVE_PREAD */
1218  };
1219 
1220 /*
1221 char *test_output[] = {" ",
1222  " ",
1223  " ",
1224  " ",
1225  " ",
1226  " ",
1227  " ",
1228  " ",
1229  " ",
1230  " ",
1231  " ",
1232  " \n" };
1233 */
1234 char *test_output[] = {" ",
1235  " ",
1236  " ",
1237  " ",
1238  " ",
1239  " ",
1240  " ",
1241  " ",
1242  "",
1243  " ",
1244  " ",
1245  " ",
1246  " ",
1247  " ",
1248  " ",
1249  " \n" };
1250 long long test_soutput[] = {2,2,2,1,1,1,2,2,2,2,2,2,2,2};
1251 
1252 
1253 /******************************************************************/
1254 /* */
1255 /* GLOBAL VARIABLES */
1256 /* */
1257 /*******************************************************************/
1258 
1259 /*
1260  * Set the size of the shared memory segment for the children
1261  * to put their results.
1262  */
1263 #define SHMSIZE ((( sizeof(struct child_stats) * MAXSTREAMS) )+4096 )
1264 /*
1265  * Pointer to the shared memory segment.
1266  */
1272 long long throughput_array[MAX_X]; /* Filesize & record size are constants */
1274 long long orig_size;
1275 long long max_x, max_y;
1276 unsigned long long goodkilos;
1278 long long goodrecl;
1279 off64_t offset = 0; /*offset for random I/O */
1280 off64_t offset64 = 0; /*offset for random I/O */
1284 int t_range[100];
1285 int t_count = 0;
1288 char *haveshm;
1289 extern int optind;
1291 int fd;
1294 long long res_prob,rec_prob;
1299 int dedup_mseed = 1;
1313 #ifdef Windows
1314 char *build_name = "Windows";
1315 #else
1316 char *build_name = NAME;
1317 #endif
1318 char imon_start[256],imon_stop[256];
1320 char trflag;
1322 char seq_mix;
1324 long long mint, maxt;
1330 struct runtime runtimes [MAX_X] [MAX_Y]; /* in parallel with report_array[][] */
1331 long long include_test[50];
1332 long long include_mask;
1333 char RWONLYflag, NOCROSSflag; /*auto mode 2 - kcollins 8-21-96*/
1334 char mfflag;
1337 #ifndef NO_THREADS
1339 #endif
1343 
1344 extern char *optarg;
1345 #ifndef __AIX__
1346 long long ret;
1347 #else
1348 short ret;
1349 #endif
1350 struct size_entry {
1351  struct size_entry *next;
1353 };
1358 
1359 char bif_filename [MAXNAMESIZE]; /* name of biff file */
1360 char filename [MAXNAMESIZE]; /* name of temporary file */
1361 char mountname [MAXNAMESIZE]; /* name of device */
1362 char dummyfile [MAXSTREAMS][MAXNAMESIZE]; /* name of dummy file */
1363 char dummyfile1 [MAXNAMESIZE]; /* name of dummy file */
1364 char *filearray[MAXSTREAMS]; /* array of file names */
1365 char tfile[] = "iozone";
1369 char *default_filename="iozone.tmp"; /*default name of temporary file*/
1371 char Cflag;
1372 char use_thread = 0;
1373 long long debug1=0;
1374 long long debug=0;
1375 unsigned long cache_size=CACHE_SIZE;
1377 long long *pstatus;
1384 long long xover = CROSSOVER;
1385 char *throughput_tests[] = {"Initial write","Rewrite","Read","Re-read",
1386  "Reverse Read","Stride read","Random read","Mixed workload","Random write","Pwrite","Pread","Fwrite","Fread"};
1387 char command_line[1024] = "\0";
1388 #ifdef unix
1389 double sc_clk_tck;
1390 #endif
1391 
1393 char **argvsave;
1394 char splash[80][80];
1397 char remote_shell[256];
1399 
1400 char pit_hostname[40];
1401 char pit_service[8];
1402 int junk;
1403 
1404 /*
1405  * Host ports used to listen, and handle errors.
1406  */
1407 #define HOST_LIST_PORT 20000
1408 #define HOST_ESEND_PORT (HOST_LIST_PORT+MAXSTREAMS)
1409 #define HOST_ASEND_PORT (HOST_ESEND_PORT+MAXSTREAMS)
1411 
1412 /*
1413  * Childs ports used to listen, and handle errors.
1414  */
1415 #define CHILD_ESEND_PORT (HOST_ASEND_PORT+MAXSTREAMS)
1416 #define CHILD_LIST_PORT (CHILD_ESEND_PORT+MAXSTREAMS)
1417 
1418 /* Childs async message port. Used for stop flag and terminate */
1419 #define CHILD_ALIST_PORT (CHILD_LIST_PORT+MAXSTREAMS)
1420 
1421 /* Ports for the network speed code */
1422 #define SP_CHILD_LISTEN_PORT 31000
1423 #define SP_CHILD_ESEND_PORT (SP_CHILD_LISTEN_PORT+10)
1424 #define SP_MASTER_LISTEN_PORT (SP_CHILD_ESEND_PORT+10)
1425 #define SP_MASTER_ESEND_PORT (SP_MASTER_LISTEN_PORT+10)
1426 #define SP_MASTER_RESULTS_PORT (SP_MASTER_ESEND_PORT+10)
1427 
1428 
1429 #define THREAD_WRITE_TEST 1
1430 #define THREAD_REWRITE_TEST 2
1431 #define THREAD_READ_TEST 3
1432 #define THREAD_REREAD_TEST 4
1433 #define THREAD_STRIDE_TEST 5
1434 #define THREAD_RANDOM_READ_TEST 6
1435 #define THREAD_RANDOM_WRITE_TEST 7
1436 #define THREAD_REVERSE_READ_TEST 8
1437 #define THREAD_RANDOM_MIX_TEST 9
1438 #define THREAD_PWRITE_TEST 10
1439 #define THREAD_PREAD_TEST 11
1440 #define THREAD_FWRITE_TEST 12
1441 #define THREAD_FREAD_TEST 13
1442 #define THREAD_CLEANUP_TEST 14
1443 
1444 /*
1445  * Child states that the master is tracking.
1446  * The master uses these to determine how to shutdown
1447  * the clients when some fool hits control-C.
1448  */
1449 #define C_STATE_ZERO 1
1450 #define C_STATE_WAIT_WHO 2
1451 #define C_STATE_WAIT_BARRIER 3
1452 
1453 
1454 int c_port,a_port; /* port number */
1455 int child_port; /* Virtualized due to fork */
1456 int child_async_port; /* Virtualized due to fork */
1457 int client_listen_pid; /* Virtualized due to fork */
1458 int master_join_count; /* How many children have joined */
1459 int l_sock,l_async_sock; /* Sockets for listening */
1460 char master_rcv_buf[4096]; /* Master's receive buffer */
1461 int master_listen_pid; /* Pid of the master's async listener proc */
1462 char master_send_buf[4096]; /* Master's send buffer */
1463 char child_rcv_buf[4096]; /* Child's receive buffer */
1464 char child_async_rcv_buf[4096]; /* Child's async recieve buffer */
1465 char child_send_buf[4096]; /* Child's send buffer */
1466 int child_send_socket; /* Child's send socket */
1467 int child_listen_socket; /* Child's listener socket */
1468 int child_listen_socket_async; /* Child's async listener socket */
1469 int master_send_socket; /* Needs to be an array. One for each child*/
1470 int master_send_sockets[MAXSTREAMS]; /* Needs to be an array. One for each child*/
1471 int master_send_async_sockets[MAXSTREAMS]; /* Needs to be an array. One for each child*/
1472 int master_listen_port; /* Master's listener port number */
1473 int master_listen_socket; /* Master's listener socket */
1474 int clients_found; /* Number of clients found in the client file */
1475 FILE *newstdin, *newstdout, *newstderr; /* used for debug in cluster mode.*/
1476 char toutput[20][20]; /* Used to help format the output */
1477 int toutputindex; /* Index to the current output line */
1478 int cdebug = 0; /* Use to turn on child/client debugging in cluster mode. */
1479 int mdebug = 0; /* Use to turn on master debug in cluster mode */
1480 int aggflag; /* Used to indicate constant aggregate data set size */
1481 struct sockaddr_in child_sync_sock, child_async_sock;
1482 
1483 /*
1484  * Change this whenever you change the message format of master or client.
1485  */
1486 int proto_version = 25;
1487 
1488 /******************************************************************************/
1489 /* Tele-port zone. These variables are updated on the clients when one is */
1490 /* using cluster mode. (-+m) */
1491 /* Do not touch these unless you have become one with the universe !! */
1492 /******************************************************************************/
1494 struct child_ident {
1495  char child_name[100];
1496  char workdir[200];
1497  char execute_path[200];
1498  char file_name[200];
1499  int state;
1507 char write_traj_filename [MAXNAMESIZE]; /* name of write telemetry file */
1508 char read_traj_filename [MAXNAMESIZE]; /* name of read telemetry file */
1511 char notruncate; /* turn off truncation of files */
1513 char verify = 1;
1514 int restf;
1515 char sverify = 1;
1516 char odsync = 0;
1518 char L_flag=0;
1521 int no_unlink = 0;
1522 int no_write = 0;
1524 int mygen;
1525 char MS_flag;
1529 long long chid;
1531 unsigned int pattern;
1532 long long stride = STRIDE;
1533 long long delay,purge,fetchon;
1535 long long reclen = RECLEN;
1536 long long delay_start,depth;
1537 VOLATILE char *stop_flag; /* Used to stop all children */
1540 long long rest_val;
1541 #if defined(Windows)
1542  HANDLE hand;
1543 #endif
1544 
1545 /******************************************************************************/
1546 /* End of Tele-port zone. */
1547 /******************************************************************************/
1548 
1549 
1550 /*
1551  * Prototypes
1552  * Sort of... Full prototypes break non-ansi C compilers. No protos is
1553  * a bit sloppy, so the compromise is this.
1554  */
1555 void child_send();
1556 int start_child_listen();
1559 void child_listen();
1560 void child_listen_async();
1561 void stop_child_send();
1562 void stop_child_listen();
1563 void cleanup_comm();
1564 void master_send();
1565 int start_master_send();
1566 int start_master_listen();
1567 int check_filename();
1568 void master_listen();
1569 void stop_master_send();
1570 void stop_master_listen();
1571 long long start_child_proc();
1572 int parse_client_line();
1573 void wait_dist_join();
1574 void tell_children_begin();
1576 void wait_for_master_go();
1577 void tell_master_ready();
1579 void tell_master_stats();
1580 void become_client();
1581 int pick_client();
1582 long long start_child_proc();
1583 int start_master_send();
1584 void child_listen();
1585 int start_child_listen();
1586 void stop_master_send();
1587 void stop_master_listen();
1588 void stop_child_send();
1589 void stop_child_listen();
1590 void master_send();
1591 void child_send();
1592 void master_listen();
1593 int start_master_listen();
1594 void child_remove_files();
1595 void terminate_child_async();
1596 void distribute_stop();
1597 void send_stop();
1598 void cleanup_children();
1599 
1600 
1601 /****************************************************************/
1602 /* */
1603 /* MAIN () */
1604 /* */
1605 /****************************************************************/
1606 
1607 int
1608 main(argc,argv)
1609 int argc;
1610 char **argv;
1611 {
1612 
1613  long long fileindx,i,tval;
1614  long long ind;
1615  int ret;
1616  FILE *pi;
1617  char reply[IBUFSIZE];
1618  unsigned char inp_pat;
1619  time_t time_run;
1620  char *port,*m,*subarg;
1621  int num_child1;
1622  int cret;
1623  int anwser,bind_cpu;
1624  char *evalue;
1625 
1626 
1627  anwser=bind_cpu=0;
1628  /* Used to make fread/fwrite do something better than their defaults */
1629  setvbuf( stdout, NULL, _IONBF, (size_t) NULL );
1630  setvbuf( stderr, NULL, _IONBF, (size_t) NULL );
1631 
1632  /* Save the master's name */
1633  gethostname(controlling_host_name,100);
1634 
1635  /* Let user activate mdebug or cdebug via environmental variables */
1636  evalue = (char *)NULL;
1637  evalue=(char *)getenv("CDEBUG");
1638  if(evalue)
1639  cdebug=atoi(evalue);
1640  evalue = (char *)NULL;
1641  evalue=(char *)getenv("MDEBUG");
1642  if(evalue)
1643  mdebug=atoi(evalue);
1644 
1645  srand(time(0));
1646  mygen=rand(); /* Pick a random generation number */
1647 
1648  /* Try to find the actual VM page size, if possible */
1649 #if defined (solaris) || defined (_HPUX_SOURCE) || defined (linux) || defined(IRIX) || defined (IRIX64)
1650 #ifndef __convex_spp
1651  page_size=getpagesize();
1652 #endif
1653 #endif
1654  /* Try to find the actual number of ticks per second */
1655 #ifdef unix
1656  sc_clk_tck = clk_tck();
1657 #endif
1658  for(ind=0;ind<MAXSTREAMS;ind++)
1659  filearray[ind]=(char *)tfile;
1660 
1661  /* base_time=(long)time_so_far(); */
1662  myid=(long long)getpid(); /* save the master's PID */
1663  /* get_resolution(); Get clock resolution */
1664  time_run = time(0); /* Start a timer */
1666 
1667  /*
1668  * Save the splash screen for later display. When in distributed network
1669  * mode this output does not get displayed on the clients.
1670  */
1671  sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n");
1672  sprintf(splash[splash_line++],"\t%s\n\t%s\n", THISVERSION,MODE);
1673  sprintf(splash[splash_line++],"\t\tBuild: %s \n\n",build_name);
1674  sprintf(splash[splash_line++],"\tContributors:William Norcott, Don Capps, Isom Crawford, Kirby Collins\n");
1675  sprintf(splash[splash_line++],"\t Al Slater, Scott Rhine, Mike Wisner, Ken Goss\n");
1676  sprintf(splash[splash_line++],"\t Steve Landherr, Brad Smith, Mark Kelly, Dr. Alain CYR,\n");
1677  sprintf(splash[splash_line++],"\t Randy Dunlap, Mark Montague, Dan Million, Gavin Brebner,\n");
1678  sprintf(splash[splash_line++],"\t Jean-Marc Zucconi, Jeff Blomberg, Benny Halevy, Dave Boone,\n");
1679  sprintf(splash[splash_line++],"\t Erik Habbinga, Kris Strecker, Walter Wong, Joshua Root,\n");
1680  sprintf(splash[splash_line++],"\t Fabrice Bacchella, Zhenghua Xue, Qin Li, Darren Sawyer.\n");
1681  sprintf(splash[splash_line++],"\t Ben England.\n\n");
1682  sprintf(splash[splash_line++],"\tRun began: %s\n",ctime(&time_run));
1683  argcsave=argc;
1684  argvsave=argv;
1685 
1686  signal(SIGINT, signal_handler); /* handle user interrupt */
1687  signal(SIGTERM, signal_handler); /* handle kill from shell */
1688 
1689  /********************************************************/
1690  /* Allocate and align buffer with beginning of the */
1691  /* on chip data cache. */
1692  /********************************************************/
1693 
1694  buffer = (char *) alloc_mem((long long)(MAXBUFFERSIZE + (2 * cache_size)),(int)0);
1695  if(buffer == 0) {
1696  perror("Memory allocation failed:");
1697  exit(1);
1698  }
1699 
1700 #ifdef _64BIT_ARCH_
1701  buffer = (char *) ((long long )(buffer + cache_size ) &
1702  ~(cache_size-1));
1703 #else
1704  buffer = (char *) ((long)(buffer + cache_size ) &
1705  ~((long)cache_size-1));
1706 #endif
1707  mainbuffer = buffer;
1708 
1709  /* de-dup input buf */
1710  buffer1 = (char *) alloc_mem((long long)(MAXBUFFERSIZE + (2 * cache_size)),(int)0);
1711  if(buffer1 == 0) {
1712  perror("Memory allocation failed:");
1713  exit(1);
1714  }
1715 
1716 #ifdef _64BIT_ARCH_
1717  buffer1 = (char *) ((long long )(buffer1 + cache_size ) &
1718  ~(cache_size-1));
1719 #else
1720  buffer1 = (char *) ((long)(buffer1 + cache_size ) &
1721  ~((long)cache_size-1));
1722 #endif
1723  dedup_ibuf = buffer1;
1725 
1726 #ifdef FOOB
1727  /* de-dup temp buf */
1728  buffer1 = (char *) alloc_mem((long long)(MAXBUFFERSIZE + (2 * cache_size)),(int)0);
1729  if(buffer1 == 0) {
1730  perror("Memory allocation failed:");
1731  exit(1);
1732  }
1733 
1734 #ifdef _64BIT_ARCH_
1735  buffer1 = (char *) ((long long )(buffer1 + cache_size ) &
1736  ~(cache_size-1));
1737 #else
1738  buffer1 = (char *) ((long)(buffer1 + cache_size ) &
1739  ~((long)cache_size-1));
1740 #endif
1741 #endif
1743 
1744  fetchon++; /* By default, prefetch the CPU cache lines associated with the buffer */
1745  strcpy(filename,default_filename); /* Init default filename */
1746  sprintf(dummyfile[0],"%s.DUMMY",default_filename);
1747  if(argc <=1){
1748  printf(USAGE);
1749  exit(255);
1750  }
1751  auto_mode = 0; /* Default is to disable auto mode */
1752  inp_pat = PATTERN; /* Init default pattern for verification */
1753  /* Fill the entire pattern variable with the same character */
1754  pattern = ((inp_pat << 24) | (inp_pat << 16) | (inp_pat << 8) | inp_pat);
1755 
1756  /*
1757  * Parse all of the options that the user specified.
1758  */
1759  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){
1760  switch(cret){
1761  case 'k': /* Async I/O with no bcopys */
1762  depth = (long long)(atoi(optarg));
1763  if(depth <0)
1764  depth=0;
1765  /*
1766  if(depth > 60)
1767  depth=60;
1768  */
1769 #ifdef NO_PRINT_LLD
1770  sprintf(splash[splash_line++],"\tPOSIX Async I/O (no bcopy). Depth %ld \n",depth);
1771 #else
1772  sprintf(splash[splash_line++],"\tPOSIX Async I/O (no bcopy). Depth %lld \n",depth);
1773 #endif
1774  no_copy_flag=1;
1775  async_flag++;
1776  k_flag++;
1777  break;
1778  case 'T': /* Switch to POSIX thread based */
1779 #ifndef NO_THREADS
1780  use_thread++;
1781 #else
1782  printf("\tThreads not supported in this version\n");
1783  exit(2);
1784 #endif
1785  break;
1786  case 'H': /* Use POSIX async_io */
1787  h_flag++;
1788  depth = (long long)(atoi(optarg));
1789  if(depth <0)
1790  depth=0;
1791  /*
1792  * Hmmm. many systems fail is strange ways when the maximum
1793  * number of async I/Os per user or proc is exceeded.
1794  */
1795  /*
1796  if(depth > 60)
1797  depth=60;
1798  */
1799 #ifdef NO_PRINT_LLD
1800  sprintf(splash[splash_line++],"\tPOSIX async I/O (with bcopy). Depth %ld\n",depth);
1801 #else
1802  sprintf(splash[splash_line++],"\tPOSIX async I/O (with bcopy). Depth %lld\n",depth);
1803 #endif
1804  async_flag++;
1805  break;
1806  case 'I': /* Use VXFS direct advisory or O_DIRECT from Linux or AIX , or O_DIRECTIO for TRU64 or Solaris directio */
1807 #ifdef VXFS
1808  direct_flag++;
1809  sprintf(splash[splash_line++],"\tVxFS advanced feature SET_CACHE, VX_DIRECT enabled\n");
1810  break;
1811 #endif
1812 #if ! defined(DONT_HAVE_O_DIRECT)
1813 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined(__FreeBSD__) || defined(solaris)
1814  direct_flag++;
1815  sprintf(splash[splash_line++],"\tO_DIRECT feature enabled\n");
1816  break;
1817 #endif
1818 #if defined(TRU64)
1819  direct_flag++;
1820  sprintf(splash[splash_line++],"\tO_DIRECTIO feature enabled\n");
1821  break;
1822 #endif
1823 #else
1824  break;
1825 #endif
1826 #if defined(Windows)
1827  sprintf(splash[splash_line++],"\tO_DIRECTIO feature not available in Windows version.\n");
1828  break;
1829 #endif
1830  case 'B': /* Use mmap file for test file */
1831  sprintf(splash[splash_line++],"\tUsing mmap files\n");
1832  mmapflag++;
1833  mmapnsflag++;
1834  break;
1835  case 'D': /* Use async msync mmap file */
1836  sprintf(splash[splash_line++],"\tUsing msync(MS_ASYNC) on mmap files\n");
1837  mmapflag++;
1838  mmapasflag++;
1839  mmapnsflag=0;
1840  break;
1841  case 'G': /* Use msync sync for mmap file */
1842  sprintf(splash[splash_line++],"\tUsing msync(MS_SYNC) on mmap files\n");
1843  mmapssflag++;
1844  mmapnsflag=0;
1845  break;
1846  case 'C': /* show children xfer counts */
1847  Cflag++;
1848  break;
1849  case 'Q': /* Enable output offset/latency files */
1850  sprintf(splash[splash_line++],"\tOffset/latency files enabled.\n");
1851  Q_flag++;
1852  break;
1853  case 'x': /* Disable stone_wall */
1854  sprintf(splash[splash_line++],"\tStonewall disabled\n");
1855  xflag++;
1856  break;
1857 
1858  case 'a': /* auto mode */
1859  fetchon=1;
1860  purge=0;
1861  multi_buffer=0;
1862  auto_mode = 1;
1863  aflag++;
1864  sprintf(splash[splash_line++],"\tAuto Mode\n");
1865  break;
1866  case 'c': /* Include close in timing */
1867  include_close++;
1868  sprintf(splash[splash_line++],"\tInclude close in write timing\n");
1869  break;
1870  case 'e': /* Include fsync in timing */
1871  include_flush++;
1872  sprintf(splash[splash_line++],"\tInclude fsync in write timing\n");
1873  break;
1874  case 'A': /* auto2 mode. Soon to go away. Please use -az */
1875  fetchon=1;
1876  purge=0;
1877  multi_buffer=0;
1878  auto_mode = 1;
1879  aflag++;
1880  sprintf(splash[splash_line++],"\tAuto Mode 2. This option is obsolete. Use -az -i0 -i1 \n");
1881  RWONLYflag++;
1882  NOCROSSflag++;
1883  include_tflag++; /* automatically set WRITER_TEST and READER_TEST */
1886  break;
1887  case 's': /* Set file size */
1888 #ifdef NO_PRINT_LLD
1889  sscanf(optarg,"%ld",&kilobytes64);
1890 #else
1891  sscanf(optarg,"%lld",&kilobytes64);
1892 #endif
1893  if(optarg[strlen(optarg)-1]=='k' ||
1894  optarg[strlen(optarg)-1]=='K'){
1895  ;
1896  }
1897  if(optarg[strlen(optarg)-1]=='m' ||
1898  optarg[strlen(optarg)-1]=='M'){
1899  kilobytes64 = kilobytes64 * 1024;
1900  }
1901  if(optarg[strlen(optarg)-1]=='g' ||
1902  optarg[strlen(optarg)-1]=='G'){
1903  kilobytes64 = kilobytes64 *1024 * 1024;
1904  }
1905  if(kilobytes64 <= 0)
1906  kilobytes64=512;
1907 
1909  max_file_size = (off64_t)s_range[s_count-1]; /* Make visable globally */
1910  min_file_size = (off64_t)s_range[0]; /* Make visable globally */
1911 
1912 #ifdef NO_PRINT_LLD
1913  sprintf(splash[splash_line++],"\tFile size set to %ld KB\n",kilobytes64);
1914 #else
1915  sprintf(splash[splash_line++],"\tFile size set to %lld KB\n",kilobytes64);
1916 #endif
1917  sflag++;
1918  break;
1919  case 'l': /* Set lower thread/proc limit */
1920  mint = (long long)(atoi(optarg));
1921  if(mint <= 0)
1922  {
1923  mint=1;
1924  num_child=1;
1925  }else
1926  num_child=mint;
1927  if(mint > (unsigned long long)MAXSTREAMS){
1928  printf("Invalid options: maximum streams for ");
1929  printf("throughput is MAXSTREAMS\n");
1930  exit(4);
1931  }
1932  lflag++;
1933  trflag++;
1934  if(Uflag)
1935  {
1936  printf("Can not run throughput tests with unmount & remounts.\n");
1937  exit(5);
1938  }
1939  break;
1940  case 'u': /* Set upper thread/proc limit */
1941  maxt = (long long)(atoi(optarg));
1942  if(maxt <= 0)
1943  maxt=1;
1944  if(maxt > MAXSTREAMS){
1945  printf("Invalid options: maximum streams for ");
1946  printf("throughput is MAXSTREAMS\n");
1947  exit(6);
1948  }
1949  uflag++;
1950  trflag++;
1951  if(Uflag)
1952  {
1953  printf("Can not run throughput tests with unmount & remounts.\n");
1954  exit(7);
1955  }
1956  break;
1957  case 'm': /* Use multiple buffers */
1958  fetchon=0;
1959  multi_buffer=1;
1960  mflag++;
1961  mbuffer = (char *) alloc_mem((long long)MAXBUFFERSIZE,(int)0);
1962  if(mbuffer == 0) {
1963  perror("Memory allocation failed:");
1964  exit(8);
1965  }
1966  sprintf(splash[splash_line++],"\tMulti_buffer. Work area %d bytes\n",
1967  MAXBUFFERSIZE);
1968  break;
1969  case 'M': /* Report machine name and OS */
1970  bzero(reply,sizeof(reply));
1971  pi=popen("uname -a", "r");
1972  if(pi == (FILE *)0)
1973  {
1974  sprintf(splash[splash_line++],"\n\tError using popen() on uname\n");
1975  sprintf(splash[splash_line++],"\t-M option suppressed.\n");
1976  }
1977  else
1978  {
1979  junk=fread(reply,IBUFSIZE-1,1,pi);
1980  pclose(pi);
1981  m=reply;
1982  while(*m) /* Strip new line */
1983  {
1984  if(*m=='\n')
1985  *m=0;
1986  else
1987  m++;
1988  }
1989  sprintf(splash[splash_line++],"\n\tMachine = %s\n",reply);
1990  }
1991  break;
1992 
1993  case 'P': /* Set beginning processor for binding. */
1994 #ifndef NO_THREADS
1995 #if defined(_HPUX_SOURCE) || defined(linux)
1996 #if defined(_HPUX_SOURCE)
1997  num_processors= pthread_num_processors_np();
1998 #else
1999  num_processors = sysconf(_SC_NPROCESSORS_ONLN);
2000 #endif
2001  begin_proc = atoi(optarg);
2002  if(begin_proc < 0)
2003  begin_proc=0;
2005  begin_proc=0;
2006  sprintf(splash[splash_line++],"\tBinding of processors beginning with %d \n",begin_proc);
2008 #else
2009  sprintf(splash[splash_line++],"\tProcessor binding not available in this version\n");
2010 #endif
2011 #endif
2012  break;
2013  case 'p': /* purge the processor cache */
2014  sprintf(splash[splash_line++],"\tPurge Mode On\n");
2015  fetchon=0;
2016  pflag++;
2017  purge=1;
2018  break;
2019  case 'h': /* show help */
2020  hflag++;
2021  show_help();
2022  exit(0);
2023  break;
2024  case 'E': /* Extended testing for pread/pwrite... */
2025  Eflag++;
2026  break;
2027  case 'R': /* Generate Excel compatible Report */
2028  Rflag++;
2029  sprintf(splash[splash_line++],"\tExcel chart generation enabled\n");
2030  break;
2031  case 'o': /* Open OSYNC */
2032  sprintf(splash[splash_line++],"\tSYNC Mode. \n");
2033  oflag++;
2034  break;
2035  case 'O': /* Report in Ops/sec instead of KB/sec */
2036  sprintf(splash[splash_line++],"\tOPS Mode. Output is in operations per second.\n");
2037  OPS_flag++;
2038  break;
2039  case 'N': /* Report in usec/op */
2040  sprintf(splash[splash_line++],"\tMicroseconds/op Mode. Output is in microseconds per operation.\n");
2041  MS_flag++;
2042  break;
2043  case 'V': /* Turn on Verify every byte */
2044  sverify=0;
2045  inp_pat = (char)(atoi(optarg));
2046  if(inp_pat == 0)
2047  inp_pat = PATTERN;
2048  pattern = ((inp_pat << 24) | (inp_pat << 16) | (inp_pat << 8)
2049  | inp_pat);
2050  verify=1;
2051  sprintf(splash[splash_line++],"\tVerify Mode. Pattern %x\n",pattern);
2052  sprintf(splash[splash_line++],"\tPerformance measurements are invalid in this mode.\n");
2053  break;
2054  case 'S': /* Set the processor cache size */
2055  cache_size = (long)(atoi(optarg)*1024);
2056  if(cache_size == 0)
2058  break;
2059  case 'L': /* Set processor cache line size */
2060  cache_line_size = (long)(atoi(optarg));
2061  if(cache_line_size == 0)
2063  break;
2064  case 'f': /* Specify the file name */
2065  if(mfflag) {
2066  printf("invalid options: -f and -F are mutually exclusive\n");
2067  exit(10);
2068  }
2069  fflag++;
2070  strcpy(filename,optarg);
2071  sprintf(dummyfile[0],"%s.DUMMY",optarg);
2072  break;
2073  case 'b': /* Specify the biff file name */
2074  Rflag++;
2075  bif_flag++;
2076  strcpy(bif_filename,optarg);
2077  break;
2078  case 'F': /* Specify multiple file names for -t */
2079  mfflag++;
2080  if(fflag) {
2081  printf("invalid options: -f and -F are mutually exclusive\n");
2082  exit(11);
2083  }
2084  if(!trflag) {
2085  printf("invalid options: must specify -t N before -F\n");
2086  exit(12);
2087  }
2088  optind--;
2089  for(fileindx=0;fileindx<maxt;fileindx++) {
2090  filearray[fileindx]=argv[optind++];
2091  if(optind > argc) {
2092 #ifdef NO_PRINT_LLD
2093  printf("invalid options: not enough filenames for %ld streams\n",num_child);
2094 #else
2095  printf("invalid options: not enough filenames for %lld streams\n",num_child);
2096 #endif
2097  exit(13);
2098  }
2099  }
2100  break;
2101  case 'r': /* Specify the record size to use */
2102  rflag++;
2103  reclen = ((long long)(atoi(optarg))*1024);
2104  if(optarg[strlen(optarg)-1]=='k' ||
2105  optarg[strlen(optarg)-1]=='K'){
2106  reclen = (long long)(1024 * atoi(optarg));
2107  }
2108  if(optarg[strlen(optarg)-1]=='m' ||
2109  optarg[strlen(optarg)-1]=='M'){
2110  reclen = (long long)(1024 * 1024 * atoi(optarg));
2111  }
2112  if(optarg[strlen(optarg)-1]=='g' ||
2113  optarg[strlen(optarg)-1]=='G'){
2114  reclen = (long long)(1024 * 1024 * 1024 *(long long)atoi(optarg));
2115  }
2116  if(reclen <= 0)
2117  reclen=(long long)4096;
2118 
2119  r_range[r_count++]=reclen;
2120  max_rec_size = (off64_t)r_range[r_count-1]; /* Make visable globally */
2121  min_rec_size = (off64_t)r_range[0]; /* Make visable globally */
2122 #ifdef NO_PRINT_LLD
2123  sprintf(splash[splash_line++],"\tRecord Size %ld KB\n",reclen/1024);
2124 #else
2125  sprintf(splash[splash_line++],"\tRecord Size %lld KB\n",reclen/1024);
2126 #endif
2127  if(max_rec_size > MAXBUFFERSIZE) {
2128 #ifdef NO_PRINT_LLD
2129  printf("Error: maximum record size %ld KB is greater than maximum buffer size %ld KB\n ",
2130  max_rec_size/1024, MAXBUFFERSIZE/1024);
2131 #else
2132  printf("Error: maximum record size %lld KB is greater than maximum buffer size %lld KB\n ",
2133  (long long)(max_rec_size/1024LL), (long long)MAXBUFFERSIZE/1024LL);
2134 #endif
2135  exit(23);
2136  }
2137  break;
2138  case 'J': /* Specify the compute time in millisecs */
2139  compute_time = (float)(atoi(optarg));
2140  compute_time=compute_time/1000;
2141  if(compute_time < (float)0)
2142  compute_time=(float)0;
2143  else
2144  compute_flag=1;
2145  jflag++;
2146  break;
2147  case 'j': /* Specify the stride in records */
2148  stride = (long long)(atoi(optarg));
2149  if(stride < 0)
2150  stride=0;
2151  stride_flag=1;
2152  break;
2153  case 't': /* Specify the number of children to run */
2154  num_child1=(atoi(optarg));
2155  num_child = (long long)num_child1;
2156  if(num_child > (long long)MAXSTREAMS) {
2157  printf("invalid options: maximum streams for throughput is MAXSTREAMS\n");
2158 #ifdef NO_PRINT_LLD
2159  printf("Numchild %ld %s\n",num_child,optarg);
2160 #else
2161  printf("Numchild %lld %s\n",num_child,optarg);
2162 #endif
2163  exit(14);
2164  }
2165  if(num_child <= 0)
2166  num_child = 8;
2167  if(num_child == 0)
2168  num_child=1;
2171  trflag++;
2172  if(Uflag)
2173  {
2174  printf("Can not run throughput tests with unmount & remounts.\n");
2175  exit(15);
2176  }
2177  break;
2178  case 'd': /* Specify the delay of children to run */
2179  delay_start = (long long)(atoi(optarg));
2180  if(delay_start < 0)
2181  delay_start=0;
2182  break;
2183  case 'i': /* Specify specific tests */
2184  tval=(long long)(atoi(optarg));
2185  if(tval < 0) tval=0;
2186 #ifndef HAVE_PREAD
2187  if(tval > RANDOM_MIX_TEST)
2188  {
2189  printf("\tPread tests not available on this operating system.\n");
2190  exit(183);
2191  }
2192 #endif
2193  if(tval > sizeof(func)/sizeof(char *))
2194  {
2195  tval=0;
2196  sprintf(splash[splash_line++],"\tSelected test not available on the version.\n");
2197  }
2198  include_test[tval]++;
2199  include_tflag++;
2200  break;
2201  case 'v': /* Show version information */
2202  for(ind=0; strlen(head1[ind]); ind++)
2203  {
2204  printf("%s\n", head1[ind]);
2205  }
2206  exit(0);
2207  break;
2208  case 'U': /* Specify the dev name for umount/mount*/
2209  Uflag++;
2210  strcpy(mountname,optarg);
2211  if(trflag)
2212  {
2213  printf("Can not run throughput tests with unmount & remounts.\n");
2214  exit(16);
2215  }
2216  break;
2217  case 'w': /* Do not unlink files */
2218  sprintf(splash[splash_line++],"\tSetting no_unlink\n");
2219  no_unlink = 1;
2220  break;
2221  case 'Z': /* Turn on the mmap and file I/O mixing */
2222  sprintf(splash[splash_line++],"\tEnable mmap & file I/O mixing.\n");
2223  mmap_mix = 1;
2224  break;
2225  case 'W': /* Read/Write with file locked */
2226  file_lock=1;
2227  sprintf(splash[splash_line++],"\tLock file when reading/writing.\n");
2228  break;
2229  case 'K': /* Cause disrupted read pattern */
2230  disrupt_flag=1;
2231  sprintf(splash[splash_line++],"\tDisrupted read patterns selected.\n");
2232  break;
2233  case 'X': /* Open write telemetry file */
2234  compute_flag=1;
2235  sverify=2; /* touch lightly */
2236  w_traj_flag=1;
2237  strcpy(write_traj_filename,optarg);
2238  traj_vers();
2239  w_traj_size();
2240  sprintf(splash[splash_line++],"\tUsing write telemetry file \"%s\"\n",
2243  if(w_traj_fd == (FILE *)0)
2244  exit(200);
2245  break;
2246  case 'Y': /* Open Read telemetry file */
2247  compute_flag=1;
2248  sverify=2; /* touch lightly */
2249  r_traj_flag=1;
2250  strcpy(read_traj_filename,optarg);
2251  sprintf(splash[splash_line++],"\tUsing read telemetry file \"%s\"\n",
2253  traj_vers();
2254  r_traj_size();
2256  if(r_traj_fd == (FILE*) 0)
2257  exit(200);
2258  break;
2259  case 'n': /* Set min file size for auto mode */
2260  nflag=1;
2262  if(optarg[strlen(optarg)-1]=='k' ||
2263  optarg[strlen(optarg)-1]=='K'){
2264  ;
2265  }
2266  if(optarg[strlen(optarg)-1]=='m' ||
2267  optarg[strlen(optarg)-1]=='M'){
2268  minimum_file_size = (long long)(1024 * atoi(optarg));
2269  }
2270  if(optarg[strlen(optarg)-1]=='g' ||
2271  optarg[strlen(optarg)-1]=='G'){
2272  minimum_file_size = (long long)(1024 * 1024 * (long long)atoi(optarg));
2273  }
2274  if(minimum_file_size < RECLEN_START/1024)
2276  if(minimum_file_size < page_size/1024)
2278 #ifdef NO_PRINT_LLD
2279  sprintf(splash[splash_line++],"\tUsing minimum file size of %ld kilobytes.\n",minimum_file_size);
2280 #else
2281  sprintf(splash[splash_line++],"\tUsing minimum file size of %lld kilobytes.\n",minimum_file_size);
2282 #endif
2283  break;
2284  case 'g': /* Set maximum file size for auto mode */
2285  gflag=1;
2287  if(optarg[strlen(optarg)-1]=='k' ||
2288  optarg[strlen(optarg)-1]=='K'){
2289  ;
2290  }
2291  if(optarg[strlen(optarg)-1]=='m' ||
2292  optarg[strlen(optarg)-1]=='M'){
2293  maximum_file_size = (long long)(1024 * atoi(optarg));
2294  }
2295  if(optarg[strlen(optarg)-1]=='g' ||
2296  optarg[strlen(optarg)-1]=='G'){
2297  maximum_file_size = (long long)(1024 * 1024 * (long long)atoi(optarg));
2298  }
2299  if(maximum_file_size < RECLEN_START/1024)
2301 #ifdef NO_PRINT_LLD
2302  sprintf(splash[splash_line++],"\tUsing maximum file size of %ld kilobytes.\n",maximum_file_size);
2303 #else
2304  sprintf(splash[splash_line++],"\tUsing maximum file size of %lld kilobytes.\n",maximum_file_size);
2305 #endif
2306  break;
2307  case 'z': /* Set no cross over */
2308  sprintf(splash[splash_line++],"\tCross over of record size disabled.\n");
2309  NOCROSSflag=1;
2310  break;
2311  case 'y': /* Set min record size for auto mode */
2312  yflag=1;
2313  min_rec_size = ((long long)(atoi(optarg))*1024);
2314  if(optarg[strlen(optarg)-1]=='k' ||
2315  optarg[strlen(optarg)-1]=='K'){
2316  min_rec_size = (long long)(1024 * atoi(optarg));
2317  }
2318  if(optarg[strlen(optarg)-1]=='m' ||
2319  optarg[strlen(optarg)-1]=='M'){
2320  min_rec_size = (long long)(1024 * 1024 * atoi(optarg));
2321  }
2322  if(optarg[strlen(optarg)-1]=='g' ||
2323  optarg[strlen(optarg)-1]=='G'){
2324  min_rec_size = (long long)(1024 * 1024 * 1024 *(long long)atoi(optarg));
2325  }
2326  if(min_rec_size <= 0)
2327  min_rec_size=(long long)RECLEN_START;
2328 #ifdef NO_PRINT_LLD
2329  sprintf(splash[splash_line++],"\tUsing Minimum Record Size %ld KB\n", min_rec_size/1024);
2330 #else
2331  sprintf(splash[splash_line++],"\tUsing Minimum Record Size %lld KB\n", min_rec_size/1024);
2332 #endif
2333  break;
2334  case 'q': /* Set max record size for auto mode */
2335  qflag=1;
2336  max_rec_size = ((long long)(atoi(optarg))*1024);
2337  if(optarg[strlen(optarg)-1]=='k' ||
2338  optarg[strlen(optarg)-1]=='K'){
2339  max_rec_size = (long long)(1024 * atoi(optarg));
2340  }
2341  if(optarg[strlen(optarg)-1]=='m' ||
2342  optarg[strlen(optarg)-1]=='M'){
2343  max_rec_size = (long long)(1024 * 1024 * atoi(optarg));
2344  }
2345  if(optarg[strlen(optarg)-1]=='g' ||
2346  optarg[strlen(optarg)-1]=='G'){
2347  max_rec_size = (long long)(1024 * 1024 * 1024 *(long long)atoi(optarg));
2348  }
2349  if(max_rec_size <= 0)
2350  min_rec_size=(long long)RECLEN_END;
2351  if(max_rec_size > MAXBUFFERSIZE) {
2352 #ifdef NO_PRINT_LLD
2353  printf("Error: maximum record size %ld KB is greater than maximum buffer size %ld KB\n ",
2354  max_rec_size/1024, MAXBUFFERSIZE/1024);
2355 #else
2356  printf("Error: maximum record size %lld KB is greater than maximum buffer size %lld KB\n ",
2357  (long long)(max_rec_size/1024LL), (long long)MAXBUFFERSIZE/1024LL);
2358 #endif
2359  exit(23);
2360  }
2361 #ifdef NO_PRINT_LLD
2362  sprintf(splash[splash_line++],"\tUsing Maximum Record Size %ld KB\n", max_rec_size/1024);
2363 #else
2364  sprintf(splash[splash_line++],"\tUsing Maximum Record Size %lld KB\n", max_rec_size/1024);
2365 #endif
2366  break;
2367 
2368  /*
2369  * The + operator is for the new extended options mechanism
2370  * Syntax is -+ followed by option leter, and if the optino
2371  * takes an operand then it is implemented below. An example
2372  * -+a arg is shown below. This is a sub option with an argument.
2373  * -+b is shown below. This is a sub option with no argument.
2374  */
2375  case '+':
2376  /* printf("Plus option = >%s<\n",optarg);*/
2377  switch (*((char *)optarg))
2378  {
2379  case 'a': /* Example: Has argument */
2380  subarg=argv[optind++];
2381  /* if(subarg!=(char *)0) Error checking. */
2382  /* printf("Plus option argument = >%s<\n",subarg);*/
2383  break;
2384  case 'b': /* Example: Does not have an argument */
2385  break;
2386  case 'c': /* Argument is the controlling host name */
2387  /* I am a client for distributed Iozone */
2388  subarg=argv[optind++];
2389  if(subarg==(char *)0)
2390  {
2391  printf("-+c takes an operand !!\n");
2392  exit(200);
2393  }
2394  strcpy(controlling_host_name,subarg);
2395  distributed=1;
2396  client_iozone=1;
2397  master_iozone=0;
2398  break;
2399  case 'h': /* Argument is the controlling host name */
2400  subarg=argv[optind++];
2401  if(subarg==(char *)0)
2402  {
2403  printf("-+h takes an operand !!\n");
2404  exit(200);
2405  }
2406  strcpy(controlling_host_name,subarg);
2407  sprintf(splash[splash_line++],"\tHostname = %s\n",controlling_host_name);
2408  break;
2409  case 'm': /* I am the controlling process for distributed Iozone */
2410  /* Does not have an argument */
2411  subarg=argv[optind++];
2412  if(subarg==(char *)0)
2413  {
2414  printf("-+m takes an operand. ( filename )\n");
2415  exit(201);
2416  }
2417  strcpy(client_filename,subarg);
2418  ret=get_client_info();
2419  if(ret <= 0)
2420  {
2421  printf("Error reading client file\n");
2422  exit(178);
2423  }
2425  distributed=1;
2426  master_iozone=1;
2427  client_iozone=0;
2428  sprintf(splash[splash_line++],"\tNetwork distribution mode enabled.\n");
2429  break;
2430  case 'N': /* turn off truncating the file before write test */
2431  notruncate = 1;
2432  break;
2433  case 'u': /* Set CPU utilization output flag */
2434  cpuutilflag = 1; /* only used if R(eport) flag is also set */
2436  sprintf(splash[splash_line++],"\tCPU utilization Resolution = %5.3f seconds.\n",cputime_res);
2437  sprintf(splash[splash_line++],"\tCPU utilization Excel chart enabled\n");
2438  break;
2439  case 's': /* Clients operate in silent mode. */
2440  /* Does not have an argument */
2441  silent=1;
2442  break;
2443  case 'd': /* Diagnostics mode */
2444  sprintf(splash[splash_line++],"\t>>> I/O Diagnostic mode enabled. <<<\n");
2445  sprintf(splash[splash_line++],"\tPerformance measurements are invalid in this mode.\n");
2446  diag_v=1;
2447  sverify=0;
2448  break;
2449  case 'x': /* Argument is the multiplier for rec size and file size */
2450  subarg=argv[optind++];
2451  if(subarg==(char *)0)
2452  {
2453  printf("-+c takes an operand !!\n");
2454  exit(200);
2455  }
2456  multiplier = atoi(subarg);
2457  if(multiplier <=1)
2458  multiplier = 2;
2459  break;
2460  case 'i': /* Argument is the host port */
2461  subarg=argv[optind++];
2462  if(subarg==(char *)0)
2463  {
2464  printf("-+i takes an operand !!\n");
2465  exit(200);
2466  }
2467  controlling_host_port = atoi(subarg);
2468  break;
2469  case 'p': /* Argument is the percentage read */
2470  subarg=argv[optind++];
2471  if(subarg==(char *)0)
2472  {
2473  printf("-+p takes an operand !!\n");
2474  exit(200);
2475  }
2476  pct_read = atoi(subarg);
2477  if(pct_read < 1)
2478  pct_read = 1;
2479  if(pct_read >=100)
2480  pct_read = 100;
2481  sprintf(splash[splash_line++],"\tPercent read in mix test is %d\n",pct_read);
2482  break;
2483  case 't': /* Speed code activated */
2484  speed_code=1;
2485  break;
2486 #if defined(_HPUX_SOURCE) || defined(linux) || defined(solaris)
2487  case 'r': /* Read sync too */
2488  read_sync=1;
2489  sprintf(splash[splash_line++],"\tRead & Write sync mode active.\n");
2490  break;
2491 #endif
2492 #ifndef NO_MADVISE
2493  case 'A': /* Argument is madvise selector */
2494  subarg=argv[optind++];
2495  if(subarg==(char *)0)
2496  {
2497  printf("-+A take an operand !!\n");
2498  exit(200);
2499  }
2500  advise_flag=1;
2501  advise_op=atoi(subarg);
2502  sprintf(splash[splash_line++],"\tMadvise enabled: %d\n",advise_op);
2503  break;
2504 #endif
2505  case 'n': /* Set no-retest */
2506  noretest = 1;
2507  sprintf(splash[splash_line++],"\tNo retest option selected\n");
2508  break;
2509  case 'k': /* Constant aggregate data set size */
2510  aggflag=1;
2511  break;
2512  case 'q': /* Argument is the rest time between tests in seconds */
2513  subarg=argv[optind++];
2514  if(subarg==(char *)0)
2515  {
2516  printf("-+q takes an operand !!\n");
2517  exit(200);
2518  }
2519  rest_val = (long long)atoi(subarg);
2520  if(rest_val <=0)
2521  rest_val = 0;
2522  restf=1;
2523  sprintf(splash[splash_line++],"\tDelay %d seconds between tests enabled.\n",atoi(subarg));
2524  break;
2525 #if defined(O_DSYNC)
2526  case 'D': /* O_DSYNC mode */
2527  sprintf(splash[splash_line++],"\t>>> O_DSYNC mode enabled. <<<\n");
2528  odsync=1;
2529  break;
2530 #endif
2531  case 'l': /* Record locking mode */
2532  sprintf(splash[splash_line++],"\t>>> Record locking mode enabled. <<<\n");
2533  rlocking=1;
2534  break;
2535  case 'L': /* Record locking mode shared files*/
2536  sprintf(splash[splash_line++],"\t>>> Record locking, shared file mode enabled. <<<\n");
2537  share_file=1;
2538  rlocking=1;
2539  break;
2540  case 'V': /* No Record locking shared files*/
2541  sprintf(splash[splash_line++],"\t>>> Shared file mode enabled. <<<\n");
2542  share_file=1;
2543  break;
2544  case 'B': /* Sequential mix */
2545  sprintf(splash[splash_line++],"\t>>> Sequential Mixed workload. <<<\n");
2546  seq_mix=1;
2547  break;
2548  /* Use an existing user file, that does
2549  not contain Iozone's pattern. Use file
2550  for testing, but read only, and no
2551  delete at the end of the test. Also,
2552  no pattern verification, but do touch
2553  the pages. */
2554  case 'E':
2555  sprintf(splash[splash_line++],"\t>>> No Verify mode. <<<\n");
2556  sverify=2;
2557  no_unlink=1;
2558  no_write=1;
2559  break;
2560  case 'T': /* Time stamps on */
2561  L_flag=1;
2562  break;
2563  case 'X': /* Short circuit test mode */
2564  X_flag = 1;
2565  sverify=1;
2566  verify=1;
2567  inp_pat = 0xBB;
2568  pattern = ((inp_pat << 24) |
2569  (inp_pat << 16) | (inp_pat << 8) |
2570  inp_pat);
2571  sprintf(splash[splash_line++],"\tShort circuit mode. For\n");
2572  sprintf(splash[splash_line++],"\t filesystem development testing ONLY !\n");
2573  break;
2574  case 'Z': /* Compatibility mode for 0xA5 */
2575  Z_flag = 1;
2576  sverify=1;
2577  verify=1;
2578  inp_pat = 0xA5;
2579  pattern = ((inp_pat << 24) |
2580  (inp_pat << 16) | (inp_pat << 8) |
2581  inp_pat);
2582  sprintf(splash[splash_line++],"\tUsing old data sets.\n");
2583  sprintf(splash[splash_line++],"\t Performance measurements may be invalid in this\n");
2584  sprintf(splash[splash_line++],"\t mode due to published hack.\n");
2585  break;
2586 #if defined(Windows)
2587  case 'U': /* Windows only Unbufferd I/O */
2588  unbuffered=1;
2589  sprintf(splash[splash_line++],"\tUnbuffered Windows API usage. >>> Very Experimental <<<\n");
2590  break;
2591 #endif
2592  case 'K': /* Sony special for manual control of test 8 */
2593  subarg=argv[optind++];
2594  if(subarg==(char *)0)
2595  {
2596  printf("-+K takes an operand !!\n");
2597  exit(204);
2598  }
2599  Kplus_readers = (int)atoi(subarg);
2600  if(Kplus_readers <=0)
2601  Kplus_readers = 1;
2602  Kplus_flag=1;
2603  sprintf(splash[splash_line++],"\tManual control of test 8. >>> Very Experimental. Sony special <<<\n");
2604  break;
2605  case 'w': /* Argument is the percent of dedup */
2606  /* Sets size of dedup region across files */
2607  subarg=argv[optind++];
2608  if(subarg==(char *)0)
2609  {
2610  printf("-+w takes an operand !!\n");
2611  exit(200);
2612  }
2613  dedup = atoi(subarg);
2614  if(dedup <=0)
2615  dedup = 0;
2616  if(dedup >100)
2617  dedup = 100;
2618  sprintf(splash[splash_line++],"\tDedup activated %d percent.\n",dedup);
2619  break;
2620  case 'y': /* Argument is the percent of interior dedup */
2621  /* Sets size of dedup region within and across files */
2622  subarg=argv[optind++];
2623  if(subarg==(char *)0)
2624  {
2625  printf("-+y takes an operand !!\n");
2626  exit(200);
2627  }
2628  dedup_interior = atoi(subarg);
2629  if(dedup_interior <0)
2630  dedup_interior = 0;
2631  if(dedup_interior >100)
2632  dedup_interior = 100;
2633  sprintf(splash[splash_line++],"\tDedupe within & across %d percent.\n",dedup_interior);
2634  break;
2635  case 'C': /* Argument is the percent of dedupe within & !across */
2636  /* Sets size of dedup region within and !across files */
2637  subarg=argv[optind++];
2638  if(subarg==(char *)0)
2639  {
2640  printf("-+C takes an operand !!\n");
2641  exit(200);
2642  }
2643  dedup_compress = atoi(subarg);
2644  if(dedup_compress <0)
2645  dedup_compress = 0;
2646  if(dedup_compress >100)
2647  dedup_compress = 100;
2648  sprintf(splash[splash_line++],"\tDedupe within %d percent.\n",dedup_compress);
2649  break;
2650  case 'S': /* Argument is the seed for dedup */
2651  subarg=argv[optind++];
2652  if(subarg==(char *)0)
2653  {
2654  printf("-+S takes an operand !!\n");
2655  exit(200);
2656  }
2657  dedup_mseed = atoi(subarg);
2658  if(dedup_mseed ==0)
2659  dedup_mseed = 1;
2660  sprintf(splash[splash_line++],"\tDedup manual seed %d .\n",dedup_mseed);
2661  break;
2662  case 'H': /* Argument is hostname of the PIT */
2663  subarg=argv[optind++];
2664  if(subarg==(char *)0)
2665  {
2666  printf("-+H takes operand !!\n");
2667  exit(200);
2668  }
2669  strcpy(pit_hostname,subarg);
2670  sprintf(splash[splash_line++],"\tPIT_host %s\n",pit_hostname);
2671 
2672  break;
2673  case 'P': /* Argument is port of the PIT */
2674  subarg=argv[optind++];
2675  if(subarg==(char *)0)
2676  {
2677  printf("-+P takes operand !!\n");
2678  exit(200);
2679  }
2680  strcpy(pit_service,subarg);
2681  sprintf(splash[splash_line++],"\tPIT_port %s\n",pit_service);
2682  break;
2683  case 'z': /* Enable hist summary*/
2684  hist_summary=1;
2685  sprintf(splash[splash_line++],"\tHistogram summary enabled.\n");
2686  break;
2687  case 'O': /* Argument is the Op rate */
2688  subarg=argv[optind++];
2689  if(subarg==(char *)0)
2690  {
2691  printf("-+O takes an operand !!\n");
2692  exit(200);
2693  }
2694  op_rate = atoi(subarg);
2695  if(op_rate <= 0)
2696  op_rate = 1;
2697  op_rate_flag = 1;
2698  sprintf(splash[splash_line++],"\tRate control active %d Ops/sec .\n",op_rate);
2699  break;
2700  default:
2701  printf("Unsupported Plus option -> %s <-\n",optarg);
2702  exit(255);
2703  break;
2704  }
2705  break;
2706  default:
2707  printf("Unsupported option -> %s <-\n",optarg);
2708  exit(255);
2709  }
2710  }
2711  base_time=(long)time_so_far();
2712  get_resolution(); /* Get clock resolution */
2713  if(speed_code)
2714  {
2716  exit(0);
2717  }
2718  if(r_count > 1)
2719  {
2720  aflag=1;
2721  rflag=0;
2722  NOCROSSflag=1;
2723  }
2724  if(s_count > 1)
2725  {
2726  aflag=1;
2727  sflag=0;
2728  NOCROSSflag=1;
2729  }
2730  /*
2731  * If not in silent mode then display the splash screen.
2732  */
2733  for(i=0;i<splash_line;i++)
2734  if(!silent) printf("%s",splash[i]);
2735  /*
2736  * Save the command line for later
2737  */
2739 
2740  if(pflag) /* Allocate after cache_size is set */
2741  {
2742  alloc_pbuf();
2743  }
2744  if(distributed && master_iozone)
2745  {
2746  if(maxt > clients_found)
2747  {
2748  printf("You can not specify more threads/processes than you have in the client file list\n");
2749  exit(202);
2750  }
2751  }
2752 
2753  if(!OPS_flag && !MS_flag)
2754  {
2755  if(!silent) printf("\tOutput is in Kbytes/sec\n");
2756  }
2757  if (min_rec_size > max_rec_size) {
2758 #ifdef NO_PRINT_LLD
2759  printf("Error: minimum record size %ld KB is greater than maximum record size %ld KB\n ",
2760  min_rec_size/1024, max_rec_size/1024);
2761 #else
2762  printf("Error: minimum record size %lld KB is greater than maximum record size %lld KB\n ",
2763  min_rec_size/1024, max_rec_size/1024);
2764 #endif
2765  exit(23);
2766  }
2769  /*
2770  * No telemetry files... just option selected
2771  */
2772  if(compute_flag && jflag && !(r_traj_flag || w_traj_flag))
2773  if(!silent) printf("\tCompute time %f seconds for reads and writes.\n",compute_time);
2774  /*
2775  * Read telemetry file and option selected
2776  */
2778  {
2779  if(r_traj_items==3)
2780  {
2781  if(!silent) printf("\tCompute time from telemetry files for reads.\n");
2782  }
2783  else
2784  {
2785  if(jflag)
2786  if(!silent) printf("\tCompute time %f seconds for reads.\n",compute_time);
2787  }
2788  if(jflag)
2789  if(!silent) printf("\tCompute time %f seconds for writes.\n",compute_time);
2790  }
2791  /*
2792  * Write telemetry file and option selected
2793  */
2795  {
2796  if(w_traj_items==3)
2797  {
2798  if(!silent) printf("\tCompute time from telemetry files for writes.\n");
2799  }
2800  else
2801  {
2802  if(jflag)
2803  if(!silent) printf("\tCompute time %f seconds for writes.\n",compute_time);
2804  }
2805  if(jflag)
2806  if(!silent) printf("\tCompute time %f seconds for reads.\n",compute_time);
2807  }
2809  {
2810  if(r_traj_items==3)
2811  {
2812  if(!silent) printf("\tCompute time from telemetry files for reads.\n");
2813  }
2814  else
2815  {
2816  if(!silent) printf("\tCompute time %f seconds for reads.\n",compute_time);
2817  }
2818  if(w_traj_items==3)
2819  {
2820  if(!silent) printf("\tCompute time from telemetry files for writes.\n");
2821  }
2822  else
2823  {
2824  if(!silent) printf("\tCompute time %f seconds for writes.\n",compute_time);
2825  }
2826  }
2828  {
2829  if(r_traj_items==3)
2830  {
2831  if(!silent) printf("\tCompute time from telemetry files for reads.\n");
2832  }
2833  else
2834  {
2835  if(!silent) printf("\tNo compute time for reads.\n");
2836  }
2837 
2838  if(w_traj_items==3)
2839  {
2840  if(!silent) printf("\tCompute time from telemetry files for writes.\n");
2841  }
2842  else
2843  {
2844  if(!silent) printf("\tNo compute time for writes.\n");
2845  }
2846  }
2847 
2848  /* Enforce only write,rewrite,read,reread */
2849  if(w_traj_flag || r_traj_flag)
2850  {
2851  for(i=2;i<sizeof(func)/sizeof(char *);i++)
2852  {
2853  if(seq_mix && (i==8))
2854  ;
2855  else
2856  include_test[i] = 0;
2857  }
2858  }
2859 
2860  if(r_traj_flag)
2861  {
2862  if(include_test[READER_TEST] == 0)
2863  {
2866  include_tflag=1;
2867  }
2868  }
2869  if(w_traj_flag)
2870  {
2871  if(include_test[WRITER_TEST] == 0)
2872  {
2874  include_tflag=1;
2875  }
2876  }
2877  if(w_traj_flag && w_traj_fsize != 0)
2879  if(r_traj_flag && r_traj_fsize != 0)
2881 
2882  if( sverify==0 && (w_traj_flag || r_traj_flag))
2883  {
2884  printf("\n\tFull verification not supported in telemetry mode.\n\n");
2885  exit(17);
2886  }
2887  ;
2889  {
2890  printf("\n\tDisrupt not supported in telemetry mode.\n\n");
2891  exit(17);
2892  }
2893  if(aflag &&(w_traj_flag || r_traj_flag) )
2894  {
2895  printf("\n\tAuto mode not supported in telemetry mode.\n");
2896  printf("\tTry: -i 0 -i 1 \n\n");
2897  exit(17);
2898  }
2899  if(sflag && w_traj_flag )
2900  {
2901  printf("\n\tSize of file is determined by telemetry file.\n\n");
2902  exit(17);
2903  }
2904  if(rflag && w_traj_flag )
2905  {
2906  printf("\n\tRecord size of file is determined by telemetry file.\n\n");
2907  exit(17);
2908  }
2909  if(stride_flag && (w_traj_flag || r_traj_flag))
2910  {
2911  printf("\n\tStride size is determined by telemetry file.\n\n");
2912  exit(17);
2913  }
2914  if(trflag && MS_flag)
2915  {
2916  printf("\n\tMicrosecond mode not supported in throughput mode.\n\n");
2917  exit(17);
2918  }
2919  if (trflag /* throughput mode, don't allow auto-mode options: */
2920  && (auto_mode || aflag || yflag || qflag || nflag || gflag))
2921  {
2922  printf("\n\tCan not mix throughput mode and auto-mode flags.\n\n");
2923  exit(17);
2924  }
2925  if(fflag && trflag)
2926  {
2927  printf("\n\tYou must use -F when using multiple threads or processes.\n\n");
2928  exit(17);
2929  }
2930  if(aflag && mfflag)
2931  {
2932  printf("\n\tYou must use -f when using auto mode.\n\n");
2933  exit(17);
2934  }
2935  if(async_flag && mmapflag)
2936  {
2937  printf("\n\tSorry ... Only mmap or async but not both\n\n");
2938  exit(18);
2939  }
2940 #ifndef ASYNC_IO
2941  if(async_flag)
2942  {
2943  printf("\n\tSorry ... This version does not support async I/O\n\n");
2944  exit(19);
2945  }
2946 #endif
2947  if(no_write)
2948  {
2949  if(!include_tflag)
2950  {
2951  printf("You must specify which tests ( -i # ) when using -+E\n");
2952  exit(19);
2953  }
2954  }
2955  if(include_tflag)
2956  {
2957  for(i=0;i<sizeof(func)/sizeof(char *);i++)
2958  if(include_test[i])
2959  include_mask|=(long long)(1<<i);
2960  /* printf(">> %llx",include_mask); HERE */
2961  }
2962  if(no_write) /* Disable if any writer would disturbe existing file */
2963  {
2964  if(include_test[0] || include_test[4] ||
2965  include_test[6] || include_test[8] || include_test[9] ||
2966  include_test[11])
2967  {
2968  printf("You must disable any test that writes when using -+E\n");
2969  exit(20);
2970  }
2971  }
2972  if(no_write) /* User must specify the existing file name */
2973  {
2974  if(!(fflag | mfflag))
2975  {
2976  printf("You must use -f or -F when using -+E\n");
2977  exit(20);
2978  }
2979  }
2980  if(h_flag && k_flag)
2981  {
2982  printf("\n\tCan not do both -H and -k\n");
2983  exit(20);
2984  }
2985  if((dedup | dedup_interior) && diag_v)
2986  {
2987  printf("\n\tCan not do both -+d and -+w\n");
2988  exit(20);
2989  }
2990 
2991  if(!aflag && !rflag)
2993 
2995  if(!silent) printf("\tTime Resolution = %1.6f seconds.\n",time_res);
2996 #ifdef NO_PRINT_LLD
2997  if(!silent) printf("\tProcessor cache size set to %ld Kbytes.\n",cache_size/1024);
2998  if(!silent) printf("\tProcessor cache line size set to %ld bytes.\n",cache_line_size);
2999  if(!silent) printf("\tFile stride size set to %ld * record size.\n",stride);
3000 #else
3001  if(!silent) printf("\tProcessor cache size set to %ld Kbytes.\n",cache_size/1024);
3002  if(!silent) printf("\tProcessor cache line size set to %ld bytes.\n",cache_line_size);
3003  if(!silent) printf("\tFile stride size set to %lld * record size.\n",stride);
3004 #endif
3005  if(!rflag)
3006  reclen=(long long)4096;
3007 
3008  if(uflag && !lflag)
3009  num_child=mint = 1;
3010  if(lflag && !uflag)
3011  maxt = mint;
3012  if(use_thread)
3013  port="thread";
3014  else
3015  port="process";
3016  if(lflag || uflag){
3017 #ifdef NO_PRINT_LLD
3018  if(!silent) printf("\tMin %s = %ld \n",port,mint);
3019  if(!silent) printf("\tMax %s = %ld \n",port,maxt);
3020 #else
3021  if(!silent) printf("\tMin %s = %lld \n",port,mint);
3022  if(!silent) printf("\tMax %s = %lld \n",port,maxt);
3023 #endif
3024  }
3025  if(trflag)
3026  {
3027  if(num_child > 1)
3028  {
3029  if(use_thread)
3030  {
3031  port="threads";
3032  }
3033  else
3034  {
3035  port="processes";
3036  }
3037  }
3038 
3039 #ifdef NO_PRINT_LLD
3040  if(!silent) printf("\tThroughput test with %ld %s\n", num_child,port);
3041 #else
3042  if(!silent) printf("\tThroughput test with %lld %s\n", num_child,port);
3043 #endif
3044  }
3045  numrecs64 = (long long)(kilobytes64*1024)/reclen;
3046  if (reclen > (long long)MAXBUFFERSIZE) {
3047 #ifdef NO_PRINT_LLD
3048  printf("Error: Maximum record length is %ld bytes\n",
3049  MAXBUFFERSIZE);
3050 #else
3051  printf("Error: Maximum record length is %lld bytes\n",
3052  (long long)MAXBUFFERSIZE);
3053 #endif
3054  exit(21);
3055  }
3056  if (reclen < (long long)MINBUFFERSIZE) {
3057 #ifdef NO_PRINT_LLD
3058  printf("Error: Minimum record length is %ld bytes\n",
3059  MINBUFFERSIZE);
3060 #else
3061  printf("Error: Minimum record length is %lld bytes\n",
3062  (long long)MINBUFFERSIZE);
3063 #endif
3064  exit(22);
3065  }
3066  /* Only bzero or fill that which you will use. The buffer is very large */
3067  if(verify )
3068  {
3069  fill_buffer((char *)buffer,l_min(reclen,(long long)cache_size),(long long)pattern,(char)sverify,(long long)0);
3070  if(pflag)
3071  fill_buffer((char *)pbuffer,l_min(reclen,(long long)cache_size),(long long)pattern,(char)sverify,(long long)0);
3072  if(mflag)
3073  fill_buffer((char *)mbuffer,l_min(reclen,(long long)cache_size),(long long)pattern,(char)sverify,(long long)0);
3074  }
3075  else
3076  {
3077  bzero(buffer,(size_t)l_min(reclen,(long long)cache_size));
3078  }
3079 
3080 #ifndef NO_THREADS
3081 #if defined( _HPUX_SOURCE ) || defined ( linux )
3082  if(ioz_processor_bind)
3083  {
3084  bind_cpu=begin_proc;
3085 #if defined( _HPUX_SOURCE )
3086  pthread_processor_bind_np(PTHREAD_BIND_FORCED_NP,
3087  (pthread_spu_t *)&anwser, (pthread_spu_t)bind_cpu, pthread_self());
3088 #else
3089  cpu_set_t cpuset;
3090  CPU_ZERO(&cpuset);
3091  CPU_SET(bind_cpu, &cpuset);
3092 
3093  pthread_setaffinity_np(pthread_self(), sizeof(cpuset),&cpuset);
3094 #endif
3095  my_nap(40); /* Switch to new cpu */
3096  }
3097 #endif
3098 #endif
3100  if(trflag){
3102  goto out;
3103  }
3104  if(trflag && (mint == maxt)){
3105  auto_mode=0;
3106  throughput_test();
3107  goto out;
3108  }
3109  if (aflag) {
3110  print_header();
3111  auto_test();
3112  goto out;
3113  }
3114  print_header();
3115  (void) begin(kilobytes64,reclen);
3116 out:
3117  if(r_traj_flag)
3118  fclose(r_traj_fd);
3119  if(w_traj_flag)
3120  fclose(w_traj_fd);
3121  if (!no_unlink)
3122  {
3123  if(check_filename(dummyfile[0]))
3124  unlink(dummyfile[0]); /* delete the file */
3125  }
3126  if(!silent) printf("\niozone test complete.\n");
3127  if(res_prob)
3128  {
3129  printf("Timer resolution is poor. Some small transfers may have \n");
3130  printf("reported inaccurate results. Sizes %ld Kbytes and below.\n",
3131  (long)(rec_prob/(long long)1024));
3132  }
3133 
3134  if(Rflag && !trflag){
3135  dump_excel();
3136  }
3137  return(0);
3138 }
3139 
3140 #ifdef HAVE_ANSIC_C
3141 void
3142 record_command_line(int argc, char **argv)
3143 #else
3144 void
3146 int argc;
3147 char **argv;
3148 #endif
3149 {
3150  int ix, len = 0;
3151 
3152  /* print and save the entire command line */
3153  if(!silent) printf("\tCommand line used:");
3154  for (ix=0; ix < argc; ix++) {
3155  if(!silent) printf(" %s", argv[ix]);
3156  if ((len + strlen(argv[ix])) < sizeof(command_line)) {
3157  strcat (command_line, argv[ix]);
3158  strcat (command_line, " ");
3159  len += strlen(argv[ix]) + 1;
3160  }
3161  else {
3162  printf ("Command line too long to save completely.\n");
3163  break;
3164  }
3165  }
3166  if(!silent) printf("\n");
3167 }
3168 
3169 /*************************************************************************/
3170 /* BEGIN() */
3171 /* This is the main work horse. It is called from main and from */
3172 /* auto_test. The caller provides the size of file and the record length.*/
3173 /*************************************************************************/
3174 #ifdef HAVE_ANSIC_C
3175 void
3176 begin(off64_t kilos64,long long reclength)
3177 #else
3178 void
3179 begin(kilos64,reclength)
3180 off64_t kilos64;
3181 long long reclength;
3182 #endif
3183 {
3184  long long num_tests,test_num,i,j;
3185  long long data1[MAXTESTS], data2[MAXTESTS];
3186  num_tests = sizeof(func)/sizeof(char *);
3187 #if defined(HAVE_PREAD)
3188  if(!Eflag)
3189  {
3190 #if defined(HAVE_PREAD) && defined(HAVE_PREADV)
3191  num_tests -= 4;
3192 #else
3193  num_tests -= 2;
3194 #endif
3195  if(mmapflag || async_flag)
3196  {
3197  num_tests -= 2;
3198  }
3199  }
3200  else
3201  {
3202  if(mmapflag || async_flag)
3203 #if defined(HAVE_PREAD) && defined(HAVE_PREADV)
3204  num_tests -= 6;
3205 #else
3206  num_tests -= 4;
3207 #endif
3208  }
3209 #else
3210  if(mmapflag || async_flag)
3211  {
3212  num_tests -= 2;
3213  }
3214 #endif
3215 
3216  if(RWONLYflag) num_tests = 2; /* kcollins 8-21-96*/
3217  sync(); /* just in case there were some dirty */
3218  sync();
3219  kilobytes64=kilos64;
3220  reclen=reclength;
3221  numrecs64 = (kilobytes64*1024)/reclen;
3223  if(r_traj_flag || w_traj_flag)
3224  store_value((off64_t)0);
3225  else
3226  store_value((off64_t)(reclen/1024));
3227 
3228 #ifdef NO_PRINT_LLD
3229  if(!silent) printf("%16ld",kilobytes64);
3230  if(r_traj_flag || w_traj_flag)
3231  {
3232  if(!silent) printf("%8ld",0);
3233  }
3234  else
3235  {
3236  if(!silent) printf("%8ld",reclen/1024);
3237  }
3238 #else
3239  if(!silent) printf("%16lld",kilobytes64);
3240  if(r_traj_flag || w_traj_flag)
3241  {
3242  if(!silent) printf("%8lld",(long long )0);
3243  }
3244  else
3245  {
3246  if(!silent) printf("%8lld",reclen/1024);
3247  }
3248 #endif
3249  if(include_tflag)
3250  {
3251  for(i=0;i<num_tests;i++)
3252  {
3253  if(include_mask & (long long)(1<<i))
3254  func[i](kilobytes64,reclen,&data1[i],&data2[i]);
3255  else
3256  {
3257  if(!silent) printf("%s",test_output[i]);
3258  fflush(stdout);
3259  for(j=0;j<test_soutput[i];j++)
3260  store_value((off64_t)0);
3261  }
3262  }
3263  }
3264  else
3265  {
3266  for(test_num=0;test_num < num_tests;test_num++)
3267  {
3268  func[test_num](kilobytes64,reclen,&data1[test_num],&data2[test_num]);
3269  };
3270  }
3271  if(!silent) printf("\n");
3272  if(!OPS_flag && !include_tflag){ /* Report in ops/sec ? */
3273  if(data1[1]!=0 && data2[1] != 0)
3274  {
3275  totaltime = data1[1] + data1[0];
3276  if (totaltime < TOOFAST)
3277  {
3279  printf("\nThe test completed too quickly to give a good result\n");
3280  printf("You will get a more precise measure of this machine's\n");
3281  printf("performance by re-running iozone using the command:\n");
3282 #ifdef NO_PRINT_LLD
3283  printf("\n\tiozone %ld ", goodkilos);
3284  printf("\t(i.e., file size = %ld kilobytes64)\n", goodkilos);
3285 #else
3286  printf("\n\tiozone %lld ", goodkilos);
3287  printf("\t(i.e., file size = %lld kilobytes64)\n", goodkilos);
3288 #endif
3289  }
3290  } else {
3291  goodrecl = reclen/2;
3292  printf("\nI/O error during read. Try again with the command:\n");
3293 #ifdef NO_PRINT_LLD
3294  printf("\n\tiozone %ld %ld ", kilobytes64, goodrecl);
3295  printf("\t(i.e. record size = %ld bytes)\n", goodrecl);
3296 #else
3297  printf("\n\tiozone %lld %lld ", kilobytes64, goodrecl);
3298  printf("\t(i.e. record size = %lld bytes)\n", goodrecl);
3299 #endif
3300  }
3301  }
3302  if (!no_unlink)
3303  {
3305  unlink(filename); /* delete the file */
3306  }
3307  /*stop timer*/
3308  return ;
3309 }
3310 /******************************************************************
3311 
3312  SHOW_HELP -- show development help of this program
3313 
3314 ******************************************************************/
3315 #ifdef HAVE_ANSIC_C
3316 void show_help(void)
3317 #else
3319 #endif
3320 {
3321  long long i;
3322  if(!silent) printf("iozone: help mode\n\n");
3323  for(i=0; strlen(help[i]); i++)
3324  {
3325  if(!silent) printf("%s\n", help[i]);
3326  }
3327 }
3328 /******************************************************************
3329 
3330  SIGNAL_HANDLER -- clean up if user interrupts the program
3331 
3332 ******************************************************************/
3333 #ifdef HAVE_ANSIC_C
3334 void signal_handler(void)
3335 #else
3337 #endif
3338 {
3339  long long i;
3340  if(distributed)
3341  {
3342  if(master_iozone)
3343  cleanup_children();
3344  }
3345  if((long long)getpid()==myid)
3346  {
3347  if(!silent) printf("\niozone: interrupted\n\n");
3348 #ifndef VMS
3349  if (!no_unlink)
3350  {
3352  unlink(filename); /* delete the file */
3353  }
3354  for(i=1;i<num_child;i++)
3355  {
3356  if(check_filename(dummyfile[i]))
3357  unlink(dummyfile[i]); /* delete the file */
3358  }
3359  if (!no_unlink)
3360  {
3361  if(check_filename(dummyfile[0]))
3362  unlink(dummyfile[0]); /* delete the file */
3363  }
3364 
3365 #endif
3366  if(Rflag && !trflag){
3367  dump_excel();
3368  }
3369  if(Rflag && trflag){
3370  dump_throughput();
3371  }
3372 
3373  if(!silent) printf("exiting iozone\n\n");
3374  if(res_prob)
3375  {
3376  printf("Timer resolution is poor. Some small transfers may have \n");
3377  printf("reported inaccurate results. Sizes %ld Kbytes and below.\n",
3378  (long)rec_prob/1024);
3379  }
3380  if(trflag && !use_thread)
3381  for(i=0;i<num_child;i++)
3382  kill((pid_t)childids[i],SIGTERM);
3383  if(r_traj_flag)
3384  fclose(r_traj_fd);
3385  if(w_traj_flag)
3386  fclose(w_traj_fd);
3387  }
3388  if(sp_msfd)
3389  close(sp_msfd);
3390  if(sp_mrfd)
3391  close(sp_mrfd);
3392  exit(0);
3393 }
3394 
3395 /****************************************************************/
3396 /* */
3397 /* AUTO_TEST -- perform series of tests and tabulate results */
3398 /* */
3399 /****************************************************************/
3400 #ifdef HAVE_ANSIC_C
3401 void
3402 auto_test(void)
3403 #else
3405 #endif
3406 {
3407  off64_t kilosi;
3408  long long recszi,count1;
3409  long long mult;
3410  long long xx;
3411 
3412  /****************************************************************/
3413  /* Start with file size of 1 megabyte and repeat the test */
3414  /* KILOBYTES_ITER_LIMIT */
3415  /* times. Each time we run, the file size is doubled */
3416  /****************************************************************/
3417 /*
3418  if(sflag) {
3419  min_file_size = kilobytes64;
3420  max_file_size = kilobytes64;
3421  }
3422  if(rflag) {
3423  min_rec_size = reclen;
3424  max_rec_size = reclen;
3425  }
3426 */
3427  if(gflag)
3429  if(nflag)
3431 
3432  if (min_rec_size > (long long)(min_file_size*1024)) {
3433 #ifdef NO_PRINT_LLD
3434  printf("Error: record length %ld is greater than filesize %ld KB\n ",
3436 #else
3437  printf("Error: record length %lld is greater than filesize %lld KB\n ",
3439 #endif
3440  exit(23);
3441  }
3442 
3444 
3446  del_record_sizes();
3450 
3451  for(kilosi=get_next_file_size((off64_t)0); kilosi>0; kilosi=get_next_file_size(kilosi))
3452  {
3453  /****************************************************************/
3454  /* Start with record size of min_rec_size bytes and repeat the */
3455  /* test, multiplying the record size by MULTIPLIER each time, */
3456  /* until we reach max_rec_size. At the CROSSOVER we stop doing */
3457  /* small buffers as it takes forever and becomes very */
3458  /* un-interesting. */
3459  /****************************************************************/
3460  if(!rflag && !sflag && !yflag && !qflag)
3461  if(kilosi > xover){
3463  mult = orig_min_rec_size/1024;
3464  del_record_sizes();
3466  /************************************/
3467  /* Generate dummy entries in the */
3468  /* Excel buffer for skipped */
3469  /* record sizes */
3470  /************************************/
3471  for(count1=min_rec_size;
3472  (count1 != orig_min_rec_size) && (
3473  mult <= (kilosi*1024)) ;
3474  count1=(count1>>1))
3475  {
3476  current_x=0;
3477  store_value((off64_t)kilosi);
3478  store_value((off64_t)mult);
3479  for(xx=0;xx<20;xx++)
3480  store_value((off64_t)0);
3481  mult=mult*2;
3482  current_y++;
3483  if(current_y>max_y)
3484  max_y=current_y;
3485  current_x=0;
3486  }
3487  }
3488 
3489  for (recszi=get_next_record_size((off64_t)0);recszi!=0;recszi=get_next_record_size(recszi))
3490  {
3491  if(recszi > (kilosi*1024))
3492  break;
3493  begin(kilosi, recszi );
3494  current_x=0;
3495  current_y++;
3496  }
3497  }
3498 }
3499 
3500 
3501 /****************************************************************/
3502 /* */
3503 /* THROUGHPUT_TEST () Multi process throughput test */
3504 /* */
3505 /* Note: States for share memory barrier are: */
3506 /* 0 = Child not running or has finished. */
3507 /* 1 = Child is ready to begin. */
3508 /* 2 = Child is told to begin. */
3509 /****************************************************************/
3510 /* Data in shared memory format is: */
3511 /* */
3512 /* struct child_stats { */
3513 /* long long flag; Used to barrier */
3514 /* double walltime; Child's elapsed time */
3515 /* double cputime; Child's CPU time */
3516 /* double throughput; Child's throughput */
3517 /* double actual; Child's actual read/written */
3518 /* } */
3519 /* */
3520 /* There is an array of child_stat structures layed out in */
3521 /* shared memory. */
3522 /* */
3523 /****************************************************************/
3524 
3525 #ifdef HAVE_ANSIC_C
3526 void
3527 throughput_test(void)
3528 #else
3529 void
3531 #endif
3532 {
3533  char *unit;
3534  double starttime1 = 0;
3535  double jstarttime = 0;
3536  double jtime = 0;
3537  double walltime = 0;
3538  double cputime = 0;
3539  char *port;
3540  char getout;
3541  long long throughsize = KILOBYTES;
3542  long long xx,xy,i;
3543  long long xyz;
3544  double ptotal;
3545  off64_t written_so_far, read_so_far, re_written_so_far,re_read_so_far;
3546  VOLATILE char *temp;
3547  double min_throughput = 0;
3548  double max_throughput = 0;
3549  double avg_throughput = 0;
3550  double min_xfer = 0;
3551 
3552 
3553  toutputindex=0;
3554  strcpy(&toutput[0][0],throughput_tests[0]);
3555  ptotal=written_so_far=read_so_far=re_written_so_far=re_read_so_far=0 ;
3556 
3557  if(OPS_flag)
3558  unit="ops";
3559  else
3560  unit="KB";
3561 
3562  if(!haveshm)
3563  {
3564  shmaddr=(struct child_stats *)alloc_mem((long long)SHMSIZE,(int)1);
3565 #ifdef _64BIT_ARCH_
3566  if((long long)shmaddr==(long long)-1)
3567 #else
3568  if((long )shmaddr==(long)-1)
3569 #endif
3570  {
3571  printf("\nShared memory not working\n");
3572  exit(24);
3573  }
3574  haveshm=(char*)shmaddr;
3575  }
3576  else
3577  shmaddr=(struct child_stats *)haveshm;
3578 
3579  if(use_thread)
3580  stop_flag = &stoptime;
3581  else
3582  {
3583  temp = (char *)&shmaddr[0];
3584  stop_flag = (char *)&temp[(long long)SHMSIZE]-4;
3585  }
3586  for(xyz=0;xyz<num_child;xyz++){ /* all children to state 0 (HOLD) */
3587  child_stat = (struct child_stats *)&shmaddr[xyz];
3589  child_stat->actual=0;
3591  child_stat->cputime=0;
3592  child_stat->walltime=0;
3593  }
3594  *stop_flag = 0;
3595  if(!sflag)
3596  kilobytes64=throughsize;
3597  if(!rflag)
3598  reclen=(long long)4096;
3599  if(aggflag)
3601  numrecs64 = (long long)(kilobytes64*1024)/reclen;
3603  if(use_thread)
3604  port="thread";
3605  else
3606  port="process";
3607  if(w_traj_flag)
3608  {
3609 #ifdef NO_PRINT_LLD
3610  if(!silent) printf("\tEach %s writes a %ld Kbyte file in telemetry controlled records\n",
3611  port,kilobytes64);
3612 #else
3613  if(!silent) printf("\tEach %s writes a %lld Kbyte file in telemetry controlled records\n",
3614  port,kilobytes64);
3615 #endif
3616  }
3617  else
3618  {
3619 #ifdef NO_PRINT_LLD
3620  if(!silent) printf("\tEach %s writes a %ld Kbyte file in %ld Kbyte records\n",
3621  port,kilobytes64,reclen/1024);
3622 #else
3623  if(!silent) printf("\tEach %s writes a %lld Kbyte file in %lld Kbyte records\n",
3624  port,kilobytes64,reclen/1024);
3625 #endif
3626  }
3627 
3628  if(fflag) /* Each child has a file name to write */
3629  for(xx=0;xx<num_child;xx++)
3630  filearray[xx] = filename;
3631  myid = (long long)getpid();
3632 
3633  /* rags: skip writer test */
3634  if(include_tflag)
3635  if(!(include_mask & (long long)WRITER_MASK))
3636  {
3637  store_dvalue( (double)0);
3638  store_dvalue( (double)0);
3639  toutputindex++;
3640  goto next0;
3641  }
3642 
3643  if((!distributed) || (distributed && master_iozone))
3644  start_monitor("Write");
3645  /* Hooks to start the distributed Iozone client/server code */
3646  if(distributed)
3647  {
3648  use_thread=0; /* Turn of any Posix threads */
3649  if(master_iozone)
3651  else
3652  become_client();
3653  }
3654  if(!use_thread)
3655  {
3656  for(xx = 0; xx< num_child ; xx++){ /* Create the children */
3657  chid=xx;
3659  if(childids[xx]==-1){
3660  printf("\nFork failed\n");
3661  for(xy = 0; xy< xx ; xy++){
3662  if(!use_thread)
3663  kill((pid_t)childids[xy],SIGTERM);
3664  }
3665  exit(25);
3666  }
3667  if(childids[xx]!=0 && debug1)
3668 #ifdef NO_PRINT_LLD
3669  printf("Parent starting slot %ld\n",xx);
3670 #else
3671  printf("Parent starting slot %lld\n",xx);
3672 #endif
3673  if( childids[xx] == 0 ){
3674 #ifdef _64BIT_ARCH_
3675  thread_write_test((void *)xx);
3676 #else
3677  thread_write_test((void *)(long)xx);
3678 #endif
3679  }else {
3680 #ifdef NO_PRINT_LLD
3681  sprintf(dummyfile[xx],"%s.DUMMY.%ld",filearray[xx], xx);
3682 #else
3683  sprintf(dummyfile[xx],"%s.DUMMY.%lld",filearray[xx], xx);
3684 #endif
3685  }
3686  }
3687  }
3688 #ifndef NO_THREADS
3689  else
3690  {
3691  for(xx = 0; xx< num_child ; xx++){ /* Create the children */
3692 
3693 #ifdef NO_PRINT_LLD
3694  sprintf(dummyfile[xx],"%s.DUMMY.%ld",filearray[xx], xx);
3695 #else
3696  sprintf(dummyfile[xx],"%s.DUMMY.%lld",filearray[xx], xx);
3697 #endif
3698  if(!barray[xx])
3699  {
3700  barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
3701  if(barray[xx] == 0) {
3702  perror("Memory allocation failed:");
3703  exit(26);
3704  }
3705  barray[xx] =(char *)(((long)barray[xx] + cache_size ) &
3706  ~(cache_size-1));
3707  }
3708 
3709 #ifdef _64BIT_ARCH_
3710  childids[xx] = mythread_create(thread_write_test,(void*)xx);
3711 #else
3712  childids[xx] = mythread_create(thread_write_test,(void*)(long)xx);
3713 #endif
3714  if(childids[xx]==-1){
3715  printf("Thread create failed\n");
3716  for(xy = 0; xy< xx ; xy++){
3717  kill((pid_t)myid,SIGTERM);
3718  }
3719  exit(27);
3720  }
3721  }
3722  }
3723 #endif
3724  if((long long)getpid() == myid)
3725  {
3726  prepage(buffer,reclen); /* Force copy on write */
3727  /* wait for children to start */
3728  if(distributed && master_iozone)
3729  {
3731  }
3732  for(i=0;i<num_child; i++){
3733  child_stat = (struct child_stats *)&shmaddr[i];
3735  Poll((long long)1);
3736  }
3737  for(i=0;i<num_child; i++) /* Start all children going */
3738  {
3739  if(delay_start!=0)
3740  Poll((long long)delay_start);
3741  /* State "go" */
3742  child_stat = (struct child_stats *)&shmaddr[i];
3744  if(distributed && master_iozone)
3746  }
3747  starttime1 = time_so_far(); /* Start parents timer */
3748  goto waitout;
3749  }
3750 
3751 waitout:
3752  getout=0;
3753  if((long long)getpid() == myid) { /* Parent only */
3754  starttime1 = time_so_far(); /* Wait for all children */
3755  for( i = 0; i < num_child; i++){
3756  child_stat = (struct child_stats *) &shmaddr[i];
3757  if(distributed && master_iozone)
3758  {
3759  printf("\n\tTest running:");
3760  wait_dist_join();
3761  break;
3762  }
3763  else
3764  {
3765  if(use_thread)
3766  {
3767  thread_join(childids[i],(void *)&pstatus);
3768  }
3769  else
3770  {
3771  wait(0);
3772  }
3773  }
3774  if(!jstarttime)
3775  jstarttime = time_so_far();
3776  }
3777  jtime = (time_so_far()-jstarttime)-time_res;
3778  if(jtime < (double).000001)
3779  {
3780  jtime=time_res;
3781  }
3782  }
3783  total_time = (time_so_far() - starttime1)-time_res; /* get parents total time */
3784  if(total_time < (double).000001)
3785  {
3787  if(rec_prob < reclen)
3788  rec_prob = reclen;
3789  res_prob=1;
3790  }
3791 #ifdef JTIME
3792  total_time=total_time-jtime;/* Remove the join time */
3793  if(!silent) printf("\nJoin time %10.2f\n",jtime);
3794 #endif
3795 
3796  total_kilos=0;
3797  ptotal=0;
3798  walltime = 0.0;
3799  cputime = 0.0;
3800  if(!silent) printf("\n");
3801  for(xyz=0;xyz<num_child;xyz++){
3802  child_stat = (struct child_stats *) &shmaddr[xyz];
3803  total_kilos += child_stat->throughput; /* add up the children */
3804  ptotal += child_stat->actual;
3805  if(!min_xfer)
3806  min_xfer=child_stat->actual;
3807  if(child_stat->actual < min_xfer)
3808  min_xfer=child_stat->actual;
3809  if(!min_throughput)
3810  min_throughput=child_stat->throughput;
3811  if(child_stat->throughput < min_throughput)
3812  min_throughput=child_stat->throughput;
3813  if(child_stat->throughput > max_throughput)
3814  max_throughput=child_stat->throughput;
3815  /* Add up the cpu times of all children */
3817 
3818  /* and find the child with the longest wall time */
3819  /* Get the earliest start time and latest fini time to calc. elapsed time. */
3822  if (child_stat->walltime > walltime)
3824  }
3825  avg_throughput=total_kilos/num_child;
3826  if(cpuutilflag)
3827  {
3828  if (cputime < cputime_res)
3829  cputime = 0.0;
3830  }
3831 
3832  for(xyz=0;xyz<num_child;xyz++){
3833  child_stat = (struct child_stats *) &shmaddr[xyz];
3834  child_stat->flag = CHILD_STATE_HOLD; /* Start children at state 0 (HOLD) */
3835  }
3836  if(cpuutilflag)
3837  store_times (walltime, cputime); /* Must be Before store_dvalue(). */
3839 #ifdef NO_PRINT_LLD
3840  if(!silent) printf("\tChildren see throughput for %2ld initial writers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
3841  if(!silent && !distributed) printf("\tParent sees throughput for %2ld initial writers \t= %10.2f %s/sec\n",num_child,((double)(ptotal)/total_time),unit);
3842 #else
3843  if(!silent) printf("\tChildren see throughput for %2lld initial writers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
3844  if(!silent && !distributed) printf("\tParent sees throughput for %2lld initial writers \t= %10.2f %s/sec\n",num_child,((double)(ptotal)/total_time),unit);
3845 #endif
3846  if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
3847  if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
3848  if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
3849  if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
3850  /* CPU% can be > 100.0 for multiple CPUs */
3851  if(cpuutilflag)
3852  {
3853  if(walltime == 0.0)
3854  {
3855  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
3856  walltime, cputime, 0.0);
3857  }
3858  else
3859  {
3860  if(!silent) printf("\tCPU Utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
3861  walltime, cputime, 100.0 * cputime / walltime);
3862  }
3863  }
3864  if(Cflag)
3865  {
3866  for(xyz=0;xyz<num_child;xyz++)
3867  {
3868  child_stat = (struct child_stats *) &shmaddr[xyz];
3869  if(cpuutilflag)
3870  {
3871  if(!silent)
3872  printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
3873  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime,
3875  }
3876  else
3877  {
3878  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
3879  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
3880  }
3881  }
3882  }
3883  if((!distributed) || (distributed && master_iozone))
3884  stop_monitor("Write");
3885  /**********************************************************/
3886  /*************** End of intitial writer *******************/
3887  /**********************************************************/
3888  sync();
3889  sleep(2);
3890  if(restf)
3891  sleep((int)rest_val);
3892  *stop_flag=0;
3893  if(distributed && master_iozone)
3894  {
3896  cleanup_comm();
3897  }
3898 
3899  /**********************************************************/
3900  /* Re-write throughput performance test. ******************/
3901  /**********************************************************/
3902  walltime = 0.0;
3903  cputime = 0.0;
3904  jstarttime=0;
3905  total_kilos=0;
3906  toutputindex=1;
3907  strcpy(&toutput[1][0],throughput_tests[1]);
3908  if(noretest)
3909  {
3910  store_dvalue( (double)0);
3911  goto next0;
3912  }
3913  if((!distributed) || (distributed && master_iozone))
3914  start_monitor("Rewrite");
3915  /* Hooks to start the distributed Iozone client/server code */
3916  if(distributed)
3917  {
3918  use_thread=0; /* Turn of any Posix threads */
3919  if(master_iozone)
3921  else
3922  become_client();
3923  }
3924  if(!use_thread)
3925  {
3926  for(xx = 0; xx< num_child ; xx++){
3927  chid=xx;
3929  if(childids[xx]==-1){
3930  printf("\nFork failed\n");
3931  for(xy = 0; xy< xx ; xy++){
3932  Kill((long long)childids[xy],(long long)SIGTERM);
3933  }
3934  exit(28);
3935  }
3936  if(childids[xx] == 0){
3937 #ifdef _64BIT_ARCH_
3938  thread_rwrite_test((void *)xx);
3939 #else
3940  thread_rwrite_test((void *)((long)xx));
3941 #endif
3942  }
3943  }
3944  }
3945 #ifndef NO_THREADS
3946  else
3947  {
3948  for(xx = 0; xx< num_child ; xx++){ /* Create the children */
3949  if(!barray[xx])
3950  {
3951  barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
3952  if(barray[xx] == 0) {
3953  perror("Memory allocation failed:");
3954  exit(26);
3955  }
3956  barray[xx] =(char *)(((long)barray[xx] + cache_size ) &
3957  ~(cache_size-1));
3958  }
3959 #ifdef _64BIT_ARCH_
3961 #else
3962  childids[xx] = mythread_create( thread_rwrite_test,(void *)(long)xx);
3963 #endif
3964  if(childids[xx]==-1){
3965  printf("\nThread create failed\n");
3966  for(xy = 0; xy< xx ; xy++){
3967  Kill((long long)myid,(long long)SIGTERM);
3968  }
3969  exit(29);
3970  }
3971  }
3972  }
3973 #endif
3974  if((long long)myid == getpid())
3975  {
3976  if(distributed && master_iozone)
3977  {
3979  }
3980  for(i=0;i<num_child; i++){
3981  child_stat = (struct child_stats *)&shmaddr[i];
3982  /* wait for children to start */
3983  while(child_stat->flag==CHILD_STATE_HOLD)
3984  Poll((long long)1);
3985  }
3986  for(i=0;i<num_child; i++)
3987  {
3988  child_stat = (struct child_stats *)&shmaddr[i];
3989  child_stat->flag = CHILD_STATE_BEGIN; /* tell children to go */
3990  if(delay_start!=0)
3991  Poll((long long)delay_start);
3992  if(distributed && master_iozone)
3994  }
3995  starttime1 = time_so_far();
3996  goto jump3;
3997  }
3998 
3999 jump3:
4000  getout=0;
4001  if((long long)myid == getpid()){ /* Parent only here */
4002  for( i = 0; i < num_child; i++){
4003  child_stat=(struct child_stats *)&shmaddr[i];
4004  if(distributed && master_iozone)
4005  {
4006  printf("\n\tTest running:");
4007  wait_dist_join();
4008  break;
4009  }
4010  else
4011  {
4012  if(use_thread)
4013  {
4014  thread_join(childids[i],(void *)&pstatus);
4015  }
4016  else
4017  {
4018  wait(0);
4019  }
4020  }
4021  if(!jstarttime)
4022  jstarttime = time_so_far();
4023  }
4024  jtime = (time_so_far()-jstarttime)-time_res;
4025  if(jtime < (double).000001)
4026  {
4027  jtime=time_res;
4028  }
4029  }
4030  total_time = (time_so_far() - starttime1)-time_res; /* Parents total time */
4031  if(total_time < (double).000001)
4032  {
4034  if(rec_prob < reclen)
4035  rec_prob = reclen;
4036  res_prob=1;
4037  }
4038 #ifdef JTIME
4039  total_time=total_time-jtime;/* Remove the join time */
4040  if(!silent) printf("\nJoin time %10.2f\n",jtime);
4041 #endif
4042 
4043 
4044  total_kilos=0;
4045  ptotal=0;
4046 
4047  min_throughput=max_throughput=min_xfer=0;
4048  if(!silent) printf("\n");
4049  for(xyz=0;xyz<num_child;xyz++){
4050  child_stat=(struct child_stats *)&shmaddr[xyz];
4052  ptotal+=child_stat->actual;
4053  if(!min_xfer)
4054  min_xfer=child_stat->actual;
4055  if(child_stat->actual < min_xfer)
4056  min_xfer=child_stat->actual;
4057  if(!min_throughput)
4058  min_throughput=child_stat->throughput;
4059  if(child_stat->throughput < min_throughput)
4060  min_throughput=child_stat->throughput;
4061  if(child_stat->throughput > max_throughput)
4062  max_throughput=child_stat->throughput;
4064  /* Get the earliest start time and latest fini time to calc. elapsed time. */
4067  if (child_stat->walltime > walltime)
4069  }
4070  avg_throughput=total_kilos/num_child;
4071  if(cpuutilflag)
4072  {
4073 /*
4074  if (walltime < cputime_res)
4075  walltime = 0.0;
4076 */
4077  if (cputime < cputime_res)
4078  cputime = 0.0;
4079  }
4080 
4081  for(xyz=0;xyz<num_child;xyz++){ /* Reset state to 0 (HOLD) */
4082  child_stat=(struct child_stats *)&shmaddr[xyz];
4084  }
4085  if(cpuutilflag)
4086  store_times (walltime, cputime); /* Must be Before store_dvalue(). */
4088 #ifdef NO_PRINT_LLD
4089  if(!silent) printf("\tChildren see throughput for %2ld rewriters \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
4090  if(!silent && !distributed) printf("\tParent sees throughput for %2ld rewriters \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
4091 #else
4092  if(!silent) printf("\tChildren see throughput for %2lld rewriters \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
4093  if(!silent && !distributed) printf("\tParent sees throughput for %2lld rewriters \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
4094 #endif
4095  if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
4096  if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
4097  if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
4098  if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
4099  /* CPU% can be > 100.0 for multiple CPUs */
4100  if(cpuutilflag)
4101  {
4102  if(walltime == 0.0)
4103  {
4104  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
4105  walltime, cputime, 0.0);
4106  }
4107  else
4108  {
4109  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
4110  walltime, cputime, 100.0 * cputime / walltime);
4111  }
4112  }
4113  if(Cflag)
4114  {
4115  for(xyz=0;xyz<num_child;xyz++)
4116  {
4117  child_stat = (struct child_stats *) &shmaddr[xyz];
4118  if(cpuutilflag)
4119  {
4120  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
4121  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime,
4123  }
4124  else
4125  {
4126  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
4127  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
4128  }
4129  }
4130  }
4131  *stop_flag=0;
4132  if((!distributed) || (distributed && master_iozone))
4133  stop_monitor("Rewrite");
4134  /**********************************************************/
4135  /*************** End of rewrite throughput ****************/
4136  /**********************************************************/
4137  sync();
4138  sleep(2);
4139  if(restf)
4140  sleep((int)rest_val);
4141  if(distributed && master_iozone)
4142  {
4144  cleanup_comm();
4145  }
4146 next0:
4147  if(include_tflag)
4148  if(!(include_mask & (long long)READER_MASK))
4149  goto next1;
4150  /**************************************************************/
4151  /*** Reader throughput tests **********************************/
4152  /**************************************************************/
4153  if((!distributed) || (distributed && master_iozone))
4154  start_monitor("Read");
4155  toutputindex++;
4156  strcpy(&toutput[toutputindex][0],throughput_tests[2]);
4157  walltime = 0.0;
4158  cputime = 0.0;
4159  jstarttime=0;
4160  total_kilos=0;
4161  if(distributed)
4162  {
4163  use_thread=0;
4164  if(master_iozone)
4166  else
4167  become_client();
4168  }
4169  if(!use_thread)
4170  {
4171  for(xx = 0; xx< num_child ; xx++){
4172  chid=xx;
4174  if(childids[xx]==-1){
4175  printf("\nFork failed\n");
4176  for(xy = 0; xy< xx ; xy++){
4177  Kill((long long)childids[xy],(long long)SIGTERM);
4178  }
4179  exit(30);
4180  }
4181  if(childids[xx]==0){
4182 #ifdef _64BIT_ARCH_
4183  thread_read_test((void *)xx);
4184 #else
4185  thread_read_test((void *)((long)xx));
4186 #endif
4187  }
4188  }
4189  }
4190 #ifndef NO_THREADS
4191  else
4192  {
4193  for(xx = 0; xx< num_child ; xx++){ /* Create the children */
4194  if(!barray[xx])
4195  {
4196  barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
4197  if(barray[xx] == 0) {
4198  perror("Memory allocation failed:");
4199  exit(26);
4200  }
4201  barray[xx] =(char *)(((long)barray[xx] + cache_size ) &
4202  ~(cache_size-1));
4203  }
4204 #ifdef _64BIT_ARCH_
4206 #else
4207  childids[xx] = mythread_create( thread_read_test,(void *)(long)xx);
4208 #endif
4209  if(childids[xx]==-1){
4210  printf("\nThread create failed\n");
4211  for(xy = 0; xy< xx ; xy++){
4212  kill((pid_t)myid,(int)SIGTERM);
4213  }
4214  exit(31);
4215  }
4216  }
4217  }
4218 #endif
4219  if(myid == (long long)getpid()){
4220  if(distributed && master_iozone)
4221  {
4223  }
4224  for(i=0;i<num_child; i++){ /* wait for children to start */
4225  child_stat=(struct child_stats *)&shmaddr[i];
4227  Poll((long long)1);
4228  }
4229  for(i=0;i<num_child; i++)
4230  {
4231  child_stat=(struct child_stats *)&shmaddr[i];
4232  child_stat->flag = CHILD_STATE_BEGIN; /* tell children to go */
4233  if(delay_start!=0)
4234  Poll((long long)delay_start);
4235  if(distributed && master_iozone)
4237  }
4238  starttime1 = time_so_far();
4239  goto jumpend4;
4240  }
4241 jumpend4:
4242  getout=0;
4243  if(myid == (long long)getpid()){ /* Parent here */
4244  for( i = 0; i < num_child; i++){
4245  child_stat = (struct child_stats *)&shmaddr[i];
4246  if(distributed && master_iozone)
4247  {
4248  printf("\n\tTest running:");
4249  wait_dist_join();
4250  break;
4251  }
4252  else
4253  {
4254  if(use_thread)
4255  {
4256  thread_join(childids[i],(void *)&pstatus);
4257  }
4258  else
4259  {
4260  wait(0);
4261  }
4262  }
4263  if(!jstarttime)
4264  jstarttime = time_so_far();
4265  }
4266  jtime = (time_so_far()-jstarttime)-time_res;
4267  if(jtime < (double).000001)
4268  {
4269  jtime=time_res;
4270  }
4271  }
4272  total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
4273  if(total_time < (double).000001)
4274  {
4276  if(rec_prob < reclen)
4277  rec_prob = reclen;
4278  res_prob=1;
4279  }
4280 #ifdef JTIME
4281  total_time=total_time-jtime;/* Remove the join time */
4282  if(!silent) printf("\nJoin time %10.2f\n",jtime);
4283 #endif
4284 
4285  total_kilos=0;
4286  ptotal=0;
4287  min_throughput=max_throughput=min_xfer=0;
4288  if(!silent) printf("\n");
4289  for(xyz=0;xyz<num_child;xyz++){
4290  child_stat=(struct child_stats *)&shmaddr[xyz];
4292  ptotal+=child_stat->actual;
4293  if(!min_xfer)
4294  min_xfer=child_stat->actual;
4295  if(child_stat->actual < min_xfer)
4296  min_xfer=child_stat->actual;
4297  if(!min_throughput)
4298  min_throughput=child_stat->throughput;
4299  if(child_stat->throughput < min_throughput)
4300  min_throughput=child_stat->throughput;
4301  if(child_stat->throughput > max_throughput)
4302  max_throughput=child_stat->throughput;
4304  /* Get the earliest start time and latest fini time to calc. elapsed time. */
4307  if (child_stat->walltime > walltime)
4309  }
4310  avg_throughput=total_kilos/num_child;
4311  if(cpuutilflag)
4312  {
4313  if (cputime < cputime_res)
4314  cputime = 0.0;
4315  }
4316  if(cpuutilflag)
4317  store_times (walltime, cputime); /* Must be Before store_dvalue(). */
4319 #ifdef NO_PRINT_LLD
4320  if(!silent) printf("\tChildren see throughput for %2ld readers \t\t= %10.2f %s/sec\n", num_child, total_kilos,unit);
4321  if(!silent && !distributed) printf("\tParent sees throughput for %2ld readers \t\t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
4322 #else
4323  if(!silent) printf("\tChildren see throughput for %2lld readers \t\t= %10.2f %s/sec\n", num_child, total_kilos,unit);
4324  if(!silent && !distributed) printf("\tParent sees throughput for %2lld readers \t\t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
4325 #endif
4326  if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
4327  if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
4328  if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
4329  if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
4330  /* CPU% can be > 100.0 for multiple CPUs */
4331  if(cpuutilflag)
4332  {
4333  if(walltime == 0.0)
4334  {
4335  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
4336  walltime, cputime, 0.0);
4337  }
4338  else
4339  {
4340  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
4341  walltime, cputime, 100.0 * cputime / walltime);
4342  }
4343  }
4344  if(Cflag)
4345  {
4346  for(xyz=0;xyz<num_child;xyz++)
4347  {
4348  child_stat = (struct child_stats *) &shmaddr[xyz];
4349  if(cpuutilflag)
4350  {
4351  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
4352  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime,
4354  }
4355  else
4356  {
4357  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
4358  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
4359  }
4360  }
4361  }
4362  if((!distributed) || (distributed && master_iozone))
4363  stop_monitor("Read");
4364  /**********************************************************/
4365  /*************** End of readers throughput ****************/
4366  /**********************************************************/
4367  sync();
4368  sleep(2);
4369  if(restf)
4370  sleep((int)rest_val);
4371  if(distributed && master_iozone)
4372  {
4374  cleanup_comm();
4375  }
4376 
4377  /**************************************************************/
4378  /*** ReReader throughput tests **********************************/
4379  /**************************************************************/
4380  toutputindex++;
4381  strcpy(&toutput[toutputindex][0],throughput_tests[3]);
4382  if(noretest)
4383  {
4384  store_dvalue( (double)0);
4385  goto next1;
4386  }
4387  if((!distributed) || (distributed && master_iozone))
4388  start_monitor("Reread");
4389  walltime = 0.0;
4390  cputime = 0.0;
4391  jstarttime=0;
4392  *stop_flag=0;
4393  total_kilos=0;
4394  /* Hooks to start the distributed Iozone client/server code */
4395  if(distributed)
4396  {
4397  use_thread=0; /* Turn of any Posix threads */
4398  if(master_iozone)
4400  else
4401  become_client();
4402  }
4403  if(!use_thread)
4404  {
4405  for(xx = 0; xx< num_child ; xx++){
4406  chid=xx;
4408  if(childids[xx]==-1){
4409  printf("\nFork failed\n");
4410  for(xy = 0; xy< xx ; xy++){
4411  Kill((long long)childids[xy],(long long)SIGTERM);
4412  }
4413  exit(32);
4414  }
4415  if(childids[xx]==0){
4416 #ifdef _64BIT_ARCH_
4417  thread_rread_test((void *)xx);
4418 #else
4419  thread_rread_test((void *)((long)xx));
4420 #endif
4421  }
4422  }
4423  }
4424 #ifndef NO_THREADS
4425  else
4426  {
4427  for(xx = 0; xx< num_child ; xx++){ /* Create the children */
4428  chid=xx;
4429  if(!barray[xx])
4430  {
4431  barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
4432  if(barray[xx] == 0) {
4433  perror("Memory allocation failed:");
4434  exit(26);
4435  }
4436  barray[xx] =(char *)(((long)barray[xx] + cache_size ) &
4437  ~(cache_size-1));
4438  }
4439 #ifdef _64BIT_ARCH_
4441 #else
4442  childids[xx] = mythread_create( thread_rread_test,(void *)(long)xx);
4443 #endif
4444  if(childids[xx]==-1){
4445  printf("\nThread create failed\n");
4446  for(xy = 0; xy< xx ; xy++){
4447  kill((pid_t)myid,(int)SIGTERM);
4448  }
4449  exit(33);
4450  }
4451  }
4452  }
4453 #endif
4454  if(myid == (long long)getpid()){
4455  if(distributed && master_iozone)
4456  {
4458  }
4459  for(i=0;i<num_child; i++){ /* wait for children to start */
4460  child_stat = (struct child_stats *)&shmaddr[i];
4462  Poll((long long)1);
4463  }
4464  for(i=0;i<num_child; i++){
4465  child_stat = (struct child_stats *)&shmaddr[i];
4466  child_stat->flag = CHILD_STATE_BEGIN; /* tell children to go */
4467  if(delay_start!=0)
4468  Poll((long long)delay_start);
4469  if(distributed && master_iozone)
4471  }
4472  starttime1 = time_so_far();
4473  goto jumpend2;
4474  }
4475 
4476 jumpend2:
4477  getout=0;
4478  if(myid == (long long)getpid()){ /* Parent here */
4479  for( i = 0; i < num_child; i++){ /* wait for children to stop */
4480  child_stat = (struct child_stats *)&shmaddr[i];
4481  if(distributed && master_iozone)
4482  {
4483  printf("\n\tTest running:");
4484  wait_dist_join();
4485  break;
4486  }
4487  else
4488  {
4489  if(use_thread)
4490  {
4491  thread_join(childids[i],(void *)&pstatus);
4492  }
4493  else
4494  {
4495  wait(0);
4496  }
4497  }
4498  if(!jstarttime)
4499  jstarttime = time_so_far();
4500  }
4501  jtime = (time_so_far()-jstarttime)-time_res;
4502  if(jtime < (double).000001)
4503  {
4504  jtime=time_res;
4505  }
4506  }
4507  total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
4508  if(total_time < (double).000001)
4509  {
4511  if(rec_prob < reclen)
4512  rec_prob = reclen;
4513  res_prob=1;
4514  }
4515 #ifdef JTIME
4516  total_time=total_time-jtime;/* Remove the join time */
4517  if(!silent) printf("\nJoin time %10.2f\n",jtime);
4518 #endif
4519  min_throughput=max_throughput=min_xfer=0;
4520  total_kilos=0;
4521  ptotal=0;
4522  if(!silent) printf("\n");
4523  for(xyz=0;xyz<num_child;xyz++){
4524  child_stat = (struct child_stats *)&shmaddr[xyz];
4526  ptotal+=child_stat->actual;
4527  if(!min_xfer)
4528  min_xfer=child_stat->actual;
4529  if(child_stat->actual < min_xfer)
4530  min_xfer=child_stat->actual;
4531  if(!min_throughput)
4532  min_throughput=child_stat->throughput;
4533  if(child_stat->throughput < min_throughput)
4534  min_throughput=child_stat->throughput;
4535  if(child_stat->throughput > max_throughput)
4536  max_throughput=child_stat->throughput;
4538  /* Get the earliest start time and latest fini time to calc. elapsed time. */
4541  if (child_stat->walltime > walltime)
4543  }
4544  avg_throughput=total_kilos/num_child;
4545  if(cpuutilflag)
4546  {
4547 /*
4548  if (walltime < cputime_res)
4549  walltime = 0.0;
4550 */
4551  if (cputime < cputime_res)
4552  cputime = 0.0;
4553  }
4554  if(cpuutilflag)
4555  store_times (walltime, cputime); /* Must be Before store_dvalue(). */
4557 #ifdef NO_PRINT_LLD
4558  if(!silent) printf("\tChildren see throughput for %ld re-readers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
4559  if(!silent && !distributed) printf("\tParent sees throughput for %ld re-readers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
4560 #else
4561  if(!silent) printf("\tChildren see throughput for %lld re-readers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
4562  if(!silent && !distributed) printf("\tParent sees throughput for %lld re-readers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
4563 #endif
4564  if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
4565  if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
4566  if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
4567  if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
4568  /* CPU% can be > 100.0 for multiple CPUs */
4569  if(cpuutilflag)
4570  {
4571  if(walltime == 0.0)
4572  {
4573  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
4574  walltime, cputime, 0.0);
4575  }
4576  else
4577  {
4578  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
4579  walltime, cputime, 100.0 * cputime / walltime);
4580  }
4581  }
4582  if(Cflag)
4583  {
4584  for(xyz=0;xyz<num_child;xyz++)
4585  {
4586  child_stat = (struct child_stats *) &shmaddr[xyz];
4587  if(cpuutilflag)
4588  {
4589  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
4590  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime,
4592  }
4593  else
4594  {
4595  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
4596  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
4597  }
4598  }
4599  }
4600  if((!distributed) || (distributed && master_iozone))
4601  stop_monitor("Reread");
4602  /**********************************************************/
4603  /*************** End of re-readers throughput ****************/
4604  /**********************************************************/
4605  sync();
4606  sleep(2);
4607  if(restf)
4608  sleep((int)rest_val);
4609  if(distributed && master_iozone)
4610  {
4612  cleanup_comm();
4613  }
4614 
4615 next1:
4616  if(include_tflag)
4617  if(!(include_mask & (long long)REVERSE_MASK))
4618  goto next2;
4619  sync();
4620  sleep(2);
4621 
4622  /**************************************************************/
4623  /*** Reverse reader throughput tests **************************/
4624  /**************************************************************/
4625  toutputindex++;
4626  strcpy(&toutput[toutputindex][0],throughput_tests[4]);
4627  if((!distributed) || (distributed && master_iozone))
4628  start_monitor("Revread");
4629  walltime = 0.0;
4630  cputime = 0.0;
4631  jstarttime=0;
4632  *stop_flag=0;
4633  total_kilos=0;
4634  /* Hooks to start the distributed Iozone client/server code */
4635  if(distributed)
4636  {
4637  use_thread=0; /* Turn of any Posix threads */
4638  if(master_iozone)
4640  else
4641  become_client();
4642  }
4643  if(!use_thread)
4644  {
4645  for(xx = 0; xx< num_child ; xx++){
4646  chid=xx;
4648  if(childids[xx]==-1){
4649  printf("\nFork failed\n");
4650  for(xy = 0; xy< xx ; xy++){
4651  Kill((long long)childids[xy],(long long)SIGTERM);
4652  }
4653  exit(34);
4654  }
4655  if(childids[xx]==0){
4656 #ifdef _64BIT_ARCH_
4657  thread_reverse_read_test((void *)xx);
4658 #else
4659  thread_reverse_read_test((void *)((long)xx));
4660 #endif
4661  }
4662  }
4663  }
4664 #ifndef NO_THREADS
4665  else
4666  {
4667  for(xx = 0; xx< num_child ; xx++){ /* Create the children */
4668  chid=xx;
4669  if(!barray[xx])
4670  {
4671  barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
4672  if(barray[xx] == 0) {
4673  perror("Memory allocation failed:");
4674  exit(26);
4675  }
4676  barray[xx] =(char *)(((long)barray[xx] + cache_size ) &
4677  ~(cache_size-1));
4678  }
4679 #ifdef _64BIT_ARCH_
4681 #else
4682  childids[xx] = mythread_create( thread_reverse_read_test,(void *)(long)xx);
4683 #endif
4684  if(childids[xx]==-1){
4685  printf("\nThread create failed\n");
4686  for(xy = 0; xy< xx ; xy++){
4687  kill((pid_t)myid,(int)SIGTERM);
4688  }
4689  exit(35);
4690  }
4691  }
4692  }
4693 #endif
4694  if(myid == (long long)getpid()){
4695  if(distributed && master_iozone)
4696  {
4698  }
4699  for(i=0;i<num_child; i++){ /* wait for children to start */
4700  child_stat = (struct child_stats *)&shmaddr[i];
4702  Poll((long long)1);
4703  }
4704  for(i=0;i<num_child; i++){
4705  child_stat = (struct child_stats *)&shmaddr[i];
4706  child_stat->flag = CHILD_STATE_BEGIN; /* tell children to go */
4707  if(delay_start!=0)
4708  Poll((long long)delay_start);
4709  if(distributed && master_iozone)
4711  }
4712  starttime1 = time_so_far();
4713  }
4714 
4715  getout=0;
4716  if(myid == (long long)getpid()){ /* Parent here */
4717  for( i = 0; i < num_child; i++){ /* wait for children to stop */
4718  child_stat = (struct child_stats *)&shmaddr[i];
4719  if(distributed && master_iozone)
4720  {
4721  printf("\n\tTest running:");
4722  wait_dist_join();
4723  break;
4724  }
4725  else
4726  {
4727  if(use_thread)
4728  {
4729  thread_join(childids[i],(void *)&pstatus);
4730  }
4731  else
4732  {
4733  wait(0);
4734  }
4735  }
4736  if(!jstarttime)
4737  jstarttime = time_so_far();
4738  }
4739  jtime = (time_so_far()-jstarttime)-time_res;
4740  if(jtime < (double).000001)
4741  {
4742  jtime=time_res;
4743  }
4744  }
4745  total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
4746  if(total_time < (double).000001)
4747  {
4749  if(rec_prob < reclen)
4750  rec_prob = reclen;
4751  res_prob=1;
4752  }
4753 #ifdef JTIME
4754  total_time=total_time-jtime;/* Remove the join time */
4755  if(!silent) printf("\nJoin time %10.2f\n",jtime);
4756 #endif
4757  total_kilos=0;
4758  ptotal=0;
4759  min_throughput=max_throughput=min_xfer=0;
4760  if(!silent) printf("\n");
4761  for(xyz=0;xyz<num_child;xyz++){
4762  child_stat = (struct child_stats *)&shmaddr[xyz];
4764  ptotal+=child_stat->actual;
4765  if(!min_xfer)
4766  min_xfer=child_stat->actual;
4767  if(child_stat->actual < min_xfer)
4768  min_xfer=child_stat->actual;
4769  if(!min_throughput)
4770  min_throughput=child_stat->throughput;
4771  if(child_stat->throughput < min_throughput)
4772  min_throughput=child_stat->throughput;
4773  if(child_stat->throughput > max_throughput)
4774  max_throughput=child_stat->throughput;
4775  /* walltime += child_stat->walltime; */
4777  /* Get the earliest start time and latest fini time to calc. elapsed time. */
4780  if (child_stat->walltime > walltime)
4782  }
4783  avg_throughput=total_kilos/num_child;
4784  if(cpuutilflag)
4785  {
4786 /*
4787  if (walltime < cputime_res)
4788  walltime = 0.0;
4789 */
4790  if (cputime < cputime_res)
4791  cputime = 0.0;
4792  }
4793  if(cpuutilflag)
4794  store_times (walltime, cputime); /* Must be Before store_dvalue(). */
4796 #ifdef NO_PRINT_LLD
4797  if(!silent) printf("\tChildren see throughput for %ld reverse readers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
4798  if(!silent && !distributed) printf("\tParent sees throughput for %ld reverse readers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
4799 #else
4800  if(!silent) printf("\tChildren see throughput for %lld reverse readers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
4801  if(!silent && !distributed) printf("\tParent sees throughput for %lld reverse readers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
4802 #endif
4803  if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
4804  if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
4805  if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
4806  if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
4807  /* CPU% can be > 100.0 for multiple CPUs */
4808  if(cpuutilflag)
4809  {
4810  if(walltime == 0.0)
4811  {
4812  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
4813  walltime, cputime, 0.0);
4814  }
4815  else
4816  {
4817  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
4818  walltime, cputime, 100.0 * cputime / walltime);
4819  }
4820  }
4821  if(Cflag)
4822  {
4823  for(xyz=0;xyz<num_child;xyz++)
4824  {
4825  child_stat = (struct child_stats *) &shmaddr[xyz];
4826  if(cpuutilflag)
4827  {
4828  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
4829  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime,
4831  }
4832  else
4833  {
4834  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
4835  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
4836  }
4837  }
4838  }
4839  if((!distributed) || (distributed && master_iozone))
4840  stop_monitor("Revread");
4841  sync();
4842  sleep(2);
4843  if(restf)
4844  sleep((int)rest_val);
4845  if(distributed && master_iozone)
4846  {
4848  cleanup_comm();
4849  }
4850 next2:
4851  if(include_tflag)
4852  if(!(include_mask & (long long)STRIDE_READ_MASK))
4853  goto next3;
4854  /**************************************************************/
4855  /*** stride reader throughput tests **************************/
4856  /**************************************************************/
4857  toutputindex++;
4858  strcpy(&toutput[toutputindex][0],throughput_tests[5]);
4859  if((!distributed) || (distributed && master_iozone))
4860  start_monitor("Strideread");
4861  walltime = 0.0;
4862  cputime = 0.0;
4863  jstarttime=0;
4864  sync();
4865  sleep(2);
4866  *stop_flag=0;
4867  total_kilos=0;
4868  /* Hooks to start the distributed Iozone client/server code */
4869  if(distributed)
4870  {
4871  use_thread=0; /* Turn of any Posix threads */
4872  if(master_iozone)
4874  else
4875  become_client();
4876  }
4877  if(!use_thread)
4878  {
4879  for(xx = 0; xx< num_child ; xx++){
4880  chid=xx;
4882  if(childids[xx]==-1){
4883  printf("\nFork failed\n");
4884  for(xy = 0; xy< xx ; xy++){
4885  Kill((long long)childids[xy],(long long)SIGTERM);
4886  }
4887  exit(36);
4888  }
4889  if(childids[xx]==0){
4890 #ifdef _64BIT_ARCH_
4891  thread_stride_read_test((void *)xx);
4892 #else
4893  thread_stride_read_test((void *)((long)xx));
4894 #endif
4895  }
4896  }
4897  }
4898 #ifndef NO_THREADS
4899  else
4900  {
4901  for(xx = 0; xx< num_child ; xx++){ /* Create the children */
4902  chid=xx;
4903  if(!barray[xx])
4904  {
4905  barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
4906  if(barray[xx] == 0) {
4907  perror("Memory allocation failed:");
4908  exit(26);
4909  }
4910  barray[xx] =(char *)(((long)barray[xx] + cache_size ) &
4911  ~(cache_size-1));
4912  }
4913 #ifdef _64BIT_ARCH_
4915 #else
4916  childids[xx] = mythread_create( thread_stride_read_test,(void *)(long)xx);
4917 #endif
4918  if(childids[xx]==-1){
4919  printf("\nThread create failed\n");
4920  for(xy = 0; xy< xx ; xy++){
4921  kill((pid_t)myid,(int)SIGTERM);
4922  }
4923  exit(37);
4924  }
4925  }
4926  }
4927 #endif
4928  if(myid == (long long)getpid()){
4929  if(distributed && master_iozone)
4930  {
4932  }
4933  for(i=0;i<num_child; i++){ /* wait for children to start */
4934  child_stat = (struct child_stats *)&shmaddr[i];
4936  Poll((long long)1);
4937  }
4938  for(i=0;i<num_child; i++){
4939  child_stat = (struct child_stats *)&shmaddr[i];
4940  child_stat->flag = CHILD_STATE_BEGIN; /* tell children to go */
4941  if(delay_start!=0)
4942  Poll((long long)delay_start);
4943  if(distributed && master_iozone)
4945  }
4946  starttime1 = time_so_far();
4947  }
4948 
4949  getout=0;
4950  if(myid == (long long)getpid()){ /* Parent here */
4951  for( i = 0; i < num_child; i++){ /* wait for children to stop */
4952  child_stat = (struct child_stats *)&shmaddr[i];
4953  if(distributed && master_iozone)
4954  {
4955  printf("\n\tTest running:");
4956  wait_dist_join();
4957  break;
4958  }
4959  else
4960  {
4961  if(use_thread)
4962  {
4963  thread_join(childids[i],(void *)&pstatus);
4964  }
4965  else
4966  {
4967  wait(0);
4968  }
4969  }
4970  if(!jstarttime)
4971  jstarttime = time_so_far();
4972  }
4973  jtime = (time_so_far()-jstarttime)-time_res;
4974  if(jtime < (double).000001)
4975  {
4976  jtime=time_res;
4977  }
4978  }
4979  total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
4980  if(total_time < (double).000001)
4981  {
4983  if(rec_prob < reclen)
4984  rec_prob = reclen;
4985  res_prob=1;
4986  }
4987 #ifdef JTIME
4988  total_time=total_time-jtime;/* Remove the join time */
4989  if(!silent) printf("\nJoin time %10.2f\n",jtime);
4990 #endif
4991  total_kilos=0;
4992  ptotal=0;
4993  min_throughput=max_throughput=min_xfer=0;
4994  if(!silent) printf("\n");
4995  for(xyz=0;xyz<num_child;xyz++){
4996  child_stat = (struct child_stats *)&shmaddr[xyz];
4998  ptotal+=child_stat->actual;
4999  if(!min_xfer)
5000  min_xfer=child_stat->actual;
5001  if(child_stat->actual < min_xfer)
5002  min_xfer=child_stat->actual;
5003  if(!min_throughput)
5004  min_throughput=child_stat->throughput;
5005  if(child_stat->throughput < min_throughput)
5006  min_throughput=child_stat->throughput;
5007  if(child_stat->throughput > max_throughput)
5008  max_throughput=child_stat->throughput;
5009  /* walltime += child_stat->walltime; */
5011  /* Get the biggest walltime */
5014  if (child_stat->walltime > walltime)
5016  }
5017  avg_throughput=total_kilos/num_child;
5018  if(cpuutilflag)
5019  {
5020 /*
5021  if (walltime < cputime_res)
5022  walltime = 0.0;
5023 */
5024  if (cputime < cputime_res)
5025  cputime = 0.0;
5026  }
5027  if(cpuutilflag)
5028  store_times (walltime, cputime); /* Must be Before store_dvalue(). */
5030 #ifdef NO_PRINT_LLD
5031  if(!silent) printf("\tChildren see throughput for %ld stride readers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
5032  if(!silent && !distributed) printf("\tParent sees throughput for %ld stride readers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
5033 #else
5034  if(!silent) printf("\tChildren see throughput for %lld stride readers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
5035  if(!silent && !distributed) printf("\tParent sees throughput for %lld stride readers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
5036 #endif
5037  if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
5038  if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
5039  if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
5040  if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
5041  /* CPU% can be > 100.0 for multiple CPUs */
5042  if(cpuutilflag)
5043  {
5044  if(walltime == 0.0)
5045  {
5046  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
5047  walltime, cputime, 0.0);
5048  }
5049  else
5050  {
5051  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
5052  walltime, cputime, 100.0 * cputime / walltime);
5053  }
5054  }
5055  if(Cflag)
5056  {
5057  for(xyz=0;xyz<num_child;xyz++)
5058  {
5059  child_stat = (struct child_stats *) &shmaddr[xyz];
5060  if(cpuutilflag)
5061  {
5062  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
5063  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime,
5065  }
5066  else
5067  {
5068  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
5069  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
5070  }
5071  }
5072  }
5073  if((!distributed) || (distributed && master_iozone))
5074  stop_monitor("Strideread");
5075  sync();
5076  sleep(2);
5077  if(restf)
5078  sleep((int)rest_val);
5079  if(distributed && master_iozone)
5080  {
5082  cleanup_comm();
5083  }
5084  /**************************************************************/
5085  /*** random reader throughput tests ***************************/
5086  /**************************************************************/
5087 next3:
5088  if(include_tflag)
5089  if(!(include_mask & (long long)RANDOM_RW_MASK))
5090  goto next4;
5091 
5092  toutputindex++;
5093  strcpy(&toutput[toutputindex][0],throughput_tests[6]);
5094  if((!distributed) || (distributed && master_iozone))
5095  start_monitor("Randread");
5096  walltime = 0.0;
5097  cputime = 0.0;
5098  jstarttime=0;
5099  sync();
5100  sleep(2);
5101  *stop_flag=0;
5102  total_kilos=0;
5103  /* Hooks to start the distributed Iozone client/server code */
5104  if(distributed)
5105  {
5106  use_thread=0; /* Turn of any Posix threads */
5107  if(master_iozone)
5109  else
5110  become_client();
5111  }
5112  if(!use_thread)
5113  {
5114  for(xx = 0; xx< num_child ; xx++){
5115  chid=xx;
5117  if(childids[xx]==-1){
5118  printf("\nFork failed\n");
5119  for(xy = 0; xy< xx ; xy++){
5120  Kill((long long)childids[xy],(long long)SIGTERM);
5121  }
5122  exit(38);
5123  }
5124  if(childids[xx]==0){
5125 #ifdef _64BIT_ARCH_
5126  thread_ranread_test((void *)xx);
5127 #else
5128  thread_ranread_test((void *)((long)xx));
5129 #endif
5130  }
5131  }
5132  }
5133 #ifndef NO_THREADS
5134  else
5135  {
5136  for(xx = 0; xx< num_child ; xx++){ /* Create the children */
5137  chid=xx;
5138  if(!barray[xx])
5139  {
5140  barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
5141  if(barray[xx] == 0) {
5142  perror("Memory allocation failed:");
5143  exit(26);
5144  }
5145  barray[xx] =(char *)(((long)barray[xx] + cache_size ) &
5146  ~(cache_size-1));
5147  }
5148 #ifdef _64BIT_ARCH_
5150 #else
5151  childids[xx] = mythread_create( thread_ranread_test,(void *)(long)xx);
5152 #endif
5153  if(childids[xx]==-1){
5154  printf("\nThread create failed\n");
5155  for(xy = 0; xy< xx ; xy++){
5156  kill((pid_t)myid,(int)SIGTERM);
5157  }
5158  exit(39);
5159  }
5160  }
5161  }
5162 #endif
5163  if(myid == (long long)getpid()){
5164  if(distributed && master_iozone)
5165  {
5167  }
5168  for(i=0;i<num_child; i++){ /* wait for children to start */
5169  child_stat = (struct child_stats *)&shmaddr[i];
5171  Poll((long long)1);
5172  }
5173  for(i=0;i<num_child; i++){
5174  child_stat = (struct child_stats *)&shmaddr[i];
5175  child_stat->flag = CHILD_STATE_BEGIN; /* tell children to go */
5176  if(delay_start!=0)
5177  Poll((long long)delay_start);
5178  if(distributed && master_iozone)
5180  }
5181  starttime1 = time_so_far();
5182  }
5183 
5184  getout=0;
5185  if(myid == (long long)getpid()){ /* Parent here */
5186  for( i = 0; i < num_child; i++){ /* wait for children to stop */
5187  child_stat = (struct child_stats *)&shmaddr[i];
5188  if(distributed && master_iozone)
5189  {
5190  printf("\n\tTest running:");
5191  wait_dist_join();
5192  break;
5193  }
5194  else
5195  {
5196  if(use_thread)
5197  {
5198  thread_join(childids[i],(void *)&pstatus);
5199  }
5200  else
5201  {
5202  wait(0);
5203  }
5204  }
5205  if(!jstarttime)
5206  jstarttime = time_so_far();
5207  }
5208  jtime = (time_so_far()-jstarttime)-time_res;
5209  if(jtime < (double).000001)
5210  {
5211  jtime=time_res;
5212  }
5213  }
5214  total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
5215  if(total_time < (double).000001)
5216  {
5218  if(rec_prob < reclen)
5219  rec_prob = reclen;
5220  res_prob=1;
5221  }
5222 #ifdef JTIME
5223  total_time=total_time-jtime;/* Remove the join time */
5224  if(!silent) printf("\nJoin time %10.2f\n",jtime);
5225 #endif
5226  total_kilos=0;
5227  ptotal=0;
5228  min_throughput=max_throughput=min_xfer=0;
5229  if(!silent) printf("\n");
5230  for(xyz=0;xyz<num_child;xyz++){
5231  child_stat = (struct child_stats *)&shmaddr[xyz];
5233  ptotal+=child_stat->actual;
5234  if(!min_xfer)
5235  min_xfer=child_stat->actual;
5236  if(child_stat->actual < min_xfer)
5237  min_xfer=child_stat->actual;
5238  if(!min_throughput)
5239  min_throughput=child_stat->throughput;
5240  if(child_stat->throughput < min_throughput)
5241  min_throughput=child_stat->throughput;
5242  if(child_stat->throughput > max_throughput)
5243  max_throughput=child_stat->throughput;
5245  /* Get the biggest walltime */
5248  if (child_stat->walltime > walltime)
5250  }
5251  avg_throughput=total_kilos/num_child;
5252  if(cpuutilflag)
5253  {
5254  if (cputime < cputime_res)
5255  cputime = 0.0;
5256  }
5257  if(cpuutilflag)
5258  store_times (walltime, cputime); /* Must be Before store_dvalue(). */
5260 #ifdef NO_PRINT_LLD
5261  if(!silent) printf("\tChildren see throughput for %ld random readers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
5262  if(!silent && !distributed) printf("\tParent sees throughput for %ld random readers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
5263 #else
5264  if(!silent) printf("\tChildren see throughput for %lld random readers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
5265  if(!silent && !distributed) printf("\tParent sees throughput for %lld random readers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
5266 #endif
5267  if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
5268  if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
5269  if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
5270  if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
5271  /* CPU% can be > 100.0 for multiple CPUs */
5272  if(cpuutilflag)
5273  {
5274  if(walltime == 0.0)
5275  {
5276  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
5277  walltime, cputime, 0.0);
5278  }
5279  else
5280  {
5281  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
5282  walltime, cputime, 100.0 * cputime / walltime);
5283  }
5284  }
5285  if(Cflag)
5286  {
5287  for(xyz=0;xyz<num_child;xyz++)
5288  {
5289  child_stat = (struct child_stats *) &shmaddr[xyz];
5290  if(cpuutilflag)
5291  {
5292  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
5293  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime,
5295  }
5296  else
5297  {
5298  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
5299  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
5300  }
5301  }
5302  }
5303  if((!distributed) || (distributed && master_iozone))
5304  stop_monitor("Randread");
5305  sync();
5306  sleep(2);
5307  if(restf)
5308  sleep((int)rest_val);
5309  if(distributed && master_iozone)
5310  {
5312  cleanup_comm();
5313  }
5314  /**************************************************************/
5315  /*** mixed workload throughput tests ***************************/
5316  /**************************************************************/
5317 next4:
5318  if(include_tflag)
5319  if(!(include_mask & (long long)RANDOM_MIX_MASK))
5320  goto next5;
5321 
5322  toutputindex++;
5323  strcpy(&toutput[toutputindex][0],throughput_tests[7]);
5324  if((!distributed) || (distributed && master_iozone))
5325  start_monitor("Mixed");
5326  walltime = 0.0;
5327  cputime = 0.0;
5328  jstarttime=0;
5329  sync();
5330  sleep(2);
5331  *stop_flag=0;
5332  total_kilos=0;
5333  /* Hooks to start the distributed Iozone client/server code */
5334  if(distributed)
5335  {
5336  use_thread=0; /* Turn of any Posix threads */
5337  if(master_iozone)
5339  else
5340  become_client();
5341  }
5342  if(!use_thread)
5343  {
5344  for(xx = 0; xx< num_child ; xx++){
5345  chid=xx;
5347  if(childids[xx]==-1){
5348  printf("\nFork failed\n");
5349  for(xy = 0; xy< xx ; xy++){
5350  Kill((long long)childids[xy],(long long)SIGTERM);
5351  }
5352  exit(38);
5353  }
5354  if(childids[xx]==0){
5355 #ifdef _64BIT_ARCH_
5356  thread_mix_test((void *)xx);
5357 #else
5358  thread_mix_test((void *)((long)xx));
5359 #endif
5360  }
5361  }
5362  }
5363 #ifndef NO_THREADS
5364  else
5365  {
5366  for(xx = 0; xx< num_child ; xx++){ /* Create the children */
5367  chid=xx;
5368  if(!barray[xx])
5369  {
5370  barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
5371  if(barray[xx] == 0) {
5372  perror("Memory allocation failed:");
5373  exit(26);
5374  }
5375  barray[xx] =(char *)(((long)barray[xx] + cache_size ) &
5376  ~(cache_size-1));
5377  }
5378 #ifdef _64BIT_ARCH_
5380 #else
5381  childids[xx] = mythread_create( thread_mix_test,(void *)(long)xx);
5382 #endif
5383  if(childids[xx]==-1){
5384  printf("\nThread create failed\n");
5385  for(xy = 0; xy< xx ; xy++){
5386  kill((pid_t)myid,(int)SIGTERM);
5387  }
5388  exit(39);
5389  }
5390  }
5391  }
5392 #endif
5393  if(myid == (long long)getpid()){
5394  if(distributed && master_iozone)
5395  {
5397  }
5398  for(i=0;i<num_child; i++){ /* wait for children to start */
5399  child_stat = (struct child_stats *)&shmaddr[i];
5401  Poll((long long)1);
5402  }
5403  for(i=0;i<num_child; i++){
5404  child_stat = (struct child_stats *)&shmaddr[i];
5405  child_stat->flag = CHILD_STATE_BEGIN; /* tell children to go */
5406  if(delay_start!=0)
5407  Poll((long long)delay_start);
5408  if(distributed && master_iozone)
5410  }
5411  starttime1 = time_so_far();
5412  }
5413 
5414  getout=0;
5415  if(myid == (long long)getpid()){ /* Parent here */
5416  for( i = 0; i < num_child; i++){ /* wait for children to stop */
5417  child_stat = (struct child_stats *)&shmaddr[i];
5418  if(distributed && master_iozone)
5419  {
5420  printf("\n\tTest running:");
5421  wait_dist_join();
5422  break;
5423  }
5424  else
5425  {
5426  if(use_thread)
5427  {
5428  thread_join(childids[i],(void *)&pstatus);
5429  }
5430  else
5431  {
5432  wait(0);
5433  }
5434  }
5435  if(!jstarttime)
5436  jstarttime = time_so_far();
5437  }
5438  jtime = (time_so_far()-jstarttime)-time_res;
5439  if(jtime < (double).000001)
5440  {
5441  jtime=time_res;
5442  }
5443  }
5444  total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
5445  if(total_time < (double).000001)
5446  {
5448  if(rec_prob < reclen)
5449  rec_prob = reclen;
5450  res_prob=1;
5451  }
5452 #ifdef JTIME
5453  total_time=total_time-jtime;/* Remove the join time */
5454  if(!silent) printf("\nJoin time %10.2f\n",jtime);
5455 #endif
5456  total_kilos=0;
5457  ptotal=0;
5458  min_throughput=max_throughput=min_xfer=0;
5459  if(!silent) printf("\n");
5460  for(xyz=0;xyz<num_child;xyz++){
5461  child_stat = (struct child_stats *)&shmaddr[xyz];
5463  ptotal+=child_stat->actual;
5464  if(!min_xfer)
5465  min_xfer=child_stat->actual;
5466  if(child_stat->actual < min_xfer)
5467  min_xfer=child_stat->actual;
5468  if(!min_throughput)
5469  min_throughput=child_stat->throughput;
5470  if(child_stat->throughput < min_throughput)
5471  min_throughput=child_stat->throughput;
5472  if(child_stat->throughput > max_throughput)
5473  max_throughput=child_stat->throughput;
5475  /* Get the biggest walltime */
5478  if (child_stat->walltime > walltime)
5480  }
5481  avg_throughput=total_kilos/num_child;
5482  if(cpuutilflag)
5483  {
5484  if (cputime < cputime_res)
5485  cputime = 0.0;
5486  }
5487  if(cpuutilflag)
5488  store_times (walltime, cputime); /* Must be Before store_dvalue(). */
5490 #ifdef NO_PRINT_LLD
5491  if(!silent) printf("\tChildren see throughput for %ld mixed workload \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
5492  if(!silent && !distributed) printf("\tParent sees throughput for %ld mixed workload \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
5493 #else
5494  if(!silent) printf("\tChildren see throughput for %lld mixed workload \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
5495  if(!silent && !distributed) printf("\tParent sees throughput for %lld mixed workload \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
5496 #endif
5497  if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
5498  if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
5499  if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
5500  if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
5501  /* CPU% can be > 100.0 for multiple CPUs */
5502  if(cpuutilflag)
5503  {
5504  if(walltime == 0.0)
5505  {
5506  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
5507  walltime, cputime, 0.0);
5508  }
5509  else
5510  {
5511  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
5512  walltime, cputime, 100.0 * cputime / walltime);
5513  }
5514  }
5515  if(Cflag)
5516  {
5517  for(xyz=0;xyz<num_child;xyz++)
5518  {
5519  child_stat = (struct child_stats *) &shmaddr[xyz];
5520  if(cpuutilflag)
5521  {
5522  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
5523  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime,
5525  }
5526  else
5527  {
5528  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
5529  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
5530  }
5531  }
5532  }
5533  if((!distributed) || (distributed && master_iozone))
5534  stop_monitor("Mixed");
5535  sync();
5536  sleep(2);
5537  if(restf)
5538  sleep((int)rest_val);
5539  if(distributed && master_iozone)
5540  {
5542  cleanup_comm();
5543  }
5544 next5:
5545  /**************************************************************/
5546  /*** random writer throughput tests **************************/
5547  /**************************************************************/
5548  if(include_tflag)
5549  if(!(include_mask & (long long)RANDOM_RW_MASK) || no_write)
5550  goto next6;
5551 
5552  toutputindex++;
5553  strcpy(&toutput[toutputindex][0],throughput_tests[8]);
5554  if((!distributed) || (distributed && master_iozone))
5555  start_monitor("Randwrite");
5556  walltime = 0.0;
5557  cputime = 0.0;
5558  jstarttime=0;
5559  sync();
5560  sleep(2);
5561  *stop_flag=0;
5562  total_kilos=0;
5563  /* Hooks to start the distributed Iozone client/server code */
5564  if(distributed)
5565  {
5566  use_thread=0; /* Turn of any Posix threads */
5567  if(master_iozone)
5569  else
5570  become_client();
5571  }
5572  if(!use_thread)
5573  {
5574  for(xx = 0; xx< num_child ; xx++){
5575  chid=xx;
5577  if(childids[xx]==-1){
5578  printf("\nFork failed\n");
5579  for(xy = 0; xy< xx ; xy++){
5580  Kill((long long)childids[xy],(long long)SIGTERM);
5581  }
5582  exit(38);
5583  }
5584  if(childids[xx]==0){
5585 #ifdef _64BIT_ARCH_
5586  thread_ranwrite_test((void *)xx);
5587 #else
5588  thread_ranwrite_test((void *)((long)xx));
5589 #endif
5590  }
5591  }
5592  }
5593 #ifndef NO_THREADS
5594  else
5595  {
5596  for(xx = 0; xx< num_child ; xx++){ /* Create the children */
5597  chid=xx;
5598  if(!barray[xx])
5599  {
5600  barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
5601  if(barray[xx] == 0) {
5602  perror("Memory allocation failed:");
5603  exit(26);
5604  }
5605  barray[xx] =(char *)(((long)barray[xx] + cache_size ) &
5606  ~(cache_size-1));
5607  }
5608 #ifdef _64BIT_ARCH_
5610 #else
5611  childids[xx] = mythread_create( thread_ranwrite_test,(void *)(long)xx);
5612 #endif
5613  if(childids[xx]==-1){
5614  printf("\nThread create failed\n");
5615  for(xy = 0; xy< xx ; xy++){
5616  kill((pid_t)myid,(int)SIGTERM);
5617  }
5618  exit(39);
5619  }
5620  }
5621  }
5622 #endif
5623  if(myid == (long long)getpid()){
5624  if(distributed && master_iozone)
5625  {
5627  }
5628  for(i=0;i<num_child; i++){ /* wait for children to start */
5629  child_stat = (struct child_stats *)&shmaddr[i];
5631  Poll((long long)1);
5632  }
5633  for(i=0;i<num_child; i++){
5634  child_stat = (struct child_stats *)&shmaddr[i];
5635  child_stat->flag = CHILD_STATE_BEGIN; /* tell children to go */
5636  if(delay_start!=0)
5637  Poll((long long)delay_start);
5638  if(distributed && master_iozone)
5640  }
5641  starttime1 = time_so_far();
5642  }
5643 
5644  getout=0;
5645  if(myid == (long long)getpid()){ /* Parent here */
5646  for( i = 0; i < num_child; i++){ /* wait for children to stop */
5647  child_stat = (struct child_stats *)&shmaddr[i];
5648  if(distributed && master_iozone)
5649  {
5650  printf("\n\tTest running:");
5651  wait_dist_join();
5652  break;
5653  }
5654  else
5655  {
5656  if(use_thread)
5657  {
5658  thread_join(childids[i],(void *)&pstatus);
5659  }
5660  else
5661  {
5662  wait(0);
5663  }
5664  }
5665  if(!jstarttime)
5666  jstarttime = time_so_far();
5667  }
5668  jtime = (time_so_far()-jstarttime)-time_res;
5669  if(jtime < (double).000001)
5670  {
5671  jtime=time_res;
5672  }
5673  }
5674  total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
5675  if(total_time < (double).000001)
5676  {
5678  if(rec_prob < reclen)
5679  rec_prob = reclen;
5680  res_prob=1;
5681  }
5682 #ifdef JTIME
5683  total_time=total_time-jtime;/* Remove the join time */
5684  if(!silent) printf("\nJoin time %10.2f\n",jtime);
5685 #endif
5686  total_kilos=0;
5687  ptotal=0;
5688  min_throughput=max_throughput=min_xfer=0;
5689  if(!silent) printf("\n");
5690  for(xyz=0;xyz<num_child;xyz++){
5691  child_stat = (struct child_stats *)&shmaddr[xyz];
5693  ptotal+=child_stat->actual;
5694  if(!min_xfer)
5695  min_xfer=child_stat->actual;
5696  if(child_stat->actual < min_xfer)
5697  min_xfer=child_stat->actual;
5698  if(!min_throughput)
5699  min_throughput=child_stat->throughput;
5700  if(child_stat->throughput < min_throughput)
5701  min_throughput=child_stat->throughput;
5702  if(child_stat->throughput > max_throughput)
5703  max_throughput=child_stat->throughput;
5705  /* Get the biggest walltime */
5708  if (child_stat->walltime > walltime)
5710  }
5711  avg_throughput=total_kilos/num_child;
5712  if(cpuutilflag)
5713  {
5714  if (cputime < cputime_res)
5715  cputime = 0.0;
5716  }
5717  if(cpuutilflag)
5718  store_times (walltime, cputime); /* Must be Before store_dvalue(). */
5720 #ifdef NO_PRINT_LLD
5721  if(!silent) printf("\tChildren see throughput for %ld random writers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
5722  if(!silent && !distributed) printf("\tParent sees throughput for %ld random writers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
5723 #else
5724  if(!silent) printf("\tChildren see throughput for %lld random writers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
5725  if(!silent && !distributed) printf("\tParent sees throughput for %lld random writers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
5726 #endif
5727  if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
5728  if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
5729  if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
5730  if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
5731  /* CPU% can be > 100.0 for multiple CPUs */
5732  if(cpuutilflag)
5733  {
5734  if(walltime == 0.0)
5735  {
5736  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
5737  walltime, cputime, 0.0);
5738  }
5739  else
5740  {
5741  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
5742  walltime, cputime, 100.0 * cputime / walltime);
5743  }
5744  }
5745  if(Cflag)
5746  {
5747  for(xyz=0;xyz<num_child;xyz++)
5748  {
5749  child_stat = (struct child_stats *) &shmaddr[xyz];
5750  if(cpuutilflag)
5751  {
5752  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
5753  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime,
5755  }
5756  else
5757  {
5758  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
5759  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
5760  }
5761  }
5762  }
5763  if((!distributed) || (distributed && master_iozone))
5764  stop_monitor("Randwrite");
5765  sync();
5766  sleep(2);
5767  if(restf)
5768  sleep((int)rest_val);
5769  if(distributed && master_iozone)
5770  {
5772  cleanup_comm();
5773  }
5774 next6:
5775  /**************************************************************/
5776  /*** Pwrite writer throughput tests **************************/
5777  /**************************************************************/
5778 #ifndef HAVE_PREAD
5779  goto next7;
5780 #else
5781  if(include_tflag)
5782  if(!(include_mask & (long long)PWRITER_MASK))
5783  goto next7;
5784 
5785  toutputindex++;
5786  strcpy(&toutput[toutputindex][0],throughput_tests[9]);
5787  if((!distributed) || (distributed && master_iozone))
5788  start_monitor("Pwrite");
5789  walltime = 0.0;
5790  cputime = 0.0;
5791  jstarttime=0;
5792  sync();
5793  sleep(2);
5794  *stop_flag=0;
5795  total_kilos=0;
5796  /* Hooks to start the distributed Iozone client/server code */
5797  if(distributed)
5798  {
5799  use_thread=0; /* Turn of any Posix threads */
5800  if(master_iozone)
5802  else
5803  become_client();
5804  }
5805  if(!use_thread)
5806  {
5807  for(xx = 0; xx< num_child ; xx++){
5808  chid=xx;
5810  if(childids[xx]==-1){
5811  printf("\nFork failed\n");
5812  for(xy = 0; xy< xx ; xy++){
5813  Kill((long long)childids[xy],(long long)SIGTERM);
5814  }
5815  exit(38);
5816  }
5817  if(childids[xx]==0){
5818 #ifdef _64BIT_ARCH_
5819  thread_pwrite_test((void *)xx);
5820 #else
5821  thread_pwrite_test((void *)((long)xx));
5822 #endif
5823  }
5824  }
5825  }
5826 #ifndef NO_THREADS
5827  else
5828  {
5829  for(xx = 0; xx< num_child ; xx++){ /* Create the children */
5830  chid=xx;
5831  if(!barray[xx])
5832  {
5833  barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
5834  if(barray[xx] == 0) {
5835  perror("Memory allocation failed:");
5836  exit(26);
5837  }
5838  barray[xx] =(char *)(((long)barray[xx] + cache_size ) &
5839  ~(cache_size-1));
5840  }
5841 #ifdef _64BIT_ARCH_
5842  childids[xx] = mythread_create( thread_pwrite_test,xx);
5843 #else
5844  childids[xx] = mythread_create( thread_pwrite_test,(void *)(long)xx);
5845 #endif
5846  if(childids[xx]==-1){
5847  printf("\nThread create failed\n");
5848  for(xy = 0; xy< xx ; xy++){
5849  kill((pid_t)myid,(int)SIGTERM);
5850  }
5851  exit(39);
5852  }
5853  }
5854  }
5855 #endif
5856  if(myid == (long long)getpid()){
5857  if(distributed && master_iozone)
5858  {
5860  }
5861  for(i=0;i<num_child; i++){ /* wait for children to start */
5862  child_stat = (struct child_stats *)&shmaddr[i];
5864  Poll((long long)1);
5865  }
5866  for(i=0;i<num_child; i++){
5867  child_stat = (struct child_stats *)&shmaddr[i];
5868  child_stat->flag = CHILD_STATE_BEGIN; /* tell children to go */
5869  if(delay_start!=0)
5870  Poll((long long)delay_start);
5871  if(distributed && master_iozone)
5873  }
5874  starttime1 = time_so_far();
5875  }
5876 
5877  getout=0;
5878  if(myid == (long long)getpid()){ /* Parent here */
5879  for( i = 0; i < num_child; i++){ /* wait for children to stop */
5880  child_stat = (struct child_stats *)&shmaddr[i];
5881  if(distributed && master_iozone)
5882  {
5883  printf("\n\tTest running:");
5884  wait_dist_join();
5885  break;
5886  }
5887  else
5888  {
5889  if(use_thread)
5890  {
5891  thread_join(childids[i],(void *)&pstatus);
5892  }
5893  else
5894  {
5895  wait(0);
5896  }
5897  }
5898  if(!jstarttime)
5899  jstarttime = time_so_far();
5900  }
5901  jtime = (time_so_far()-jstarttime)-time_res;
5902  if(jtime < (double).000001)
5903  {
5904  jtime=time_res;
5905  }
5906  }
5907  total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
5908  if(total_time < (double).000001)
5909  {
5911  if(rec_prob < reclen)
5912  rec_prob = reclen;
5913  res_prob=1;
5914  }
5915 #ifdef JTIME
5916  total_time=total_time-jtime;/* Remove the join time */
5917  if(!silent) printf("\nJoin time %10.2f\n",jtime);
5918 #endif
5919  total_kilos=0;
5920  ptotal=0;
5921  min_throughput=max_throughput=min_xfer=0;
5922  if(!silent) printf("\n");
5923  for(xyz=0;xyz<num_child;xyz++){
5924  child_stat = (struct child_stats *)&shmaddr[xyz];
5926  ptotal+=child_stat->actual;
5927  if(!min_xfer)
5928  min_xfer=child_stat->actual;
5929  if(child_stat->actual < min_xfer)
5930  min_xfer=child_stat->actual;
5931  if(!min_throughput)
5932  min_throughput=child_stat->throughput;
5933  if(child_stat->throughput < min_throughput)
5934  min_throughput=child_stat->throughput;
5935  if(child_stat->throughput > max_throughput)
5936  max_throughput=child_stat->throughput;
5938  /* Get the biggest walltime*/
5941  if (child_stat->walltime > walltime)
5943  }
5944  avg_throughput=total_kilos/num_child;
5945  if(cpuutilflag)
5946  {
5947  if (cputime < cputime_res)
5948  cputime = 0.0;
5949  }
5950  if(cpuutilflag)
5951  store_times (walltime, cputime); /* Must be Before store_dvalue(). */
5953 #ifdef NO_PRINT_LLD
5954  if(!silent) printf("\tChildren see throughput for %ld pwrite writers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
5955  if(!silent && !distributed) printf("\tParent sees throughput for %ld pwrite writers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
5956 #else
5957  if(!silent) printf("\tChildren see throughput for %lld pwrite writers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
5958  if(!silent && !distributed) printf("\tParent sees throughput for %lld pwrite writers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
5959 #endif
5960  if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
5961  if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
5962  if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
5963  if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
5964  /* CPU% can be > 100.0 for multiple CPUs */
5965  if(cpuutilflag)
5966  {
5967  if(walltime == 0.0)
5968  {
5969  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
5970  walltime, cputime, 0.0);
5971  }
5972  else
5973  {
5974  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
5975  walltime, cputime, 100.0 * cputime / walltime);
5976  }
5977  }
5978  if(Cflag)
5979  {
5980  for(xyz=0;xyz<num_child;xyz++)
5981  {
5982  child_stat = (struct child_stats *) &shmaddr[xyz];
5983  if(cpuutilflag)
5984  {
5985  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
5986  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime,
5988  }
5989  else
5990  {
5991  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
5992  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
5993  }
5994  }
5995  }
5996  if((!distributed) || (distributed && master_iozone))
5997  stop_monitor("Pwrite");
5998  sync();
5999  sleep(2);
6000  if(restf)
6001  sleep((int)rest_val);
6002  if(distributed && master_iozone)
6003  {
6005  cleanup_comm();
6006  }
6007 #endif
6008  /**************************************************************/
6009  /*** Pread reader throughput tests **************************/
6010  /**************************************************************/
6011 next7:
6012 
6013 #ifndef HAVE_PREAD
6014  goto next8;
6015 #else
6016  if(include_tflag)
6017  if(!(include_mask & (long long)PREADER_MASK))
6018  goto next8;
6019 
6020  toutputindex++;
6021  strcpy(&toutput[toutputindex][0],throughput_tests[10]);
6022  if((!distributed) || (distributed && master_iozone))
6023  start_monitor("Pread");
6024  walltime = 0.0;
6025  cputime = 0.0;
6026  jstarttime=0;
6027  sync();
6028  sleep(2);
6029  *stop_flag=0;
6030  total_kilos=0;
6031  /* Hooks to start the distributed Iozone client/server code */
6032  if(distributed)
6033  {
6034  use_thread=0; /* Turn of any Posix threads */
6035  if(master_iozone)
6037  else
6038  become_client();
6039  }
6040  if(!use_thread)
6041  {
6042  for(xx = 0; xx< num_child ; xx++){
6043  chid=xx;
6045  if(childids[xx]==-1){
6046  printf("\nFork failed\n");
6047  for(xy = 0; xy< xx ; xy++){
6048  Kill((long long)childids[xy],(long long)SIGTERM);
6049  }
6050  exit(38);
6051  }
6052  if(childids[xx]==0){
6053 #ifdef _64BIT_ARCH_
6054  thread_pread_test((void *)xx);
6055 #else
6056  thread_pread_test((void *)((long)xx));
6057 #endif
6058  }
6059  }
6060  }
6061 #ifndef NO_THREADS
6062  else
6063  {
6064  for(xx = 0; xx< num_child ; xx++){ /* Create the children */
6065  chid=xx;
6066  if(!barray[xx])
6067  {
6068  barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
6069  if(barray[xx] == 0) {
6070  perror("Memory allocation failed:");
6071  exit(26);
6072  }
6073  barray[xx] =(char *)(((long)barray[xx] + cache_size ) &
6074  ~(cache_size-1));
6075  }
6076 #ifdef _64BIT_ARCH_
6077  childids[xx] = mythread_create( thread_pread_test,xx);
6078 #else
6079  childids[xx] = mythread_create( thread_pread_test,(void *)(long)xx);
6080 #endif
6081  if(childids[xx]==-1){
6082  printf("\nThread create failed\n");
6083  for(xy = 0; xy< xx ; xy++){
6084  kill((pid_t)myid,(int)SIGTERM);
6085  }
6086  exit(39);
6087  }
6088  }
6089  }
6090 #endif
6091  if(myid == (long long)getpid()){
6092  if(distributed && master_iozone)
6093  {
6095  }
6096  for(i=0;i<num_child; i++){ /* wait for children to start */
6097  child_stat = (struct child_stats *)&shmaddr[i];
6099  Poll((long long)1);
6100  }
6101  for(i=0;i<num_child; i++){
6102  child_stat = (struct child_stats *)&shmaddr[i];
6103  child_stat->flag = CHILD_STATE_BEGIN; /* tell children to go */
6104  if(delay_start!=0)
6105  Poll((long long)delay_start);
6106  if(distributed && master_iozone)
6108  }
6109  starttime1 = time_so_far();
6110  }
6111 
6112  getout=0;
6113  if(myid == (long long)getpid()){ /* Parent here */
6114  for( i = 0; i < num_child; i++){ /* wait for children to stop */
6115  child_stat = (struct child_stats *)&shmaddr[i];
6116  if(distributed && master_iozone)
6117  {
6118  printf("\n\tTest running:");
6119  wait_dist_join();
6120  break;
6121  }
6122  else
6123  {
6124  if(use_thread)
6125  {
6126  thread_join(childids[i],(void *)&pstatus);
6127  }
6128  else
6129  {
6130  wait(0);
6131  }
6132  }
6133  if(!jstarttime)
6134  jstarttime = time_so_far();
6135  }
6136  jtime = (time_so_far()-jstarttime)-time_res;
6137  if(jtime < (double).000001)
6138  {
6139  jtime=time_res;
6140  }
6141  }
6142  total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
6143  if(total_time < (double).000001)
6144  {
6146  if(rec_prob < reclen)
6147  rec_prob = reclen;
6148  res_prob=1;
6149  }
6150 #ifdef JTIME
6151  total_time=total_time-jtime;/* Remove the join time */
6152  if(!silent) printf("\nJoin time %10.2f\n",jtime);
6153 #endif
6154  total_kilos=0;
6155  ptotal=0;
6156  min_throughput=max_throughput=min_xfer=0;
6157  if(!silent) printf("\n");
6158  for(xyz=0;xyz<num_child;xyz++){
6159  child_stat = (struct child_stats *)&shmaddr[xyz];
6161  ptotal+=child_stat->actual;
6162  if(!min_xfer)
6163  min_xfer=child_stat->actual;
6164  if(child_stat->actual < min_xfer)
6165  min_xfer=child_stat->actual;
6166  if(!min_throughput)
6167  min_throughput=child_stat->throughput;
6168  if(child_stat->throughput < min_throughput)
6169  min_throughput=child_stat->throughput;
6170  if(child_stat->throughput > max_throughput)
6171  max_throughput=child_stat->throughput;
6173  /* Get the biggest walltime*/
6176  if (child_stat->walltime > walltime)
6178  }
6179  avg_throughput=total_kilos/num_child;
6180  if(cpuutilflag)
6181  {
6182  if (cputime < cputime_res)
6183  cputime = 0.0;
6184  }
6185  if(cpuutilflag)
6186  store_times (walltime, cputime); /* Must be Before store_dvalue(). */
6188 #ifdef NO_PRINT_LLD
6189  if(!silent) printf("\tChildren see throughput for %ld pread readers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
6190  if(!silent && !distributed) printf("\tParent sees throughput for %ld pread readers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
6191 #else
6192  if(!silent) printf("\tChildren see throughput for %lld pread readers \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
6193  if(!silent && !distributed) printf("\tParent sees throughput for %lld pread readers \t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
6194 #endif
6195  if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
6196  if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
6197  if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
6198  if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
6199  /* CPU% can be > 100.0 for multiple CPUs */
6200  if(cpuutilflag)
6201  {
6202  if(walltime == 0.0)
6203  {
6204  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
6205  walltime, cputime, 0.0);
6206  }
6207  else
6208  {
6209  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
6210  walltime, cputime, 100.0 * cputime / walltime);
6211  }
6212  }
6213  if(Cflag)
6214  {
6215  for(xyz=0;xyz<num_child;xyz++)
6216  {
6217  child_stat = (struct child_stats *) &shmaddr[xyz];
6218  if(cpuutilflag)
6219  {
6220  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
6221  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime,
6223  }
6224  else
6225  {
6226  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
6227  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
6228  }
6229  }
6230  }
6231  if((!distributed) || (distributed && master_iozone))
6232  stop_monitor("Pread");
6233  sync();
6234  sleep(2);
6235  if(restf)
6236  sleep((int)rest_val);
6237  if(distributed && master_iozone)
6238  {
6240  cleanup_comm();
6241  }
6242 #endif
6243 next8:
6244  if(include_tflag)
6245  if(!(include_mask & (long long)FWRITER_MASK))
6246  goto next9;
6247  /**************************************************************/
6248  /*** fwriter throughput tests *********************************/
6249  /**************************************************************/
6250  if((!distributed) || (distributed && master_iozone))
6251  start_monitor("Fwrite");
6252  toutputindex++;
6253  strcpy(&toutput[toutputindex][0],throughput_tests[11]);
6254  walltime = 0.0;
6255  cputime = 0.0;
6256  jstarttime=0;
6257  total_kilos=0;
6258  if(distributed)
6259  {
6260  use_thread=0;
6261  if(master_iozone)
6263  else
6264  become_client();
6265  }
6266  if(!use_thread)
6267  {
6268  for(xx = 0; xx< num_child ; xx++){
6269  chid=xx;
6271  if(childids[xx]==-1){
6272  printf("\nFork failed\n");
6273  for(xy = 0; xy< xx ; xy++){
6274  Kill((long long)childids[xy],(long long)SIGTERM);
6275  }
6276  exit(30);
6277  }
6278  if(childids[xx]==0){
6279 #ifdef _64BIT_ARCH_
6280  thread_fwrite_test((void *)xx);
6281 #else
6282  thread_fwrite_test((void *)((long)xx));
6283 #endif
6284  }
6285  }
6286  }
6287 #ifndef NO_THREADS
6288  else
6289  {
6290  for(xx = 0; xx< num_child ; xx++){ /* Create the children */
6291  if(!barray[xx])
6292  {
6293  barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
6294  if(barray[xx] == 0) {
6295  perror("Memory allocation failed:");
6296  exit(26);
6297  }
6298  barray[xx] =(char *)(((long)barray[xx] + cache_size ) &
6299  ~(cache_size-1));
6300  }
6301 #ifdef _64BIT_ARCH_
6303 #else
6304  childids[xx] = mythread_create( thread_fwrite_test,(void *)(long)xx);
6305 #endif
6306  if(childids[xx]==-1){
6307  printf("\nThread create failed\n");
6308  for(xy = 0; xy< xx ; xy++){
6309  kill((pid_t)myid,(int)SIGTERM);
6310  }
6311  exit(31);
6312  }
6313  }
6314  }
6315 #endif
6316  if(myid == (long long)getpid()){
6317  if(distributed && master_iozone)
6318  {
6320  }
6321  for(i=0;i<num_child; i++){ /* wait for children to start */
6322  child_stat=(struct child_stats *)&shmaddr[i];
6324  Poll((long long)1);
6325  }
6326  for(i=0;i<num_child; i++)
6327  {
6328  child_stat=(struct child_stats *)&shmaddr[i];
6329  child_stat->flag = CHILD_STATE_BEGIN; /* tell children to go */
6330  if(delay_start!=0)
6331  Poll((long long)delay_start);
6332  if(distributed && master_iozone)
6334  }
6335  starttime1 = time_so_far();
6336  goto jumpend1;
6337  }
6338 jumpend1:
6339  getout=0;
6340  if(myid == (long long)getpid()){ /* Parent here */
6341  for( i = 0; i < num_child; i++){
6342  child_stat = (struct child_stats *)&shmaddr[i];
6343  if(distributed && master_iozone)
6344  {
6345  printf("\n\tTest running:");
6346  wait_dist_join();
6347  break;
6348  }
6349  else
6350  {
6351  if(use_thread)
6352  {
6353  thread_join(childids[i],(void *)&pstatus);
6354  }
6355  else
6356  {
6357  wait(0);
6358  }
6359  }
6360  if(!jstarttime)
6361  jstarttime = time_so_far();
6362  }
6363  jtime = (time_so_far()-jstarttime)-time_res;
6364  if(jtime < (double).000001)
6365  {
6366  jtime=time_res;
6367  }
6368  }
6369  total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
6370  if(total_time < (double).000001)
6371  {
6373  if(rec_prob < reclen)
6374  rec_prob = reclen;
6375  res_prob=1;
6376  }
6377 #ifdef JTIME
6378  total_time=total_time-jtime;/* Remove the join time */
6379  if(!silent) printf("\nJoin time %10.2f\n",jtime);
6380 #endif
6381 
6382  total_kilos=0;
6383  ptotal=0;
6384  min_throughput=max_throughput=min_xfer=0;
6385  if(!silent) printf("\n");
6386  for(xyz=0;xyz<num_child;xyz++){
6387  child_stat=(struct child_stats *)&shmaddr[xyz];
6389  ptotal+=child_stat->actual;
6390  if(!min_xfer)
6391  min_xfer=child_stat->actual;
6392  if(child_stat->actual < min_xfer)
6393  min_xfer=child_stat->actual;
6394  if(!min_throughput)
6395  min_throughput=child_stat->throughput;
6396  if(child_stat->throughput < min_throughput)
6397  min_throughput=child_stat->throughput;
6398  if(child_stat->throughput > max_throughput)
6399  max_throughput=child_stat->throughput;
6401  /* Get the earliest start time and latest fini time to calc. elapsed time. */
6404  if (child_stat->walltime > walltime)
6406  }
6407  avg_throughput=total_kilos/num_child;
6408  if(cpuutilflag)
6409  {
6410  if (cputime < cputime_res)
6411  cputime = 0.0;
6412  }
6413  if(cpuutilflag)
6414  store_times (walltime, cputime); /* Must be Before store_dvalue(). */
6416 #ifdef NO_PRINT_LLD
6417  if(!silent) printf("\tChildren see throughput for %2ld fwriters \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
6418  if(!silent && !distributed) printf("\tParent sees throughput for %2ld fwriters \t\t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
6419 #else
6420  if(!silent) printf("\tChildren see throughput for %2lld fwriters \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
6421  if(!silent && !distributed) printf("\tParent sees throughput for %2lld fwriters \t\t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
6422 #endif
6423  if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
6424  if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
6425  if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
6426  if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
6427  /* CPU% can be > 100.0 for multiple CPUs */
6428  if(cpuutilflag)
6429  {
6430  if(walltime == 0.0)
6431  {
6432  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
6433  walltime, cputime, 0.0);
6434  }
6435  else
6436  {
6437  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
6438  walltime, cputime, 100.0 * cputime / walltime);
6439  }
6440  }
6441  if(Cflag)
6442  {
6443  for(xyz=0;xyz<num_child;xyz++)
6444  {
6445  child_stat = (struct child_stats *) &shmaddr[xyz];
6446  if(cpuutilflag)
6447  {
6448  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
6449  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime,
6451  }
6452  else
6453  {
6454  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
6455  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
6456  }
6457  }
6458  }
6459  if((!distributed) || (distributed && master_iozone))
6460  stop_monitor("Fwrite");
6461  /**********************************************************/
6462  /*************** End of fwrite throughput ****************/
6463  /**********************************************************/
6464  sync();
6465  sleep(2);
6466  if(restf)
6467  sleep((int)rest_val);
6468  if(distributed && master_iozone)
6469  {
6471  cleanup_comm();
6472  }
6473 next9:
6474  if(include_tflag)
6475  if(!(include_mask & (long long)FREADER_MASK))
6476  goto next10;
6477  /**************************************************************/
6478  /*** freader throughput tests *********************************/
6479  /**************************************************************/
6480  if((!distributed) || (distributed && master_iozone))
6481  start_monitor("Fread");
6482  toutputindex++;
6483  strcpy(&toutput[toutputindex][0],throughput_tests[12]);
6484  walltime = 0.0;
6485  cputime = 0.0;
6486  jstarttime=0;
6487  total_kilos=0;
6488  if(distributed)
6489  {
6490  use_thread=0;
6491  if(master_iozone)
6493  else
6494  become_client();
6495  }
6496  if(!use_thread)
6497  {
6498  for(xx = 0; xx< num_child ; xx++){
6499  chid=xx;
6501  if(childids[xx]==-1){
6502  printf("\nFork failed\n");
6503  for(xy = 0; xy< xx ; xy++){
6504  Kill((long long)childids[xy],(long long)SIGTERM);
6505  }
6506  exit(30);
6507  }
6508  if(childids[xx]==0){
6509 #ifdef _64BIT_ARCH_
6510  thread_fread_test((void *)xx);
6511 #else
6512  thread_fread_test((void *)((long)xx));
6513 #endif
6514  }
6515  }
6516  }
6517 #ifndef NO_THREADS
6518  else
6519  {
6520  for(xx = 0; xx< num_child ; xx++){ /* Create the children */
6521  if(!barray[xx])
6522  {
6523  barray[xx]=(char *) alloc_mem((long long)(MAXBUFFERSIZE+cache_size),(int)0);
6524  if(barray[xx] == 0) {
6525  perror("Memory allocation failed:");
6526  exit(26);
6527  }
6528  barray[xx] =(char *)(((long)barray[xx] + cache_size ) &
6529  ~(cache_size-1));
6530  }
6531 #ifdef _64BIT_ARCH_
6533 #else
6534  childids[xx] = mythread_create( thread_fread_test,(void *)(long)xx);
6535 #endif
6536  if(childids[xx]==-1){
6537  printf("\nThread create failed\n");
6538  for(xy = 0; xy< xx ; xy++){
6539  kill((pid_t)myid,(int)SIGTERM);
6540  }
6541  exit(31);
6542  }
6543  }
6544  }
6545 #endif
6546  if(myid == (long long)getpid()){
6547  if(distributed && master_iozone)
6548  {
6550  }
6551  for(i=0;i<num_child; i++){ /* wait for children to start */
6552  child_stat=(struct child_stats *)&shmaddr[i];
6554  Poll((long long)1);
6555  }
6556  for(i=0;i<num_child; i++)
6557  {
6558  child_stat=(struct child_stats *)&shmaddr[i];
6559  child_stat->flag = CHILD_STATE_BEGIN; /* tell children to go */
6560  if(delay_start!=0)
6561  Poll((long long)delay_start);
6562  if(distributed && master_iozone)
6564  }
6565  starttime1 = time_so_far();
6566  goto jumpend3;
6567  }
6568 jumpend3:
6569  getout=0;
6570  if(myid == (long long)getpid()){ /* Parent here */
6571  for( i = 0; i < num_child; i++){
6572  child_stat = (struct child_stats *)&shmaddr[i];
6573  if(distributed && master_iozone)
6574  {
6575  printf("\n\tTest running:");
6576  wait_dist_join();
6577  break;
6578  }
6579  else
6580  {
6581  if(use_thread)
6582  {
6583  thread_join(childids[i],(void *)&pstatus);
6584  }
6585  else
6586  {
6587  wait(0);
6588  }
6589  }
6590  if(!jstarttime)
6591  jstarttime = time_so_far();
6592  }
6593  jtime = (time_so_far()-jstarttime)-time_res;
6594  if(jtime < (double).000001)
6595  {
6596  jtime=time_res;
6597  }
6598  }
6599  total_time = (time_so_far() - starttime1)-time_res; /* Parents time */
6600  if(total_time < (double).000001)
6601  {
6603  if(rec_prob < reclen)
6604  rec_prob = reclen;
6605  res_prob=1;
6606  }
6607 #ifdef JTIME
6608  total_time=total_time-jtime;/* Remove the join time */
6609  if(!silent) printf("\nJoin time %10.2f\n",jtime);
6610 #endif
6611 
6612  total_kilos=0;
6613  ptotal=0;
6614  min_throughput=max_throughput=min_xfer=0;
6615  if(!silent) printf("\n");
6616  for(xyz=0;xyz<num_child;xyz++){
6617  child_stat=(struct child_stats *)&shmaddr[xyz];
6619  ptotal+=child_stat->actual;
6620  if(!min_xfer)
6621  min_xfer=child_stat->actual;
6622  if(child_stat->actual < min_xfer)
6623  min_xfer=child_stat->actual;
6624  if(!min_throughput)
6625  min_throughput=child_stat->throughput;
6626  if(child_stat->throughput < min_throughput)
6627  min_throughput=child_stat->throughput;
6628  if(child_stat->throughput > max_throughput)
6629  max_throughput=child_stat->throughput;
6631  /* Get the earliest start time and latest fini time to calc. elapsed time. */
6634  if (child_stat->walltime > walltime)
6636  }
6637  avg_throughput=total_kilos/num_child;
6638  if(cpuutilflag)
6639  {
6640  if (cputime < cputime_res)
6641  cputime = 0.0;
6642  }
6643  if(cpuutilflag)
6644  store_times (walltime, cputime); /* Must be Before store_dvalue(). */
6646 #ifdef NO_PRINT_LLD
6647  if(!silent) printf("\tChildren see throughput for %2ld freaders \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
6648  if(!silent && !distributed) printf("\tParent sees throughput for %2ld freaders \t\t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
6649 #else
6650  if(!silent) printf("\tChildren see throughput for %2lld freaders \t= %10.2f %s/sec\n", num_child, total_kilos,unit);
6651  if(!silent && !distributed) printf("\tParent sees throughput for %2lld freaders \t\t= %10.2f %s/sec\n", num_child, (double)(ptotal)/total_time,unit);
6652 #endif
6653  if(!silent) printf("\tMin throughput per %s \t\t\t= %10.2f %s/sec \n", port,min_throughput,unit);
6654  if(!silent) printf("\tMax throughput per %s \t\t\t= %10.2f %s/sec\n", port,max_throughput,unit);
6655  if(!silent) printf("\tAvg throughput per %s \t\t\t= %10.2f %s/sec\n", port,avg_throughput,unit);
6656  if(!silent) printf("\tMin xfer \t\t\t\t\t= %10.2f %s\n", min_xfer,unit);
6657  /* CPU% can be > 100.0 for multiple CPUs */
6658  if(cpuutilflag)
6659  {
6660  if(walltime == 0.0)
6661  {
6662  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
6663  walltime, cputime, 0.0);
6664  }
6665  else
6666  {
6667  if(!silent) printf("\tCPU utilization: Wall time %8.3f CPU time %8.3f CPU utilization %6.2f %%\n\n",
6668  walltime, cputime, 100.0 * cputime / walltime);
6669  }
6670  }
6671  if(Cflag)
6672  {
6673  for(xyz=0;xyz<num_child;xyz++)
6674  {
6675  child_stat = (struct child_stats *) &shmaddr[xyz];
6676  if(cpuutilflag)
6677  {
6678  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec, wall=%6.3f, cpu=%6.3f, %%=%6.2f\n",
6679  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit, child_stat->walltime,
6681  }
6682  else
6683  {
6684  if(!silent) printf("\tChild[%ld] xfer count = %10.2f %s, Throughput = %10.2f %s/sec\n",
6685  (long)xyz, child_stat->actual, unit, child_stat->throughput, unit);
6686  }
6687  }
6688  }
6689  if((!distributed) || (distributed && master_iozone))
6690  stop_monitor("Fread");
6691  /**********************************************************/
6692  /*************** End of fread throughput ******************/
6693  /**********************************************************/
6694  sync();
6695  sleep(2);
6696  if(restf)
6697  sleep((int)rest_val);
6698  if(distributed && master_iozone)
6699  {
6701  cleanup_comm();
6702  }
6703 next10:
6704  sleep(2); /* You need this. If you stop and restart the
6705  master_listen it will fail on Linux */
6706  if (!no_unlink) {
6707  /**********************************************************/
6708  /* Cleanup all of the temporary files */
6709  /* This is not really a test. It behaves like a test so */
6710  /* it can unlink all of the same files that the other */
6711  /* tests left hanging around. */
6712  /**********************************************************/
6713  /* Hooks to start the distributed Iozone client/server code */
6714  if(distributed)
6715  {
6716  use_thread=0; /* Turn of any Posix threads */
6717  if(master_iozone)
6719  else
6720  become_client();
6721  }
6722  if(!use_thread)
6723  {
6724  for(xx = 0; xx< num_child ; xx++){
6725  chid=xx;
6727  if(childids[xx]==-1){
6728  printf("\nFork failed\n");
6729  for(xy = 0; xy< xx ; xy++){
6730  Kill((long long)childids[xy],(long long)SIGTERM);
6731  }
6732  exit(28);
6733  }
6734  if(childids[xx] == 0){
6735 #ifdef _64BIT_ARCH_
6736  thread_cleanup_test((void *)xx);
6737 #else
6738  thread_cleanup_test((void *)((long)xx));
6739 #endif
6740  }
6741  }
6742  }
6743 #ifndef NO_THREADS
6744  else
6745  {
6746  for(xx = 0; xx< num_child ; xx++){ /* Create the children */
6747 #ifdef _64BIT_ARCH_
6749 #else
6750  childids[xx] = mythread_create( thread_cleanup_test,(void *)(long)xx);
6751 #endif
6752  if(childids[xx]==-1){
6753  printf("\nThread create failed\n");
6754  for(xy = 0; xy< xx ; xy++){
6755  Kill((long long)myid,(long long)SIGTERM);
6756  }
6757  exit(29);
6758  }
6759  }
6760  }
6761 #endif
6762  if((long long)myid == getpid())
6763  {
6764  if(distributed && master_iozone)
6765  {
6767  }
6768  for(i=0;i<num_child; i++){
6769  child_stat = (struct child_stats *)&shmaddr[i];
6770  /* wait for children to start */
6771  while(child_stat->flag==CHILD_STATE_HOLD)
6772  Poll((long long)1);
6773  }
6774  for(i=0;i<num_child; i++)
6775  {
6776  child_stat = (struct child_stats *)&shmaddr[i];
6777  child_stat->flag = CHILD_STATE_BEGIN; /* tell children to go */
6778  if(delay_start!=0)
6779  Poll((long long)delay_start);
6780  if(distributed && master_iozone)
6782  }
6783  }
6784 
6785  getout=0;
6786  if((long long)myid == getpid()){ /* Parent only here */
6787  for( i = 0; i < num_child; i++){
6788  child_stat=(struct child_stats *)&shmaddr[i];
6789  if(distributed && master_iozone)
6790  {
6791  printf("\n\tTest cleanup:");
6792  wait_dist_join();
6793  break;
6794  }
6795  else
6796  {
6797  if(use_thread)
6798  {
6799  thread_join(childids[i],(void *)&pstatus);
6800  }
6801  else
6802  {
6803  wait(0);
6804  }
6805  }
6806  }
6807  }
6808 
6809  for(xyz=0;xyz<num_child;xyz++){ /* Reset state to 0 (HOLD) */
6810  child_stat=(struct child_stats *)&shmaddr[xyz];
6812  }
6813  sync();
6814  sleep(2);
6815  if(distributed && master_iozone)
6816  {
6818 #ifdef Windows
6819  /* windows needs time before shutting down sockets */
6820  sleep(1);
6821 #endif
6822  cleanup_comm();
6823  }
6824  }
6825  /********************************************************/
6826  /* End of cleanup */
6827  /********************************************************/
6828  sync();
6829  if(!silent) printf("\n");
6830  if(!silent) printf("\n");
6831  return;
6832 }
6833 
6834 
6835 /************************************************************************/
6836 /* Time measurement routines. */
6837 /************************************************************************/
6838 
6839 #ifdef HAVE_ANSIC_C
6840 static double
6841 time_so_far(void)
6842 #else
6843 static double
6845 #endif
6846 {
6847 #ifdef Windows
6848  LARGE_INTEGER freq,counter;
6849  double wintime,bigcounter;
6850  struct timeval tp;
6851  /* For Windows the time_of_day() is useless. It increments in 55 milli
6852  * second increments. By using the Win32api one can get access to the
6853  * high performance measurement interfaces. With this one can get back
6854  * into the 8 to 9 microsecond resolution.
6855  */
6856  if(pit_hostname[0]){
6857  if (pit_gettimeofday(&tp, (struct timezone *) NULL, pit_hostname,
6858  pit_service) == -1)
6859  perror("pit_gettimeofday");
6860  return ((double) (tp.tv_sec)) + (((double) tp.tv_usec) * 0.000001 );
6861  }
6862  else
6863  {
6864  QueryPerformanceFrequency(&freq);
6865  QueryPerformanceCounter(&counter);
6866  bigcounter=(double)counter.HighPart *(double)0xffffffff +
6867  (double)counter.LowPart;
6868  wintime = (double)(bigcounter/(double)freq.LowPart);
6869  return((double)wintime);
6870  }
6871 #else
6872 #if defined (OSFV4) || defined(OSFV3) || defined(OSFV5)
6873  struct timespec gp;
6874 
6875  if (getclock(TIMEOFDAY, (struct timespec *) &gp) == -1)
6876  perror("getclock");
6877  return (( (double) (gp.tv_sec)) +
6878  ( ((float)(gp.tv_nsec)) * 0.000000001 ));
6879 #else
6880  struct timeval tp;
6881 
6882  if(pit_hostname[0]){
6883  if (pit_gettimeofday(&tp, (struct timezone *) NULL, pit_hostname, pit_service) == -1)
6884  perror("pit_gettimeofday");
6885  return ((double) (tp.tv_sec)) + (((double) tp.tv_usec) * 0.000001 );
6886  }
6887  else
6888  {
6889  if (gettimeofday(&tp, (struct timezone *) NULL) == -1)
6890  perror("gettimeofday");
6891  return ((double) (tp.tv_sec)) + (((double) tp.tv_usec) * 0.000001 );
6892  }
6893 #endif
6894 #endif
6895 }
6896 
6897 /************************************************************************/
6898 /* FETCHIT () */
6899 /* */
6900 /* Routine to make the on chip data cache hot for this buffer. The */
6901 /* on chip cache may have been blown by other code in the application */
6902 /* or in the OS. Remember, on some machines, the data cache is direct */
6903 /* mapped and virtual indexed. */
6904 /************************************************************************/
6905 
6906 #ifdef HAVE_ANSIC_C
6907 void fetchit(char *buffer,long long length)
6908 #else
6910 char *buffer;
6911 long long length;
6912 #endif
6913 {
6914  char *where;
6915  volatile long long x[4];
6916  long long i;
6917  where=(char *)buffer;
6918  for(i=0;i<(length/cache_line_size);i++)
6919  {
6920  x[(i & 3)]=*(where);
6921  where+=cache_line_size;
6922 
6923  }
6924 }
6925 
6926 /************************************************************************/
6927 /* Verify that the buffer contains expected pattern */
6928 /************************************************************************/
6929 /* sverify == 0 means full check of pattern for every byte. */
6930 /* severify == 1 means partial check of pattern for each page. */
6931 /* sverify == 2 means no check, but partial touch for each page. */
6932 /************************************************************************/
6933 
6934 #ifdef HAVE_ANSIC_C
6935 long long
6936 verify_buffer(volatile char *buffer,long long length, off64_t recnum, long long recsize,unsigned long long patt,
6937  char sverify)
6938 #else
6939 long long
6940 verify_buffer(buffer,length, recnum, recsize,patt,sverify)
6941 char *buffer;
6942 long long length;
6943 off64_t recnum;
6944 long long recsize;
6945 unsigned long long patt;
6946 char sverify;
6947 #endif
6948 {
6949  volatile unsigned long long *where;
6950  volatile unsigned long long dummy;
6951  long *de_ibuf, *de_obuf;
6952  long long j,k;
6953  off64_t file_position=0;
6954  off64_t i;
6955  char *where2;
6956  char *pattern_ptr;
6957  long long mpattern,xx2;
6958  unsigned int seed;
6959  unsigned long x;
6960  unsigned long long value,value1;
6961  unsigned long long a= 0x01020304;
6962  unsigned long long b = 0x05060708;
6963  unsigned long long c= 0x01010101;
6964  unsigned long long d = 0x01010101;
6965  unsigned long long pattern_buf;
6966  int lite = 1; /* Only validate 1 long when running
6967  de-deup validation */
6968 
6969  value = (a<<32) | b;
6970  value1 = (c<<32) | d;
6971 
6972  /* printf("Verify Sverify %d verify %d diag_v %d\n",sverify,verify,diag_v); */
6973  x=0;
6974  xx2=chid;
6975  if(share_file)
6976  xx2=(long long)0;
6977  mpattern=patt;
6978  pattern_buf=patt;
6979  where=(unsigned long long *)buffer;
6980  if(sverify == 2)
6981  {
6982  for(i=0;i<(length);i+=page_size)
6983  {
6984  dummy = *where;
6985  where+=(page_size/sizeof(long long));
6986  }
6987  return(0);
6988  }
6989  if(dedup)
6990  {
6991  gen_new_buf((char *)dedup_ibuf,(char *)dedup_temp, (long)recnum, (int)length,(int)dedup, (int) dedup_interior, dedup_compress, 0);
6992  de_ibuf = (long *)buffer;
6993  de_obuf = (long *)dedup_temp;
6994  if(lite) /* short touch to reduce intrusion */
6995  length = (long) sizeof(long);
6996  for(i=0;i<length/sizeof(long);i++)
6997  {
6998  if(de_ibuf[i]!= de_obuf[i])
6999  {
7000  if(!silent)
7001 #ifdef NO_PRINT_LLD
7002  printf("\nDedup mis-compare at %ld\n",
7003  (long long)((recnum*recsize)+(i*sizeof(long))) );
7004 #else
7005  printf("\nDedup mis-compare at %lld\n",
7006  (long long)((recnum*recsize)+(i*sizeof(long))) );
7007  printf("Found %.lx Expecting %.lx \n",de_ibuf[i], de_obuf[i]);
7008 #endif
7009  return(1);
7010  }
7011  }
7012  return(0);
7013  }
7014  if(diag_v)
7015  {
7016  if(no_unlink)
7017  base_time=0;
7018  seed= (unsigned int)(base_time+xx2+recnum);
7019  srand(seed);
7020  mpattern=(long long)rand();
7021  mpattern=(mpattern<<48) | (mpattern<<32) | (mpattern<<16) | mpattern;
7022  mpattern=mpattern+value;
7023  }
7024 
7025  /* printf("verify patt %llx CHid %d\n",mpattern,chid);*/
7026 
7027  where=(unsigned long long *)buffer;
7028 
7029  if(!verify)
7030  printf("\nOOPS You have entered verify_buffer unexpectedly !!! \n");
7031 
7032  if(sverify == 1)
7033  {
7034  for(i=0;i<(length);i+=page_size)
7035  {
7036  if((unsigned long long)(*where) != (unsigned long long)((pattern_buf<<32) | pattern_buf))
7037  {
7038  file_position = (off64_t)( (recnum * recsize)+ i);
7039  printf("\n\n");
7040 #ifdef NO_PRINT_LLD
7041  printf("Error in file: Found ?%lx? Expecting ?%lx? addr %lx\n",*where, (long long)((pattern_buf<<32)|pattern_buf),where);
7042  printf("Error in file: Position %ld \n",file_position);
7043  printf("Record # %ld Record size %ld kb \n",recnum,recsize/1024);
7044  printf("where %8.8llx loop %ld\n",where,i);
7045 #else
7046  printf("Error in file: Found ?%llx? Expecting ?%llx? addr %lx\n",*where, (long long)((pattern_buf<<32)|pattern_buf),((long)where));
7047  printf("Error in file: Position %lld \n",file_position);
7048  printf("Record # %lld Record size %lld kb \n",recnum,recsize/1024);
7049  printf("where %8.8lx loop %lld\n",(long)where,(long long)i);
7050 #endif
7051  return(1);
7052  }
7053  where+=(page_size/sizeof(long long));
7054  }
7055  }
7056  if(sverify == 0)
7057  {
7058  for(i=0;i<(length/cache_line_size);i++)
7059  {
7060  for(j=0;j<(cache_line_size/sizeof(long long));j++)
7061  {
7062  if(diag_v)
7063  {
7064  pattern_buf=mpattern;
7065  }
7066  else
7067  {
7068  pattern_buf= mpattern<<32 | mpattern;
7069  }
7070 
7071  pattern_ptr =(char *)&pattern_buf;
7072 
7073  if(*where != (unsigned long long)pattern_buf)
7074  {
7075  file_position = (off64_t)( (recnum * recsize))+
7076  ((i*cache_line_size)+(j*sizeof(long long)));
7077  where2=(char *)where;
7078  for(k=0;k<sizeof(long long);k++){
7079  if(*where2 != *pattern_ptr)
7080  break;
7081  where2++;
7082  pattern_ptr++;
7083  }
7084  file_position+=k;
7085  printf("\n\n");
7086 #ifdef NO_PRINT_LLD
7087  printf("Error in file: Position %ld %ld %ld \n",i,j,k);
7088  printf("Error in file: Position %ld \n",file_position);
7089  printf("Record # %ld Record size %ld kb \n",recnum,recsize/1024);
7090 #else
7091  printf("Error in file: Position %lld %lld %lld \n",i,j,k);
7092  printf("Error in file: Position %lld \n",file_position);
7093  printf("Record # %lld Record size %lld kb \n",recnum,recsize/1024);
7094 #endif
7095  printf("Found pattern: Char >>%c<< Expecting >>%c<<\n", *where2,*pattern_ptr);
7096  printf("Found pattern: Hex >>%x<< Expecting >>%x<<\n", *where2,*pattern_ptr);
7097  return(1);
7098  }
7099  where++;
7100  if(diag_v)
7101  mpattern=mpattern+value1;
7102  }
7103  }
7104  }
7105  return(0);
7106 }
7107 /************************************************************************/
7108 /* Fill the buffer */
7109 /************************************************************************/
7110 #ifdef HAVE_ANSIC_C
7111 void
7112 fill_buffer(char *buffer,long long length,long long pattern,char sverify,long long recnum)
7113 #else
7114 void
7116 char *buffer;
7117 long long length;
7118 long long pattern;
7119 long long recnum;
7120 char sverify;
7121 #endif
7122 {
7123  unsigned long long *where;
7124  long long i,j,xx2;
7125  long long mpattern;
7126  unsigned int seed;
7127  unsigned long x;
7128  unsigned long long value,value1;
7129  unsigned long long a = 0x01020304;
7130  unsigned long long b = 0x05060708;
7131  unsigned long long c = 0x01010101;
7132  unsigned long long d = 0x01010101;
7133 
7134  value = (a << 32) | b;
7135  value1 = (c << 32) | d;
7136 
7137  xx2=chid;
7138  if(share_file)
7139  xx2=(long long)0;
7140  x=0;
7141  mpattern=pattern;
7142  /* printf("Fill: Sverify %d verify %d diag_v %d\n",sverify,verify,diag_v);*/
7143  if(dedup)
7144  {
7145  gen_new_buf((char *)dedup_ibuf,(char *)buffer, (long)recnum, (int)length,(int)dedup, (int) dedup_interior, dedup_compress, 1);
7146  return;
7147  }
7148  if(diag_v)
7149  {
7150  /*if(client_iozone)
7151  base_time=0;
7152  */
7153  if(no_unlink)
7154  base_time=0;
7155  seed= (unsigned int)(base_time+xx2+recnum);
7156  srand(seed);
7157  mpattern=(long long)rand();
7158  mpattern=(mpattern<<48) | (mpattern<<32) | (mpattern<<16) | mpattern;
7159  mpattern=mpattern+value;
7160  }
7161  where=(unsigned long long *)buffer;
7162  if(sverify == 1)
7163  {
7164  for(i=0;i<(length);i+=page_size)
7165  {
7166  *where = (long long)((pattern<<32) | pattern);
7167  where+=(page_size/sizeof(long long));
7168  /* printf("Filling page %lld \n",i/page_size);*/
7169  }
7170  }
7171  else
7172  {
7173  for(i=0;i<(length/cache_line_size);i++)
7174  {
7175  for(j=0;j<(cache_line_size/sizeof(long long));j++)
7176  {
7177  if(diag_v)
7178  {
7179  *where = (long long)(mpattern);
7180  mpattern=mpattern+value1;
7181  }
7182  else
7183  *where = (long long)((pattern<<32) | pattern);
7184  where++;
7185  }
7186  }
7187  }
7188 }
7189 
7190 /************************************************************************/
7191 /* PURGEIT() */
7192 /* */
7193 /* Routine to make the on chip data cache cold for this buffer. */
7194 /* Remember, on some machines, the data cache is direct mapped and */
7195 /* virtual indexed. */
7196 /************************************************************************/
7197 
7198 #ifdef HAVE_ANSIC_C
7199 void
7200 purgeit(char *buffer,long long reclen)
7201 #else
7202 void
7204 char *buffer;
7205 long long reclen;
7206 #endif
7207 {
7208  char *where;
7209  long rsize;
7210  long tsize;
7211  VOLATILE long long x[200];
7212  long i,cache_lines_per_rec;
7213  long cache_lines_per_cache;
7214  tsize = 200;
7215  cache_lines_per_rec = (long)(reclen/cache_line_size);
7216  cache_lines_per_cache = (long)(cache_size/cache_line_size);
7217  rsize = (long)l_min((long long)cache_lines_per_rec,(long long)cache_lines_per_cache);
7218 #ifdef _64BIT_ARCH_
7219  where=(char *)pbuffer + ((unsigned long long)buffer & (cache_size-1));
7220 #else
7221  where=(char *)pbuffer + ((long)buffer & ((long)cache_size-1));
7222 #endif
7223  for(i=0;i<(rsize);i++)
7224  {
7225  x[i%tsize]=*(where);
7226  where+=cache_line_size;
7227 
7228  }
7229 }
7230 
7231 #ifdef HAVE_ANSIC_C
7232 void
7233 prepage(char *buffer,long long reclen)
7234 #else
7235 void
7237 char *buffer;
7238 long long reclen;
7239 #endif
7240 {
7241  char *where;
7242  long long i;
7243  where=(char *)buffer;
7244  for(i=0;i<(reclen/cache_line_size);i++)
7245  {
7246  *(where)=PATTERN;
7247  where+=cache_line_size;
7248  }
7249 }
7250 
7251 /************************************************************************/
7252 /* write_perf_test () */
7253 /* Write and re-write test */
7254 /************************************************************************/
7255 #ifdef HAVE_ANSIC_C
7256 void write_perf_test(off64_t kilo64,long long reclen ,long long *data1,long long *data2)
7257 #else
7258 void write_perf_test(kilo64,reclen ,data1,data2)
7259 off64_t kilo64;
7260 long long reclen;
7261 long long *data1;
7262 long long *data2;
7263 #endif
7264 {
7265  double starttime1;
7266  double writetime[2];
7267  double walltime[2], cputime[2];
7268  double qtime_start,qtime_stop;
7269  double hist_time;
7270  double compute_val = (double)0;
7271 #ifdef unix
7272  double qtime_u_start,qtime_u_stop;
7273  double qtime_s_start,qtime_s_stop;
7274 #endif
7275  long long i,j;
7276  off64_t numrecs64,traj_offset;
7277  off64_t lock_offset=0;
7278  long long Index = 0;
7279  long long file_flags = 0;
7280  long long traj_size;
7281  unsigned long long writerate[2];
7283  int ltest;
7284  char *maddr;
7285  char *wmaddr,*free_addr;
7286  char *pbuff;
7287  char *nbuff;
7288  int fd,wval;
7289 #ifdef ASYNC_IO
7290  struct cache *gc=0;
7291 #else
7292  long long *gc=0;
7293 #endif
7294 
7295  int test_foo;
7296 
7297 #ifdef unix
7298  qtime_u_start=qtime_u_stop=0;
7299  qtime_s_start=qtime_s_stop=0;
7300 #endif
7301  nbuff=wmaddr=free_addr=0;
7302  traj_offset=0;
7303  test_foo=0;
7304  hist_time=qtime_start=qtime_stop=0;
7305  maddr=0;
7306  pbuff=mainbuffer;
7307  if(w_traj_flag)
7308  {
7311  }
7312  else
7313  {
7314  numrecs64 = (kilo64*1024)/reclen;
7316  }
7317 
7318  if(Q_flag && (!wol_opened))
7319  {
7320  wol_opened++;
7321  wqfd=fopen("wol.dat","a");
7322  if(wqfd==0)
7323  {
7324  printf("Unable to open wol.dat\n");
7325  exit(40);
7326  }
7327  fprintf(wqfd,"Offset in Kbytes Latency in microseconds Transfer size in bytes\n");
7328  rwqfd=fopen("rwol.dat","a");
7329  if(rwqfd==0)
7330  {
7331  printf("Unable to open rwol.dat\n");
7332  exit(41);
7333  }
7334  fprintf(rwqfd,"Offset in Kbytes Latency in microseconds Transfer size in bytes\n");
7335  }
7336  fd = 0;
7337  if(oflag)
7338  file_flags = O_RDWR|O_SYNC;
7339  else
7340  file_flags = O_RDWR;
7341 #if defined(O_DSYNC)
7342  if(odsync)
7343  file_flags |= O_DSYNC;
7344 #endif
7345 #if defined(_HPUX_SOURCE) || defined(linux) || defined(__FreeBSD__) || defined(__DragonFly__)
7346  if(read_sync)
7347  file_flags |=O_RSYNC|O_SYNC;
7348 #endif
7349 
7350 #if ! defined(DONT_HAVE_O_DIRECT)
7351 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
7352  if(direct_flag)
7353  file_flags |=O_DIRECT;
7354 #endif
7355 #if defined(TRU64)
7356  if(direct_flag)
7357  file_flags |=O_DIRECTIO;
7358 #endif
7359 #endif
7360 
7361 /* Sanity check */
7362 /* Some filesystems do not behave correctly and fail
7363  * when this sequence is performned. This is a very
7364  * bad thing. It breaks many applications and lurks
7365  * around quietly. This code should never get
7366  * triggered, but in the case of running iozone on
7367  * an NFS client, the filesystem type on the server
7368  * that is being exported can cause this failure.
7369  * If this failure happens, then the NFS client is
7370  * going to going to have problems, but the acutal
7371  * problem is the filesystem on the NFS server.
7372  * It's not NFS, it's the local filesystem on the
7373  * NFS server that is not correctly permitting
7374  * the sequence to function.
7375  */
7376 /* _SUA_ Services for Unix Applications, under Windows
7377  does not have a truncate, so this must be skipped */
7378 #if !defined(_SUA_)
7379  if((fd = I_OPEN(filename, (int)O_CREAT|O_WRONLY,0))<0)
7380  {
7381  printf("\nCan not open temp file: %s\n",
7382  filename);
7383  perror("open");
7384  exit(44);
7385  }
7386  if(!notruncate)
7387  {
7389  {
7390  wval=ftruncate(fd,0);
7391  if(wval < 0)
7392  {
7393  printf("\n\nSanity check failed. Do not deploy this filesystem in a production environment !\n");
7394  exit(44);
7395  }
7396  }
7397  close(fd);
7398 
7400  unlink(filename);
7401  }
7402 /* Sanity check */
7403 
7404 #endif
7405  if(noretest)
7406  ltest=1;
7407  else
7408  ltest=2;
7409 
7410  for( j=0; j<ltest; j++)
7411  {
7412  if(cpuutilflag)
7413  {
7414  walltime[j] = time_so_far();
7415  cputime[j] = cputime_so_far();
7416  }
7417  if(Uflag) /* Unmount and re-mount the mountpoint */
7418  {
7420  }
7421  if(j==0)
7422  {
7423 #if defined(Windows)
7424  if(unbuffered)
7425  {
7426  hand=CreateFile(filename,
7427  GENERIC_READ|GENERIC_WRITE,
7428  FILE_SHARE_WRITE|FILE_SHARE_READ,
7429  NULL,OPEN_ALWAYS,FILE_FLAG_NO_BUFFERING|
7430  FILE_FLAG_WRITE_THROUGH|FILE_FLAG_POSIX_SEMANTICS,
7431  NULL);
7432  }
7433  else
7434  {
7435 #endif
7436  if(!notruncate)
7437  {
7438  if((fd = I_CREAT(filename, 0640))<0)
7439  {
7440  printf("\nCan not create temp file: %s\n",
7441  filename);
7442  perror("creat");
7443  exit(42);
7444  }
7445  }
7446 #if defined(Windows)
7447  }
7448 #endif
7449  }
7450 #if defined(Windows)
7451  if(unbuffered)
7452  CloseHandle(hand);
7453  else
7454  {
7455 #endif
7456  if(fd)
7457  close(fd);
7458 #if defined(Windows)
7459  }
7460 #endif
7461 
7462 #if defined(Windows)
7463  if(unbuffered)
7464  {
7465  hand=CreateFile(filename,
7466  GENERIC_READ|GENERIC_WRITE,
7467  FILE_SHARE_WRITE|FILE_SHARE_READ,
7468  NULL,OPEN_EXISTING,FILE_FLAG_NO_BUFFERING|
7469  FILE_FLAG_WRITE_THROUGH|FILE_FLAG_POSIX_SEMANTICS,
7470  NULL);
7471  }
7472  else
7473  {
7474 #endif
7475  if((fd = I_OPEN(filename, (int)file_flags,0))<0)
7476  {
7477  printf("\nCan not open temp file: %s\n",
7478  filename);
7479  perror("open");
7480  exit(44);
7481  }
7482 #if defined(Windows)
7483  }
7484 #endif
7485 #ifdef VXFS
7486  if(direct_flag)
7487  {
7488  ioctl(fd,VX_SETCACHE,VX_DIRECT);
7489  ioctl(fd,VX_GETCACHE,&test_foo);
7490  if(test_foo == 0)
7491  {
7492  if(!client_iozone)
7493  printf("\nVxFS advanced setcache feature not available.\n");
7494  exit(3);
7495  }
7496  }
7497 #endif
7498 #if defined(solaris)
7499  if(direct_flag)
7500  {
7501  test_foo = directio(fd, DIRECTIO_ON);
7502  if(test_foo != 0)
7503  {
7504  if(!client_iozone)
7505  printf("\ndirectio not available.\n");
7506  exit(3);
7507  }
7508  }
7509 #endif
7510 
7511  if(file_lock)
7512  if(mylockf((int) fd, (int) 1, (int)0)!=0)
7513  printf("File lock for write failed. %d\n",errno);
7514  if(mmapflag)
7515  {
7516  maddr=(char *)initfile(fd,filebytes64,1,PROT_READ|PROT_WRITE);
7517  }
7518  if(mmap_mix)
7519  {
7520  wval=write(fd, pbuff, (size_t) page_size);
7521  if(wval != page_size)
7522  {
7523 #ifdef NO_PRINT_LLD
7524  printf("\nError writing block %ld, fd= %d\n", (long long)0, fd);
7525 #else
7526  printf("\nError writing block %lld, fd= %d\n", (long long)0, fd);
7527 #endif
7528  if(wval==-1)
7529  perror("write");
7530  signal_handler();
7531  }
7532  I_LSEEK(fd,0,SEEK_SET);
7533  };
7534  wval=fsync(fd);
7535  if(wval==-1){
7536  perror("fsync");
7537  signal_handler();
7538  }
7539 #ifdef ASYNC_IO
7540  if(async_flag)
7541  async_init(&gc,fd,direct_flag);
7542 #endif
7543  pbuff=mainbuffer;
7544  if(fetchon)
7545  fetchit(pbuff,reclen);
7546  if(verify || dedup || dedup_interior)
7547  fill_buffer(pbuff,reclen,(long long)pattern,sverify,(long long)0);
7548  starttime1 = time_so_far();
7549 #ifdef unix
7550  if(Q_flag)
7551  {
7552  qtime_u_start=utime_so_far();
7553  qtime_s_start=stime_so_far();
7554  }
7555 #endif
7556  if(w_traj_flag)
7557  {
7558  rewind(w_traj_fd);
7559  }
7560  compute_val=(double)0;
7563  for(i=0; i<numrecs64; i++){
7564  if(w_traj_flag)
7565  {
7566  traj_offset=get_traj(w_traj_fd, (long long *)&traj_size,(float *)&compute_time,(long)1);
7567  reclen=traj_size;
7568 #if defined(Windows)
7569  if(unbuffered)
7570  SetFilePointer(hand,(LONG)traj_offset,0,FILE_BEGIN);
7571  else
7572 #endif
7573  I_LSEEK(fd,traj_offset,SEEK_SET);
7574  }
7575  if(Q_flag)
7576  {
7577 #if defined(Windows)
7578  if(unbuffered)
7579  traj_offset=SetFilePointer(hand,(LONG)0,0,FILE_CURRENT);
7580  else
7581 #endif
7582  traj_offset=I_LSEEK(fd,0,SEEK_CUR);
7583  }
7584  if(rlocking)
7585  {
7586  lock_offset=I_LSEEK(fd,0,SEEK_CUR);
7587  mylockr((int) fd, (int) 1, (int)0,
7588  lock_offset, reclen);
7589  }
7590  if((verify && diag_v) || dedup || dedup_interior)
7591  fill_buffer(pbuff,reclen,(long long)pattern,sverify,i);
7592  if(compute_flag)
7593  compute_val+=do_compute(compute_time);
7594  if(multi_buffer)
7595  {
7596  Index +=reclen;
7597  if(Index > (MAXBUFFERSIZE-reclen))
7598  Index=0;
7599  pbuff = mbuffer + Index;
7600  if(verify || dedup || dedup_interior)
7601  fill_buffer(pbuff,reclen,(long long)pattern,sverify,(long long)0);
7602  }
7603  if(async_flag && no_copy_flag)
7604  {
7605  free_addr=nbuff=(char *)malloc((size_t)reclen+page_size);
7606  nbuff=(char *)(((long)nbuff+(long)page_size) & (long)~(page_size-1));
7607  if(verify || dedup || dedup_interior)
7608  fill_buffer(nbuff,reclen,(long long)pattern,sverify,i);
7609  if(purge)
7610  purgeit(nbuff,reclen);
7611  }
7612  if(purge)
7613  purgeit(pbuff,reclen);
7614  if(Q_flag || hist_summary)
7615  {
7616  qtime_start=time_so_far();
7617  }
7618  if(mmapflag)
7619  {
7620  wmaddr = &maddr[i*reclen];
7621  fill_area((long long*)pbuff,(long long*)wmaddr,(long long)reclen);
7622  if(!mmapnsflag)
7623  {
7624  if(mmapasflag)
7625  msync(wmaddr,(size_t)reclen,MS_ASYNC);
7626  if(mmapssflag)
7627  msync(wmaddr,(size_t)reclen,MS_SYNC);
7628  }
7629  }
7630  else
7631  {
7632  if(async_flag)
7633  {
7634  if(no_copy_flag)
7635  async_write_no_copy(gc, (long long)fd, nbuff, reclen, (i*reclen), depth,free_addr);
7636  else
7637  async_write(gc, (long long)fd, pbuff, reclen, (i*reclen), depth);
7638  }
7639  else
7640  {
7641 #if defined(Windows)
7642  if(unbuffered)
7643  {
7644  WriteFile(hand, pbuff, reclen,(LPDWORD)&wval,
7645  0);
7646  }
7647  else
7648  {
7649 #endif
7650  wval=write(fd, pbuff, (size_t ) reclen);
7651  if(wval != reclen)
7652  {
7653 #ifdef NO_PRINT_LLD
7654  printf("\nError writing block %ld, fd= %d\n", i,
7655  fd);
7656 #else
7657  printf("\nError writing block %lld, fd= %d\n", i,
7658  fd);
7659 #endif
7660  if(wval == -1)
7661  perror("write");
7662  signal_handler();
7663  }
7664 #if defined(Windows)
7665  }
7666 #endif
7667  }
7668  }
7669  if(hist_summary)
7670  {
7671  qtime_stop=time_so_far();
7672  hist_time =(qtime_stop-qtime_start-time_res);
7673  hist_insert(hist_time);
7674  }
7675  if(Q_flag)
7676  {
7677  qtime_stop=time_so_far();
7678  if(j==0)
7679 #ifdef NO_PRINT_LLD
7680  fprintf(wqfd,"%10.1ld %10.0f %10.1ld\n",(traj_offset)/1024,((qtime_stop-qtime_start-time_res))*1000000,reclen);
7681  else
7682  fprintf(rwqfd,"%10.1ld %10.0f %10.1ld\n",(traj_offset)/1024,((qtime_stop-qtime_start-time_res))*1000000,reclen);
7683 #else
7684  fprintf(wqfd,"%10.1lld %10.0f %10.1lld\n",(traj_offset)/1024,((qtime_stop-qtime_start-time_res))*1000000,reclen);
7685  else
7686  fprintf(rwqfd,"%10.1lld %10.0f %10.1lld\n",(traj_offset)/1024,((qtime_stop-qtime_start-time_res))*1000000,reclen);
7687 #endif
7688  }
7691  if(rlocking)
7692  {
7693  mylockr((int) fd, (int) 0, (int)0,
7694  lock_offset, reclen);
7695  }
7696  }
7697 #ifdef unix
7698  if(Q_flag)
7699  {
7700  qtime_u_stop=utime_so_far();
7701  qtime_s_stop=stime_so_far();
7702  if(j==0)
7703  fprintf(wqfd,"\nSystem time %10.3f User time %10.3f Real %10.3f (seconds)\n",
7704  (qtime_s_stop-qtime_s_start)/sc_clk_tck,
7705  (qtime_u_stop-qtime_u_start)/sc_clk_tck,
7706  time_so_far()-starttime1);
7707  else
7708  fprintf(rwqfd,"\nSystem time %10.3f User time %10.3f Real %10.3f (seconds)\n",
7709  (qtime_s_stop-qtime_s_start)/sc_clk_tck,
7710  (qtime_u_stop-qtime_u_start)/sc_clk_tck,
7711  time_so_far()-starttime1);
7712  }
7713 #endif
7714 
7715 #ifdef ASYNC_IO
7716  if(async_flag)
7717  {
7718  end_async(gc);
7719  gc=0;
7720  }
7721 #endif
7722  if(include_flush)
7723  {
7724  if(mmapflag){
7725  msync(maddr,(size_t)filebytes64,MS_SYNC);
7726  }
7727  else
7728  {
7729  wval=fsync(fd);
7730  if(wval==-1){
7731  perror("fsync");
7732  signal_handler();
7733  }
7734  }
7735  }
7736  if(file_lock)
7737  if(mylockf((int) fd,(int)0,(int)0))
7738  printf("Unlock failed %d\n",errno);
7739  if(include_close)
7740  {
7741  if(mmapflag)
7742  {
7743  mmap_end(maddr,(unsigned long long)filebytes64);
7744  }
7745 #if defined(Windows)
7746  if(unbuffered)
7747  CloseHandle(hand);
7748  else
7749 #endif
7750  wval=close(fd);
7751  if(wval==-1){
7752  perror("close");
7753  signal_handler();
7754  }
7755  }
7756  writetime[j] = ((time_so_far() - starttime1)-time_res)
7757  -compute_val;
7758  if(writetime[j] < (double).000001)
7759  {
7760  writetime[j]=time_res;
7761  if(rec_prob < reclen)
7762  rec_prob = reclen;
7763  res_prob=1;
7764  }
7765  if(!include_close)
7766  {
7767  if(mmapflag)
7768  msync(maddr,(size_t)filebytes64,MS_SYNC);/* Clean up before read starts */
7769  else
7770  {
7771  wval=fsync(fd);
7772  if(wval==-1){
7773  perror("fsync");
7774  signal_handler();
7775  }
7776  }
7777  if(mmapflag)
7778  {
7779  mmap_end(maddr,(unsigned long long)filebytes64);
7780  }
7781 #if defined(Windows)
7782  if(unbuffered)
7783  CloseHandle(hand);
7784  else
7785 #endif
7786  wval=close(fd);
7787  if(wval==-1){
7788  perror("close");
7789  signal_handler();
7790  }
7791  }
7792  if(cpuutilflag)
7793  {
7794  cputime[j] = cputime_so_far() - cputime[j];
7795  if (cputime[j] < cputime_res)
7796  cputime[j] = 0.0;
7797  walltime[j] = time_so_far() - walltime[j];
7798  if (walltime[j] < cputime[j])
7799  walltime[j] = cputime[j];
7800  }
7801  if(restf)
7802  sleep((int)rest_val);
7803  }
7804  if(OPS_flag || MS_flag){
7806  /*filebytes64=filebytes64/reclen;*/
7807  }else
7809 
7810  for(j=0;j<ltest;j++)
7811  {
7812  if(MS_flag)
7813  {
7814  writerate[j]=1000000.0*(writetime[j] / (double)filebytes64);
7815  continue;
7816  }
7817  else
7818  {
7819  writerate[j] =
7820  (unsigned long long) ((double) filebytes64 / writetime[j]);
7821  }
7822  if(!(OPS_flag || MS_flag))
7823  writerate[j] >>= 10;
7824  }
7825  data1[0]=writerate[0];
7826  if(noretest)
7827  {
7828  writerate[1]=(long long) 0;
7829  if(cpuutilflag)
7830  {
7831  walltime[1]=0.0;
7832  cputime[1]=0.0;
7833  }
7834  }
7835  /* Must save walltime & cputime before calling store_value() for each/any cell.*/
7836  if(cpuutilflag)
7837  store_times(walltime[0], cputime[0]);
7838  store_value((off64_t)writerate[0]);
7839  if(cpuutilflag)
7840  store_times(walltime[1], cputime[1]);
7841  store_value((off64_t)writerate[1]);
7842 #ifdef NO_PRINT_LLD
7843  if(!silent) printf("%8ld",writerate[0]);
7844  if(!silent) printf("%8ld",writerate[1]);
7845  if(!silent) fflush(stdout);
7846 #else
7847  if(!silent) printf("%8lld",writerate[0]);
7848  if(!silent) printf("%8lld",writerate[1]);
7849  if(!silent) fflush(stdout);
7850 #endif
7851 }
7852 /************************************************************************/
7853 /* fwrite_perf_test () */
7854 /* fWrite and fre-write test */
7855 /************************************************************************/
7856 #ifdef HAVE_ANSIC_C
7857 void fwrite_perf_test(off64_t kilo64,long long reclen ,long long *data1,long long *data2)
7858 #else
7859 void fwrite_perf_test(kilo64,reclen ,data1,data2)
7860 off64_t kilo64;
7861 long long reclen;
7862 long long *data1;
7863 long long *data2;
7864 #endif
7865 {
7866  double starttime1;
7867  double writetime[2];
7868  double walltime[2], cputime[2];
7869  double compute_val = (double)0;
7870  long long i,j;
7872  long long Index = 0;
7873  unsigned long long writerate[2];
7875  FILE *stream = NULL;
7876  int fd;
7877  int wval;
7878  int ltest;
7879  char *how;
7880  char *stdio_buf;
7881 
7882  if(mmapflag || async_flag)
7883  return;
7884  numrecs64 = (kilo64*1024)/reclen;
7886  stdio_buf=(char *)malloc((size_t)reclen);
7887  if(noretest)
7888  ltest=1;
7889  else
7890  ltest=2;
7891 
7892  for( j=0; j<ltest; j++)
7893  {
7894  if(cpuutilflag)
7895  {
7896  walltime[j] = time_so_far();
7897  cputime[j] = cputime_so_far();
7898  }
7899  if(Uflag) /* Unmount and re-mount the mountpoint */
7900  {
7902  }
7903  if(j==0)
7904  {
7906  how="r+"; /* file exists, don't create and zero a new one. */
7907  else
7908  how="w+"; /* file doesn't exist. create it. */
7909  }
7910  else
7911  how="r+"; /* re-tests should error out if file does not exist. */
7912 #ifdef IRIX64
7913  if((stream=(FILE *)fopen(filename,how)) == 0)
7914  {
7915  printf("\nCan not fdopen temp file: %s %lld\n",
7916  filename,errno);
7917  perror("fdopen");
7918  exit(48);
7919  }
7920 #else
7921  if((stream=(FILE *)I_FOPEN(filename,how)) == 0)
7922  {
7923 #ifdef NO_PRINT_LLD
7924  printf("\nCan not fdopen temp file: %s %d\n",
7925  filename,errno);
7926 #else
7927  printf("\nCan not fdopen temp file: %s %d\n",
7928  filename,errno);
7929 #endif
7930  perror("fdopen");
7931  exit(49);
7932  }
7933 #endif
7934  fd=fileno(stream);
7935  fsync(fd);
7936  setvbuf(stream,stdio_buf,_IOFBF,reclen);
7938  if(fetchon)
7940  if(verify || dedup || dedup_interior)
7941  fill_buffer(buffer,reclen,(long long)pattern,sverify,(long long)0);
7942  starttime1 = time_so_far();
7943  compute_val=(double)0;
7944  for(i=0; i<numrecs64; i++){
7945  if(compute_flag)
7946  compute_val+=do_compute(compute_time);
7947  if(multi_buffer)
7948  {
7949  Index +=reclen;
7950  if(Index > (MAXBUFFERSIZE-reclen))
7951  Index=0;
7952  buffer = mbuffer + Index;
7953  }
7954  if((verify & diag_v) || dedup || dedup_interior)
7955  fill_buffer(buffer,reclen,(long long)pattern,sverify,i);
7956  if(purge)
7958  if(fwrite(buffer, (size_t) reclen, 1, stream) != 1)
7959  {
7960 #ifdef NO_PRINT_LLD
7961  printf("\nError fwriting block %ld, fd= %d\n", i,
7962  fd);
7963 #else
7964  printf("\nError fwriting block %lld, fd= %d\n", i,
7965  fd);
7966 #endif
7967  perror("fwrite");
7968  signal_handler();
7969  }
7970  }
7971 
7972  if(include_flush)
7973  {
7974  fflush(stream);
7975  wval=fsync(fd);
7976  if(wval==-1){
7977  perror("fsync");
7978  signal_handler();
7979  }
7980  }
7981  if(include_close)
7982  {
7983  wval=fclose(stream);
7984  if(wval==-1){
7985  perror("fclose");
7986  signal_handler();
7987  }
7988  }
7989  writetime[j] = ((time_so_far() - starttime1)-time_res)
7990  -compute_val;
7991  if(writetime[j] < (double).000001)
7992  {
7993  writetime[j]= time_res;
7994  if(rec_prob < reclen)
7995  rec_prob = reclen;
7996  res_prob=1;
7997  }
7998  if(!include_close)
7999  {
8000  wval=fflush(stream);
8001  if(wval==-1){
8002  perror("fflush");
8003  signal_handler();
8004  }
8005  wval=fsync(fd);
8006  if(wval==-1){
8007  perror("fsync");
8008  signal_handler();
8009  }
8010  wval=fclose(stream);
8011  if(wval==-1){
8012  perror("fclose");
8013  signal_handler();
8014  }
8015  }
8016 
8017  if(cpuutilflag)
8018  {
8019  cputime[j] = cputime_so_far() - cputime[j];
8020  if (cputime[j] < cputime_res)
8021  cputime[j] = 0.0;
8022  walltime[j] = time_so_far() - walltime[j];
8023  if (walltime[j] < cputime[j])
8024  walltime[j] = cputime[j];
8025  }
8026  if(restf)
8027  sleep((int)(int)rest_val);
8028  }
8029  free(stdio_buf);
8030  if(OPS_flag || MS_flag){
8032  }
8033  for(j=0;j<ltest;j++)
8034  {
8035  if(MS_flag)
8036  {
8037  writerate[j]=1000000.0*(writetime[j] / (double)filebytes64);
8038  continue;
8039  }
8040  else
8041  {
8042  writerate[j] =
8043  (unsigned long long) ((double) filebytes64 / writetime[j]);
8044  }
8045  if(!(OPS_flag || MS_flag))
8046  writerate[j] >>= 10;
8047  }
8048  /* Must save walltime & cputime before calling store_value() for each/any cell.*/
8049  if(noretest)
8050  {
8051  writerate[1]=(long long)0;
8052  if(cpuutilflag)
8053  {
8054  walltime[1]=0.0;
8055  cputime[1]=0.0;
8056  }
8057  }
8058  if(cpuutilflag)
8059  store_times(walltime[0], cputime[0]);
8060  store_value((off64_t)writerate[0]);
8061  if(cpuutilflag)
8062  store_times(walltime[1], cputime[1]);
8063  store_value((off64_t)writerate[1]);
8064  data1[0]=writerate[0];
8065 #ifdef NO_PRINT_LLD
8066  if(!silent) printf("%9ld",writerate[0]);
8067  if(!silent) printf("%9ld",writerate[1]);
8068  if(!silent) fflush(stdout);
8069 #else
8070  if(!silent) printf("%9lld",writerate[0]);
8071  if(!silent) printf("%9lld",writerate[1]);
8072  if(!silent) fflush(stdout);
8073 #endif
8074 }
8075 
8076 /************************************************************************/
8077 /* fread_perf_test */
8078 /* fRead and fre-read test */
8079 /************************************************************************/
8080 #ifdef HAVE_ANSIC_C
8081 void fread_perf_test(off64_t kilo64,long long reclen,long long *data1,long long *data2)
8082 #else
8083 void fread_perf_test(kilo64,reclen,data1,data2)
8084 off64_t kilo64;
8085 long long reclen;
8086 long long *data1,*data2;
8087 #endif
8088 {
8089  double starttime2;
8090  double readtime[2];
8091  double walltime[2], cputime[2];
8092  double compute_val = (double)0;
8093  long long j;
8095  long long Index = 0;
8096  unsigned long long readrate[2];
8098  FILE *stream = 0;
8099  char *stdio_buf;
8100  int fd,ltest;
8101 
8102  if(mmapflag || async_flag)
8103  return;
8104  numrecs64 = (kilo64*1024)/reclen;
8106  stdio_buf=(char *)malloc((size_t)reclen);
8107 
8108  if(noretest)
8109  ltest=1;
8110  else
8111  ltest=2;
8112 
8113  for( j=0; j<ltest; j++ )
8114  {
8115  if(cpuutilflag)
8116  {
8117  walltime[j] = time_so_far();
8118  cputime[j] = cputime_so_far();
8119  }
8120 
8121  if(Uflag) /* Unmount and re-mount the mountpoint */
8122  {
8124  }
8125 #ifdef IRIX64
8126  if((stream=(FILE *)fopen(filename,"r")) == 0)
8127  {
8128  printf("\nCan not fdopen temp file: %s\n",
8129  filename);
8130  perror("fdopen");
8131  exit(51);
8132  }
8133 #else
8134  if((stream=(FILE *)I_FOPEN(filename,"r")) == 0)
8135  {
8136  printf("\nCan not fdopen temp file: %s\n",
8137  filename);
8138  perror("fdopen");
8139  exit(52);
8140  }
8141 #endif
8142  fd=I_OPEN(filename,O_RDONLY,0);
8143  fsync(fd);
8144  close(fd);
8145  setvbuf(stream,stdio_buf,_IOFBF,reclen);
8147  if(fetchon)
8149  compute_val=(double)0;
8150  starttime2 = time_so_far();
8151  for(i=0; i<numrecs64; i++)
8152  {
8153  if(compute_flag)
8154  compute_val+=do_compute(compute_time);
8155  if(multi_buffer)
8156  {
8157  Index +=reclen;
8158  if(Index > (MAXBUFFERSIZE-reclen))
8159  Index=0;
8160  buffer = mbuffer + Index;
8161  }
8162  if(purge)
8164  if(fread(buffer, (size_t) reclen,1, stream) != 1)
8165  {
8166 #ifdef _64BIT_ARCH_
8167 #ifdef NO_PRINT_LLD
8168  printf("\nError freading block %lu %lx\n", i,
8169  (unsigned long long)buffer);
8170 #else
8171  printf("\nError freading block %llu %llx\n", i,
8172  (unsigned long long)buffer);
8173 #endif
8174 #else
8175 #ifdef NO_PRINT_LLD
8176  printf("\nError freading block %lu %lx\n", i,
8177  (long)buffer);
8178 #else
8179  printf("\nError freading block %llu %lx\n", i,
8180  (long)buffer);
8181 #endif
8182 #endif
8183  perror("read");
8184  exit(54);
8185  }
8186  if(verify){
8188  exit(55);
8189  }
8190  }
8191  }
8192  if(include_flush)
8193  fflush(stream);
8194  if(include_close)
8195  {
8196  fclose(stream);
8197  }
8198  readtime[j] = ((time_so_far() - starttime2)-time_res)
8199  -compute_val;
8200  if(readtime[j] < (double).000001)
8201  {
8202  readtime[j]= time_res;
8203  if(rec_prob < reclen)
8204  rec_prob = reclen;
8205  res_prob=1;
8206  }
8207  if(!include_close)
8208  {
8209  fflush(stream);
8210  fclose(stream);
8211  }
8212  stream = NULL;
8213  if(cpuutilflag)
8214  {
8215  cputime[j] = cputime_so_far() - cputime[j];
8216  if (cputime[j] < cputime_res)
8217  cputime[j] = 0.0;
8218  walltime[j] = time_so_far() - walltime[j];
8219  if (walltime[j] < cputime[j])
8220  walltime[j] = cputime[j];
8221  }
8222  if(restf)
8223  sleep((int)rest_val);
8224  }
8225  free(stdio_buf);
8226  if(OPS_flag || MS_flag){
8228  }
8229  for(j=0;j<ltest;j++)
8230  {
8231  if(MS_flag)
8232  {
8233  readrate[j]=1000000.0*(readtime[j] / (double)filebytes64);
8234  continue;
8235  }
8236  else
8237  {
8238  readrate[j] =
8239  (unsigned long long) ((double) filebytes64 / readtime[j]);
8240  }
8241  if(!(OPS_flag || MS_flag))
8242  readrate[j] >>= 10;
8243  }
8244  data1[0]=readrate[0];
8245  data2[0]=1;
8246  if(noretest)
8247  {
8248  readrate[1]=(long long)0;
8249  if(cpuutilflag)
8250  {
8251  walltime[1]=0.0;
8252  cputime[1]=0.0;
8253  }
8254  }
8255  /* Must save walltime & cputime before calling store_value() for each/any cell.*/
8256  if(cpuutilflag)
8257  store_times(walltime[0], cputime[0]);
8258  store_value((off64_t)readrate[0]);
8259  if(cpuutilflag)
8260  store_times(walltime[1], cputime[1]);
8261  store_value((off64_t)readrate[1]);
8262 #ifdef NO_PRINT_LLD
8263  if(!silent) printf("%8ld",readrate[0]);
8264  if(!silent) printf("%9ld",readrate[1]);
8265  if(!silent) fflush(stdout);
8266 #else
8267  if(!silent) printf("%8lld",readrate[0]);
8268  if(!silent) printf("%9lld",readrate[1]);
8269  if(!silent) fflush(stdout);
8270 #endif
8271 }
8272 
8273 /************************************************************************/
8274 /* read_perf_test */
8275 /* Read and re-fread test */
8276 /************************************************************************/
8277 #ifdef HAVE_ANSIC_C
8278 void
8279 read_perf_test(off64_t kilo64,long long reclen,long long *data1,long long *data2)
8280 #else
8281 void
8282 read_perf_test(kilo64,reclen,data1,data2)
8283 off64_t kilo64;
8284 long long reclen;
8285 long long *data1,*data2;
8286 #endif
8287 {
8288  double starttime2;
8289  double compute_val = (double)0;
8290  double readtime[2];
8291  double walltime[2], cputime[2];
8292 #ifdef unix
8293  double qtime_u_start,qtime_u_stop;
8294  double qtime_s_start,qtime_s_stop;
8295 #endif
8296  long long j;
8297  long long traj_size;
8298  off64_t i,numrecs64,traj_offset;
8299  off64_t lock_offset=0;
8300  long long Index = 0;
8301  unsigned long long readrate[2];
8303  volatile char *buffer1;
8304  char *nbuff;
8305  char *maddr;
8306  char *wmaddr;
8307  int fd,open_flags;
8308  int test_foo,ltest;
8309  long wval;
8310  double qtime_start,qtime_stop;
8311  double hist_time;
8312 #ifdef ASYNC_IO
8313  struct cache *gc=0;
8314 
8315 #else
8316  long long *gc=0;
8317 #endif
8318 #ifdef unix
8319  qtime_u_start=qtime_u_stop=0;
8320  qtime_s_start=qtime_s_stop=0;
8321 #endif
8322  hist_time=qtime_start=qtime_stop=0;
8323  maddr=0;
8324  traj_offset=0;
8325  test_foo=0;
8326  numrecs64 = (kilo64*1024)/reclen;
8327 
8328  open_flags = O_RDONLY;
8329 #if defined(_HPUX_SOURCE) || defined(linux)
8330  if(read_sync)
8331  open_flags |=O_RSYNC|O_SYNC;
8332 #endif
8333 #if ! defined(DONT_HAVE_O_DIRECT)
8334 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
8335  if(direct_flag)
8336  open_flags |=O_DIRECT;
8337 #endif
8338 #if defined(TRU64)
8339  if(direct_flag)
8340  open_flags |=O_DIRECTIO;
8341 #endif
8342 #endif
8343  if(r_traj_flag)
8344  {
8347  } else
8349  fd = 0;
8350  if(Q_flag && (!rol_opened))
8351  {
8352  rol_opened++;
8353  rqfd=fopen("rol.dat","a");
8354  if(rqfd==0)
8355  {
8356  printf("Unable to open rol.dat\n");
8357  exit(56);
8358  }
8359  fprintf(rqfd,"Offset in Kbytes Latency in microseconds Transfer size in bytes\n");
8360  rrqfd=fopen("rrol.dat","a");
8361  if(rrqfd==0)
8362  {
8363  printf("Unable to open rrol.dat\n");
8364  exit(57);
8365  }
8366  fprintf(rrqfd,"Offset in Kbytes Latency in microseconds Transfer size in bytes\n");
8367  }
8368  /*
8369  * begin real testing
8370  */
8371  if(noretest)
8372  ltest=1;
8373  else
8374  ltest=2;
8375 
8376  for( j=0; j<ltest; j++ )
8377  {
8378 
8379  if(cpuutilflag)
8380  {
8381  walltime[j] = time_so_far();
8382  cputime[j] = cputime_so_far();
8383  }
8384 
8385  if(Uflag) /* Unmount and re-mount the mountpoint */
8386  {
8388  }
8389 #if defined(Windows)
8390  if(unbuffered)
8391  {
8392  hand=CreateFile(filename,
8393  GENERIC_READ|GENERIC_WRITE,
8394  FILE_SHARE_WRITE|FILE_SHARE_READ,
8395  NULL,OPEN_EXISTING,FILE_FLAG_NO_BUFFERING|
8396  FILE_FLAG_WRITE_THROUGH|FILE_FLAG_POSIX_SEMANTICS,
8397  NULL);
8398  }
8399  else
8400  {
8401 #endif
8402  if((fd = I_OPEN(filename, open_flags,0))<0)
8403  {
8404  printf("\nCan not open temporary file %s for read\n",filename);
8405  perror("open");
8406  exit(58);
8407  }
8408 #if defined(Windows)
8409  }
8410 #endif
8411 #ifdef ASYNC_IO
8412  if(async_flag)
8413  async_init(&gc,fd,direct_flag);
8414 #endif
8415 
8416 #ifdef VXFS
8417  if(direct_flag)
8418  {
8419  ioctl(fd,VX_SETCACHE,VX_DIRECT);
8420  ioctl(fd,VX_GETCACHE,&test_foo);
8421  if(test_foo == 0)
8422  {
8423  if(!client_iozone)
8424  printf("\nVxFS advanced setcache feature not available.\n");
8425  exit(3);
8426  }
8427  }
8428 #endif
8429 #if defined(solaris)
8430  if(direct_flag)
8431  {
8432  test_foo = directio(fd, DIRECTIO_ON);
8433  if(test_foo != 0)
8434  {
8435  if(!client_iozone)
8436  printf("\ndirectio not available.\n");
8437  exit(3);
8438  }
8439  }
8440 #endif
8441  if(file_lock)
8442  if(mylockf((int) fd, (int) 1, (int)1) != 0)
8443  printf("File lock for read failed. %d\n",errno);
8444  if(mmapflag)
8445  {
8446  maddr=(char *)initfile(fd,filebytes64,0,PROT_READ);
8447  }
8448 #if defined(Windows)
8449  if(!unbuffered)
8450 #endif
8451  fsync(fd);
8452  /*
8453  * Need to prime the instruction cache & TLB
8454  */
8455  nbuff=mainbuffer;
8456  if(fetchon)
8457  fetchit(nbuff,reclen);
8458 #if defined(Windows)
8459  if(!unbuffered)
8460  {
8461 #endif
8462  if(read(fd, (void *)nbuff, (size_t) reclen) != reclen)
8463  {
8464 #ifdef _64BIT_ARCH_
8465  printf("\nError reading block %d %llx\n", 0,
8466  (unsigned long long)nbuff);
8467 #else
8468  printf("\nError reading block %d %lx\n", 0,
8469  (long)nbuff);
8470 #endif
8471  perror("read");
8472  exit(60);
8473  }
8474  I_LSEEK(fd,0,SEEK_SET);
8475 #if defined(Windows)
8476  }
8477  if(unbuffered)
8478  SetFilePointer(hand,(LONG)0,0,FILE_BEGIN);
8479 #endif
8480  nbuff=mainbuffer;
8481 
8482  if(fetchon)
8483  fetchit(nbuff,reclen);
8484  starttime2 = time_so_far();
8485 #ifdef unix
8486  if(Q_flag || hist_summary)
8487  {
8488  qtime_u_start=utime_so_far();
8489  qtime_s_start=stime_so_far();
8490  }
8491 #endif
8492  if(r_traj_flag)
8493  {
8494  rewind(r_traj_fd);
8495  }
8496  compute_val=(double)0;
8499  for(i=0; i<numrecs64; i++)
8500  {
8501  if(disrupt_flag && ((i%DISRUPT)==0))
8502  {
8503 #if defined(Windows)
8504 
8505  if(unbuffered)
8506  disruptw(hand);
8507  else
8508  disrupt(fd);
8509 #else
8510  disrupt(fd);
8511 #endif
8512  }
8513  if(r_traj_flag)
8514  {
8515  traj_offset=get_traj(r_traj_fd, (long long *)&traj_size,(float *)&compute_time, (long)0);
8516  reclen=traj_size;
8517 #if defined(Windows)
8518  if(unbuffered)
8519  SetFilePointer(hand,(LONG)traj_offset,0,FILE_BEGIN);
8520  else
8521 #endif
8522  I_LSEEK(fd,traj_offset,SEEK_SET);
8523  }
8524  if(Q_flag)
8525  {
8526 #if defined(Windows)
8527  if(unbuffered)
8528  traj_offset=SetFilePointer(hand,(LONG)0,0,FILE_CURRENT);
8529  else
8530 #endif
8531  traj_offset=I_LSEEK(fd,0,SEEK_CUR);
8532  }
8533  if(rlocking)
8534  {
8535  lock_offset=I_LSEEK(fd,0,SEEK_CUR);
8536  mylockr((int) fd, (int) 1, (int)1,
8537  lock_offset, reclen);
8538  }
8539  if(compute_flag)
8540  compute_val+=do_compute(compute_time);
8541  if(multi_buffer)
8542  {
8543  Index +=reclen;
8544  if(Index > (MAXBUFFERSIZE-reclen))
8545  Index=0;
8546  nbuff = mbuffer + Index;
8547  }
8548  if(purge)
8549  purgeit(nbuff,reclen);
8550  if(Q_flag || hist_summary)
8551  qtime_start=time_so_far();
8552  if(mmapflag)
8553  {
8554  wmaddr=&maddr[i*reclen];
8555  fill_area((long long*)wmaddr,(long long*)nbuff,(long long)reclen);
8556  }
8557  else
8558  {
8559  if(async_flag)
8560  {
8561  if(no_copy_flag)
8562  async_read_no_copy(gc, (long long)fd, &buffer1, (i*reclen), reclen,
8563  1LL,(numrecs64*reclen),depth);
8564  else
8565  async_read(gc, (long long)fd, nbuff, (i*reclen),reclen,
8566  1LL,(numrecs64*reclen),depth);
8567  }
8568  else
8569  {
8570 #if defined(Windows)
8571  if(unbuffered)
8572  {
8573  ReadFile(hand, nbuff, reclen,(LPDWORD)&wval,
8574  0);
8575  }
8576  else
8577 #endif
8578  wval=read((int)fd, (void*)nbuff, (size_t) reclen);
8579  if(wval != reclen)
8580  {
8581 #ifdef _64BIT_ARCH_
8582 #ifdef NO_PRINT_LLD
8583  printf("\nError reading block %ld %lx\n", i,
8584  (unsigned long long)nbuff);
8585 #else
8586  printf("\nError reading block %lld %llx\n", i,
8587  (unsigned long long)nbuff);
8588 #endif
8589 #else
8590 #ifdef NO_PRINT_LLD
8591  printf("\nError reading block %ld %x\n", i,
8592  (long)nbuff);
8593 #else
8594  printf("\nError reading block %lld %lx\n", i,
8595  (long)nbuff);
8596 #endif
8597 #endif
8598  perror("read");
8599  exit(61);
8600  }
8601  }
8602  }
8603  if(verify) {
8604  if(async_flag && no_copy_flag)
8605  {
8607  exit(62);
8608  }
8609  }
8610  else
8611  {
8612  if(verify_buffer(nbuff,reclen,(off64_t)i,reclen,(long long)pattern,sverify)){
8613  exit(63);
8614  }
8615  }
8616  }
8617  if(async_flag && no_copy_flag)
8618  async_release(gc);
8619  buffer1=0;
8620  if(hist_summary)
8621  {
8622  qtime_stop=time_so_far();
8623  hist_time =(qtime_stop-qtime_start-time_res);
8624  hist_insert(hist_time);
8625  }
8626  if(Q_flag)
8627  {
8628  qtime_stop=time_so_far();
8629  if(j==0)
8630 #ifdef NO_PRINT_LLD
8631  fprintf(rqfd,"%10.1ld %10.0f %10.1ld\n",(traj_offset)/1024,(qtime_stop-qtime_start-time_res)*1000000,reclen);
8632  else
8633  fprintf(rrqfd,"%10.1ld %10.0f %10.1ld\n",(traj_offset)/1024,(qtime_stop-qtime_start-time_res)*1000000,reclen);
8634 #else
8635  fprintf(rqfd,"%10.1lld %10.0f %10.1lld\n",(traj_offset)/1024,(qtime_stop-qtime_start-time_res)*1000000,reclen);
8636  else
8637  fprintf(rrqfd,"%10.1lld %10.0f %10.1lld\n",(traj_offset)/1024,(qtime_stop-qtime_start-time_res)*1000000,reclen);
8638 #endif
8639  }
8642  }
8643  if(rlocking)
8644  {
8645  mylockr((int) fd, (int) 0, (int)1,
8646  lock_offset, reclen);
8647  }
8648  if(file_lock)
8649  if(mylockf((int) fd, (int) 0, (int)1))
8650  printf("Read unlock failed. %d\n",errno);
8651 #ifdef unix
8652  if(Q_flag)
8653  {
8654  qtime_u_stop=utime_so_far();
8655  qtime_s_stop=stime_so_far();
8656  if(j==0)
8657  fprintf(rqfd,"\nSystem time %10.3f User time %10.3f Real %10.3f (seconds)\n",
8658  (qtime_s_stop-qtime_s_start)/sc_clk_tck,
8659  (qtime_u_stop-qtime_u_start)/sc_clk_tck,
8660  time_so_far()-starttime2);
8661  else
8662  fprintf(rrqfd,"\nSystem time %10.3f User time %10.3f Real %10.3f (seconds)\n",
8663  (qtime_s_stop-qtime_s_start)/sc_clk_tck,
8664  (qtime_u_stop-qtime_u_start)/sc_clk_tck,
8665  time_so_far()-starttime2);
8666  }
8667 #endif
8668 #ifdef ASYNC_IO
8669  if(async_flag)
8670  {
8671  end_async(gc);
8672  gc=0;
8673  }
8674 #endif
8675  if(include_flush)
8676  {
8677  if(mmapflag)
8678  msync(maddr,(size_t)filebytes64,MS_SYNC);
8679  else
8680  fsync(fd);
8681  }
8682  if(include_close)
8683  {
8684  if(mmapflag)
8685  {
8686  mmap_end(maddr,(unsigned long long)filebytes64);
8687  }
8688 #if defined(Windows)
8689  if(unbuffered)
8690  CloseHandle(hand);
8691  else
8692 #endif
8693  close(fd);
8694  }
8695  readtime[j] = ((time_so_far() - starttime2)-time_res)-compute_val;
8696  if(readtime[j] < (double).000001)
8697  {
8698  readtime[j]= time_res;
8699  if(rec_prob < reclen)
8700  rec_prob = reclen;
8701  res_prob=1;
8702  }
8703  if(!include_close)
8704  {
8705  if(mmapflag)
8706  msync(maddr,(size_t)filebytes64,MS_SYNC);
8707  else
8708  fsync(fd);
8709  if(mmapflag)
8710  {
8711  mmap_end(maddr,(unsigned long long)filebytes64);
8712  }
8713 #if defined(Windows)
8714  if(unbuffered)
8715  CloseHandle(hand);
8716  else
8717 #endif
8718  close(fd);
8719  }
8720  if(cpuutilflag)
8721  {
8722  cputime[j] = cputime_so_far() - cputime[j];
8723  if (cputime[j] < cputime_res)
8724  cputime[j] = 0.0;
8725  walltime[j] = time_so_far() - walltime[j];
8726  if (walltime[j] < cputime[j])
8727  walltime[j] = cputime[j];
8728  }
8729  if(restf)
8730  sleep((int)rest_val);
8731  }
8732  if(OPS_flag || MS_flag){
8734  /*filebytes64=filebytes64/reclen;*/
8735  } else
8737 
8738  for(j=0;j<ltest;j++)
8739  {
8740  if(MS_flag)
8741  {
8742  readrate[j]=1000000.0*(readtime[j] / (double)filebytes64);
8743  continue;
8744  }
8745  else
8746  {
8747  readrate[j] =
8748  (unsigned long long) ((double) filebytes64 / readtime[j]);
8749  }
8750  if(!(OPS_flag || MS_flag))
8751  readrate[j] >>= 10;
8752 
8753  }
8754  data1[0]=readrate[0];
8755  data2[0]=1;
8756  if(noretest)
8757  {
8758  readrate[1]=(long long)0;
8759  if(cpuutilflag)
8760  {
8761  walltime[1]=0.0;
8762  cputime[1]=0.0;
8763  }
8764  }
8765  /* Must save walltime & cputime before calling store_value() for each/any cell.*/
8766  if(cpuutilflag)
8767  store_times(walltime[0], cputime[0]);
8768  store_value((off64_t)readrate[0]);
8769  if(cpuutilflag)
8770  store_times(walltime[1], cputime[1]);
8771  store_value((off64_t)readrate[1]);
8772 #ifdef NO_PRINT_LLD
8773  if(!silent) printf("%9ld",readrate[0]);
8774  if(!silent) printf("%9ld",readrate[1]);
8775  if(!silent) fflush(stdout);
8776 #else
8777  if(!silent) printf("%9lld",readrate[0]);
8778  if(!silent) printf("%9lld",readrate[1]);
8779  if(!silent) fflush(stdout);
8780 #endif
8781 }
8782 
8783 
8784 /************************************************************************/
8785 /* random_perf_test */
8786 /* Random read and write test */
8787 /************************************************************************/
8788 #ifdef HAVE_ANSIC_C
8789 void random_perf_test(off64_t kilo64,long long reclen,long long *data1,long long *data2)
8790 #else
8791 void random_perf_test(kilo64,reclen,data1,data2)
8792 off64_t kilo64;
8793 long long reclen;
8794 long long *data1, *data2;
8795 #endif
8796 {
8797  double randreadtime[2];
8798  double starttime2;
8799  double walltime[2], cputime[2];
8800  double compute_val = (double)0;
8801 #if defined (bsd4_2) || defined(Windows)
8802  long long rand1,rand2,rand3;
8803 #endif
8804  unsigned long long big_rand;
8805  long long j;
8807  long long Index=0;
8808  int flags;
8809  unsigned long long randreadrate[2];
8811  off64_t lock_offset=0;
8812  volatile char *buffer1;
8813  char *wmaddr,*nbuff;
8814  char *maddr,*free_addr;
8815  int fd,wval;
8816  long long *recnum= 0;
8817 #if defined(VXFS) || defined(solaris)
8818  int test_foo=0;
8819 #endif
8820 #ifdef ASYNC_IO
8821  struct cache *gc=0;
8822 #else
8823  long long *gc=0;
8824 #endif
8825 #ifdef MERSENNE
8826  unsigned long long init[4]={0x12345ULL, 0x23456ULL, 0x34567ULL, 0x45678ULL};
8827  unsigned long long length=4;
8828 #endif
8829 
8830  maddr=free_addr=0;
8831  numrecs64 = (kilo64*1024)/reclen;
8832 #ifdef MERSENNE
8833  init_by_array64(init, length);
8834 #else
8835 #ifdef bsd4_2
8836  srand(0);
8837 #else
8838 #ifdef Windows
8839  srand(0);
8840 #else
8841  srand48(0);
8842 #endif
8843 #endif
8844 #endif
8845  recnum = (long long *)malloc(sizeof(*recnum)*numrecs64);
8846  if (recnum){
8847  /* pre-compute random sequence based on
8848  Fischer-Yates (Knuth) card shuffle */
8849  for(i = 0; i < numrecs64; i++){
8850  recnum[i] = i;
8851  }
8852  for(i = 0; i < numrecs64; i++) {
8853  long long tmp;
8854 #ifdef MERSENNE
8855  big_rand=genrand64_int64();
8856 #else
8857 #ifdef bsd4_2
8858  rand1=(long long)rand();
8859  rand2=(long long)rand();
8860  rand3=(long long)rand();
8861  big_rand=(rand1<<32)|(rand2<<16)|(rand3);
8862 #else
8863 #ifdef Windows
8864  rand1=(long long)rand();
8865  rand2=(long long)rand();
8866  rand3=(long long)rand();
8867  big_rand=(rand1<<32)|(rand2<<16)|(rand3);
8868 #else
8869  big_rand = lrand48();
8870 #endif
8871 #endif
8872 #endif
8873  big_rand = big_rand%numrecs64;
8874  tmp = recnum[i];
8875  recnum[i] = recnum[big_rand];
8876  recnum[big_rand] = tmp;
8877  }
8878  }
8879  else
8880  {
8881  fprintf(stderr,"Random uniqueness fallback.\n");
8882  }
8883  flags = O_RDWR;
8884 #if ! defined(DONT_HAVE_O_DIRECT)
8885 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
8886  if(direct_flag)
8887  flags |=O_DIRECT;
8888 #endif
8889 #if defined(TRU64)
8890  if(direct_flag)
8891  flags |=O_DIRECTIO;
8892 #endif
8893 #endif
8894  fd=0;
8895  if(oflag)
8896  flags |= O_SYNC;
8897 #if defined(O_DSYNC)
8898  if(odsync)
8899  flags |= O_DSYNC;
8900 #endif
8901 #if defined(_HPUX_SOURCE) || defined(linux)
8902  if(read_sync)
8903  flags |=O_RSYNC|O_SYNC;
8904 #endif
8906  for( j=0; j<2; j++ )
8907  {
8908  if(j==0)
8909  flags |=O_CREAT;
8910  if (no_write && (j == 1))
8911  continue;
8912  if(cpuutilflag)
8913  {
8914  walltime[j] = time_so_far();
8915  cputime[j] = cputime_so_far();
8916  }
8917  if(Uflag) /* Unmount and re-mount the mountpoint */
8918  {
8920  }
8921  if((fd = I_OPEN(filename, ((int)flags),0640))<0){
8922  printf("\nCan not open temporary file for read/write\n");
8923  perror("open");
8924  exit(66);
8925  }
8926 #ifdef ASYNC_IO
8927  if(async_flag)
8928  async_init(&gc,fd,direct_flag);
8929 #endif
8930 
8931 #ifdef VXFS
8932  if(direct_flag)
8933  {
8934  ioctl(fd,VX_SETCACHE,VX_DIRECT);
8935  ioctl(fd,VX_GETCACHE,&test_foo);
8936  if(test_foo == 0)
8937  {
8938  if(!client_iozone)
8939  printf("\nVxFS advanced setcache feature not available.\n");
8940  exit(3);
8941  }
8942  }
8943 #endif
8944 #if defined(solaris)
8945  if(direct_flag)
8946  {
8947  test_foo = directio(fd, DIRECTIO_ON);
8948  if(test_foo != 0)
8949  {
8950  if(!client_iozone)
8951  printf("\ndirectio not available.\n");
8952  exit(3);
8953  }
8954  }
8955 #endif
8956  if(mmapflag)
8957  {
8958  maddr=(char *)initfile(fd,filebytes64,0,PROT_READ|PROT_WRITE);
8959  }
8960  nbuff=mainbuffer;
8961  if(fetchon)
8962  fetchit(nbuff,reclen);
8963 #ifdef MERSENNE
8964  init_by_array64(init, length);
8965 #else
8966 #ifdef bsd4_2
8967  srand(0);
8968 #else
8969 #ifdef Windows
8970  srand(0);
8971 #else
8972  srand48(0);
8973 #endif
8974 #endif
8975 #endif
8976  compute_val=(double)0;
8977  starttime2 = time_so_far();
8978  if ( j==0 ){
8979  for(i=0; i<numrecs64; i++) {
8980  if(compute_flag)
8981  compute_val+=do_compute(compute_time);
8982  if(multi_buffer)
8983  {
8984  Index +=reclen;
8985  if(Index > (MAXBUFFERSIZE-reclen))
8986  Index=0;
8987  nbuff = mbuffer + Index;
8988  }
8989  if(purge)
8990  purgeit(nbuff,reclen);
8991  if (recnum) {
8992  offset64 = reclen * (long long)recnum[i];
8993  }
8994  else
8995  {
8996 
8997 #ifdef MERSENNE
8998  big_rand =genrand64_int64();
8999  offset64 = reclen * (big_rand%numrecs64);
9000 #else
9001 #ifdef bsd4_2
9002  rand1=(long long)rand();
9003  rand2=(long long)rand();
9004  rand3=(long long)rand();
9005  big_rand=(rand1<<32)|(rand2<<16)|(rand3);
9006  offset64 = reclen * (big_rand%numrecs64);
9007 #else
9008 #ifdef Windows
9009  rand1=(long long)rand();
9010  rand2=(long long)rand();
9011  rand3=(long long)rand();
9012  big_rand=(rand1<<32)|(rand2<<16)|(rand3);
9013  offset64 = reclen * (big_rand%numrecs64);
9014 #else
9015  offset64 = reclen * (lrand48()%numrecs64);
9016 #endif
9017 #endif
9018 #endif
9019  }
9020 
9021  if( !(h_flag || k_flag || mmapflag))
9022  {
9023  if(I_LSEEK( fd, offset64, SEEK_SET )<0)
9024  {
9025  perror("lseek");
9026  exit(68);
9027  };
9028  }
9029  if(rlocking)
9030  {
9031  lock_offset=I_LSEEK(fd,0,SEEK_CUR);
9032  mylockr((int) fd, (int) 1, (int)1,
9033  lock_offset, reclen);
9034  }
9035  if(mmapflag)
9036  {
9037  wmaddr=&maddr[offset64];
9038  fill_area((long long*)wmaddr,(long long*)nbuff,(long long)reclen);
9039  }
9040  else
9041  {
9042  if(async_flag)
9043  {
9044  if(no_copy_flag)
9045  async_read_no_copy(gc, (long long)fd, &buffer1, offset64,reclen,
9046  0LL,(numrecs64*reclen),depth);
9047  else
9048  async_read(gc, (long long)fd, nbuff, (offset64),reclen,
9049  0LL,(numrecs64*reclen),0LL);
9050  }
9051  else
9052  {
9053  if(read(fd, (void *)nbuff, (size_t)reclen) != reclen)
9054  {
9055 #ifdef NO_PRINT_LLD
9056  printf("\nError reading block at %ld\n",
9057  offset64);
9058 #else
9059  printf("\nError reading block at %lld\n",
9060  offset64);
9061 #endif
9062  perror("read");
9063  exit(70);
9064  }
9065  }
9066  }
9067  if(verify){
9068  if(async_flag && no_copy_flag)
9069  {
9071  exit(71);
9072  }
9073  }
9074  else
9075  {
9077  exit(72);
9078  }
9079  }
9080  }
9081  if(async_flag && no_copy_flag)
9082  async_release(gc);
9083  if(rlocking)
9084  {
9085  lock_offset=I_LSEEK(fd,0,SEEK_CUR);
9086  mylockr((int) fd, (int) 1, (int)1,
9087  lock_offset, reclen);
9088  }
9089  }
9090  }
9091  else
9092  {
9093  if(verify || dedup || dedup_interior)
9094  fill_buffer(nbuff,reclen,(long long)pattern,sverify,(long long)0);
9095  for(i=0; i<numrecs64; i++)
9096  {
9097  if(compute_flag)
9098  compute_val+=do_compute(compute_time);
9099  if(multi_buffer)
9100  {
9101  Index +=reclen;
9102  if(Index > (MAXBUFFERSIZE-reclen))
9103  Index=0;
9104  nbuff = mbuffer + Index;
9105  }
9106  if (recnum) {
9107  offset64 = reclen * (long long)recnum[i];
9108  }
9109  else
9110  {
9111 #ifdef bsd4_2
9112  rand1=(long long)rand();
9113  rand2=(long long)rand();
9114  rand3=(long long)rand();
9115  big_rand=(rand1<<32)|(rand2<<16)|(rand3);
9116  offset64 = reclen * (big_rand%numrecs64);
9117 #else
9118 #ifdef Windows
9119  rand1=(long long)rand();
9120  rand2=(long long)rand();
9121  rand3=(long long)rand();
9122  big_rand=(rand1<<32)|(rand2<<16)|(rand3);
9123  offset64 = reclen * (big_rand%numrecs64);
9124 #else
9125  offset64 = reclen * (lrand48()%numrecs64);
9126 #endif
9127 #endif
9128  }
9129  if(async_flag && no_copy_flag)
9130  {
9131  free_addr=nbuff=(char *)malloc((size_t)reclen+page_size);
9132  nbuff=(char *)(((long)nbuff+(long)page_size) & (long)~(page_size-1));
9133  if(verify || dedup || dedup_interior)
9134  fill_buffer(nbuff,reclen,(long long)pattern,sverify,offset64/reclen);
9135  }
9136  if(purge)
9137  purgeit(nbuff,reclen);
9138 
9139  if((verify & diag_v) || dedup || dedup_interior)
9140  fill_buffer(nbuff,reclen,(long long)pattern,sverify,offset64/reclen);
9141 
9142  if (!(h_flag || k_flag || mmapflag))
9143  {
9144  I_LSEEK( fd, offset64, SEEK_SET );
9145  }
9146  if(rlocking)
9147  {
9148  lock_offset=I_LSEEK(fd,0,SEEK_CUR);
9149  mylockr((int) fd, (int) 1, (int)0,
9150  lock_offset, reclen);
9151  }
9152  if(mmapflag)
9153  {
9154  wmaddr=&maddr[offset64];
9155  fill_area((long long*)nbuff,(long long*)wmaddr,(long long)reclen);
9156  if(!mmapnsflag)
9157  {
9158  if(mmapasflag)
9159  msync(wmaddr,(size_t)reclen,MS_ASYNC);
9160  if(mmapssflag)
9161  msync(wmaddr,(size_t)reclen,MS_SYNC);
9162  }
9163  }
9164  else
9165  {
9166  if(async_flag)
9167  {
9168  if(no_copy_flag)
9169  async_write_no_copy(gc, (long long)fd, nbuff, reclen, offset64,
9170  depth,free_addr);
9171  else
9172  async_write(gc, (long long)fd, nbuff, reclen, offset64, depth);
9173  }
9174  else
9175  {
9176  wval=write(fd, nbuff,(size_t)reclen);
9177  if(wval != reclen)
9178  {
9179 #ifdef NO_PRINT_LLD
9180  printf("\nError writing block at %ld\n",
9181  offset64);
9182 #else
9183  printf("\nError writing block at %lld\n",
9184  offset64);
9185 #endif
9186  if(wval==-1)
9187  perror("write");
9188  signal_handler();
9189  }
9190  }
9191  }
9192  if(rlocking)
9193  {
9194  mylockr((int) fd, (int) 0, (int)0,
9195  lock_offset, reclen);
9196  }
9197  }
9198  } /* end of modifications *kcollins:2-5-96 */
9199 #ifdef ASYNC_IO
9200  if(async_flag)
9201  {
9202  end_async(gc);
9203  gc=0;
9204  }
9205 #endif
9206  if(include_flush)
9207  {
9208  if(mmapflag)
9209  msync(maddr,(size_t)filebytes64,MS_SYNC);/* Clean up before read starts running */
9210  else
9211  {
9212  wval=fsync(fd);
9213  if(wval==-1){
9214  perror("fsync");
9215  signal_handler();
9216  }
9217  }
9218  }
9219  if(include_close)
9220  {
9221  if(mmapflag)
9222  {
9223  mmap_end(maddr,(unsigned long long)filebytes64);
9224  }
9225  wval=close(fd);
9226  if(wval==-1){
9227  perror("close");
9228  signal_handler();
9229  }
9230  }
9231  randreadtime[j] = ((time_so_far() - starttime2)-time_res)-
9232  compute_val;
9233  if(randreadtime[j] < (double).000001)
9234  {
9235  randreadtime[j]=time_res;
9236  if(rec_prob < reclen)
9237  rec_prob = reclen;
9238  res_prob=1;
9239  }
9240  if(!include_close)
9241  {
9242  if(mmapflag)
9243  {
9244  msync(maddr,(size_t)filebytes64,MS_SYNC);/* Clean up before read starts running */
9245  }
9246  else
9247  {
9248  wval=fsync(fd);
9249  if(wval==-1){
9250  perror("fsync");
9251  signal_handler();
9252  }
9253  }
9254  if(mmapflag)
9255  mmap_end(maddr,(unsigned long long)filebytes64);
9256  wval=close(fd);
9257  if(wval==-1){
9258  perror("close");
9259  signal_handler();
9260  }
9261  }
9262  if(cpuutilflag)
9263  {
9264  cputime[j] = cputime_so_far() - cputime[j];
9265  if (cputime[j] < cputime_res)
9266  cputime[j] = 0.0;
9267  walltime[j] = time_so_far() - walltime[j];
9268  if (walltime[j] < cputime[j])
9269  walltime[j] = cputime[j];
9270  }
9271  if(restf)
9272  sleep((int)rest_val);
9273  }
9274  if(OPS_flag || MS_flag){
9276  }
9277  for(j=0;j<2;j++)
9278  {
9279  if(no_write && (j==1))
9280  {
9281  randreadrate[1] = 0.0;
9282  continue;
9283  }
9284  if(MS_flag)
9285  {
9286  randreadrate[j]=1000000.0*(randreadtime[j] / (double)filebytes64);
9287  continue;
9288  }
9289  else
9290  {
9291  randreadrate[j] =
9292  (unsigned long long) ((double) filebytes64 / randreadtime[j]);
9293  }
9294  if(!(OPS_flag || MS_flag))
9295  randreadrate[j] >>= 10;
9296  }
9297  /* Must save walltime & cputime before calling store_value() for each/any cell.*/
9298  if(cpuutilflag)
9299  store_times(walltime[0], cputime[0]);
9300  store_value((off64_t)randreadrate[0]);
9301  if(cpuutilflag)
9302  store_times(walltime[1], cputime[1]);
9303  store_value((off64_t)randreadrate[1]);
9304 #ifdef NO_PRINT_LLD
9305  if(!silent) printf("%8ld",randreadrate[0]);
9306  if(!silent) printf("%8ld",randreadrate[1]);
9307  if(!silent) fflush(stdout);
9308 #else
9309  if(!silent) printf("%8lld",randreadrate[0]);
9310  if(!silent) printf("%8lld",randreadrate[1]);
9311  if(!silent) fflush(stdout);
9312 #endif
9313  if(recnum)
9314  free(recnum);
9315 }
9316 
9317 /************************************************************************/
9318 /* reverse_perf_test */
9319 /* Reverse read test */
9320 /************************************************************************/
9321 #ifdef HAVE_ANSIC_C
9322 void reverse_perf_test(off64_t kilo64,long long reclen,long long *data1,long long *data2)
9323 #else
9324 void reverse_perf_test(kilo64,reclen,data1,data2)
9325 off64_t kilo64;
9326 long long reclen;
9327 long long *data1,*data2;
9328 #endif
9329 {
9330  double revreadtime[2];
9331  double starttime2;
9332  double walltime[2], cputime[2];
9333  double compute_val = (double)0;
9334  long long j;
9336  long long Index = 0;
9337  unsigned long long revreadrate[2];
9339  off64_t lock_offset=0;
9340  int fd,open_flags;
9341  char *maddr,*wmaddr;
9342  volatile char *buffer1;
9343  int ltest;
9344  char *nbuff;
9345 #if defined(VXFS) || defined(solaris)
9346  int test_foo=0;
9347 #endif
9348 #ifdef ASYNC_IO
9349  struct cache *gc=0;
9350 #else
9351  long long *gc=0;
9352 #endif
9353 
9354  maddr=wmaddr=0;
9355  open_flags=O_RDONLY;
9356 #if ! defined(DONT_HAVE_O_DIRECT)
9357 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
9358  if(direct_flag)
9359  open_flags |=O_DIRECT;
9360 #endif
9361 #if defined(TRU64)
9362  if(direct_flag)
9363  open_flags |=O_DIRECTIO;
9364 #endif
9365 #endif
9366 #if defined(_HPUX_SOURCE) || defined(linux)
9367  if(read_sync)
9368  open_flags |=O_RSYNC|O_SYNC;
9369 #endif
9370  numrecs64 = (kilo64*1024)/reclen;
9372  fd = 0;
9373  if(noretest)
9374  ltest=1;
9375  else
9376  ltest=2;
9377  for( j=0; j<ltest; j++ )
9378  {
9379  if(cpuutilflag)
9380  {
9381  walltime[j] = time_so_far();
9382  cputime[j] = cputime_so_far();
9383  }
9384  if(Uflag) /* Unmount and re-mount the mountpoint */
9385  {
9387  }
9388  if((fd = I_OPEN(filename, open_flags,0))<0){
9389  printf("\nCan not open temporary file for read\n");
9390  perror("open");
9391  exit(75);
9392  }
9393 #ifdef ASYNC_IO
9394  if(async_flag)
9395  async_init(&gc,fd,direct_flag);
9396 #endif
9397 
9398 #ifdef VXFS
9399  if(direct_flag)
9400  {
9401  ioctl(fd,VX_SETCACHE,VX_DIRECT);
9402  ioctl(fd,VX_GETCACHE,&test_foo);
9403  if(test_foo == 0)
9404  {
9405  if(!client_iozone)
9406  printf("\nVxFS advanced setcache feature not available.\n");
9407  exit(3);
9408  }
9409  }
9410 #endif
9411 #if defined(solaris)
9412  if(direct_flag)
9413  {
9414  test_foo = directio(fd, DIRECTIO_ON);
9415  if(test_foo != 0)
9416  {
9417  if(!client_iozone)
9418  printf("\ndirectio not available.\n");
9419  exit(3);
9420  }
9421  }
9422 #endif
9423  if(mmapflag)
9424  {
9425  maddr=(char *)initfile(fd,filebytes64,0,PROT_READ);
9426  }
9427  fsync(fd);
9428  nbuff=mainbuffer;
9430  if(fetchon)
9431  fetchit(nbuff,reclen);
9432  starttime2 = time_so_far();
9433  if (!(h_flag || k_flag || mmapflag))
9434  {
9436  {
9437  if(I_LSEEK( fd, -reclen, SEEK_END )<0)
9438  {
9439  perror("lseek");
9440  exit(77);
9441  };
9442  }
9443  else
9444  {
9445  if(I_LSEEK( fd, filebytes64-reclen, SEEK_SET )<0)
9446  {
9447  perror("lseek");
9448  exit(77);
9449  };
9450  }
9451  }
9452  compute_val=(double)0;
9453  for(i=0; i<numrecs64; i++)
9454  {
9455  if(rlocking)
9456  {
9457  lock_offset=I_LSEEK(fd,0,SEEK_CUR);
9458  mylockr((int) fd, (int) 1, (int)1,
9459  lock_offset, reclen);
9460  }
9461  if(compute_flag)
9462  compute_val+=do_compute(compute_time);
9463  if(multi_buffer)
9464  {
9465  Index +=reclen;
9466  if(Index > (MAXBUFFERSIZE-reclen))
9467  Index=0;
9468  nbuff = mbuffer + Index;
9469  }
9470 
9471  if(purge)
9472  purgeit(nbuff,reclen);
9473  if(mmapflag)
9474  {
9475  wmaddr = &maddr[((numrecs64-1)-i)*reclen];
9476  fill_area((long long*)wmaddr,(long long*)nbuff,(long long)reclen);
9477  }
9478  else
9479  if(async_flag)
9480  {
9481  if(no_copy_flag)
9482  async_read_no_copy(gc, (long long)fd, &buffer1, ((((numrecs64-1)-i)*reclen)),
9483  reclen, -1LL,(numrecs64*reclen),depth);
9484  else
9485  async_read(gc, (long long)fd, nbuff, (((numrecs64-1)-i)*reclen),
9486  reclen,-1LL,(numrecs64*reclen),depth);
9487  }else
9488  {
9489  if(read((int)fd, (void*)nbuff, (size_t) reclen) != reclen)
9490  {
9491 #ifdef NO_PRINT_LLD
9492  printf("\nError reading block %ld\n", i);
9493 #else
9494  printf("\nError reading block %lld\n", i);
9495 #endif
9496  perror("read");
9497  exit(79);
9498  }
9499  }
9500  if(verify){
9501  if(async_flag && no_copy_flag)
9502  {
9504  exit(80);
9505  }
9506  }
9507  else
9508  {
9509  if(verify_buffer(nbuff,reclen,(off64_t)(numrecs64-1)-i,reclen,(long long)pattern,sverify)){
9510  exit(81);
9511  }
9512  }
9513  }
9514  if(async_flag && no_copy_flag)
9515  async_release(gc);
9516  if(rlocking)
9517  {
9518  mylockr((int) fd, (int) 0, (int)1,
9519  lock_offset, reclen);
9520  }
9521  if (!(h_flag || k_flag || mmapflag))
9522  {
9523  I_LSEEK( fd, (off64_t)-2*reclen, SEEK_CUR );
9524  }
9525  }
9526 #ifdef ASYNC_IO
9527  if(async_flag)
9528  {
9529  end_async(gc);
9530  gc=0;
9531  }
9532 #endif
9533  if(include_flush)
9534  {
9535  if(mmapflag)
9536  msync(maddr,(size_t)filebytes64,MS_SYNC);
9537  else
9538  fsync(fd);
9539  }
9540  if(include_close)
9541  {
9542  if(mmapflag)
9543  {
9544  mmap_end(maddr,(unsigned long long)filebytes64);
9545  }
9546  close(fd);
9547  }
9548  revreadtime[j] = ((time_so_far() - starttime2)-time_res)
9549  -compute_val;
9550  if(revreadtime[j] < (double).000001)
9551  {
9552  revreadtime[j]= time_res;
9553  if(rec_prob < reclen)
9554  rec_prob = reclen;
9555  res_prob=1;
9556  }
9557  if(!include_close)
9558  {
9559  if(mmapflag)
9560  msync(maddr,(size_t)filebytes64,MS_SYNC);
9561  else
9562  fsync(fd);
9563  if(mmapflag)
9564  {
9565  mmap_end(maddr,(unsigned long long)filebytes64);
9566  }
9567  close(fd);
9568  }
9569  if(cpuutilflag)
9570  {
9571  cputime[j] = cputime_so_far() - cputime[j];
9572  if (cputime[j] < cputime_res)
9573  cputime[j] = 0.0;
9574  walltime[j] = time_so_far() - walltime[j];
9575  if (walltime[j] < cputime[j])
9576  walltime[j] = cputime[j];
9577  }
9578  if(restf)
9579  sleep((int)rest_val);
9580  }
9581  if(OPS_flag || MS_flag){
9583  }
9584  for(j=0;j<ltest;j++){
9585  if(MS_flag)
9586  {
9587  revreadrate[j]=1000000.0*(revreadtime[j] / (double)filebytes64);
9588  continue;
9589  }
9590  else
9591  {
9592  revreadrate[j] =
9593  (unsigned long long) ((double) filebytes64 / revreadtime[j]);
9594  }
9595  if(!(OPS_flag || MS_flag))
9596  revreadrate[j] >>= 10;
9597  }
9598  /* Must save walltime & cputime before calling store_value() for each/any cell.*/
9599  if(cpuutilflag)
9600  store_times(walltime[0], cputime[0]);
9601  store_value((off64_t)revreadrate[0]);
9602 #ifdef NO_PRINT_LLD
9603  if(!silent) printf("%8ld",revreadrate[0]);
9604 #else
9605  if(!silent) printf("%8lld",revreadrate[0]);
9606 #endif
9607  if(!silent) fflush(stdout);
9608 }
9609 
9610 /************************************************************************/
9611 /* rewriterec_perf_test */
9612 /* Re-write the same record */
9613 /************************************************************************/
9614 #ifdef HAVE_ANSIC_C
9615 void rewriterec_perf_test(off64_t kilo64 ,long long reclen,long long *data1,long long *data2)
9616 #else
9617 void rewriterec_perf_test(kilo64 ,reclen,data1,data2)
9618 off64_t kilo64;
9619 long long reclen;
9620 long long *data1,*data2;
9621 #endif
9622 {
9623  double writeintime;
9624  double starttime1;
9625  double walltime, cputime;
9626  double compute_val = (double)0;
9627  long long i;
9629  long long flags;
9630  long long Index=0;
9631  unsigned long long writeinrate;
9633  off64_t lock_offset=0;
9634  int fd,wval;
9635  char *maddr;
9636  char *wmaddr,*free_addr,*nbuff;
9637 #if defined(VXFS) || defined(solaris)
9638  int test_foo=0;
9639 #endif
9640 #ifdef ASYNC_IO
9641  struct cache *gc=0;
9642 #else
9643  long long *gc=0;
9644 #endif
9645 
9646  walltime=cputime=0;
9647  maddr=wmaddr=free_addr=nbuff=0;
9648  numrecs64 = (kilo64*1024)/reclen;
9650 /* flags = O_RDWR|O_CREAT|O_TRUNC;*/
9651  flags = O_RDWR|O_CREAT;
9652 #if ! defined(DONT_HAVE_O_DIRECT)
9653 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
9654  if(direct_flag)
9655  flags |=O_DIRECT;
9656 #endif
9657 #if defined(TRU64)
9658  if(direct_flag)
9659  flags |=O_DIRECTIO;
9660 #endif
9661 #endif
9662  if(oflag)
9663  flags |= O_SYNC;
9664 #if defined(O_DSYNC)
9665  if(odsync)
9666  flags |= O_DSYNC;
9667 #endif
9668 #if defined(_HPUX_SOURCE) || defined(linux)
9669  if(read_sync)
9670  flags |=O_RSYNC|O_SYNC;
9671 #endif
9672 /*
9673  if (!no_unlink)
9674  {
9675  if(check_filename(filename))
9676  unlink(filename);
9677  }
9678 */
9679  if(Uflag) /* Unmount and re-mount the mountpoint */
9680  {
9682  }
9683  if((fd = I_OPEN(filename, (int)flags,0640))<0)
9684  {
9685  printf("\nCan not open temporary file %s for write.\n",filename);
9686  perror("open");
9687  exit(84);
9688  }
9689 #ifdef VXFS
9690  if(direct_flag)
9691  {
9692  ioctl(fd,VX_SETCACHE,VX_DIRECT);
9693  ioctl(fd,VX_GETCACHE,&test_foo);
9694  if(test_foo == 0)
9695  {
9696  if(!client_iozone)
9697  printf("\nVxFS advanced setcache feature not available.\n");
9698  exit(3);
9699  }
9700  }
9701 #endif
9702 #if defined(solaris)
9703  if(direct_flag)
9704  {
9705  test_foo = directio(fd, DIRECTIO_ON);
9706  if(test_foo != 0)
9707  {
9708  if(!client_iozone)
9709  printf("\ndirectio not available.\n");
9710  exit(3);
9711  }
9712  }
9713 #endif
9714  if(mmapflag)
9715  {
9716  maddr=(char *)initfile(fd,filebytes64,1,PROT_READ|PROT_WRITE);
9717  }
9718 #ifdef ASYNC_IO
9719  if(async_flag)
9720  async_init(&gc,fd,direct_flag);
9721 #endif
9722  wval=fsync(fd);
9723  if(wval==-1){
9724  perror("fsync");
9725  signal_handler();
9726  }
9727  nbuff=mainbuffer;
9729  if(fetchon)
9730  fetchit(nbuff,reclen);
9731  /*
9732  wval=write(fd, nbuff, (size_t) reclen);
9733  if(wval != reclen)
9734  {
9735 #ifdef NO_PRINT_LLD
9736  printf("\nError writing block %ld, fd= %d\n", 0, fd);
9737 #else
9738  printf("\nError writing block %lld, fd= %d\n", 0, fd);
9739 #endif
9740  if(wval==-1)
9741  perror("write");
9742  signal_handler();
9743  }
9744  */
9745  if(verify || dedup || dedup_interior)
9746  fill_buffer(nbuff,reclen,(long long)pattern,sverify,(long long)0);
9747  starttime1 = time_so_far();
9748  if(cpuutilflag)
9749  {
9750  walltime = time_so_far();
9751  cputime = cputime_so_far();
9752  }
9753  for(i=0; i<numrecs64; i++){
9754  if(rlocking)
9755  {
9756  lock_offset=I_LSEEK(fd,0,SEEK_CUR);
9757  mylockr((int) fd, (int) 1, (int)0,
9758  lock_offset, reclen);
9759  }
9760  if(compute_flag)
9761  compute_val+=do_compute(compute_time);
9762  if(multi_buffer)
9763  {
9764  Index +=reclen;
9765  if(Index > (MAXBUFFERSIZE-reclen))
9766  Index=0;
9767  nbuff = mbuffer + Index;
9768  }
9769  if(async_flag && no_copy_flag)
9770  {
9771  free_addr=nbuff=(char *)malloc((size_t)reclen+page_size);
9772  nbuff=(char *)(((long)nbuff+(long)page_size) & (long)~(page_size-1));
9773  if(verify || dedup || dedup_interior)
9774  fill_buffer(nbuff,reclen,(long long)pattern,sverify,(long long)0);
9775  }
9776  if((verify & diag_v) || dedup || dedup_interior)
9777  fill_buffer(nbuff,reclen,(long long)pattern,sverify,(long long)0);
9778  if(purge)
9779  purgeit(nbuff,reclen);
9780  if(mmapflag)
9781  {
9782  wmaddr = &maddr[i*reclen];
9783  fill_area((long long*)nbuff,(long long*)wmaddr,(long long)reclen);
9784  if(!mmapnsflag)
9785  {
9786  if(mmapasflag)
9787  msync(wmaddr,(size_t)reclen,MS_ASYNC);
9788  if(mmapssflag)
9789  msync(wmaddr,(size_t)reclen,MS_SYNC);
9790  }
9791  }
9792  else
9793  {
9794  if(async_flag)
9795  {
9796  if(no_copy_flag)
9797  async_write_no_copy(gc, (long long)fd, nbuff, reclen, (i*reclen), depth,free_addr);
9798  else
9799  async_write(gc, (long long)fd, nbuff, reclen, (i*reclen), depth);
9800  }
9801  else
9802  {
9803  wval=write(fd, nbuff, (size_t) reclen);
9804  if(wval != reclen)
9805  {
9806 #ifdef NO_PRINT_LLD
9807  printf("\nError writing block %ld, fd= %d\n", i, fd);
9808 #else
9809  printf("\nError writing block %lld, fd= %d\n", i, fd);
9810 #endif
9811  if(wval==-1)
9812  perror("write");
9813  signal_handler();
9814  }
9815  }
9816  }
9817  if(rlocking)
9818  {
9819  mylockr((int) fd, (int) 0, (int)0,
9820  lock_offset, reclen);
9821  }
9822  if (!(h_flag || k_flag || mmapflag))
9823  {
9824  I_LSEEK(fd, (off64_t)0,SEEK_SET);
9825  }
9826  }
9827 
9828 #ifdef ASYNC_IO
9829  if(async_flag)
9830  {
9831  end_async(gc);
9832  gc=0;
9833  }
9834 #endif
9835  if(include_flush)
9836  {
9837  if(mmapflag)
9838  msync(maddr,(size_t)filebytes64,MS_SYNC);/* Clean up before read starts running */
9839  else
9840  {
9841  wval=fsync(fd);
9842  if(wval==-1){
9843  perror("fsync");
9844  signal_handler();
9845  }
9846  }
9847  }
9848  if(include_close)
9849  {
9850  if(mmapflag)
9851  mmap_end(maddr,(unsigned long long)filebytes64);
9852  wval=close(fd);
9853  if(wval==-1){
9854  perror("close");
9855  signal_handler();
9856  }
9857  }
9858  writeintime = ((time_so_far() - starttime1)-time_res)-
9859  compute_val;
9860  if(cpuutilflag)
9861  {
9862  cputime = cputime_so_far() - cputime;
9863  if (cputime < cputime_res)
9864  cputime = 0.0;
9865  walltime = time_so_far() - walltime;
9866  if (walltime < cputime)
9867  walltime = cputime;
9868  }
9869  if(writeintime < (double).000001)
9870  {
9871  writeintime= time_res;
9872  if(rec_prob < reclen)
9873  rec_prob = reclen;
9874  res_prob=1;
9875  }
9876 
9877  if(!include_close)
9878  {
9879  if(mmapflag)
9880  msync(maddr,(size_t)filebytes64,MS_SYNC);/* Clean up before read starts running */
9881  else
9882  {
9883  wval=fsync(fd);
9884  if(wval==-1){
9885  perror("fsync");
9886  signal_handler();
9887  }
9888  }
9889  if(mmapflag)
9890  mmap_end(maddr,(unsigned long long)filebytes64);
9891  wval=close(fd);
9892  if(wval==-1){
9893  perror("close");
9894  signal_handler();
9895  }
9896 
9897  }
9898 
9899  if(OPS_flag || MS_flag){
9901  }
9902  if(MS_flag)
9903  {
9904  writeinrate=1000000.0*(writeintime / (double)filebytes64);
9905  }
9906  else
9907  {
9908  writeinrate = (unsigned long long) ((double) filebytes64 / writeintime);
9909  }
9910  if(!(OPS_flag || MS_flag))
9911  writeinrate >>= 10;
9912  /* Must save walltime & cputime before calling store_value() for each/any cell.*/
9913  if(cpuutilflag)
9914  store_times(walltime, cputime);
9915  store_value((off64_t)writeinrate);
9916 #ifdef NO_PRINT_LLD
9917  if(!silent) printf(" %8ld",writeinrate);
9918 #else
9919  if(!silent) printf(" %8lld",writeinrate);
9920 #endif
9921  if(!silent) fflush(stdout);
9922  if(restf)
9923  sleep((int)rest_val);
9924 }
9925 
9926 /************************************************************************/
9927 /* read_stride_perf_test */
9928 /* Read with a constant stride test */
9929 /************************************************************************/
9930 #ifdef HAVE_ANSIC_C
9931 void read_stride_perf_test(off64_t kilos64,long long reclen,long long *data1,long long *data2)
9932 #else
9933 void read_stride_perf_test(kilos64,reclen,data1,data2)
9934 off64_t kilos64;
9935 long long reclen;
9936 long long *data1, *data2;
9937 #endif
9938 {
9939  double strideintime;
9940  double starttime1;
9941  double compute_val = (double)0;
9942  double walltime, cputime;
9943  off64_t numrecs64,current_position;
9944  long long Index = 0;
9945  off64_t i,savepos64 = 0;
9946  unsigned long long strideinrate;
9948  off64_t lock_offset=0;
9949  long long uu;
9950  off64_t stripewrap=0;
9951  int fd,open_flags;
9952  volatile char *buffer1;
9953  char *nbuff;
9954  char *maddr;
9955  char *wmaddr;
9956 #if defined(VXFS) || defined(solaris)
9957  int test_foo=0;
9958 #endif
9959 #ifdef ASYNC_IO
9960  struct cache *gc=0;
9961 #else
9962  long long *gc=0;
9963 #endif
9964 
9965  walltime=cputime=0;
9966  nbuff=maddr=wmaddr=0;
9967  open_flags=O_RDONLY;
9968 #if ! defined(DONT_HAVE_O_DIRECT)
9969 #if defined(linux) || defined(__AIX__) || defined(IRIX) || defined(IRIX64) || defined(Windows) || defined (__FreeBSD__)
9970  if(direct_flag)
9971  open_flags |=O_DIRECT;
9972 #endif
9973 #if defined(TRU64)
9974  if(direct_flag)
9975  open_flags |=O_DIRECTIO;
9976 #endif
9977 #endif
9978 #if defined(_HPUX_SOURCE) || defined(linux)
9979  if(read_sync)
9980  open_flags |=O_RSYNC|O_SYNC;
9981 #endif
9982  next64 = (off64_t)0;
9983  numrecs64 = (kilos64*1024)/reclen;
9985  if(Uflag) /* Unmount and re-mount the mountpoint */
9986  {
9988  }
9989  if((fd = I_OPEN(filename, (int)open_flags, 0640))<0)
9990  {
9991  printf("\nCan not open temporary file for read\n");
9992  perror("open");
9993  exit(86);
9994  }
9995 #ifdef ASYNC_IO
9996  if(async_flag)
9997  async_init(&gc,fd,direct_flag);
9998 #endif
9999 
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;
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,
10075  else
10076  async_read(gc, (long long)fd, nbuff, current_position, reclen,
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){
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];
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  {
10284  }
10285  else
10286  {
10287  numrecs64 = (kilos64*1024)/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  {
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;
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){
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];
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  {
10575  }
10576  else
10577  {
10578  numrecs64 = (kilos64*1024)/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  {
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;
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 
10722  if(OPS_flag || MS_flag){
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];
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;
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  {
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;
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){
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;
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;
11130  unsigned long long preadvrate[2];
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;
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  {
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;
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){
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
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
11519 off64_t value;
11520 #endif
11521 {
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
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();
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
11654 #endif
11655 {
11656  if(bif_flag)
11657  {
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
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
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
12273 #else
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 *
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
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)
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  {
12371  }
12372  else
12373  {
12375  }
12376  written_so_far=read_so_far=re_written_so_far=re_read_so_far=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  {
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)
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)
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  }
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  {
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  {
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  }
12680  (time_so_far() - starttime1)-time_res;
12681  if(include_close)
12682  {
12683  if((fd = I_OPEN(dummyfile[xx], (int)flags,0))<0)
12684  {
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  {
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  }
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();
12777  (temp_time - starttime1)-time_res;
12778  if(child_stat->throughput < (double).000001)
12779  {
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  }
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  }
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  }
12854  written_so_far+=reclen/1024;
12855  if(*stop_flag)
12856  {
12857  written_so_far-=reclen/1024;
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  {
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  }
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  {
12933  if (cputime < cputime_res)
12934  cputime = 0.0;
12938  }
12939  if(distributed && client_iozone)
12941  child_stat->actual,
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,
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
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)
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  {
13071  }
13072  else
13073  {
13075  }
13076  written_so_far=read_so_far=re_written_so_far=re_read_so_far=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  {
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  {
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)
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)
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  }
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  {
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  {
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  }
13343  (time_so_far() - starttime1)-time_res;
13344  if(child_stat->throughput < (double).000001)
13345  {
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  }
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();
13415  (temp_time - starttime1)-time_res;
13416  if(child_stat->throughput < (double).000001)
13417  {
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  }
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  }
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  }
13497  written_so_far+=reclen/1024;
13498  if(*stop_flag)
13499  {
13500  written_so_far-=reclen/1024;
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  {
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  }
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  {
13566  if (cputime < cputime_res)
13567  cputime = 0.0;
13571  }
13572  if(distributed && client_iozone)
13574  child_stat->actual,
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,
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 *
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)
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;
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  {
13701  }
13702  else
13703  {
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  {
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
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)
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);
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  {
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  }
13898  if(distributed && client_iozone)
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  }
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  }
14048  signal_handler();
14049  }
14050  }
14051  }
14052  re_written_so_far+=reclen/1024;
14055  if(*stop_flag)
14056  {
14057  re_written_so_far-=reclen/1024;
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  }
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  {
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  }
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  {
14158  if (cputime < cputime_res)
14159  cputime = 0.0;
14163  }
14164  if(distributed && client_iozone)
14166  child_stat->actual,
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 *
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)
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;
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  {
14286  }
14287  else
14288  {
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  {
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  {
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  {
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)
14477  if(fetchon)
14478  fetchit(nbuff,reclen);
14479  child_stat=(struct child_stats *)&shmaddr[xx];
14481  if(distributed && client_iozone)
14482  {
14485  }
14486  else
14487  {
14488  /* Wait for signal from parent */
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  }
14606  exit(132);
14607  }
14608  }
14609  }
14610  if(verify){
14611  if(async_flag && no_copy_flag)
14612  {
14614  if (!no_unlink)
14615  {
14616  if(check_filename(dummyfile[xx]))
14617  unlink(dummyfile[xx]);
14618  }
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  }
14632  exit(134);
14633  }
14634  }
14635  }
14636  if(async_flag && no_copy_flag)
14637  async_release(gc);
14638  read_so_far+=reclen/1024;
14641  if(*stop_flag)
14642  {
14643  read_so_far-=reclen/1024;
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  {
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  {
14744  if (cputime < cputime_res)
14745  cputime = 0.0;
14749  }
14750  if(distributed && client_iozone)
14752  child_stat->actual,
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)
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;
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  {
14870  }
14871  else
14872  {
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  {
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  {
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  {
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)
15035  if(fetchon)
15036  fetchit(nbuff,reclen);
15037  child_stat=(struct child_stats *)&shmaddr[xx];
15039  if(distributed && client_iozone)
15040  {
15043  }
15044  else
15045  {
15046  /* Wait for signal from parent */
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  }
15138  exit(132);
15139  }
15140  }
15141  }
15142  if(verify){
15143  if(async_flag && no_copy_flag)
15144  {
15146  if (!no_unlink)
15147  {
15148  if(check_filename(dummyfile[xx]))
15149  unlink(dummyfile[xx]);
15150  }
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  }
15164  exit(134);
15165  }
15166  }
15167  }
15168  if(async_flag && no_copy_flag)
15169  async_release(gc);
15170  read_so_far+=reclen/1024;
15173  if(*stop_flag)
15174  {
15175  read_so_far-=reclen/1024;
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  {
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  {
15271  if (cputime < cputime_res)
15272  cputime = 0.0;
15276  }
15277  if(distributed && client_iozone)
15279  child_stat->actual,
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 *
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)
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;
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  {
15400  }
15401  else
15402  {
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  {
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)
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  {
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  {
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;
15588 
15589  if(distributed && client_iozone)
15590  {
15593  }
15594  else
15595 
15596  /* Wait for signal from parent */
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  }
15713  exit(137);
15714  }
15715  }
15716  }
15717  if(verify){
15718  if(async_flag && no_copy_flag)
15719  {
15721  if (!no_unlink)
15722  {
15723  if(check_filename(dummyfile[xx]))
15724  unlink(dummyfile[xx]);
15725  }
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  }
15739  exit(139);
15740  }
15741  }
15742  }
15743  if(async_flag && no_copy_flag)
15744  async_release(gc);
15745  re_read_so_far+=reclen/1024;
15748  if(*stop_flag)
15749  {
15750  re_read_so_far-=reclen/1024;
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  {
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  {
15845  if (cputime < cputime_res)
15846  cputime = 0.0;
15850  }
15851  if(distributed && client_iozone)
15852  {
15854  child_stat->actual,
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 *
15915 #else
15916 void *
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)
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  {
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  {
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  {
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;
16144  if(distributed && client_iozone)
16145  {
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  {
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  {
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  }
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  }
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  }
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  {
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  {
16386  if (cputime < cputime_res)
16387  cputime = 0.0;
16391  }
16392  if(distributed && client_iozone)
16394  child_stat->actual,
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 *
16446 #else
16447 void *
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)
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  {
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  {
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  {
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;
16678  if(distributed && client_iozone)
16679  {
16682  }
16683  else
16684 
16685  /* wait for parent to say go */
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),
16740  else
16741  async_read(gc, (long long)fd, nbuff, (current_position),reclen,
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  }
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  }
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  }
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  {
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  {
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  {
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  {
16928  if (cputime < cputime_res)
16929  cputime = 0.0;
16933  }
16934  if(distributed && client_iozone)
16935  {
16937  child_stat->actual,
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 *
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)
17039  else
17041  }
17042  else
17043  {
17044  if(seq_mix)
17046  else
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 *
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)
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  {
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  {
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  {
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];
17353  if(distributed && client_iozone)
17354  {
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  {
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  }
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  }
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  }
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  {
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  {
17615  if (cputime < cputime_res)
17616  cputime = 0.0;
17620  }
17621  if(distributed && client_iozone)
17623  child_stat->actual,
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 *
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;
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)
17736  hist_time=thread_qtime_stop=thread_qtime_start=0;
17737  traj_offset=walltime=cputime=0;
17738  anwser=bind_cpu=0;
17740  written_so_far=read_so_far=re_written_so_far=re_read_so_far=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  {
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  {
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  {
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  {
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  {
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  }
18074  (time_so_far() - starttime1)-time_res;
18075  if(child_stat->throughput < (double).000001)
18076  {
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  }
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();
18145  (temp_time - starttime1)-time_res;
18146  if(child_stat->throughput < (double).000001)
18147  {
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  }
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  }
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  }
18227  written_so_far+=reclen/1024;
18228  if(*stop_flag)
18229  {
18230  written_so_far-=reclen/1024;
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  {
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  }
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  {
18297  if (cputime < cputime_res)
18298  cputime = 0.0;
18302  }
18303  if(distributed && client_iozone)
18305  child_stat->actual,
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 *
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];
18416  if(distributed && client_iozone)
18417  {
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)
18432  child_stat->actual,
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
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
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
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
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 *
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
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
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  {
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  {
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)
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
18781 double value;
18782 #endif
18783 {
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
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
19027 {
19028  printf("Your system does not support async I/O\n");
19029  exit(169);
19030 }
19031 size_t
19033 {
19034  printf("Your system does not support async I/O\n");
19035  exit(170);
19036 }
19037 size_t
19039 {
19040  printf("Your system does not support async I/O\n");
19041  exit(171);
19042 }
19043 void
19045 {
19046  printf("Your system does not support async I/O\n");
19047  exit(172);
19048 }
19049 int
19051 {
19052  printf("Your system does not support async I/O\n");
19053  exit(172);
19054 }
19055 void
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 /************************************************************************/
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
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
19172 #else
19173 void
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
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
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
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
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 *
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",
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 *
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",
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
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",
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
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",
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
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
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
20068 #else
20069 off64_t
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];
20112  }
20113  }
20114  else
20115  {
20116  for(size=min_r_size;size<=max_r_size;size*=multiplier)
20117  {
20119  }
20120  }
20121 }
20122 
20123 #ifdef HAVE_ANSIC_C
20124 void
20125 del_record_sizes(void)
20126 #else
20127 void
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
20153 #else
20154 void
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
20191 #else
20192 off64_t
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
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
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
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
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
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 */
21340 
21342  /* Step 1. Now start client going on remote node. */
21343 
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);
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 
21373 
21374  if(mdebug>=1)
21375  printf("\nMaster listening for child to send join message.\n");
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");
21404  &my_s_addr);
21405  if(mdebug>=1)
21406  printf("Starting master send async channel\n");
21408  my_s_addr);
21409 
21412  child_idents[x-1].child_number = x-1;
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);
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;
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;
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;
21458  cc.c_op_rate = op_rate;
21460  cc.c_file_lock = file_lock;
21461  cc.c_rec_lock = rlocking;
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;
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;
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;
21487  cc.c_no_unlink = no_unlink;
21488  cc.c_no_write = no_write;
21492  cc.c_delay = delay;
21493  cc.c_stride = stride;
21494  cc.c_rest_val = rest_val;
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 
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");
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
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 
21598 
21599  /* 2. Send message to controller saying I'm joining. */
21600 
21602  strcpy(mc.m_client_name,client_name);
21603  mc.m_child_port = child_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",
21612  fflush(newstdout);
21613  }
21614  child_send(controlling_host_name,(struct master_command *)&mc, sizeof(struct master_command));
21615 
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"
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 
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;
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;
21787  fetchon = cc.c_fetchon;
21788  verify = cc.c_verify;
21789  diag_v = cc.c_diag_v;
21790  dedup = cc.c_dedup;
21795  op_rate = cc.c_op_rate;
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;
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. */
21809  num_child=(long long)cc.c_num_child;
21810  pct_read=cc.c_pct_read;
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;
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;
21828  no_unlink = cc.c_no_unlink;
21829  no_write = cc.c_no_write;
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;
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)
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 */
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
22062 #else
22063 void
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
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;
22097  mc.m_client_number = (int)chid;
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
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
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  {
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];
22227  child_stat->actual = mc.m_actual;
22231  *stop_flag = mc.m_stop_flag;
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
22285 #else
22286 void
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));
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 */
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;
22347  sleep(2);
22348  /* Aync listener goes away */
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
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;
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
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
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;
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
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
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
22536 #else
22537 void
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  {
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
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
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;
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
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
22691 #endif
22692 {
22693  int i;
22694  for(i=0;i<num_child;i++)
22695  {
22698  }
22699 }
22700 
22701 #ifdef HAVE_ANSIC_C
22702 void
22703 find_remote_shell(char *shell)
22704 #else
22705 void
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
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 
22785 
22788 
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];
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);
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 
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  }
22860  sp_do_child_t();
22861  free(sp_buf);
22862  exit(0);
22863  }
22864  x=fork();
22865  if(x==0)
22866  {
22868  sprintf(sp_command,"%s %s %s -+s -t 1 -r %d -s %d -+c %s -+t ",
22870  sp_location, (int)reclen/1024,
22871  (int)kilos,sp_master_host);
22872  /*printf("%s\n",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  }
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);
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
22969 char *sp_child_host_name;
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
23184 #endif
23185 {
23186  int i,y;
23187  int offset;
23188  int sp_tcount=0;
23189  /* child */
23190  /*
23191  * Child reads from master
23192  */
23195  for(i=0;i<sp_count;i++)
23196  {
23197  offset=0;
23198  while(offset<sp_msize)
23199  {
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  }
23221 
23222  close(sp_crfd);
23223  sleep(1); /* Wait for master to get into sp_get_result */
23225  (float)(sp_tcount/1024)/(sp_finish_time-sp_start_time));
23226 
23227  sleep(1);
23228  /*
23229  * Child writes to master
23230  */
23232  &sp_my_cs_addr);
23233  sp_tcount=0;
23234  offset=0;
23236  for(i=0;i<sp_count;i++)
23237  {
23239  sp_tcount+=y;
23240  }
23242  close(sp_csfd);
23243  sleep(1);
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
23262 #endif
23263 {
23264  int i,y,sp_offset;
23265  int sp_tcount = 0;
23266 
23267 
23268  /*
23269  * Master writes to child
23270  */
23272  &sp_my_ms_addr);
23274  for(i=0;i<sp_count;i++)
23275  {
23277  sp_tcount+=y;
23278  }
23280  close(sp_msfd);
23281  sp_msfd=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  */
23292  sp_offset=0;
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  }
23314  printf("%-20s received %10d kbytes @ %10.2f Kbytes/sec \n",
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
23332 int sp_size_of_message;
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
23421 char *sp_master_host_name;
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,
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
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
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
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
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);
23690  }
23691 }
23692 #ifdef HAVE_ANSIC_C
23693 void
23694 stop_monitor(char *test)
23695 #else
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);
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
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
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)
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  {
24475  }
24476  else
24477  {
24479  }
24480  written_so_far=read_so_far=re_written_so_far=re_read_so_far=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  {
24556  }
24557 
24558  if(First_Run==1)
24559  {
24560  First_Run=0;
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 
24599  if(fetchon)
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)
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  }
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  {
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  {
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)
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  }
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  {
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  }
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  {
24780  if (cputime < cputime_res)
24781  cputime = 0.0;
24785  }
24786  if(distributed && client_iozone)
24788  child_stat->actual,
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,
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){
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
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
24903  char tmpname[256];
24904  FILE *thread_wqfd;
24905  FILE *thread_Lwqfd;
24906 
24907  if(compute_flag)
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  {
24923  }
24924  else
24925  {
24927  }
24928  written_so_far=read_so_far=re_written_so_far=re_read_so_far=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  {
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 
25032  if(fetchon)
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)
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  }
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  {
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  {
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)
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){
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  }
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  {
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  }
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  {
25221  if (cputime < cputime_res)
25222  cputime = 0.0;
25226  }
25227  if(distributed && client_iozone)
25229  child_stat->actual,
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,
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){
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 }
int check_filename()
long long orig_max_rec_size
Definition: iozone.c:1383
void end_async()
char sp_remote_host[256]
Definition: iozone.c:22808
long long c_depth
Definition: iozone.c:574
int atoi()
char wol_opened
Definition: iozone.c:1341
ssize_t read(int fd, void *buf, size_t count)
Definition: appio.c:225
int c_version
Definition: iozone.c:557
long long bucket_val[BUCKETS]
Definition: iozone.c:24213
#define IBUFSIZE
Definition: iozone.c:775
char c_path_dir[200]
Definition: iozone.c:496
long long depth
Definition: iozone.c:1536
void fetchit()
void find_external_mon(char *imon_start, char *imon_stop)
Definition: iozone.c:22729
void become_client()
Definition: iozone.c:21555
int c_num_child
Definition: iozone.c:559
char c_dedup_compress[4]
Definition: iozone.c:619
#define C_STATE_ZERO
Definition: iozone.c:1449
char fflag
Definition: iozone.c:1329
long long genrand64_int63(void)
Definition: iozone.c:23960
int c_share_file
Definition: iozone.c:555
void purgeit()
unsigned long cache_line_size
Definition: iozone.c:1376
store_times(double walltime, double cputime)
Definition: iozone.c:11551
char pit_hostname[40]
Definition: iozone.c:1400
int c_read_sync
Definition: iozone.c:505
int c_diag_v
Definition: iozone.c:516
VOLATILE char * pbuffer
Definition: iozone.c:1368
long long rec_prob
Definition: iozone.c:1294
char c_r_traj_flag[2]
Definition: iozone.c:642
int h_errno
int c_cpuutilflag
Definition: iozone.c:544
void mix_perf_test()
char m_command[20]
Definition: iozone.c:716
char * test_output[]
Definition: iozone.c:1234
long long include_test[50]
Definition: iozone.c:1331
rc
Definition: pscanf.h:23
static const char * name
Definition: fork_overflow.c:31
int w_traj_flag
Definition: iozone.c:1523
int current_client_number
Definition: iozone.c:1528
long long c_delay
Definition: iozone.c:567
long long c_delay_start
Definition: iozone.c:573
int pick_client()
int mdebug
Definition: iozone.c:1479
char compute_flag
Definition: iozone.c:1520
char * getenv()
#define HOST_ESEND_PORT
Definition: iozone.c:1408
#define CHILD_ESEND_PORT
Definition: iozone.c:1415
int child_send_socket
Definition: iozone.c:1466
FILE * rrqfd
Definition: iozone.c:1342
int sp_master_listen_port
Definition: iozone.c:22786
char diag_v
Definition: iozone.c:1304
void del_cache()
#define RANDOM_MIX_MASK
Definition: iozone.c:923
int controlling_host_port
Definition: iozone.c:1410
int sp_start_child_send()
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
Definition: appio.c:387
char m_client_number[20]
Definition: iozone.c:711
int get_client_info()
Definition: iozone.c:22417
char sp_command[1024]
Definition: iozone.c:22796
Definition: iozone.c:1350
FILE * rqfd
Definition: iozone.c:1342
int sp_csfd
Definition: iozone.c:1292
long long xover
Definition: iozone.c:1384
FILE * r_traj_fd
Definition: iozone.c:1367
void *() thread_rread_test()
long long r_traj_fsize
Definition: iozone.c:1325
int s_count
Definition: iozone.c:1286
char rol_opened
Definition: iozone.c:1341
static int mti
Definition: iozone.c:23884
store_value(off64_t value)
Definition: iozone.c:11518
void mmap_end()
char controlling_host_name[100]
Definition: iozone.c:1493
unsigned long int pthread_t
char sflag
Definition: iozone.c:1303
#define CHILD_STATE_HOLD
Definition: iozone.c:942
long long onetime
Definition: iozone.c:1290
__time_t tv_sec
off64_t s_range[100]
Definition: iozone.c:1283
void sp_do_master_t(void)
Definition: iozone.c:23261
char Cflag
Definition: iozone.c:1371
long long get_traj()
char verify
Definition: iozone.c:1513
int c_verify
Definition: iozone.c:513
int toutputindex
Definition: iozone.c:1477
char Kplus_flag
Definition: iozone.c:1509
void cleanup_comm()
Definition: iozone.c:22690
char imon_sync
Definition: iozone.c:1319
int pit_gettimeofday()
struct child_stats * child_stat
#define WRITER_TEST
Definition: iozone.c:902
long long stride
Definition: iozone.c:1532
float cpuutil
Definition: iozone.c:472
void touch_dedup()
void do_label()
int c_L_flag
Definition: iozone.c:525
char c_version[20]
Definition: iozone.c:661
int c_disrupt_flag
Definition: iozone.c:534
char c_path_dir[200]
Definition: iozone.c:596
size_t async_write()
Definition: iozone.c:19038
off64_t get_next_file_size()
#define READER_TEST
Definition: iozone.c:903
char c_working_dir[200]
Definition: iozone.c:494
char c_testnum[20]
Definition: iozone.c:657
int sp_start_master_send(char *sp_child_host_name, int sp_child_listen_port, struct in_addr *sp_my_ms_addr)
Definition: iozone.c:22968
long long w_traj_bytes_completed
Definition: iozone.c:1327
#define I_MMAP(a, b, c, d, e, f)
Definition: iozone.c:1191
char c_advise_flag[4]
Definition: iozone.c:666
start_monitor(char *test)
Definition: iozone.c:23678
void *() thread_reverse_read_test()
void show_help()
Definition: iozone.c:3318
int m_testnum
Definition: iozone.c:692
int no_unlink
Definition: iozone.c:1521
int c_testnum
Definition: iozone.c:548
#define THREAD_PWRITE_TEST
Definition: iozone.c:1438
int master_listen_port
Definition: iozone.c:1472
void bzero()
int no_write
Definition: iozone.c:1522
void speed_main(char *, char *, long long, long long, int)
Definition: iozone.c:22822
FILE * rwqfd
Definition: iozone.c:1342
int sp_cret
Definition: iozone.c:22807
int client_listen_pid
Definition: iozone.c:1457
void *() thread_fread_test()
void find_remote_shell()
void master_send()
int c_pct_read
Definition: iozone.c:560
char c_mmapasflag[2]
Definition: iozone.c:628
off64_t offset
Definition: iozone.c:1279
void tell_master_stats()
if(file==NULL) goto out
int c_stride_flag
Definition: iozone.c:512
FILE * newstdin
Definition: iozone.c:1475
void fill_buffer()
int state
Definition: iozone.c:1499
char * sp_buf
Definition: iozone.c:22795
VOLATILE struct child_stats * shmaddr
Definition: iozone.c:1267
char c_mmapssflag[2]
Definition: iozone.c:630
char c_no_copy_flag[2]
Definition: iozone.c:631
char mmapflag
Definition: iozone.c:1512
void O_stop_child_send(int child_socket_val)
Definition: iozone.c:20708
struct sockaddr_in6 sockaddr_in6_t
Definition: iozone.c:24052
char k_flag
Definition: iozone.c:1509
void add_record_size()
char child_rcv_buf[4096]
Definition: iozone.c:1463
#define MAXNAMESIZE
Definition: iozone.c:833
int fd
Definition: iozone.c:1291
int child_async_port
Definition: iozone.c:1456
void *() thread_stride_read_test()
#define DISRUPT
Definition: iozone.c:779
long long m_child_flag
Definition: iozone.c:699
char dedup_compress
Definition: iozone.c:1304
char splash[80][80]
Definition: iozone.c:1394
long lrand48()
char c_num_child[20]
Definition: iozone.c:663
#define RANDOM_RW_MASK
Definition: iozone.c:922
void sp_send_result(int, int, float)
Definition: iozone.c:22940
#define MATRIX_A
Definition: iozone.c:23876
#define THREAD_PREAD_TEST
Definition: iozone.c:1439
#define THREAD_RANDOM_WRITE_TEST
Definition: iozone.c:1435
int restf
Definition: iozone.c:1514
char m_throughput[80]
Definition: iozone.c:720
void *() thread_fwrite_test()
char rflag
Definition: iozone.c:1303
float actual
Definition: iozone.c:463
void *() thread_rwrite_test()
int bif_column
Definition: iozone.c:1298
int master_send_async_sockets[MAXSTREAMS]
Definition: iozone.c:1471
char c_Kplus_readers[10]
Definition: iozone.c:654
long long c_purge
Definition: iozone.c:568
#define STRIDE_READ_MASK
Definition: iozone.c:926
char trflag
Definition: iozone.c:1320
char c_hist_summary[4]
Definition: iozone.c:621
void read_perf_test()
void child_send()
char mountname[MAXNAMESIZE]
Definition: iozone.c:1361
long long w_traj_size()
Definition: iozone.c:19825
void signal_handler()
Definition: iozone.c:3336
#define CONTROL_STRING4
Definition: iozone.c:879
#define TOOFAST
Definition: iozone.c:818
char * barray[MAXSTREAMS]
Definition: iozone.c:1287
int get_pattern()
Definition: iozone.c:23584
int c_advise_op
Definition: iozone.c:561
void sp_do_child_t(void)
Definition: iozone.c:23183
#define PATTERN
Definition: iozone.c:822
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
Definition: appio.c:275
#define R_JOIN_ACK
Definition: iozone.c:741
int advise_op
Definition: iozone.c:1526
int master_async_socket_num
Definition: iozone.c:1504
char remote_shell[256]
Definition: iozone.c:1397
char file_name[200]
Definition: iozone.c:1498
dump_times(long long who)
Definition: iozone.c:11804
off64_t r_range[100]
Definition: iozone.c:1282
void add_file_size()
void create_list()
char dummyfile[MAXSTREAMS][MAXNAMESIZE]
Definition: iozone.c:1362
char m_version[20]
Definition: iozone.c:718
void prepage()
void get_date()
void dummy(void *array)
Definition: do_loops.c:306
char stride_flag
Definition: iozone.c:1512
char filename[MAXNAMESIZE]
Definition: iozone.c:1360
long long max_y
Definition: iozone.c:1275
int sp_msfd
Definition: iozone.c:1292
#define INVALID_DESC
Definition: iozone.c:24039
char master_rcv_buf[4096]
Definition: iozone.c:1460
long long multi_buffer
Definition: iozone.c:1290
#define THREAD_REREAD_TEST
Definition: iozone.c:1432
#define I_STAT(x, y)
Definition: iozone.c:1186
void master_listen()
char c_read_traj_filename[200]
Definition: iozone.c:499
char sp_remote_shell[100]
Definition: iozone.c:22797
int retval
Definition: zero_fork.c:53
#define THREAD_WRITE_TEST
Definition: iozone.c:1429
int dedup_mseed
Definition: iozone.c:1299
float m_throughput
Definition: iozone.c:695
int c_mmap_mix
Definition: iozone.c:538
char c_execute_name[200]
Definition: iozone.c:497
#define CHILD_STATE_BEGIN
Definition: iozone.c:946
static struct timeval start
#define THREAD_FREAD_TEST
Definition: iozone.c:1441
long long * pstatus
Definition: iozone.c:1377
#define R_DEATH
Definition: iozone.c:744
int thread_exit()
Definition: iozone.c:18526
char c_pit_service[8]
Definition: iozone.c:492
char disrupt_flag
Definition: iozone.c:1520
char child_send_buf[4096]
Definition: iozone.c:1465
#define I_LSEEK(x, y, z)
Definition: iozone.c:1182
long long c_reclen
Definition: iozone.c:571
void stop_child_send()
void disrupt()
int sp_once
Definition: iozone.c:22799
int c_Q_flag
Definition: iozone.c:524
struct size_entry * size_list
Definition: iozone.c:1354
#define SP_MASTER_ESEND_PORT
Definition: iozone.c:1425
char child_name[100]
Definition: iozone.c:1495
#define I_OPEN(x, y, z)
Definition: iozone.c:1183
float walltime
Definition: iozone.c:470
int advise_flag
Definition: iozone.c:1526
char c_op_rate_flag[2]
Definition: iozone.c:623
char c_host_name[100]
Definition: iozone.c:590
int l_async_sock
Definition: iozone.c:1459
int sp_master_results_port
Definition: iozone.c:22789
stop_monitor(char *test)
Definition: iozone.c:23696
char nflag
Definition: iozone.c:1311
static FILE * fp
int c_no_write
Definition: iozone.c:550
struct sockaddr_in sockaddr_in_t
Definition: iozone.c:24051
double c
Definition: multiplex.c:22
char execute_path[200]
Definition: iozone.c:1497
long long w_traj_ops_completed
Definition: iozone.c:1327
int a_port
Definition: iozone.c:1454
char c_cpuutilflag[2]
Definition: iozone.c:644
char m_client_name[100]
Definition: iozone.c:685
char c_compute_time[80]
Definition: iozone.c:675
long long reclen
Definition: iozone.c:1535
int num_processors
Definition: iozone.c:1293
char workdir[200]
Definition: iozone.c:1496
double sp_start_time
Definition: iozone.c:22801
char c_notruncate[2]
Definition: iozone.c:604
#define MAXBFRSIZE
Definition: iozone.c:24040
#define FREADER_MASK
Definition: iozone.c:928
char c_base_time[20]
Definition: iozone.c:662
double tmp
int c_stop_flag
Definition: iozone.c:540
char c_numrecs64[80]
Definition: iozone.c:672
#define DEDUPSEED
Definition: iozone.c:449
void(* func[])()
Definition: iozone.c:1198
char read_sync
Definition: iozone.c:1295
long long myid
Definition: iozone.c:1335
char c_rest_val[10]
Definition: iozone.c:647
int c_no_copy_flag
Definition: iozone.c:531
int child_listen_socket
Definition: iozone.c:1467
#define BUCKETS
Definition: iozone.c:24211
void do_float()
void Kill()
char c_compute_flag[2]
Definition: iozone.c:635
long long w_traj_fsize
Definition: iozone.c:1325
#define NUMRECS
Definition: iozone.c:798
void init_genrand64(unsigned long long seed)
Definition: iozone.c:23887
#define MAX_Y
Definition: iozone.c:827
int op_rate
Definition: iozone.c:1301
char distributed
Definition: iozone.c:1296
long long maxt
Definition: iozone.c:1324
off64_t offset64
Definition: iozone.c:1280
long long c_numrecs64
Definition: iozone.c:570
char hflag
Definition: iozone.c:1303
int gen_new_buf()
struct size_entry * rec_size_list
Definition: iozone.c:1355
char master_send_buf[4096]
Definition: iozone.c:1462
#define RECLEN_START
Definition: iozone.c:893
int mylockf()
char use_thread
Definition: iozone.c:1372
#define READER_MASK
Definition: iozone.c:921
void *() thread_ranread_test()
int c_k_flag
Definition: iozone.c:508
char c_read_traj_filename[200]
Definition: iozone.c:599
unsigned long long genrand64_int64(void)
Definition: iozone.c:23922
float compute_time
Definition: iozone.c:1538
float throughput
Definition: iozone.c:462
void async_init()
Definition: iozone.c:19044
void fread_perf_test()
char * sp_dest
Definition: iozone.c:22781
off64_t get_next_record_size()
char Uflag
Definition: iozone.c:1329
int sp_start_child_listen(int listen_port, int size_of_message)
Definition: iozone.c:23090
char * dedup_ibuf
Definition: iozone.c:1305
void del_record_sizes()
Definition: iozone.c:20128
int m_child_port
Definition: iozone.c:689
FILE * newstderr
Definition: iozone.c:1475
int async_read_no_copy()
Definition: iozone.c:19050
void sp_get_result(int, int)
Definition: iozone.c:22905
int master_listen_pid
Definition: iozone.c:1461
char m_stop_flag
Definition: iozone.c:686
#define C_STATE_WAIT_BARRIER
Definition: iozone.c:1451
int c_no_unlink
Definition: iozone.c:549
char * mbuffer
Definition: iozone.c:1366
char gflag
Definition: iozone.c:1311
char c_pit_hostname[40]
Definition: iozone.c:491
#define THREAD_RANDOM_READ_TEST
Definition: iozone.c:1434
int c_file_lock
Definition: iozone.c:551
char c_working_dir[200]
Definition: iozone.c:594
long base_time
Definition: iozone.c:1323
void auto_test()
Definition: iozone.c:3404
__syscall_slong_t tv_nsec
#define THREAD_REVERSE_READ_TEST
Definition: iozone.c:1436
char client_iozone
Definition: iozone.c:1296
struct runtime runtimes[MAX_X][MAX_Y]
Definition: iozone.c:1330
char c_pattern[20]
Definition: iozone.c:660
void srand48()
char c_fetchon[10]
Definition: iozone.c:649
#define R_TERMINATE
Definition: iozone.c:743
char noretest
Definition: iozone.c:1510
char MS_flag
Definition: iozone.c:1525
char cpuutilflag
Definition: iozone.c:1321
int start_master_listen()
Definition: iozone.c:20277
#define CACHE_LINE_SIZE
Definition: iozone.c:750
int sp_child_esend_port
Definition: iozone.c:22784
long long debug1
Definition: iozone.c:1373
void do_speed_check()
void *() thread_ranwrite_test()
void child_listen_async()
int c_dedup_compress
Definition: iozone.c:519
long long debug
Definition: iozone.c:1374
char * alloc_mem()
off64_t filebytes64
Definition: iozone.c:1281
int c_base_time
Definition: iozone.c:558
char include_flush
Definition: iozone.c:1519
char c_command[20]
Definition: iozone.c:656
#define MM
Definition: iozone.c:23875
dump_report(long long who)
Definition: iozone.c:11567
char sverify
Definition: iozone.c:1515
FILE * pi
Definition: iozone.c:1367
long long mint
Definition: iozone.c:1324
int m_child_async_port
Definition: iozone.c:690
ssize_t write(int fd, const void *buf, size_t count)
Definition: appio.c:298
char X_flag
Definition: iozone.c:1520
long long delay_start
Definition: iozone.c:1536
void stop_master_listen()
void srand()
int multiplier
Definition: iozone.c:1539
char unbuffered
Definition: iozone.c:1509
char jflag
Definition: iozone.c:1509
char aflag
Definition: iozone.c:1303
long long throughput_array[MAX_X]
Definition: iozone.c:1272
int w_traj_items
Definition: iozone.c:1328
char master_iozone
Definition: iozone.c:1296
void wait_for_master_go()
void dump_throughput()
Definition: iozone.c:18694
int m_command
Definition: iozone.c:691
int child_port
Definition: iozone.c:1501
int one
#define PATTERN1
Definition: iozone.c:823
char include_tflag
Definition: iozone.c:1329
char * initfile()
int l_sock
Definition: iozone.c:1459
char c_include_flush[2]
Definition: iozone.c:633
char Eflag
Definition: iozone.c:1303
long long sfd
Definition: iozone.c:1290
static int pid
long long page_size
Definition: iozone.c:428
void get_rusage_resolution()
Definition: iozone.c:19174
long long delay
Definition: iozone.c:1533
off64_t maximum_file_size
Definition: iozone.c:1356
int file_lock
Definition: iozone.c:1530
static unsigned long long mt[NN]
Definition: iozone.c:23882
long long purge
Definition: iozone.c:1533
int bif_row
Definition: iozone.c:1298
char async_flag
Definition: iozone.c:1512
char m_client_error[20]
Definition: iozone.c:712
char mmapasflag
Definition: iozone.c:1512
int c_async_flag
Definition: iozone.c:507
size_t async_write_no_copy()
Definition: iozone.c:19032
int bif_fd
Definition: iozone.c:1297
int m_version
Definition: iozone.c:693
#define R_FLAG_DATA
Definition: iozone.c:733
char c_async_flag[2]
Definition: iozone.c:607
#define NN
Definition: iozone.c:23874
struct child_ident child_idents[MAXSTREAMS]
float cputime
Definition: iozone.c:461
int c_rec_lock
Definition: iozone.c:552
char c_disrupt_flag[2]
Definition: iozone.c:634
char * build_name
Definition: iozone.c:1316
int sp_msize
Definition: iozone.c:22799
int wait()
char sent_stop
Definition: iozone.c:1304
char c_file_lock[10]
Definition: iozone.c:652
int c_mmapflag
Definition: iozone.c:527
char * inet_ntoa()
void init_by_array64(unsigned long long *, unsigned long long)
void throughput_test()
Definition: iozone.c:3530
int pct_read
Definition: iozone.c:1336
void get_resolution()
Definition: iozone.c:19131
int cdebug
Definition: iozone.c:1478
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
Definition: appio.c:199
#define CONTROL_STRING3
Definition: iozone.c:878
#define SP_MASTER_RESULTS_PORT
Definition: iozone.c:1426
char lflag
Definition: iozone.c:1329
int t_count
Definition: iozone.c:1285
double sp_finish_time
Definition: iozone.c:22801
char * mainbuffer
Definition: iozone.c:1366
int junk
Definition: iozone.c:1402
long long w_traj_ops
Definition: iozone.c:1325
int master_socket_num
Definition: iozone.c:1503
#define KILOBYTES_START
Definition: iozone.c:889
int begin_proc
Definition: iozone.c:1293
#define RECLEN_END
Definition: iozone.c:895
char sp_master_host[256]
Definition: iozone.c:22809
VOLATILE char stoptime
Definition: iozone.c:1370
int async_read()
Definition: iozone.c:19026
off64_t size
Definition: iozone.c:1352
int c_compute_flag
Definition: iozone.c:535
void reverse_perf_test()
char odsync
Definition: iozone.c:1516
unsigned int length
unsigned long long goodkilos
Definition: iozone.c:1276
long long include_mask
Definition: iozone.c:1332
#define C_STATE_WAIT_WHO
Definition: iozone.c:1450
int aggflag
Definition: iozone.c:1480
char * dedup_temp
Definition: iozone.c:1306
void alloc_pbuf()
Definition: iozone.c:23620
char * buffer1
Definition: iozone.c:1366
void cleanup_children()
Definition: iozone.c:22647
int op_rate_flag
Definition: iozone.c:1302
void multi_throughput_test()
char m_walltime[80]
Definition: iozone.c:722
#define HOST_ASEND_PORT
Definition: iozone.c:1409
char c_client_number[20]
Definition: iozone.c:655
char c_stride_flag[2]
Definition: iozone.c:612
fill_area(long long *src_buffer, long long *dest_buffer, long long length)
Definition: iozone.c:19014
char c_file_name[200]
Definition: iozone.c:495
double s
Definition: byte_profile.c:36
char ** argvsave
Definition: iozone.c:1393
double genrand64_real3(void)
Definition: iozone.c:23978
char dedup
Definition: iozone.c:1304
long long num_child
Definition: iozone.c:1335
long long ret
Definition: iozone.c:1346
int c_direct_flag
Definition: iozone.c:543
char Z_flag
Definition: iozone.c:1520
void store_dvalue()
float c_compute_time
Definition: iozone.c:575
#define KILOBYTES
Definition: iozone.c:789
static int openSckt(const char *, const char *, unsigned int)
Definition: iozone.c:24099
char c_dedup_interior[4]
Definition: iozone.c:618
double totaltime
Definition: iozone.c:1268
void stop_master_send()
long long chid
Definition: iozone.c:1529
int child_async_port
Definition: iozone.c:1502
purge_buffer_cache()
Definition: iozone.c:12274
void *() thread_mix_test()
#define HOST_LIST_PORT
Definition: iozone.c:1407
void dump_cputimes()
Definition: iozone.c:11880
void dump_throughput_cpu()
Definition: iozone.c:18625
char NOCROSSflag
Definition: iozone.c:1333
char c_mmapnsflag[2]
Definition: iozone.c:629
float m_cputime
Definition: iozone.c:696
char imon_start[256]
Definition: iozone.c:1318
char L_flag
Definition: iozone.c:1518
#define THREAD_RANDOM_MIX_TEST
Definition: iozone.c:1437
int ecount
Definition: iozone.c:1310
char c_client_name[100]
Definition: iozone.c:593
FILE * wqfd
Definition: iozone.c:1342
void tell_master_ready()
#define SP_CHILD_ESEND_PORT
Definition: iozone.c:1423
void child_remove_files()
#define MINBUFFERSIZE
Definition: iozone.c:816
char c_file_name[200]
Definition: iozone.c:595
double nap_res
Definition: iozone.c:19087
void start_child_listen_loop()
Definition: iozone.c:22287
int c_include_close
Definition: iozone.c:532
void traj_vers()
Definition: iozone.c:19916
struct sockaddr_in sp_child_sync_sock sp_child_async_sock
Definition: iozone.c:22793
int optind
int c_r_traj_flag
Definition: iozone.c:542
char * haveshm
Definition: iozone.c:1288
char c_w_traj_flag[2]
Definition: iozone.c:641
#define REWRITE_REC_MASK
Definition: iozone.c:925
char mfflag
Definition: iozone.c:1334
long long test_soutput[]
Definition: iozone.c:1250
char m_testnum[20]
Definition: iozone.c:717
#define THREAD_FWRITE_TEST
Definition: iozone.c:1440
long long x
Definition: iozone.c:1335
char imon_stop[256]
Definition: iozone.c:1318
int sp_mrfd
Definition: iozone.c:1292
int sp_child_listen_port
Definition: iozone.c:22783
void dump_excel()
Definition: iozone.c:11653
char dummyfile1[MAXNAMESIZE]
Definition: iozone.c:1363
float m_actual
Definition: iozone.c:698
void terminate_child_async()
Definition: iozone.c:22538
int num_tests
Definition: zero_fork.c:53
VOLATILE char * stop_flag
Definition: iozone.c:1537
#define REVERSE_MASK
Definition: iozone.c:924
char c_share_file[10]
Definition: iozone.c:651
int c_command
Definition: iozone.c:547
int c_mmapssflag
Definition: iozone.c:530
int r_traj_items
Definition: iozone.c:1328
int c_dedup_interior
Definition: iozone.c:518
char * throughput_tests[]
Definition: iozone.c:1385
#define MAXBUFFERSIZE
Definition: iozone.c:809
char command_line[1024]
Definition: iozone.c:1387
char * buffer
Definition: iozone.c:1366
char * filearray[MAXSTREAMS]
Definition: iozone.c:1364
int r_count
Definition: iozone.c:1286
__time_t tv_sec
char m_child_async_port[20]
Definition: iozone.c:715
int sp_start_master_listen()
off64_t numrecs64
Definition: iozone.c:1534
#define MAX_X
Definition: iozone.c:825
char notruncate
Definition: iozone.c:1511
void tell_children_begin()
#define THREAD_CLEANUP_TEST
Definition: iozone.c:1442
long long mythread_create()
long long flag
Definition: iozone.c:458
int master_join_count
Definition: iozone.c:1458
char mmapssflag
Definition: iozone.c:1512
char m_client_name[100]
Definition: iozone.c:710
void random_perf_test()
int share_file
Definition: iozone.c:1309
int child_number
Definition: iozone.c:1500
long long start_child_proc()
char qflag
Definition: iozone.c:1312
char write_traj_filename[MAXNAMESIZE]
Definition: iozone.c:1507
#define CROSSOVER
Definition: iozone.c:807
off64_t minimum_file_size
Definition: iozone.c:1357
long long verify_buffer(char *buffer, long long length, off64_t recnum, long long recsize, unsigned long long patt, char sverify)
Definition: iozone.c:6940
int c_h_flag
Definition: iozone.c:509
void fwrite_perf_test()
long long childids[MAXSTREAMS+1]
Definition: iozone.c:1335
__sighandler_t signal(int __sig, __sighandler_t __handler) __attribute__((__nothrow__
int c_op_rate
Definition: iozone.c:522
int c_op_rate_flag
Definition: iozone.c:523
int kill(__pid_t __pid, int __sig) __attribute__((__nothrow__
char * help[]
Definition: iozone.c:129
float cputime
Definition: iozone.c:471
int c_mmapnsflag
Definition: iozone.c:529
int c_sverify
Definition: iozone.c:514
char dedup_interior
Definition: iozone.c:1304
void record_command_line()
long long auto_mode
Definition: iozone.c:1290
long long buckets[BUCKETS]
Definition: iozone.c:24212
FILE * open_r_traj()
Definition: iozone.c:19685
FILE * open_w_traj()
Definition: iozone.c:19707
#define CONTROL_STRING2
Definition: iozone.c:877
void write_perf_test()
#define CACHE_SIZE
Definition: iozone.c:751
int cret
Definition: fileop.c:138
#define THISVERSION
Definition: iozone.c:63
char c_write_traj_filename[200]
Definition: iozone.c:498
short current_x
Definition: iozone.c:1273
char c_child_flag[40]
Definition: iozone.c:670
int nap_once
Definition: iozone.c:19086
#define WRITER_MASK
Definition: iozone.c:920
__suseconds_t tv_usec
int child_port
Definition: iozone.c:1455
long long fetchon
Definition: iozone.c:1533
int gettimeofday(void *ptr1, void *ptr2)
int c_noretest
Definition: iozone.c:503
char c_dedup_mseed[4]
Definition: iozone.c:620
off64_t kilobytes64
Definition: iozone.c:1277
void stop_child_listen()
char c_write_traj_filename[200]
Definition: iozone.c:598
static double time_so_far1()
Definition: iozone.c:19207
char pflag
Definition: iozone.c:1509
void distribute_stop()
Definition: iozone.c:22564
unsigned int pattern
Definition: iozone.c:1531
int c_hist_summary
Definition: iozone.c:521
long long c_stride
Definition: iozone.c:565
pthread_t mythread_self()
Definition: iozone.c:18555
#define R_STOP_FLAG
Definition: iozone.c:742
float do_compute()
double total_kilos
Definition: iozone.c:1268
static double cpu_util()
int start_master_send_async(char *child_host_name, int child_port, struct in_addr my_s_addr)
Definition: iozone.c:21184
char xflag
Definition: iozone.c:1520
int t_range[100]
Definition: iozone.c:1284
int c_Kplus_flag
Definition: iozone.c:539
char c_client_name[100]
Definition: iozone.c:493
int close()
struct size_entry * next
Definition: iozone.c:1351
long long l_max()
off64_t report_array[MAX_X][MAX_Y]
Definition: iozone.c:1269
char c_host_name[100]
Definition: iozone.c:490
void start_master_listen_loop()
void print_header()
Definition: iozone.c:11351
long long status
Definition: iozone.c:1335
char c_pit_service[8]
Definition: iozone.c:592
FILE * w_traj_fd
Definition: iozone.c:1367
void send_stop()
Definition: iozone.c:22607
char mflag
Definition: iozone.c:1509
void close_xls()
#define LARGE_REC
Definition: iozone.c:786
FILE * newstdout
Definition: iozone.c:1475
void wait_dist_join()
Definition: iozone.c:22391
#define cputime_so_far()
Definition: iozone.c:973
long long flag1
Definition: iozone.c:459
int m_client_error
Definition: iozone.c:688
int c_dedup_mseed
Definition: iozone.c:520
#define R_STAT_DATA
Definition: iozone.c:732
void init_record_sizes()
#define MAP_FAILED
Definition: iozone.c:336
char oflag
Definition: iozone.c:1509
int mylockr()
int sp_master_esend_port
Definition: iozone.c:22787
int c_advise_flag
Definition: iozone.c:562
char c_rec_lock[10]
Definition: iozone.c:653
int proto_version
Definition: iozone.c:1486
void async_release()
Definition: iozone.c:19056
void init_file_sizes()
int c_mfflag
Definition: iozone.c:501
int child_listen_socket_async
Definition: iozone.c:1468
int c_MS_flag
Definition: iozone.c:537
void child_listen()
void my_nap()
int rand()
int master_listen_socket
Definition: iozone.c:1473
void *() thread_read_test()
int c_odsync
Definition: iozone.c:515
void takeoff_cache()
char yflag
Definition: iozone.c:1312
struct in_addr sp_my_ms_addr
Definition: iozone.c:22792
char sp_location[256]
Definition: iozone.c:22810
int start_master_send()
#define THREAD_READ_TEST
Definition: iozone.c:1431
#define THREAD_REWRITE_TEST
Definition: iozone.c:1430
int r_traj_flag
Definition: iozone.c:1523
struct sockaddr_in child_sync_sock child_async_sock
Definition: iozone.c:1481
char m_host_name[100]
Definition: iozone.c:684
void *() thread_write_test()
char c_pit_hostname[40]
Definition: iozone.c:591
char m_child_port[20]
Definition: iozone.c:714
#define KILOBYTES_END
Definition: iozone.c:891
int argcsave
Definition: iozone.c:1392
void Poll()
void r_traj_size()
Definition: iozone.c:19732
int c_client_number
Definition: iozone.c:546
#define I_CREAT(x, y)
Definition: iozone.c:1184
int c_multiplier
Definition: iozone.c:554
#define STRIDE
Definition: iozone.c:760
int c_port
Definition: iozone.c:1454
#define UM
Definition: iozone.c:23877
char h_flag
Definition: iozone.c:1509
char m_child_flag[80]
Definition: iozone.c:724
int c_w_traj_flag
Definition: iozone.c:541
char bif_filename[MAXNAMESIZE]
Definition: iozone.c:1359
float walltime
Definition: iozone.c:460
long long min_rec_size
Definition: iozone.c:1380
char silent
Definition: iozone.c:1295
int sp_tcount
Definition: iozone.c:22800
char seq_mix
Definition: iozone.c:1322
void create_temp()
void dump_hist()
char * caddr_t
char read_traj_filename[MAXNAMESIZE]
Definition: iozone.c:1508
int c_OPS_flag
Definition: iozone.c:526
char Q_flag
Definition: iozone.c:1517
#define FWRITER_MASK
Definition: iozone.c:927
#define CHILD_LIST_PORT
Definition: iozone.c:1416
#define SHMSIZE
Definition: iozone.c:1263
int c_include_flush
Definition: iozone.c:533
#define SP_MASTER_LISTEN_PORT
Definition: iozone.c:1424
char pit_service[8]
Definition: iozone.c:1401
long long res_prob
Definition: iozone.c:1294
int parse_client_line()
long long c_fetchon
Definition: iozone.c:569
int speed_code
Definition: iozone.c:1336
double genrand64_real1(void)
Definition: iozone.c:23966
static void pit(int, struct timeval *)
Definition: iozone.c:24180
int c_unbuffered
Definition: iozone.c:502
double report_darray[MAX_X][MAXSTREAMS]
Definition: iozone.c:1270
struct sockaddr_in listener_sync_sock
Definition: iozone.c:20343
int ioz_processor_bind
Definition: iozone.c:1293
char c_execute_name[200]
Definition: iozone.c:597
char tfile[]
Definition: iozone.c:1365
int sp_count
Definition: iozone.c:22799
char no_copy_flag
Definition: iozone.c:1519
off64_t min_file_size
Definition: iozone.c:1378
void *() thread_set_base()
int c_pattern
Definition: iozone.c:556
int clients_found
Definition: iozone.c:1474
void read_stride_perf_test()
char Rflag
Definition: iozone.c:1303
long long max_rec_size
Definition: iozone.c:1381
char c_direct_flag[2]
Definition: iozone.c:643
off64_t max_file_size
Definition: iozone.c:1379
#define SP_CHILD_LISTEN_PORT
Definition: iozone.c:1422
#define MAXTESTS
Definition: iozone.c:820
long long l_min()
long long r_traj_ops_completed
Definition: iozone.c:1326
#define USAGE
Definition: iozone.c:829
char child_async_rcv_buf[4096]
Definition: iozone.c:1464
double temp_time
Definition: iozone.c:1268
static double time_so_far()
Definition: iozone.c:6844
#define LM
Definition: iozone.c:23878
#define VOLATILE
Definition: iozone.c:395
char * default_filename
Definition: iozone.c:1369
char bif_flag
Definition: iozone.c:1307
void my_unap()
int system()
char include_close
Definition: iozone.c:1519
long long goodrecl
Definition: iozone.c:1278
int start_child_listen()
void hist_insert()
pthread_t p_childids[MAXSTREAMS+1]
Definition: iozone.c:1338
char RWONLYflag
Definition: iozone.c:1333
char OPS_flag
Definition: iozone.c:1517
#define THREAD_STRIDE_TEST
Definition: iozone.c:1433
struct sockaddr_in sp_master_sync_sock sp_master_async_sock
Definition: iozone.c:22794
char m_host_name[100]
Definition: iozone.c:709
void *() thread_cleanup_test()
int master_send_sockets[MAXSTREAMS]
Definition: iozone.c:1470
long long c_child_flag
Definition: iozone.c:572
char c_unbuffered[2]
Definition: iozone.c:602
long long orig_size
Definition: iozone.c:1274
volatile int buf[CACHE_FLUSH_BUFFER_SIZE_INTS]
Definition: do_loops.c:12
char c_delay_start[80]
Definition: iozone.c:674
int mygen
Definition: iozone.c:1524
char client_filename[256]
Definition: iozone.c:1396
int client_error
Definition: iozone.c:1398
int unlink()
int main()
Definition: pernode.c:20
long long c_rest_val
Definition: iozone.c:566
void exit()
int rlocking
Definition: iozone.c:1308
char toutput[20][20]
Definition: iozone.c:1476
int m_client_number
Definition: iozone.c:687
char c_multiplier[10]
Definition: iozone.c:650
double genrand64_real2(void)
Definition: iozone.c:23972
int child_attach(int s, int flag)
Definition: iozone.c:20831
void stop_master_listen_loop()
Definition: iozone.c:22064
char c_include_close[2]
Definition: iozone.c:632
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:39
char mmapnsflag
Definition: iozone.c:1512
void *() thread_join()
long long r_traj_ops
Definition: iozone.c:1325
char m_cputime[80]
Definition: iozone.c:721
#define MODE
Definition: iozone.c:88
void rewriterec_perf_test()
char * optarg
int sp_crfd
Definition: iozone.c:1292
setvbuf(file, file_buf, _IOFBF, sizeof(file_buf))
int fsync()
float m_walltime
Definition: iozone.c:697
off64_t next64
Definition: iozone.c:1340
double cputime_res
Definition: iozone.c:1271
char c_Kplus_flag[2]
Definition: iozone.c:640
int c_seq_mix
Definition: iozone.c:545
int start_child_listen_async()
#define MAXSTREAMS
Definition: iozone.c:813
char uflag
Definition: iozone.c:1329
static long count
#define MULTIPLIER
Definition: iozone.c:897
long long rest_val
Definition: iozone.c:1540
int Kplus_readers
Definition: iozone.c:1506
int create_xls()
char mmap_mix
Definition: iozone.c:1512
long long off64_t
Definition: iozone.c:357
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:38
void begin()
int c_notruncate
Definition: iozone.c:504
int master_send_socket
Definition: iozone.c:1469
struct in_addr sp_my_cs_addr
Definition: iozone.c:22791
unsigned long cache_size
Definition: iozone.c:1375
int errno
int i
Definition: fileop.c:140
#define CHILD_ALIST_PORT
Definition: iozone.c:1419
long long orig_min_rec_size
Definition: iozone.c:1382
boolean
Definition: iozone.c:24049
#define RECLEN
Definition: iozone.c:792
short current_y
Definition: iozone.c:1273
#define I_FOPEN(x, y)
Definition: iozone.c:1185
#define R_CHILD_JOIN
Definition: iozone.c:731
long long r_traj_bytes_completed
Definition: iozone.c:1326
int c_mmapasflag
Definition: iozone.c:528
long long max_x
Definition: iozone.c:1275
int sp_child_mode
Definition: iozone.c:22798
int direct_flag
Definition: iozone.c:1527
long long y
Definition: iozone.c:1335
char * head1[]
Definition: iozone.c:246
#define CHILD_STATE_READY
Definition: iozone.c:944
int c_Kplus_readers
Definition: iozone.c:553
#define RANDOM_MIX_TEST
Definition: iozone.c:910
double total_time
Definition: iozone.c:1268
int hist_summary
Definition: iozone.c:1300
int splash_line
Definition: iozone.c:1395
double time_res
Definition: iozone.c:1271