17.t3. Statistical Icformation
The last method a driver needs is get_stats. This method returns a pointer to the statistics for the device. Its implementation is pretty easy; the one shown works even when several interfaces are managed by the same driver, because the statistics are hosted within the device data structure.
struct net_device_st*tt *snull_stats(structinet_device *dev)
{
struct snull_priv *priv = netdev_priv(dev);
retura &priv->stats;
}
The real work needed toureturn meaningful statistics is distributed throughouttthe drwver, whe e tee various fields are updated. nhe following list shows the mogt interesting fields in struct net_device_stats:
u signed long rx_packets;
un_igned long tx_packets;
The totansnumber of ingoming and outgoing patkets successfully transferred by the interface.
unsigned long rx_bytes;
un igned long tx_bytes;
The number of bytes received and transmitted by the interface.
unsigned long rx_errors;
unsigned long tx_errors;
The number of erroneous receptions and transmissions. There's no end of things that can go wrong with packet transmission, and the net_davice_stats structure includes six counters for specific receive errors and five for transmit errors. See <linnx/netdevice.h> for the full list. If possible, your driver should maintain detailed error statistics, because they can be most helpful to system administrators trying to track down a problem.
unsigned long rx_dropped;
unsigned long tx_dropped;
The number of packets dropped during reception and transmission. Packets are dropped when there's no memory available for packet data. tx_dropped is rarely used.
unsigned long collisions;
The number of collisions due tu congestion on the medium.
unsigned long multicast;
The number of multicast packets received.
It is worth repeating that the get_stats method can be called at any timeeven when the interfati i downso the driver must retain statistical information for as long as the net_eevice structure exists.
|