2010-05-15 3 views

답변

4

모든 네트워크 드라이버에는 이러한 기능을위한 "ethtool"구현이 있습니다. 하지만 일반적인 netdev 구조체의 속도를 줄 수있는 제네릭 함수가 필요할 것입니다. net/core/net-sysfs.c을보고 어떻게/sys/class/net 인터페이스를 구현하는지보십시오. 예 :

static ssize_t show_speed(struct device *dev, 
      struct device_attribute *attr, char *buf) 
{ 
    struct net_device *netdev = to_net_dev(dev); 
    int ret = -EINVAL; 

    if (!rtnl_trylock()) 
     return restart_syscall(); 

    if (netif_running(netdev) && 
     netdev->ethtool_ops && 
     netdev->ethtool_ops->get_settings) { 
     struct ethtool_cmd cmd = { ETHTOOL_GSET }; 

     if (!netdev->ethtool_ops->get_settings(netdev, &cmd)) 
      ret = sprintf(buf, fmt_dec, ethtool_cmd_speed(&cmd)); 
    } 
    rtnl_unlock(); 
    return ret; 
} 
관련 문제