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.


Added selective per CPU initialization option
[palacios.git] / palacios / src / vnet / vnet_core.c
index 4669029..e7b37f9 100644 (file)
@@ -53,7 +53,7 @@ struct vnet_dev {
        
     void * private_data;
 
-    struct list_head node;\r
+    struct list_head node;
 } __attribute__((packed));
 
 
@@ -213,10 +213,9 @@ static struct vnet_dev * dev_by_id(int idx) {
     struct vnet_dev * dev = NULL; 
 
     list_for_each_entry(dev, &(vnet_state.devs), node) {
-       int dev_id = dev->dev_id;
-
-       if (dev_id == idx)
+       if (dev->dev_id == idx) {
            return dev;
+       }
     }
 
     return NULL;
@@ -303,7 +302,7 @@ void v3_vnet_del_route(uint32_t route_idx){
     flags = vnet_lock_irqsave(vnet_state.lock);
 
     list_for_each_entry(route, &(vnet_state.routes), node) {
-       V3_Print("v3_vnet_del_route, route idx: %d\n", route->idx);
+       Vnet_Print(0, "v3_vnet_del_route, route idx: %d\n", route->idx);
        if(route->idx == route_idx){
            list_del(&(route->node));
            Vnet_Free(route);
@@ -322,12 +321,12 @@ void v3_vnet_del_route(uint32_t route_idx){
 
 /* delete all route entries with specfied src or dst device id */ 
 static void inline del_routes_by_dev(int dev_id){
-    struct vnet_route_info * route = NULL;
+    struct vnet_route_info * route, *tmp_route;
     unsigned long flags; 
 
     flags = vnet_lock_irqsave(vnet_state.lock);
 
-    list_for_each_entry(route, &(vnet_state.routes), node) {
+    list_for_each_entry_safe(route, tmp_route, &(vnet_state.routes), node) {
        if((route->route_def.dst_type == LINK_INTERFACE &&
             route->route_def.dst_id == dev_id) ||
             (route->route_def.src_type == LINK_INTERFACE &&
@@ -549,7 +548,7 @@ int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void * private_data) {
 
 
 int v3_vnet_add_dev(struct v3_vm_info * vm, uint8_t * mac, 
-                   struct v3_vnet_dev_ops *ops, int quote, int poll_state,
+                   struct v3_vnet_dev_ops * ops, int quote, int poll_state,
                    void * priv_data){
     struct vnet_dev * new_dev = NULL;
     unsigned long flags;
@@ -563,6 +562,7 @@ int v3_vnet_add_dev(struct v3_vm_info * vm, uint8_t * mac,
    
     memcpy(new_dev->mac_addr, mac, 6);
     new_dev->dev_ops.input = ops->input;
+    new_dev->dev_ops.poll = ops->poll;
     new_dev->private_data = priv_data;
     new_dev->vm = vm;
     new_dev->dev_id = 0;
@@ -575,6 +575,12 @@ int v3_vnet_add_dev(struct v3_vm_info * vm, uint8_t * mac,
        list_add(&(new_dev->node), &(vnet_state.devs));
        new_dev->dev_id = ++ vnet_state.dev_idx;
        vnet_state.num_devs ++;
+
+       if(new_dev->poll) {
+           v3_enqueue(vnet_state.poll_devs, (addr_t)new_dev);
+       }
+    } else {
+       PrintError("VNET/P: Device with the same MAC is already there\n");
     }
 
     vnet_unlock_irqrestore(vnet_state.lock, flags);
@@ -624,18 +630,18 @@ int v3_vnet_stat(struct vnet_stat * stats){
 }
 
 static void deinit_devices_list(){
-    struct vnet_dev * dev = NULL; 
+    struct vnet_dev * dev, * tmp; 
 
-    list_for_each_entry(dev, &(vnet_state.devs), node) {
+    list_for_each_entry_safe(dev, tmp, &(vnet_state.devs), node) {
        list_del(&(dev->node));
        Vnet_Free(dev);
     }
 }
 
 static void deinit_routes_list(){
-    struct vnet_route_info * route = NULL; 
+    struct vnet_route_info * route, * tmp; 
 
-    list_for_each_entry(route, &(vnet_state.routes), node) {
+    list_for_each_entry_safe(route, tmp, &(vnet_state.routes), node) {
        list_del(&(route->node));
        list_del(&(route->match_node));
        Vnet_Free(route);
@@ -708,25 +714,23 @@ void v3_vnet_del_bridge(uint8_t type) {
   * that runs on multiple cores 
   * or it could be running on a dedicated side core
   */
-static int vnet_tx_flush(void *args){
+static int vnet_tx_flush(void * args){
     struct vnet_dev * dev = NULL;
     int ret;
 
     Vnet_Print(0, "VNET/P Polling Thread Starting ....\n");
 
-    /* we need thread sleep/wakeup in Palacios */
     while(!vnet_thread_should_stop()){
        dev = (struct vnet_dev *)v3_dequeue(vnet_state.poll_devs);
        if(dev != NULL){
            if(dev->poll && dev->dev_ops.poll != NULL){
                ret = dev->dev_ops.poll(dev->vm, dev->quote, dev->private_data);
-
+               
                if (ret < 0){
-                   PrintDebug("VNET/P: poll from device %p error!\n", dev);
+                   Vnet_Print(0, "VNET/P: poll from device %p error!\n", dev);
                }
-
-               v3_enqueue(vnet_state.poll_devs, (addr_t)dev); 
            }
+           v3_enqueue(vnet_state.poll_devs, (addr_t)dev); 
        }else { /* no device needs to be polled */
           /* sleep here? */
            Vnet_Yield();
@@ -736,7 +740,6 @@ static int vnet_tx_flush(void *args){
     return 0;
 }
 
-
 int v3_init_vnet() {
     memset(&vnet_state, 0, sizeof(vnet_state));
        
@@ -758,7 +761,7 @@ int v3_init_vnet() {
 
     vnet_state.poll_devs = v3_create_queue();
 
-    vnet_state.pkt_flush_thread = vnet_start_thread(vnet_tx_flush, NULL, "vnetd");
+    vnet_state.pkt_flush_thread = vnet_start_thread(vnet_tx_flush, NULL, "vnetd-1");
 
     Vnet_Debug("VNET/P is initiated\n");