LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* Simple utility to measure disk random access time
@ 2007-01-16 14:49 Linux Portal
  2007-01-16 19:01 ` Bill Davidsen
  0 siblings, 1 reply; 2+ messages in thread
From: Linux Portal @ 2007-01-16 14:49 UTC (permalink / raw)
  To: linux-kernel

And a few graphs here: http://linux.inet.hr/how_fast_is_your_disk.html

Comments welcome!

#define _LARGEFILE64_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <signal.h>
#include <sys/fcntl.h>
#include <sys/ioctl.h>
#include <linux/fs.h>

#define BLOCKSIZE 512
#define TIMEOUT 30

int count;
time_t start;

void done()
{
	time_t end;

	time(&end);

	if (end < start + TIMEOUT) {
		printf(".");
		alarm(1);
		return;
	}

	if (count) {
	  printf(".\nResults: %d seeks/second, %.2f ms random access time\n",
		 count / TIMEOUT, 1000.0 * TIMEOUT / count);
	}
	exit(EXIT_SUCCESS);
}

void handle(const char *string, int error)
{
	if (error) {
		perror(string);
		exit(EXIT_FAILURE);
	}
}

int main(int argc, char **argv)
{
	char buffer[BLOCKSIZE];
	int fd, retval;
	unsigned long numblocks;
	off64_t offset;

	setvbuf(stdout, NULL, _IONBF, 0);

	printf("Seeker v2.0, 2007-01-15, "
	       "http://linux.inet.hr/how_fast_is_your_disk.html\n");

	if (argc != 2) {
		printf("Usage: seeker <raw disk device>\n");
		exit(EXIT_SUCCESS);
	}

	fd = open(argv[1], O_RDONLY);
	handle("open", fd < 0);

	retval = ioctl(fd, BLKGETSIZE, &numblocks);
	handle("ioctl", retval == -1);
	printf("Benchmarking %s [%luMB], wait %d seconds",
	       argv[1], numblocks / 2048, TIMEOUT);

	time(&start);
	srand(start);
	signal(SIGALRM, &done);
	alarm(1);

	for (;;) {
		offset = (off64_t) numblocks * random() / RAND_MAX;
		retval = lseek64(fd, BLOCKSIZE * offset, SEEK_SET);
		handle("lseek64", retval == (off64_t) -1);
		retval = read(fd, buffer, BLOCKSIZE);
		handle("read", retval < 0);
		count++;
	}
	/* notreached */
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Simple utility to measure disk random access time
  2007-01-16 14:49 Simple utility to measure disk random access time Linux Portal
@ 2007-01-16 19:01 ` Bill Davidsen
  0 siblings, 0 replies; 2+ messages in thread
From: Bill Davidsen @ 2007-01-16 19:01 UTC (permalink / raw)
  To: Linux Portal, Linux Kernel mailing List

Linux Portal wrote:
> And a few graphs here: http://linux.inet.hr/how_fast_is_your_disk.html
> 
> Comments welcome!

These results:

gaimboi:davidsen> ./da /dev/hdb
Seeker v2.0, 2007-01-15, http://linux.inet.hr/how_fast_is_your_disk.html
Benchmarking /dev/hdb [0MB], wait 30 seconds..............................
Results: 565841 seeks/second, 0.00 ms random access time
gaimboi:davidsen> ./da /dev/hda
Seeker v2.0, 2007-01-15, http://linux.inet.hr/how_fast_is_your_disk.html
Benchmarking /dev/hda [19092MB], wait 30 
seconds..............................
Results: 49 seeks/second, 20.20 ms random access time
gaimboi:davidsen> ./da /dev/hdc
Seeker v2.0, 2007-01-15, http://linux.inet.hr/how_fast_is_your_disk.html
Benchmarking /dev/hdc [57241MB], wait 30 
seconds..............................
Results: 64 seeks/second, 15.56 ms random access time


led to this patch:

RCS file: RCS/disk_access.c,v
retrieving revision 1.1
diff -r1.1 disk_access.c
67a68,72
 >       if (numblocks <= 0) {
 >               /* pretty small disk found here */
 >               printf("Disk too small, size: %d blocks\n", numblocks);
 >               exit(EXIT_FAILURE);
 >       }
69a75
 >

and this warning:

gaimboi:davidsen> ./da /dev/hdb
Seeker v2.0, 2007-01-15, http://linux.inet.hr/how_fast_is_your_disk.html
Disk too small, size: 0 blocks


-- 
bill davidsen <davidsen@tmr.com>
   CTO TMR Associates, Inc
   Doing interesting things with small computers since 1979

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-01-16 18:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-16 14:49 Simple utility to measure disk random access time Linux Portal
2007-01-16 19:01 ` Bill Davidsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).