summaryrefslogtreecommitdiff
path: root/sys/src/ape/lib/ap/power
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@gmx.de>2013-09-26 22:24:31 +0200
committercinap_lenrek <cinap_lenrek@gmx.de>2013-09-26 22:24:31 +0200
commitcdc2c30e99f2fb3d65dfbc8ef73efd433a3f1966 (patch)
tree5c3d5a6a42311f09444ca34d09bfebc78e08f5a3 /sys/src/ape/lib/ap/power
parentb4cdfc6c5517390d6be05b2c01e56bacc9e85ea8 (diff)
reverting semaphore lock changes from sources (r41ccd6d221da, rb28756e5ba29)
semaphore locks have much higher overhead than initially presented in the "Semaphores in Plan9" paper. until the reason for it has been found out i will revert the changes.
Diffstat (limited to 'sys/src/ape/lib/ap/power')
-rw-r--r--sys/src/ape/lib/ap/power/atom.s63
-rw-r--r--sys/src/ape/lib/ap/power/lock.c50
-rw-r--r--sys/src/ape/lib/ap/power/mkfile1
3 files changed, 30 insertions, 84 deletions
diff --git a/sys/src/ape/lib/ap/power/atom.s b/sys/src/ape/lib/ap/power/atom.s
deleted file mode 100644
index b387300df..000000000
--- a/sys/src/ape/lib/ap/power/atom.s
+++ /dev/null
@@ -1,63 +0,0 @@
-TEXT _xinc(SB),$0 /* void _xinc(long *); */
-TEXT ainc(SB),$0 /* long ainc(long *); */
- MOVW R3, R4
-xincloop:
- LWAR (R4), R3
- ADD $1, R3
- DCBT (R4) /* fix 405 errata cpu_210 */
- STWCCC R3, (R4)
- BNE xincloop
- RETURN
-
-TEXT _xdec(SB),$0 /* long _xdec(long *); */
-TEXT adec(SB),$0 /* long adec(long *); */
- MOVW R3, R4
-xdecloop:
- LWAR (R4), R3
- ADD $-1, R3
- DCBT (R4) /* fix 405 errata cpu_210 */
- STWCCC R3, (R4)
- BNE xdecloop
- RETURN
-
-TEXT loadlink(SB), $0
-
- LWAR (R3), R3
- RETURN
-
-TEXT storecond(SB), $0
-
- MOVW val+4(FP), R4
- DCBT (R3) /* fix 405 errata cpu_210 */
- STWCCC R4, (R3)
- BNE storecondfail
- MOVW $1, R3
- RETURN
-storecondfail:
- MOVW $0, R3
- RETURN
-
-/*
- * int cas(uint *p, int ov, int nv);
- * int casp(void **p, void *ov, void *nv);
- */
-
-TEXT cas+0(SB),0,$0
-TEXT casp+0(SB),0,$0
- MOVW ov+4(FP),R4
- MOVW nv+8(FP),R8
- LWAR (R3),R5
- CMP R5,R4
- BNE fail
- DCBT (R3) /* fix 405 errata cpu_210 */
- STWCCC R8,(R3)
- BNE fail1
- MOVW $1,R3
- RETURN
-fail:
- DCBT (R3) /* fix 405 errata cpu_210 */
- STWCCC R5,(R3) /* give up exclusive access */
-fail1:
- MOVW R0,R3
- RETURN
- END
diff --git a/sys/src/ape/lib/ap/power/lock.c b/sys/src/ape/lib/ap/power/lock.c
index 65a65df7b..0d17c34d5 100644
--- a/sys/src/ape/lib/ap/power/lock.c
+++ b/sys/src/ape/lib/ap/power/lock.c
@@ -3,33 +3,43 @@
#define _LOCK_EXTENSION
#include <lock.h>
+int tas(int*);
+
void
-lock(Lock *l)
+lock(Lock *lk)
{
- if(ainc(&l->key) == 1)
- return; /* changed from 0 -> 1: we hold lock */
- /* otherwise wait in kernel */
- while(_SEMACQUIRE(&l->sem, 1) < 0){
- /* interrupted; try again */
+ int i;
+
+ /* once fast */
+ if(!tas(&lk->val))
+ return;
+ /* a thousand times pretty fast */
+ for(i=0; i<1000; i++){
+ if(!tas(&lk->val))
+ return;
+ _SLEEP(0);
}
+ /* now nice and slow */
+ for(i=0; i<1000; i++){
+ if(!tas(&lk->val))
+ return;
+ _SLEEP(100);
+ }
+ /* take your time */
+ while(tas(&lk->val))
+ _SLEEP(1000);
}
-void
-unlock(Lock *l)
+int
+canlock(Lock *lk)
{
- if(adec(&l->key) == 0)
- return; /* changed from 1 -> 0: no contention */
- _SEMRELEASE(&l->sem, 1);
+ if(tas(&lk->val))
+ return 0;
+ return 1;
}
-int
-canlock(Lock *l)
+void
+unlock(Lock *lk)
{
- if(ainc(&l->key) == 1)
- return 1; /* changed from 0 -> 1: success */
- /* Undo increment (but don't miss wakeup) */
- if(adec(&l->key) == 0)
- return 0; /* changed from 1 -> 0: no contention */
- _SEMRELEASE(&l->sem, 1);
- return 0;
+ lk->val = 0;
}
diff --git a/sys/src/ape/lib/ap/power/mkfile b/sys/src/ape/lib/ap/power/mkfile
index ab4b35df6..cc546cd84 100644
--- a/sys/src/ape/lib/ap/power/mkfile
+++ b/sys/src/ape/lib/ap/power/mkfile
@@ -2,7 +2,6 @@ APE=/sys/src/ape
<$APE/config
LIB=/$objtype/lib/ape/libap.a
OFILES=\
- atom.$O\
cycles.$O\
getfcr.$O\
lock.$O\