Commit 5e174d5e authored by Vlad Buslov's avatar Vlad Buslov Committed by David S. Miller
Browse files

net: sched: modify stats helper functions to support regular stats



Modify stats update helper functions introduced in previous patches in this
series to fallback to regular tc_action->tcfa_{b|q}stats if cpu stats are
not allocated for the action argument. If regular non-percpu allocated
counters are in use, then obtain action tcfa_lock while modifying them.

Signed-off-by: default avatarVlad Buslov <vladbu@mellanox.com>
Acked-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ef816f3c
Loading
Loading
Loading
Loading
+21 −9
Original line number Diff line number Diff line
@@ -190,23 +190,35 @@ int tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int, int);
static inline void tcf_action_update_bstats(struct tc_action *a,
					    struct sk_buff *skb)
{
	if (likely(a->cpu_bstats)) {
		bstats_cpu_update(this_cpu_ptr(a->cpu_bstats), skb);
		return;
	}

static inline struct gnet_stats_queue *
tcf_action_get_qstats(struct tc_action *a)
{
	return this_cpu_ptr(a->cpu_qstats);
	spin_lock(&a->tcfa_lock);
	bstats_update(&a->tcfa_bstats, skb);
	spin_unlock(&a->tcfa_lock);
}

static inline void tcf_action_inc_drop_qstats(struct tc_action *a)
{
	if (likely(a->cpu_qstats)) {
		qstats_drop_inc(this_cpu_ptr(a->cpu_qstats));
		return;
	}
	spin_lock(&a->tcfa_lock);
	qstats_drop_inc(&a->tcfa_qstats);
	spin_unlock(&a->tcfa_lock);
}

static inline void tcf_action_inc_overlimit_qstats(struct tc_action *a)
{
	if (likely(a->cpu_qstats)) {
		qstats_overlimit_inc(this_cpu_ptr(a->cpu_qstats));
		return;
	}
	spin_lock(&a->tcfa_lock);
	qstats_overlimit_inc(&a->tcfa_qstats);
	spin_unlock(&a->tcfa_lock);
}

void tcf_action_update_stats(struct tc_action *a, u64 bytes, u32 packets,
+14 −5
Original line number Diff line number Diff line
@@ -992,6 +992,7 @@ err:
void tcf_action_update_stats(struct tc_action *a, u64 bytes, u32 packets,
			     bool drop, bool hw)
{
	if (a->cpu_bstats) {
		_bstats_cpu_update(this_cpu_ptr(a->cpu_bstats), bytes, packets);

		if (drop)
@@ -1000,6 +1001,14 @@ void tcf_action_update_stats(struct tc_action *a, u64 bytes, u32 packets,
		if (hw)
			_bstats_cpu_update(this_cpu_ptr(a->cpu_bstats_hw),
					   bytes, packets);
		return;
	}

	_bstats_update(&a->tcfa_bstats, bytes, packets);
	if (drop)
		a->tcfa_qstats.drops += packets;
	if (hw)
		_bstats_update(&a->tcfa_bstats_hw, bytes, packets);
}
EXPORT_SYMBOL(tcf_action_update_stats);