• Home
  • Raw
  • Download

Lines Matching refs:bev

114 bufferevent_update_buckets(struct bufferevent_private *bev)  in bufferevent_update_buckets()  argument
119 event_base_gettimeofday_cached(bev->bev.ev_base, &now); in bufferevent_update_buckets()
120 tick = ev_token_bucket_get_tick_(&now, bev->rate_limiting->cfg); in bufferevent_update_buckets()
121 if (tick != bev->rate_limiting->limit.last_updated) in bufferevent_update_buckets()
122 ev_token_bucket_update_(&bev->rate_limiting->limit, in bufferevent_update_buckets()
123 bev->rate_limiting->cfg, tick); in bufferevent_update_buckets()
198 bufferevent_get_rlim_max_(struct bufferevent_private *bev, int is_write) in bufferevent_get_rlim_max_() argument
201 ev_ssize_t max_so_far = is_write?bev->max_single_write:bev->max_single_read; in bufferevent_get_rlim_max_()
216 if (!bev->rate_limiting) in bufferevent_get_rlim_max_()
224 if (bev->rate_limiting->cfg) { in bufferevent_get_rlim_max_()
225 bufferevent_update_buckets(bev); in bufferevent_get_rlim_max_()
226 max_so_far = LIM(bev->rate_limiting->limit); in bufferevent_get_rlim_max_()
228 if (bev->rate_limiting->group) { in bufferevent_get_rlim_max_()
230 bev->rate_limiting->group; in bufferevent_get_rlim_max_()
238 bufferevent_suspend_write_(&bev->bev, in bufferevent_get_rlim_max_()
241 bufferevent_suspend_read_(&bev->bev, in bufferevent_get_rlim_max_()
261 bufferevent_get_read_max_(struct bufferevent_private *bev) in bufferevent_get_read_max_() argument
263 return bufferevent_get_rlim_max_(bev, 0); in bufferevent_get_read_max_()
267 bufferevent_get_write_max_(struct bufferevent_private *bev) in bufferevent_get_write_max_() argument
269 return bufferevent_get_rlim_max_(bev, 1); in bufferevent_get_write_max_()
273 bufferevent_decrement_read_buckets_(struct bufferevent_private *bev, ev_ssize_t bytes) in bufferevent_decrement_read_buckets_() argument
278 if (!bev->rate_limiting) in bufferevent_decrement_read_buckets_()
281 if (bev->rate_limiting->cfg) { in bufferevent_decrement_read_buckets_()
282 bev->rate_limiting->limit.read_limit -= bytes; in bufferevent_decrement_read_buckets_()
283 if (bev->rate_limiting->limit.read_limit <= 0) { in bufferevent_decrement_read_buckets_()
284 bufferevent_suspend_read_(&bev->bev, BEV_SUSPEND_BW); in bufferevent_decrement_read_buckets_()
285 if (event_add(&bev->rate_limiting->refill_bucket_event, in bufferevent_decrement_read_buckets_()
286 &bev->rate_limiting->cfg->tick_timeout) < 0) in bufferevent_decrement_read_buckets_()
288 } else if (bev->read_suspended & BEV_SUSPEND_BW) { in bufferevent_decrement_read_buckets_()
289 if (!(bev->write_suspended & BEV_SUSPEND_BW)) in bufferevent_decrement_read_buckets_()
290 event_del(&bev->rate_limiting->refill_bucket_event); in bufferevent_decrement_read_buckets_()
291 bufferevent_unsuspend_read_(&bev->bev, BEV_SUSPEND_BW); in bufferevent_decrement_read_buckets_()
295 if (bev->rate_limiting->group) { in bufferevent_decrement_read_buckets_()
296 LOCK_GROUP(bev->rate_limiting->group); in bufferevent_decrement_read_buckets_()
297 bev->rate_limiting->group->rate_limit.read_limit -= bytes; in bufferevent_decrement_read_buckets_()
298 bev->rate_limiting->group->total_read += bytes; in bufferevent_decrement_read_buckets_()
299 if (bev->rate_limiting->group->rate_limit.read_limit <= 0) { in bufferevent_decrement_read_buckets_()
300 bev_group_suspend_reading_(bev->rate_limiting->group); in bufferevent_decrement_read_buckets_()
301 } else if (bev->rate_limiting->group->read_suspended) { in bufferevent_decrement_read_buckets_()
302 bev_group_unsuspend_reading_(bev->rate_limiting->group); in bufferevent_decrement_read_buckets_()
304 UNLOCK_GROUP(bev->rate_limiting->group); in bufferevent_decrement_read_buckets_()
311 bufferevent_decrement_write_buckets_(struct bufferevent_private *bev, ev_ssize_t bytes) in bufferevent_decrement_write_buckets_() argument
316 if (!bev->rate_limiting) in bufferevent_decrement_write_buckets_()
319 if (bev->rate_limiting->cfg) { in bufferevent_decrement_write_buckets_()
320 bev->rate_limiting->limit.write_limit -= bytes; in bufferevent_decrement_write_buckets_()
321 if (bev->rate_limiting->limit.write_limit <= 0) { in bufferevent_decrement_write_buckets_()
322 bufferevent_suspend_write_(&bev->bev, BEV_SUSPEND_BW); in bufferevent_decrement_write_buckets_()
323 if (event_add(&bev->rate_limiting->refill_bucket_event, in bufferevent_decrement_write_buckets_()
324 &bev->rate_limiting->cfg->tick_timeout) < 0) in bufferevent_decrement_write_buckets_()
326 } else if (bev->write_suspended & BEV_SUSPEND_BW) { in bufferevent_decrement_write_buckets_()
327 if (!(bev->read_suspended & BEV_SUSPEND_BW)) in bufferevent_decrement_write_buckets_()
328 event_del(&bev->rate_limiting->refill_bucket_event); in bufferevent_decrement_write_buckets_()
329 bufferevent_unsuspend_write_(&bev->bev, BEV_SUSPEND_BW); in bufferevent_decrement_write_buckets_()
333 if (bev->rate_limiting->group) { in bufferevent_decrement_write_buckets_()
334 LOCK_GROUP(bev->rate_limiting->group); in bufferevent_decrement_write_buckets_()
335 bev->rate_limiting->group->rate_limit.write_limit -= bytes; in bufferevent_decrement_write_buckets_()
336 bev->rate_limiting->group->total_written += bytes; in bufferevent_decrement_write_buckets_()
337 if (bev->rate_limiting->group->rate_limit.write_limit <= 0) { in bufferevent_decrement_write_buckets_()
338 bev_group_suspend_writing_(bev->rate_limiting->group); in bufferevent_decrement_write_buckets_()
339 } else if (bev->rate_limiting->group->write_suspended) { in bufferevent_decrement_write_buckets_()
340 bev_group_unsuspend_writing_(bev->rate_limiting->group); in bufferevent_decrement_write_buckets_()
342 UNLOCK_GROUP(bev->rate_limiting->group); in bufferevent_decrement_write_buckets_()
353 struct bufferevent_private *bev; in bev_group_suspend_reading_() local
363 LIST_FOREACH(bev, &g->members, rate_limiting->next_in_group) { in bev_group_suspend_reading_()
364 if (EVLOCK_TRY_LOCK_(bev->lock)) { in bev_group_suspend_reading_()
365 bufferevent_suspend_read_(&bev->bev, in bev_group_suspend_reading_()
367 EVLOCK_UNLOCK(bev->lock, 0); in bev_group_suspend_reading_()
378 struct bufferevent_private *bev; in bev_group_suspend_writing_() local
381 LIST_FOREACH(bev, &g->members, rate_limiting->next_in_group) { in bev_group_suspend_writing_()
382 if (EVLOCK_TRY_LOCK_(bev->lock)) { in bev_group_suspend_writing_()
383 bufferevent_suspend_write_(&bev->bev, in bev_group_suspend_writing_()
385 EVLOCK_UNLOCK(bev->lock, 0); in bev_group_suspend_writing_()
398 struct bufferevent_private *bev = arg; in bev_refill_callback_() local
400 BEV_LOCK(&bev->bev); in bev_refill_callback_()
401 if (!bev->rate_limiting || !bev->rate_limiting->cfg) { in bev_refill_callback_()
402 BEV_UNLOCK(&bev->bev); in bev_refill_callback_()
407 event_base_gettimeofday_cached(bev->bev.ev_base, &now); in bev_refill_callback_()
409 bev->rate_limiting->cfg); in bev_refill_callback_()
410 ev_token_bucket_update_(&bev->rate_limiting->limit, in bev_refill_callback_()
411 bev->rate_limiting->cfg, in bev_refill_callback_()
415 if ((bev->read_suspended & BEV_SUSPEND_BW)) { in bev_refill_callback_()
416 if (bev->rate_limiting->limit.read_limit > 0) in bev_refill_callback_()
417 bufferevent_unsuspend_read_(&bev->bev, BEV_SUSPEND_BW); in bev_refill_callback_()
421 if ((bev->write_suspended & BEV_SUSPEND_BW)) { in bev_refill_callback_()
422 if (bev->rate_limiting->limit.write_limit > 0) in bev_refill_callback_()
423 bufferevent_unsuspend_write_(&bev->bev, BEV_SUSPEND_BW); in bev_refill_callback_()
435 event_add(&bev->rate_limiting->refill_bucket_event, in bev_refill_callback_()
436 &bev->rate_limiting->cfg->tick_timeout); in bev_refill_callback_()
438 BEV_UNLOCK(&bev->bev); in bev_refill_callback_()
449 struct bufferevent_private *bev; in bev_group_random_element_() local
460 bev = LIST_FIRST(&group->members); in bev_group_random_element_()
462 bev = LIST_NEXT(bev, rate_limiting->next_in_group); in bev_group_random_element_()
464 return bev; in bev_group_random_element_()
477 for (bev = first; bev != LIST_END(&g->members); \
478 bev = LIST_NEXT(bev, rate_limiting->next_in_group)) { \
481 for (bev = LIST_FIRST(&g->members); bev && bev != first; \
482 bev = LIST_NEXT(bev, rate_limiting->next_in_group)) { \
491 struct bufferevent_private *bev, *first; in bev_group_unsuspend_reading_() local
495 if (EVLOCK_TRY_LOCK_(bev->lock)) { in bev_group_unsuspend_reading_()
496 bufferevent_unsuspend_read_(&bev->bev, in bev_group_unsuspend_reading_()
498 EVLOCK_UNLOCK(bev->lock, 0); in bev_group_unsuspend_reading_()
510 struct bufferevent_private *bev, *first; in bev_group_unsuspend_writing_() local
514 if (EVLOCK_TRY_LOCK_(bev->lock)) { in bev_group_unsuspend_writing_()
515 bufferevent_unsuspend_write_(&bev->bev, in bev_group_unsuspend_writing_()
517 EVLOCK_UNLOCK(bev->lock, 0); in bev_group_unsuspend_writing_()
560 bufferevent_set_rate_limit(struct bufferevent *bev, in bufferevent_set_rate_limit() argument
564 EVUTIL_UPCAST(bev, struct bufferevent_private, bev); in bufferevent_set_rate_limit()
572 BEV_LOCK(bev); in bufferevent_set_rate_limit()
578 bufferevent_unsuspend_read_(bev, BEV_SUSPEND_BW); in bufferevent_set_rate_limit()
579 bufferevent_unsuspend_write_(bev, BEV_SUSPEND_BW); in bufferevent_set_rate_limit()
587 event_base_gettimeofday_cached(bev->ev_base, &now); in bufferevent_set_rate_limit()
612 event_assign(&rlim->refill_bucket_event, bev->ev_base, in bufferevent_set_rate_limit()
616 bufferevent_unsuspend_read_(bev, BEV_SUSPEND_BW); in bufferevent_set_rate_limit()
618 bufferevent_suspend_read_(bev, BEV_SUSPEND_BW); in bufferevent_set_rate_limit()
622 bufferevent_unsuspend_write_(bev, BEV_SUSPEND_BW); in bufferevent_set_rate_limit()
624 bufferevent_suspend_write_(bev, BEV_SUSPEND_BW); in bufferevent_set_rate_limit()
634 BEV_UNLOCK(bev); in bufferevent_set_rate_limit()
736 bufferevent_add_to_rate_limit_group(struct bufferevent *bev, in bufferevent_add_to_rate_limit_group() argument
741 EVUTIL_UPCAST(bev, struct bufferevent_private, bev); in bufferevent_add_to_rate_limit_group()
742 BEV_LOCK(bev); in bufferevent_add_to_rate_limit_group()
748 BEV_UNLOCK(bev); in bufferevent_add_to_rate_limit_group()
751 event_assign(&rlim->refill_bucket_event, bev->ev_base, in bufferevent_add_to_rate_limit_group()
757 BEV_UNLOCK(bev); in bufferevent_add_to_rate_limit_group()
761 bufferevent_remove_from_rate_limit_group(bev); in bufferevent_add_to_rate_limit_group()
774 bufferevent_suspend_read_(bev, BEV_SUSPEND_BW_GROUP); in bufferevent_add_to_rate_limit_group()
776 bufferevent_suspend_write_(bev, BEV_SUSPEND_BW_GROUP); in bufferevent_add_to_rate_limit_group()
778 BEV_UNLOCK(bev); in bufferevent_add_to_rate_limit_group()
783 bufferevent_remove_from_rate_limit_group(struct bufferevent *bev) in bufferevent_remove_from_rate_limit_group() argument
785 return bufferevent_remove_from_rate_limit_group_internal_(bev, 1); in bufferevent_remove_from_rate_limit_group()
789 bufferevent_remove_from_rate_limit_group_internal_(struct bufferevent *bev, in bufferevent_remove_from_rate_limit_group_internal_() argument
793 EVUTIL_UPCAST(bev, struct bufferevent_private, bev); in bufferevent_remove_from_rate_limit_group_internal_()
794 BEV_LOCK(bev); in bufferevent_remove_from_rate_limit_group_internal_()
805 bufferevent_unsuspend_read_(bev, BEV_SUSPEND_BW_GROUP); in bufferevent_remove_from_rate_limit_group_internal_()
806 bufferevent_unsuspend_write_(bev, BEV_SUSPEND_BW_GROUP); in bufferevent_remove_from_rate_limit_group_internal_()
808 BEV_UNLOCK(bev); in bufferevent_remove_from_rate_limit_group_internal_()
822 bufferevent_get_read_limit(struct bufferevent *bev) in bufferevent_get_read_limit() argument
826 BEV_LOCK(bev); in bufferevent_get_read_limit()
827 bevp = BEV_UPCAST(bev); in bufferevent_get_read_limit()
834 BEV_UNLOCK(bev); in bufferevent_get_read_limit()
841 bufferevent_get_write_limit(struct bufferevent *bev) in bufferevent_get_write_limit() argument
845 BEV_LOCK(bev); in bufferevent_get_write_limit()
846 bevp = BEV_UPCAST(bev); in bufferevent_get_write_limit()
853 BEV_UNLOCK(bev); in bufferevent_get_write_limit()
858 bufferevent_set_max_single_read(struct bufferevent *bev, size_t size) in bufferevent_set_max_single_read() argument
861 BEV_LOCK(bev); in bufferevent_set_max_single_read()
862 bevp = BEV_UPCAST(bev); in bufferevent_set_max_single_read()
867 BEV_UNLOCK(bev); in bufferevent_set_max_single_read()
872 bufferevent_set_max_single_write(struct bufferevent *bev, size_t size) in bufferevent_set_max_single_write() argument
875 BEV_LOCK(bev); in bufferevent_set_max_single_write()
876 bevp = BEV_UPCAST(bev); in bufferevent_set_max_single_write()
881 BEV_UNLOCK(bev); in bufferevent_set_max_single_write()
886 bufferevent_get_max_single_read(struct bufferevent *bev) in bufferevent_get_max_single_read() argument
890 BEV_LOCK(bev); in bufferevent_get_max_single_read()
891 r = BEV_UPCAST(bev)->max_single_read; in bufferevent_get_max_single_read()
892 BEV_UNLOCK(bev); in bufferevent_get_max_single_read()
897 bufferevent_get_max_single_write(struct bufferevent *bev) in bufferevent_get_max_single_write() argument
901 BEV_LOCK(bev); in bufferevent_get_max_single_write()
902 r = BEV_UPCAST(bev)->max_single_write; in bufferevent_get_max_single_write()
903 BEV_UNLOCK(bev); in bufferevent_get_max_single_write()
908 bufferevent_get_max_to_read(struct bufferevent *bev) in bufferevent_get_max_to_read() argument
911 BEV_LOCK(bev); in bufferevent_get_max_to_read()
912 r = bufferevent_get_read_max_(BEV_UPCAST(bev)); in bufferevent_get_max_to_read()
913 BEV_UNLOCK(bev); in bufferevent_get_max_to_read()
918 bufferevent_get_max_to_write(struct bufferevent *bev) in bufferevent_get_max_to_write() argument
921 BEV_LOCK(bev); in bufferevent_get_max_to_write()
922 r = bufferevent_get_write_max_(BEV_UPCAST(bev)); in bufferevent_get_max_to_write()
923 BEV_UNLOCK(bev); in bufferevent_get_max_to_write()
928 bufferevent_get_token_bucket_cfg(const struct bufferevent *bev) { in bufferevent_get_token_bucket_cfg() argument
929 struct bufferevent_private *bufev_private = BEV_UPCAST(bev); in bufferevent_get_token_bucket_cfg()
932 BEV_LOCK(bev); in bufferevent_get_token_bucket_cfg()
940 BEV_UNLOCK(bev); in bufferevent_get_token_bucket_cfg()
972 bufferevent_decrement_read_limit(struct bufferevent *bev, ev_ssize_t decr) in bufferevent_decrement_read_limit() argument
977 BEV_LOCK(bev); in bufferevent_decrement_read_limit()
978 bevp = BEV_UPCAST(bev); in bufferevent_decrement_read_limit()
984 bufferevent_suspend_read_(bev, BEV_SUSPEND_BW); in bufferevent_decrement_read_limit()
991 bufferevent_unsuspend_read_(bev, BEV_SUSPEND_BW); in bufferevent_decrement_read_limit()
994 BEV_UNLOCK(bev); in bufferevent_decrement_read_limit()
999 bufferevent_decrement_write_limit(struct bufferevent *bev, ev_ssize_t decr) in bufferevent_decrement_write_limit() argument
1006 BEV_LOCK(bev); in bufferevent_decrement_write_limit()
1007 bevp = BEV_UPCAST(bev); in bufferevent_decrement_write_limit()
1013 bufferevent_suspend_write_(bev, BEV_SUSPEND_BW); in bufferevent_decrement_write_limit()
1020 bufferevent_unsuspend_write_(bev, BEV_SUSPEND_BW); in bufferevent_decrement_write_limit()
1023 BEV_UNLOCK(bev); in bufferevent_decrement_write_limit()
1085 bufferevent_ratelim_init_(struct bufferevent_private *bev) in bufferevent_ratelim_init_() argument
1087 bev->rate_limiting = NULL; in bufferevent_ratelim_init_()
1088 bev->max_single_read = MAX_SINGLE_READ_DEFAULT; in bufferevent_ratelim_init_()
1089 bev->max_single_write = MAX_SINGLE_WRITE_DEFAULT; in bufferevent_ratelim_init_()