Change the 2LS reflected fault op to take a ctx
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 21 Jan 2016 20:49:47 +0000 (15:49 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 2 Feb 2016 22:43:52 +0000 (17:43 -0500)
VM exits are another type of reflected fault.  The existing reflected fault
code assumes they are hardware faults.  For the most part, the handling of
the two types of contexts is the same, as far as uthread.c is concerned.

By passing the context, instead of interpretting the context, directly to
the 2LS, we'll eventually be able to handle VM exits as well, without the
parlib / uthread code caring at all.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
user/parlib/include/uthread.h
user/parlib/thread0_sched.c
user/parlib/uthread.c
user/pthread/pthread.c

index 252cc0a..b108110 100644 (file)
@@ -50,8 +50,7 @@ struct schedule_ops {
        void (*thread_paused)(struct uthread *);
        void (*thread_blockon_sysc)(struct uthread *, void *);
        void (*thread_has_blocked)(struct uthread *, int);
-       void (*thread_refl_fault)(struct uthread *, unsigned int, unsigned int,
-                                                         unsigned long);
+       void (*thread_refl_fault)(struct uthread *, struct user_context *);
        /**** Defining these functions is optional. ****/
        /* 2LSs can leave the mutex funcs empty for a default implementation */
        uth_mutex_t (*mutex_alloc)(void);
index e0b7f9f..953f849 100644 (file)
 #include <parlib/vcore.h>
 #include <parlib/uthread.h>
 #include <parlib/event.h>
+#include <parlib/arch/trap.h>
 #include <stdlib.h>
 
 static void thread0_sched_entry(void);
 static void thread0_thread_blockon_sysc(struct uthread *uthread, void *sysc);
-static void thread0_thread_refl_fault(struct uthread *uthread,
-                                      unsigned int trap_nr, unsigned int err,
-                                      unsigned long aux);
+static void thread0_thread_refl_fault(struct uthread *uth,
+                                      struct user_context *ctx);
 static void thread0_thread_runnable(struct uthread *uth);
 static void thread0_thread_has_blocked(struct uthread *uth, int flags);
 static uth_mutex_t thread0_mtx_alloc(void);
@@ -96,15 +96,21 @@ static void thread0_thread_blockon_sysc(struct uthread *uthread, void *arg)
                thread0_thread_runnable(uthread);
 }
 
-static void thread0_thread_refl_fault(struct uthread *uthread,
-                                      unsigned int trap_nr, unsigned int err,
-                                      unsigned long aux)
+static void thread0_thread_refl_fault(struct uthread *uth,
+                                      struct user_context *ctx)
 {
-       printf("SCP has unhandled fault: %d, err: %d, aux: %p\n", trap_nr, err,
-              aux);
-       print_user_context(&uthread->u_ctx);
-       printf("Turn on printx to spew unhandled, malignant trap info\n");
-       exit(-1);
+       switch (ctx->type) {
+       case ROS_HW_CTX:
+               printf("SCP has unhandled fault: %d, err: %d, aux: %p\n",
+                      __arch_refl_get_nr(ctx), __arch_refl_get_err(ctx),
+                      __arch_refl_get_aux(ctx));
+               print_user_context(ctx);
+               printf("Turn on printx to spew unhandled, malignant trap info\n");
+               exit(-1);
+               break;
+       default:
+               assert(0);
+       }
 }
 
 static void thread0_thread_runnable(struct uthread *uth)
index ba9a74b..3f04979 100644 (file)
@@ -576,9 +576,7 @@ static void set_uthread_tls(struct uthread *uthread, uint32_t vcoreid)
 /* Attempts to handle a fault for uth, etc */
 static void handle_refl_fault(struct uthread *uth, struct user_context *ctx)
 {
-       sched_ops->thread_refl_fault(uth, __arch_refl_get_nr(ctx),
-                                    __arch_refl_get_err(ctx),
-                                    __arch_refl_get_aux(ctx));
+       sched_ops->thread_refl_fault(uth, ctx);
 }
 
 /* Run the thread that was current_uthread, from a previous run.  Should be
index bc71697..51b1363 100644 (file)
@@ -42,8 +42,8 @@ static void pth_thread_runnable(struct uthread *uthread);
 static void pth_thread_paused(struct uthread *uthread);
 static void pth_thread_blockon_sysc(struct uthread *uthread, void *sysc);
 static void pth_thread_has_blocked(struct uthread *uthread, int flags);
-static void pth_thread_refl_fault(struct uthread *uthread, unsigned int trap_nr,
-                                  unsigned int err, unsigned long aux);
+static void pth_thread_refl_fault(struct uthread *uth,
+                                  struct user_context *ctx);
 
 /* Event Handlers */
 static void pth_handle_syscall(struct event_msg *ev_msg, unsigned int ev_type,
@@ -305,8 +305,9 @@ static void handle_page_fault(struct uthread *uthread, unsigned int err,
        }
 }
 
-static void pth_thread_refl_fault(struct uthread *uthread, unsigned int trap_nr,
-                                  unsigned int err, unsigned long aux)
+static void pth_thread_refl_hw_fault(struct uthread *uthread,
+                                     unsigned int trap_nr,
+                                     unsigned int err, unsigned long aux)
 {
        struct pthread_tcb *pthread = (struct pthread_tcb*)uthread;
 
@@ -334,6 +335,23 @@ static void pth_thread_refl_fault(struct uthread *uthread, unsigned int trap_nr,
        }
 }
 
+static void pth_thread_refl_fault(struct uthread *uth,
+                                  struct user_context *ctx)
+{
+       switch (ctx->type) {
+       case ROS_HW_CTX:
+               pth_thread_refl_hw_fault(uth, __arch_refl_get_nr(ctx),
+                                        __arch_refl_get_err(ctx),
+                                        __arch_refl_get_aux(ctx));
+               break;
+       case ROS_VM_CTX:
+               /* TODO: (VMCTX) the pthread 2LS might not bother with this */
+               break;
+       default:
+               assert(0);
+       }
+}
+
 /* Akaros pthread extensions / hacks */
 
 /* Tells the pthread 2LS to not change the number of vcores.  This means it will