A hokey cilk abort -- enough to abort exec

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