dsched_fq - correct disk busy% calculation
authorAlex Hornung <ahornung@gmail.com>
Tue, 20 Apr 2010 22:31:12 +0000 (22:31 +0000)
committerAlex Hornung <ahornung@gmail.com>
Tue, 20 Apr 2010 22:31:12 +0000 (22:31 +0000)
* Previously old_tv was static, causing problems when several disks had
  the fq policy enabled, as the start time of the interval was taken
  from some other disk.

* Avoid this issue by keeping the information in diskctx, where it
  belongs.

sys/dsched/fq/dsched_fq.h
sys/dsched/fq/dsched_fq_core.c

index 6b31c87..001e5eb 100644 (file)
@@ -161,6 +161,7 @@ struct fq_disk_ctx {
        struct timeval start_idle;      /* disk idleness start time */
        int     idle_time;              /* aggregate idle time in interval */
        int     die;                    /* flag to kill related threads */
+       struct timeval start_interval;  /* current interval start time */
 
        int     prev_full;              /* disk >90% busy during prev. to last
                                           interval? */
index 21a6d40..01addf6 100644 (file)
@@ -417,16 +417,16 @@ void
 fq_balance_thread(struct fq_disk_ctx *diskctx)
 {
        struct  fq_thread_io    *tdio, *tdio2;
-       static struct timeval old_tv;
-       struct timeval tv;
+       struct timeval tv, old_tv;
        int64_t total_budget, product;
        int64_t budget[FQ_PRIO_MAX+1];
        int     n, i, sum, total_disk_time;
        int     lost_bits;
 
-       getmicrotime(&old_tv);
-
        FQ_DISK_CTX_LOCK(diskctx);
+
+       getmicrotime(&diskctx->start_interval);
+
        for (;;) {
                /* sleep ~1s */
                if ((lksleep(curthread, &diskctx->lock, 0, "fq_balancer", hz/2) == 0)) {
@@ -440,6 +440,7 @@ fq_balance_thread(struct fq_disk_ctx *diskctx)
                total_budget = 0;
                n = 0;
 
+               old_tv = diskctx->start_interval;
                getmicrotime(&tv);
 
                total_disk_time = (int)(1000000*((tv.tv_sec - old_tv.tv_sec)) +
@@ -450,7 +451,7 @@ fq_balance_thread(struct fq_disk_ctx *diskctx)
 
                dsched_debug(LOG_INFO, "total_disk_time = %d\n", total_disk_time);
 
-               old_tv = tv;
+               diskctx->start_interval = tv;
 
                diskctx->disk_busy = (100*(total_disk_time - diskctx->idle_time)) / total_disk_time;
                if (diskctx->disk_busy < 0)