Path: blob/main/benchmarks/bonnie/files/patch-Bonnie.c
16461 views
--- Bonnie.c.orig 1996-08-28 16:23:49 UTC1+++ Bonnie.c2@@ -25,6 +25,9 @@34#include <unistd.h>5#include <stdio.h>6+#if !defined(SysV)7+#include <stdlib.h>8+#endif9#include <errno.h>10#include <fcntl.h>11#include <sys/types.h>12@@ -49,7 +52,7 @@13#define Seeks (4000)14#define UpdateSeek (10)15#define SeekProcCount (3)16-#define Chunk (16384)17+#define Chunk (8192)1819/* labels for the tests, used as an array index */20typedef enum21@@ -87,7 +90,7 @@ static double delta[(int) TestCount][2];22static double last_cpustamp = 0.0; /* for computing delta-t */23static double last_timestamp = 0.0; /* for computing delta-t */2425-main(26+int main(27int argc,28char * argv[])29{30@@ -146,7 +149,7 @@ main(31/* size is in meg, rounded down to multiple of Chunk */32size *= (1024 * 1024);33size = Chunk * (size / Chunk);34- fprintf(stderr, "File '%s', size: %ld\n", name, size);35+ fprintf(stderr, "File '%s', size: %lld\n", name, size);3637/* Fill up a file, writing it a char at a time with the stdio putc() call */38fprintf(stderr, "Writing with putc()...");39@@ -167,7 +170,7 @@ main(4041/* Now read & rewrite it using block I/O. Dirty one word in each block */42newfile(name, &fd, &stream, 0);43- if (lseek(fd, (off_t) 0, 0) == (off_t) -1)44+ if (lseek(fd, (off_t) 0, SEEK_SET) == (off_t) -1)45io_error("lseek(2) before rewrite");46fprintf(stderr, "Rewriting...");47timestamp();48@@ -179,7 +182,7 @@ main(49if (bufindex == Chunk / IntSize)50bufindex = 0;51buf[bufindex++]++;52- if (lseek(fd, (off_t) -words, 1) == -1)53+ if (lseek(fd, (off_t) -words, SEEK_CUR) == -1)54io_error("relative lseek(2)");55if (write(fd, (char *) buf, words) == -1)56io_error("re write(2)");57@@ -235,7 +238,7 @@ main(5859/* Now suck it in, Chunk at a time, as fast as we can */60newfile(name, &fd, &stream, 0);61- if (lseek(fd, (off_t) 0, 0) == -1)62+ if (lseek(fd, (off_t) 0, SEEK_SET) == -1)63io_error("lseek before read");64fprintf(stderr, "Reading intelligently...");65timestamp();66@@ -288,6 +291,7 @@ main(67{ /* child process */6869/* set up and wait for the go-ahead */70+ close(0);71close(seek_feedback[0]);72close(seek_control[1]);73newfile(name, &fd, &stream, 0);74@@ -303,7 +307,12 @@ main(75/* loop until we read a 0 ticket back from our parent */76while(seek_tickets[0])77{ /* until Mom says stop */78- doseek((long) (random() % (size / Chunk)), fd,79+ off_t seekto;80+ if (size / Chunk < (1 << 25))81+ seekto = random() % (size / Chunk);82+ else83+ seekto = (((off_t)random() << 31) + random()) % (size / Chunk);84+ doseek(seekto, fd,85((lseek_count++ % UpdateSeek) == 0));86if (read(seek_control[0], seek_tickets, 1) != 1)87io_error("read ticket");88@@ -413,7 +422,7 @@ report(89printf("K/sec %%CPU K/sec %%CPU K/sec %%CPU K/sec %%CPU K/sec ");90printf("%%CPU /sec %%CPU\n");9192- printf("%-8.8s %4d ", machine, size / (1024 * 1024));93+ printf("%-8.8s %4lld ", machine, size / (1024 * 1024));94printf("%5d %4.1f %5d %4.1f %5d %4.1f ",95(int) (((double) size) / (delta[(int) Putc][Elapsed] * 1024.0)),96delta[(int) Putc][CPU] / delta[(int) Putc][Elapsed] * 100.0,97@@ -529,7 +538,10 @@ io_error(char * message)98{99char buf[Chunk];100101- sprintf(buf, "Bonnie: drastic I/O error (%s)", message);102+ if((errno == EOVERFLOW) || (errno == EFBIG))103+ sprintf(buf, "\nBonnie: drastic I/O error (%s): %s", message, strerror(errno));104+ else105+ sprintf(buf, "\nBonnie: drastic I/O error (%s)", message);106perror(buf);107exit(1);108}109@@ -557,7 +569,7 @@ doseek(110off_t size;111112probe = where * Chunk;113- if (lseek(fd, probe, 0) != probe)114+ if (lseek(fd, (off_t)probe, SEEK_SET) != probe)115io_error("lseek in doseek");116if ((size = read(fd, (char *) buf, Chunk)) == -1)117io_error("read in doseek");118@@ -568,7 +580,7 @@ doseek(119120/* touch a word */121buf[((int) random() % (size/IntSize - 2)) + 1]--;122- if (lseek(fd, (long) probe, 0) != probe)123+ if (lseek(fd, (off_t)probe, SEEK_SET) != probe)124io_error("lseek in doseek update");125if (write(fd, (char *) buf, size) == -1)126io_error("write in doseek");127128129