|
4 | 4 |
|
5 | 5 | #include <linux/netdevice.h> |
6 | 6 |
|
| 7 | +/* See the netdev.yaml spec for definition of each statistic */ |
| 8 | +struct netdev_queue_stats_rx { |
| 9 | + u64 bytes; |
| 10 | + u64 packets; |
| 11 | + u64 alloc_fail; |
| 12 | +}; |
| 13 | + |
| 14 | +struct netdev_queue_stats_tx { |
| 15 | + u64 bytes; |
| 16 | + u64 packets; |
| 17 | +}; |
| 18 | + |
| 19 | +/** |
| 20 | + * struct netdev_stat_ops - netdev ops for fine grained stats |
| 21 | + * @get_queue_stats_rx: get stats for a given Rx queue |
| 22 | + * @get_queue_stats_tx: get stats for a given Tx queue |
| 23 | + * @get_base_stats: get base stats (not belonging to any live instance) |
| 24 | + * |
| 25 | + * Query stats for a given object. The values of the statistics are undefined |
| 26 | + * on entry (specifically they are *not* zero-initialized). Drivers should |
| 27 | + * assign values only to the statistics they collect. Statistics which are not |
| 28 | + * collected must be left undefined. |
| 29 | + * |
| 30 | + * Queue objects are not necessarily persistent, and only currently active |
| 31 | + * queues are queried by the per-queue callbacks. This means that per-queue |
| 32 | + * statistics will not generally add up to the total number of events for |
| 33 | + * the device. The @get_base_stats callback allows filling in the delta |
| 34 | + * between events for currently live queues and overall device history. |
| 35 | + * When the statistics for the entire device are queried, first @get_base_stats |
| 36 | + * is issued to collect the delta, and then a series of per-queue callbacks. |
| 37 | + * Only statistics which are set in @get_base_stats will be reported |
| 38 | + * at the device level, meaning that unlike in queue callbacks, setting |
| 39 | + * a statistic to zero in @get_base_stats is a legitimate thing to do. |
| 40 | + * This is because @get_base_stats has a second function of designating which |
| 41 | + * statistics are in fact correct for the entire device (e.g. when history |
| 42 | + * for some of the events is not maintained, and reliable "total" cannot |
| 43 | + * be provided). |
| 44 | + * |
| 45 | + * Device drivers can assume that when collecting total device stats, |
| 46 | + * the @get_base_stats and subsequent per-queue calls are performed |
| 47 | + * "atomically" (without releasing the rtnl_lock). |
| 48 | + * |
| 49 | + * Device drivers are encouraged to reset the per-queue statistics when |
| 50 | + * number of queues change. This is because the primary use case for |
| 51 | + * per-queue statistics is currently to detect traffic imbalance. |
| 52 | + */ |
| 53 | +struct netdev_stat_ops { |
| 54 | + void (*get_queue_stats_rx)(struct net_device *dev, int idx, |
| 55 | + struct netdev_queue_stats_rx *stats); |
| 56 | + void (*get_queue_stats_tx)(struct net_device *dev, int idx, |
| 57 | + struct netdev_queue_stats_tx *stats); |
| 58 | + void (*get_base_stats)(struct net_device *dev, |
| 59 | + struct netdev_queue_stats_rx *rx, |
| 60 | + struct netdev_queue_stats_tx *tx); |
| 61 | +}; |
| 62 | + |
7 | 63 | /** |
8 | 64 | * DOC: Lockless queue stopping / waking helpers. |
9 | 65 | * |
|
0 commit comments