David Ahern
2021-Nov-30 02:36 UTC
[PATCH v2 net-next 01/26] rtnetlink: introduce generic XDP statistics
On 11/23/21 9:39 AM, Alexander Lobakin wrote:> +static bool rtnl_get_xdp_stats_xdpxsk(struct sk_buff *skb, u32 ch, > + const void *attr_data) > +{ > + const struct ifla_xdp_stats *xstats = attr_data; > + > + xstats += ch; > + > + if (nla_put_u64_64bit(skb, IFLA_XDP_XSTATS_PACKETS, xstats->packets, > + IFLA_XDP_XSTATS_UNSPEC) || > + nla_put_u64_64bit(skb, IFLA_XDP_XSTATS_BYTES, xstats->bytes, > + IFLA_XDP_XSTATS_UNSPEC) || > + nla_put_u64_64bit(skb, IFLA_XDP_XSTATS_ERRORS, xstats->errors, > + IFLA_XDP_XSTATS_UNSPEC) || > + nla_put_u64_64bit(skb, IFLA_XDP_XSTATS_ABORTED, xstats->aborted, > + IFLA_XDP_XSTATS_UNSPEC) || > + nla_put_u64_64bit(skb, IFLA_XDP_XSTATS_DROP, xstats->drop, > + IFLA_XDP_XSTATS_UNSPEC) || > + nla_put_u64_64bit(skb, IFLA_XDP_XSTATS_INVALID, xstats->invalid, > + IFLA_XDP_XSTATS_UNSPEC) || > + nla_put_u64_64bit(skb, IFLA_XDP_XSTATS_PASS, xstats->pass, > + IFLA_XDP_XSTATS_UNSPEC) || > + nla_put_u64_64bit(skb, IFLA_XDP_XSTATS_REDIRECT, xstats->redirect, > + IFLA_XDP_XSTATS_UNSPEC) || > + nla_put_u64_64bit(skb, IFLA_XDP_XSTATS_REDIRECT_ERRORS, > + xstats->redirect_errors, > + IFLA_XDP_XSTATS_UNSPEC) || > + nla_put_u64_64bit(skb, IFLA_XDP_XSTATS_TX, xstats->tx, > + IFLA_XDP_XSTATS_UNSPEC) || > + nla_put_u64_64bit(skb, IFLA_XDP_XSTATS_TX_ERRORS, > + xstats->tx_errors, IFLA_XDP_XSTATS_UNSPEC) || > + nla_put_u64_64bit(skb, IFLA_XDP_XSTATS_XMIT_PACKETS, > + xstats->xmit_packets, IFLA_XDP_XSTATS_UNSPEC) || > + nla_put_u64_64bit(skb, IFLA_XDP_XSTATS_XMIT_BYTES, > + xstats->xmit_bytes, IFLA_XDP_XSTATS_UNSPEC) || > + nla_put_u64_64bit(skb, IFLA_XDP_XSTATS_XMIT_ERRORS, > + xstats->xmit_errors, IFLA_XDP_XSTATS_UNSPEC) || > + nla_put_u64_64bit(skb, IFLA_XDP_XSTATS_XMIT_FULL, > + xstats->xmit_full, IFLA_XDP_XSTATS_UNSPEC)) > + return false; > + > + return true; > +} > +Another thought on this patch: with individual attributes you could save some overhead by not sending 0 counters to userspace. e.g., define a helper that does: static inline int nla_put_u64_if_set(struct sk_buff *skb, int attrtype, u64 value, int padattr) { if (value) return nla_put_u64_64bit(skb, attrtype, value, padattr); return 0; }