From: Petr Machata Date: Fri, 22 Apr 2022 08:30:56 +0000 (+0200) Subject: ipstats: Add a group "offload", subgroup "cpu_hit" X-Git-Tag: v5.19.0~24^2~9^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af5e7955273e47ee40b83f0b04c1879fe7ad92ae;p=thirdparty%2Fiproute2.git ipstats: Add a group "offload", subgroup "cpu_hit" 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 Reviewed-by: Ido Schimmel Signed-off-by: David Ahern --- diff --git a/ip/ipstats.c b/ip/ipstats.c index e4f97dddd..283fba4e1 100644 --- a/ip/ipstats.c +++ b/ip/ipstats.c @@ -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 = {