Skip to content

Commit

Permalink
netfront: Introduce TX statistics interface
Browse files Browse the repository at this point in the history
  • Loading branch information
skuenzer committed Mar 8, 2017
1 parent d81d6bf commit cc41f44
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/netfront.h
Expand Up @@ -54,3 +54,8 @@ void networking_set_addr(struct ip_addr *ipaddr, struct ip_addr *netmask, struct
#ifdef CONFIG_SELECT_POLL
int netfront_get_fd(struct netfront_dev *dev);
#endif

#ifdef CONFIG_NETFRONT_STATS
void netfront_reset_txcounters(struct netfront_dev *dev);
void netfront_get_txcounters(struct netfront_dev *dev, uint64_t *out_txpkts, uint64_t *out_txbytes);
#endif
32 changes: 32 additions & 0 deletions netfront.c
Expand Up @@ -168,6 +168,11 @@ struct netfront_dev {
#endif
void (*netif_rx)(unsigned char* data, int len, void *arg);
void *netif_rx_arg;

#ifdef CONFIG_NETFRONT_STATS
uint64_t txpkts;
uint64_t txbytes;
#endif
};

struct netfront_dev_list {
Expand Down Expand Up @@ -934,6 +939,10 @@ void netfront_xmit(struct netfront_dev *dev, unsigned char *data, int len)
tx->flags |= (NETTXF_data_validated);
tx->size = len;

#ifdef CONFIG_NETFRONT_STATS
++dev->txpkts;
dev->txbytes += len;
#endif
netfront_xmit_notify(dev);
dprintk("tx: raw %d\n", len);

Expand Down Expand Up @@ -1207,6 +1216,10 @@ err_t netfront_xmit_pbuf(struct netfront_dev *dev, struct pbuf *p, int co_type,
if (push)
netfront_xmit_push(dev);

#ifdef CONFIG_NETFRONT_STATS
++dev->txpkts;
dev->txbytes += p->tot_len;
#endif
dprintk("tx: %c%c%c %u bytes (%u slots)\n", sego ? 'S' : '-', co_type ? 'C' : '-', push ? 'P' : '-', p->tot_len, slots);
return ERR_OK;
}
Expand Down Expand Up @@ -1688,6 +1701,9 @@ static struct netfront_dev *_init_netfront(struct netfront_dev *dev,
#ifdef CONFIG_SELECT_POLL
dev->fd = alloc_fd(FTYPE_TAP);
files[dev->fd].read = 0;
#endif
#ifdef CONFIG_NETFRONT_STATS
netfront_reset_txcounters(dev);
#endif
return dev;
error:
Expand Down Expand Up @@ -1859,3 +1875,19 @@ int netfront_get_fd(struct netfront_dev *dev)
return dev->fd;
}
#endif

#ifdef CONFIG_NETFRONT_STATS
void netfront_reset_txcounters(struct netfront_dev *dev)
{
dev->txpkts = 0;
dev->txbytes = 0;
}

void netfront_get_txcounters(struct netfront_dev *dev, uint64_t *out_txpkts, uint64_t *out_txbytes)
{
if (likely(out_txpkts))
*out_txpkts = dev->txpkts;
if (likely(out_txbytes))
*out_txbytes = dev->txbytes;
}
#endif
2 changes: 2 additions & 0 deletions stub.mk
Expand Up @@ -126,6 +126,7 @@ CONFIG_TPMBACK ?= n
CONFIG_NETMAP ?= n
CONFIG_NETMAP_API ?= 10
CONFIG_NETFRONT ?= y
CONFIG_NETFRONT_STATS ?= n
CONFIG_NETFRONT_POLL ?= n
CONFIG_NETFRONT_POLLTIMEOUT ?= 10000 # usecs
CONFIG_SELECT_POLL ?= n
Expand Down Expand Up @@ -193,6 +194,7 @@ MINIOS_OPT_FLAGS-$(CONFIG_SPARSE_BSS) += -DCONFIG_SPARSE_BSS
MINIOS_OPT_FLAGS-$(CONFIG_QEMU_XS_ARGS) += -DCONFIG_QEMU_XS_ARGS
MINIOS_OPT_FLAGS-$(CONFIG_PCIFRONT) += -DCONFIG_PCIFRONT
MINIOS_OPT_FLAGS-$(CONFIG_NETFRONT) += -DCONFIG_NETFRONT
MINIOS_OPT_FLAGS-$(CONFIG_NETFRONT_STATS) += -DCONFIG_NETFRONT_STATS
MINIOS_OPT_FLAGS-$(CONFIG_NETFRONT_GSO) += -DCONFIG_NETFRONT_GSO
MINIOS_OPT_FLAGS-$(CONFIG_NETFRONT_PERSISTENT_GRANTS) += -DCONFIG_NETFRONT_PERSISTENT_GRANTS
MINIOS_OPT_FLAGS-$(CONFIG_NETFRONT_WAITFORTX) += -DCONFIG_NETFRONT_WAITFORTX
Expand Down

0 comments on commit cc41f44

Please sign in to comment.