X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Flnx_virtio_nic.c;h=8993066ba8f526c62ca0f179825fddfdd74aff00;hb=27eb2f39dd8e616c48f115c67ecca22f1c799b23;hp=c62670852a901f3f94e6f870309f734607131cc2;hpb=edd0131b7b8672c9c3a7ef8682d17a48d682a53f;p=palacios.git diff --git a/palacios/src/devices/lnx_virtio_nic.c b/palacios/src/devices/lnx_virtio_nic.c index c626708..8993066 100644 --- a/palacios/src/devices/lnx_virtio_nic.c +++ b/palacios/src/devices/lnx_virtio_nic.c @@ -82,6 +82,10 @@ struct virtio_net_state { ulong_t pkt_sent, pkt_recv, pkt_drop; +#if 1 //for temporary performance testing purpose + long last_sent_time, last_recv_time; +#endif + struct v3_dev_net_ops * net_ops; v3_lock_t lock; @@ -137,7 +141,7 @@ static int pkt_tx(struct guest_info *core, struct virtio_net_state * virtio, str PrintDebug("Virtio NIC: Virtio Pkt Sending, net_state: %p, pkt size: %d\n", virtio, len); - if (guest_pa_to_host_va(core, buf_desc->addr_gpa, (addr_t *)&(buf)) == -1) { + if (v3_gpa_to_hva(core, buf_desc->addr_gpa, (addr_t *)&(buf)) == -1) { PrintError("Could not translate buffer address\n"); return -1; } @@ -170,7 +174,7 @@ static int copy_data_to_desc(struct guest_info *core, uint32_t len; uint8_t * desc_buf = NULL; - if (guest_pa_to_host_va(core, desc->addr_gpa, (addr_t *)&(desc_buf)) == -1) { + if (v3_gpa_to_hva(core, desc->addr_gpa, (addr_t *)&(desc_buf)) == -1) { PrintError("Could not translate buffer address\n"); return -1; } @@ -204,6 +208,7 @@ static int handle_pkt_tx(struct guest_info *core, struct virtio_net_state * virt struct virtio_queue * q = &(virtio_state->tx_vq); struct virtio_net_hdr * hdr = NULL; + PrintDebug("Virtio NIC: TX: running on cpu: %d\n", V3_Get_CPU()); while (q->cur_avail_idx != q->avail->index) { struct vring_desc * hdr_desc = NULL; @@ -214,14 +219,14 @@ static int handle_pkt_tx(struct guest_info *core, struct virtio_net_state * virt int i = 0; hdr_desc = &(q->desc[desc_idx]); - if (guest_pa_to_host_va(core, hdr_desc->addr_gpa, &(hdr_addr)) == -1) { + if (v3_gpa_to_hva(core, hdr_desc->addr_gpa, &(hdr_addr)) == -1) { PrintError("Could not translate block header address\n"); return -1; } hdr = (struct virtio_net_hdr*)hdr_addr; desc_idx = hdr_desc->next; - + for (i = 0; i < desc_cnt - 1; i++) { struct vring_desc * buf_desc = &(q->desc[desc_idx]); if (pkt_tx(core, virtio_state, buf_desc) == -1) { @@ -246,6 +251,20 @@ static int handle_pkt_tx(struct guest_info *core, struct virtio_net_state * virt virtio_state->virtio_cfg.pci_isr = 0x1; } +#ifdef CONFIG_VNET_PROFILE + if (virtio_state->pkt_sent % 50000 == 0){ + long cur_time, time; + rdtscll(cur_time); + time = cur_time - virtio_state->last_sent_time; + PrintError("Virtio NIC: last sent 50000 cycles: %ld\n",time); + //PrintError("Virtio NIC: sent: %ld, rxed: %ld, dropped: %ld\n", + // virtio_state->pkt_sent, + // virtio_state->pkt_recv, + // virtio_state->pkt_drop); + rdtscll(virtio_state->last_sent_time); + } +#endif + return 0; } @@ -265,17 +284,17 @@ static int virtio_setup_queue(struct guest_info *core, // round up to next page boundary. queue->ring_used_addr = (queue->ring_used_addr + 0xfff) & ~0xfff; - if (guest_pa_to_host_va(core, queue->ring_desc_addr, (addr_t *)&(queue->desc)) == -1) { + if (v3_gpa_to_hva(core, queue->ring_desc_addr, (addr_t *)&(queue->desc)) == -1) { PrintError("Could not translate ring descriptor address\n"); return -1; } - if (guest_pa_to_host_va(core, queue->ring_avail_addr, (addr_t *)&(queue->avail)) == -1) { + if (v3_gpa_to_hva(core, queue->ring_avail_addr, (addr_t *)&(queue->avail)) == -1) { PrintError("Could not translate ring available address\n"); return -1; } - if (guest_pa_to_host_va(core, queue->ring_used_addr, (addr_t *)&(queue->used)) == -1) { + if (v3_gpa_to_hva(core, queue->ring_used_addr, (addr_t *)&(queue->used)) == -1) { PrintError("Could not translate ring used address\n"); return -1; } @@ -478,12 +497,12 @@ static int virtio_rx(uint8_t * buf, uint32_t size, void * private_data) { uint32_t data_len = size; uint32_t offset = 0; unsigned long flags; - int ret_val; + int ret_val = -1; int raw = 1; flags = v3_lock_irqsave(virtio->lock); - - PrintDebug("VIRTIO NIC: receiving packet to virtio nic %p, size:%d\n", virtio, size); + + PrintDebug("VIRTIO NIC: RX on cpu %d to virtio nic %p, size:%d\n", V3_Get_CPU(), virtio, size); virtio->pkt_recv ++; @@ -495,7 +514,6 @@ static int virtio_rx(uint8_t * buf, uint32_t size, void * private_data) { if (q->ring_avail_addr == 0) { PrintError("Queue is not set\n"); - ret_val = -1; goto exit; } @@ -506,7 +524,7 @@ static int virtio_rx(uint8_t * buf, uint32_t size, void * private_data) { struct vring_desc * hdr_desc = NULL; hdr_desc = &(q->desc[hdr_idx]); - if (guest_pa_to_host_va(&(virtio->virtio_dev->vm->cores[0]), hdr_desc->addr_gpa, &(hdr_addr)) == -1) { + if (v3_gpa_to_hva(&(virtio->virtio_dev->vm->cores[0]), hdr_desc->addr_gpa, &(hdr_addr)) == -1) { PrintError("Could not translate receive buffer address\n"); ret_val = -1; goto exit; @@ -536,6 +554,7 @@ static int virtio_rx(uint8_t * buf, uint32_t size, void * private_data) { q->cur_avail_idx++; } else { virtio->pkt_drop++; + goto exit; } if (!(q->avail->flags & VIRTIO_NO_IRQ_FLAG)) { @@ -547,6 +566,20 @@ static int virtio_rx(uint8_t * buf, uint32_t size, void * private_data) { ret_val = offset; exit: + +#ifdef CONFIG_VNET_PROFILE + if (virtio->pkt_recv % 50000 == 0){ + long cur_time, time; + rdtscll(cur_time); + time = cur_time - virtio->last_recv_time; + PrintError("Virtio NIC: last recv 50000 cycles: %ld\n",time); + //PrintError("Virtio NIC: sent: %ld, rxed: %ld, dropped: %ld\n", + //virtio->pkt_sent, + //virtio->pkt_recv, + //virtio->pkt_drop); + rdtscll(virtio->last_recv_time); + } +#endif v3_unlock_irqrestore(virtio->lock, flags); @@ -653,9 +686,9 @@ static int connect_fn(struct v3_vm_info * info, static int virtio_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { struct vm_device * pci_bus = v3_find_dev(vm, v3_cfg_val(cfg, "bus")); struct virtio_dev_state * virtio_state = NULL; - char * name = v3_cfg_val(cfg, "name"); + char * dev_id = v3_cfg_val(cfg, "ID"); - PrintDebug("Virtio NIC: Initializing VIRTIO Network device: %s\n", name); + PrintDebug("Virtio NIC: Initializing VIRTIO Network device: %s\n", dev_id); if (pci_bus == NULL) { PrintError("Virtio NIC: VirtIO devices require a PCI Bus"); @@ -669,14 +702,14 @@ static int virtio_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { virtio_state->pci_bus = pci_bus; virtio_state->vm = vm; - struct vm_device * dev = v3_allocate_device(name, &dev_ops, virtio_state); + struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, virtio_state); if (v3_attach_device(vm, dev) == -1) { - PrintError("Virtio NIC: Could not attach device %s\n", name); + PrintError("Virtio NIC: Could not attach device %s\n", dev_id); return -1; } - if (v3_dev_add_net_frontend(vm, name, connect_fn, (void *)virtio_state) == -1) { - PrintError("Virtio NIC: Could not register %s as net frontend\n", name); + if (v3_dev_add_net_frontend(vm, dev_id, connect_fn, (void *)virtio_state) == -1) { + PrintError("Virtio NIC: Could not register %s as net frontend\n", dev_id); return -1; }