} while (1);
}
-static void rate_throttle(struct thread_data *td, unsigned long time_spent)
+static void rate_throttle(struct thread_data *td, unsigned long time_spent,
+ unsigned int bytes)
{
+ unsigned long usec_cycle;
+
if (!td->rate)
return;
- if (time_spent < td->rate_usec_cycle) {
- unsigned long s = td->rate_usec_cycle - time_spent;
+ usec_cycle = td->rate_usec_cycle * (bytes / td->min_bs);
+
+ if (time_spent < usec_cycle) {
+ unsigned long s = usec_cycle - time_spent;
td->rate_pending_usleep += s;
if (td->rate_pending_usleep >= 100000) {
td->rate_pending_usleep = 0;
}
} else {
- long overtime = time_spent - td->rate_usec_cycle;
+ long overtime = time_spent - usec_cycle;
td->rate_pending_usleep -= overtime;
}
usec = utime_since(&io_u->start_time, &e);
- rate_throttle(td, usec);
+ rate_throttle(td, usec, io_u->buflen);
if (check_min_rate(td, &e)) {
td->error = ENODATA;
#define iocb_time(iocb) ((unsigned long) (iocb)->data)
#define ev_to_iou(ev) (struct io_u *) ((unsigned long) (ev)->obj)
-static void ios_completed(struct thread_data *td, int nr)
+static int ios_completed(struct thread_data *td, int nr)
{
unsigned long msec;
struct io_u *io_u;
struct timeval e;
- int i;
+ int i, bytes_done;
gettimeofday(&e, NULL);
- for (i = 0; i < nr; i++) {
+ for (i = 0, bytes_done = 0; i < nr; i++) {
io_u = ev_to_iou(td->aio_events + i);
td->io_blocks++;
td->io_kb += io_u->buflen >> 10;
+ bytes_done += io_u->buflen;
msec = mtime_since(&io_u->issue_time, &e);
put_io_u(td, io_u);
}
+
+ return bytes_done;
}
static void cleanup_pending_aio(struct thread_data *td)
struct timespec *timeout;
int ret, min_evts = 0;
struct io_u *io_u;
+ unsigned int bytes_done;
if (td->terminate)
break;
} else if (!ret)
continue;
- ios_completed(td, ret);
+ bytes_done = ios_completed(td, ret);
if (should_fsync(td) && td->fsync_blocks &&
(td->io_blocks % td->fsync_blocks) == 0)
gettimeofday(&e, NULL);
usec = utime_since(&s, &e);
- rate_throttle(td, usec);
+ rate_throttle(td, usec, bytes_done);
if (check_min_rate(td, &e)) {
td->error = ENODATA;