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