[BACK]Return to patch-ac CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / pkgsrc / benchmarks / bonnie / patches

File: [cvs.NetBSD.org] / pkgsrc / benchmarks / bonnie / patches / patch-ac (download)

Revision 1.5, Mon Sep 12 07:17:14 2011 UTC (9 years, 1 month ago) by dholland
Branch: MAIN
CVS Tags: pkgsrc-2013Q2-base, pkgsrc-2013Q2, pkgsrc-2013Q1-base, pkgsrc-2013Q1, pkgsrc-2012Q4-base, pkgsrc-2012Q4, pkgsrc-2012Q3-base, pkgsrc-2012Q3, pkgsrc-2012Q2-base, pkgsrc-2012Q2, pkgsrc-2012Q1-base, pkgsrc-2012Q1, pkgsrc-2011Q4-base, pkgsrc-2011Q4, pkgsrc-2011Q3-base, pkgsrc-2011Q3
Changes since 1.4: +26 -14 lines

Update the patch here to use %llu instead of %qu for 64-bit values,
since clang objects to %qu. Also patch another format string that
was previously missed

$NetBSD: patch-ac,v 1.5 2011/09/12 07:17:14 dholland Exp $

- ...
- cope with 64-bit off_t

--- bonnie.c.orig	1996-08-28 16:23:49.000000000 +0000
+++ bonnie.c
@@ -25,8 +25,10 @@
 
 #include <unistd.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <string.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #if defined(SysV)
@@ -34,6 +36,7 @@
 #include <sys/times.h>
 #else
 #include <sys/resource.h>
+#include <sys/wait.h>
 #endif
 
 #define IntSize (sizeof(int))
@@ -49,7 +52,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
@@ -87,11 +91,12 @@ static double delta[(int) TestCount][2];
 static double last_cpustamp = 0.0;       /* for computing delta-t */
 static double last_timestamp = 0.0;      /* for computing delta-t */
 
+int
 main(
   int    argc,
   char * argv[])
 {
-  int    buf[Chunk / IntSize];
+  int    *buf;
   int    bufindex;
   int    chars[256];
   int    child;
@@ -122,6 +127,8 @@ main(
   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 +153,12 @@ main(
   /* 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: %llu\n", name, (unsigned long long) size);
+
+  if (!(buf = (int *) malloc(Chunk))) {
+    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 +300,7 @@ main(
     { /* 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 +316,13 @@ main(
       /* 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");
@@ -380,7 +399,7 @@ write_html(
   off_t  size)
 {
 
-  printf("<TR><TD>%s</TD><TD>%d</TD>", machine, size / (1024 * 1024));
+  printf("<TR><TD>%s</TD><TD>%lld</TD>", machine, (long long) (size / (1024 * 1024)));
   printf("<TD>%d</TD><TD>%4.1f</TD><TD>%d</TD><TD>%4.1f</TD><TD>%d</TD><TD>%4.1f</TD>",
     (int) (((double) size) / (delta[(int) Putc][Elapsed] * 1024.0)),
     delta[(int) Putc][CPU] / delta[(int) Putc][Elapsed] * 100.0,
@@ -413,7 +432,7 @@ report(
   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 %4llu ", machine, (unsigned long long) 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 +477,7 @@ static void
 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 +548,7 @@ io_error(char * message)
 {
   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 +587,7 @@ doseek(
 
     /* 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");