From be44179b005ee33d936ff55ef743bca5e84ee1b3 Mon Sep 17 00:00:00 2001 From: Bryan Ward Date: Tue, 14 May 2013 12:38:08 -0400 Subject: latest changes on pound. --- src/spinlocks.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/spinlocks.c b/src/spinlocks.c index 9b04702..520e12a 100644 --- a/src/spinlocks.c +++ b/src/spinlocks.c @@ -60,12 +60,13 @@ void rwrnlp_init(rwrnlp *lock) for(i = 0; i < NR_CPUS; i++){ lock->enter[i] = 0; lock->leave[i] = 0; + lock->curr[i] = 0; } spin_init(lock->enqueue); spin_init(lock->state); } -void rwrnlp_read_lock(rwrnlp *lock, resource_mask_t resources, int processor) +long rwrnlp_read_lock(rwrnlp *lock, resource_mask_t resources, int processor) { request *req; #if MEASURE==TRUE @@ -76,7 +77,7 @@ void rwrnlp_read_lock(rwrnlp *lock, resource_mask_t resources, int processor) enter_np(); - req = &lock->requests[processor]; + req = &lock->requests[processor][lock->curr[processor]]; req->resources = resources; req->type = read_req; req->status = waiting; @@ -116,13 +117,15 @@ void rwrnlp_read_lock(rwrnlp *lock, resource_mask_t resources, int processor) clock_gettime(CLOCK_MONOTONIC, &now); overhead += diff_ns(&last, &now); } - printf("read lock overhead: %ld\n", overhead); + return overhead; +#else + return 0; #endif // printf("%d:%d reader satisfied\n", __sync_fetch_and_add(&events,1), gettid()); } -void rwrnlp_write_lock(rwrnlp *lock, resource_mask_t resources, int processor) +long rwrnlp_write_lock(rwrnlp *lock, resource_mask_t resources, int processor) { int r,i,start,end; request *req, *contender; @@ -137,7 +140,7 @@ void rwrnlp_write_lock(rwrnlp *lock, resource_mask_t resources, int processor) // printf("%d:%d rwrnlp_write_lock\n", __sync_fetch_and_add(&events,1), gettid()); - req = &lock->requests[processor]; + req = &lock->requests[processor][lock->curr[processor]]; req->resources = resources; req->type = write_req; @@ -179,9 +182,9 @@ void rwrnlp_write_lock(rwrnlp *lock, resource_mask_t resources, int processor) for(i = 0; i < NR_CPUS; i++){ if(i != processor){ - start = lock->enter[i]; - contender = &lock->requests[i]; end = lock->leave[i]; + contender = &lock->requests[i][lock->curr[processor]]; + start = lock->enter[i]; if(start <= end || contender->type == write_req || contender->status == waiting || @@ -210,27 +213,32 @@ void rwrnlp_write_lock(rwrnlp *lock, resource_mask_t resources, int processor) #if MEASURE==TRUE clock_gettime(CLOCK_MONOTONIC, &now); overhead += diff_ns(&last, &now); - printf("write lock overhead: %ld\n", overhead); + return overhead; +#else + return 0; #endif } -void rwrnlp_read_unlock(rwrnlp *lock, int processor) +long rwrnlp_read_unlock(rwrnlp *lock, int processor) { #if MEASURE==TRUE struct timespec now, last; clock_gettime(CLOCK_MONOTONIC, &last); #endif lock->leave[processor] += 1; + lock->curr[processor] = (lock->curr[processor] + 1) % 2; // printf("%d:%d rwrnlp_read_unlock\n", __sync_fetch_and_add(&events,1), gettid()); exit_np(); #if MEASURE==TRUE clock_gettime(CLOCK_MONOTONIC, &now); - printf("read unlock overhead: %ld\n", diff_ns(&last, &now)); + return diff_ns(&last, &now); +#else + return 0; #endif } -void rwrnlp_write_unlock(rwrnlp *lock, int processor) +long rwrnlp_write_unlock(rwrnlp *lock, int processor) { int r; request *req; @@ -239,13 +247,11 @@ void rwrnlp_write_unlock(rwrnlp *lock, int processor) struct timespec now, last; clock_gettime(CLOCK_MONOTONIC, &last); #endif - req= &lock->requests[processor]; + req= &lock->requests[processor][lock->curr[processor]]; tmp = req->resources; // printf("%d:%d rwrnlp_write_unlock\n", __sync_fetch_and_add(&events,1), gettid()); - lock->leave[processor] += 1; - spin_lock(lock->state); r = ffsl(tmp); while(r != 0){ @@ -257,12 +263,17 @@ void rwrnlp_write_unlock(rwrnlp *lock, int processor) lock->wlocked &= ~(req->resources); lock->unavailable &= ~(req->resources); spin_unlock(lock->state); + + lock->leave[processor] += 1; + lock->curr[processor] = (lock->curr[processor] + 1) % 2; // printf("%d:%d write unlocked %lu\n", __sync_fetch_and_add(&events,1), gettid(), req->resources); // printf("unavailable %lu\nwentitled %lu\nwlocked %lu\n", lock->unavailable, lock->wentitled, lock->wlocked); exit_np(); #if MEASURE==TRUE clock_gettime(CLOCK_MONOTONIC, &now); - printf("write unlock overhead: %ld\n", diff_ns(&last, &now)); + return diff_ns(&last, &now); +#else + return 0; #endif } -- cgit v1.2.2