Changes in the user space code of the optimistic semaphores. Unused semaphore stats have been removed. ACs use spin locks with no backoff. The other roles use the standard locks. Reference: /n/patches.lsub.org/patch/upsemstats Date: Mon Jun 25 20:29:16 CES 2012 Signed-off-by: esoriano@lsub.org --- /sys/src/libc/9sys/upsem.c Fri Jun 8 11:35:52 2012 +++ /sys/src/libc/9sys/upsem.c Mon Jun 25 19:18:31 2012 @@ -4,10 +4,6 @@ typedef struct Cnt Cnt; /* debug */ struct Cnt { - int sleep; - int zsleep; - int wake; - int zwake; int uup; int kup; int udown; @@ -24,25 +20,17 @@ static Cnt c; /* - * The genuine spin lock + * For ACs, no backoff */ static void -_lock(Lock *lk) +nixaclock(Lock *lk) { while(_tas(&lk->val)) - ; + while(lk->val) + ; return; } -static void -_yield(void) -{ - int nixtype; - - getcoreno(&nixtype); - if(nixtype != NIXAC) - sleep(0); -} void initsem(Sem *s, int val) @@ -55,10 +43,17 @@ void upsem(Sem *s) { + int nixtype; assert(s != nil); - - _lock(s); + + getcoreno(&nixtype); + + if(nixtype == NIXAC) + nixaclock(s); + else + lock(s); + if(s->tickets == 0 && (s->waiting > 0 || s->going > 0)){ unlock(s); ainc(&c.kup); @@ -74,14 +69,20 @@ downsem(Sem *s, int block) { int i; + int nixtype; assert(s != nil); + getcoreno(&nixtype); /* busy wait */ for(i = 0; s->tickets == 0 && i < semtrytimes; i++) ; - _lock(s); + if(nixtype == NIXAC) + nixaclock(s); + else + lock(s); + if(! block && s->tickets == 0){ unlock(s); return 0; @@ -100,7 +101,6 @@ return 1; } - /* * No optimistic for now. */ @@ -134,10 +134,6 @@ void semstats(void) { - print("sleep: %d\n", c.sleep); - print("zsleep: %d\n", c.zsleep); - print("wake: %d\n", c.wake); - print("zwake: %d\n", c.zwake); print("uup: %d\n", c.uup); print("kup: %d\n", c.kup); print("udown: %d\n", c.udown);