summaryrefslogtreecommitdiff
path: root/benchmarks/bonnie/patches/patch-ac
blob: f851e82bfbd216de20bf6c1b043dba7ee2dcc367 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
$NetBSD: patch-ac,v 1.2 2005/03/03 08:58:27 garbled Exp $

--- bonnie.c.orig	Wed Aug 28 12:23:49 1996
+++ bonnie.c	Tue Apr 29 23:22:39 2003
@@ -25,6 +25,7 @@
 
 #include <unistd.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <sys/types.h>
@@ -49,7 +50,8 @@
 #define Seeks (4000)
 #define UpdateSeek (10)
 #define SeekProcCount (3)
-#define Chunk (16384)
+
+unsigned int Chunk = 16384;
 
 /* labels for the tests, used as an array index */
 typedef enum
@@ -91,7 +93,7 @@
   int    argc,
   char * argv[])
 {
-  int    buf[Chunk / IntSize];
+  int    *buf;
   int    bufindex;
   int    chars[256];
   int    child;
@@ -122,6 +124,8 @@
   for (next = 1; next < argc; next++)
     if (strcmp(argv[next], "-d") == 0)
       dir = argv[++next];
+    else if (strcmp(argv[next], "-c") == 0)
+      Chunk = atoi(argv[++next]);
     else if (strcmp(argv[next], "-s") == 0)
       size = atol(argv[++next]);
     else if (strcmp(argv[next], "-m") == 0)
@@ -146,7 +150,12 @@
   /* size is in meg, rounded down to multiple of Chunk */
   size *= (1024 * 1024);
   size = Chunk * (size / Chunk);
-  fprintf(stderr, "File '%s', size: %ld\n", name, size);
+  fprintf(stderr, "File '%s', size: %qu\n", name, (u_quad_t) size);
+
+  if (!(buf = (int *) malloc(Chunk / IntSize))) {
+    fprintf(stderr, "Error allocating buffer memory: %s\n", strerror(errno));
+    exit(1);
+  }     
 
   /* Fill up a file, writing it a char at a time with the stdio putc() call */
   fprintf(stderr, "Writing with putc()...");
@@ -288,6 +297,7 @@
     { /* child process */
 
       /* set up and wait for the go-ahead */
+      close(0);					/* From FreeBSD */
       close(seek_feedback[0]);
       close(seek_control[1]);
       newfile(name, &fd, &stream, 0);
@@ -303,7 +313,13 @@
       /* loop until we read a 0 ticket back from our parent */
       while(seek_tickets[0])
       { /* until Mom says stop */
-        doseek((long) (random() % (size / Chunk)), fd,
+        off_t seekto;
+
+        if (size < ((off_t)1 << 32))		/* From FreeBSD */
+          seekto = random() % (size / Chunk);
+        else
+          seekto = ((off_t)random() << 32 + random()) % (size / Chunk);
+        doseek(seekto, fd,
 	  ((lseek_count++ % UpdateSeek) == 0));
 	if (read(seek_control[0], seek_tickets, 1) != 1)
 	  io_error("read ticket");
@@ -413,7 +429,7 @@
   printf("K/sec %%CPU K/sec %%CPU K/sec %%CPU K/sec %%CPU K/sec ");
   printf("%%CPU  /sec %%CPU\n");
 
-  printf("%-8.8s %4d ", machine, size / (1024 * 1024));
+  printf("%-8.8s %4qu ", machine, (u_quad_t) size / (1024 * 1024));
   printf("%5d %4.1f %5d %4.1f %5d %4.1f ",
     (int) (((double) size) / (delta[(int) Putc][Elapsed] * 1024.0)),
     delta[(int) Putc][CPU] / delta[(int) Putc][Elapsed] * 100.0,
@@ -458,7 +474,7 @@
 usage()
 {
   fprintf(stderr,
-    "usage: Bonnie [-d scratch-dir] [-s size-in-Mb] [-html] [-m machine-label]\n");
+    "usage: bonnie [-c chunk-size] [-d scratch-dir] [-s size-in-Mb] [-html] [-m machine-label]\n");
   exit(1);
 }
 
@@ -529,7 +545,7 @@
 {
   char buf[Chunk];
 
-  sprintf(buf, "Bonnie: drastic I/O error (%s)", message);
+  sprintf(buf, "\nBonnie: drastic I/O error (%s)", message);
   perror(buf);
   exit(1);
 }
@@ -568,7 +584,7 @@
 
     /* touch a word */
     buf[((int) random() % (size/IntSize - 2)) + 1]--;
-    if (lseek(fd, (long) probe, 0) != probe)
+    if (lseek(fd, probe, 0) != probe)
       io_error("lseek in doseek update");
     if (write(fd, (char *) buf, size) == -1)
       io_error("write in doseek");