home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume33 / iozone / part01 / iozone.c next >
Encoding:
Text File  |  1992-11-04  |  34.2 KB  |  1,122 lines

  1. char *help[] = {
  2.   "       'IO Zone' Benchmark Program",
  3.   " ",
  4.   "       Author: Bill Norcott (norcott_bill@tandem.com)",
  5.   "               1060 Hyde Avenue",
  6.   "               San Jose, CA  95129",
  7.   " ",
  8.   "  Copyright 1991, 1992   William D. Norcott",
  9.   " ",
  10.   "  License to freely use and distribute this software is hereby granted ",
  11.   "  by the author, subject to the condition that this copyright notice ",
  12.   "  remains intact.  The author retains the exclusive right to publish ",
  13.   "  derivative works based on this work, including, but not limited to, ",
  14.   "  revised versions of this work",
  15.   " ",
  16.   "  This test writes a X MEGABYTE sequential file in Y byte chunks, then",
  17.   "  rewinds it  and reads it back.  [The size of the file should be",
  18.   "  big enough to factor out the effect of any disk cache.].  Finally,",
  19.   "  IOZONE deletes the temporary file",
  20.   "        ",
  21.   "  The file is written (filling any cache buffers), and then read.  If the",
  22.   "  cache is >= X MB, then most if not all the reads will be satisfied from",
  23.   "  the cache.  However, if it is less than or equal to .5X MB, then NONE of",
  24.   "  the reads will be satisfied from the cache.  This is becase after the ",
  25.   "  file is written, a .5X MB cache will contain the upper .5 MB of the test",
  26.   "  file, but we will start reading from the beginning of the file (data",
  27.   "  which is no longer in the cache)",
  28.   "        ",
  29.   "  In order for this to be a fair test, the length of the test file must",
  30.   "  be AT LEAST 2X the amount of disk cache memory for your system.  If",
  31.   "  not, you are really testing the speed at which your CPU can read blocks",
  32.   "  out of the cache (not a fair test)",
  33.   "        ",
  34.   "  IOZONE does not normally test the raw I/O speed of your disk or system.",
  35.   "  It tests the speed of sequential I/O to actual files.  Therefore, this",
  36.   "  measurement factors in the efficiency of you machines file system,",
  37.   "  operating system, C compiler, and C runtime library.  It produces a ",
  38.   "  measurement which is the number of bytes per second that your system",
  39.   "  can read or write to a file.  ",
  40.   " ",
  41.   "  You use IOZONE to test the I/O speed of a UNIX 'RAW DEVICE' such",
  42.   "  as a tape drive, hard disk drive, floppy disk drive, etc.  To do this,",
  43.   "  you must define the symbol NO_DELETE when you compile IOZONE.  If you",   
  44.   "  fail to define NO_DELETE, IOZONE will treat the raw device as a ",
  45.   "  temporary file, and WILL DELETE THE RAW DEVICE after the test completes!",
  46.   "  When testing raw devices, any UNIX buffer caching is bypassed.  IOZONE",
  47.   "  still is using the read()/write() system calls, so you are not quite",
  48.   "  testing the device at the low level of say, disk controller diagnostics.",
  49.   "  On the other hand, that kind of testing is highly system- and device-",
  50.   "  specific, and my goal for IOZONE has been to build a highly portable",
  51.   "  benchmark -- not one which is tied to a particular operating system or",
  52.   "  hardware configuration.  In practice, I have tested raw disk and tape",
  53.   "  peripherals and the results are very close to the manufacturer's specs",
  54.   "  for those devices.", 
  55.   " ",
  56.   "  For V1.06, IOZONE adds the 'auto test' feature.  This is activated",
  57.   "  by the command:  'iozone auto' .  The auto test runs IOZONE repeatedly  ",
  58.   "  using record sizes from 512 to 8192 bytes, and file sizes from 1 to 16",
  59.   "  megabytes.  It creates a table of results.",
  60.   "        ",
  61.   "  For V1.06, IOZONE lets you specify the number of file system sizes and      ",
  62.   "  record lengths to test when using auto mode.  Define the constants",
  63.   "  MEGABYTES_ITER_LIMIT and RECLEN_ITER_LIMIT as seen below      ",
  64.   "        ",
  65.   "  For V1.09 you can show the development help by typing 'iozone help'",
  66.   "        ",
  67.   "  For V1.10 IOzone traps SIGINT (user interrupt) and SIGTERM",
  68.   "  (kill from shell) signals and deletes the temporary file",
  69.   "        ",
  70.   "  For V1.11 IOzone requires no compilation flags for AIX",
  71.   "  Also, come miscellaneous cleanups have been made to the source",
  72.   "        ",
  73.   "  For V1.12 IOzone support has been added for the MIPS RISCos,",
  74.   "  Tandem Non-StopUX, and Tandem GUARDIAN 90 operating systems.",
  75.   "  IOzone is now a 'Conforming POSIX.1 Application'  (IEEE Std 1003.1-1988)",
  76.   "        ",
  77.   "  For V1.14 IOzone supports Next and QNX systems.  It also prints out", 
  78.   "  the name of the operating system when run.  There is now the option",
  79.   "  to force IOzone to flush all writes to disk via fsync()",
  80.   "  Defining USE_FSYNC will make IOzone include in its measurements the time",
  81.   "  it takes to actually write the data onto disk, as opposed to",
  82.   "  just writing into the system cache.  BSD UNIX and SVR4 support fsync(),",
  83.   "  but SVR3 and generic POSIX systems do not.  I have enabled USE_FSYNC",
  84.   "  for the systems which support it",
  85.   "        ",
  86.   "  For V1.14, we now officially support AT&T SVR4.  It has worked just",
  87.   "  fine using SVR4 with previous versions of IOzone.  Also, for systems",
  88.   "  which use the times() function, we calculate the 'base time' the first",
  89.   "  time we ever call time_so_far(), then subtract this time from all",
  90.   "  future measurements.  This increases the precision of our measurement",
  91.   "  and fixes a loss-of-precision problem which occurred on some systems",
  92.   "        ",
  93.   "  For V1.15, add the NO_DELETE symbol.  If you define NO_DELETE during",
  94.   "  the compilation (e.g., for UNIX systems compile with cc -DNO_DELETE),",
  95.   "  IOzone will not delete the 'temporary' file which it reads & writes.",
  96.   "  This is REQUIRED when testing RAW DEVICES such as disks and tape drives!",
  97.   "        ",
  98.   " ",
  99.   "  This program has been ported and tested on the following computer",
  100.   "  operating systems:",
  101.   " ",
  102.   "    Vendor             Operating System    Notes on compiling IOzone",
  103.   "    -------------------------------------------------------------------------",
  104.   "    Apollo          Domain/OS           no cc switches -- BSD domain", 
  105.   "    AT&T               UNIX System V Release 4",
  106.   "    AT&T 6386WGS       AT&T UNIX 5.3.2     can't get it to compile with cc",
  107.   "                          It should work with gcc via:",
  108.   "                          'gcc -ansi -o iozone iozone.c'",
  109.   "    Generic AT&T       UNIX System V R3    may need cc -DSVR3",
  110.   "    Convergent         Unisys/AT&T Sys5r3  cc -DCONVERGENT -o iozone iozone.c",
  111.   "    Digital Equipment  ULTRIX V4.1 ",
  112.   "    Digital Equipment  VAX/VMS V5.4        see below **         ",
  113.   "    Digital Equipment  VAX/VMS (POSIX) ",
  114.   "    Hewlett-Packard    HP-UX 7.05",
  115.   "    IBM                AIX Ver. 3 rel. 1",
  116.   "    Interactive        UNIX System V R3    ",
  117.   "    Microsoft          MS-DOS 3.3          tested Borland, Microsoft C",
  118.   "    MIPS               RISCos 4.52",
  119.   "    NeXt               NeXt OS 2.x",
  120.   "    OSF                OSF/1",
  121.   "    Portable!          POSIX 1003.1-1988   may need to -D_POSIX_SOURCE",
  122.   "    QNX                QNX 4.0",
  123.   "    SCO                UNIX System V/386 3.2.2",
  124.   "    SCO                XENIX 2.3",
  125.   "    SCO                XENIX 3.2",
  126.   "    Silicon Graphics   UNIX                cc -DSGI -o iozone iozone.c",
  127.   "    Sony Microsystems  UNIX                same as MIPS",
  128.   "    Sun Microsystems   SUNOS 4.1.1",
  129.   "    Tandem Computers   GUARDIAN 90         1. call the source file IOZONEC",
  130.   "                                           2. C/IN IOZONEC/IOZONE;RUNNABLE",
  131.   "                                           3. RUN IOZONE",
  132.   "    Tandem Computers   Non-Stop UX",
  133.   "        ",
  134.   "    ** for VMS, define iozone as a foreign command via this DCL command:       ",
  135.   " ",
  136.   "       $IOZONE :== $SYS$DISK:[]IOZONE.EXE      ",
  137.   " ",
  138.   "       this lets you pass the command line arguments to IOZONE",
  139.   " ",
  140.   "  Acknowledgements to the following persons for their feedback on IOzone:       ",
  141.   " ",
  142.   "  Andy Puchrik, Michael D. Lawler, Krishna E. Bera, Sam Drake, John H. Hartman, ",
  143.   "  Ted Lyszczarz, Bill Metzenthen, Jody Winston, Clarence Dold, Axel",
  144.   "  Dan Hildebrand, Joe Nordman, Bob Fritz, Jeff Johnson",
  145.   "        ",
  146.   "  --- MODIFICATION HISTORY:",
  147.   " ",
  148.   " ",
  149.   "    3/7/91 William D. Norcott (Bill.Norcott@nuo.mts.dec.com)",
  150.   "                               created",
  151.   " ",
  152.   "    3/22/91 Bill Norcott       tested on OSF/1 ... it works",
  153.   " ",
  154.   "    3/24/91 Bill Norcott       V1.02 -- use calloc in TURBOC to",
  155.   "                                       fix bug with their malloc",
  156.   " ",
  157.   "    3/25/91 Bill Norcott       V1.03 -- add ifdef for XENIX",
  158.   "                                       ",
  159.   "    3/27/91 Bill Norcott       V1.04 -- Includes for SCO UNIX",
  160.   "                                       ",
  161.   "    4/26/91 Bill Norcott       V1.05 -- support AIX and SUNos, check",
  162.   "                                       length of read() and write()",
  163.   "    4/26/91 Bill Norcott       V1.06 -- tabulate results of a series ",
  164.   "                                       of tests",
  165.   "    5/17/91 Bill Norcott       V1.07 -- use time() for VMS",
  166.   "    5/20/91 Bill Norcott       V1.08 -- use %ld for Turbo C and",
  167.   "                                       use #ifdef sun to bypass",
  168.   "                                       inclusion of limits.h",
  169.   "    6/19/91 Bill Norcott       V1.09 -- rid #elif to support HP-UX and ",
  170.   "                                       Silicon Graphics UNIX, and",
  171.   "                                       add #ifdef SGI",
  172.   "                                       add #ifdef CONVERGENT",
  173.   "                                       for Convergent Technologies",
  174.   "                                       also add help option",
  175.   "    7/2/91 Bill Norcott        V1.10 -- delete file if get SIGINT",
  176.   "                                       or SIGTERM",
  177.   "    8/20/91 Bill Norcott       V1.11 -- require no flags with AIX",
  178.   "    11/4/91 Bill Norcott       V1.12 -- support MIPS RISCos",
  179.   "                                         Tandem NonStop-UX, and",
  180.   "                                        IEEE Std POSIX 1003.1-1988",
  181.   "    12/4/91 Bill Norcott       V1.13 -- support NeXT; tell host OS type",
  182.   "    1/23/92 Bill Norcott      V1.14 -- support QNX & use calloc() for buffer",
  183.   "    5/1/92 Bill Norcott      V1.15 -- support SVR4; fix loss of precision",
  184.   "                                       in times() function.  ",
  185.   "                                       support Interactive UNIX",
  186.   "                                       detect ANSI if no O/S",
  187.   "                                       Also, define for generic SVR3",
  188.   "                                       Apollo Domain/OS",
  189.   "                                       Define NO_DELETE and iozone wont",
  190.   "                                       delete the temp file.  Needed to",
  191.   "                                       test raw devices without deleting",
  192.   "                                       them",
  193.   "    10/28/92 Bill Norcott    V1.16 -- bug fix: some unsigned longs changed",
  194.   "                                      to unsigned in V1.15 caused problem",
  195.   "                                      so change back.  Also, note problems",
  196.   "                     with AT&T 6386WGS systems",
  197.   " ",
  198.   "" };
  199.  
  200. /******************************************************************
  201.   
  202.   INCLUDE FILES (system-dependent)
  203.   
  204.   ******************************************************************/
  205. /* 
  206. V1.15 -- Define the symbol NO_DELETE if you plan to use IOzone to test
  207. the speed of UNIX raw devices such as disk- and tape drives.  This will
  208. tell IOzone NOT to delete the file after the test completes
  209. */
  210. /* #define NO_DELETE */
  211. /* 
  212. V1.15 -- If you have a generic System V R3 not on my list of supported
  213. systems, define SVR3 when you compile IOzone. If you have to use this, please
  214. send tell me what preprocessor symbols your C compiler defines which
  215. will help me test for your particular system... do a 'man cc' on a
  216. UNIX system to check, or just do a 'man cc > cc.txt' and mail me
  217. cc.txt
  218. */
  219. /*  Define the following if you have a generic System V R3 system which
  220. is not one of the specific versions listed above
  221. */
  222. /* #define SVR3 */
  223. #ifdef SVR3
  224. #ifndef OS_TYPE
  225. #define OS_TYPE "'Generic' UNIX System V Release 3 -- vendor unknown" 
  226. #endif
  227. #include <fcntl.h>
  228. #include <sys/types.h>
  229. #define SysVtime
  230. #endif
  231. /* V1.15 -- add Apollo Domain O/S to the list -- it also worked in previous
  232. versions, now it will print its identity
  233. */
  234. #ifdef apollo
  235. #ifndef OS_TYPE
  236. #define OS_TYPE "Apollo Domain/OS -- using BSD libraries"
  237. #define BSDtime
  238. #define USE_FSYNC
  239. #endif
  240. #endif
  241.  
  242. /* V1.14 -- use calloc instead of stack for buffer, on all platforms */
  243. #define usecalloc
  244. /* 
  245. V1.14b -- check for ultrix which uses sysconf in newer POSIX version 
  246. but uses BSD-style time in the pre-POSIX versions
  247. V1.15 use fsync() for ultrix even though V4.2 will pick up other options
  248. from POSIX
  249. */
  250. #ifdef ultrix
  251. #ifndef OS_TYPE
  252. #define OS_TYPE "ULTRIX 4.0 or earlier"
  253. #define BSDtime
  254. #define USE_FSYNC
  255. #endif
  256. #endif
  257. /* V1.13 -- support NeXT by treating it like a Sun... Thanks Axel! */
  258. #ifdef __NeXT__
  259. #ifndef OS_TYPE
  260. #define OS_TYPE "NeXT OS"
  261. #endif
  262. #define sun
  263. #endif
  264. /*
  265.   define nolimits if your system has no limits.h.  Sun's don't but I
  266.   take care of this explicitly beginning with V1.08 of IOzone.
  267.   */
  268. #ifdef sun
  269. #ifndef OS_TYPE
  270. #define OS_TYPE "SunOS"
  271. #endif
  272. #define nolimits
  273. #define BSDtime
  274. #define USE_FSYNC
  275. #endif
  276. /* V1.09 -- Silicon Graphics compile with -DSGI  */
  277. #ifdef SGI
  278. #ifndef OS_TYPE
  279. #define OS_TYPE "Silicon Graphics"
  280. #endif
  281. #define nolimits
  282. #define BSDtime
  283. #endif
  284.  
  285. /* V1.13 For MIPS RISC/OS and Tandem NonStop-UX*/
  286. #ifdef SYSTYPE_BSD43
  287. #define bsd4_3
  288. #ifndef OS_TYPE
  289. #define OS_TYPE "MIPS RISC/os (BSD 4.3 libraries)"
  290. #endif
  291. #endif
  292.  
  293. #ifdef SYSTYPE_SYSV
  294. #include <sys/utsname.h>
  295. #define nolimits
  296. #ifdef T_NONSTOP
  297. #define OS_TYPE "TANDEM NonStop-UX (System V libraries)"
  298. #endif
  299. #ifndef OS_TYPE
  300. #define OS_TYPE "MIPS RISC/os (System V libraries)"
  301. #endif
  302. #define SysVtime
  303. #include <sys/types.h>
  304. #include <sys/times.h>
  305. #include <sys/fcntl.h>
  306. #endif
  307. /* V1.14 -- define nolimits and BSDtime for Xenix 2.3.3 */
  308. /* incl definitions of O_* flags for XENIX */
  309. #ifdef M_UNIX
  310. #define SCOunix
  311. #else
  312. #ifdef M_XENIX
  313. #define SCOxenix
  314. #endif
  315. #endif
  316.  
  317. /* SCO Unix System V */
  318. #ifdef SCOunix
  319. #define OS_TYPE "SCO UNIX System V/386"
  320. #include <sys/types.h>
  321. #include <sys/fcntl.h>
  322. #endif
  323.  
  324. #ifdef SCOxenix
  325. #ifdef XENIX_2_3
  326. #define OS_TYPE "SCO XENIX 2.3.x"
  327. #define BSDtime
  328. #else
  329. #define OS_TYPE "SCO XENIX 3.x"
  330. #define SysVtime
  331. #endif
  332. #endif
  333.  
  334. /* V1.12 -- test for POSIX-conformant operating system; requires limits.h */
  335. /*
  336. V1.15 -- I have been told that there is a problem in the times() POSIX 
  337. function in Ultrix V4.1 and greater.  It seems to return the time in
  338. whole seconds (expressed in terms of clock ticks) instead of correctly
  339. returning the elapsed time in clock ticks ALTHOUGH POSIX 1003.1-1988 
  340. and ISO 9945 CLEARLY STATE that "times() shall return the elapsed real 
  341. time, in clock ticks."  
  342.  
  343. This means calling times() twice in the same second and subtracting
  344. the two values, produces an answer of 0, which IOzone detects as an error.
  345.  
  346. I thought I had a problem in V1.14 under Ultrix with loss of precision, 
  347. i.e. taking the difference of two large floating point numbers, 
  348. but the problem seems be that Ultrix times() *inherently* has a 
  349. loss of precision, so my "fix" can't fix the broken system call.  
  350. Until they fix it in Ultrix I am going to use BSD-style everything
  351. for Ultrix
  352. */
  353. #ifndef nolimits
  354.  
  355. #include <limits.h>
  356. #ifdef _POSIX_ARG_MAX
  357. #ifndef ultrix
  358. #ifndef OS_TYPE
  359. #define OS_TYPE "POSIX 1003.1-1988"
  360. #endif
  361. #define isposix
  362. #undef USE_FSYNC
  363. #else
  364. /* It's ultrix disguised as POSIX; still use BSD calls until they fix it */
  365. #undef OS_TYPE
  366. #define OS_TYPE "ULTRIX 4.1 or later"
  367. #endif
  368. #endif
  369. #endif
  370.  
  371. /* Tandem's GUARDIAN operating system */
  372. #include <stdio.h>
  373. #ifdef __TANDEM
  374. #ifndef OS_TYPE
  375. #define OS_TYPE "TANDEM GUARDIAN 90"
  376. #endif
  377. #define nosignals
  378. #define ANSItime
  379. #define ANSI_MAIN
  380. #include <fcntl.h>
  381. #include <stdlib.h>
  382. #include <string.h>
  383. #include <time.h>
  384. #endif
  385. #ifndef nosignals
  386. #include <signal.h>
  387. #endif
  388. #ifdef  __MSDOS__               /* Turbo C define this way for PCs... */
  389. #define MSDOS                   /* Microsoft C defines this */
  390. #endif
  391. /* VMS and MS-DOS both have ANSI C compilers and use rand()/srand() */
  392. #ifdef  VMS_POSIX
  393. #undef   VMS
  394. #define ANSI_RANDOM     1
  395. #endif
  396. #ifdef  MSDOS
  397. #define ANSI_RANDOM     1
  398. #endif
  399. /* Convergent Technologies M680xx based with Unisys/AT&T Sys5r3 */
  400. #ifdef CONVERGENT
  401. #ifndef OS_TYPE
  402. #define OS_TYPE "Convergent Technologies" 
  403. #endif
  404. #include <fcntl.h>
  405. #define SysVtime
  406. #endif
  407. /* Interactive UNIX System V Release 3.2 */
  408. #ifdef isc386
  409. #ifndef OS_TYPE
  410. #define OS_TYPE "Interactive UNIX System V/386" 
  411. #endif
  412. #include <fcntl.h>
  413. #define SysVtime
  414. #endif
  415.  
  416. /* V1.11 -- With the following includes, AIX no longer requires -Dunix */
  417. #ifdef _AIX
  418. #ifndef OS_TYPE
  419. #define OS_TYPE "AIX"
  420. #endif
  421. #include <fcntl.h>
  422. #include <sys/time.h>
  423. #endif
  424.  
  425. #if defined(VMS)
  426. #ifndef OS_TYPE
  427. #define OS_TYPE "VAX/VMS"
  428. #endif
  429. #define ANSItime
  430. #define ANSI_RANDOM     1
  431. #include    <math.h>
  432. #include    <unixio.h>
  433. #include    <ssdef.h>
  434. #include    <file.h>
  435. #include    <time.h>
  436.  
  437. #else
  438. /* ... either MSDOS, POSIX, or a generic non-POSIX UNIX */
  439. #ifdef MSDOS
  440. #ifndef OS_TYPE
  441. #define OS_TYPE "MS-DOS"
  442. #endif
  443. #define usecalloc
  444. #include <fcntl.h>
  445. #include <time.h>
  446. #endif
  447. /* nope, not MS-DOS, try POSIX */
  448. #ifdef isposix
  449. #include <time.h>
  450. #include <sys/times.h>
  451. #include <fcntl.h>
  452. #include <unistd.h>
  453. #else
  454. #ifdef unix
  455. #include <fcntl.h>
  456. #else 
  457. #define O_RDONLY 0
  458. #endif
  459. #endif
  460. #endif
  461.  
  462. /* for systems with System V-style time, define SysVtime */
  463. #ifdef M_SYSV
  464. #define SysVtime
  465. #endif
  466.  
  467. /* for systems with BSD style time, define BSDtime */
  468. #ifdef bsd4_2
  469. #define USE_FSYNC
  470. #ifndef OS_TYPE
  471. #define OS_TYPE "BSD 4.2"
  472. #endif
  473. #define BSDtime
  474. #endif
  475. #ifdef bsd4_3
  476. #define USE_FSYNC
  477. #ifndef OS_TYPE
  478. #define OS_TYPE "BSD 4.3"
  479. #endif
  480. #define BSDtime
  481. #endif
  482. /*
  483. If we made it this far and still don't know which operating system
  484. we are running, check if we at least have ANSI C so we can do some
  485. kind of time functions.  On the other hand, if we know what O/S
  486. we are running use the (more precise) time routines for that O/S,
  487. even if we do have ANSI C.  If we don't know what O/S we are and
  488. we don't have ANSI C, but we are some flavor of UNIX, I will use
  489. time() which any UNIX will have.  For the worst case we are not 
  490. any form of UNIX nor a supported proprietary O/S, and we don't have 
  491. ANSI C either,  one of two things will happen:
  492. 1. If you define NOTIMER then you will have to use a stopwatch
  493. 2. If NOTIMER not defined, we will assume we can use time()
  494. */
  495. #ifndef OS_TYPE
  496. #ifdef __STDC__
  497. #define OS_TYPE "ANSI C"
  498. #define ANSItime
  499. #include    <time.h>
  500. #endif
  501. #endif
  502.  
  503. #ifndef OS_TYPE
  504. #ifdef unix
  505. #define OS_TYPE "UNIX (can't tell if System V or BSD) -- using time()"
  506. #define ANSItime
  507. #include    <time.h>
  508. #endif
  509. #endif
  510.  
  511. #ifndef OS_TYPE
  512. #if NOTIMER
  513. #define OS_TYPE "System type unknown & not ANSI C -- disabling timing"
  514. #define noclock 1
  515. #else
  516. #define OS_TYPE "System type unknown & not ANSI C -- using time()"
  517. #define ANSItime
  518. #include    <time.h>
  519. #endif
  520. #endif
  521.  
  522. #ifdef SysVtime
  523. #undef BSDtime
  524. #include <sys/times.h>
  525. #include <sys/param.h>
  526. #ifndef CLK_TCK
  527. #define CLK_TCK HZ
  528. #endif
  529. #endif
  530.  
  531. #ifdef BSDtime
  532. #undef SysVtime
  533. #include <sys/time.h>
  534. #endif
  535.  
  536. /******************************************************************
  537.   
  538.   DEFINED CONSTANTS
  539.   
  540.   ******************************************************************/
  541. /* Define NULL in case we don't have it... */
  542. #ifndef NULL
  543. #define NULL 0
  544. #endif
  545. /* 
  546.   V1.14: Define ONETEST to run a single test at runtime as the default
  547.   V1.14: Define AUTOTEST to run in auto test mode as the default
  548.   i.e. the behavior of IOzone when it is invoked with no arguments.  ONETEST
  549.   makes IOzone run a single test using a 1 MB file and 512 byte records.
  550.   AUTOTEST causes IOzone to use auto test mode.
  551.   For compatibility with previous versions of IOZONE, ONETEST is the default
  552.   setting
  553. */
  554. #define ONETEST 1
  555. #ifndef ONETEST
  556. #define AUTOTEST
  557. #endif
  558.  
  559. /* 
  560.   V1.14: Define USE_FSYNC to force writes to disk during the write phase
  561.   BSD and BSD-derived UNIX variants and also SVR4 are known to have fsync 
  562.   UNIX).  After the file is written and before it is closed, call fsync()
  563.   to force the data to be written from cache to disk.  This (mostly) cancels
  564.   the fact that systems with a lot of memory for cache buffers or memory
  565.   mapping display artificially high transfer rates during the write phase
  566.   of IOzone, because the data never makes it onto the disk.  
  567.  
  568. */
  569. #if 0
  570. #define USE_FSYNC
  571. #endif
  572.  
  573. #define MEGABYTES 1                     /* number of megabytes in file */
  574. #define RECLEN 512                      /* number of bytes in a record */
  575. #define FILESIZE 1048576                /*size of file in bytes*/
  576. #define NUMRECS 2048                    /* number of records */
  577. #define MAXBUFFERSIZE 16*1024           /*maximum buffer size*/
  578. #define MINBUFFERSIZE 128
  579. #define TOOFAST 10
  580. #define IOZONE_USAGE \
  581. "\tUsage:\tiozone [megabytes] [record_length_in_bytes] [[path]filename]\n\t\tiozone auto\n\t\tiozone help\n\n"
  582. #define THISVERSION "V1.16"
  583. #define RELEASEDATE "10/28/92"
  584.   /* Define only one of the following two.  All modern operating systems
  585.      have time functions so let TIME be defined */
  586. #ifndef noclock
  587. #define TIME 1
  588. #endif
  589.   
  590. #define MAXNAMESIZE 1000                /* max # of characters in filename */
  591. #define CONTROL_STRING1 "\t%-8ld%-8ld%-20ld%-20ld\n"
  592. #define CONTROL_STRING2 "\t%-8s%-8s%-20s%-20s\n"
  593.   /*
  594.     For 'auto mode', these defines determine the number of iterations
  595.     to perform for both the file size and the record length.
  596.     I.e., if MEGABYTES_ITER_LIMIT = 5 use 1, 2, 4, 8 & 16 megabyte files
  597.     if RECLEN_ITER_LIMIT = 5 use 512, 1024, 2048, 4096 & 8192 byte records
  598.     */
  599. #define MEGABYTES_ITER_LIMIT 5
  600. #define RECLEN_ITER_LIMIT 5
  601. /******************************************************************
  602.   
  603.   MACRO DEFINITIONS
  604.   
  605.   ******************************************************************/
  606. #define abs(X) ( (X) < 0 ? (-(X)) : (X) )  /* Absolute value of X */
  607.   /******************************************************************
  608.     
  609.     FUNCTION DECLARATIONS
  610.     
  611.  
  612.     ******************************************************************/
  613. void auto_test();               /* perform automatic test series */
  614. void show_help();               /* show development help*/
  615. double time_so_far();        /* time since start of program */
  616. void signal_handler();          /* clean up if user interrupts us */
  617. /******************************************************************
  618.   
  619.   GLOBAL VARIABLES
  620.   
  621.   ******************************************************************/
  622. int auto_mode;
  623. char filename [MAXNAMESIZE];            /* name of temporary file */
  624. /******************************************************************
  625.   
  626.   MAIN -- entry point
  627.   
  628.   ******************************************************************/
  629. #ifdef ANSI_MAIN
  630. int 
  631. main(int argc, char *argv[], char *env[])    /* main body of code */
  632. #else
  633. int
  634.      main(argc,argv)
  635.      int argc;
  636.      char *argv[];
  637. #endif
  638. {
  639. #ifdef ANSI_MAIN
  640.   char *fooenv;
  641. #endif
  642.   int fd;
  643.   char *default_filename;
  644.   
  645. #ifdef  usecalloc
  646.   char *buffer;
  647. #else
  648.   char buffer [MAXBUFFERSIZE];            /*a temporary data buffer*/
  649. #endif
  650.   unsigned long i;
  651.   unsigned long megabytes = MEGABYTES;
  652.   unsigned long reclen = RECLEN;
  653.   unsigned long filesize;
  654.   unsigned long numrecs;
  655.   unsigned long thisrec;
  656. #ifdef TIME
  657.   unsigned long filebytes;
  658.   unsigned long readrate, writerate;
  659.   unsigned long goodmegs;
  660.   unsigned long goodrecl;
  661.   double starttime;
  662.   double writetime, readtime;
  663.   double totaltime;
  664. #endif
  665. #ifdef usecalloc
  666.     buffer = (char *) calloc(1, MAXBUFFERSIZE);
  667. #endif
  668.   
  669. #if defined (ANSI_MAIN)
  670.   fooenv= env[0];       /* dummy so we make some use of env (to avoid warnings) */
  671. #endif
  672.   
  673. #if defined (__TANDEM)
  674.   default_filename ="IOZONET"; /* TANDEM GUARDIAN 90 has max 8 char filenames */
  675. #else
  676.   default_filename ="iozone.tmp"; /*default name of temporary file*/
  677. #endif
  678.   if (!auto_mode)
  679.     {
  680.       printf("\n\tIOZONE: Performance Test of Sequential File I/O  --  %s (%s)\n",
  681.          THISVERSION, RELEASEDATE);
  682.       printf("\t\tBy Bill Norcott\n\n");
  683. #ifdef USE_FSYNC
  684.       printf("\tOperating System: %s -- using fsync()\n\n", OS_TYPE);
  685. #else
  686.       printf("\tOperating System: %s\n\n", OS_TYPE);
  687. #endif
  688. #ifndef nosignals
  689.       signal(SIGINT, signal_handler);      /* handle user interrupt */
  690.       signal(SIGTERM, signal_handler);     /* handle kill from shell */
  691. #endif
  692.     }
  693.   strcpy(filename,default_filename);
  694.   switch (argc) {
  695.   case 1:     /* no args, take all defaults */ 
  696.     printf(IOZONE_USAGE);
  697. #ifdef AUTOTEST 
  698.     auto_mode = 1;
  699.     auto_test();
  700.     printf("Completed series of tests\n");
  701.     exit(0);
  702. #endif
  703.     break;
  704.   case 2:     /* <megabytes|filename> */
  705.     i = (unsigned) abs(atoi(argv[1])); 
  706.     if (i) {
  707.       megabytes = i;
  708.     } else {
  709.       /*
  710.     'Auto mode' will be enabled if the first command line argument is
  711.     the word 'auto'.  This will trigger a series of tests
  712.     */
  713.       if ( (strcmp(argv[1], "auto") == 0) ||
  714.       (strcmp(argv[1], "AUTO") == 0) )
  715.     {
  716.       auto_mode = 1;
  717.       auto_test();
  718.       printf("Completed series of tests\n");
  719.       exit(0);
  720.     } else {
  721.       auto_mode = 0;
  722.     }
  723.       if ( (strcmp(argv[1], "help") == 0) ||
  724.       (strcmp(argv[1], "HELP") == 0) )
  725.     {
  726.       show_help();
  727.       exit(0);
  728.     }
  729.       strcpy(filename,argv[1]);
  730.     }
  731.     break;
  732.   case 3:     /* <megabytes> <reclen|filename> */
  733.     megabytes = (unsigned) atoi(argv[1]);
  734.     if (atoi(argv[2])) {
  735.       reclen = atoi(argv[2]);
  736.     } else {
  737.       strcpy(filename,argv[2]);
  738.     }
  739.     break;
  740.   case 4:     /* <megabytes> <reclen> <filename> */
  741.     megabytes = (unsigned) atoi(argv[1]);
  742.     reclen = atoi(argv[2]);
  743.     strcpy(filename,argv[3]);
  744.     break;
  745.   default:
  746.     printf("IOZONE: bad usage\n");
  747.     printf(IOZONE_USAGE);
  748.     exit(1);
  749.     
  750.   }
  751.   if (!auto_mode)
  752.     {
  753.       printf("\tSend comments to:\tnorcott_bill@tandem.com\n\n");
  754.     }
  755.   filesize = (unsigned long) (1024L*1024L*megabytes);
  756.   numrecs =  filesize/(unsigned long) reclen;
  757.   if (reclen >  MAXBUFFERSIZE) {
  758.     printf("<Error: Maximum record length is %d bytes\n", MAXBUFFERSIZE);
  759.     exit(1);
  760.   }
  761.   if (reclen < MINBUFFERSIZE) {
  762.     printf("Error: Minimum record length is %d bytes\n", MINBUFFERSIZE);
  763.     exit(1);
  764.   }
  765.   if (!auto_mode)
  766.     {
  767.       printf("\tIOZONE writes a %ld Megabyte sequential file consisting of\n",
  768.          megabytes);
  769.       printf("\t%ld records which are each %ld bytes in length.\n",
  770.          numrecs, reclen);
  771.       printf("\tIt then reads the file.  It prints the bytes-per-second\n");
  772.       printf("\trate at which the computer can read and write files.\n\n");
  773.       printf("\nWriting the %ld Megabyte file, '%s'...", megabytes, filename);
  774.     }
  775.   
  776. #if defined (__TANDEM)
  777.   /*
  778.     Tandem's GUARDIAN preallocates file space based on primary- and secondary extents.
  779.     The last 2 parameters to open are the sizes of the primary- and secondary extents,
  780.     in blocks which are 2K bytes each.  After the primary extent is filled, GUARDIAN
  781.     allocates up to 15 additional extents, one at a time.
  782.     */
  783. #define SPECIAL_CREAT
  784. #define PRI_EXT_BLOCKS 1024
  785. #define SEC_EXT_BLOCKS 1024
  786.   if((fd = creat(filename, 0640,
  787.          PRI_EXT_BLOCKS, SEC_EXT_BLOCKS))<0){
  788.     printf("Cannot create temporary file: %s\n", filename);
  789.     exit(1);
  790.   }
  791. #endif
  792. #ifndef SPECIAL_CREAT
  793.   if((fd = creat(filename, 0640))<0){
  794.     printf("Cannot create temporary file: %s\n", filename);
  795.     exit(1);
  796.   }
  797. #endif
  798. #ifdef TIME
  799.   starttime = time_so_far();
  800. #endif
  801. #ifndef TIME
  802.   printf("\nstart timing\n");
  803. #endif
  804.   for(thisrec=0; thisrec<numrecs; thisrec++){
  805. #ifndef DEBUG_ME
  806.     if(write(fd, buffer, (unsigned) reclen) != reclen)
  807.       {
  808.     printf("Error writing block %d\n", thisrec);
  809.     perror("iozone");
  810.     close(fd);
  811. #ifndef VMS
  812. #ifndef NO_DELETE
  813.     unlink(filename);   /* delete the file */
  814. #endif
  815.     /*stop timer*/
  816. #endif
  817.     exit(1);
  818.       }
  819. #endif
  820.   }
  821. #ifdef USE_FSYNC
  822.   fsync(fd);
  823. #endif
  824. #ifdef TIME
  825.   writetime = time_so_far() - starttime;
  826.   if (!auto_mode)
  827.     {
  828.       printf("%f seconds", writetime);
  829.     }
  830. #endif
  831. #ifndef TIME
  832.   printf("\nstop timing\n");
  833. #endif
  834.   close(fd);
  835. #if defined (VMS)
  836. #define SPECIAL_OPEN_READ
  837.   if((fd = open(filename, O_RDONLY, 0640))<0){
  838.     printf("Cannot open temporary file for read\n");
  839.     exit(1);
  840.   }
  841. #endif
  842.   
  843. #ifdef MSDOS
  844. #define SPECIAL_OPEN_READ
  845.   if((fd = open(filename, O_RDONLY, 0640))<0){
  846.     printf("Cannot open temporary file for read\n");
  847.     exit(1);
  848.   }
  849. #endif
  850.   
  851.   /*
  852.     'Generic' case, compiled if no operating system-specific case was invoked
  853.     */
  854. #ifndef SPECIAL_OPEN_READ
  855.   if((fd = open(filename, O_RDONLY))<0){
  856.     printf("Cannot open temporary file for read\n");
  857.     exit(1);
  858.   }
  859. #endif
  860.   
  861.   
  862.   
  863.   /*start timing*/
  864.   if (!auto_mode)
  865.     {
  866.       printf("\nReading the file...");
  867.     }
  868. #ifndef TIME
  869.   printf("\nstart timing\n");
  870. #endif
  871. #ifdef TIME
  872.   starttime = time_so_far();
  873. #endif
  874.   for(thisrec=0; thisrec<numrecs; thisrec++) {
  875. #ifndef DEBUG_ME
  876.     if(read(fd, buffer, (unsigned) reclen) != reclen)
  877.       {
  878.     printf("Error reading block %d\n", thisrec);
  879.     exit(1);
  880.       }
  881. #endif
  882.   }
  883. #ifndef TIME
  884.   printf("\nstop timing\n");
  885. #endif
  886. #ifdef TIME
  887.   readtime = time_so_far() - starttime;
  888.   if (!auto_mode)
  889.     {
  890.       printf("%f seconds\n", readtime);
  891.     }
  892. #ifdef DEBUG_ME
  893.   readtime = 1;
  894.   writetime = 1;
  895. #endif
  896.   if(readtime!=0)
  897.     {
  898.       filebytes = numrecs* (unsigned long) reclen;
  899.       readrate = (unsigned long) ((double) filebytes / readtime);
  900.       writerate = (unsigned long) ((double) filebytes / writetime);
  901.       if (auto_mode)
  902.     {
  903.       printf(CONTROL_STRING1,
  904.          megabytes,
  905.          reclen,
  906.          writerate,
  907.          readrate);
  908.       
  909.     } else {
  910.       printf("\nIOZONE performance measurements:\n");
  911.       printf("\t%ld bytes/second for writing the file\n", writerate);
  912.       printf("\t%ld bytes/second for reading the file\n", readrate);
  913.       totaltime = readtime + writetime;
  914.       if (totaltime < TOOFAST)
  915.         {
  916.           goodmegs = (TOOFAST/totaltime)*2*megabytes;
  917.           printf("\nThe test completed too quickly to give a good result\n");
  918.           printf("You will get a more precise measure of this machine's\n");
  919.           printf("performance by re-running IOZONE using the command:\n");
  920.           printf("\n\tiozone %ld ", goodmegs);
  921.           printf("\t(i.e., file size = %ld megabytes)\n", goodmegs);
  922.         }
  923.     }
  924.     } else {
  925.       goodrecl = reclen/2;
  926.       printf("\nI/O error during read.  Try again with the command:\n");
  927.       printf("\n\tiozone %ld %ld ", megabytes,  goodrecl);
  928.       printf("\t(i.e. record size = %ld bytes)\n",  goodrecl);
  929.     }
  930. #endif
  931.   close(fd);
  932. #ifndef VMS
  933. #ifndef NO_DELETE
  934.   unlink(filename);   /* delete the file */
  935. #endif
  936.   /*stop timer*/
  937. #endif
  938. #ifdef  usecalloc
  939.   free(buffer);           /* deallocate the memory */
  940. #endif
  941. #ifdef VMS
  942.   return SS$_NORMAL;
  943. #else
  944.   return 0;
  945. #endif
  946. }
  947. /******************************************************************
  948.   
  949.   SHOW_HELP -- show development help of this program
  950.   
  951.   ******************************************************************/
  952. void 
  953.   show_help()
  954. {
  955.   int i;
  956.   printf("IOZONE: help mode\n\n");
  957.   for(i=0; strlen(help[i]); i++)
  958.     {
  959.       printf("%s\n", help[i]);
  960.     }
  961. }
  962. /******************************************************************
  963.   
  964.   SIGNAL_HANDLER -- clean up if user interrupts the program
  965.   
  966.   ******************************************************************/
  967. void 
  968.   signal_handler()
  969. {
  970.   printf("\nIOZONE: interrupted\n\n");
  971. #ifndef VMS
  972. #ifndef NO_DELETE
  973.   printf("deleting file: %s\n", filename);
  974.   unlink(filename);   /* delete the file */
  975. #endif
  976. #endif
  977.   printf("exiting IOzone\n\n");
  978.   exit(0);
  979. }
  980. /******************************************************************
  981.   
  982.   AUTO_TEST -- perform series of tests and tabulate results
  983.   
  984.   ******************************************************************/
  985. void 
  986.   auto_test()
  987. {
  988.   
  989.   int megsi, recszi;
  990.   char megs[10];
  991.   char recsz[10];
  992.   int i,j;
  993.   int autoArgc = 3;
  994.   char *autoArgv[3];
  995.   
  996.   printf("IOZONE: auto-test mode\n\n");
  997.   printf(CONTROL_STRING2,
  998.      "MB",
  999.      "reclen",
  1000.      "bytes/sec written",
  1001.      "bytes/sec read");
  1002.   autoArgv[0] = "IOzone auto-test";
  1003.   autoArgv[1] = megs;
  1004.   autoArgv[2] = recsz;
  1005.   /*
  1006.     Start with file size of 1 megabyte and repeat the test MEGABYTES_ITER_LIMIT
  1007.     times.  Each time we run, the file size is doubled
  1008.     */
  1009.   for(i=0,megsi=1;i<MEGABYTES_ITER_LIMIT;i++,megsi*=2)
  1010.     {
  1011.       sprintf(megs, "%d", megsi);
  1012.       /*
  1013.     Start with record size of 512 bytes and repeat the test RECLEN_ITER_LIMIT
  1014.     times.  Each time we run, the record size is doubled
  1015.     */
  1016.       for (j=0,recszi=512;j<RECLEN_ITER_LIMIT;j++,recszi*=2)
  1017.         {
  1018.       sprintf(recsz, "%d", recszi);
  1019. #ifdef ANSI_MAIN
  1020.       main(autoArgc, autoArgv, NULL);
  1021. #else
  1022.       main(autoArgc, autoArgv);
  1023. #endif
  1024.         }
  1025.     }
  1026. }
  1027.  
  1028. #ifdef TIME
  1029. /******************************************************************
  1030.   
  1031.   TIME_SO_FAR -- return elapsed time
  1032.  
  1033.   5/17/91 Bill Norcott        V1.07 -- use time() for VMS
  1034.   The times() function in VMS returns proc & user CPU time in 10-millisecond
  1035.   ticks.  Instead, use time() which lacks the precision but gives clock
  1036.   time in seconds.
  1037.   V1.14 make val of type clock_t if we are dealing with POSIX
  1038.   V1.15 first time this is called, set base to initial number of clock
  1039.   ticks, then subtract this value from all subsequent calculations.  This
  1040.   will fix a loss of precision when times returns very big numbers;
  1041.   
  1042.   Here is what we check for (in order).  Each returns so we do not
  1043.   have to nest the #ifdefs -- should satisfy even the dumbest 
  1044.   pre-processor.  Note that each has its own flavor of timekeeping
  1045.   1. ANSI C
  1046.   2. POSIX - with and without CLK_TCK defined
  1047.   3. System V variants
  1048.   4. MS-DOS
  1049.   5. BSD variants
  1050.   ******************************************************************/
  1051. double
  1052.   time_so_far()
  1053. {
  1054. #if defined(ANSItime)
  1055.   return (double) time(NULL);
  1056. #endif
  1057.  
  1058. #ifdef isposix
  1059.   {
  1060.     static clock_t base, val;
  1061.     struct tms tms;
  1062.     
  1063.     if (base == 0)
  1064.       {
  1065.     base = times(&tms);
  1066.     if (base == (clock_t) -1)
  1067.       {
  1068.         perror("times");
  1069.       }
  1070.       }
  1071.     val = times(&tms);
  1072.     if (val == (clock_t) -1)
  1073.       {
  1074.     perror("times");
  1075.       }
  1076.     val = val - base;
  1077. #ifndef CLK_TCK
  1078.     return ((double) val) / ((double) sysconf(_SC_CLK_TCK));
  1079. #else
  1080.     return ((double) val) / ((double) CLK_TCK);
  1081. #endif
  1082.   }
  1083. #endif
  1084.  
  1085. #ifdef SysVtime
  1086.   {
  1087.     static long base, val;
  1088.     struct tms tms;
  1089.     
  1090.     if (base == 0)
  1091.       {
  1092.     if ((base = times(&tms)) == -1)
  1093.       {
  1094.         perror("times");
  1095.       }
  1096.       }
  1097.     if ((val = times(&tms)) == -1)
  1098.       {
  1099.     perror("times");
  1100.       }
  1101.     val = val - base;
  1102.     return ((double) val) / ((double) CLK_TCK);
  1103.   }
  1104. #endif
  1105.  
  1106. #if defined(MSDOS)
  1107.   return ((double) clock()) / ((double) CLK_TCK);
  1108. #endif
  1109.  
  1110. #ifdef BSDtime
  1111.   {
  1112.     struct timeval tp;
  1113.     
  1114.     if (gettimeofday(&tp, (struct timezone *) NULL) == -1)
  1115.       perror("gettimeofday");
  1116.     return ((double) (tp.tv_sec)) +
  1117.       (((double) tp.tv_usec) / 1000000.0);
  1118.   }
  1119. #endif
  1120. }
  1121. #endif
  1122.