diff options
author | Gabor Juhos <juhosg@openwrt.org> | 2010-01-08 20:22:55 +0000 |
---|---|---|
committer | Gabor Juhos <juhosg@openwrt.org> | 2010-01-08 20:22:55 +0000 |
commit | d8ace8978a02ab24f74559c525475c7915eac74f (patch) | |
tree | f2d8ffce5cfe443b7d19ef2a76a6d7dd41fd5d76 /target/linux | |
parent | afb9aa89b60c10e1872941bf2e909614acaf2a51 (diff) | |
download | mtk-20170518-d8ace8978a02ab24f74559c525475c7915eac74f.zip mtk-20170518-d8ace8978a02ab24f74559c525475c7915eac74f.tar.gz mtk-20170518-d8ace8978a02ab24f74559c525475c7915eac74f.tar.bz2 |
ar71xx: add NAPI statistics to the ag71xx driver
SVN-Revision: 19079
Diffstat (limited to 'target/linux')
3 files changed, 114 insertions, 13 deletions
diff --git a/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx.h b/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx.h index ef135ef..139fc94 100644 --- a/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx.h +++ b/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx.h @@ -119,10 +119,26 @@ struct ag71xx_int_stats { unsigned long total; }; +struct ag71xx_napi_stats { + unsigned long napi_calls; + unsigned long rx_count; + unsigned long rx_packets; + unsigned long rx_packets_max; + unsigned long tx_count; + unsigned long tx_packets; + unsigned long tx_packets_max; + + unsigned long rx[AG71XX_NAPI_WEIGHT + 1]; + unsigned long tx[AG71XX_NAPI_WEIGHT + 1]; +}; + struct ag71xx_debug { struct dentry *debugfs_dir; struct dentry *debugfs_int_stats; + struct dentry *debugfs_napi_stats; + struct ag71xx_int_stats int_stats; + struct ag71xx_napi_stats napi_stats; }; struct ag71xx { @@ -476,13 +492,16 @@ void ag71xx_debugfs_root_exit(void); int ag71xx_debugfs_init(struct ag71xx *ag); void ag71xx_debugfs_exit(struct ag71xx *ag); void ag71xx_debugfs_update_int_stats(struct ag71xx *ag, u32 status); +void ag71xx_debugfs_update_napi_stats(struct ag71xx *ag, int rx, int tx); #else static inline int ag71xx_debugfs_root_init(void) { return 0; } static inline void ag71xx_debugfs_root_exit(void) {} static inline int ag71xx_debugfs_init(struct ag71xx *ag) { return 0; } static inline void ag71xx_debugfs_exit(struct ag71xx *ag) {} static inline void ag71xx_debugfs_update_int_stats(struct ag71xx *ag, - u32 status) {} + u32 status) {} +static inline void ag71xx_debugfs_update_napi_stats(struct ag71xx *ag, + int rx, int tx) {} #endif /* CONFIG_AG71XX_DEBUG_FS */ #endif /* _AG71XX_H */ diff --git a/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_debugfs.c b/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_debugfs.c index 83bd4b0..c37265e 100644 --- a/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_debugfs.c +++ b/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_debugfs.c @@ -71,8 +71,77 @@ static const struct file_operations ag71xx_fops_int_stats = { .owner = THIS_MODULE }; +void ag71xx_debugfs_update_napi_stats(struct ag71xx *ag, int rx, int tx) +{ + struct ag71xx_napi_stats *stats = &ag->debug.napi_stats; + + if (rx) { + stats->rx_count++; + stats->rx_packets += rx; + if (rx <= AG71XX_NAPI_WEIGHT) + stats->rx[rx]++; + if (rx > stats->rx_packets_max) + stats->rx_packets_max = rx; + } + + if (tx) { + stats->tx_count++; + stats->tx_packets += tx; + if (tx <= AG71XX_NAPI_WEIGHT) + stats->tx[tx]++; + if (tx > stats->tx_packets_max) + stats->tx_packets_max = tx; + } +} + +static ssize_t read_file_napi_stats(struct file *file, char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct ag71xx *ag = file->private_data; + struct ag71xx_napi_stats *stats = &ag->debug.napi_stats; + char buf[2048]; + unsigned int len = 0; + unsigned long rx_avg = 0; + unsigned long tx_avg = 0; + int i; + + if (stats->rx_count) + rx_avg = stats->rx_packets / stats->rx_count; + + if (stats->tx_count) + tx_avg = stats->tx_packets / stats->tx_count; + + len += snprintf(buf + len, sizeof(buf) - len, "%3s %10s %10s\n", + "len", "rx", "tx"); + + for (i = 1; i <= AG71XX_NAPI_WEIGHT; i++) + len += snprintf(buf + len, sizeof(buf) - len, + "%3d: %10lu %10lu\n", + i, stats->rx[i], stats->tx[i]); + + len += snprintf(buf + len, sizeof(buf) - len, "\n"); + + len += snprintf(buf + len, sizeof(buf) - len, "%3s: %10lu %10lu\n", + "sum", stats->rx_count, stats->tx_count); + len += snprintf(buf + len, sizeof(buf) - len, "%3s: %10lu %10lu\n", + "avg", rx_avg, tx_avg); + len += snprintf(buf + len, sizeof(buf) - len, "%3s: %10lu %10lu\n", + "max", stats->rx_packets_max, stats->tx_packets_max); + len += snprintf(buf + len, sizeof(buf) - len, "%3s: %10lu %10lu\n", + "pkt", stats->rx_packets, stats->tx_packets); + + return simple_read_from_buffer(user_buf, count, ppos, buf, len); +} + +static const struct file_operations ag71xx_fops_napi_stats = { + .open = ag71xx_debugfs_generic_open, + .read = read_file_napi_stats, + .owner = THIS_MODULE +}; + void ag71xx_debugfs_exit(struct ag71xx *ag) { + debugfs_remove(ag->debug.debugfs_napi_stats); debugfs_remove(ag->debug.debugfs_int_stats); debugfs_remove(ag->debug.debugfs_dir); } @@ -93,6 +162,15 @@ int ag71xx_debugfs_init(struct ag71xx *ag) if (!ag->debug.debugfs_int_stats) goto err; + ag->debug.debugfs_napi_stats = + debugfs_create_file("napi_stats", + S_IRUGO, + ag->debug.debugfs_dir, + ag, + &ag71xx_fops_napi_stats); + if (!ag->debug.debugfs_napi_stats) + goto err; + return 0; err: diff --git a/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_main.c b/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_main.c index 97a677c..884366f 100644 --- a/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_main.c +++ b/target/linux/ar71xx/files/drivers/net/ag71xx/ag71xx_main.c @@ -608,10 +608,10 @@ static void ag71xx_restart_work_func(struct work_struct *work) ag71xx_open(ag->dev); } -static void ag71xx_tx_packets(struct ag71xx *ag) +static int ag71xx_tx_packets(struct ag71xx *ag) { struct ag71xx_ring *ring = &ag->tx_ring; - unsigned int sent; + int sent; DBG("%s: processing TX ring\n", ag->dev->name); @@ -641,6 +641,7 @@ static void ag71xx_tx_packets(struct ag71xx *ag) if ((ring->curr - ring->dirty) < AG71XX_TX_THRES_WAKEUP) netif_wake_queue(ag->dev); + return sent; } static int ag71xx_rx_packets(struct ag71xx *ag, int limit) @@ -711,13 +712,16 @@ static int ag71xx_poll(struct napi_struct *napi, int limit) struct ag71xx_ring *rx_ring; unsigned long flags; u32 status; - int done; + int tx_done; + int rx_done; pdata->ddr_flush(); - ag71xx_tx_packets(ag); + tx_done = ag71xx_tx_packets(ag); DBG("%s: processing RX ring\n", dev->name); - done = ag71xx_rx_packets(ag, limit); + rx_done = ag71xx_rx_packets(ag, limit); + + ag71xx_debugfs_update_napi_stats(ag, rx_done, tx_done); rx_ring = &ag->rx_ring; if (rx_ring->buf[rx_ring->dirty % AG71XX_RX_RING_SIZE].skb == NULL) @@ -732,7 +736,7 @@ static int ag71xx_poll(struct napi_struct *napi, int limit) ag71xx_wr(ag, AG71XX_REG_RX_CTRL, RX_CTRL_RXE); } - if (done < limit) { + if (rx_done < limit) { if (status & RX_STATUS_PR) goto more; @@ -740,8 +744,8 @@ static int ag71xx_poll(struct napi_struct *napi, int limit) if (status & TX_STATUS_PS) goto more; - DBG("%s: disable polling mode, done=%d, limit=%d\n", - dev->name, done, limit); + DBG("%s: disable polling mode, rx=%d, tx=%d,limit=%d\n", + dev->name, rx_done, tx_done, limit); napi_complete(napi); @@ -749,13 +753,13 @@ static int ag71xx_poll(struct napi_struct *napi, int limit) spin_lock_irqsave(&ag->lock, flags); ag71xx_int_enable(ag, AG71XX_INT_POLL); spin_unlock_irqrestore(&ag->lock, flags); - return done; + return rx_done; } more: - DBG("%s: stay in polling mode, done=%d, limit=%d\n", - dev->name, done, limit); - return done; + DBG("%s: stay in polling mode, rx=%d, tx=%d, limit=%d\n", + dev->name, rx_done, tx_done, limit); + return rx_done; oom: if (netif_msg_rx_err(ag)) |