Lines Matching refs:meter
45 static void ovs_meter_free(struct dp_meter *meter) in ovs_meter_free() argument
47 if (!meter) in ovs_meter_free()
50 kfree_rcu(meter, rcu); in ovs_meter_free()
59 struct dp_meter *meter; in lookup_meter() local
61 meter = rcu_dereference_ovsl(ti->dp_meters[hash]); in lookup_meter()
62 if (meter && likely(meter->id == meter_id)) in lookup_meter()
63 return meter; in lookup_meter()
117 struct dp_meter *meter) in dp_meter_instance_insert() argument
121 hash = meter_hash(ti, meter->id); in dp_meter_instance_insert()
122 rcu_assign_pointer(ti->dp_meters[hash], meter); in dp_meter_instance_insert()
126 struct dp_meter *meter) in dp_meter_instance_remove() argument
130 hash = meter_hash(ti, meter->id); in dp_meter_instance_remove()
134 static int attach_meter(struct dp_meter_table *tbl, struct dp_meter *meter) in attach_meter() argument
137 u32 hash = meter_hash(ti, meter->id); in attach_meter()
146 dp_meter_instance_insert(ti, meter); in attach_meter()
164 dp_meter_instance_remove(ti, meter); in attach_meter()
169 static int detach_meter(struct dp_meter_table *tbl, struct dp_meter *meter) in detach_meter() argument
174 if (!meter) in detach_meter()
178 dp_meter_instance_remove(ti, meter); in detach_meter()
204 dp_meter_instance_insert(ti, meter); in detach_meter()
233 struct dp_meter *meter) in ovs_meter_cmd_reply_stats() argument
243 sizeof(struct ovs_flow_stats), &meter->stats)) in ovs_meter_cmd_reply_stats()
246 if (nla_put_u64_64bit(reply, OVS_METER_ATTR_USED, meter->used, in ovs_meter_cmd_reply_stats()
254 band = meter->bands; in ovs_meter_cmd_reply_stats()
256 for (i = 0; i < meter->n_bands; ++i, ++band) { in ovs_meter_cmd_reply_stats()
331 struct dp_meter *meter; in dp_meter_create() local
344 meter = kzalloc(struct_size(meter, bands, n_bands), GFP_KERNEL_ACCOUNT); in dp_meter_create()
345 if (!meter) in dp_meter_create()
348 meter->id = nla_get_u32(a[OVS_METER_ATTR_ID]); in dp_meter_create()
349 meter->used = div_u64(ktime_get_ns(), 1000 * 1000); in dp_meter_create()
350 meter->kbps = a[OVS_METER_ATTR_KBPS] ? 1 : 0; in dp_meter_create()
351 meter->keep_stats = !a[OVS_METER_ATTR_CLEAR]; in dp_meter_create()
352 spin_lock_init(&meter->lock); in dp_meter_create()
353 if (meter->keep_stats && a[OVS_METER_ATTR_STATS]) { in dp_meter_create()
354 meter->stats = *(struct ovs_flow_stats *) in dp_meter_create()
357 meter->n_bands = n_bands; in dp_meter_create()
360 band = meter->bands; in dp_meter_create()
394 if (band_max_delta_t > meter->max_delta_t) in dp_meter_create()
395 meter->max_delta_t = band_max_delta_t; in dp_meter_create()
399 return meter; in dp_meter_create()
402 kfree(meter); in dp_meter_create()
409 struct dp_meter *meter, *old_meter; in ovs_meter_cmd_set() local
422 meter = dp_meter_create(a); in ovs_meter_cmd_set()
423 if (IS_ERR(meter)) in ovs_meter_cmd_set()
424 return PTR_ERR(meter); in ovs_meter_cmd_set()
448 err = attach_meter(meter_tbl, meter); in ovs_meter_cmd_set()
479 kfree(meter); in ovs_meter_cmd_set()
488 struct dp_meter *meter; in ovs_meter_cmd_get() local
513 meter = lookup_meter(&dp->meter_tbl, meter_id); in ovs_meter_cmd_get()
514 if (!meter) { in ovs_meter_cmd_get()
519 spin_lock_bh(&meter->lock); in ovs_meter_cmd_get()
520 err = ovs_meter_cmd_reply_stats(reply, meter_id, meter); in ovs_meter_cmd_get()
521 spin_unlock_bh(&meter->lock); in ovs_meter_cmd_get()
598 struct dp_meter *meter; in ovs_meter_execute() local
604 meter = lookup_meter(&dp->meter_tbl, meter_id); in ovs_meter_execute()
606 if (!meter) in ovs_meter_execute()
610 spin_lock(&meter->lock); in ovs_meter_execute()
612 long_delta_ms = (now_ms - meter->used); /* ms */ in ovs_meter_execute()
625 delta_ms = (long_delta_ms > (long long int)meter->max_delta_t) in ovs_meter_execute()
626 ? meter->max_delta_t : (u32)long_delta_ms; in ovs_meter_execute()
630 meter->used = now_ms; in ovs_meter_execute()
631 meter->stats.n_packets += 1; in ovs_meter_execute()
632 meter->stats.n_bytes += skb->len; in ovs_meter_execute()
644 cost = (meter->kbps) ? skb->len * 8 : 1000; in ovs_meter_execute()
647 for (i = 0; i < meter->n_bands; ++i) { in ovs_meter_execute()
650 band = &meter->bands[i]; in ovs_meter_execute()
667 band = &meter->bands[band_exceeded_max]; in ovs_meter_execute()
673 spin_unlock(&meter->lock); in ovs_meter_execute()
678 spin_unlock(&meter->lock); in ovs_meter_execute()