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.


Basic HVM data structures and functions
[palacios.git] / palacios / src / palacios / vmm_barrier.c
index f887a05..a94e40f 100644 (file)
@@ -93,6 +93,10 @@ int v3_wait_for_barrier(struct v3_vm_info * vm_info, struct guest_info * local_c
     int all_blocked = 0;
     int i = 0;
 
+    if (barrier->active == 0) {
+       return -1;
+    }
+
     // wait for barrier catch on all cores
     while (all_blocked == 0) {
        all_blocked = 1;
@@ -116,7 +120,8 @@ int v3_wait_for_barrier(struct v3_vm_info * vm_info, struct guest_info * local_c
            break;
        }
 
-       v3_yield(local_core);
+        // return immediately and spin if there is no one to yield to 
+       v3_yield(local_core,-1);
     }
 
     return 0;
@@ -137,6 +142,12 @@ int v3_wait_for_barrier(struct v3_vm_info * vm_info, struct guest_info * local_c
 int v3_raise_barrier(struct v3_vm_info * vm_info, struct guest_info * local_core) {
     int ret = 0;
 
+
+    if ((vm_info->run_state != VM_RUNNING) && 
+       (vm_info->run_state != VM_SIMULATING)) {
+       return 0;
+    }
+
     ret = v3_raise_barrier_nowait(vm_info, local_core);
 
     if (ret != 0) {
@@ -158,6 +169,12 @@ int v3_raise_barrier(struct v3_vm_info * vm_info, struct guest_info * local_core
 int v3_lower_barrier(struct v3_vm_info * vm_info) {
     struct v3_barrier * barrier = &(vm_info->barrier);
 
+    
+    if ((vm_info->run_state != VM_RUNNING) && 
+       (vm_info->run_state != VM_SIMULATING)) {
+       return 0;
+    }
+
     // Clear the active flag, so cores won't wait 
     barrier->active = 0;
 
@@ -181,8 +198,15 @@ int v3_wait_at_barrier(struct guest_info * core) {
     if (barrier->active == 0) {
        return 0;
     }
+#ifndef V3_CONFIG_FP_SWITCH
+    v3_get_fp_state(core); // snapshot FP state now
+#else
+#   ifdef V3_CONFIG_LAZY_FP_SWITCH
+    v3_get_fp_state(core); // snapshot FP state now regardless of lazy eval
+#   endif
+#endif
 
-    V3_Print("Core %d waiting at barrier\n", core->vcpu_id);
+    V3_Print(core->vm_info, core, "Core %d waiting at barrier\n", core->vcpu_id);
 
     /*  Barrier has been activated. 
      *  Wait here until it's lowered
@@ -191,12 +215,21 @@ int v3_wait_at_barrier(struct guest_info * core) {
     
     // set cpu bit in barrier bitmap
     v3_bitmap_set(&(barrier->cpu_map), core->vcpu_id);
-    V3_Print("Core %d bit set as waiting\n", core->vcpu_id);
+    V3_Print(core->vm_info, core, "Core %d bit set as waiting\n", core->vcpu_id);
 
     // wait for cpu bit to clear
     while (v3_bitmap_check(&(barrier->cpu_map), core->vcpu_id)) {
-       v3_yield(core);
+        // Barrier wait will spin if there is no competing work
+       v3_yield(core,-1);
     }
 
+#ifndef V3_CONFIG_FP_SWITCH    
+    core->fp_state.need_restore=1;  // restore FP on next entry
+#else
+#   ifdef V3_CONFIG_LAZY_FP_SWITCH
+    core->fp_state.need_restore=1;  // restore FP on next entry
+#   endif
+#endif
+
     return 0;
 }