2003-04-09 10:52:10 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2003 Poul-Henning Kamp
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The names of the authors may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior written
|
|
|
|
* permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
2004-04-05 08:15:04 +00:00
|
|
|
#include <stdlib.h>
|
2011-07-21 19:39:40 +00:00
|
|
|
#include <strings.h>
|
2003-04-09 10:52:10 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2004-05-24 22:52:32 +00:00
|
|
|
#include <libutil.h>
|
2003-04-09 10:52:10 +00:00
|
|
|
#include <paths.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <sys/disk.h>
|
Plumb device physical path reporting from CAM devices, through GEOM and
DEVFS, and make it accessible via the diskinfo utility.
Extend GEOM's generic attribute query mechanism into generic disk consumers.
sys/geom/geom_disk.c:
sys/geom/geom_disk.h:
sys/cam/scsi/scsi_da.c:
sys/cam/ata/ata_da.c:
- Allow disk providers to implement a new method which can override
the default BIO_GETATTR response, d_getattr(struct bio *). This
function returns -1 if not handled, otherwise it returns 0 or an
errno to be passed to g_io_deliver().
sys/cam/scsi/scsi_da.c:
sys/cam/ata/ata_da.c:
- Don't copy the serial number to dp->d_ident anymore, as the CAM XPT
is now responsible for returning this information via
d_getattr()->(a)dagetattr()->xpt_getatr().
sys/geom/geom_dev.c:
- Implement a new ioctl, DIOCGPHYSPATH, which returns the GEOM
attribute "GEOM::physpath", if possible. If the attribute request
returns a zero-length string, ENOENT is returned.
usr.sbin/diskinfo/diskinfo.c:
- If the DIOCGPHYSPATH ioctl is successful, report physical path
data when diskinfo is executed with the '-v' option.
Submitted by: will
Reviewed by: gibbs
Sponsored by: Spectra Logic Corporation
Add generic attribute change notification support to GEOM.
sys/sys/geom/geom.h:
Add a new attrchanged method field to both g_class
and g_geom.
sys/sys/geom/geom.h:
sys/geom/geom_event.c:
- Provide the g_attr_changed() function that providers
can use to advertise attribute changes.
- Perform delivery of attribute change notifications
from a thread context via the standard GEOM event
mechanism.
sys/geom/geom_subr.c:
Inherit the attrchanged method from class to geom (class instance).
sys/geom/geom_disk.c:
Provide disk_attr_changed() to provide g_attr_changed() access
to consumers of the disk API.
sys/cam/scsi/scsi_pass.c:
sys/cam/scsi/scsi_da.c:
sys/geom/geom_dev.c:
sys/geom/geom_disk.c:
Use attribute changed events to track updates to physical path
information.
sys/cam/scsi/scsi_da.c:
Add AC_ADVINFO_CHANGED to the registered asynchronous CAM
events for this driver. When this event occurs, and
the updated buffer type references our physical path
attribute, emit a GEOM attribute changed event via the
disk_attr_changed() API.
sys/cam/scsi/scsi_pass.c:
Add AC_ADVINFO_CHANGED to the registered asynchronous CAM
events for this driver. When this event occurs, update
the physical patch devfs alias for this pass instance.
Submitted by: gibbs
Sponsored by: Spectra Logic Corporation
2011-06-14 17:10:32 +00:00
|
|
|
#include <sys/param.h>
|
2004-04-05 08:15:04 +00:00
|
|
|
#include <sys/time.h>
|
2003-04-09 10:52:10 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2005-01-11 10:53:09 +00:00
|
|
|
fprintf(stderr, "usage: diskinfo [-ctv] disk ...\n");
|
2003-04-09 10:52:10 +00:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2004-11-09 12:28:41 +00:00
|
|
|
static int opt_c, opt_t, opt_v;
|
2003-04-09 10:52:10 +00:00
|
|
|
|
2004-04-05 08:15:04 +00:00
|
|
|
static void speeddisk(int fd, off_t mediasize, u_int sectorsize);
|
2004-11-09 12:28:41 +00:00
|
|
|
static void commandtime(int fd, off_t mediasize, u_int sectorsize);
|
2003-04-09 10:52:10 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2011-02-08 11:32:22 +00:00
|
|
|
int i, ch, fd, error, exitval = 0;
|
Plumb device physical path reporting from CAM devices, through GEOM and
DEVFS, and make it accessible via the diskinfo utility.
Extend GEOM's generic attribute query mechanism into generic disk consumers.
sys/geom/geom_disk.c:
sys/geom/geom_disk.h:
sys/cam/scsi/scsi_da.c:
sys/cam/ata/ata_da.c:
- Allow disk providers to implement a new method which can override
the default BIO_GETATTR response, d_getattr(struct bio *). This
function returns -1 if not handled, otherwise it returns 0 or an
errno to be passed to g_io_deliver().
sys/cam/scsi/scsi_da.c:
sys/cam/ata/ata_da.c:
- Don't copy the serial number to dp->d_ident anymore, as the CAM XPT
is now responsible for returning this information via
d_getattr()->(a)dagetattr()->xpt_getatr().
sys/geom/geom_dev.c:
- Implement a new ioctl, DIOCGPHYSPATH, which returns the GEOM
attribute "GEOM::physpath", if possible. If the attribute request
returns a zero-length string, ENOENT is returned.
usr.sbin/diskinfo/diskinfo.c:
- If the DIOCGPHYSPATH ioctl is successful, report physical path
data when diskinfo is executed with the '-v' option.
Submitted by: will
Reviewed by: gibbs
Sponsored by: Spectra Logic Corporation
Add generic attribute change notification support to GEOM.
sys/sys/geom/geom.h:
Add a new attrchanged method field to both g_class
and g_geom.
sys/sys/geom/geom.h:
sys/geom/geom_event.c:
- Provide the g_attr_changed() function that providers
can use to advertise attribute changes.
- Perform delivery of attribute change notifications
from a thread context via the standard GEOM event
mechanism.
sys/geom/geom_subr.c:
Inherit the attrchanged method from class to geom (class instance).
sys/geom/geom_disk.c:
Provide disk_attr_changed() to provide g_attr_changed() access
to consumers of the disk API.
sys/cam/scsi/scsi_pass.c:
sys/cam/scsi/scsi_da.c:
sys/geom/geom_dev.c:
sys/geom/geom_disk.c:
Use attribute changed events to track updates to physical path
information.
sys/cam/scsi/scsi_da.c:
Add AC_ADVINFO_CHANGED to the registered asynchronous CAM
events for this driver. When this event occurs, and
the updated buffer type references our physical path
attribute, emit a GEOM attribute changed event via the
disk_attr_changed() API.
sys/cam/scsi/scsi_pass.c:
Add AC_ADVINFO_CHANGED to the registered asynchronous CAM
events for this driver. When this event occurs, update
the physical patch devfs alias for this pass instance.
Submitted by: gibbs
Sponsored by: Spectra Logic Corporation
2011-06-14 17:10:32 +00:00
|
|
|
char buf[BUFSIZ], ident[DISK_IDENT_SIZE], physpath[MAXPATHLEN];
|
2009-12-24 21:39:30 +00:00
|
|
|
off_t mediasize, stripesize, stripeoffset;
|
2003-04-09 10:52:10 +00:00
|
|
|
u_int sectorsize, fwsectors, fwheads;
|
|
|
|
|
2004-11-09 12:28:41 +00:00
|
|
|
while ((ch = getopt(argc, argv, "ctv")) != -1) {
|
2003-04-09 10:52:10 +00:00
|
|
|
switch (ch) {
|
2004-11-09 12:28:41 +00:00
|
|
|
case 'c':
|
|
|
|
opt_c = 1;
|
|
|
|
opt_v = 1;
|
|
|
|
break;
|
2003-04-09 10:52:10 +00:00
|
|
|
case 't':
|
|
|
|
opt_t = 1;
|
|
|
|
opt_v = 1;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
opt_v = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2004-03-30 07:37:04 +00:00
|
|
|
if (argc < 1)
|
|
|
|
usage();
|
|
|
|
|
2003-04-09 10:52:10 +00:00
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
fd = open(argv[i], O_RDONLY);
|
|
|
|
if (fd < 0 && errno == ENOENT && *argv[i] != '/') {
|
|
|
|
sprintf(buf, "%s%s", _PATH_DEV, argv[i]);
|
|
|
|
fd = open(buf, O_RDONLY);
|
|
|
|
}
|
2011-02-08 11:32:22 +00:00
|
|
|
if (fd < 0) {
|
|
|
|
warn("%s", argv[i]);
|
|
|
|
exitval = 1;
|
|
|
|
goto out;
|
|
|
|
}
|
2003-04-09 10:52:10 +00:00
|
|
|
error = ioctl(fd, DIOCGMEDIASIZE, &mediasize);
|
2011-02-08 11:32:22 +00:00
|
|
|
if (error) {
|
2012-03-09 18:34:14 +00:00
|
|
|
warnx("%s: ioctl(DIOCGMEDIASIZE) failed, probably not a disk.", argv[i]);
|
2011-02-08 11:32:22 +00:00
|
|
|
exitval = 1;
|
|
|
|
goto out;
|
|
|
|
}
|
2003-04-09 10:52:10 +00:00
|
|
|
error = ioctl(fd, DIOCGSECTORSIZE, §orsize);
|
2011-02-08 11:32:22 +00:00
|
|
|
if (error) {
|
2012-03-09 18:34:14 +00:00
|
|
|
warnx("%s: ioctl(DIOCGSECTORSIZE) failed, probably not a disk.", argv[i]);
|
2011-02-08 11:32:22 +00:00
|
|
|
exitval = 1;
|
|
|
|
goto out;
|
|
|
|
}
|
2003-04-09 10:52:10 +00:00
|
|
|
error = ioctl(fd, DIOCGFWSECTORS, &fwsectors);
|
|
|
|
if (error)
|
|
|
|
fwsectors = 0;
|
|
|
|
error = ioctl(fd, DIOCGFWHEADS, &fwheads);
|
|
|
|
if (error)
|
|
|
|
fwheads = 0;
|
2009-12-24 21:39:30 +00:00
|
|
|
error = ioctl(fd, DIOCGSTRIPESIZE, &stripesize);
|
|
|
|
if (error)
|
|
|
|
stripesize = 0;
|
|
|
|
error = ioctl(fd, DIOCGSTRIPEOFFSET, &stripeoffset);
|
|
|
|
if (error)
|
|
|
|
stripeoffset = 0;
|
2003-04-09 10:52:10 +00:00
|
|
|
if (!opt_v) {
|
|
|
|
printf("%s", argv[i]);
|
|
|
|
printf("\t%u", sectorsize);
|
|
|
|
printf("\t%jd", (intmax_t)mediasize);
|
|
|
|
printf("\t%jd", (intmax_t)mediasize/sectorsize);
|
2009-12-24 21:39:30 +00:00
|
|
|
printf("\t%jd", (intmax_t)stripesize);
|
|
|
|
printf("\t%jd", (intmax_t)stripeoffset);
|
2003-04-09 10:52:10 +00:00
|
|
|
if (fwsectors != 0 && fwheads != 0) {
|
|
|
|
printf("\t%jd", (intmax_t)mediasize /
|
|
|
|
(fwsectors * fwheads * sectorsize));
|
|
|
|
printf("\t%u", fwheads);
|
|
|
|
printf("\t%u", fwsectors);
|
|
|
|
}
|
|
|
|
} else {
|
2004-05-25 12:11:13 +00:00
|
|
|
humanize_number(buf, 5, (int64_t)mediasize, "",
|
2004-05-24 22:52:32 +00:00
|
|
|
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
|
2003-04-09 10:52:10 +00:00
|
|
|
printf("%s\n", argv[i]);
|
|
|
|
printf("\t%-12u\t# sectorsize\n", sectorsize);
|
2004-05-24 22:52:32 +00:00
|
|
|
printf("\t%-12jd\t# mediasize in bytes (%s)\n",
|
|
|
|
(intmax_t)mediasize, buf);
|
2003-04-09 10:52:10 +00:00
|
|
|
printf("\t%-12jd\t# mediasize in sectors\n",
|
|
|
|
(intmax_t)mediasize/sectorsize);
|
2009-12-24 21:39:30 +00:00
|
|
|
printf("\t%-12jd\t# stripesize\n", stripesize);
|
|
|
|
printf("\t%-12jd\t# stripeoffset\n", stripeoffset);
|
2003-04-09 10:52:10 +00:00
|
|
|
if (fwsectors != 0 && fwheads != 0) {
|
|
|
|
printf("\t%-12jd\t# Cylinders according to firmware.\n", (intmax_t)mediasize /
|
|
|
|
(fwsectors * fwheads * sectorsize));
|
|
|
|
printf("\t%-12u\t# Heads according to firmware.\n", fwheads);
|
|
|
|
printf("\t%-12u\t# Sectors according to firmware.\n", fwsectors);
|
|
|
|
}
|
2009-09-03 22:19:09 +00:00
|
|
|
if (ioctl(fd, DIOCGIDENT, ident) == 0)
|
2007-05-06 00:25:21 +00:00
|
|
|
printf("\t%-12s\t# Disk ident.\n", ident);
|
Plumb device physical path reporting from CAM devices, through GEOM and
DEVFS, and make it accessible via the diskinfo utility.
Extend GEOM's generic attribute query mechanism into generic disk consumers.
sys/geom/geom_disk.c:
sys/geom/geom_disk.h:
sys/cam/scsi/scsi_da.c:
sys/cam/ata/ata_da.c:
- Allow disk providers to implement a new method which can override
the default BIO_GETATTR response, d_getattr(struct bio *). This
function returns -1 if not handled, otherwise it returns 0 or an
errno to be passed to g_io_deliver().
sys/cam/scsi/scsi_da.c:
sys/cam/ata/ata_da.c:
- Don't copy the serial number to dp->d_ident anymore, as the CAM XPT
is now responsible for returning this information via
d_getattr()->(a)dagetattr()->xpt_getatr().
sys/geom/geom_dev.c:
- Implement a new ioctl, DIOCGPHYSPATH, which returns the GEOM
attribute "GEOM::physpath", if possible. If the attribute request
returns a zero-length string, ENOENT is returned.
usr.sbin/diskinfo/diskinfo.c:
- If the DIOCGPHYSPATH ioctl is successful, report physical path
data when diskinfo is executed with the '-v' option.
Submitted by: will
Reviewed by: gibbs
Sponsored by: Spectra Logic Corporation
Add generic attribute change notification support to GEOM.
sys/sys/geom/geom.h:
Add a new attrchanged method field to both g_class
and g_geom.
sys/sys/geom/geom.h:
sys/geom/geom_event.c:
- Provide the g_attr_changed() function that providers
can use to advertise attribute changes.
- Perform delivery of attribute change notifications
from a thread context via the standard GEOM event
mechanism.
sys/geom/geom_subr.c:
Inherit the attrchanged method from class to geom (class instance).
sys/geom/geom_disk.c:
Provide disk_attr_changed() to provide g_attr_changed() access
to consumers of the disk API.
sys/cam/scsi/scsi_pass.c:
sys/cam/scsi/scsi_da.c:
sys/geom/geom_dev.c:
sys/geom/geom_disk.c:
Use attribute changed events to track updates to physical path
information.
sys/cam/scsi/scsi_da.c:
Add AC_ADVINFO_CHANGED to the registered asynchronous CAM
events for this driver. When this event occurs, and
the updated buffer type references our physical path
attribute, emit a GEOM attribute changed event via the
disk_attr_changed() API.
sys/cam/scsi/scsi_pass.c:
Add AC_ADVINFO_CHANGED to the registered asynchronous CAM
events for this driver. When this event occurs, update
the physical patch devfs alias for this pass instance.
Submitted by: gibbs
Sponsored by: Spectra Logic Corporation
2011-06-14 17:10:32 +00:00
|
|
|
if (ioctl(fd, DIOCGPHYSPATH, physpath) == 0)
|
|
|
|
printf("\t%-12s\t# Physical path\n", physpath);
|
2003-04-09 10:52:10 +00:00
|
|
|
}
|
|
|
|
printf("\n");
|
2004-11-09 12:28:41 +00:00
|
|
|
if (opt_c)
|
|
|
|
commandtime(fd, mediasize, sectorsize);
|
2003-04-09 10:52:10 +00:00
|
|
|
if (opt_t)
|
2004-04-05 08:15:04 +00:00
|
|
|
speeddisk(fd, mediasize, sectorsize);
|
2011-02-08 11:32:22 +00:00
|
|
|
out:
|
2003-04-09 10:52:10 +00:00
|
|
|
close(fd);
|
|
|
|
}
|
2011-02-08 11:32:22 +00:00
|
|
|
exit (exitval);
|
2003-04-09 10:52:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static char sector[65536];
|
|
|
|
static char mega[1024 * 1024];
|
|
|
|
|
|
|
|
static void
|
2011-07-21 19:39:40 +00:00
|
|
|
rdsect(int fd, off_t blockno, u_int sectorsize)
|
2003-04-09 10:52:10 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2003-04-09 14:25:04 +00:00
|
|
|
lseek(fd, (off_t)blockno * sectorsize, SEEK_SET);
|
2003-04-09 10:52:10 +00:00
|
|
|
error = read(fd, sector, sectorsize);
|
2012-03-09 18:34:14 +00:00
|
|
|
if (error == -1)
|
|
|
|
err(1, "read");
|
2004-04-05 08:15:04 +00:00
|
|
|
if (error != (int)sectorsize)
|
2012-03-09 18:34:14 +00:00
|
|
|
errx(1, "disk too small for test.");
|
2003-04-09 10:52:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rdmega(int fd)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = read(fd, mega, sizeof(mega));
|
2012-03-09 18:34:14 +00:00
|
|
|
if (error == -1)
|
|
|
|
err(1, "read");
|
2003-04-09 10:52:10 +00:00
|
|
|
if (error != sizeof(mega))
|
2012-03-09 18:34:14 +00:00
|
|
|
errx(1, "disk too small for test.");
|
2003-04-09 10:52:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct timeval tv1, tv2;
|
|
|
|
|
|
|
|
static void
|
|
|
|
T0(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
fflush(stdout);
|
|
|
|
sync();
|
|
|
|
sleep(1);
|
|
|
|
sync();
|
|
|
|
sync();
|
|
|
|
gettimeofday(&tv1, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
TN(int count)
|
|
|
|
{
|
|
|
|
double dt;
|
|
|
|
|
|
|
|
gettimeofday(&tv2, NULL);
|
|
|
|
dt = (tv2.tv_usec - tv1.tv_usec) / 1e6;
|
|
|
|
dt += (tv2.tv_sec - tv1.tv_sec);
|
|
|
|
printf("%5d iter in %10.6f sec = %8.3f msec\n",
|
|
|
|
count, dt, dt * 1000.0 / count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
TR(double count)
|
|
|
|
{
|
|
|
|
double dt;
|
|
|
|
|
|
|
|
gettimeofday(&tv2, NULL);
|
|
|
|
dt = (tv2.tv_usec - tv1.tv_usec) / 1e6;
|
|
|
|
dt += (tv2.tv_sec - tv1.tv_sec);
|
|
|
|
printf("%8.0f kbytes in %10.6f sec = %8.0f kbytes/sec\n",
|
|
|
|
count, dt, count / dt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-04-05 08:15:04 +00:00
|
|
|
speeddisk(int fd, off_t mediasize, u_int sectorsize)
|
2003-04-09 10:52:10 +00:00
|
|
|
{
|
2011-07-21 19:39:40 +00:00
|
|
|
int bulk, i;
|
|
|
|
off_t b0, b1, sectorcount, step;
|
2003-04-09 10:52:10 +00:00
|
|
|
|
|
|
|
sectorcount = mediasize / sectorsize;
|
2011-07-21 19:39:40 +00:00
|
|
|
step = 1ULL << (flsll(sectorcount / (4 * 200)) - 1);
|
|
|
|
if (step > 16384)
|
|
|
|
step = 16384;
|
|
|
|
bulk = mediasize / (1024 * 1024);
|
|
|
|
if (bulk > 100)
|
|
|
|
bulk = 100;
|
2003-04-09 10:52:10 +00:00
|
|
|
|
|
|
|
printf("Seek times:\n");
|
|
|
|
printf("\tFull stroke:\t");
|
|
|
|
b0 = 0;
|
2011-07-21 19:39:40 +00:00
|
|
|
b1 = sectorcount - step;
|
2003-04-09 10:52:10 +00:00
|
|
|
T0();
|
|
|
|
for (i = 0; i < 125; i++) {
|
|
|
|
rdsect(fd, b0, sectorsize);
|
2011-07-21 19:39:40 +00:00
|
|
|
b0 += step;
|
2003-04-09 10:52:10 +00:00
|
|
|
rdsect(fd, b1, sectorsize);
|
2011-07-21 19:39:40 +00:00
|
|
|
b1 -= step;
|
2003-04-09 10:52:10 +00:00
|
|
|
}
|
|
|
|
TN(250);
|
|
|
|
|
|
|
|
printf("\tHalf stroke:\t");
|
|
|
|
b0 = sectorcount / 4;
|
|
|
|
b1 = b0 + sectorcount / 2;
|
|
|
|
T0();
|
|
|
|
for (i = 0; i < 125; i++) {
|
|
|
|
rdsect(fd, b0, sectorsize);
|
2011-07-21 19:39:40 +00:00
|
|
|
b0 += step;
|
2003-04-09 10:52:10 +00:00
|
|
|
rdsect(fd, b1, sectorsize);
|
2011-07-21 19:39:40 +00:00
|
|
|
b1 += step;
|
2003-04-09 10:52:10 +00:00
|
|
|
}
|
|
|
|
TN(250);
|
|
|
|
printf("\tQuarter stroke:\t");
|
|
|
|
b0 = sectorcount / 4;
|
|
|
|
b1 = b0 + sectorcount / 4;
|
|
|
|
T0();
|
|
|
|
for (i = 0; i < 250; i++) {
|
|
|
|
rdsect(fd, b0, sectorsize);
|
2011-07-21 19:39:40 +00:00
|
|
|
b0 += step;
|
2003-04-09 10:52:10 +00:00
|
|
|
rdsect(fd, b1, sectorsize);
|
2011-07-21 19:39:40 +00:00
|
|
|
b1 += step;
|
2003-04-09 10:52:10 +00:00
|
|
|
}
|
|
|
|
TN(500);
|
|
|
|
|
|
|
|
printf("\tShort forward:\t");
|
|
|
|
b0 = sectorcount / 2;
|
|
|
|
T0();
|
2003-04-09 14:25:04 +00:00
|
|
|
for (i = 0; i < 400; i++) {
|
2003-04-09 10:52:10 +00:00
|
|
|
rdsect(fd, b0, sectorsize);
|
2011-07-21 19:39:40 +00:00
|
|
|
b0 += step;
|
2003-04-09 10:52:10 +00:00
|
|
|
}
|
2003-04-09 14:25:04 +00:00
|
|
|
TN(400);
|
2003-04-09 10:52:10 +00:00
|
|
|
|
|
|
|
printf("\tShort backward:\t");
|
|
|
|
b0 = sectorcount / 2;
|
|
|
|
T0();
|
2003-04-09 14:25:04 +00:00
|
|
|
for (i = 0; i < 400; i++) {
|
2003-04-09 10:52:10 +00:00
|
|
|
rdsect(fd, b0, sectorsize);
|
2011-07-21 19:39:40 +00:00
|
|
|
b0 -= step;
|
2003-04-09 10:52:10 +00:00
|
|
|
}
|
2003-04-09 14:25:04 +00:00
|
|
|
TN(400);
|
2003-04-09 10:52:10 +00:00
|
|
|
|
|
|
|
printf("\tSeq outer:\t");
|
|
|
|
b0 = 0;
|
|
|
|
T0();
|
2003-04-09 14:25:04 +00:00
|
|
|
for (i = 0; i < 2048; i++) {
|
2003-04-09 10:52:10 +00:00
|
|
|
rdsect(fd, b0, sectorsize);
|
|
|
|
b0++;
|
|
|
|
}
|
2003-04-09 14:25:04 +00:00
|
|
|
TN(2048);
|
2003-04-09 10:52:10 +00:00
|
|
|
|
|
|
|
printf("\tSeq inner:\t");
|
2011-07-21 19:39:40 +00:00
|
|
|
b0 = sectorcount - 2048;
|
2003-04-09 10:52:10 +00:00
|
|
|
T0();
|
2003-04-09 14:25:04 +00:00
|
|
|
for (i = 0; i < 2048; i++) {
|
2003-04-09 10:52:10 +00:00
|
|
|
rdsect(fd, b0, sectorsize);
|
|
|
|
b0++;
|
|
|
|
}
|
2003-04-09 14:25:04 +00:00
|
|
|
TN(2048);
|
2003-04-09 10:52:10 +00:00
|
|
|
|
|
|
|
printf("Transfer rates:\n");
|
|
|
|
printf("\toutside: ");
|
|
|
|
rdsect(fd, 0, sectorsize);
|
|
|
|
T0();
|
2011-07-21 19:39:40 +00:00
|
|
|
for (i = 0; i < bulk; i++) {
|
2003-04-09 10:52:10 +00:00
|
|
|
rdmega(fd);
|
|
|
|
}
|
2011-07-21 19:39:40 +00:00
|
|
|
TR(bulk * 1024);
|
2003-04-09 10:52:10 +00:00
|
|
|
|
|
|
|
printf("\tmiddle: ");
|
2011-07-21 19:39:40 +00:00
|
|
|
b0 = sectorcount / 2 - bulk * (1024*1024 / sectorsize) / 2 - 1;
|
2003-04-09 10:52:10 +00:00
|
|
|
rdsect(fd, b0, sectorsize);
|
|
|
|
T0();
|
2011-07-21 19:39:40 +00:00
|
|
|
for (i = 0; i < bulk; i++) {
|
2003-04-09 10:52:10 +00:00
|
|
|
rdmega(fd);
|
|
|
|
}
|
2011-07-21 19:39:40 +00:00
|
|
|
TR(bulk * 1024);
|
2003-04-09 10:52:10 +00:00
|
|
|
|
|
|
|
printf("\tinside: ");
|
2012-10-22 03:00:37 +00:00
|
|
|
b0 = sectorcount - bulk * (1024*1024 / sectorsize) - 1;
|
2003-04-09 10:52:10 +00:00
|
|
|
rdsect(fd, b0, sectorsize);
|
|
|
|
T0();
|
2011-07-21 19:39:40 +00:00
|
|
|
for (i = 0; i < bulk; i++) {
|
2003-04-09 10:52:10 +00:00
|
|
|
rdmega(fd);
|
|
|
|
}
|
2011-07-21 19:39:40 +00:00
|
|
|
TR(bulk * 1024);
|
2003-04-09 10:52:10 +00:00
|
|
|
|
|
|
|
printf("\n");
|
2004-11-09 12:28:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
commandtime(int fd, off_t mediasize, u_int sectorsize)
|
|
|
|
{
|
|
|
|
double dtmega, dtsector;
|
|
|
|
int i;
|
2003-04-09 10:52:10 +00:00
|
|
|
|
2004-11-09 12:28:41 +00:00
|
|
|
printf("I/O command overhead:\n");
|
|
|
|
i = mediasize;
|
|
|
|
rdsect(fd, 0, sectorsize);
|
|
|
|
T0();
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
rdmega(fd);
|
|
|
|
gettimeofday(&tv2, NULL);
|
|
|
|
dtmega = (tv2.tv_usec - tv1.tv_usec) / 1e6;
|
|
|
|
dtmega += (tv2.tv_sec - tv1.tv_sec);
|
|
|
|
|
|
|
|
printf("\ttime to read 10MB block %10.6f sec\t= %8.3f msec/sector\n",
|
|
|
|
dtmega, dtmega*100/2048);
|
|
|
|
|
|
|
|
rdsect(fd, 0, sectorsize);
|
|
|
|
T0();
|
|
|
|
for (i = 0; i < 20480; i++)
|
|
|
|
rdsect(fd, 0, sectorsize);
|
|
|
|
gettimeofday(&tv2, NULL);
|
|
|
|
dtsector = (tv2.tv_usec - tv1.tv_usec) / 1e6;
|
|
|
|
dtsector += (tv2.tv_sec - tv1.tv_sec);
|
|
|
|
|
|
|
|
printf("\ttime to read 20480 sectors %10.6f sec\t= %8.3f msec/sector\n",
|
|
|
|
dtsector, dtsector*100/2048);
|
|
|
|
printf("\tcalculated command overhead\t\t\t= %8.3f msec/sector\n",
|
|
|
|
(dtsector - dtmega)*100/2048);
|
|
|
|
|
|
|
|
printf("\n");
|
2003-04-09 10:52:10 +00:00
|
|
|
return;
|
|
|
|
}
|