naccyde / rpms / iproute

Forked from rpms/iproute 5 months ago
Clone

Blame SOURCES/0036-tc_util-Add-support-for-showing-TCA_STATS_BASIC_HW-s.patch

7e752c
From 1610b7b240601085ea42848e8d86469a091e560c Mon Sep 17 00:00:00 2001
7e752c
From: Phil Sutter <psutter@redhat.com>
7e752c
Date: Thu, 25 Oct 2018 17:01:52 +0200
7e752c
Subject: [PATCH] tc_util: Add support for showing TCA_STATS_BASIC_HW
7e752c
 statistics
7e752c
7e752c
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1637440
7e752c
Upstream Status: iproute2.git commit 5ac138324e31c
7e752c
7e752c
commit 5ac138324e31c75edc65c69cedcf699fb624c113
7e752c
Author: Eelco Chaudron <echaudro@redhat.com>
7e752c
Date:   Tue Oct 2 03:27:18 2018 -0400
7e752c
7e752c
    tc_util: Add support for showing TCA_STATS_BASIC_HW statistics
7e752c
7e752c
    Add support for showing hardware specific counters to easy
7e752c
    troubleshooting hardware offload.
7e752c
7e752c
    $ tc -s filter show dev enp3s0np0 parent ffff:
7e752c
    filter protocol ip pref 1 flower chain 0
7e752c
    filter protocol ip pref 1 flower chain 0 handle 0x1
7e752c
      eth_type ipv4
7e752c
      dst_ip 2.0.0.0
7e752c
      src_ip 1.0.0.0
7e752c
      ip_flags nofrag
7e752c
      in_hw
7e752c
            action order 1: mirred (Egress Redirect to device eth1) stolen
7e752c
            index 1 ref 1 bind 1 installed 0 sec used 0 sec
7e752c
            Action statistics:
7e752c
            Sent 534884742 bytes 8915697 pkt (dropped 0, overlimits 0 requeues 0)
7e752c
            Sent software 187542 bytes 4077 pkt
7e752c
            Sent hardware 534697200 bytes 8911620 pkt
7e752c
            backlog 0b 0p requeues 0
7e752c
            cookie 89173e6a44447001becfd486bda17e29
7e752c
7e752c
    Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
7e752c
    Signed-off-by: David Ahern <dsahern@gmail.com>
7e752c
---
7e752c
 tc/tc_util.c | 41 +++++++++++++++++++++++++++++++++++++++++
7e752c
 1 file changed, 41 insertions(+)
7e752c
7e752c
diff --git a/tc/tc_util.c b/tc/tc_util.c
7e752c
index d757852..5a1bbf2 100644
7e752c
--- a/tc/tc_util.c
7e752c
+++ b/tc/tc_util.c
7e752c
@@ -800,6 +800,44 @@ void print_tm(FILE *f, const struct tcf_t *tm)
7e752c
 	}
7e752c
 }
7e752c
 
7e752c
+static void print_tcstats_basic_hw(struct rtattr **tbs, char *prefix)
7e752c
+{
7e752c
+	struct gnet_stats_basic bs_hw;
7e752c
+
7e752c
+	if (!tbs[TCA_STATS_BASIC_HW])
7e752c
+		return;
7e752c
+
7e752c
+	memcpy(&bs_hw, RTA_DATA(tbs[TCA_STATS_BASIC_HW]),
7e752c
+	       MIN(RTA_PAYLOAD(tbs[TCA_STATS_BASIC_HW]), sizeof(bs_hw)));
7e752c
+
7e752c
+	if (bs_hw.bytes == 0 && bs_hw.packets == 0)
7e752c
+		return;
7e752c
+
7e752c
+	if (tbs[TCA_STATS_BASIC]) {
7e752c
+		struct gnet_stats_basic bs;
7e752c
+
7e752c
+		memcpy(&bs, RTA_DATA(tbs[TCA_STATS_BASIC]),
7e752c
+		       MIN(RTA_PAYLOAD(tbs[TCA_STATS_BASIC]),
7e752c
+			   sizeof(bs)));
7e752c
+
7e752c
+		if (bs.bytes >= bs_hw.bytes && bs.packets >= bs_hw.packets) {
7e752c
+			print_string(PRINT_FP, NULL, "%s", _SL_);
7e752c
+			print_string(PRINT_FP, NULL, "%s", prefix);
7e752c
+			print_lluint(PRINT_ANY, "sw_bytes",
7e752c
+				     "Sent software %llu bytes",
7e752c
+				     bs.bytes - bs_hw.bytes);
7e752c
+			print_uint(PRINT_ANY, "sw_packets", " %u pkt",
7e752c
+				   bs.packets - bs_hw.packets);
7e752c
+		}
7e752c
+	}
7e752c
+
7e752c
+	print_string(PRINT_FP, NULL, "%s", _SL_);
7e752c
+	print_string(PRINT_FP, NULL, "%s", prefix);
7e752c
+	print_lluint(PRINT_ANY, "hw_bytes", "Sent hardware %llu bytes",
7e752c
+		     bs_hw.bytes);
7e752c
+	print_uint(PRINT_ANY, "hw_packets", " %u pkt", bs_hw.packets);
7e752c
+}
7e752c
+
7e752c
 void print_tcstats2_attr(FILE *fp, struct rtattr *rta, char *prefix, struct rtattr **xstats)
7e752c
 {
7e752c
 	SPRINT_BUF(b1);
7e752c
@@ -826,6 +864,9 @@ void print_tcstats2_attr(FILE *fp, struct rtattr *rta, char *prefix, struct rtat
7e752c
 		print_uint(PRINT_ANY, "requeues", " requeues %u) ", q.requeues);
7e752c
 	}
7e752c
 
7e752c
+	if (tbs[TCA_STATS_BASIC_HW])
7e752c
+		print_tcstats_basic_hw(tbs, prefix);
7e752c
+
7e752c
 	if (tbs[TCA_STATS_RATE_EST64]) {
7e752c
 		struct gnet_stats_rate_est64 re = {0};
7e752c
 
7e752c
-- 
7e752c
1.8.3.1
7e752c