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()
63 struct dp_meter *meter; in lookup_meter() local
67 hlist_for_each_entry_rcu(meter, head, dp_hash_node) { in lookup_meter()
68 if (meter->id == meter_id) in lookup_meter()
69 return meter; in lookup_meter()
74 static void attach_meter(struct datapath *dp, struct dp_meter *meter) in attach_meter() argument
76 struct hlist_head *head = meter_hash_bucket(dp, meter->id); in attach_meter()
78 hlist_add_head_rcu(&meter->dp_hash_node, head); in attach_meter()
81 static void detach_meter(struct dp_meter *meter) in detach_meter() argument
84 if (meter) in detach_meter()
85 hlist_del_rcu(&meter->dp_hash_node); in detach_meter()
112 struct dp_meter *meter) in ovs_meter_cmd_reply_stats() argument
121 if (!meter) in ovs_meter_cmd_reply_stats()
125 sizeof(struct ovs_flow_stats), &meter->stats) || in ovs_meter_cmd_reply_stats()
126 nla_put_u64_64bit(reply, OVS_METER_ATTR_USED, meter->used, in ovs_meter_cmd_reply_stats()
134 band = meter->bands; in ovs_meter_cmd_reply_stats()
136 for (i = 0; i < meter->n_bands; ++i, ++band) { in ovs_meter_cmd_reply_stats()
196 struct dp_meter *meter; in dp_meter_create() local
209 meter = kzalloc(n_bands * sizeof(struct dp_meter_band) + in dp_meter_create()
210 sizeof(*meter), GFP_KERNEL); in dp_meter_create()
211 if (!meter) in dp_meter_create()
214 meter->id = nla_get_u32(a[OVS_METER_ATTR_ID]); in dp_meter_create()
215 meter->used = div_u64(ktime_get_ns(), 1000 * 1000); in dp_meter_create()
216 meter->kbps = a[OVS_METER_ATTR_KBPS] ? 1 : 0; in dp_meter_create()
217 meter->keep_stats = !a[OVS_METER_ATTR_CLEAR]; in dp_meter_create()
218 spin_lock_init(&meter->lock); in dp_meter_create()
219 if (meter->keep_stats && a[OVS_METER_ATTR_STATS]) { in dp_meter_create()
220 meter->stats = *(struct ovs_flow_stats *) in dp_meter_create()
223 meter->n_bands = n_bands; in dp_meter_create()
226 band = meter->bands; in dp_meter_create()
260 if (band_max_delta_t > meter->max_delta_t) in dp_meter_create()
261 meter->max_delta_t = band_max_delta_t; in dp_meter_create()
265 return meter; in dp_meter_create()
268 kfree(meter); in dp_meter_create()
275 struct dp_meter *meter, *old_meter; in ovs_meter_cmd_set() local
288 meter = dp_meter_create(a); in ovs_meter_cmd_set()
289 if (IS_ERR_OR_NULL(meter)) in ovs_meter_cmd_set()
290 return PTR_ERR(meter); in ovs_meter_cmd_set()
311 attach_meter(dp, meter); in ovs_meter_cmd_set()
337 kfree(meter); in ovs_meter_cmd_set()
350 struct dp_meter *meter; in ovs_meter_cmd_get() local
371 meter = lookup_meter(dp, meter_id); in ovs_meter_cmd_get()
372 if (!meter) { in ovs_meter_cmd_get()
377 spin_lock_bh(&meter->lock); in ovs_meter_cmd_get()
378 err = ovs_meter_cmd_reply_stats(reply, meter_id, meter); in ovs_meter_cmd_get()
379 spin_unlock_bh(&meter->lock); in ovs_meter_cmd_get()
449 struct dp_meter *meter; in ovs_meter_execute() local
458 meter = lookup_meter(dp, meter_id); in ovs_meter_execute()
460 if (!meter) in ovs_meter_execute()
464 spin_lock(&meter->lock); in ovs_meter_execute()
466 long_delta_ms = (now_ms - meter->used); /* ms */ in ovs_meter_execute()
471 delta_ms = (long_delta_ms > (long long int)meter->max_delta_t) in ovs_meter_execute()
472 ? meter->max_delta_t : (u32)long_delta_ms; in ovs_meter_execute()
476 meter->used = now_ms; in ovs_meter_execute()
477 meter->stats.n_packets += 1; in ovs_meter_execute()
478 meter->stats.n_bytes += skb->len; in ovs_meter_execute()
490 cost = (meter->kbps) ? skb->len * 8 : 1000; in ovs_meter_execute()
493 for (i = 0; i < meter->n_bands; ++i) { in ovs_meter_execute()
496 band = &meter->bands[i]; in ovs_meter_execute()
513 band = &meter->bands[band_exceeded_max]; in ovs_meter_execute()
519 spin_unlock(&meter->lock); in ovs_meter_execute()
524 spin_unlock(&meter->lock); in ovs_meter_execute()
595 struct dp_meter *meter; in ovs_meters_exit() local
598 hlist_for_each_entry_safe(meter, n, head, dp_hash_node) in ovs_meters_exit()
599 kfree(meter); in ovs_meters_exit()