Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Jan 2000 14:09:53 -0800 (PST)
From:      Matthew Jacob <mjacob@feral.com>
To:        Adam <bsdx@looksharp.net>
Cc:        scsi@FreeBSD.ORG
Subject:   Re: sym troubles
Message-ID:  <Pine.BSF.4.05.10001031405130.44830-100000@semuta.feral.com>
In-Reply-To: <Pine.BSF.4.21.0001031650350.889-100000@turtle.looksharp.net>

next in thread | previous in thread | raw e-mail | index | archive | help

Usually drives cache some amount of info- CDs, maybe not. Use the attached
to find out.


> Hmm, I wonder if theres any way to find out.. 40x * 150 is only 6MB/sec so
> it wouldnt be noticable if I did a speed test, and I have it alone on a
> bus so I wouldn't be able to tell if it slowed down other things
> either.  So I guess all I can do is test patches :P  The cdrom and
> controller are sort-of spare parts for me, so it isnt a critical issue to
> fix.  I have a Tekram 390F btw. 
> 
> On Mon, 3 Jan 2000, Matthew Jacob wrote:


/*
 * Copyright (c) 1998, Matthew Jacob
 *
 *      This software is free software; you can redistribute it and/or
 *      modify it under the terms of the GNU Library General Public
 *      License as published by the Free Software Foundation; version 2.
 *
 *      This software is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *      Library General Public License for more details.
 *
 *      You should have received a copy of the GNU Library General Public
 *      License along with this software; if not, write to the Free
 *      Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *      The author may be reached via electronic communications at
 *
 *              mjacob@feral.com
 *
 *      or, via United States Postal Address
 *
 *              Matthew Jacob
 *              1831 Castro Street
 *              San Francisco, CA, 94131
 *
 ***************************************************************************
 */
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#if	defined(__osf__) || defined(__linux__) || defined(__FreeBSD__)
#include <sys/time.h>
#else
#include <time.h>
#endif
#include <errno.h>
#include <string.h>

#ifdef	__linux__
#include <linux/fs.h>
#endif

static unsigned long szarg(char *);
static char *progname(char *);

int
main(int a, char **v)
{
    int (*iofunc)(int, char *, int);
    int fd, r, oflags;
    unsigned long blksize, offset, nblks, count, loc, etime;
    struct timeval st, et;
    char *name, *bptr;
    double kbsec;

    if (a != 5) {
	fprintf(stderr, "Usage: %s device blksize offsetblk nblks\n", *v);
	return (1);
    }

    if (strcmp(progname(v[0]), "rdsame") == 0) {
	iofunc = (int (*)())read;
	oflags = O_RDONLY;
    } else {
	iofunc = (int (*)())write;
	oflags = O_WRONLY;
    }
	
    name = v[1];
    blksize = szarg(v[2]);
    offset = szarg(v[3]);
    nblks = szarg(v[4]);


    bptr = malloc(blksize);
    if (bptr == NULL) {
	perror("malloc");
	return (1);
    }

    fd = open(name, oflags);
    if (fd < 0) {
	perror(name);
	return (1);
    }
#ifdef	__linux__
    if (ioctl (fd, BLKFLSBUF, 0) < 0) {
	perror("BLKFLSBUF");
    }
#endif
    loc = offset * blksize;
    if (gettimeofday(&st, (struct timezone *) 0) < 0) {
	perror("gettimeofday");
	return (1);
    }
    for (count = 0; count < nblks; count++) {
	if (lseek(fd, loc, 0) != loc) {
	    perror("lseek");
	    return (1);
	}
	if ((r = (*iofunc)(fd, bptr, (int) blksize)) != (int) blksize) {
	    fprintf(stderr, "I/O returned %d, err is %s\n", r, strerror(errno));
	    return (1);
	}
    }
    if (gettimeofday(&et, (struct timezone *) 0) < 0) {
	perror("\ngettimeofday");
	return (1);
    }
    etime = et.tv_sec - st.tv_sec;
    if (et.tv_usec < st.tv_usec) {
	etime--;
	etime *= 1000000;
	etime += (et.tv_usec + 1000000 - st.tv_usec);
    } else {
	etime *= 1000000;
	etime += (et.tv_usec - st.tv_usec);
    }
    kbsec = (double) blksize * (double) count;	/* total bytes */
    kbsec /= (double) 1024.0;
    kbsec *= (double) 1000000.0;
    kbsec /= (double) etime;
    fprintf(stdout, "%s %ld bytes in %d.%d seconds, %5.2fKB/sec in %ld "
	"byte blocks\n", (oflags == O_RDONLY)? "Read" : "Wrote",
	blksize * count, etime / 1000000, etime % 1000000,
	kbsec, blksize);
    return (0);
}

static unsigned long
szarg(char *n)
{
    register int shift = 0;
    register char s, *q = n;
    unsigned long result;

    while (*q != (char) 0)
	q++;
    q--;

    if (*q == 'b' || *q == 'B')
	q--;

    s = *q;
    if (*q == 'k' || *q == 'K') {
	shift = 10;
	*q = 0;
    } else if (*q == 'm' || *q == 'M') {
	shift = 20;
	*q = 0;
    } else if (*q == 'g' || *q == 'G') {
	shift = 30;
	*q = 0;
    }
    result = strtoul((const char *)n, (char **) NULL, 0) << shift;
    *q = s;
    return (result);
}

static char *
progname(char *name)
{
   char *p = strrchr(name, '/');
   if (p)
	return (++p);
   else
	return (name);
}

/*
 * ---------------------------------------------------------------------------
 * Local variables:
 * c-indent-level: 4
 * c-brace-imaginary-offset: 0
 * c-brace-offset: -4
 * c-argdecl-indent: 4
 * c-label-offset: -4
 * c-continued-statement-offset: 4
 * c-continued-brace-offset: 0
 * End:
 */



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-scsi" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.05.10001031405130.44830-100000>