Re: [linux-audio-dev] disk seek/read performance testing

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] disk seek/read performance testing
From: Paul Barton-Davis (pbd_AT_Op.Net)
Date: ke helmi  02 2000 - 14:54:53 EST


>I want to make this clear to myself, please confirm:
>several simultaneous 1 seconds (say) reads are split to smaller pieces
>so that those reads are actually interleaved by kernel. But now I wonder
>how much is the split block size?

the kernel *ALWAYS* reads from the disk in 4K chunks. there is no way
around this, as far as i know, without going to 2.3.X and using
stephen c. tweedie's rawio devices.

the following program generates a simple gnuplot-or-human-eye usable
data file called "seekdata". i've been using it a lot to measure disk
behaviour. comments are welcome.

it seeks to a random location on a disk, then reads a block of data,
over and over again until it has read a specified amount of stuff.

it mlocks the buffer to prevent fault from causing a problem, so you
need to be root or use su or sudo to run it.

you should almost certainly access the disk device rather than a
partition or a file so that the seeking covers the entire disk surface
and the buffer cache is less likely to skew results. I use alternating
disks each time i run it to also reduce the buffer cache effect, but
its not that necessary, since the buffer cache reduces the average
read time down to something effectively close to zero compared with
those that really needed a seek.

use: testseek <file> <read-size-in-bytes> <total-bytes-of-data-to-be-read>

eg. testseek /dev/sda 192000 104857600

to measure actual seek time, i use:

testseek /dev/sda 1 5000

i.e. seek, read 1 byte, seek, read 1 byte etc. etc.

oh, one last thing: the msec measurement assumes a 450MHz
machine. Change the "450000" to suit yours if you use it. You may also
need to alter MSEC_LIMIT if the read peaktimes take more than 100msec.

--p

----------------------------------------------------------------------

#include <stdio.h>
#include <asm/msr.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>

#define MSEC_LIMIT 100

main (int argc, char *argv[])

{
        int fd;
        unsigned long now;
        unsigned long then;
        off_t location;
        char *buf;
        int n;
        struct stat statbuf;
        size_t bufsize;
        size_t file_size;
        size_t times[MSEC_LIMIT];
        FILE *foo;
        size_t data_read;
        size_t data_limit;

        bufsize = atoi (argv[2]);
        data_limit = atoi (argv[3]);

        if ((fd = open (argv[1], O_RDONLY)) < 0) {
                fprintf (stderr, "cannot open %s (%s)\n",
                         argv[1], strerror (errno));
                return -1;
        }

        fstat (fd, &statbuf);

        file_size = statbuf.st_size - bufsize;

        buf = (char *) malloc (bufsize);
        if (mlock (buf, bufsize) == 0) {
                printf ("Buffer locked\n");
        }
        memset (times, 0, sizeof (times));
        srandom (time ((time_t) 0));

        data_read = 0;
        while (data_read < data_limit) {
                size_t msecs;
                size_t nread;

                location = random() % file_size;

                rdtscl (then);
                if ((nread = pread (fd, buf, bufsize, location)) < 0) {
                        fprintf (stderr, "read failed (%s)\n",
                                 strerror (errno));
                        return -1;
                }
                rdtscl (now);

                data_read += nread;

                msecs = (now - then) / 450000;

                if (msecs < MSEC_LIMIT) {
                        times[msecs]++;
                } else {
                        fprintf (stderr, "TOO LONG: %d\n", msecs);
                }
        }

        foo = fopen ("seekdata", "w");

        for (n = 0; n < sizeof(times)/sizeof(times[0]); n++) {
                fprintf (foo, "%d %d\n", n, times[n]);
        }

        fclose (foo);

        close (fd);
        exit (0);
}


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : pe maalis 10 2000 - 07:23:27 EST