Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'Implement-stats_update-callback-for-pedit-and-skbedit'

Petr Machata says:

====================
Implement stats_update callback for pedit and skbedit

The stats_update callback is used for adding HW counters to the SW ones.
Both skbedit and pedit actions are actually recognized by flow_offload.h,
but do not implement these callbacks. As a consequence, the reported values
are only the SW ones, even where there is a HW counter available.

Patch #1 adds the callback to action skbedit, patch #2 adds it to action
pedit. Patch #3 tweaks an skbedit selftest with a check that would have
caught this problem.

The pedit test is not likewise tweaked, because the iproute2 pedit action
currently does not support JSON dumping. This will be addressed later.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+29 -2
+11
net/sched/act_pedit.c
··· 409 409 return p->tcf_action; 410 410 } 411 411 412 + static void tcf_pedit_stats_update(struct tc_action *a, u64 bytes, u32 packets, 413 + u64 lastuse, bool hw) 414 + { 415 + struct tcf_pedit *d = to_pedit(a); 416 + struct tcf_t *tm = &d->tcf_tm; 417 + 418 + tcf_action_update_stats(a, bytes, packets, false, hw); 419 + tm->lastuse = max_t(u64, tm->lastuse, lastuse); 420 + } 421 + 412 422 static int tcf_pedit_dump(struct sk_buff *skb, struct tc_action *a, 413 423 int bind, int ref) 414 424 { ··· 495 485 .id = TCA_ID_PEDIT, 496 486 .owner = THIS_MODULE, 497 487 .act = tcf_pedit_act, 488 + .stats_update = tcf_pedit_stats_update, 498 489 .dump = tcf_pedit_dump, 499 490 .cleanup = tcf_pedit_cleanup, 500 491 .init = tcf_pedit_init,
+11
net/sched/act_skbedit.c
··· 73 73 return TC_ACT_SHOT; 74 74 } 75 75 76 + static void tcf_skbedit_stats_update(struct tc_action *a, u64 bytes, 77 + u32 packets, u64 lastuse, bool hw) 78 + { 79 + struct tcf_skbedit *d = to_skbedit(a); 80 + struct tcf_t *tm = &d->tcf_tm; 81 + 82 + tcf_action_update_stats(a, bytes, packets, false, hw); 83 + tm->lastuse = max_t(u64, tm->lastuse, lastuse); 84 + } 85 + 76 86 static const struct nla_policy skbedit_policy[TCA_SKBEDIT_MAX + 1] = { 77 87 [TCA_SKBEDIT_PARMS] = { .len = sizeof(struct tc_skbedit) }, 78 88 [TCA_SKBEDIT_PRIORITY] = { .len = sizeof(u32) }, ··· 333 323 .id = TCA_ID_SKBEDIT, 334 324 .owner = THIS_MODULE, 335 325 .act = tcf_skbedit_act, 326 + .stats_update = tcf_skbedit_stats_update, 336 327 .dump = tcf_skbedit_dump, 337 328 .init = tcf_skbedit_init, 338 329 .cleanup = tcf_skbedit_cleanup,
+7 -2
tools/testing/selftests/net/forwarding/skbedit_priority.sh
··· 120 120 flower action skbedit priority $prio 121 121 122 122 local pkt0=$(qdisc_parent_stats_get $swp2 $classid .packets) 123 + local pkt2=$(tc_rule_handle_stats_get "$locus" 101) 123 124 $MZ $h1 -t udp "sp=54321,dp=12345" -c 10 -d 20msec -p 100 \ 124 125 -a own -b $h2mac -A 192.0.2.1 -B 192.0.2.2 -q 126 + 125 127 local pkt1 126 128 pkt1=$(busywait "$HIT_TIMEOUT" until_counter_is ">= $((pkt0 + 10))" \ 127 129 qdisc_parent_stats_get $swp2 $classid .packets) 130 + check_err $? "Expected to get 10 packets on class $classid, but got $((pkt1 - pkt0))." 128 131 129 - check_err $? "Expected to get 10 packets on class $classid, but got 130 - $((pkt1 - pkt0))." 132 + local pkt3=$(tc_rule_handle_stats_get "$locus" 101) 133 + ((pkt3 >= pkt2 + 10)) 134 + check_err $? "Expected to get 10 packets on skbedit rule but got $((pkt3 - pkt2))." 135 + 131 136 log_test "$locus skbedit priority $prio -> classid $classid" 132 137 133 138 tc filter del $locus pref 1