Skip to contentSkip to conversation

tc: add hit counter for matchall

PATCH Applied Cong Wang 3 participants 5 messages Jan 17, 2019 – Jan 24, 2019

Subsystems (2)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 tc: add hit counter for matchall

Cc Martin Olsson <[email protected]>
Cc Jamal Hadi Salim <[email protected]>
Cc Jiri Pirko <[email protected]>
Cc David Ahern <[email protected]>
---
 tc/f_matchall.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
tc/f_matchall.c +14 -0
index 5ebd0415..03dd51de 100644
@@ -114,6 +114,7 @@ static int matchall_print_opt(struct filter_util *qu, FILE *f,
 			   struct rtattr *opt, __u32 handle)
 {
 	struct rtattr *tb[TCA_MATCHALL_MAX+1];
+	struct tc_matchall_pcnt *pf = NULL;
 
 	if (opt == NULL)
 		return 0;
@@ -143,6 +144,19 @@ static int matchall_print_opt(struct filter_util *qu, FILE *f,
 			print_bool(PRINT_ANY, "not_in_hw", "\n  not_in_hw", true);
 	}
 
+	if (tb[TCA_MATCHALL_PCNT]) {
+		if (RTA_PAYLOAD(tb[TCA_MATCHALL_PCNT])  < sizeof(*pf)) {
+			print_string(PRINT_FP, NULL, "Broken perf counters\n", NULL);
+			return -1;
+		}
+		pf = RTA_DATA(tb[TCA_MATCHALL_PCNT]);
+	}
+
+	if (show_stats && NULL != pf)
+		print_u64(PRINT_ANY, "rule_hit", " (rule hit %llu)",
+			(unsigned long long) pf->rhit);
+
+
 	if (tb[TCA_MATCHALL_ACT])
 		tc_print_action(f, tb[TCA_MATCHALL_ACT], 0);
 
Signature · 1 line
2.20.1
author
#2 lore raw
Quoted 12 lines · David Ahern
Quoted 9 lines · Cong Wang
Cc Martin Olsson <[email protected]>
Cc Jamal Hadi Salim <[email protected]>
Cc Jiri Pirko <[email protected]>
Cc David Ahern <[email protected]>
---
 tc/f_matchall.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
Quoted 4 lines

applied to iproute2-next.

In the future, add some kind of description to the log - preferably including example output from the command.

Will do.
I did in the kernel commit, but somehow forgot for iproute2.

Thanks.

#3 lore raw
In reply to Cong Wang

tc/f_matchall.c static int matchall_print_opt(struct filter_util *qu, FILE *f, · line 149

Quoted 4 lines · On Thu, 17 Jan 2019 13:18:55 -0800 Cong Wang <[email protected]> wrote:
tc/f_matchall.c +3 -0
+	if (tb[TCA_MATCHALL_PCNT]) {
+		if (RTA_PAYLOAD(tb[TCA_MATCHALL_PCNT])  < sizeof(*pf)) {
+			print_string(PRINT_FP, NULL, "Broken perf counters\n", NULL);

This the wrong way to print an error message with iproute2 suite. The correct answer is simple.

			fprintf(stderr, "Broken perf counters\n");

and better yet give a more informative message that says what is incorrect.

author
#4 lore raw
Quoted 5 lines · Stephen Hemminger
Quoted 1 line · On Thu, 17 Jan 2019 13:18:55 -0800 Cong Wang <[email protected]> wrote:
Quoted 8 lines

tc/f_matchall.c static int matchall_print_opt(struct filter_util *qu, FILE *f, · line 149

Quoted 3 lines
tc/f_matchall.c +3 -0
+     if (tb[TCA_MATCHALL_PCNT]) {
+             if (RTA_PAYLOAD(tb[TCA_MATCHALL_PCNT])  < sizeof(*pf)) {
+                     print_string(PRINT_FP, NULL, "Broken perf counters\n", NULL);

This the wrong way to print an error message with iproute2 suite. The correct answer is simple.

                        fprintf(stderr, "Broken perf counters\n");

and better yet give a more informative message that says what is incorrect.

What's your suggestion?

In fact, I am not sure if we really have to check the size here, it should be safe to assume kernel will always dump a non-broken struct here, and this struct will never shrink.