X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fpalacios%2Fvmm_vnet_core.c;h=e0e0ac7448dc9e95896531abd1db863f3ec9cd8f;hb=dc6c877618496cea23e3350ab56ae30abf5165f4;hp=4ce9b04c8b8266529cdd3a8e93e6796b0d05a709;hpb=06577917122b2b412618525d0f36fbd2438e9bae;p=palacios.git diff --git a/palacios/src/palacios/vmm_vnet_core.c b/palacios/src/palacios/vmm_vnet_core.c index 4ce9b04..e0e0ac7 100644 --- a/palacios/src/palacios/vmm_vnet_core.c +++ b/palacios/src/palacios/vmm_vnet_core.c @@ -46,7 +46,9 @@ struct vnet_dev { void * private_data; int active; - uint8_t mode; //vmm_drivern or guest_drivern + + uint64_t bytes_tx, bytes_rx; + uint32_t pkts_tx, pkt_rx; struct list_head node; } __attribute__((packed)); @@ -57,7 +59,7 @@ struct vnet_brg_dev { struct v3_vnet_bridge_ops brg_ops; uint8_t type; - uint8_t mode; + int active; void * private_data; } __attribute__((packed)); @@ -90,9 +92,10 @@ static struct { int num_routes; int num_devs; - struct vnet_brg_dev *bridge; + struct vnet_brg_dev * bridge; v3_lock_t lock; + struct vnet_stat stats; struct hashtable * route_cache; } vnet_state; @@ -206,9 +209,6 @@ static struct vnet_dev * dev_by_mac(uint8_t * mac) { if (!compare_ethaddr(dev->mac_addr, mac)){ return dev; } - - char *dmac = dev->mac_addr; - PrintDebug("device %d: %2x:%2x:%2x:%2x:%2x:%2x\n", dev->dev_id, dmac[0], dmac[1], dmac[2], dmac[3], dmac[4], dmac[5]); } return NULL; @@ -218,8 +218,6 @@ static struct vnet_dev * dev_by_mac(uint8_t * mac) { int v3_vnet_find_dev(uint8_t * mac) { struct vnet_dev * dev = NULL; - PrintDebug("find_dev: %2x:%2x:%2x:%2x:%2x:%2x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - dev = dev_by_mac(mac); if(dev != NULL) { @@ -237,8 +235,10 @@ int v3_vnet_add_route(struct v3_vnet_route route) { new_route = (struct vnet_route_info *)V3_Malloc(sizeof(struct vnet_route_info)); memset(new_route, 0, sizeof(struct vnet_route_info)); +#ifdef CONFIG_DEBUG_VNET PrintDebug("VNET/P Core: add_route_entry:\n"); print_route(&route); +#endif memcpy(new_route->route_def.src_mac, route.src_mac, ETH_ALEN); memcpy(new_route->route_def.dst_mac, route.dst_mac, ETH_ALEN); @@ -306,8 +306,8 @@ static struct route_list * match_route(const struct v3_vnet_pkt * pkt) { int max_rank = 0; struct list_head match_list; struct eth_hdr * hdr = (struct eth_hdr *)(pkt->data); - // uint8_t src_type = pkt->src_type; - // uint32_t src_link = pkt->src_id; +// uint8_t src_type = pkt->src_type; + // uint32_t src_link = pkt->src_id; #ifdef CONFIG_DEBUG_VNET { @@ -436,12 +436,14 @@ int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void * private_data) { PrintDebug("VNET/P Core: cpu %d: pkt (size %d, src_id:%d, src_type: %d, dst_id: %d, dst_type: %d)\n", cpu, pkt->size, pkt->src_id, pkt->src_type, pkt->dst_id, pkt->dst_type); - //v3_hexdump(pkt->data, pkt->size, NULL, 0); } #endif flags = v3_lock_irqsave(vnet_state.lock); + vnet_state.stats.rx_bytes += pkt->size; + vnet_state.stats.rx_pkts++; + look_into_cache(pkt, &matched_routes); if (matched_routes == NULL) { PrintDebug("VNET/P Core: send pkt Looking into routing table\n"); @@ -478,6 +480,8 @@ int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void * private_data) { PrintDebug("VNET/P Core: Packet not sent properly to bridge\n"); continue; } + vnet_state.stats.tx_bytes += pkt->size; + vnet_state.stats.tx_pkts ++; } else if (route->route_def.dst_type == LINK_INTERFACE) { if (route->dst_dev == NULL || route->dst_dev->active == 0){ PrintDebug("VNET/P Core: No active device to sent data to\n"); @@ -488,6 +492,8 @@ int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void * private_data) { PrintDebug("VNET/P Core: Packet not sent properly\n"); continue; } + vnet_state.stats.tx_bytes += pkt->size; + vnet_state.stats.tx_pkts ++; } else { PrintError("VNET/P Core: Wrong dst type\n"); } @@ -516,7 +522,6 @@ int v3_vnet_add_dev(struct v3_vm_info * vm, uint8_t * mac, new_dev->vm = vm; new_dev->dev_id = 0; new_dev->active = 1; - new_dev->mode = GUEST_DRIVERN; flags = v3_lock_irqsave(vnet_state.lock); @@ -561,6 +566,15 @@ int v3_vnet_del_dev(int dev_id){ return 0; } +int v3_vnet_stat(struct vnet_stat * stats){ + + stats->rx_bytes = vnet_state.stats.rx_bytes; + stats->rx_pkts = vnet_state.stats.rx_pkts; + stats->tx_bytes = vnet_state.stats.tx_bytes; + stats->tx_pkts = vnet_state.stats.tx_pkts; + + return 0; +} static void free_devices(){ struct vnet_dev * dev = NULL; @@ -616,7 +630,6 @@ int v3_vnet_add_bridge(struct v3_vm_info * vm, tmp_bridge->brg_ops.poll = ops->poll; tmp_bridge->private_data = priv_data; tmp_bridge->active = 1; - tmp_bridge->mode = GUEST_DRIVERN; tmp_bridge->type = type; /* make this atomic to avoid possible race conditions */ @@ -628,6 +641,20 @@ int v3_vnet_add_bridge(struct v3_vm_info * vm, } +void v3_vnet_do_poll(struct v3_vm_info * vm){ + struct vnet_dev * dev = NULL; + + /* TODO: run this on separate threads + * round-robin schedule, with maximal budget for each poll + */ + list_for_each_entry(dev, &(vnet_state.devs), node) { + if(dev->dev_ops.poll != NULL){ + dev->dev_ops.poll(vm, -1, dev->private_data); + } + } +} + + int v3_init_vnet() { memset(&vnet_state, 0, sizeof(vnet_state));