]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ipstats: Add a group "offload", subgroup "cpu_hit"
authorPetr Machata <petrm@nvidia.com>
Fri, 22 Apr 2022 08:30:56 +0000 (10:30 +0200)
committerDavid Ahern <dsahern@kernel.org>
Thu, 28 Apr 2022 02:12:42 +0000 (20:12 -0600)
Add a new group, "offload", for showing counters from the
IFLA_STATS_LINK_OFFLOAD_XSTATS nest, and a subgroup "cpu_hit" for the
IFLA_OFFLOAD_XSTATS_CPU_HIT stats suite.

For example:

 # ip stats show dev swp1 group offload subgroup cpu_hit
 4178: swp1: group offload subgroup cpu_hit
     RX:  bytes packets errors dropped  missed   mcast
          45522     353      0       0       0       0
     TX:  bytes packets errors dropped carrier collsns
          46054     355      0       0       0       0

 # ip -j stats show dev swp1 group offload subgroup cpu_hit | jq
 [
   {
     "ifindex": 4178,
     "ifname": "swp1",
     "group": "offload",
     "subgroup": "cpu_hit",
     "stats64": {
       "rx": {
         "bytes": 45522,
         "packets": 353,
         "errors": 0,
         "dropped": 0,
         "over_errors": 0,
         "multicast": 0
       },
       "tx": {
         "bytes": 46054,
         "packets": 355,
         "errors": 0,
         "dropped": 0,
         "carrier_errors": 0,
         "collisions": 0
       }
     }
   }
 ]

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
ip/ipstats.c

index e4f97dddde980e9b99a361eea248933332b53d25..283fba4e1a526b8055b1d40127eef6eb4e9038d1 100644 (file)
@@ -164,6 +164,42 @@ static int ipstats_show_64(struct ipstats_stat_show_attrs *attrs,
        return 0;
 }
 
+static void
+ipstats_stat_desc_pack_cpu_hit(struct ipstats_stat_dump_filters *filters,
+                              const struct ipstats_stat_desc *desc)
+{
+       ipstats_stat_desc_enable_bit(filters,
+                                    IFLA_STATS_LINK_OFFLOAD_XSTATS,
+                                    IFLA_OFFLOAD_XSTATS_CPU_HIT);
+}
+
+static int ipstats_stat_desc_show_cpu_hit(struct ipstats_stat_show_attrs *attrs,
+                                         const struct ipstats_stat_desc *desc)
+{
+       print_nl();
+       return ipstats_show_64(attrs,
+                              IFLA_STATS_LINK_OFFLOAD_XSTATS,
+                              IFLA_OFFLOAD_XSTATS_CPU_HIT);
+}
+
+static const struct ipstats_stat_desc ipstats_stat_desc_offload_cpu_hit = {
+       .name = "cpu_hit",
+       .kind = IPSTATS_STAT_DESC_KIND_LEAF,
+       .pack = &ipstats_stat_desc_pack_cpu_hit,
+       .show = &ipstats_stat_desc_show_cpu_hit,
+};
+
+static const struct ipstats_stat_desc *ipstats_stat_desc_offload_subs[] = {
+       &ipstats_stat_desc_offload_cpu_hit,
+};
+
+static const struct ipstats_stat_desc ipstats_stat_desc_offload_group = {
+       .name = "offload",
+       .kind = IPSTATS_STAT_DESC_KIND_GROUP,
+       .subs = ipstats_stat_desc_offload_subs,
+       .nsubs = ARRAY_SIZE(ipstats_stat_desc_offload_subs),
+};
+
 static void
 ipstats_stat_desc_pack_link(struct ipstats_stat_dump_filters *filters,
                            const struct ipstats_stat_desc *desc)
@@ -189,6 +225,7 @@ static const struct ipstats_stat_desc ipstats_stat_desc_toplev_link = {
 
 static const struct ipstats_stat_desc *ipstats_stat_desc_toplev_subs[] = {
        &ipstats_stat_desc_toplev_link,
+       &ipstats_stat_desc_offload_group,
 };
 
 static const struct ipstats_stat_desc ipstats_stat_desc_toplev_group = {