Net device error logging
Subsystems (2)
PATCH 1/1 Net device error logging
The enclosed patch implements the netdev_* error-logging macros for network drivers. These macros have been discussed at length on the linux-kernel and linux-netdev lists. With the v2.6.0-test6 version of these macros, we addressed all the issues that reviewers had raised. This is just an update for v2.6.0-test11.
As previously discussed, these macros are in demand now (e.g., for the e1000 driver) and have essentially no impact on drivers that don't use them.
RECAP (from previous posts):
Calls to the netdev_* macros (netdev_printk and wrappers such as netdev_err) are intended to replace calls to printk in network device drivers. These macros have the following characteristics:
- Same format + args as the corresponding printk call.
- Approximately the same amount of text as the corresponding printk call.
- The first arg is a pointer to the net_device struct.
- The second arg, which is a NETIF_MSG_* message level, can be used to implement verbosity control.
- Standard message prefixes: verbose (interface name, driver name, bus ID) during probe, or just the interface name once the device is registered.
- The current implementation just calls printk. However, the netdev_* interface (and availability of the net_device pointer) opens the door for logging additional information (via printk, via evlog/netlink, etc.) as desired, with no change to driver code.
Examples:
netdev_err(netdev, RX_ERR, "No mem: dropped packet\n");
logs a message such as the following if the NETIF_MSG_RX_ERR bit is set in netdev->msg_enable.
eth2: No mem: dropped packet
netdev_fatal(netdev, PROBE, "The EEPROM Checksum Is Not Valid\n");
or
netdev_err(netdev, ALL, "The EEPROM Checksum Is Not Valid\n");
unconditionally logs a message such as:
eth%d (e1000 0000:00:03.0): The EEPROM Checksum Is Not ValidThe message's prefix includes the driver name and bus ID because the message is logged at probe time, before netdev is registered.
SAMPLE DRIVERS
As examples of how the netdev_* macros could be used, patches for the v2.6.0-test11 e100, e1000, and tg3 drivers are available on request.
LINUX v2.4 SUPPORT
Since there is no v2.6-style struct device underlying the net_device, a v2.4.23-compatible version of netdev_printk would always log the interface name as the message prefix:
#define netdev_printk(sevlevel, netdev, msglevel, format, arg...) \
do { \
if (NETIF_MSG_##msglevel == NETIF_MSG_ALL \
|| (netdev->msg_enable & NETIF_MSG_##msglevel)) { \
printk(sevlevel "%s: " format , netdev->name , ## arg); \
} \
} while (0)Jim Keniston
IBM Linux Technology Center
include/linux/netdevice.h +39 -0
@@ -467,6 +467,9 @@struct divert_blk *divert;#endif /* CONFIG_NET_DIVERT */ +/* NETIF_MSG_* flags to control the types of events we log */ +int msg_enable; +/* class/net/name entry */ struct class_device class_dev;struct net_device_stats * (*last_stats)(struct net_device *);
@@ -749,6 +752,7 @@NETIF_MSG_PKTDATA =0x1000 ,NETIF_MSG_HW =0x2000 ,NETIF_MSG_WOL =0x4000 , + NETIF_MSG_ALL = -1, /* always log message */ };#define netif_msg_drv (p) ((p)->msg_enable & NETIF_MSG_DRV)
@@ -910,6 +914,41 @@#ifdef CONFIG_SYSCTL extern char *net_sysctl_strdup (const char *s);#endif + +/* debugging and troubleshooting/diagnostic helpers. */ +/** +* netdev_printk() - Log message with interface name, gated by message level +* @sevlevel: severity level -- e.g., KERN_INFO +* @netdev: net_device pointer +* @msglevel: a standard message-level flag with the NETIF_MSG_ prefix removed. +* Unless msglevel is ALL, log the message only if that flag is set in +* netdev->msg_enable. +* @format: as with printk +* @args: as with printk +*/ +extern int __netdev_printk (const char *sevlevel, +const struct net_device *netdev,int msglevel,const char *format, ...); +#define netdev_printk(sevlevel, netdev, msglevel, format, arg...) \ + __netdev_printk(sevlevel , netdev , NETIF_MSG_##msglevel , \ + format , ## arg) + +#ifdef DEBUG +#define netdev_dbg(netdev, msglevel, format, arg...) \ + netdev_printk(KERN_DEBUG , netdev , msglevel , format , ## arg) +#else +#define netdev_dbg(netdev, msglevel, format, arg...) do {} while (0) +#endif + +#define netdev_err(netdev, msglevel, format, arg...) \ + netdev_printk(KERN_ERR , netdev , msglevel , format , ## arg) +#define netdev_info(netdev, msglevel, format, arg...) \ + netdev_printk(KERN_INFO , netdev , msglevel , format , ## arg) +#define netdev_warn(netdev, msglevel, format, arg...) \ + netdev_printk(KERN_WARNING , netdev , msglevel , format , ## arg) + +/* report fatal error unconditionally; msglevel ignored for now */ +#define netdev_fatal(netdev, msglevel, format, arg...) \ + netdev_printk(KERN_ERR , netdev , ALL , format , ## arg)#endif /* __KERNEL__ */
net/core/dev.c +73 -0
79 lines not on this page · raw message
Quoted 49 lines · Jim Keniston
The enclosed patch implements the netdev_* error-logging macros for network drivers. These macros have been discussed at length on the linux-kernel and linux-netdev lists. With the v2.6.0-test6 version of these macros, we addressed all the issues that reviewers had raised. This is just an update for v2.6.0-test11.
As previously discussed, these macros are in demand now (e.g., for the e1000 driver) and have essentially no impact on drivers that don't use them.
RECAP (from previous posts):
Calls to the netdev_* macros (netdev_printkand wrappers such asnetdev_err) are intended to replace calls to printk in network device drivers. These macros have the following characteristics:
- Same format + args as the corresponding printk call.
- Approximately the same amount of text as the corresponding printk call.
- The first arg is a pointer to thenet_devicestruct.
- The second arg, which is a NETIF_MSG_* message level, can be used to implement verbosity control.
- Standard message prefixes: verbose (interface name, driver name, bus ID) during probe, or just the interface name once the device is registered.
- The current implementation just calls printk. However, the netdev_* interface (and availability of thenet_devicepointer) opens the door for logging additional information (via printk, via evlog/netlink, etc.) as desired, with no change to driver code.Examples:
netdev_err(netdev, RX_ERR, "No mem: dropped packet\n");logs a message such as the following if the
NETIF_MSG_RX_ERRbit is set innetdev->msg_enable.
eth2: No mem: dropped packet
netdev_fatal(netdev, PROBE, "The EEPROM Checksum Is Not Valid\n");
ornetdev_err(netdev, ALL, "The EEPROM Checksum Is Not Valid\n"); unconditionally logs a message such as: eth%d (e1000 0000:00:03.0): The EEPROM Checksum Is Not ValidThe message's prefix includes the driver name and bus ID because the message is logged at probe time, before netdev is registered.
SAMPLE DRIVERS
As examples of how the netdev_* macros could be used, patches for the v2.6.0-test11 e100, e1000, and tg3 drivers are available on request.LINUX v2.4 SUPPORT
Since there is no v2.6-style struct device underlying thenet_device, a v2.4.23-compatible version ofnetdev_printkwould always log the interface name as the message prefix:
Quoted 7 lines
#define
netdev_printk(sevlevel, netdev, msglevel, format, arg...)\do { \ if (NETIF_MSG_##msglevel == NETIF_MSG_ALL \ || (netdev->msg_enable & NETIF_MSG_##msglevel)) { \ printk(sevlevel "%s: " format , netdev->name , ## arg); \ } \ } while (0)
I discussed this a bit with David. My personal feelings are that I prefer just leaving all the printk's as they are. But Linus and GregKH have been accepting patches into other parts of the tree like this one, and logging additional already-computer-parsed information is probably not a bad thing long-term, so perhaps I've been being a bit of a Luddite on this issue.
It's definitely too late for 2.6.0-testX mainline merging, until Andrew (2.6) and Linus (2.7) re-open their respective trees, but a good first step would be for me to merge this into the net-drivers-2.5-exp queue.
Jeff
Quoted 6 lines · Jeff Garzik
I discussed this a bit with David. My personal feelings are that I prefer just leaving all the printk's as they are. But Linus and GregKH have been accepting patches into other parts of the tree like this one, and logging additional already-computer-parsed information is probably not a bad thing long-term, so perhaps I've been being a bit of a Luddite on this issue.
To be fair, the patches I've taken (dev_err and friends) are _much_ simpler than these, so accepting them was not that big of a deal. It enabled the subsystems that have started to use them (USB and I2C) to log better messages (we now know exactly which device caused the errors, instead of just which driver).
So please judge this patch on its own, and feel no pressure due to the dev_*() calls :)
thanks,
greg k-h