X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fvnet%2Fvnet_core.c;h=46690294165b5f50eac65f501ba7ef2f8c24bba1;hb=96c8702630006b04e8e8f762f059f5300660e612;hp=9bf044a29fec8b95f754dec621beb4765bf1da98;hpb=d12cdf5b213b2b51d525914a852ceacd2c198b5a;p=palacios.git diff --git a/palacios/src/vnet/vnet_core.c b/palacios/src/vnet/vnet_core.c index 9bf044a..4669029 100644 --- a/palacios/src/vnet/vnet_core.c +++ b/palacios/src/vnet/vnet_core.c @@ -10,7 +10,7 @@ * Copyright (c) 2010, Lei Xia * Copyright (c) 2009, Yuan Tang * Copyright (c) 2009, The V3VEE Project - * All rights reserved. + * All rights reserved * * Author: Lei Xia * Yuan Tang @@ -20,18 +20,18 @@ */ #include -#include -#include +#include +#include +#include + #include -#include -#include #ifndef V3_CONFIG_DEBUG_VNET -#undef PrintDebug -#define PrintDebug(fmt, args...) +#undef Vnet_Debug +#define Vnet_Debug(fmt, args...) #endif -int v3_net_debug = 0; +int net_debug = 0; struct eth_hdr { uint8_t dst_mac[ETH_ALEN]; @@ -45,9 +45,15 @@ struct vnet_dev { uint8_t mac_addr[ETH_ALEN]; struct v3_vm_info * vm; struct v3_vnet_dev_ops dev_ops; + + int poll; + +#define VNET_MAX_QUOTE 64 + int quote; + void * private_data; - struct list_head node; + struct list_head node; } __attribute__((packed)); @@ -68,6 +74,8 @@ struct vnet_route_info { struct vnet_dev * dst_dev; struct vnet_dev * src_dev; + uint32_t idx; + struct list_head node; struct list_head match_node; // used for route matching }; @@ -88,36 +96,34 @@ struct queue_entry{ uint32_t size_alloc; }; -#define VNET_QUEUE_SIZE 1024 -struct vnet_queue { - struct queue_entry buf[VNET_QUEUE_SIZE]; - int head, tail; - int count; - v3_lock_t lock; -}; static struct { struct list_head routes; struct list_head devs; - - int num_routes; - int num_devs; + + uint8_t status; + + uint32_t num_routes; + uint32_t route_idx; + uint32_t num_devs; + uint32_t dev_idx; struct vnet_brg_dev * bridge; - v3_lock_t lock; + vnet_lock_t lock; struct vnet_stat stats; - void * pkt_flush_thread; + /* device queue that are waiting to be polled */ + struct v3_queue * poll_devs; - struct vnet_queue pkt_q; + struct vnet_thread * pkt_flush_thread; struct hashtable * route_cache; } vnet_state; #ifdef V3_CONFIG_DEBUG_VNET -static inline void mac_to_string(uint8_t * mac, char * buf) { +static inline void mac2str(uint8_t * mac, char * buf) { snprintf(buf, 100, "%2x:%2x:%2x:%2x:%2x:%2x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); @@ -126,16 +132,16 @@ static inline void mac_to_string(uint8_t * mac, char * buf) { static void print_route(struct v3_vnet_route * route){ char str[50]; - mac_to_string(route->src_mac, str); - PrintDebug("Src Mac (%s), src_qual (%d)\n", + mac2str(route->src_mac, str); + Vnet_Debug("Src Mac (%s), src_qual (%d)\n", str, route->src_mac_qual); - mac_to_string(route->dst_mac, str); - PrintDebug("Dst Mac (%s), dst_qual (%d)\n", + mac2str(route->dst_mac, str); + Vnet_Debug("Dst Mac (%s), dst_qual (%d)\n", str, route->dst_mac_qual); - PrintDebug("Src dev id (%d), src type (%d)", + Vnet_Debug("Src dev id (%d), src type (%d)", route->src_id, route->src_type); - PrintDebug("Dst dev id (%d), dst type (%d)\n", + Vnet_Debug("Dst dev id (%d), dst type (%d)\n", route->dst_id, route->dst_type); } @@ -143,14 +149,13 @@ static void print_route(struct v3_vnet_route * route){ static void dump_routes(){ struct vnet_route_info *route; - int i = 0; - PrintDebug("\n========Dump routes starts ============\n"); + Vnet_Debug("\n========Dump routes starts ============\n"); list_for_each_entry(route, &(vnet_state.routes), node) { - PrintDebug("\nroute %d:\n", i++); + Vnet_Debug("\nroute %d:\n", route->idx); print_route(&(route->route_def)); if (route->route_def.dst_type == LINK_INTERFACE) { - PrintDebug("dst_dev (%p), dst_dev_id (%d), dst_dev_ops(%p), dst_dev_data (%p)\n", + Vnet_Debug("dst_dev (%p), dst_dev_id (%d), dst_dev_ops(%p), dst_dev_data (%p)\n", route->dst_dev, route->dst_dev->dev_id, (void *)&(route->dst_dev->dev_ops), @@ -158,7 +163,7 @@ static void dump_routes(){ } } - PrintDebug("\n========Dump routes end ============\n"); + Vnet_Debug("\n========Dump routes end ============\n"); } #endif @@ -171,7 +176,7 @@ static void dump_routes(){ static inline uint_t hash_fn(addr_t hdr_ptr) { uint8_t * hdr_buf = (uint8_t *)hdr_ptr; - return v3_hash_buffer(hdr_buf, VNET_HASH_SIZE); + return vnet_hash_buffer(hdr_buf, VNET_HASH_SIZE); } static inline int hash_eq(addr_t key1, addr_t key2) { @@ -181,7 +186,7 @@ static inline int hash_eq(addr_t key1, addr_t key2) { static int add_route_to_cache(const struct v3_vnet_pkt * pkt, struct route_list * routes) { memcpy(routes->hash_buf, pkt->hash_buf, VNET_HASH_SIZE); - if (v3_htable_insert(vnet_state.route_cache, (addr_t)routes->hash_buf, (addr_t)routes) == 0) { + if (vnet_htable_insert(vnet_state.route_cache, (addr_t)routes->hash_buf, (addr_t)routes) == 0) { PrintError("VNET/P Core: Failed to insert new route entry to the cache\n"); return -1; } @@ -190,15 +195,15 @@ static int add_route_to_cache(const struct v3_vnet_pkt * pkt, struct route_list } static int clear_hash_cache() { - v3_free_htable(vnet_state.route_cache, 1, 1); - vnet_state.route_cache = v3_create_htable(0, &hash_fn, &hash_eq); + vnet_free_htable(vnet_state.route_cache, 1, 1); + vnet_state.route_cache = vnet_create_htable(0, &hash_fn, &hash_eq); return 0; } static int look_into_cache(const struct v3_vnet_pkt * pkt, struct route_list ** routes) { - *routes = (struct route_list *)v3_htable_search(vnet_state.route_cache, (addr_t)(pkt->hash_buf)); + *routes = (struct route_list *)vnet_htable_search(vnet_state.route_cache, (addr_t)(pkt->hash_buf)); return 0; } @@ -247,11 +252,11 @@ int v3_vnet_add_route(struct v3_vnet_route route) { struct vnet_route_info * new_route = NULL; unsigned long flags; - new_route = (struct vnet_route_info *)V3_Malloc(sizeof(struct vnet_route_info)); + new_route = (struct vnet_route_info *)Vnet_Malloc(sizeof(struct vnet_route_info)); memset(new_route, 0, sizeof(struct vnet_route_info)); #ifdef V3_CONFIG_DEBUG_VNET - PrintDebug("VNET/P Core: add_route_entry:\n"); + Vnet_Debug("VNET/P Core: add_route_entry:\n"); print_route(&route); #endif @@ -273,19 +278,45 @@ int v3_vnet_add_route(struct v3_vnet_route route) { } - flags = v3_lock_irqsave(vnet_state.lock); + flags = vnet_lock_irqsave(vnet_state.lock); list_add(&(new_route->node), &(vnet_state.routes)); - clear_hash_cache(); + new_route->idx = ++ vnet_state.route_idx; + vnet_state.num_routes ++; + + vnet_unlock_irqrestore(vnet_state.lock, flags); - v3_unlock_irqrestore(vnet_state.lock, flags); - + clear_hash_cache(); #ifdef V3_CONFIG_DEBUG_VNET dump_routes(); #endif - return 0; + return new_route->idx; +} + + +void v3_vnet_del_route(uint32_t route_idx){ + struct vnet_route_info * route = NULL; + unsigned long flags; + + 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); + if(route->idx == route_idx){ + list_del(&(route->node)); + Vnet_Free(route); + break; + } + } + + vnet_unlock_irqrestore(vnet_state.lock, flags); + clear_hash_cache(); + +#ifdef V3_CONFIG_DEBUG_VNET + dump_routes(); +#endif } @@ -294,7 +325,7 @@ static void inline del_routes_by_dev(int dev_id){ struct vnet_route_info * route = NULL; unsigned long flags; - flags = v3_lock_irqsave(vnet_state.lock); + flags = vnet_lock_irqsave(vnet_state.lock); list_for_each_entry(route, &(vnet_state.routes), node) { if((route->route_def.dst_type == LINK_INTERFACE && @@ -304,11 +335,11 @@ static void inline del_routes_by_dev(int dev_id){ list_del(&(route->node)); list_del(&(route->match_node)); - V3_Free(route); + Vnet_Free(route); } } - v3_unlock_irqrestore(vnet_state.lock, flags); + vnet_unlock_irqrestore(vnet_state.lock, flags); } /* At the end allocate a route_list @@ -321,7 +352,7 @@ 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; + // uint8_t src_type = pkt->src_type; // uint32_t src_link = pkt->src_id; #ifdef V3_CONFIG_DEBUG_VNET @@ -329,9 +360,9 @@ static struct route_list * match_route(const struct v3_vnet_pkt * pkt) { char dst_str[100]; char src_str[100]; - mac_to_string(hdr->src_mac, src_str); - mac_to_string(hdr->dst_mac, dst_str); - PrintDebug("VNET/P Core: match_route. pkt: SRC(%s), DEST(%s)\n", src_str, dst_str); + mac2str(hdr->src_mac, src_str); + mac2str(hdr->dst_mac, dst_str); + Vnet_Debug("VNET/P Core: match_route. pkt: SRC(%s), DEST(%s)\n", src_str, dst_str); } #endif @@ -418,14 +449,14 @@ static struct route_list * match_route(const struct v3_vnet_pkt * pkt) { } } - PrintDebug("VNET/P Core: match_route: Matches=%d\n", num_matches); + Vnet_Debug("VNET/P Core: match_route: Matches=%d\n", num_matches); if (num_matches == 0) { return NULL; } - matches = (struct route_list *)V3_Malloc(sizeof(struct route_list) + - (sizeof(struct vnet_route_info *) * num_matches)); + matches = (struct route_list *)Vnet_Malloc(sizeof(struct route_list) + + (sizeof(struct vnet_route_info *) * num_matches)); matches->num_routes = num_matches; @@ -440,42 +471,42 @@ static struct route_list * match_route(const struct v3_vnet_pkt * pkt) { } -int vnet_tx_one_pkt(struct v3_vnet_pkt * pkt, void * private_data) { +int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void * private_data) { struct route_list * matched_routes = NULL; unsigned long flags; int i; int cpu = V3_Get_CPU(); - V3_Net_Print(2, "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); - if(v3_net_debug >= 4){ - v3_hexdump(pkt->data, pkt->size, NULL, 0); + Vnet_Print(2, "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); + if(net_debug >= 4){ + v3_hexdump(pkt->data, pkt->size, NULL, 0); } - flags = v3_lock_irqsave(vnet_state.lock); + flags = vnet_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"); + Vnet_Debug("VNET/P Core: send pkt Looking into routing table\n"); matched_routes = match_route(pkt); if (matched_routes) { add_route_to_cache(pkt, matched_routes); } else { - PrintDebug("VNET/P Core: Could not find route for packet... discards packet\n"); - v3_unlock_irqrestore(vnet_state.lock, flags); + Vnet_Debug("VNET/P Core: Could not find route for packet... discards packet\n"); + vnet_unlock_irqrestore(vnet_state.lock, flags); return 0; /* do we return -1 here?*/ } } - v3_unlock_irqrestore(vnet_state.lock, flags); + vnet_unlock_irqrestore(vnet_state.lock, flags); - PrintDebug("VNET/P Core: send pkt route matches %d\n", matched_routes->num_routes); + Vnet_Debug("VNET/P Core: send pkt route matches %d\n", matched_routes->num_routes); for (i = 0; i < matched_routes->num_routes; i++) { struct vnet_route_info * route = matched_routes->routes[i]; @@ -486,30 +517,30 @@ int vnet_tx_one_pkt(struct v3_vnet_pkt * pkt, void * private_data) { pkt->dst_id = route->route_def.dst_id; if (bridge == NULL) { - V3_Net_Print(2, "VNET/P Core: No active bridge to sent data to\n"); - continue; + Vnet_Print(2, "VNET/P Core: No active bridge to sent data to\n"); + continue; } if(bridge->brg_ops.input(bridge->vm, pkt, bridge->private_data) < 0){ - V3_Net_Print(2, "VNET/P Core: Packet not sent properly to bridge\n"); + Vnet_Print(2, "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){ - V3_Net_Print(2, "VNET/P Core: No active device to sent data to\n"); + Vnet_Print(2, "VNET/P Core: No active device to sent data to\n"); continue; } if(route->dst_dev->dev_ops.input(route->dst_dev->vm, pkt, route->dst_dev->private_data) < 0) { - V3_Net_Print(2, "VNET/P Core: Packet not sent properly\n"); + Vnet_Print(2, "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"); + Vnet_Print(0, "VNET/P Core: Wrong dst type\n"); } } @@ -517,74 +548,16 @@ int vnet_tx_one_pkt(struct v3_vnet_pkt * pkt, void * private_data) { } -static int vnet_pkt_enqueue(struct v3_vnet_pkt * pkt){ - unsigned long flags; - struct queue_entry * entry; - struct vnet_queue * q = &(vnet_state.pkt_q); - uint16_t num_pages; - - flags = v3_lock_irqsave(q->lock); - - if (q->count >= VNET_QUEUE_SIZE){ - V3_Net_Print(1, "VNET Queue overflow!\n"); - v3_unlock_irqrestore(q->lock, flags); - return -1; - } - - q->count ++; - entry = &(q->buf[q->tail++]); - q->tail %= VNET_QUEUE_SIZE; - - v3_unlock_irqrestore(q->lock, flags); - - /* this is ugly, but should happen very unlikely */ - while(entry->use); - - if(entry->size_alloc < pkt->size){ - if(entry->data != NULL){ - V3_FreePages(V3_PAddr(entry->data), (entry->size_alloc / PAGE_SIZE)); - entry->data = NULL; - } - - num_pages = 1 + (pkt->size / PAGE_SIZE); - entry->data = V3_VAddr(V3_AllocPages(num_pages)); - if(entry->data == NULL){ - return -1; - } - entry->size_alloc = PAGE_SIZE * num_pages; - } - - entry->pkt.data = entry->data; - memcpy(&(entry->pkt), pkt, sizeof(struct v3_vnet_pkt)); - memcpy(entry->data, pkt->data, pkt->size); - - entry->use = 1; - - return 0; -} - - -int v3_vnet_send_pkt(struct v3_vnet_pkt * pkt, void * private_data, int synchronize) { - if(synchronize){ - vnet_tx_one_pkt(pkt, NULL); - }else { - vnet_pkt_enqueue(pkt); - V3_Net_Print(2, "VNET/P Core: Put pkt into Queue: pkt size %d\n", pkt->size); - } - - return 0; -} - int v3_vnet_add_dev(struct v3_vm_info * vm, uint8_t * mac, - struct v3_vnet_dev_ops *ops, + struct v3_vnet_dev_ops *ops, int quote, int poll_state, void * priv_data){ struct vnet_dev * new_dev = NULL; unsigned long flags; - new_dev = (struct vnet_dev *)V3_Malloc(sizeof(struct vnet_dev)); + new_dev = (struct vnet_dev *)Vnet_Malloc(sizeof(struct vnet_dev)); if (new_dev == NULL) { - PrintError("Malloc fails\n"); + Vnet_Print(0, "Malloc fails\n"); return -1; } @@ -593,23 +566,26 @@ int v3_vnet_add_dev(struct v3_vm_info * vm, uint8_t * mac, new_dev->private_data = priv_data; new_dev->vm = vm; new_dev->dev_id = 0; + new_dev->quote = quotepoll = poll_state; - flags = v3_lock_irqsave(vnet_state.lock); + flags = vnet_lock_irqsave(vnet_state.lock); if (dev_by_mac(mac) == NULL) { list_add(&(new_dev->node), &(vnet_state.devs)); - new_dev->dev_id = ++vnet_state.num_devs; + new_dev->dev_id = ++ vnet_state.dev_idx; + vnet_state.num_devs ++; } - v3_unlock_irqrestore(vnet_state.lock, flags); + vnet_unlock_irqrestore(vnet_state.lock, flags); /* if the device was found previosly the id should still be 0 */ if (new_dev->dev_id == 0) { - PrintError("VNET/P Core: Device Already exists\n"); + Vnet_Print(0, "VNET/P Core: Device Already exists\n"); return -1; } - PrintDebug("VNET/P Core: Add Device: dev_id %d\n", new_dev->dev_id); + Vnet_Debug("VNET/P Core: Add Device: dev_id %d\n", new_dev->dev_id); return new_dev->dev_id; } @@ -619,26 +595,26 @@ int v3_vnet_del_dev(int dev_id){ struct vnet_dev * dev = NULL; unsigned long flags; - flags = v3_lock_irqsave(vnet_state.lock); + flags = vnet_lock_irqsave(vnet_state.lock); dev = dev_by_id(dev_id); if (dev != NULL){ list_del(&(dev->node)); - del_routes_by_dev(dev_id); + //del_routes_by_dev(dev_id); + vnet_state.num_devs --; } - v3_unlock_irqrestore(vnet_state.lock, flags); + vnet_unlock_irqrestore(vnet_state.lock, flags); - V3_Free(dev); + Vnet_Free(dev); - PrintDebug("VNET/P Core: Remove Device: dev_id %d\n", dev_id); + Vnet_Debug("VNET/P Core: Remove Device: dev_id %d\n", 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; @@ -647,22 +623,22 @@ int v3_vnet_stat(struct vnet_stat * stats){ return 0; } -static void free_devices(){ +static void deinit_devices_list(){ struct vnet_dev * dev = NULL; list_for_each_entry(dev, &(vnet_state.devs), node) { list_del(&(dev->node)); - V3_Free(dev); + Vnet_Free(dev); } } -static void free_routes(){ +static void deinit_routes_list(){ struct vnet_route_info * route = NULL; list_for_each_entry(route, &(vnet_state.routes), node) { list_del(&(route->node)); list_del(&(route->match_node)); - V3_Free(route); + Vnet_Free(route); } } @@ -674,19 +650,19 @@ int v3_vnet_add_bridge(struct v3_vm_info * vm, int bridge_free = 0; struct vnet_brg_dev * tmp_bridge = NULL; - flags = v3_lock_irqsave(vnet_state.lock); + flags = vnet_lock_irqsave(vnet_state.lock); if (vnet_state.bridge == NULL) { bridge_free = 1; vnet_state.bridge = (void *)1; } - v3_unlock_irqrestore(vnet_state.lock, flags); + vnet_unlock_irqrestore(vnet_state.lock, flags); if (bridge_free == 0) { PrintError("VNET/P Core: Bridge already set\n"); return -1; } - tmp_bridge = (struct vnet_brg_dev *)V3_Malloc(sizeof(struct vnet_brg_dev)); + tmp_bridge = (struct vnet_brg_dev *)Vnet_Malloc(sizeof(struct vnet_brg_dev)); if (tmp_bridge == NULL) { PrintError("Malloc Fails\n"); @@ -701,49 +677,65 @@ int v3_vnet_add_bridge(struct v3_vm_info * vm, tmp_bridge->type = type; /* make this atomic to avoid possible race conditions */ - flags = v3_lock_irqsave(vnet_state.lock); + flags = vnet_lock_irqsave(vnet_state.lock); vnet_state.bridge = tmp_bridge; - v3_unlock_irqrestore(vnet_state.lock, flags); + vnet_unlock_irqrestore(vnet_state.lock, flags); return 0; } -#if 0 -static int vnet_tx_flush(void *args){ - unsigned long flags; - struct queue_entry * entry; - struct vnet_queue * q = &(vnet_state.pkt_q); - V3_Print("VNET/P Handing Pkt Thread Starting ....\n"); +void v3_vnet_del_bridge(uint8_t type) { + unsigned long flags; + struct vnet_brg_dev * tmp_bridge = NULL; + + flags = vnet_lock_irqsave(vnet_state.lock); + + if (vnet_state.bridge != NULL && vnet_state.bridge->type == type) { + tmp_bridge = vnet_state.bridge; + vnet_state.bridge = NULL; + } + + vnet_unlock_irqrestore(vnet_state.lock, flags); - //V3_THREAD_SLEEP(); - /* we need thread sleep/wakeup in Palacios */ - while(1){ - flags = v3_lock_irqsave(q->lock); + if (tmp_bridge) { + Vnet_Free(tmp_bridge); + } +} - if (q->count <= 0){ - v3_unlock_irqrestore(q->lock, flags); - v3_yield(NULL); - //V3_THREAD_SLEEP(); - }else { - q->count --; - entry = &(q->buf[q->head++]); - q->head %= VNET_QUEUE_SIZE; - v3_unlock_irqrestore(q->lock, flags); +/* can be instanieoued to multiple threads + * that runs on multiple cores + * or it could be running on a dedicated side core + */ +static int vnet_tx_flush(void *args){ + struct vnet_dev * dev = NULL; + int ret; - /* this is ugly, but should happen very unlikely */ - while(!entry->use); - vnet_tx_one_pkt(&(entry->pkt), NULL); + Vnet_Print(0, "VNET/P Polling Thread Starting ....\n"); - /* asynchronizely release allocated memory for buffer entry here */ - entry->use = 0; + /* 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); + } - V3_Net_Print(2, "vnet_tx_flush: pkt (size %d)\n", entry->pkt.size); + v3_enqueue(vnet_state.poll_devs, (addr_t)dev); + } + }else { /* no device needs to be polled */ + /* sleep here? */ + Vnet_Yield(); } } + + return 0; } -#endif + int v3_init_vnet() { memset(&vnet_state, 0, sizeof(vnet_state)); @@ -754,21 +746,21 @@ int v3_init_vnet() { vnet_state.num_devs = 0; vnet_state.num_routes = 0; - if (v3_lock_init(&(vnet_state.lock)) == -1){ - PrintError("VNET/P Core: Fails to initiate lock\n"); + if (vnet_lock_init(&(vnet_state.lock)) == -1){ + PrintError("VNET/P: Fails to initiate lock\n"); } - vnet_state.route_cache = v3_create_htable(0, &hash_fn, &hash_eq); + vnet_state.route_cache = vnet_create_htable(0, &hash_fn, &hash_eq); if (vnet_state.route_cache == NULL) { - PrintError("VNET/P Core: Fails to initiate route cache\n"); + PrintError("VNET/P: Fails to initiate route cache\n"); return -1; } - v3_lock_init(&(vnet_state.pkt_q.lock)); + vnet_state.poll_devs = v3_create_queue(); - //vnet_state.pkt_flush_thread = V3_CREATE_THREAD(vnet_tx_flush, NULL, "VNET_Pkts"); + vnet_state.pkt_flush_thread = vnet_start_thread(vnet_tx_flush, NULL, "vnetd"); - PrintDebug("VNET/P Core is initiated\n"); + Vnet_Debug("VNET/P is initiated\n"); return 0; } @@ -776,13 +768,13 @@ int v3_init_vnet() { void v3_deinit_vnet(){ - v3_lock_deinit(&(vnet_state.lock)); + vnet_lock_deinit(&(vnet_state.lock)); - free_devices(); - free_routes(); + deinit_devices_list(); + deinit_routes_list(); - v3_free_htable(vnet_state.route_cache, 1, 1); - V3_Free(vnet_state.bridge); + vnet_free_htable(vnet_state.route_cache, 1, 1); + Vnet_Free(vnet_state.bridge); }