int fd;
int stat_fd;
pid_t pid;
+ char *buf;
volatile int terminate;
volatile int runstate;
unsigned int ddir;
static void do_sync_io(struct thread_data *td)
{
struct timeval s, e;
- char *buffer, *ptr;
unsigned long blocks, msec, usec;
- ptr = malloc(td->bs + MASK);
- buffer = ALIGN(ptr);
-
- gettimeofday(&td->start, NULL);
-
- if (td->ratemin)
- memcpy(&td->lastrate, &td->start, sizeof(td->start));
-
for (blocks = 0; blocks < td->blocks; blocks++) {
off_t offset = get_next_offset(td);
int ret;
gettimeofday(&s, NULL);
if (td->ddir == DDIR_READ)
- ret = read(td->fd, buffer, td->bs);
+ ret = read(td->fd, td->buf, td->bs);
else
- ret = write(td->fd, buffer, td->bs);
+ ret = write(td->fd, td->buf, td->bs);
if (ret < (int) td->bs) {
if (ret == -1)
if (should_fsync(td))
fsync(td->fd);
-
- gettimeofday(&e, NULL);
- td->runtime = mtime_since(&td->start, &e);
-
- free(ptr);
}
static void aio_put_iocb(struct thread_data *td, struct iocb *iocb)
td->aio_cur_depth--;
}
-static struct iocb *aio_get_iocb(struct thread_data *td, char *buffer,
- struct timeval *t)
+static struct iocb *aio_get_iocb(struct thread_data *td, struct timeval *t)
{
struct iocb *iocb = NULL;
unsigned int i;
if (iocb) {
off_t off = get_next_offset(td);
- char *p = buffer + i * td->bs;
+ char *p = td->buf + i * td->bs;
if (td->ddir == DDIR_READ)
io_prep_pread(iocb, td->fd, p, td->bs, off);
static void do_async_io(struct thread_data *td)
{
struct timeval s, e;
- char *buf, *ptr;
unsigned long blocks, msec, usec;
- ptr = malloc(td->bs * td->aio_depth + MASK);
- buf = ALIGN(ptr);
-
- gettimeofday(&td->start, NULL);
-
- if (td->ratemin)
- memcpy(&td->lastrate, &td->start, sizeof(td->start));
-
for (blocks = 0; blocks < td->blocks; blocks++) {
struct timespec ts = { .tv_sec = 0, .tv_nsec = 0};
struct timespec *timeout;
gettimeofday(&s, NULL);
- iocb = aio_get_iocb(td, buf, &s);
+ iocb = aio_get_iocb(td, &s);
ret = aio_submit(td, iocb);
if (ret) {
break;
}
}
-
- gettimeofday(&e, NULL);
- td->runtime = mtime_since(&td->start, &e);
-
- free(ptr);
}
static void cleanup_pending_aio(struct thread_data *td)
static void *thread_main(int shm_id, int offset, char *argv[])
{
struct thread_data *td;
- void *data;
+ struct timeval end;
+ void *data, *ptr = NULL;
struct stat st;
int ret = 1, flags;
+ setsid();
+
data = shmat(shm_id, NULL, 0);
td = data + offset * sizeof(struct thread_data);
td->pid = getpid();
sem_post(&startup_sem);
sem_wait(&td->mutex);
- if (!td->use_aio)
+ gettimeofday(&td->start, NULL);
+
+ if (td->ratemin)
+ memcpy(&td->lastrate, &td->start, sizeof(td->start));
+
+ if (!td->use_aio) {
+ ptr = malloc(td->bs + MASK);
+ td->buf = ALIGN(ptr);
do_sync_io(td);
- else
+ } else {
+ ptr = malloc(td->bs * td->aio_depth + MASK);
+ td->buf = ALIGN(ptr);
do_async_io(td);
+ }
+
+ gettimeofday(&end, NULL);
+ td->runtime = mtime_since(&td->start, &end);
ret = 0;
out:
shutdown_stat_file(td);
err:
- if (td->fd != -1)
- close(td->fd);
if (td->use_aio)
cleanup_aio(td);
+ if (td->fd != -1) {
+ close(td->fd);
+ td->fd = -1;
+ }
if (ret)
sem_post(&startup_sem);
-
+ if (ptr)
+ free(ptr);
td->runstate = TD_EXITED;
shmdt(data);
return NULL;
return 1;
}
-static int is_empty(char *line)
+static int is_empty_or_comment(char *line)
{
unsigned int i;
- for (i = 0; i < strlen(line); i++)
+ for (i = 0; i < strlen(line); i++) {
if (!isspace(line[i]) && !iscntrl(line[i]))
return 0;
+ if (line[i] == ';')
+ return 0;
+ }
return 1;
}
name = malloc(256);
while ((p = fgets(string, 4096, f)) != NULL) {
+ if (is_empty_or_comment(p))
+ continue;
if (sscanf(p, "[%s]", name) != 1)
continue;
fgetpos(f, &off);
while ((p = fgets(string, 4096, f)) != NULL) {
- if (is_empty(p))
+ if (is_empty_or_comment(p))
continue;
if (strstr(p, "["))
break;
printf("Starting %d threads\n", thread_number);
fflush(stdout);
+ signal(SIGINT, sig_handler);
+
if (timeout) {
signal(SIGALRM, sig_handler);
- signal(SIGINT, sig_handler);
alarm(timeout);
}