A hokey cilk abort -- enough to abort exec

上级 b589989b
...@@ -263,23 +263,25 @@ struct work * allocwork(void); ...@@ -263,23 +263,25 @@ struct work * allocwork(void);
void freework(struct work *w); void freework(struct work *w);
// cilk.c // cilk.c
void initcilkframe(struct cilkframe*);
#if CILKENABLE #if CILKENABLE
void cilk_push(void (*fn)(uptr, uptr), u64 arg0, u64 arg1); void cilk_push(void (*fn)(uptr, uptr), u64 arg0, u64 arg1);
void cilk_start(void); void cilk_start(void);
void cilk_end(void); u64 cilk_end(void);
void cilk_dump(void); void cilk_dump(void);
int cilk_trywork(void); void cilk_abort(u64 val);
void initcilkframe(struct cilkframe *wq);
#else #else
#define cilk_push(rip, arg0, arg1) do { \ #define cilk_push(rip, arg0, arg1) do { \
void (*fn)(uptr, uptr) = rip; \ void (*fn)(uptr, uptr) = rip; \
fn(arg0, arg1); \ fn(arg0, arg1); \
} while(0) } while(0)
#define cilk_start() do { } while(0) #define cilk_start() do { } while(0)
#define cilk_end() do { } while(0)
#define cilk_end() (myproc()->cilkframe.abort)
#define cilk_dump() do { } while(0) #define cilk_dump() do { } while(0)
#define cilk_trywork() 0 #define cilk_abort(val) do { \
#define initcilkframe(x) do { } while (0) cmpxch(&myproc()->cilkframe.abort, (u64)0, (u64)val); \
} while (0)
#endif #endif
// other exported/imported functions // other exported/imported functions
......
...@@ -19,6 +19,7 @@ struct context { ...@@ -19,6 +19,7 @@ struct context {
// Work queue frame // Work queue frame
struct cilkframe { struct cilkframe {
volatile std::atomic<u64> ref; volatile std::atomic<u64> ref;
volatile std::atomic<u64> abort;
}; };
// Per-process, per-stack meta data for mtrace // Per-process, per-stack meta data for mtrace
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
// cprintf("%c %c\n", arg[0], arg[1]); // cprintf("%c %c\n", arg[0], arg[1]);
// } // }
#if CILKENABLE
#include "types.h" #include "types.h"
#include "kernel.hh" #include "kernel.hh"
#include "amd64.h" #include "amd64.h"
...@@ -34,6 +33,8 @@ ...@@ -34,6 +33,8 @@
#include "condvar.h" #include "condvar.h"
#include "queue.h" #include "queue.h"
#include "proc.hh" #include "proc.hh"
#if CILKENABLE
#include "mtrace.h" #include "mtrace.h"
#include "wq.hh" #include "wq.hh"
#include "percpu.hh" #include "percpu.hh"
...@@ -62,7 +63,8 @@ __cilk_run(struct work *w, void *xfn, void *arg0, void *arg1, void *xframe) ...@@ -62,7 +63,8 @@ __cilk_run(struct work *w, void *xfn, void *arg0, void *arg1, void *xframe)
stat->steal++; stat->steal++;
mycpu()->cilkframe = frame; mycpu()->cilkframe = frame;
fn((uptr)arg0, (uptr)arg1); if (frame->abort == 0)
fn((uptr)arg0, (uptr)arg1);
mycpu()->cilkframe = old; mycpu()->cilkframe = old;
frame->ref--; frame->ref--;
} }
...@@ -110,14 +112,26 @@ cilk_start(void) ...@@ -110,14 +112,26 @@ cilk_start(void)
// End of the current work queue frame. // End of the current work queue frame.
// The core works while the reference count of the current // The core works while the reference count of the current
// work queue frame is not 0. // work queue frame is not 0.
void u64
cilk_end(void) cilk_end(void)
{ {
u64 r;
while (cilk_frame()->ref != 0) while (cilk_frame()->ref != 0)
wq_trywork(); wq_trywork();
r = cilk_frame()->abort;
mycpu()->cilkframe = 0; mycpu()->cilkframe = 0;
popcli(); popcli();
return r;
}
void
cilk_abort(u64 val)
{
cmpxch(&cilk_frame()->abort, (u64)0, val);
} }
void void
...@@ -161,10 +175,11 @@ testcilk(void) ...@@ -161,10 +175,11 @@ testcilk(void)
} }
popcli(); popcli();
} }
#endif // CILKENABLE
void void
initcilkframe(struct cilkframe *cilk) initcilkframe(struct cilkframe *cilk)
{ {
memset(cilk, 0, sizeof(*cilk)); cilk->ref = 0;
cilk->abort = 0;
} }
#endif // CILKENABLE
...@@ -65,10 +65,10 @@ dosegment(uptr a0, u64 a1) ...@@ -65,10 +65,10 @@ dosegment(uptr a0, u64 a1)
} }
bad: bad:
panic("dosegment: Oops"); cilk_abort(-1);
} }
static void dostack(uptr a0, u64 a1) static void __attribute__((unused)) dostack(uptr a0, u64 a1)
{ {
struct vmnode *vmn = nullptr; struct vmnode *vmn = nullptr;
struct eargs *args = (eargs*) a0; struct eargs *args = (eargs*) a0;
...@@ -112,16 +112,17 @@ static void dostack(uptr a0, u64 a1) ...@@ -112,16 +112,17 @@ static void dostack(uptr a0, u64 a1)
last = s+1; last = s+1;
safestrcpy(args->proc->name, last, sizeof(args->proc->name)); safestrcpy(args->proc->name, last, sizeof(args->proc->name));
// XXX(sbw) Oops, don't want to do this, unless we have abort
args->proc->tf->rsp = sp; args->proc->tf->rsp = sp;
prof_end(dostack_prof); prof_end(dostack_prof);
return; return;
bad: bad:
panic("dostack: Oops"); cilk_abort(-1);
} }
static void doheap(uptr a0, u64 a1) static void __attribute__((unused)) doheap(uptr a0, u64 a1)
{ {
struct vmnode *vmn = nullptr; struct vmnode *vmn = nullptr;
struct eargs *args = (eargs*) a0; struct eargs *args = (eargs*) a0;
...@@ -138,7 +139,7 @@ static void doheap(uptr a0, u64 a1) ...@@ -138,7 +139,7 @@ static void doheap(uptr a0, u64 a1)
return; return;
bad: bad:
panic("doheap: Oops"); cilk_abort(-1);
} }
int int
...@@ -204,7 +205,8 @@ exec(const char *path, char **argv) ...@@ -204,7 +205,8 @@ exec(const char *path, char **argv)
//cilk_push(dostack, (uptr)&args, (uptr)0); //cilk_push(dostack, (uptr)&args, (uptr)0);
dostack((uptr)&args, (uptr)0); dostack((uptr)&args, (uptr)0);
cilk_end(); if (cilk_end())
goto bad;
// Commit to the user image. // Commit to the user image.
oldvmap = myproc()->vmap; oldvmap = myproc()->vmap;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论