Skip to contentSkip to conversation

tc: add performance counters for basic filter

PATCH In review Cong Wang 2 participants 3 messages Jan 23, 2019 – Jan 24, 2019

Subsystems (2)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 tc: add performance counters for basic filter

Sample output:

filter protocol arp pref 49152 basic chain 0
filter protocol arp pref 49152 basic chain 0 handle 0x1 (rule hit 3 success 3)
action order 1: gact action pass
random type none pass val 0
index 1 ref 1 bind 1 installed 81 sec used 4 sec
Action statistics:
Sent 126 bytes 3 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0

Cc Jamal Hadi Salim <[email protected]>
Cc Jiri Pirko <[email protected]>
Cc David Ahern <[email protected]>
---
 tc/f_basic.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
tc/f_basic.c +14 -0
index af98c088..97d43d49 100644
@@ -110,6 +110,7 @@ static int basic_print_opt(struct filter_util *qu, FILE *f,
 			   struct rtattr *opt, __u32 handle)
 {
 	struct rtattr *tb[TCA_BASIC_MAX+1];
+	struct tc_basic_pcnt *pf = NULL;
 
 	if (opt == NULL)
 		return 0;
@@ -125,6 +126,19 @@ static int basic_print_opt(struct filter_util *qu, FILE *f,
 			sprint_tc_classid(rta_getattr_u32(tb[TCA_BASIC_CLASSID]), b1));
 	}
 
+	if (tb[TCA_BASIC_PCNT]) {
+		if (RTA_PAYLOAD(tb[TCA_BASIC_PCNT])  < sizeof(*pf)) {
+			fprintf(f, "Broken perf counters\n");
+			return -1;
+		}
+		pf = RTA_DATA(tb[TCA_BASIC_PCNT]);
+	}
+
+	if (show_stats && NULL != pf)
+		fprintf(f, " (rule hit %llu success %llu)",
+			(unsigned long long) pf->rcnt,
+			(unsigned long long) pf->rhit);
+
 	if (tb[TCA_BASIC_EMATCHES])
 		print_ematch(f, tb[TCA_BASIC_EMATCHES]);
 
Signature · 1 line
2.20.1
#1 lore raw

tc/f_basic.c static int basic_print_opt(struct filter_util *qu, FILE *f, · line 132

Quoted 4 lines · On Tue, 22 Jan 2019 22:41:45 -0800 Cong Wang <[email protected]> wrote:
tc/f_basic.c +4 -0
+	if (tb[TCA_BASIC_PCNT]) {
+		if (RTA_PAYLOAD(tb[TCA_BASIC_PCNT])  < sizeof(*pf)) {
+			fprintf(f, "Broken perf counters\n");
+			return -1;

Errors should go to stderr not f (which is stdout).

author
#2 lore raw
Quoted 10 lines · Stephen Hemminger

tc/f_basic.c static int basic_print_opt(struct filter_util *qu, FILE *f, · line 132

Quoted 4 lines · On Tue, 22 Jan 2019 22:41:45 -0800 Cong Wang <[email protected]> wrote:
tc/f_basic.c +4 -0
+     if (tb[TCA_BASIC_PCNT]) {
+             if (RTA_PAYLOAD(tb[TCA_BASIC_PCNT])  < sizeof(*pf)) {
+                     fprintf(f, "Broken perf counters\n");
+                     return -1;

Errors should go to stderr not f (which is stdout).

Ok, I copy the code from u32 filter, so it has the same issue.