summaryrefslogtreecommitdiff
path: root/sys/src/9/port/taslock.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2014-06-05 21:54:32 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2014-06-05 21:54:32 +0200
commit91614f582fb1504ae3be2d57c079f24b60d71613 (patch)
tree47382b0ee5f71cccc75f1e08f8ef7ff9e216765e /sys/src/9/port/taslock.c
parent76db435e3cf86e0a6eb750d789bc15b64027a379 (diff)
kernel: dont use atomic increment for Proc.nlocks, maintain Lock.m for lock(), use uintptr intstead of long for pc values
change Proc.nlocks from Ref to int and just use normal increment and decrelemt as done in erik quanstros 9atom. It is not clear why we used atomic increment in the fist place as even if we get preempted by interrupt and scheduled before we write back the incremented value, it shouldnt be a problem and we'll just continue where we left off as our process is the only one that can write to it. Yoann Padioleau found that the Mach pointer Lock.m wasnt maintained consistently for lock() vs canlock() and ilock(). Fixed. Use uintptr instead of ulong for maxlockpc, maxilockpc and ilockpc debug variables.
Diffstat (limited to 'sys/src/9/port/taslock.c')
-rw-r--r--sys/src/9/port/taslock.c41
1 files changed, 13 insertions, 28 deletions
diff --git a/sys/src/9/port/taslock.c b/sys/src/9/port/taslock.c
index 641b84d16..730538ba7 100644
--- a/sys/src/9/port/taslock.c
+++ b/sys/src/9/port/taslock.c
@@ -10,8 +10,8 @@ long maxlockcycles;
long maxilockcycles;
long cumlockcycles;
long cumilockcycles;
-ulong maxlockpc;
-ulong maxilockpc;
+uintptr maxlockpc;
+uintptr maxilockpc;
struct
{
@@ -21,23 +21,6 @@ struct
} lockstats;
static void
-inccnt(Ref *r)
-{
- _xinc(&r->ref);
-}
-
-static int
-deccnt(Ref *r)
-{
- int x;
-
- x = _xdec(&r->ref);
- if(x < 0)
- panic("deccnt pc=%#p", getcallerpc(&r));
- return x;
-}
-
-static void
dumplockmem(char *tag, Lock *l)
{
uchar *cp;
@@ -73,12 +56,13 @@ lock(Lock *l)
lockstats.locks++;
if(up)
- inccnt(&up->nlocks); /* prevent being scheded */
+ up->nlocks++; /* prevent being scheded */
if(tas(&l->key) == 0){
if(up)
up->lastlock = l;
l->pc = pc;
l->p = up;
+ l->m = MACHP(m->machno);
l->isilock = 0;
#ifdef LOCKCYCLES
l->lockcycles = -lcycles();
@@ -86,7 +70,7 @@ lock(Lock *l)
return 0;
}
if(up)
- deccnt(&up->nlocks);
+ up->nlocks--;
lockstats.glare++;
for(;;){
@@ -108,12 +92,13 @@ lock(Lock *l)
}
}
if(up)
- inccnt(&up->nlocks);
+ up->nlocks++;
if(tas(&l->key) == 0){
if(up)
up->lastlock = l;
l->pc = pc;
l->p = up;
+ l->m = MACHP(m->machno);
l->isilock = 0;
#ifdef LOCKCYCLES
l->lockcycles = -lcycles();
@@ -121,7 +106,7 @@ lock(Lock *l)
return 1;
}
if(up)
- deccnt(&up->nlocks);
+ up->nlocks--;
}
}
@@ -159,8 +144,8 @@ acquire:
l->sr = x;
l->pc = pc;
l->p = up;
- l->isilock = 1;
l->m = MACHP(m->machno);
+ l->isilock = 1;
#ifdef LOCKCYCLES
l->lockcycles = -lcycles();
#endif
@@ -170,10 +155,10 @@ int
canlock(Lock *l)
{
if(up)
- inccnt(&up->nlocks);
+ up->nlocks++;
if(tas(&l->key)){
if(up)
- deccnt(&up->nlocks);
+ up->nlocks--;
return 0;
}
@@ -210,7 +195,7 @@ unlock(Lock *l)
l->key = 0;
coherence();
- if(up && deccnt(&up->nlocks) == 0 && up->delaysched && islo()){
+ if(up && --up->nlocks == 0 && up->delaysched && islo()){
/*
* Call sched if the need arose while locks were held
* But, don't do it from interrupt routines, hence the islo() test
@@ -219,7 +204,7 @@ unlock(Lock *l)
}
}
-ulong ilockpcs[0x100] = { [0xff] = 1 };
+uintptr ilockpcs[0x100] = { [0xff] = 1 };
static int n;
void