vthread: allow programs to have threads exit on halt.
authorRonald G. Minnich <rminnich@gmail.com>
Thu, 8 Sep 2016 16:51:26 +0000 (09:51 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 12 Sep 2016 13:21:08 +0000 (09:21 -0400)
For example, a benchmark declares the vm as follows:
struct virtual_machine vm = {.halt_exit = true,};

Which will force guests that halt to exit.

Change-Id: Ie6368093072f324c86c9ace1807075cd073d540c
Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
user/vmm/include/vmm/sched.h
user/vmm/include/vmm/vmm.h
user/vmm/vmexit.c
user/vmm/vthread.c

index 403ca3f..a098cf7 100644 (file)
@@ -30,6 +30,7 @@ struct guest_thread {
        struct uthread                          uthread;
        struct ctlr_thread                      *buddy;
        unsigned int                            gpc_id;
+       bool                                            halt_exit;
        uth_mutex_t                                     halt_mtx;
        uth_cond_var_t                          halt_cv;
 };
index e5f3f35..65ddd4a 100644 (file)
@@ -40,6 +40,9 @@ struct virtual_machine {
         * where all guests share a page table. It's not required
         * however. */
        void                                            *root;
+
+       /* Default value for whether guest threads halt on an exit. */
+       bool                                            halt_exit;
 };
 
 char *regname(uint8_t reg);
index 9ab6f44..4404ec9 100644 (file)
@@ -190,6 +190,8 @@ static bool handle_halt(struct guest_thread *gth)
 {
        struct vm_trapframe *vm_tf = gth_to_vmtf(gth);
 
+       if (gth->halt_exit)
+               return FALSE;
        /* It's possible the guest disabled IRQs and halted, perhaps waiting on an
         * NMI or something.  If we need to support that, we can change this.  */
        sleep_til_irq(gth);
index e7963e5..5ef8d4c 100644 (file)
@@ -103,6 +103,7 @@ static int vmsetup(struct virtual_machine *vm, int flags)
                return ret;
 
        for (i = 0; i < vm->nr_gpcs; i++) {
+               vm->gths[i]->halt_exit = vm->halt_exit;
                vm_tf = gth_to_vmtf(vm->gths[i]);
                vm_tf->tf_cr3 = (uint64_t)p512;
        }