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.


Resource control extensions to host OS interface
[palacios.git] / palacios / include / vnet / vnet_host.h
index 47f6481..ec6a28c 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef __VNET_HOST_H__
 #define __VNET_HOST_H__
 
+#include <vnet/vnet_base.h>
 #include <vnet/vnet_vmm.h>
 
 struct vnet_thread {
@@ -30,31 +31,38 @@ struct vnet_timer {
     void * host_timer;
 };
 
-typedef addr_t vnet_lock_t;
-
+typedef unsigned long vnet_lock_t;
+typedef void *vnet_intr_flags_t;
 
 
 struct vnet_host_hooks {
-    void *(*thread_start)(int (*fn)(void * arg), void * arg, char * thread_name);
-    void (*thread_sleep)(int timeout);
+    void *(*thread_start)(int (*fn)(void * arg), 
+                         void * arg, 
+                         char * thread_name,
+                          v3_resource_control_t *resource_control);
+
+    void (*thread_sleep)(long timeout);
     void (*thread_wakeup)(void * thread);
     void (*thread_stop)(void * thread);
-    int (*thread_should_stop)();
+    int (*thread_should_stop)(void);
+
+    void *(*timer_create)(unsigned long interval, 
+                         void (* timer_fun)(void * priv_data), 
+                         void * data);
 
-    void *(*timer_create)(unsigned long interval, void (* timer_fun)(void * priv_data), void * data);
     void (*timer_del)(void * timer);
-    int (*timer_start)(void * timer);
-    int (*timer_stop)(void * timer);
+    void (*timer_start)(void * timer);
+    void (*timer_stop)(void * timer);
     void (*timer_reset)(void * timer, unsigned long interval);
 
     void (*udelay)(unsigned long usecs);
 
     /* duplicate part from os_hooks */
     void (*yield_cpu)(void); 
-    void (*print)(const char * format, ...)
-       __attribute__ ((format (printf, 1, 2)));
+    void (*print)(void *vm , int core, const char * format, ...)
+       __attribute__ ((format (printf, 3, 4)));
   
-    void *(*allocate_pages)(int num_pages, unsigned int alignment);
+    void *(*allocate_pages)(int num_pages, unsigned int alignment, int node_id);
     void (*free_pages)(void * page, int num_pages);
 
     void *(*malloc)(unsigned int size);
@@ -67,10 +75,14 @@ struct vnet_host_hooks {
     void (*mutex_free)(void * mutex);
     void (*mutex_lock)(void * mutex, int must_spin);
     void (*mutex_unlock)(void * mutex);
+    vnet_intr_flags_t (*mutex_lock_irqsave)(void * mutex, int must_spin);
+    void (*mutex_unlock_irqrestore)(void * mutex, vnet_intr_flags_t flags);
 };
 
 
 
+#ifdef __V3VEE__
+
 extern struct vnet_host_hooks * host_hooks;
 
 
@@ -81,7 +93,7 @@ extern struct vnet_host_hooks * host_hooks;
 /* 4KB-aligned */
 static inline void * Vnet_AllocPages(int num_pages){
     if ((host_hooks) && host_hooks->allocate_pages) {
-       return host_hooks->allocate_pages(num_pages, PAGE_SIZE_4KB);
+       return host_hooks->allocate_pages(num_pages, PAGE_SIZE_4KB,-1); 
     }
 
     return NULL;
@@ -101,7 +113,7 @@ static inline void * Vnet_VAddr(void * addr) {
     return NULL;
 }
 
-static inline void * Vnet_PAddr(void *addr) {
+static inline void * Vnet_PAddr(void * addr) {
     if ((host_hooks) && host_hooks->vaddr_to_paddr) {
        return host_hooks->vaddr_to_paddr(addr);
     }
@@ -124,15 +136,14 @@ static inline void Vnet_Free(void * addr){
 }
 
 
-static inline void Vnet_Yield(){
+static inline void Vnet_Yield(void){
     if ((host_hooks) && (host_hooks)->yield_cpu) {
        host_hooks->yield_cpu();
     }
 }
 
 /* THREAD FUNCTIONS */
-struct vnet_thread * vnet_start_thread(int (*func)(void *), 
-                                      void *arg, char * name);
+struct vnet_thread * vnet_start_thread(int (*func)(void *), void *arg, char * name);
 
 static inline void vnet_thread_sleep(long timeout){
     if((host_hooks) && host_hooks->thread_sleep){
@@ -153,7 +164,7 @@ static inline void vnet_thread_stop(struct vnet_thread * thread){
     }
 }
 
-static inline int vnet_thread_should_stop(){
+static inline int vnet_thread_should_stop(void){
     if((host_hooks) && host_hooks->thread_should_stop){
        return host_hooks->thread_should_stop();
     }
@@ -180,23 +191,20 @@ static inline void vnet_del_timer(struct vnet_timer * timer){
     }
 }
        
-static inline int vnet_start_timer(struct vnet_timer * timer){
+static inline void vnet_start_timer(struct vnet_timer * timer){
     if((host_hooks) && host_hooks->timer_start){
-       return host_hooks->timer_start(timer->host_timer);
+       host_hooks->timer_start(timer->host_timer);
     }
-
-    return -1;
 }
 
-static inline int vnet_stop_timer(struct vnet_timer * timer){
+static inline void vnet_stop_timer(struct vnet_timer * timer){
     if((host_hooks) && host_hooks->timer_stop){
-       return host_hooks->timer_stop(timer->host_timer);
+       host_hooks->timer_stop(timer->host_timer);
     }
-
-    return -1;
 }
 
-static inline void vnet_reset_timer(struct vnet_timer * timer, unsigned long new_interval){
+static inline void vnet_reset_timer(struct vnet_timer * timer, 
+                                   unsigned long new_interval){
     if((host_hooks) && host_hooks->timer_reset){
        host_hooks->timer_reset(timer->host_timer, new_interval);
     }
@@ -206,57 +214,78 @@ static inline void vnet_reset_timer(struct vnet_timer * timer, unsigned long new
 
 #define Vnet_Print(level, fmt, args...)                                        \
     do {                                                               \
-       extern int vnet_debug;                                          \
-       if(level <= vnet_debug) {                                       \
+       extern int net_debug;                                           \
+       if(level <= net_debug) {                                        \
            extern struct vnet_host_hooks * host_hooks;                 \
            if ((host_hooks) && (host_hooks)->print) {                  \
-               (host_hooks)->print((fmt), ##args);                     \
+             (host_hooks)->print(0, -1, (fmt), ##args);                        \
            }                                                           \
        }                                                               \
     } while (0)        
 
 
-#define Vnet_Debug(fmt, args...)                                       \
+#define Vnet_Debug(fmt, args...)                               \
     do {                                                               \
-       extern struct vnet_host_hooks * host_hooks;                     \
-       if ((host_hooks) && (host_hooks)->print) {                      \
-           (host_hooks)->print((fmt), ##args);                         \
-       }                                                               \
+           extern struct vnet_host_hooks * host_hooks;                 \
+           if ((host_hooks) && (host_hooks)->print) {                  \
+             (host_hooks)->print(0, -1, (fmt), ##args);                        \
+           }                                                           \
     } while (0)        
 
 
 
+
 /* Lock Utilities */
-int vnet_lock_init(vnet_lock_t * lock);
+static inline int vnet_lock_init(vnet_lock_t * lock) {
+    if((host_hooks) && host_hooks->mutex_alloc){
+       *lock = (addr_t)(host_hooks->mutex_alloc());
+       if (*lock) {
+           return 0;
+       }
+    }
+    return -1;
+}
 
 static inline void vnet_lock_deinit(vnet_lock_t * lock) {
-    host_hooks->mutex_free((void *)*lock);
-    *lock = 0;
+    if (host_hooks && (host_hooks->mutex_free)) { 
+       host_hooks->mutex_free((void *)*lock);
+       *lock = 0;
+    }
 }
 
 static inline void vnet_lock(vnet_lock_t lock) {
-    host_hooks->mutex_lock((void *)lock, 0);    
+    if (host_hooks && (host_hooks->mutex_lock)) { 
+       host_hooks->mutex_lock((void *)lock,0);    
+    }
 }
 
 static inline void vnet_unlock(vnet_lock_t lock) {
-    host_hooks->mutex_unlock((void *)lock);
+    if (host_hooks && (host_hooks->mutex_lock)) { 
+       host_hooks->mutex_unlock((void *)lock);
+    }
 }
 
-static inline addr_t vnet_lock_irqsave(vnet_lock_t lock) {
-    addr_t irq_state = v3_irq_save();
-    host_hooks->mutex_lock((void *)lock, 1);
-    return irq_state;
+static inline vnet_intr_flags_t vnet_lock_irqsave(vnet_lock_t lock) 
+{
+    if (host_hooks && host_hooks->mutex_lock_irqsave) { 
+       return (host_hooks->mutex_lock_irqsave((void *)lock, 1));
+    } else {
+       return NULL;
+    }
 }
 
 
-static inline void vnet_unlock_irqrestore(vnet_lock_t lock, addr_t irq_state) {
-    host_hooks->mutex_unlock((void *)lock);
-    v3_irq_restore(irq_state);
+static inline void vnet_unlock_irqrestore(vnet_lock_t lock, vnet_intr_flags_t irq_state) 
+{
+    if (host_hooks && (host_hooks->mutex_unlock_irqrestore)) {
+       host_hooks->mutex_unlock_irqrestore((void *)lock,irq_state);
+    }
 }
-
+#endif
 
 
 void init_vnet(struct vnet_host_hooks * hooks);
+void deinit_vnet(void);
 
 
 #endif