Lines Matching +full:burst +full:- +full:length
4 * Copyright (C) Nodalink, EURL. 2013-2014
41 leak = (bkt->avg * (double) delta_ns) / NANOSECONDS_PER_SECOND; in throttle_leak_bucket()
44 bkt->level = MAX(bkt->level - leak, 0); in throttle_leak_bucket()
47 * keep track of bkt->burst_level so the bkt->max goal per second in throttle_leak_bucket()
49 if (bkt->burst_length > 1) { in throttle_leak_bucket()
50 leak = (bkt->max * (double) delta_ns) / NANOSECONDS_PER_SECOND; in throttle_leak_bucket()
51 bkt->burst_level = MAX(bkt->burst_level - leak, 0); in throttle_leak_bucket()
62 int64_t delta_ns = now - ts->previous_leak; in throttle_do_leak()
65 ts->previous_leak = now; in throttle_do_leak()
73 throttle_leak_bucket(&ts->cfg.buckets[i], delta_ns); in throttle_do_leak()
98 double bucket_size; /* I/O before throttling to bkt->avg */ in throttle_compute_wait()
99 double burst_bucket_size; /* Before throttling to bkt->max */ in throttle_compute_wait()
101 if (!bkt->avg) { in throttle_compute_wait()
105 if (!bkt->max) { in throttle_compute_wait()
106 /* If bkt->max is 0 we still want to allow short bursts of I/O in throttle_compute_wait()
109 bucket_size = (double) bkt->avg / 10; in throttle_compute_wait()
112 /* If we have a burst limit then we have to wait until all I/O in throttle_compute_wait()
113 * at burst rate has finished before throttling to bkt->avg */ in throttle_compute_wait()
114 bucket_size = bkt->max * bkt->burst_length; in throttle_compute_wait()
115 burst_bucket_size = (double) bkt->max / 10; in throttle_compute_wait()
119 extra = bkt->level - bucket_size; in throttle_compute_wait()
121 return throttle_do_compute_wait(bkt->avg, extra); in throttle_compute_wait()
125 * burst bucket in order to enforce the burst limit */ in throttle_compute_wait()
126 if (bkt->burst_length > 1) { in throttle_compute_wait()
127 assert(bkt->max > 0); /* see throttle_is_valid() */ in throttle_compute_wait()
128 extra = bkt->burst_level - burst_bucket_size; in throttle_compute_wait()
130 return throttle_do_compute_wait(bkt->max, extra); in throttle_compute_wait()
159 wait = throttle_compute_wait(&ts->cfg.buckets[index]); in throttle_compute_wait_for()
206 if (tt->timer_cb[dir]) { in throttle_timers_attach_aio_context()
207 tt->timers[dir] = in throttle_timers_attach_aio_context()
208 aio_timer_new(new_context, tt->clock_type, SCALE_NS, in throttle_timers_attach_aio_context()
209 tt->timer_cb[dir], tt->timer_opaque); in throttle_timers_attach_aio_context()
223 cfg->buckets[i].burst_length = 1; in throttle_config_init()
231 throttle_config_init(&ts->cfg); in throttle_init()
245 tt->clock_type = clock_type; in throttle_timers_init()
246 tt->timer_cb[THROTTLE_READ] = read_timer_cb; in throttle_timers_init()
247 tt->timer_cb[THROTTLE_WRITE] = write_timer_cb; in throttle_timers_init()
248 tt->timer_opaque = timer_opaque; in throttle_timers_init()
269 throttle_timer_destroy(&tt->timers[dir]); in throttle_timers_detach_aio_context()
285 if (tt->timers[dir]) { in throttle_timers_are_initialized()
303 if (cfg->buckets[i].avg > 0) { in throttle_enabled()
322 bps_flag = cfg->buckets[THROTTLE_BPS_TOTAL].avg && in throttle_is_valid()
323 (cfg->buckets[THROTTLE_BPS_READ].avg || in throttle_is_valid()
324 cfg->buckets[THROTTLE_BPS_WRITE].avg); in throttle_is_valid()
326 ops_flag = cfg->buckets[THROTTLE_OPS_TOTAL].avg && in throttle_is_valid()
327 (cfg->buckets[THROTTLE_OPS_READ].avg || in throttle_is_valid()
328 cfg->buckets[THROTTLE_OPS_WRITE].avg); in throttle_is_valid()
330 bps_max_flag = cfg->buckets[THROTTLE_BPS_TOTAL].max && in throttle_is_valid()
331 (cfg->buckets[THROTTLE_BPS_READ].max || in throttle_is_valid()
332 cfg->buckets[THROTTLE_BPS_WRITE].max); in throttle_is_valid()
334 ops_max_flag = cfg->buckets[THROTTLE_OPS_TOTAL].max && in throttle_is_valid()
335 (cfg->buckets[THROTTLE_OPS_READ].max || in throttle_is_valid()
336 cfg->buckets[THROTTLE_OPS_WRITE].max); in throttle_is_valid()
344 if (cfg->op_size && in throttle_is_valid()
345 !cfg->buckets[THROTTLE_OPS_TOTAL].avg && in throttle_is_valid()
346 !cfg->buckets[THROTTLE_OPS_READ].avg && in throttle_is_valid()
347 !cfg->buckets[THROTTLE_OPS_WRITE].avg) { in throttle_is_valid()
353 LeakyBucket *bkt = &cfg->buckets[i]; in throttle_is_valid()
354 if (bkt->avg > THROTTLE_VALUE_MAX || bkt->max > THROTTLE_VALUE_MAX) { in throttle_is_valid()
360 if (!bkt->burst_length) { in throttle_is_valid()
361 error_setg(errp, "the burst length cannot be 0"); in throttle_is_valid()
365 if (bkt->burst_length > 1 && !bkt->max) { in throttle_is_valid()
366 error_setg(errp, "burst length set without burst rate"); in throttle_is_valid()
370 if (bkt->max && bkt->burst_length > THROTTLE_VALUE_MAX / bkt->max) { in throttle_is_valid()
371 error_setg(errp, "burst length too high for this burst rate"); in throttle_is_valid()
375 if (bkt->max && !bkt->avg) { in throttle_is_valid()
381 if (bkt->max && bkt->max < bkt->avg) { in throttle_is_valid()
402 ts->cfg = *cfg; in throttle_config()
406 ts->cfg.buckets[i].level = 0; in throttle_config()
407 ts->cfg.buckets[i].burst_level = 0; in throttle_config()
410 ts->previous_leak = qemu_clock_get_ns(clock_type); in throttle_config()
420 *cfg = ts->cfg; in throttle_get_config()
436 int64_t now = qemu_clock_get_ns(tt->clock_type); in throttle_schedule_timer()
442 timer = tt->timers[direction]; in throttle_schedule_timer()
455 /* request throttled and timer pending -> do nothing */ in throttle_schedule_timer()
460 /* request throttled and timer not pending -> arm timer */ in throttle_schedule_timer()
486 if (ts->cfg.op_size && size > ts->cfg.op_size) { in throttle_account()
487 units = (double) size / ts->cfg.op_size; in throttle_account()
493 bkt = &ts->cfg.buckets[bucket_types_size[direction][i]]; in throttle_account()
494 bkt->level += size; in throttle_account()
495 if (bkt->burst_length > 1) { in throttle_account()
496 bkt->burst_level += size; in throttle_account()
499 bkt = &ts->cfg.buckets[bucket_types_units[direction][i]]; in throttle_account()
500 bkt->level += units; in throttle_account()
501 if (bkt->burst_length > 1) { in throttle_account()
502 bkt->burst_level += units; in throttle_account()
516 if (arg->has_bps_total) { in throttle_limits_to_config()
517 cfg->buckets[THROTTLE_BPS_TOTAL].avg = arg->bps_total; in throttle_limits_to_config()
519 if (arg->has_bps_read) { in throttle_limits_to_config()
520 cfg->buckets[THROTTLE_BPS_READ].avg = arg->bps_read; in throttle_limits_to_config()
522 if (arg->has_bps_write) { in throttle_limits_to_config()
523 cfg->buckets[THROTTLE_BPS_WRITE].avg = arg->bps_write; in throttle_limits_to_config()
526 if (arg->has_iops_total) { in throttle_limits_to_config()
527 cfg->buckets[THROTTLE_OPS_TOTAL].avg = arg->iops_total; in throttle_limits_to_config()
529 if (arg->has_iops_read) { in throttle_limits_to_config()
530 cfg->buckets[THROTTLE_OPS_READ].avg = arg->iops_read; in throttle_limits_to_config()
532 if (arg->has_iops_write) { in throttle_limits_to_config()
533 cfg->buckets[THROTTLE_OPS_WRITE].avg = arg->iops_write; in throttle_limits_to_config()
536 if (arg->has_bps_total_max) { in throttle_limits_to_config()
537 cfg->buckets[THROTTLE_BPS_TOTAL].max = arg->bps_total_max; in throttle_limits_to_config()
539 if (arg->has_bps_read_max) { in throttle_limits_to_config()
540 cfg->buckets[THROTTLE_BPS_READ].max = arg->bps_read_max; in throttle_limits_to_config()
542 if (arg->has_bps_write_max) { in throttle_limits_to_config()
543 cfg->buckets[THROTTLE_BPS_WRITE].max = arg->bps_write_max; in throttle_limits_to_config()
545 if (arg->has_iops_total_max) { in throttle_limits_to_config()
546 cfg->buckets[THROTTLE_OPS_TOTAL].max = arg->iops_total_max; in throttle_limits_to_config()
548 if (arg->has_iops_read_max) { in throttle_limits_to_config()
549 cfg->buckets[THROTTLE_OPS_READ].max = arg->iops_read_max; in throttle_limits_to_config()
551 if (arg->has_iops_write_max) { in throttle_limits_to_config()
552 cfg->buckets[THROTTLE_OPS_WRITE].max = arg->iops_write_max; in throttle_limits_to_config()
555 if (arg->has_bps_total_max_length) { in throttle_limits_to_config()
556 if (arg->bps_total_max_length > UINT_MAX) { in throttle_limits_to_config()
557 error_setg(errp, "bps-total-max-length value must be in" in throttle_limits_to_config()
561 cfg->buckets[THROTTLE_BPS_TOTAL].burst_length = arg->bps_total_max_length; in throttle_limits_to_config()
563 if (arg->has_bps_read_max_length) { in throttle_limits_to_config()
564 if (arg->bps_read_max_length > UINT_MAX) { in throttle_limits_to_config()
565 error_setg(errp, "bps-read-max-length value must be in" in throttle_limits_to_config()
569 cfg->buckets[THROTTLE_BPS_READ].burst_length = arg->bps_read_max_length; in throttle_limits_to_config()
571 if (arg->has_bps_write_max_length) { in throttle_limits_to_config()
572 if (arg->bps_write_max_length > UINT_MAX) { in throttle_limits_to_config()
573 error_setg(errp, "bps-write-max-length value must be in" in throttle_limits_to_config()
577 cfg->buckets[THROTTLE_BPS_WRITE].burst_length = arg->bps_write_max_length; in throttle_limits_to_config()
579 if (arg->has_iops_total_max_length) { in throttle_limits_to_config()
580 if (arg->iops_total_max_length > UINT_MAX) { in throttle_limits_to_config()
581 error_setg(errp, "iops-total-max-length value must be in" in throttle_limits_to_config()
585 cfg->buckets[THROTTLE_OPS_TOTAL].burst_length = arg->iops_total_max_length; in throttle_limits_to_config()
587 if (arg->has_iops_read_max_length) { in throttle_limits_to_config()
588 if (arg->iops_read_max_length > UINT_MAX) { in throttle_limits_to_config()
589 error_setg(errp, "iops-read-max-length value must be in" in throttle_limits_to_config()
593 cfg->buckets[THROTTLE_OPS_READ].burst_length = arg->iops_read_max_length; in throttle_limits_to_config()
595 if (arg->has_iops_write_max_length) { in throttle_limits_to_config()
596 if (arg->iops_write_max_length > UINT_MAX) { in throttle_limits_to_config()
597 error_setg(errp, "iops-write-max-length value must be in" in throttle_limits_to_config()
601 cfg->buckets[THROTTLE_OPS_WRITE].burst_length = arg->iops_write_max_length; in throttle_limits_to_config()
604 if (arg->has_iops_size) { in throttle_limits_to_config()
605 cfg->op_size = arg->iops_size; in throttle_limits_to_config()
618 var->bps_total = cfg->buckets[THROTTLE_BPS_TOTAL].avg; in throttle_config_to_limits()
619 var->bps_read = cfg->buckets[THROTTLE_BPS_READ].avg; in throttle_config_to_limits()
620 var->bps_write = cfg->buckets[THROTTLE_BPS_WRITE].avg; in throttle_config_to_limits()
621 var->iops_total = cfg->buckets[THROTTLE_OPS_TOTAL].avg; in throttle_config_to_limits()
622 var->iops_read = cfg->buckets[THROTTLE_OPS_READ].avg; in throttle_config_to_limits()
623 var->iops_write = cfg->buckets[THROTTLE_OPS_WRITE].avg; in throttle_config_to_limits()
624 var->bps_total_max = cfg->buckets[THROTTLE_BPS_TOTAL].max; in throttle_config_to_limits()
625 var->bps_read_max = cfg->buckets[THROTTLE_BPS_READ].max; in throttle_config_to_limits()
626 var->bps_write_max = cfg->buckets[THROTTLE_BPS_WRITE].max; in throttle_config_to_limits()
627 var->iops_total_max = cfg->buckets[THROTTLE_OPS_TOTAL].max; in throttle_config_to_limits()
628 var->iops_read_max = cfg->buckets[THROTTLE_OPS_READ].max; in throttle_config_to_limits()
629 var->iops_write_max = cfg->buckets[THROTTLE_OPS_WRITE].max; in throttle_config_to_limits()
630 var->bps_total_max_length = cfg->buckets[THROTTLE_BPS_TOTAL].burst_length; in throttle_config_to_limits()
631 var->bps_read_max_length = cfg->buckets[THROTTLE_BPS_READ].burst_length; in throttle_config_to_limits()
632 var->bps_write_max_length = cfg->buckets[THROTTLE_BPS_WRITE].burst_length; in throttle_config_to_limits()
633 var->iops_total_max_length = cfg->buckets[THROTTLE_OPS_TOTAL].burst_length; in throttle_config_to_limits()
634 var->iops_read_max_length = cfg->buckets[THROTTLE_OPS_READ].burst_length; in throttle_config_to_limits()
635 var->iops_write_max_length = cfg->buckets[THROTTLE_OPS_WRITE].burst_length; in throttle_config_to_limits()
636 var->iops_size = cfg->op_size; in throttle_config_to_limits()
638 var->has_bps_total = true; in throttle_config_to_limits()
639 var->has_bps_read = true; in throttle_config_to_limits()
640 var->has_bps_write = true; in throttle_config_to_limits()
641 var->has_iops_total = true; in throttle_config_to_limits()
642 var->has_iops_read = true; in throttle_config_to_limits()
643 var->has_iops_write = true; in throttle_config_to_limits()
644 var->has_bps_total_max = true; in throttle_config_to_limits()
645 var->has_bps_read_max = true; in throttle_config_to_limits()
646 var->has_bps_write_max = true; in throttle_config_to_limits()
647 var->has_iops_total_max = true; in throttle_config_to_limits()
648 var->has_iops_read_max = true; in throttle_config_to_limits()
649 var->has_iops_write_max = true; in throttle_config_to_limits()
650 var->has_bps_read_max_length = true; in throttle_config_to_limits()
651 var->has_bps_total_max_length = true; in throttle_config_to_limits()
652 var->has_bps_write_max_length = true; in throttle_config_to_limits()
653 var->has_iops_total_max_length = true; in throttle_config_to_limits()
654 var->has_iops_read_max_length = true; in throttle_config_to_limits()
655 var->has_iops_write_max_length = true; in throttle_config_to_limits()
656 var->has_iops_size = true; in throttle_config_to_limits()