Include a very basic (and beta) tool for stressing disks using the POSIX
AIO calls. This small program queues up a controllable number of concurrent AIO read operations w/ controllable io size against a disk or regular file. There are a few other things to add (notably optional write support!) but it works well enough at the present time to stress the AIO code out relatively harshly in the disk IO case.
This commit is contained in:
parent
3af387c9d2
commit
86067c7714
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=178823
6
tools/regression/aio/aiop/Makefile
Normal file
6
tools/regression/aio/aiop/Makefile
Normal file
@ -0,0 +1,6 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= aiop
|
||||
NO_MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
191
tools/regression/aio/aiop/aiop.c
Normal file
191
tools/regression/aio/aiop/aiop.c
Normal file
@ -0,0 +1,191 @@
|
||||
/*
|
||||
* Copyright (c) 2002 Adrian Chadd <adrian@FreeBSD.org>.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software was developed for the FreeBSD Project by Marshall
|
||||
* Kirk McKusick and Network Associates Laboratories, the Security
|
||||
* Research Division of Network Associates, Inc. under DARPA/SPAWAR
|
||||
* contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
|
||||
* research program.
|
||||
*
|
||||
* Copyright (c) 1980, 1989, 1993
|
||||
* The Regents of the University of California. 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.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/disk.h>
|
||||
#include <aio.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
|
||||
/*
|
||||
* This is a bit of a quick hack to do parallel IO testing through POSIX AIO.
|
||||
* Its specifically designed to work under FreeBSD and its derivatives;
|
||||
* note how I cheat by using aio_waitcomplete().
|
||||
*
|
||||
* TODO:
|
||||
*
|
||||
* + Add write support; so we can make sure we're not hitting throughput issues
|
||||
* with read/modify/write of entire tracks of the disk
|
||||
* + Add in per-op stats - time and offset - so one could start mapping out
|
||||
* the speed hotspots of the disk
|
||||
* + Add in different distributions - random, normal, left/right skewed normal,
|
||||
* zipf, etc - and perhaps add the ability to run concurrent distributions
|
||||
* (so a normal and a zipf; and also a random read; zipf write, etc.)
|
||||
*
|
||||
* Adrian Chadd <adrian@creative.net.au>
|
||||
*/
|
||||
|
||||
static size_t
|
||||
disk_getsize(int fd)
|
||||
{
|
||||
off_t mediasize;
|
||||
|
||||
if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) < 0) {
|
||||
perror("ioctl(DIOCGMEDIASIZE)");
|
||||
exit(1);
|
||||
}
|
||||
return mediasize;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
set_aio(struct aiocb *a, int fd, off_t offset, int size, char *buf)
|
||||
{
|
||||
int r;
|
||||
bzero(a, sizeof(*a));
|
||||
a->aio_fildes = fd;
|
||||
a->aio_nbytes = size;
|
||||
a->aio_offset = offset;
|
||||
a->aio_buf = buf;
|
||||
r = aio_read(a);
|
||||
if (r != 0) {
|
||||
perror("aio_read");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int fd;
|
||||
struct stat sb;
|
||||
struct aiocb *aio;
|
||||
char **abuf;
|
||||
const char *fn;
|
||||
int aio_len;
|
||||
int io_size, nrun;
|
||||
off_t file_size, offset;
|
||||
struct aiocb *a;
|
||||
int i, n;
|
||||
struct timeval st, et, rt;
|
||||
float f_rt;
|
||||
|
||||
|
||||
if (argc < 5) {
|
||||
printf("Usage: %s <file> <io size> <number of runs> <concurrency>\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fn = argv[1];
|
||||
io_size = atoi(argv[2]);
|
||||
nrun = atoi(argv[3]);
|
||||
aio_len = atoi(argv[4]);
|
||||
|
||||
/*
|
||||
* Random returns values between 0 and (2^32)-1; only good for 4 gig.
|
||||
* Lets instead treat random() as returning a block offset w/ block size
|
||||
* being "io_size", so we can handle > 4 gig files.
|
||||
*/
|
||||
|
||||
fd = open(fn, O_RDONLY | O_DIRECT);
|
||||
if (fd < 0) {
|
||||
perror("open");
|
||||
exit(1);
|
||||
}
|
||||
if (fstat(fd, &sb) < 0) {
|
||||
perror("fstat");
|
||||
exit(1);
|
||||
}
|
||||
if (S_ISREG(sb.st_mode)) {
|
||||
file_size = sb.st_size;
|
||||
} else if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode)) {
|
||||
file_size = disk_getsize(fd);
|
||||
} else {
|
||||
perror("unknown file type\n");
|
||||
exit(1);
|
||||
}
|
||||
printf("File: %s; File size %ld bytes\n", fn, (long) file_size);
|
||||
|
||||
aio = calloc(aio_len, sizeof(struct aiocb));
|
||||
abuf = calloc(aio_len, sizeof(char *));
|
||||
for (i = 0; i < aio_len; i++) {
|
||||
abuf[i] = calloc(1, io_size * sizeof(char));
|
||||
}
|
||||
|
||||
/* Fill with the initial contents */
|
||||
gettimeofday(&st, NULL);
|
||||
for (i = 0; i < aio_len; i++) {
|
||||
offset = random() % (file_size / io_size);
|
||||
offset *= io_size;
|
||||
set_aio(aio + i, fd, offset, io_size, abuf[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < nrun; i++) {
|
||||
aio_waitcomplete(&a, NULL);
|
||||
n = a - aio;
|
||||
assert(n < aio_len);
|
||||
assert(n >= 0);
|
||||
offset = random() % (file_size / io_size);
|
||||
offset *= io_size;
|
||||
set_aio(aio + n, fd, offset, io_size, abuf[n]);
|
||||
}
|
||||
|
||||
gettimeofday(&et, NULL);
|
||||
timersub(&et, &st, &rt);
|
||||
f_rt = ((float) (rt.tv_usec)) / 1000000.0;
|
||||
f_rt += (float) (rt.tv_sec);
|
||||
printf("Runtime: %.2f seconds, ", f_rt);
|
||||
printf("Op rate: %.2f ops/sec, ", ((float) (nrun)) / f_rt);
|
||||
printf("Avg transfer rate: %.2f bytes/sec\n", ((float) (nrun)) * ((float)io_size) / f_rt);
|
||||
|
||||
|
||||
|
||||
exit(0);
|
||||
}
|
Loading…
Reference in New Issue
Block a user