提交 0538397f 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

inline range::lock

上级 1c96fd2f
...@@ -88,7 +88,7 @@ struct range : public rcu_freed { ...@@ -88,7 +88,7 @@ struct range : public rcu_freed {
const int nlevel; // the number of levels this range should appear const int nlevel; // the number of levels this range should appear
crange *const cr; // the crange this range is part of crange *const cr; // the crange this range is part of
markptr<range>* const next; // one next pointer per level markptr<range>* const next; // one next pointer per level
spinlock *lock; // on separate cache line? spinlock lock; // on separate cache line?
void print(int l); void print(int l);
void dec_ref(void); void dec_ref(void);
...@@ -166,7 +166,7 @@ struct crange_locked { ...@@ -166,7 +166,7 @@ struct crange_locked {
for (range *e = prev_; e && e != succ_; e = n) { for (range *e = prev_; e && e != succ_; e = n) {
// as soon a we release, the next pointer can change, so read it first // as soon a we release, the next pointer can change, so read it first
n = e->next[0].ptr(); n = e->next[0].ptr();
release(e->lock); release(&e->lock);
} }
} }
} }
......
...@@ -87,12 +87,11 @@ range::~range() ...@@ -87,12 +87,11 @@ range::~range()
{ {
//dprintf("%d: range_free: 0x%lx 0x%lx-0x%lx(%ld)\n", myproc()->cpuid, (u64) this, key, key+size, size); //dprintf("%d: range_free: 0x%lx 0x%lx-0x%lx(%ld)\n", myproc()->cpuid, (u64) this, key, key+size, size);
cr->check(this); cr->check(this);
// assert(curlevel == -1); // assert(curlevel == -1);
for (int l = 0; l < nlevel; l++) { for (int l = 0; l < nlevel; l++) {
next[l] = (struct range *) 0xDEADBEEF; next[l] = (struct range *) 0xDEADBEEF;
} }
destroylock(lock); destroylock(&lock);
kmalignfree(lock, CACHELINE, sizeof(struct spinlock));
delete[] next; delete[] next;
} }
...@@ -118,9 +117,7 @@ range::range(crange *crarg, u64 k, u64 sz, int nl) ...@@ -118,9 +117,7 @@ range::range(crange *crarg, u64 k, u64 sz, int nl)
assert(cr->nlevel > 0); assert(cr->nlevel > 0);
assert(next); assert(next);
for (int l = 0; l < nlevel; l++) next[l] = 0; for (int l = 0; l < nlevel; l++) next[l] = 0;
assert(kmalign((void **) &lock, CACHELINE, initlock(&lock, "crange", LOCKSTAT_CRANGE);
sizeof(struct spinlock)) == 0);
initlock(lock, "crange", LOCKSTAT_CRANGE);
} }
// //
...@@ -132,11 +129,11 @@ int ...@@ -132,11 +129,11 @@ int
range::lockif(markptr<range> e) range::lockif(markptr<range> e)
{ {
assert(!e.mark()); assert(!e.mark());
acquire(lock); acquire(&lock);
if (next[0] == e) { if (next[0] == e) {
return 1; return 1;
} }
release(lock); release(&lock);
// cprintf("%d: range_lock_pred: retry %u\n", mycpu()->id, key); // cprintf("%d: range_lock_pred: retry %u\n", mycpu()->id, key);
return 0; return 0;
} }
...@@ -329,7 +326,7 @@ crange::lock_range(u64 k, u64 sz, int l, range **er, range **pr, range **fr, ran ...@@ -329,7 +326,7 @@ crange::lock_range(u64 k, u64 sz, int l, range **er, range **pr, range **fr, ran
assert(*fr); assert(*fr);
*lr = e; *lr = e;
if (l == 0) { if (l == 0) {
acquire(e->lock); // lock all ranges in the sequence acquire(&e->lock); // lock all ranges in the sequence
} }
e = e->next[l].ptr(); e = e->next[l].ptr();
} }
...@@ -444,7 +441,7 @@ crange_locked::replace(range *prev, range *repl) ...@@ -444,7 +441,7 @@ crange_locked::replace(range *prev, range *repl)
range *newlast = 0; range *newlast = 0;
for (range *e = repl; e; e = e->next[0].ptr()) { for (range *e = repl; e; e = e->next[0].ptr()) {
assert(e->key >= base_ && e->key + e->size <= base_ + size_); assert(e->key >= base_ && e->key + e->size <= base_ + size_);
acquire(e->lock); acquire(&e->lock);
newlast = e; newlast = e;
} }
...@@ -458,7 +455,7 @@ crange_locked::replace(range *prev, range *repl) ...@@ -458,7 +455,7 @@ crange_locked::replace(range *prev, range *repl)
crange::mark(replaced, succ_); crange::mark(replaced, succ_);
for (range *e = replaced; e && e != succ_; e = e->next[0].ptr()) { for (range *e = replaced; e && e != succ_; e = e->next[0].ptr()) {
release(e->lock); release(&e->lock);
e->dec_ref(); e->dec_ref();
} }
} }
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论