首先mlx5_core驱动有一个单线程的workqueue,每一秒mlx5_fc_stats_work都会被调到,去fw里面查询flow对应的counter。然后放在struct mlx5_fc。这里面用到了单线程,单链表,所以mlx5_fc插入删除的时候并没有锁。当然也不是一个一个的查,而是批量的查。这个即使上百万的flow counter也不会消耗太长时间。
然后用tc去查询相应的flow的时候,下面的函数会被调到:
fl_dump
fl_hw_update_stats
tc_setup_cb_call
mlx5e_setup_tc_block_cb
mlx5e_stats_flower
tcf_exts_stats_update
for(nr_actions)
tcf_action_stats_update
stats_update
tcfa_bstats_hw
tc_action的cpu_bstats和cpu_bstats_hw并不是每个action都有,tcf_idr_create的时候有个参数cpustats控制创建与否。但是如果实现了stats_update callback的话,这个action也可以显示hw offload counters了。
之所以有两个counter,是因为per cpu的counter太耗费cpu资源,action初始化的时候可以选择不用per cpu counter。相应的patch是:
commit bd7ac13f9c32b3251ac3c0caf6be8f64c276c5a1
Author: Vlad Buslov <vladbu@mellanox.com>
Date: Wed Oct 30 16:09:06 2019 +0200
net: sched: update action implementations to support flags
Extend struct tc_action with new "tcfa_flags" field. Set the field in
tcf_idr_create() function and provide new helper
tcf_idr_create_from_flags() that derives 'cpustats' boolean from flags
value. Update individual hardware-offloaded actions init() to pass their
"flags" argument to new helper in order to skip percpu stats allocation
when user requested it through flags.
Signed-off-by: Vlad Buslov <vladbu@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry-picked from commit e38226786022d2d8e5876ab7bc37e82b0eb57e65)
Signed-off-by: Wen-chien Jesse Sung <jesse.sung@canonical.com>