X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Flnx_virtio_nic.c;h=3c519aad72227d2327f8a751e89e6b945b859d20;hb=ee05d4a828862fb4e79616585c15be0aee11ea50;hp=baf3369571347d57c7d34f853a6c624ea4e4f327;hpb=70842a596167a7cfb7d8c8121cf0d5d2350079ea;p=palacios-OLD.git diff --git a/palacios/src/devices/lnx_virtio_nic.c b/palacios/src/devices/lnx_virtio_nic.c index baf3369..3c519aa 100644 --- a/palacios/src/devices/lnx_virtio_nic.c +++ b/palacios/src/devices/lnx_virtio_nic.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include @@ -33,11 +33,15 @@ #include -#ifndef CONFIG_DEBUG_VIRTIO_NET +#ifndef V3_CONFIG_DEBUG_VIRTIO_NET #undef PrintDebug #define PrintDebug(fmt, args...) #endif +#ifndef V3_CONFIG_VNET +static int net_debug = 0; +#endif + #define TX_QUEUE_SIZE 4096 #define RX_QUEUE_SIZE 4096 #define CTRL_QUEUE_SIZE 64 @@ -127,7 +131,7 @@ struct virtio_net_state { uint8_t mergeable_rx_bufs; struct v3_timer * timer; - void * poll_thread; + struct vnet_thread * poll_thread; struct nic_statistics stats; @@ -199,7 +203,7 @@ static int tx_one_pkt(struct guest_info * core, } V3_Net_Print(2, "Virtio-NIC: virtio_tx: size: %d\n", len); - if(v3_net_debug >= 4){ + if(net_debug >= 4){ v3_hexdump(buf, len, NULL, 0); } @@ -248,11 +252,15 @@ static inline int get_desc_count(struct virtio_queue * q, int index) { } static inline void enable_cb(struct virtio_queue *queue){ - queue->used->flags &= ~ VRING_NO_NOTIFY_FLAG; + if(queue->used){ + queue->used->flags &= ~ VRING_NO_NOTIFY_FLAG; + } } static inline void disable_cb(struct virtio_queue *queue) { - queue->used->flags |= VRING_NO_NOTIFY_FLAG; + if(queue->used){ + queue->used->flags |= VRING_NO_NOTIFY_FLAG; + } } static int handle_pkt_tx(struct guest_info * core, @@ -406,7 +414,7 @@ static int virtio_io_write(struct guest_info *core, virtio_setup_queue(core, virtio, &virtio->tx_vq, pfn, page_addr); if(virtio->tx_notify == 0){ disable_cb(&virtio->tx_vq); - V3_THREAD_WAKEUP(virtio->poll_thread); + vnet_thread_wakeup(virtio->poll_thread); } break; case 2: @@ -561,7 +569,7 @@ static int virtio_rx(uint8_t * buf, uint32_t size, void * private_data) { unsigned long flags; V3_Net_Print(2, "Virtio-NIC: virtio_rx: size: %d\n", size); - if(v3_net_debug >= 4){ + if(net_debug >= 4){ v3_hexdump(buf, size, NULL, 0); } @@ -660,7 +668,7 @@ static int virtio_rx(uint8_t * buf, uint32_t size, void * private_data) { /* kick guest to refill the queue */ virtio->virtio_cfg.pci_isr = 0x1; v3_pci_raise_irq(virtio->virtio_dev->pci_bus, 0, virtio->pci_dev); - v3_interrupt_cpu(virtio->virtio_dev->vm, virtio->virtio_dev->vm->cores[0].cpu_id, 0); + v3_interrupt_cpu(virtio->virtio_dev->vm, virtio->virtio_dev->vm->cores[0].pcpu_id, 0); virtio->stats.rx_interrupts ++; goto err_exit; @@ -679,8 +687,8 @@ static int virtio_rx(uint8_t * buf, uint32_t size, void * private_data) { /* notify guest if it is in guest mode */ if(virtio->rx_notify == 1 && - V3_Get_CPU() != virtio->virtio_dev->vm->cores[0].cpu_id){ - v3_interrupt_cpu(virtio->virtio_dev->vm, virtio->virtio_dev->vm->cores[0].cpu_id, 0); + V3_Get_CPU() != virtio->virtio_dev->vm->cores[0].pcpu_id){ + v3_interrupt_cpu(virtio->virtio_dev->vm, virtio->virtio_dev->vm->cores[0].pcpu_id, 0); } return 0; @@ -725,7 +733,7 @@ static int virtio_tx_flush(void * args){ handle_pkt_tx(&(virtio->vm->cores[0]), virtio); v3_yield(NULL); }else { - V3_THREAD_SLEEP(); + vnet_thread_sleep(-1); } } @@ -804,6 +812,7 @@ static int register_dev(struct virtio_dev_state * virtio, return 0; } + #define RATE_UPPER_THRESHOLD 10 /* 10000 pkts per second, around 100Mbits */ #define RATE_LOWER_THRESHOLD 1 #define PROFILE_PERIOD 10000 /*us*/ @@ -815,6 +824,10 @@ static void virtio_nic_timer(struct guest_info * core, uint64_t period_us; static int profile_ms = 0; + if(!net_state->status){ /* VNIC is not in working status */ + return; + } + period_us = (1000*cpu_cycles)/cpu_freq; net_state->past_us += period_us; @@ -831,7 +844,7 @@ static void virtio_nic_timer(struct guest_info * core, V3_Print("Virtio NIC: Switch TX to VMM driven mode\n"); disable_cb(&(net_state->tx_vq)); net_state->tx_notify = 0; - V3_THREAD_WAKEUP(net_state->poll_thread); + vnet_thread_wakeup(net_state->poll_thread); } if(tx_rate < RATE_LOWER_THRESHOLD && net_state->tx_notify == 0){ @@ -890,11 +903,15 @@ static int connect_fn(struct v3_vm_info * info, net_state->timer = v3_add_timer(&(info->cores[0]),&timer_ops,net_state); + PrintError("net_state 0x%p\n", (void *)net_state); + ops->recv = virtio_rx; ops->frontend_data = net_state; memcpy(ops->fnt_mac, virtio->mac, ETH_ALEN); - net_state->poll_thread = V3_CREATE_THREAD(virtio_tx_flush, (void *)net_state, "Virtio_Poll"); + net_state->poll_thread = vnet_start_thread(virtio_tx_flush, (void *)net_state, "Virtio_Poll"); + + net_state->status = 1; return 0; }