Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Merge branch 'devel' of palacios@newskysaw.cs.northwestern.edu:/home/palacios/palacio...
Lei Xia [Wed, 13 Apr 2011 16:15:16 +0000 (11:15 -0500)]
palacios/include/palacios/vmm_dev_mgr.h
palacios/include/palacios/vmm_ethernet.h
palacios/include/palacios/vmm_vnet.h
palacios/src/devices/lnx_virtio_nic.c
palacios/src/devices/vnet_nic.c
palacios/src/palacios/vmm_vnet_core.c

index 1ec922c..e789207 100644 (file)
@@ -180,14 +180,10 @@ struct v3_dev_blk_ops {
 struct v3_dev_net_ops {
     /* Backend implemented functions */
     int (*send)(uint8_t * buf, uint32_t count, void * private_data);
-    void (*start_rx)(void * back_data);
-    void (*stop_rx)(void * back_data);
 
     /* Frontend implemented functions */
     int (*recv)(uint8_t * buf, uint32_t count, void * frnt_data);
-    void (*poll)(struct v3_vm_info * vm, void * frnt_data);
-    void (*start_tx)(void * frnt_data);
-    void (*stop_tx)(void * frnt_data);
+    void (*poll)(struct v3_vm_info * vm, int budget, void * frnt_data);
 
     /* This is ugly... */
     void * frontend_data; 
index 06dde7b..3794d77 100644 (file)
 #include <palacios/vmm.h>
 
 struct nic_statistics {
-    uint64_t tx_pkts;
+    uint32_t tx_pkts;
     uint64_t tx_bytes;
-    uint64_t tx_dropped;
+    uint32_t tx_dropped;
        
-    uint64_t rx_pkts;
+    uint32_t rx_pkts;
     uint64_t rx_bytes;
-    uint64_t rx_dropped;
+    uint32_t rx_dropped;
 
     uint32_t interrupts;
 };
index 1f83e54..1750fff 100644 (file)
@@ -106,19 +106,17 @@ int v3_vnet_stat(struct vnet_stat * stats);
 
 #ifdef __V3VEE__
 
-typedef enum {VMM_DRIVERN = 1, GUEST_DRIVERN} vnet_poll_type_t;
-
 struct v3_vnet_dev_ops {
     int (*input)(struct v3_vm_info * vm, 
                struct v3_vnet_pkt * pkt, 
                void * dev_data);
-    void (*poll) (struct v3_vm_info * vm, void * dev_data);
+    void (*poll) (struct v3_vm_info * vm, int budget, void * dev_data);
 };
 
 int v3_init_vnet(void);        
 void v3_deinit_vnet(void);
 
-void v3_vnet_poll(struct v3_vm_info * vm);
+void v3_vnet_do_poll(struct v3_vm_info * vm);
 
 int v3_vnet_add_dev(struct v3_vm_info * info, uint8_t * mac, 
                    struct v3_vnet_dev_ops * ops,
index da6644e..bb13a69 100644 (file)
@@ -30,6 +30,7 @@
 #include <palacios/vmm_util.h>
 #include <devices/pci.h>
 #include <palacios/vmm_ethernet.h>
+#include <palacios/vmm_time.h>
 
 
 #ifndef CONFIG_DEBUG_VIRTIO_NET
@@ -57,14 +58,15 @@ struct virtio_net_hdr_mrg_rxbuf {
 };
 
        
-#define TX_QUEUE_SIZE 64
-#define RX_QUEUE_SIZE 1024
+#define TX_QUEUE_SIZE 256
+#define RX_QUEUE_SIZE 4096
 #define CTRL_QUEUE_SIZE 64
 
 #define VIRTIO_NET_F_MRG_RXBUF 15      /* Host can merge receive buffers. */
 #define VIRTIO_NET_F_MAC       5       /* Host has given MAC address. */
 #define VIRTIO_NET_F_GSO       6       /* Host handles pkts w/ any GSO type */
 #define VIRTIO_NET_F_HOST_TSO4 11      /* Host can handle TSOv4 in. */
+#define VIRTIO_NET_F_HOST_UFO  14      /* Host can handle UFO in. */
 
 /* Port to get virtio config */
 #define VIRTIO_NET_CONFIG 20  
@@ -95,17 +97,22 @@ struct virtio_net_state {
     struct virtio_queue tx_vq;         /* idx 1*/
     struct virtio_queue ctrl_vq;       /* idx 2*/
 
+    struct v3_timer * timer;
+
     struct nic_statistics statistics;
 
     struct v3_dev_net_ops * net_ops;
     v3_lock_t rx_lock, tx_lock;
 
+    uint8_t tx_notify, rx_notify;
+    uint32_t tx_pkts, rx_pkts;
+    uint64_t past_ms;
+
     void * backend_data;
     struct virtio_dev_state * virtio_dev;
     struct list_head dev_link;
 };
 
-
 static int virtio_init_state(struct virtio_net_state * virtio) 
 {
     virtio->rx_vq.queue_size = RX_QUEUE_SIZE;
@@ -132,7 +139,9 @@ static int virtio_init_state(struct virtio_net_state * virtio)
 
     virtio->virtio_cfg.pci_isr = 0;
        
-    virtio->virtio_cfg.host_features = 0 | (1 << VIRTIO_NET_F_MAC);
+    virtio->virtio_cfg.host_features = 0 | (1 << VIRTIO_NET_F_MAC) | 
+                                                               (1 << VIRTIO_NET_F_HOST_UFO) | 
+                                                               (1 << VIRTIO_NET_F_HOST_TSO4);
 
     if ((v3_lock_init(&(virtio->rx_lock)) == -1) ||
        (v3_lock_init(&(virtio->tx_lock)) == -1)){
@@ -261,7 +270,7 @@ static int handle_pkt_tx(struct guest_info * core,
        desc_idx = hdr_desc->next;
 
        if(desc_cnt > 2){
-           PrintError("VNIC: merged rx buffer not supported\n");
+           PrintError("VNIC: merged rx buffer not supported, desc_cnt %d\n", desc_cnt);
            goto exit_error;
        }
 
@@ -535,7 +544,7 @@ static int virtio_rx(uint8_t * buf, uint32_t size, void * private_data) {
     uint32_t offset = 0;
     unsigned long flags;
 
-#ifndef CONFIG_DEBUG_VIRTIO_NET
+#ifdef CONFIG_DEBUG_VIRTIO_NET
     PrintDebug("Virtio-NIC: virtio_rx: size: %d\n", size);     
     v3_hexdump(buf, size, NULL, 0);
 #endif
@@ -604,6 +613,11 @@ static int virtio_rx(uint8_t * buf, uint32_t size, void * private_data) {
 
     v3_unlock_irqrestore(virtio->rx_lock, flags);
 
+    /* notify guest if guest is running */
+    if(virtio->rx_notify == 1){
+       v3_interrupt_cpu(virtio->virtio_dev->vm, virtio->virtio_dev->vm->cores[0].cpu_id, 0);
+    }
+
     return 0;
 
 err_exit:
@@ -636,10 +650,12 @@ static struct v3_device_ops dev_ops = {
 };
 
 
-static void virtio_nic_poll(struct v3_vm_info * vm, void * data){
+static void virtio_nic_poll(struct v3_vm_info * vm, int budget, void * data){
     struct virtio_net_state * virtio = (struct virtio_net_state *)data;
-       
-    handle_pkt_tx(&(vm->cores[0]), virtio);
+
+    if(virtio->tx_notify == 0){
+       handle_pkt_tx(&(vm->cores[0]), virtio);
+    }
 }
 
 static int register_dev(struct virtio_dev_state * virtio, 
@@ -714,6 +730,61 @@ 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 50 /*50ms*/
+
+/* Timer Functions */
+static void virtio_nic_timer(struct guest_info * core, 
+                            uint64_t cpu_cycles, uint64_t cpu_freq, 
+                            void * priv_data) {
+    struct virtio_net_state * net_state = (struct virtio_net_state *)priv_data;
+    uint64_t period_ms;
+
+    period_ms = cpu_cycles/cpu_freq;
+    net_state->past_ms += period_ms;
+
+    if(net_state->past_ms >  PROFILE_PERIOD){ 
+       uint32_t tx_rate, rx_rate;
+       
+       tx_rate = (net_state->statistics.tx_pkts - net_state->tx_pkts)/net_state->past_ms; /* pkts/per ms */
+       rx_rate = (net_state->statistics.rx_pkts - net_state->rx_pkts)/net_state->past_ms;
+
+       net_state->tx_pkts = net_state->statistics.tx_pkts;
+       net_state->rx_pkts = net_state->statistics.rx_pkts;
+
+       if(tx_rate > RATE_UPPER_THRESHOLD && net_state->tx_notify == 1){
+           V3_Print("Virtio NIC: Switch TX to VMM driven mode\n");
+           disable_cb(&(net_state->tx_vq));
+           net_state->tx_notify = 0;
+       }
+
+       if(tx_rate < RATE_LOWER_THRESHOLD && net_state->tx_notify == 0){
+           V3_Print("Virtio NIC: Switch TX to Guest  driven mode\n");
+           enable_cb(&(net_state->tx_vq));
+           net_state->tx_notify = 1;
+       }
+
+       if(rx_rate > RATE_UPPER_THRESHOLD && net_state->rx_notify == 1){
+           PrintDebug("Virtio NIC: Switch RX to VMM None notify mode\n");
+           net_state->rx_notify = 0;
+       }
+
+       if(rx_rate < RATE_LOWER_THRESHOLD && net_state->rx_notify == 0){
+           PrintDebug("Virtio NIC: Switch RX to VMM notify mode\n");
+           net_state->rx_notify = 1;
+       }
+
+       net_state->past_ms = 0;
+    }
+}
+
+
+static struct v3_timer_ops timer_ops = {
+    .update_timer = virtio_nic_timer,
+};
+
+
 static int connect_fn(struct v3_vm_info * info, 
                      void * frontend_data, 
                      struct v3_dev_net_ops * ops, 
@@ -728,7 +799,10 @@ static int connect_fn(struct v3_vm_info * info,
     net_state->net_ops = ops;
     net_state->backend_data = private_data;
     net_state->virtio_dev = virtio;
-       
+    net_state->tx_notify = 1;
+    net_state->rx_notify = 1;
+
+    net_state->timer = v3_add_timer(&(info->cores[0]),&timer_ops,net_state);
 
     ops->recv = virtio_rx;
     ops->poll = virtio_nic_poll;
@@ -742,7 +816,9 @@ 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 * dev_id = v3_cfg_val(cfg, "ID");
-    char * macstr = v3_cfg_val(cfg, "mac");
+    char macstr[128];
+    char * str = v3_cfg_val(cfg, "mac");
+    memcpy(macstr, str, strlen(str));
 
     if (pci_bus == NULL) {
        PrintError("Virtio NIC: VirtIO devices require a PCI Bus");
@@ -758,6 +834,12 @@ static int virtio_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
 
     if (macstr != NULL && !str2mac(macstr, virtio_state->mac)) {
        PrintDebug("Virtio NIC: Mac specified %s\n", macstr);
+       PrintDebug("MAC: %x:%x:%x:%x:%x:%x\n", virtio_state->mac[0],
+                               virtio_state->mac[1],
+                               virtio_state->mac[2],
+                               virtio_state->mac[3],
+                               virtio_state->mac[4],
+                               virtio_state->mac[5]);
     }else {
        PrintDebug("Virtio NIC: MAC not specified\n");
        random_ethaddr(virtio_state->mac);
index 1831270..0fdaaba 100644 (file)
@@ -79,10 +79,11 @@ static int virtio_input(struct v3_vm_info * info,
 
 /* poll data from front-end */
 static void virtio_poll(struct v3_vm_info * info, 
+                       int budget,
                        void * private_data){
     struct vnet_nic_state *vnetnic = (struct vnet_nic_state *)private_data;
 
-    vnetnic->net_ops.poll(info, vnetnic->net_ops.frontend_data);
+    vnetnic->net_ops.poll(info, budget, vnetnic->net_ops.frontend_data);
 }
 
 
index 6b86436..e0e0ac7 100644 (file)
@@ -46,7 +46,9 @@ struct vnet_dev {
     void * private_data;
 
     int active;
-    vnet_poll_type_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;
-    vnet_poll_type_t mode;
+
     int active;
     void * private_data;
 } __attribute__((packed));
@@ -90,7 +92,7 @@ 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;
@@ -304,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
     {
@@ -434,7 +436,6 @@ 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
 
@@ -521,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);
 
@@ -630,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 */
@@ -642,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));