On Wed, Aug 09, 2023 at 12:19:19AM +0800, mit...@outlook.com wrote:
> From: Lin Huang <linhu...@ruijie.com.cn>
> 
> Now, token-bucket 'last_fill' is updated by token_bucket_withdraw() itself.
> Add a new function parameter 'now' to update timestamp by caller.
> 
> Signed-off-by: Lin Huang <linhu...@ruijie.com.cn>

...

> diff --git a/lib/vlog.c b/lib/vlog.c
> index b2653142f..a025f79e5 100644
> --- a/lib/vlog.c
> +++ b/lib/vlog.c
> @@ -1321,12 +1321,13 @@ vlog_should_drop(const struct vlog_module *module, 
> enum vlog_level level,
>      }
>  
>      ovs_mutex_lock(&rl->mutex);
> -    if (!token_bucket_withdraw(&rl->token_bucket, VLOG_MSG_TOKENS)) {
> -        time_t now = time_now();
> +    long long int now = time_msec();
> +    time_t now_sec = now / 1000;

Sorry for not noticing this earlier, but
I think it would be more in keeping with the prevailing
code stile to declare variables at the top of a block.
So now and now_set should be declared at the beginning of the function.

> +    if (!token_bucket_withdraw(&rl->token_bucket, VLOG_MSG_TOKENS, now)) {
>          if (!rl->n_dropped) {
> -            rl->first_dropped = now;
> +            rl->first_dropped = now_sec;
>          }
> -        rl->last_dropped = now;
> +        rl->last_dropped = now_sec;
>          rl->n_dropped++;
>          ovs_mutex_unlock(&rl->mutex);
>          return true;
> @@ -1335,10 +1336,9 @@ vlog_should_drop(const struct vlog_module *module, 
> enum vlog_level level,
>      if (!rl->n_dropped) {
>          ovs_mutex_unlock(&rl->mutex);
>      } else {
> -        time_t now = time_now();
>          unsigned int n_dropped = rl->n_dropped;
> -        unsigned int first_dropped_elapsed = now - rl->first_dropped;
> -        unsigned int last_dropped_elapsed = now - rl->last_dropped;
> +        unsigned int first_dropped_elapsed = now_sec - rl->first_dropped;
> +        unsigned int last_dropped_elapsed = now_sec - rl->last_dropped;
>          rl->n_dropped = 0;
>          ovs_mutex_unlock(&rl->mutex);
>  

...
_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to